diff --git a/Gemfile b/Gemfile index 4524ef71c..07594c34c 100644 --- a/Gemfile +++ b/Gemfile @@ -67,7 +67,8 @@ gem 'deep_cloneable', '~> 2.1.1' gem 'digidoc_client', '~> 0.2.1' # epp + repp client -gem 'depp', github: 'domify/depp', ref: '2939cf6a84a115c35cd4f7176a90abdaad0e869f' +gem 'depp', github: 'domify/depp', ref: '2a14f5025f4909e0225d5c30ad4cc0ab81629034' +# gem 'depp', path: '~/projects/depp' gem 'epp', '~> 1.4.2', github: 'gitlabeu/epp' group :development do diff --git a/Gemfile.lock b/Gemfile.lock index 5fcb38938..f783543dd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,8 +10,8 @@ GIT GIT remote: git://github.com/domify/depp.git - revision: 2939cf6a84a115c35cd4f7176a90abdaad0e869f - ref: 2939cf6a84a115c35cd4f7176a90abdaad0e869f + revision: 2a14f5025f4909e0225d5c30ad4cc0ab81629034 + ref: 2a14f5025f4909e0225d5c30ad4cc0ab81629034 specs: depp (0.0.2) coderay (>= 1.1.0) diff --git a/app/api/repp/api.rb b/app/api/repp/api.rb index 9693f5054..95f89f094 100644 --- a/app/api/repp/api.rb +++ b/app/api/repp/api.rb @@ -8,10 +8,10 @@ module Repp end before do - next if Rails.env.test? + next if Rails.env.test? || Rails.env.development? message = 'Certificate mismatch! Cert common name should be:' request_name = env['HTTP_SSL_CLIENT_S_DN_CN'] - + if request.ip == ENV['webclient_ip'] webclient_cert_name = ENV['webclient_cert_common_name'] || 'webclient' error! "Webclient #{message} #{webclient_cert_name}", 401 if webclient_cert_name != request_name diff --git a/app/api/repp/domain_v1.rb b/app/api/repp/domain_v1.rb index 5c9411120..7afb494c6 100644 --- a/app/api/repp/domain_v1.rb +++ b/app/api/repp/domain_v1.rb @@ -4,11 +4,22 @@ module Repp resource :domains do desc 'Return list of domains' + params do + optional :limit, type: Integer, values: (1..20).to_a + end + get '/' do - domains = current_user.registrar.domains.page(params[:page]) + limit = params[:limit] || 20 + + if params[:details] == 'true' + domains = current_user.registrar.domains.limit(limit) + else + domains = current_user.registrar.domains.limit(limit).pluck(:name) + end + @response = { domains: domains, - total_pages: domains.total_pages + total_number_of_records: current_user.registrar.domains.count } end end diff --git a/spec/requests/domain_spec.rb b/spec/requests/domain_spec.rb index 6be5da8f7..97dd58ec5 100644 --- a/spec/requests/domain_spec.rb +++ b/spec/requests/domain_spec.rb @@ -5,25 +5,63 @@ describe Repp::DomainV1 do create_settings @registrar1 = Fabricate(:registrar1) @api_user = Fabricate(:gitlab_api_user, registrar: @registrar1) + Fabricate.times(2, :domain, registrar: @api_user.registrar) end describe 'GET /repp/v1/domains', autodoc: true do it 'returns domains of the current registrar' do - Fabricate.times(2, :domain, registrar: @api_user.registrar) - get_with_auth '/repp/v1/domains', { page: 1 }, @api_user + get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @api_user response.status.should == 200 body = JSON.parse(response.body) - body['total_pages'].should == 1 + body['total_number_of_records'].should == 2 # TODO: Maybe there is a way not to convert from and to json again - body['domains'].to_json.should == @api_user.reload.registrar.domains.to_json + body['domains'].to_json.should == @api_user.reload.registrar.domains.limit(1).to_json log = ApiLog::ReppLog.last log[:request_path].should == '/repp/v1/domains' log[:request_method].should == 'GET' - log[:request_params].should == '{"page":"1"}' + log[:request_params].should == '{"limit":1,"details":"true"}' + 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 + + it 'returns domain names of the current registrar' do + + get_with_auth '/repp/v1/domains', {}, @api_user + response.status.should == 200 + + body = JSON.parse(response.body) + body['total_number_of_records'].should == 2 + + # TODO: Maybe there is a way not to convert from and to json again + body['domains'].to_json.should == @api_user.reload.registrar.domains.pluck(:name).to_json + + log = ApiLog::ReppLog.last + log[:request_path].should == '/repp/v1/domains' + 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 + + it 'returns an error with invalid parameters in domain index' do + get_with_auth '/repp/v1/domains', { limit: 0 }, @api_user + response.status.should == 400 + + body = JSON.parse(response.body) + body['error'].should == 'limit does not have a valid value' + + log = ApiLog::ReppLog.last + log[:request_path].should == '/repp/v1/domains' + 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'