From 9b4e9ca12cb55f5c2e5646aa0727c7f0d8406b41 Mon Sep 17 00:00:00 2001 From: Martin Lensment Date: Tue, 19 May 2015 19:24:53 +0300 Subject: [PATCH] Add test for REPP IP whitelisting --- spec/fabricators/white_ip_fabricator.rb | 3 +- spec/requests/v1/account_spec.rb | 53 +++++++++++++++---------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/spec/fabricators/white_ip_fabricator.rb b/spec/fabricators/white_ip_fabricator.rb index e449573fb..b9a4b73ab 100644 --- a/spec/fabricators/white_ip_fabricator.rb +++ b/spec/fabricators/white_ip_fabricator.rb @@ -1,9 +1,8 @@ Fabricator(:white_ip) do - ipv4 '192.168.1.1' + ipv4 '127.0.0.1' interface WhiteIp::EPP end Fabricator(:white_ip_repp, from: :white_ip) do - ipv4 '127.0.0.1' interface WhiteIp::REPP end diff --git a/spec/requests/v1/account_spec.rb b/spec/requests/v1/account_spec.rb index 3928ad64a..324e8d191 100644 --- a/spec/requests/v1/account_spec.rb +++ b/spec/requests/v1/account_spec.rb @@ -1,30 +1,43 @@ require 'rails_helper' describe Repp::AccountV1 do - before :all do - @registrar1 = Fabricate(:registrar1, accounts: - [Fabricate(:account, { balance: '324.45', account_activities: [] })] - ) - @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) + it 'should fail without whitelisted IP' do + @registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip)]) + @api_user = Fabricate(:api_user, registrar: @registrar1) + + get_with_auth '/repp/v1/accounts/balance', {}, @api_user + response.status.should == 401 + body = JSON.parse(response.body) + + body['error'].should == 'IP is not whitelisted' end - describe 'GET /repp/v1/accounts/balance' do - it 'returns account balance of the current registrar', autodoc: true, route_info_doc: true do - get_with_auth '/repp/v1/accounts/balance', {}, @api_user - response.status.should == 200 + context 'with valid registrar' do + before :all do + @registrar1 = Fabricate(:registrar1, accounts: + [Fabricate(:account, { balance: '324.45', account_activities: [] })] + ) + @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) + end - body = JSON.parse(response.body) - body['balance'].should == '324.45' - body['currency'].should == 'EUR' + describe 'GET /repp/v1/accounts/balance' do + it 'returns account balance of the current registrar', autodoc: true, route_info_doc: true do + get_with_auth '/repp/v1/accounts/balance', {}, @api_user + response.status.should == 200 - log = ApiLog::ReppLog.last - log[:request_path].should == '/repp/v1/accounts/balance' - log[:request_method].should == 'GET' - log[:request_params].should == '{}' - log[:response_code].should == '200' - log[:api_user_name].should == 'gitlab' - log[:api_user_registrar].should == 'registrar1' - log[:ip].should == '127.0.0.1' + body = JSON.parse(response.body) + body['balance'].should == '324.45' + body['currency'].should == 'EUR' + + log = ApiLog::ReppLog.last + log[:request_path].should == '/repp/v1/accounts/balance' + log[:request_method].should == 'GET' + log[:request_params].should == '{}' + log[:response_code].should == '200' + log[:api_user_name].should == 'gitlab' + log[:api_user_registrar].should == 'registrar1' + log[:ip].should == '127.0.0.1' + end end end end