mirror of
https://github.com/internetee/registry.git
synced 2025-06-07 21:25:39 +02:00
parent
3ef38768a5
commit
a5eaae562a
4 changed files with 62 additions and 2 deletions
|
@ -58,5 +58,6 @@ module Repp
|
||||||
mount Repp::ContactV1
|
mount Repp::ContactV1
|
||||||
mount Repp::AccountV1
|
mount Repp::AccountV1
|
||||||
mount Repp::DomainTransfersV1
|
mount Repp::DomainTransfersV1
|
||||||
|
mount Repp::NameserversV1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
30
app/api/repp/nameservers_v1.rb
Normal file
30
app/api/repp/nameservers_v1.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
module Repp
|
||||||
|
class NameserversV1 < Grape::API
|
||||||
|
version 'v1', using: :path
|
||||||
|
|
||||||
|
resource :nameservers do
|
||||||
|
put '/' do
|
||||||
|
params do
|
||||||
|
requires :data, type: Hash do
|
||||||
|
requires :type, type: String, allow_blank: false
|
||||||
|
requires :id, type: String, allow_blank: false
|
||||||
|
requires :attributes, type: Hash do
|
||||||
|
requires :hostname, type: String, allow_blank: false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
current_user.registrar.nameservers.where(hostname: params[:data][:id]).each do |nameserver|
|
||||||
|
nameserver.hostname = params[:data][:attributes][:hostname]
|
||||||
|
nameserver.ipv4 = params[:data][:attributes][:ipv4]
|
||||||
|
nameserver.ipv6 = params[:data][:attributes][:ipv6]
|
||||||
|
nameserver.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
status 204
|
||||||
|
body false
|
||||||
|
@response = {}
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
4
test/fixtures/nameservers.yml
vendored
4
test/fixtures/nameservers.yml
vendored
|
@ -3,7 +3,7 @@ ns1:
|
||||||
ipv4:
|
ipv4:
|
||||||
- 192.0.2.1
|
- 192.0.2.1
|
||||||
ipv6:
|
ipv6:
|
||||||
- 2001:DB8::1
|
- 2001:db8::1
|
||||||
domain: shop
|
domain: shop
|
||||||
|
|
||||||
ns2:
|
ns2:
|
||||||
|
@ -11,5 +11,5 @@ ns2:
|
||||||
ipv4:
|
ipv4:
|
||||||
- 192.0.2.2
|
- 192.0.2.2
|
||||||
ipv6:
|
ipv6:
|
||||||
- 2001:DB8::2
|
- 2001:db8::2
|
||||||
domain: shop
|
domain: shop
|
||||||
|
|
29
test/integration/api/nameservers/put_nameservers_test.rb
Normal file
29
test/integration/api/nameservers/put_nameservers_test.rb
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
require 'test_helper'
|
||||||
|
|
||||||
|
class APIPutNameserversTest < ActionDispatch::IntegrationTest
|
||||||
|
def test_changes_nameservers_of_all_domains_of_current_registrar
|
||||||
|
ns2 = domains(:shop).nameservers.find_by(hostname: 'ns2.bestnames.test')
|
||||||
|
request_params = { format: :json, data: { type: 'nameservers', id: 'ns2.bestnames.test',
|
||||||
|
attributes: { hostname: 'ns3.bestnames.test',
|
||||||
|
ipv4: ['192.0.2.3'],
|
||||||
|
ipv6: ['2001:DB8::3'] } } }
|
||||||
|
put '/repp/v1/nameservers', request_params, { 'HTTP_AUTHORIZATION' => http_auth_key }
|
||||||
|
ns2.reload
|
||||||
|
assert_equal 'ns3.bestnames.test', ns2.hostname
|
||||||
|
assert_equal ['192.0.2.3'], ns2.ipv4
|
||||||
|
assert_equal ['2001:DB8::3'], ns2.ipv6
|
||||||
|
assert_response 204
|
||||||
|
assert_empty response.body
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_unauthenticated
|
||||||
|
put '/repp/v1/nameservers'
|
||||||
|
assert_response 401
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def http_auth_key
|
||||||
|
ActionController::HttpAuthentication::Basic.encode_credentials('test_bestnames', 'testtest')
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue