Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
SeleniumHQ
GitHub Repository: SeleniumHQ/Selenium
Path: blob/trunk/rb/spec/unit/selenium/webdriver/common/credentials_spec.rb
1865 views
1
# frozen_string_literal: true
2
3
# Licensed to the Software Freedom Conservancy (SFC) under one
4
# or more contributor license agreements. See the NOTICE file
5
# distributed with this work for additional information
6
# regarding copyright ownership. The SFC licenses this file
7
# to you under the Apache License, Version 2.0 (the
8
# "License"); you may not use this file except in compliance
9
# with the License. You may obtain a copy of the License at
10
#
11
# http://www.apache.org/licenses/LICENSE-2.0
12
#
13
# Unless required by applicable law or agreed to in writing,
14
# software distributed under the License is distributed on an
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
# KIND, either express or implied. See the License for the
17
# specific language governing permissions and limitations
18
# under the License.
19
20
require File.expand_path('../spec_helper', __dir__)
21
22
module Selenium
23
module WebDriver
24
describe Credential do
25
let(:base64_encoded_pk) do
26
'MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbBOu5Lhs4vpowbCnmCyLUpIE7JM9sm9QXzye2G+jr+Kr' \
27
'MsinWohEce47BFPJlTaDzHSvOW2eeunBO89ZcvvVc8RLz4qyQ8rO98xS1jtgqi1NcBPETDrtzthODu/gd0sjB2Tk3TLuBGV' \
28
'oPXt54a+Oo4JbBJ6h3s0+5eAfGplCbSNq6hN3Jh9YOTw5ZA6GCEy5l8zBaOgjXytd2v2OdSVoEDNiNQRkjJd2rmS2oi9AyQ' \
29
'FR3B7BrPSiDlCcITZFOWgLF5C31Wp/PSHwQhlnh7/6YhnE2y9tzsUvzx0wJXrBADW13+oMxrneDK3WGbxTNYgIi1PvSqXlq' \
30
'GjHtCK+R2QkXAgMBAAECggEAVc6bu7VAnP6v0gDOeX4razv4FX/adCao9ZsHZ+WPX8PQxtmWYqykH5CY4TSfsuizAgyPuQ0' \
31
'+j4Vjssr9VOD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EqosRrH' \
42
'zJOGpf9x2RSWzQJ+dq8+6fACgfFZOVpN644+sAHfNPAI/gnNKU5OfUv+eav8fBnzlf1A3y3GIkyMyzFN3DE7e0n/lyqxE4H' \
43
'BYGpI8g=='
44
end
45
let(:id) { [1, 2, 3, 4] }
46
let(:rp_id) { 'localhost' }
47
let(:user_handle) { [1] }
48
let(:private_key) { described_class.decode(base64_encoded_pk) }
49
let(:sign_count) { 0 }
50
51
describe '#self.resident' do
52
it 'adds credential' do
53
credential = described_class.resident(id: id,
54
rp_id: rp_id,
55
user_handle: user_handle,
56
private_key: private_key,
57
sign_count: sign_count)
58
59
expect(credential.id).to eq([1, 2, 3, 4])
60
expect(credential.resident_credential?).to be(true)
61
expect(credential.rp_id).to eq('localhost')
62
expect(credential.user_handle).to eq(user_handle)
63
expect(credential.private_key).to eq(private_key)
64
expect(credential.sign_count).to eq(0)
65
end
66
end
67
68
describe '#self.non_resident' do
69
it 'can testRkDisabledCredential' do
70
credential = described_class.non_resident(id: id,
71
rp_id: rp_id,
72
private_key: private_key,
73
sign_count: sign_count)
74
75
expect(credential.id).to eq([1, 2, 3, 4])
76
expect(credential.resident_credential?).to be(false)
77
expect(credential.rp_id).to eq('localhost')
78
expect(credential.private_key).to eq(private_key)
79
expect(credential.sign_count).to eq(0)
80
end
81
end
82
83
describe '#self.from_json' do
84
it 'creates Credential from JSON' do
85
credential_data = {'credentialId' => described_class.encode(id),
86
'isResidentCredential' => true,
87
'rpId' => 'localhost',
88
'userHandle' => described_class.encode(user_handle),
89
'privateKey' => base64_encoded_pk,
90
'signCount' => 0}
91
92
credential = described_class.from_json(credential_data)
93
94
expect(credential.id).to eq(id)
95
expect(credential.resident_credential?).to be(true)
96
expect(credential.rp_id).to eq('localhost')
97
expect(credential.user_handle).to eq(user_handle)
98
expect(credential.private_key).to eq(base64_encoded_pk)
99
expect(credential.sign_count).to eq(0)
100
end
101
end
102
103
describe '#as_json' do
104
it 'converts to JSON' do
105
credential = described_class.resident(id: id,
106
rp_id: rp_id,
107
private_key: private_key,
108
user_handle: user_handle,
109
sign_count: sign_count)
110
111
credential_json = credential.as_json
112
113
expect(credential_json['credentialId']).to eq(described_class.encode([1, 2, 3, 4]))
114
expect(credential_json['isResidentCredential']).to be(true)
115
expect(credential_json['rpId']).to eq('localhost')
116
expect(credential_json['userHandle']).to eq(described_class.encode(user_handle))
117
118
expect(credential_json['privateKey']).to eq(described_class.encode(private_key))
119
expect(credential_json['signCount']).to eq(0)
120
end
121
end
122
end # Credential
123
end # WebDriver
124
end # Selenium
125
126