mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 08:22:05 +02:00
parent
3cca4c78cc
commit
c88d21ab1d
55 changed files with 16 additions and 7287 deletions
|
@ -1,20 +0,0 @@
|
|||
<%# coding: UTF-8 -%>
|
||||
## <%= title %>
|
||||
<%= description %>
|
||||
<% rid = route_info_doc %>
|
||||
<% if rid %>
|
||||
#### Parameters
|
||||
|
||||
<%= rid %>
|
||||
<% end %>
|
||||
#### Request
|
||||
```
|
||||
<%= method %> <%= request.path %><%= request_query %> <%= request_http_version %>
|
||||
<%= request_header %><%= request_body_section %>
|
||||
```
|
||||
|
||||
#### Response
|
||||
```
|
||||
<%= response_http_version %> <%= response.status %>
|
||||
<%= response_header %><%= response_body_section %>
|
||||
```
|
|
@ -1,47 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Repp::AccountV1 do
|
||||
it 'should fail without whitelisted IP' do
|
||||
ENV['webclient_ips'] = '192.188.1.1'
|
||||
Setting.api_ip_whitelist_enabled = true
|
||||
@registrar1 = Fabricate(:registrar, white_ips: [Fabricate(:white_ip_registrar, ipv4: '99.99.99.99')])
|
||||
@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'
|
||||
ENV['webclient_ips'] = '127.0.0.1'
|
||||
Setting.api_ip_whitelist_enabled = false
|
||||
end
|
||||
|
||||
context 'with valid registrar' do
|
||||
before :all do
|
||||
@registrar1 = Fabricate(:registrar1)
|
||||
@registrar1.accounts = [Fabricate(:account, { balance: '324.45', account_activities: [] })]
|
||||
@registrar1.save
|
||||
@api_user = Fabricate(:gitlab_api_user, registrar: @registrar1)
|
||||
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
|
||||
|
||||
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
|
|
@ -1,81 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Repp::ContactV1 do
|
||||
before :all do
|
||||
@api_user = Fabricate(:gitlab_api_user)
|
||||
Fabricate.times(2, :contact, registrar: @api_user.registrar)
|
||||
Fabricate.times(2, :contact)
|
||||
end
|
||||
|
||||
describe 'GET /repp/v1/contacts' do
|
||||
it 'returns contacts of the current registrar', autodoc: true, route_info_doc: true do
|
||||
get_with_auth '/repp/v1/contacts', { limit: 1, details: true }, @api_user
|
||||
expect(response.status).to eq(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
|
||||
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.limit(1).to_json)
|
||||
|
||||
log = ApiLog::ReppLog.last
|
||||
expect(log[:request_path]).to eq('/repp/v1/contacts')
|
||||
expect(log[:request_method]).to eq('GET')
|
||||
expect(log[:request_params]).to eq('{"limit":1,"details":"true"}')
|
||||
expect(log[:response].length).to be > 20
|
||||
expect(log[:response_code]).to eq('200')
|
||||
expect(log[:api_user_name]).to eq('gitlab')
|
||||
expect(log[:ip]).to eq('127.0.0.1')
|
||||
end
|
||||
|
||||
it 'returns contact names with offset', autodoc: true do
|
||||
get_with_auth '/repp/v1/contacts', { offset: 1 }, @api_user
|
||||
expect(response.status).to eq(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
|
||||
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.offset(1).pluck(:code).to_json)
|
||||
|
||||
log = ApiLog::ReppLog.last
|
||||
expect(log[:request_path]).to eq('/repp/v1/contacts')
|
||||
expect(log[:request_method]).to eq('GET')
|
||||
expect(log[:request_params]).to eq('{"offset":1}')
|
||||
expect(log[:response].length).to be > 20
|
||||
expect(log[:response_code]).to eq('200')
|
||||
expect(log[:api_user_name]).to eq('gitlab')
|
||||
expect(log[:ip]).to eq('127.0.0.1')
|
||||
end
|
||||
|
||||
it 'returns contact names of the current registrar' do
|
||||
get_with_auth '/repp/v1/contacts', {}, @api_user
|
||||
expect(response.status).to eq(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
|
||||
expect(body['contacts'].to_json).to eq(@api_user.registrar.contacts.pluck(:code).to_json)
|
||||
|
||||
log = ApiLog::ReppLog.last
|
||||
expect(log[:request_path]).to eq('/repp/v1/contacts')
|
||||
expect(log[:request_method]).to eq('GET')
|
||||
expect(log[:request_params]).to eq('{}')
|
||||
expect(log[:response].length).to be > 20
|
||||
expect(log[:response_code]).to eq('200')
|
||||
expect(log[:api_user_name]).to eq('gitlab')
|
||||
expect(log[:ip]).to eq('127.0.0.1')
|
||||
end
|
||||
|
||||
it 'returns an error with invalid parameters in contact index' do
|
||||
get_with_auth '/repp/v1/contacts', { limit: 0 }, @api_user
|
||||
expect(response.status).to eq(400)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body['error'].should == 'limit does not have a valid value'
|
||||
|
||||
# TODO: Log failed API requests too
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,91 +0,0 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Repp::DomainV1 do
|
||||
before :all do
|
||||
Fabricate(:zonefile_setting, origin: 'ee')
|
||||
@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' do
|
||||
it 'returns domains of the current registrar', autodoc: true, route_info_doc: true do
|
||||
get_with_auth '/repp/v1/domains', { limit: 1, details: true }, @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.limit(1).to_json
|
||||
|
||||
log = ApiLog::ReppLog.last
|
||||
log[:request_path].should == '/repp/v1/domains'
|
||||
log[:request_method].should == 'GET'
|
||||
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 with offset', autodoc: true do
|
||||
get_with_auth '/repp/v1/domains', { offset: 1 }, @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.offset(1).pluck(:name).to_json
|
||||
|
||||
log = ApiLog::ReppLog.last
|
||||
log[:request_path].should == '/repp/v1/domains'
|
||||
log[:request_method].should == 'GET'
|
||||
log[:request_params].should == '{"offset":1}'
|
||||
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'
|
||||
|
||||
# TODO: Log failed API requests too
|
||||
end
|
||||
|
||||
it 'returns an error with invalid credentials' do
|
||||
invalid_user = OpenStruct.new(username: 'bla', password: 'blabala')
|
||||
get_with_auth '/repp/v1/domains', {}, invalid_user
|
||||
response.status.should == 401
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
body['error'].should == 'API user not found'
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue