|
103 | 103 | end |
104 | 104 |
|
105 | 105 | describe "user present validation" do |
106 | | - let(:assertion) { client.get(challenge: original_challenge, user_present: false, user_verified: false) } |
| 106 | + context "when user presence flag is off" do |
| 107 | + let(:assertion) { client.get(challenge: original_challenge, user_present: false, user_verified: false) } |
| 108 | + |
| 109 | + context "when silent_authentication is not set" do |
| 110 | + context 'when user presence is not set' do |
| 111 | + it "doesn't verify" do |
| 112 | + expect { |
| 113 | + assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 114 | + }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 115 | + end |
| 116 | + |
| 117 | + it "is invalid" do |
| 118 | + expect( |
| 119 | + assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 120 | + ).to be_falsy |
| 121 | + end |
| 122 | + end |
107 | 123 |
|
108 | | - context "if user flags are off" do |
109 | | - it "doesn't verify" do |
110 | | - expect { |
111 | | - assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0) |
112 | | - }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 124 | + context 'when user presence is not required' do |
| 125 | + it "verifies if user presence is not required" do |
| 126 | + expect( |
| 127 | + assertion_response.verify( |
| 128 | + original_challenge, |
| 129 | + public_key: credential_public_key, |
| 130 | + sign_count: 0, |
| 131 | + user_presence: false |
| 132 | + ) |
| 133 | + ).to be_truthy |
| 134 | + end |
| 135 | + |
| 136 | + it "is valid" do |
| 137 | + expect( |
| 138 | + assertion_response.valid?( |
| 139 | + original_challenge, |
| 140 | + public_key: credential_public_key, |
| 141 | + sign_count: 0, |
| 142 | + user_presence: false |
| 143 | + ) |
| 144 | + ).to be_truthy |
| 145 | + end |
| 146 | + end |
| 147 | + |
| 148 | + context 'when user presence is required' do |
| 149 | + it "doesn't verify" do |
| 150 | + expect { |
| 151 | + assertion_response.verify( |
| 152 | + original_challenge, |
| 153 | + public_key: credential_public_key, |
| 154 | + sign_count: 0, |
| 155 | + user_presence: true |
| 156 | + ) |
| 157 | + }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 158 | + end |
| 159 | + |
| 160 | + it "is invalid" do |
| 161 | + expect( |
| 162 | + assertion_response.valid?( |
| 163 | + original_challenge, |
| 164 | + public_key: credential_public_key, |
| 165 | + sign_count: 0, |
| 166 | + user_presence: true |
| 167 | + ) |
| 168 | + ).to be_falsy |
| 169 | + end |
| 170 | + end |
113 | 171 | end |
114 | 172 |
|
115 | | - it "is invalid" do |
116 | | - expect( |
117 | | - assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0) |
118 | | - ).to be_falsy |
| 173 | + context "when silent_authentication is disabled" do |
| 174 | + around do |ex| |
| 175 | + old_value = WebAuthn.configuration.silent_authentication |
| 176 | + WebAuthn.configuration.silent_authentication = false |
| 177 | + |
| 178 | + ex.run |
| 179 | + |
| 180 | + WebAuthn.configuration.silent_authentication = old_value |
| 181 | + end |
| 182 | + |
| 183 | + context 'when user presence is not set' do |
| 184 | + it "doesn't verify" do |
| 185 | + expect { |
| 186 | + assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 187 | + }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 188 | + end |
| 189 | + |
| 190 | + it "is invalid" do |
| 191 | + expect( |
| 192 | + assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 193 | + ).to be_falsy |
| 194 | + end |
| 195 | + end |
| 196 | + |
| 197 | + context 'when user presence is not required' do |
| 198 | + it "verifies if user presence is not required" do |
| 199 | + expect( |
| 200 | + assertion_response.verify( |
| 201 | + original_challenge, |
| 202 | + public_key: credential_public_key, |
| 203 | + sign_count: 0, |
| 204 | + user_presence: false |
| 205 | + ) |
| 206 | + ).to be_truthy |
| 207 | + end |
| 208 | + |
| 209 | + it "is valid" do |
| 210 | + expect( |
| 211 | + assertion_response.valid?( |
| 212 | + original_challenge, |
| 213 | + public_key: credential_public_key, |
| 214 | + sign_count: 0, |
| 215 | + user_presence: false |
| 216 | + ) |
| 217 | + ).to be_truthy |
| 218 | + end |
| 219 | + end |
| 220 | + |
| 221 | + context 'when user presence is required' do |
| 222 | + it "doesn't verify" do |
| 223 | + expect { |
| 224 | + assertion_response.verify( |
| 225 | + original_challenge, |
| 226 | + public_key: credential_public_key, |
| 227 | + sign_count: 0, |
| 228 | + user_presence: true |
| 229 | + ) |
| 230 | + }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 231 | + end |
| 232 | + |
| 233 | + it "is invalid" do |
| 234 | + expect( |
| 235 | + assertion_response.valid?( |
| 236 | + original_challenge, |
| 237 | + public_key: credential_public_key, |
| 238 | + sign_count: 0, |
| 239 | + user_presence: true |
| 240 | + ) |
| 241 | + ).to be_falsy |
| 242 | + end |
| 243 | + end |
| 244 | + end |
| 245 | + |
| 246 | + context "when silent_authentication is enabled" do |
| 247 | + around do |ex| |
| 248 | + old_value = WebAuthn.configuration.silent_authentication |
| 249 | + WebAuthn.configuration.silent_authentication = true |
| 250 | + |
| 251 | + ex.run |
| 252 | + |
| 253 | + WebAuthn.configuration.silent_authentication = old_value |
| 254 | + end |
| 255 | + |
| 256 | + context 'when user presence is not set' do |
| 257 | + it "verifies if user presence is not required" do |
| 258 | + expect( |
| 259 | + assertion_response.verify(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 260 | + ).to be_truthy |
| 261 | + end |
| 262 | + |
| 263 | + it "is valid" do |
| 264 | + expect( |
| 265 | + assertion_response.valid?(original_challenge, public_key: credential_public_key, sign_count: 0) |
| 266 | + ).to be_truthy |
| 267 | + end |
| 268 | + end |
| 269 | + |
| 270 | + context 'when user presence is not required' do |
| 271 | + it "verifies if user presence is not required" do |
| 272 | + expect( |
| 273 | + assertion_response.verify( |
| 274 | + original_challenge, |
| 275 | + public_key: credential_public_key, |
| 276 | + sign_count: 0, |
| 277 | + user_presence: false |
| 278 | + ) |
| 279 | + ).to be_truthy |
| 280 | + end |
| 281 | + |
| 282 | + it "is valid" do |
| 283 | + expect( |
| 284 | + assertion_response.valid?( |
| 285 | + original_challenge, |
| 286 | + public_key: credential_public_key, |
| 287 | + sign_count: 0, |
| 288 | + user_presence: false |
| 289 | + ) |
| 290 | + ).to be_truthy |
| 291 | + end |
| 292 | + end |
| 293 | + |
| 294 | + context 'when user presence is required' do |
| 295 | + it "doesn't verify" do |
| 296 | + expect { |
| 297 | + assertion_response.verify( |
| 298 | + original_challenge, |
| 299 | + public_key: credential_public_key, |
| 300 | + sign_count: 0, |
| 301 | + user_presence: true |
| 302 | + ) |
| 303 | + }.to raise_exception(WebAuthn::UserPresenceVerificationError) |
| 304 | + end |
| 305 | + |
| 306 | + it "is invalid" do |
| 307 | + expect( |
| 308 | + assertion_response.valid?( |
| 309 | + original_challenge, |
| 310 | + public_key: credential_public_key, |
| 311 | + sign_count: 0, |
| 312 | + user_presence: true |
| 313 | + ) |
| 314 | + ).to be_falsy |
| 315 | + end |
| 316 | + end |
119 | 317 | end |
120 | 318 | end |
121 | 319 | end |
|
0 commit comments