|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -require 'selenium-webdriver' |
| 3 | +require 'spec_helper' |
4 | 4 |
|
5 | 5 | RSpec.describe 'Virtual Authenticator' do |
6 | 6 | let(:driver) { start_session } |
|
41 | 41 |
|
42 | 42 | it 'creates virtual authenticator' do |
43 | 43 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new(protocol: :u2f, resident_key: false) |
44 | | - @authenticator = driver.add_virtual_authenticator(options) |
| 44 | + authenticator = driver.add_virtual_authenticator(options) |
45 | 45 |
|
46 | | - expect(@authenticator.valid?).to eq true |
| 46 | + expect(authenticator.valid?).to eq true |
47 | 47 | end |
48 | 48 |
|
49 | 49 | it 'removes virtual authenticator' do |
50 | 50 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new |
51 | | - @authenticator = driver.add_virtual_authenticator(options) |
52 | | - @authenticator.remove! |
| 51 | + authenticator = driver.add_virtual_authenticator(options) |
| 52 | + authenticator.remove! |
53 | 53 |
|
54 | | - expect(@authenticator.valid?).to eq false |
| 54 | + expect(authenticator.valid?).to eq false |
55 | 55 | end |
56 | 56 |
|
57 | 57 | it 'creates and add resident credential' do |
58 | 58 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new(protocol: :ctap2, resident_key: true, |
59 | 59 | user_verification: true, user_verified: true) |
60 | | - @authenticator = driver.add_virtual_authenticator(options) |
| 60 | + authenticator = driver.add_virtual_authenticator(options) |
61 | 61 |
|
62 | 62 | resident_credential = Selenium::WebDriver::Credential.resident(id: [1, 2, 3, 4], |
63 | 63 | rp_id: 'localhost', |
64 | 64 | user_handle: [1], |
65 | 65 | private_key: Selenium::WebDriver::Credential |
66 | 66 | .decode(encoded_private_key), |
67 | 67 | sign_count: 0) |
68 | | - @authenticator.add_credential(resident_credential) |
69 | | - credential_list = @authenticator.credentials |
| 68 | + authenticator.add_credential(resident_credential) |
| 69 | + credential_list = authenticator.credentials |
70 | 70 | expect(credential_list.length).to eq 1 |
71 | 71 |
|
72 | 72 | credential_id = credential_list.first.id |
|
75 | 75 |
|
76 | 76 | it 'does not support resident credential when authenticator uses u2f protocol' do |
77 | 77 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new(protocol: :u2f, resident_key: true) |
78 | | - @authenticator = driver.add_virtual_authenticator(options) |
| 78 | + authenticator = driver.add_virtual_authenticator(options) |
79 | 79 |
|
80 | 80 | resident_credential = Selenium::WebDriver::Credential.resident(id: [1, 2, 3, 4], |
81 | 81 | rp_id: 'localhost', |
|
85 | 85 | sign_count: 0) |
86 | 86 |
|
87 | 87 | expect { |
88 | | - @authenticator.add_credential(resident_credential) |
| 88 | + authenticator.add_credential(resident_credential) |
89 | 89 | }.to raise_error(Selenium::WebDriver::Error::InvalidArgumentError) |
90 | 90 | end |
91 | 91 |
|
92 | 92 | it 'creates and add non-resident credential' do |
93 | 93 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new(protocol: :u2f, resident_key: false) |
94 | | - @authenticator = driver.add_virtual_authenticator(options) |
| 94 | + authenticator = driver.add_virtual_authenticator(options) |
95 | 95 |
|
96 | 96 | non_resident_credential = Selenium::WebDriver::Credential.non_resident(id: [1, 2, 3, 4], |
97 | 97 | rp_id: 'localhost', |
98 | 98 | private_key: Selenium::WebDriver::Credential |
99 | 99 | .decode(pkcs8_private_key), |
100 | 100 | sign_count: 0) |
101 | | - @authenticator.add_credential(non_resident_credential) |
102 | | - credentials = @authenticator.credentials |
| 101 | + authenticator.add_credential(non_resident_credential) |
| 102 | + credentials = authenticator.credentials |
103 | 103 |
|
104 | 104 | expect(credentials.length).to eq 1 |
105 | 105 | expect(credentials.first.id).to eq [1, 2, 3, 4] |
|
108 | 108 | it 'gets all credentials' do |
109 | 109 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new(protocol: :ctap2, resident_key: true, |
110 | 110 | user_verification: true, user_verified: true) |
111 | | - @authenticator = @driver.add_virtual_authenticator(options) |
| 111 | + authenticator = driver.add_virtual_authenticator(options) |
112 | 112 |
|
113 | 113 | resident_credential = Selenium::WebDriver::Credential.resident(id: [1, 2, 3, 4], |
114 | 114 | rp_id: 'localhost', |
|
121 | 121 | private_key: Selenium::WebDriver::Credential |
122 | 122 | .decode(encoded_private_key), |
123 | 123 | sign_count: 0) |
124 | | - @authenticator.add_credential(resident_credential) |
125 | | - @authenticator.add_credential(non_resident_credential) |
| 124 | + authenticator.add_credential(resident_credential) |
| 125 | + authenticator.add_credential(non_resident_credential) |
126 | 126 |
|
127 | | - credentials = @authenticator.credentials |
| 127 | + credentials = authenticator.credentials |
128 | 128 | expect(credentials.length).to eq 2 |
129 | 129 | expect(credentials.first.id).to eq [1, 2, 3, 4] |
130 | 130 | end |
131 | 131 |
|
132 | 132 | it 'removes all credentials' do |
133 | 133 | options = Selenium::WebDriver::VirtualAuthenticatorOptions.new |
134 | | - @authenticator = driver.add_virtual_authenticator(options) |
| 134 | + authenticator = driver.add_virtual_authenticator(options) |
135 | 135 |
|
136 | 136 | non_resident_credential = Selenium::WebDriver::Credential.non_resident(id: [1, 2, 3, 4], |
137 | 137 | rp_id: 'localhost', |
138 | 138 | private_key: Selenium::WebDriver::Credential |
139 | 139 | .decode(encoded_private_key), |
140 | 140 | sign_count: 0) |
141 | | - @authenticator.add_credential(non_resident_credential) |
142 | | - expect(@authenticator.credentials.length).to eq 1 |
| 141 | + authenticator.add_credential(non_resident_credential) |
| 142 | + expect(authenticator.credentials.length).to eq 1 |
143 | 143 |
|
144 | | - @authenticator.remove_all_credentials |
145 | | - expect(@authenticator.credentials).to be_empty |
| 144 | + authenticator.remove_all_credentials |
| 145 | + expect(authenticator.credentials).to be_empty |
146 | 146 | end |
147 | 147 | end |
0 commit comments