Commit c5e45556 authored by Alper Akgun's avatar Alper Akgun

Merge branch 'mmj-presence-validator-webauthn_registration' into 'master'

Remove presence validator on name on WebauthnRegistration

See merge request gitlab-org/gitlab!74376
parents 0990ad76 9c88b3ad
......@@ -5,7 +5,8 @@
class WebauthnRegistration < ApplicationRecord
belongs_to :user
validates :credential_xid, :public_key, :name, :counter, presence: true
validates :credential_xid, :public_key, :counter, presence: true
validates :name, length: { minimum: 0, allow_nil: false }
validates :counter,
numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: 2**32 - 1 }
end
......@@ -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,12 +18,28 @@ RSpec.describe U2fRegistration do
describe 'callbacks' do
describe '#create_webauthn_registration' do
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 }
it_behaves_like 'creates webauthn registration'
end
it 'logs error' do
allow(Gitlab::Auth::U2fWebauthnConverter).to receive(:new).and_raise('boom!')
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe WebauthnRegistration do
describe 'relations' do
it { is_expected.to belong_to(:user) }
end
describe 'validations' do
it { is_expected.to validate_presence_of(:credential_xid) }
it { is_expected.to validate_presence_of(:public_key) }
it { is_expected.to validate_presence_of(:counter) }
it { is_expected.to validate_length_of(:name).is_at_least(0) }
it { is_expected.not_to allow_value(nil).for(:name) }
it do
is_expected.to validate_numericality_of(:counter)
.only_integer
.is_greater_than_or_equal_to(0)
.is_less_than_or_equal_to(4294967295)
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment