forked from SeleniumHQ/seleniumhq.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvirtual_authenticator_spec.rb
More file actions
161 lines (116 loc) · 4.57 KB
/
virtual_authenticator_spec.rb
File metadata and controls
161 lines (116 loc) · 4.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'VirtualAuthenticator' do
let(:driver) { start_session }
let(:private_key) {
Base64.strict_encode64(OpenSSL::PKey::RSA.generate(2048).private_to_der)
}
let(:options) { Selenium::WebDriver::VirtualAuthenticatorOptions.new }
it "Registers a new virtual authenticator" do
options.protocol = :u2f
options.resident_key = false
authenticator = driver.add_virtual_authenticator(options)
credential_list = authenticator.credentials
expect(credential_list).to be_empty
end
it "Removes a virtual authenticator" do
authenticator = driver.add_virtual_authenticator(options)
authenticator.remove!
expect {
authenticator.credentials
}.to raise_error(Selenium::WebDriver::Error::InvalidArgumentError)
end
it "Creates and adds a resident_key" do
options.protocol = :ctap2
options.resident_key = true
options.user_verification = true
options.user_verified = true
authenticator = driver.add_virtual_authenticator(options)
credential_id = [1,2,3,4] # byte array
user_handle = [1] # byte array
# decode from Base64, then turn into a byte array
decoded_private_key = Base64.strict_decode64(private_key).bytes
resident_credential = Selenium::WebDriver::Credential.resident(
id: credential_id,
private_key: decoded_private_key,
rp_id: "localhost",
user_handle: user_handle
)
authenticator.add_credential(resident_credential)
credential_list = authenticator.credentials
expect(credential_list.size).to eq(1)
expect(credential_id).to eq(credential_list[0].id)
end
it "adding resident keys is not supported when the authenticator uses the U2F protocol" do
options.protocol = :u2f
options.resident_key = true
authenticator = driver.add_virtual_authenticator(options)
credential_id = [1,2,3,4] # byte array
user_handle = [1] # byte array
# decode from Base64, then turn into a byte array
decoded_private_key = Base64.strict_decode64(private_key).bytes
resident_credential = Selenium::WebDriver::Credential.resident(
id: credential_id,
private_key: decoded_private_key,
rp_id: "localhost",
user_handle: user_handle
)
expect {
authenticator.add_credential(resident_credential)
}.to raise_error(Selenium::WebDriver::Error::InvalidArgumentError)
end
it "Creates and adds a non-resident key" do
options.protocol = :u2f
options.resident_key = false
authenticator = driver.add_virtual_authenticator(options)
credential_id = [1,2,3,4] # byte array
# decode from Base64, then turn into a byte array
decoded_private_key = Base64.strict_decode64(private_key).bytes
resident_credential = Selenium::WebDriver::Credential.non_resident(
id: credential_id,
private_key: decoded_private_key,
rp_id: "localhost"
)
authenticator.add_credential(resident_credential)
credential_list = authenticator.credentials
expect(credential_list.size).to eq(1)
expect(credential_id).to eq(credential_list[0].id)
end
it "Can get a credential" do
options.protocol = :ctap2
options.resident_key = true
options.user_verification = true
options.user_verified = true
authenticator = driver.add_virtual_authenticator(options)
credential_id = [1,2,3,4] # byte array
user_handle = [1] # byte array
# decode from Base64, then turn into a byte array
decoded_private_key = Base64.strict_decode64(private_key).bytes
resident_credential = Selenium::WebDriver::Credential.resident(
id: credential_id,
private_key: decoded_private_key,
rp_id: "localhost",
user_handle: user_handle
)
authenticator.add_credential(resident_credential)
credential_list = authenticator.credentials
expect(credential_list.size).to eq(1)
expect(credential_id).to eq(credential_list[0].id)
expect(private_key).to eq(credential_list[0].private_key)
end
it "Removes all credentials" do
authenticator = driver.add_virtual_authenticator(options)
credential_id = [1,2,3,4] # byte array
# decode from Base64, then turn into a byte array
decoded_private_key = Base64.strict_decode64(private_key).bytes
resident_credential = Selenium::WebDriver::Credential.non_resident(
id: credential_id,
private_key: decoded_private_key,
rp_id: "localhost"
)
authenticator.add_credential(resident_credential)
authenticator.remove_all_credentials
credential_list = authenticator.credentials
expect(credential_list.size).to eq(0)
end
end