Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/credentials_spec.rb
1865 views
# frozen_string_literal: true12# Licensed to the Software Freedom Conservancy (SFC) under one3# or more contributor license agreements. See the NOTICE file4# distributed with this work for additional information5# regarding copyright ownership. The SFC licenses this file6# to you under the Apache License, Version 2.0 (the7# "License"); you may not use this file except in compliance8# with the License. You may obtain a copy of the License at9#10# http://www.apache.org/licenses/LICENSE-2.011#12# Unless required by applicable law or agreed to in writing,13# software distributed under the License is distributed on an14# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15# KIND, either express or implied. See the License for the16# specific language governing permissions and limitations17# under the License.1819require File.expand_path('../spec_helper', __dir__)2021module Selenium22module WebDriver23describe Credential do24let(:base64_encoded_pk) do25'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbBOu5Lhs4vpowbCnmCyLUpIE7JM9sm9QXzye2G+jr+Kr' \26'MsinWohEce47BFPJlTaDzHSvOW2eeunBO89ZcvvVc8RLz4qyQ8rO98xS1jtgqi1NcBPETDrtzthODu/gd0sjB2Tk3TLuBGV' \27'oPXt54a+Oo4JbBJ6h3s0+5eAfGplCbSNq6hN3Jh9YOTw5ZA6GCEy5l8zBaOgjXytd2v2OdSVoEDNiNQRkjJd2rmS2oi9AyQ' \28'FR3B7BrPSiDlCcITZFOWgLF5C31Wp/PSHwQhlnh7/6YhnE2y9tzsUvzx0wJXrBADW13+oMxrneDK3WGbxTNYgIi1PvSqXlq' \29'GjHtCK+R2QkXAgMBAAECggEAVc6bu7VAnP6v0gDOeX4razv4FX/adCao9ZsHZ+WPX8PQxtmWYqykH5CY4TSfsuizAgyPuQ0' \30'+j4Vjssr9VODLqFoanspT6YXsvaKanncUYbasNgUJnfnLnw3an2XpU2XdmXTNYckCPRX9nsAAURWT3/n9ljc/XYY22ecYxM' \31'8sDWnHu2uKZ1B7M3X60bQYL5T/lVXkKdD6xgSNLeP4AkRx0H4egaop68hoW8FIwmDPVWYVAvo8etzWCtibRXz5FcNld9MgD' \32'/Ai7ycKy4Q1KhX5GBFI79MVVaHkSQfxPHpr7/XcmpQOEAr+BMPon4s4vnKqAGdGB3j/E3d/+4F2swykoQKBgQD8hCsp6FIQ' \33'5umJlk9/j/nGsMl85LgLaNVYpWlPRKPc54YNumtvj5vx1BG+zMbT7qIE3nmUPTCHP7qb5ERZG4CdMCS6S64/qzZEqijLCqe' \34'pwj6j4fV5SyPWEcpxf6ehNdmcfgzVB3Wolfwh1ydhx/96L1jHJcTKchdJJzlfTvq8wwKBgQDeCnKws1t5GapfE1rmC/h4ol' \35'L2qZTth9oQmbrXYohVnoqNFslDa43ePZwL9Jmd9kYb0axOTNMmyrP0NTj41uCfgDS0cJnNTc63ojKjegxHIyYDKRZNVUR/d' \36'xAYB/vPfBYZUS7M89pO6LLsHhzS3qpu3/hppo/Uc/AM/r8PSflNHQKBgDnWgBh6OQncChPUlOLv9FMZPR1ZOfqLCYrjYEqi' \37'uzGm6iKM13zXFO4AGAxu1P/IAd5BovFcTpg79Z8tWqZaUUwvscnl+cRlj+mMXAmdqCeO8VASOmqM1ml667axeZDIR867ZG8' \38'K5V029Wg+4qtX5uFypNAAi6GfHkxIKrD04yOHAoGACdh4wXESi0oiDdkz3KOHPwIjn6BhZC7z8mx+pnJODU3cYukxv3WTct' \39'lUhAsyjJiQ/0bK1yX87ulqFVgO0Knmh+wNajrb9wiONAJTMICG7tiWJOm7fW5cfTJwWkBwYADmkfTRmHDvqzQSSvoC2S7aa' \40'9QulbC3C/qgGFNrcWgcT9kCgYAZTa1P9bFCDU7hJc2mHwJwAW7/FQKEJg8SL33KINpLwcR8fqaYOdAHWWz636osVEqosRrH' \41'zJOGpf9x2RSWzQJ+dq8+6fACgfFZOVpN644+sAHfNPAI/gnNKU5OfUv+eav8fBnzlf1A3y3GIkyMyzFN3DE7e0n/lyqxE4H' \42'BYGpI8g=='43end44let(:id) { [1, 2, 3, 4] }45let(:rp_id) { 'localhost' }46let(:user_handle) { [1] }47let(:private_key) { described_class.decode(base64_encoded_pk) }48let(:sign_count) { 0 }4950describe '#self.resident' do51it 'adds credential' do52credential = described_class.resident(id: id,53rp_id: rp_id,54user_handle: user_handle,55private_key: private_key,56sign_count: sign_count)5758expect(credential.id).to eq([1, 2, 3, 4])59expect(credential.resident_credential?).to be(true)60expect(credential.rp_id).to eq('localhost')61expect(credential.user_handle).to eq(user_handle)62expect(credential.private_key).to eq(private_key)63expect(credential.sign_count).to eq(0)64end65end6667describe '#self.non_resident' do68it 'can testRkDisabledCredential' do69credential = described_class.non_resident(id: id,70rp_id: rp_id,71private_key: private_key,72sign_count: sign_count)7374expect(credential.id).to eq([1, 2, 3, 4])75expect(credential.resident_credential?).to be(false)76expect(credential.rp_id).to eq('localhost')77expect(credential.private_key).to eq(private_key)78expect(credential.sign_count).to eq(0)79end80end8182describe '#self.from_json' do83it 'creates Credential from JSON' do84credential_data = {'credentialId' => described_class.encode(id),85'isResidentCredential' => true,86'rpId' => 'localhost',87'userHandle' => described_class.encode(user_handle),88'privateKey' => base64_encoded_pk,89'signCount' => 0}9091credential = described_class.from_json(credential_data)9293expect(credential.id).to eq(id)94expect(credential.resident_credential?).to be(true)95expect(credential.rp_id).to eq('localhost')96expect(credential.user_handle).to eq(user_handle)97expect(credential.private_key).to eq(base64_encoded_pk)98expect(credential.sign_count).to eq(0)99end100end101102describe '#as_json' do103it 'converts to JSON' do104credential = described_class.resident(id: id,105rp_id: rp_id,106private_key: private_key,107user_handle: user_handle,108sign_count: sign_count)109110credential_json = credential.as_json111112expect(credential_json['credentialId']).to eq(described_class.encode([1, 2, 3, 4]))113expect(credential_json['isResidentCredential']).to be(true)114expect(credential_json['rpId']).to eq('localhost')115expect(credential_json['userHandle']).to eq(described_class.encode(user_handle))116117expect(credential_json['privateKey']).to eq(described_class.encode(private_key))118expect(credential_json['signCount']).to eq(0)119end120end121end # Credential122end # WebDriver123end # Selenium124125126