mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Tests for registrar ip whitelist
This commit is contained in:
parent
9fd54025f5
commit
a7a984d999
3 changed files with 32 additions and 4 deletions
|
@ -15,7 +15,7 @@ class Registrar::SessionsController < ::SessionsController
|
||||||
# rubocop:disable Metrics/CyclomaticComplexity
|
# rubocop:disable Metrics/CyclomaticComplexity
|
||||||
def create
|
def create
|
||||||
@depp_user = Depp::User.new(params[:depp_user].merge(
|
@depp_user = Depp::User.new(params[:depp_user].merge(
|
||||||
pki: !Rails.env.development?
|
pki: !(Rails.env.development? || Rails.env.test?)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class WhiteIp < ActiveRecord::Base
|
||||||
).and(
|
).and(
|
||||||
at[:ipv4].eq(ip)
|
at[:ipv4].eq(ip)
|
||||||
)
|
)
|
||||||
)
|
).any?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,11 +1,35 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
|
|
||||||
feature 'Sessions', type: :feature do
|
feature 'Sessions', type: :feature do
|
||||||
|
context 'with invalid ip' do
|
||||||
|
it 'should not see login page' do
|
||||||
|
WhiteIp.destroy_all
|
||||||
|
visit registrar_login_path
|
||||||
|
page.should have_text('IP is not whitelisted')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should see log in' do
|
||||||
|
@fixed_registrar.white_ips = [Fabricate(:white_ip_registrar)]
|
||||||
|
visit registrar_login_path
|
||||||
|
page.should have_text('Log in')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not get in with invalid ip' do
|
||||||
|
Fabricate(:registrar, white_ips: [Fabricate(:white_ip), Fabricate(:white_ip_registrar)])
|
||||||
|
@api_user_invalid_ip = Fabricate(:api_user, identity_code: '37810013294', registrar: Fabricate(:registrar, white_ips: []))
|
||||||
|
visit registrar_login_path
|
||||||
|
fill_in 'depp_user_tag', with: @api_user_invalid_ip.username
|
||||||
|
fill_in 'depp_user_password', with: @api_user_invalid_ip.password
|
||||||
|
click_button 'Log in'
|
||||||
|
page.should have_text('IP is not whitelisted')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'as unknown user' do
|
||||||
before :all do
|
before :all do
|
||||||
Fabricate(:api_user)
|
Fabricate(:api_user)
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as unknown user' do
|
|
||||||
it 'should not get in' do
|
it 'should not get in' do
|
||||||
client = instance_double("Digidoc::Client")
|
client = instance_double("Digidoc::Client")
|
||||||
allow(client).to receive(:authenticate).and_return(
|
allow(client).to receive(:authenticate).and_return(
|
||||||
|
@ -28,6 +52,10 @@ feature 'Sessions', type: :feature do
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'as known api user' do
|
context 'as known api user' do
|
||||||
|
before :all do
|
||||||
|
Fabricate(:api_user)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should not get in when external service fails' do
|
it 'should not get in when external service fails' do
|
||||||
client = instance_double("Digidoc::Client")
|
client = instance_double("Digidoc::Client")
|
||||||
allow(client).to receive(:authenticate).and_return(
|
allow(client).to receive(:authenticate).and_return(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue