summaryrefslogtreecommitdiff
path: root/spec/models/u2f_registration_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-18 13:16:36 +0000
commit311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch)
tree07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/models/u2f_registration_spec.rb
parent27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff)
downloadgitlab-ce-056d9df33865790d1b3c10f77912e00f61193000.tar.gz
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/models/u2f_registration_spec.rb')
-rw-r--r--spec/models/u2f_registration_spec.rb28
1 files changed, 23 insertions, 5 deletions
diff --git a/spec/models/u2f_registration_spec.rb b/spec/models/u2f_registration_spec.rb
index aba2f27d104..7a70cf69566 100644
--- a/spec/models/u2f_registration_spec.rb
+++ b/spec/models/u2f_registration_spec.rb
@@ -5,9 +5,11 @@ require 'spec_helper'
RSpec.describe U2fRegistration do
let_it_be(:user) { create(:user) }
+ let(:u2f_registration_name) { 'u2f_device' }
+
let(:u2f_registration) do
device = U2F::FakeU2F.new(FFaker::BaconIpsum.characters(5))
- create(:u2f_registration, name: 'u2f_device',
+ create(:u2f_registration, name: u2f_registration_name,
user: user,
certificate: Base64.strict_encode64(device.cert_raw),
key_handle: U2F.urlsafe_encode64(device.key_handle_raw),
@@ -16,11 +18,27 @@ RSpec.describe U2fRegistration do
describe 'callbacks' do
describe '#create_webauthn_registration' do
- it 'creates webauthn registration' do
- u2f_registration.save!
+ shared_examples_for 'creates webauthn registration' do
+ it 'creates webauthn registration' do
+ u2f_registration.save!
+
+ webauthn_registration = WebauthnRegistration.where(u2f_registration_id: u2f_registration.id)
+ expect(webauthn_registration).to exist
+ end
+ end
+
+ it_behaves_like 'creates webauthn registration'
+
+ context 'when the u2f_registration has a blank name' do
+ let(:u2f_registration_name) { '' }
+
+ it_behaves_like 'creates webauthn registration'
+ end
+
+ context 'when the u2f_registration has the name as `nil`' do
+ let(:u2f_registration_name) { nil }
- webauthn_registration = WebauthnRegistration.where(u2f_registration_id: u2f_registration.id)
- expect(webauthn_registration).to exist
+ it_behaves_like 'creates webauthn registration'
end
it 'logs error' do