diff options
Diffstat (limited to 'spec/models/authentication_event_spec.rb')
-rw-r--r-- | spec/models/authentication_event_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/models/authentication_event_spec.rb b/spec/models/authentication_event_spec.rb index 83598fa6765..23e253c2a28 100644 --- a/spec/models/authentication_event_spec.rb +++ b/spec/models/authentication_event_spec.rb @@ -44,4 +44,31 @@ RSpec.describe AuthenticationEvent do expect(described_class.providers).to match_array %w(ldapmain google_oauth2 standard two-factor two-factor-via-u2f-device two-factor-via-webauthn-device) end end + + describe '.initial_login_or_known_ip_address?' do + let_it_be(:user) { create(:user) } + let_it_be(:ip_address) { '127.0.0.1' } + + subject { described_class.initial_login_or_known_ip_address?(user, ip_address) } + + context 'on first login, when no record exists yet' do + it { is_expected.to eq(true) } + end + + context 'on second login from the same ip address' do + before do + create(:authentication_event, :successful, user: user, ip_address: ip_address) + end + + it { is_expected.to eq(true) } + end + + context 'on second login from another ip address' do + before do + create(:authentication_event, :successful, user: user, ip_address: '1.2.3.4') + end + + it { is_expected.to eq(false) } + end + end end |