Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
seleniumhq
GitHub Repository: seleniumhq/selenium
Path: blob/trunk/javascript/selenium-webdriver/test/lib/credentials_test.js
2885 views
1
// Licensed to the Software Freedom Conservancy (SFC) under one
2
// or more contributor license agreements. See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership. The SFC licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License. You may obtain a copy of the License at
8
//
9
// http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied. See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
'use strict'
19
20
const assert = require('node:assert')
21
const virtualAuthenticatorCredential = require('selenium-webdriver/lib/virtual_authenticator').Credential
22
23
describe('Credentials', function () {
24
const BASE64_ENCODED_PK = `MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDbBOu5Lhs4vpowbCnmCyLUpIE7JM9sm9QXzye2G+jr+Kr
25
MsinWohEce47BFPJlTaDzHSvOW2eeunBO89ZcvvVc8RLz4qyQ8rO98xS1jtgqi1NcBPETDrtzthODu/gd0sjB2Tk3TLuBGV
26
oPXt54a+Oo4JbBJ6h3s0+5eAfGplCbSNq6hN3Jh9YOTw5ZA6GCEy5l8zBaOgjXytd2v2OdSVoEDNiNQRkjJd2rmS2oi9AyQ
27
FR3B7BrPSiDlCcITZFOWgLF5C31Wp/PSHwQhlnh7/6YhnE2y9tzsUvzx0wJXrBADW13+oMxrneDK3WGbxTNYgIi1PvSqXlq
28
GjHtCK+R2QkXAgMBAAECggEAVc6bu7VAnP6v0gDOeX4razv4FX/adCao9ZsHZ+WPX8PQxtmWYqykH5CY4TSfsuizAgyPuQ0
29
+j4Vjssr9VODLqFoanspT6Y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pN644+sAHfNPAI/gnNKU5OfUv+eav8fBnzlf1A3y3GIkyMyzFN3DE7e0n/lyqxE4H
41
BYGpI8g==`
42
43
const data = {
44
_id: new Uint8Array([1, 2, 3, 4]),
45
rpId: 'localhost',
46
userHandle: new Uint8Array([1]),
47
privateKey: Buffer.from(BASE64_ENCODED_PK, 'base64').toString('binary'),
48
signCount: 0,
49
}
50
51
it('can testRkEnabledCredential', function () {
52
const { _id, rpId, userHandle, privateKey, signCount } = data
53
const credential = virtualAuthenticatorCredential.createResidentCredential(
54
_id,
55
rpId,
56
userHandle,
57
privateKey,
58
signCount,
59
)
60
61
let testCredentialId = new Uint8Array([1, 2, 3, 4])
62
63
/**
64
* Checking if credential.id() matches with testCredentialId. Both values are
65
* arrays so we check if the lengths of both are equal and if one array has
66
* all its elements in the other array and vice-versa.
67
*/
68
assert.equal(
69
credential.id().length == testCredentialId.length &&
70
credential.id().every((item) => testCredentialId.includes(item)) &&
71
testCredentialId.every((item) => credential.id().includes(item)),
72
true,
73
)
74
if (credential.isResidentCredential() == true) {
75
assert(true)
76
} else {
77
assert(false)
78
}
79
assert.equal(credential.rpId(), 'localhost')
80
81
let testUserHandle = new Uint8Array([1])
82
83
/**
84
* Checking if credential.userHandle() matches with testUserHandle. Both values are
85
* arrays so we check if the lengths of both are equal and if one array has
86
* all its elements in the other array and vice-versa.
87
*/
88
assert.equal(
89
credential.userHandle().length == testUserHandle.length &&
90
credential.userHandle().every((item) => testUserHandle.includes(item)) &&
91
testUserHandle.every((item) => credential.userHandle().includes(item)),
92
true,
93
)
94
assert.equal(credential.privateKey(), Buffer.from(BASE64_ENCODED_PK, 'base64url').toString('binary'))
95
assert.equal(credential.signCount(), 0)
96
})
97
98
it('can testRkDisabledCredential', function () {
99
const { _id, rpId, privateKey, signCount } = data
100
const credential = virtualAuthenticatorCredential.createNonResidentCredential(_id, rpId, privateKey, signCount)
101
102
let testCredentialId = new Uint8Array([1, 2, 3, 4])
103
104
/**
105
* Checking if credential.id() matches with testCredentialId. Both values are
106
* arrays so we check if the lengths of both are equal and if one array has
107
* all its elements in the other array and vice-versa.
108
*/
109
assert.equal(
110
credential.id().length == testCredentialId.length &&
111
credential.id().every((item) => testCredentialId.includes(item)) &&
112
testCredentialId.every((item) => credential.id().includes(item)),
113
true,
114
)
115
116
if (credential.isResidentCredential() == false) {
117
assert(true)
118
} else {
119
assert(false)
120
}
121
122
if (credential.userHandle() == null) {
123
assert(true)
124
} else {
125
assert(false)
126
}
127
})
128
129
it('can testToDict', function () {
130
const { _id, rpId, userHandle, privateKey, signCount } = data
131
const credential = virtualAuthenticatorCredential.createResidentCredential(
132
_id,
133
rpId,
134
userHandle,
135
privateKey,
136
signCount,
137
)
138
139
let credential_dict = credential.toDict()
140
assert.equal(credential_dict['credentialId'], Buffer.from(new Uint8Array([1, 2, 3, 4])).toString('base64url'))
141
142
if (credential_dict['isResidentCredential'] == true) {
143
assert(true)
144
} else {
145
assert(false)
146
}
147
148
assert.equal(credential_dict['rpId'], 'localhost')
149
assert.equal(credential_dict['userHandle'], Buffer.from(new Uint8Array([1])).toString('base64url'))
150
assert.equal(credential_dict['privateKey'], Buffer.from(privateKey, 'binary').toString('base64url'))
151
assert.equal(credential_dict['signCount'], 0)
152
})
153
154
it('can testFromDict', function () {
155
let credential_data = {
156
credentialId: Buffer.from(new Uint8Array([1, 2, 3, 4])).toString('base64url'),
157
isResidentCredential: true,
158
rpId: 'localhost',
159
userHandle: Buffer.from(new Uint8Array([1])).toString('base64url'),
160
privateKey: BASE64_ENCODED_PK,
161
signCount: 0,
162
}
163
164
let credential = new virtualAuthenticatorCredential().fromDict(credential_data)
165
let testCredentialId = new Uint8Array([1, 2, 3, 4])
166
assert.equal(
167
credential.id().length == testCredentialId.length &&
168
credential.id().every((item) => testCredentialId.includes(item)) &&
169
testCredentialId.every((item) => credential.id().includes(item)),
170
true,
171
)
172
173
if (credential.isResidentCredential() == true) {
174
assert(true)
175
} else {
176
assert(false)
177
}
178
179
assert.equal(credential.rpId(), 'localhost')
180
181
let testUserHandle = new Uint8Array([1])
182
183
/**
184
* Checking if credential.userHandle() matches with testUserHandle. Both values are
185
* arrays so we check if the lengths of both are equal and if one array has
186
* all its elements in the other array and vice-versa.
187
*/
188
assert.equal(
189
credential.userHandle().length == testUserHandle.length &&
190
credential.userHandle().every((item) => testUserHandle.includes(item)) &&
191
testUserHandle.every((item) => credential.userHandle().includes(item)),
192
true,
193
)
194
195
assert.equal(credential.privateKey(), Buffer.from(BASE64_ENCODED_PK, 'base64url').toString('binary'))
196
assert.equal(credential.signCount(), 0)
197
})
198
})
199
200