2011-09-08 17:25:22 -04:00
|
|
|
require 'spec'
|
|
|
|
require 'spec/mocks'
|
|
|
|
|
2011-02-07 22:12:56 -05:00
|
|
|
Shindo.tests('Dynect::dns | DNS requests', ['dynect', 'dns']) do
|
2011-07-14 20:22:43 -04:00
|
|
|
|
|
|
|
shared_format = {
|
|
|
|
'job_id' => Integer,
|
|
|
|
'msgs' => [{
|
|
|
|
'ERR_CD' => Fog::Nullable::String,
|
|
|
|
'INFO' => String,
|
|
|
|
'LVL' => String,
|
|
|
|
'SOURCE' => String
|
|
|
|
}],
|
|
|
|
'status' => String
|
|
|
|
}
|
|
|
|
|
2011-02-08 22:03:06 -05:00
|
|
|
tests "success" do
|
2011-07-14 20:22:43 -04:00
|
|
|
|
|
|
|
@dns = Fog::DNS[:dynect]
|
|
|
|
@domain = generate_unique_domain
|
|
|
|
@fqdn = "www.#{@domain}"
|
|
|
|
|
|
|
|
post_session_format = shared_format.merge({
|
|
|
|
'data' => {
|
|
|
|
'token' => String,
|
|
|
|
'version' => String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("post_session").formats(post_session_format) do
|
|
|
|
@dns.post_session.body
|
|
|
|
end
|
|
|
|
|
|
|
|
post_zone_format = shared_format.merge({
|
|
|
|
'data' => {
|
|
|
|
'serial' => Integer,
|
|
|
|
'zone' => String,
|
|
|
|
'zone_type' => String,
|
|
|
|
'serial_style' => String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("post_zone('netops@#{@domain}', 3600, '#{@domain}')").formats(post_zone_format) do
|
|
|
|
@dns.post_zone("netops@#{@domain}", 3600, @domain).body
|
|
|
|
end
|
|
|
|
|
|
|
|
get_zones_format = shared_format.merge({
|
|
|
|
'data' => [String]
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("get_zone").formats(get_zones_format) do
|
|
|
|
@dns.get_zone.body
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
get_zone_format = shared_format.merge({
|
|
|
|
'data' => {
|
|
|
|
"serial" => Integer,
|
|
|
|
"serial_style" => String,
|
|
|
|
"zone" => String,
|
|
|
|
"zone_type" => String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("get_zone('zone' => '#{@domain}')").formats(get_zone_format) do
|
|
|
|
@dns.get_zone('zone' => @domain).body
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
post_record_format = shared_format.merge({
|
|
|
|
'data' => {
|
|
|
|
'fqdn' => String,
|
|
|
|
'rdata' => {
|
|
|
|
'address' => String
|
|
|
|
},
|
|
|
|
'record_id' => Integer,
|
|
|
|
'record_type' => String,
|
|
|
|
'ttl' => Integer,
|
|
|
|
'zone' => String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("post_record('A', '#{@domain}', '#{@fqdn}', 'address' => '1.2.3.4')").formats(post_record_format) do
|
2011-09-03 16:41:53 -04:00
|
|
|
@dns.post_record('A', @domain, @fqdn, {'address' => '1.2.3.4'}).body
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|
2011-02-08 21:47:44 -05:00
|
|
|
|
2011-08-30 12:58:26 -04:00
|
|
|
publish_zone_format = shared_format.merge({
|
2011-07-14 20:22:43 -04:00
|
|
|
'data' => {
|
|
|
|
'serial' => Integer,
|
|
|
|
'serial_style' => String,
|
|
|
|
'zone' => String,
|
|
|
|
'zone_type' => String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2011-08-30 12:58:26 -04:00
|
|
|
tests("put_zone('#{@domain}', 'publish' => true)").formats(publish_zone_format) do
|
|
|
|
@dns.put_zone(@domain, 'publish' => true).body
|
|
|
|
end
|
|
|
|
|
|
|
|
freeze_zone_format = shared_format.merge({
|
|
|
|
'data' => {}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("put_zone('#{@domain}', 'freeze' => true)").formats(freeze_zone_format) do
|
|
|
|
@dns.put_zone(@domain, 'freeze' => true).body
|
|
|
|
end
|
|
|
|
|
|
|
|
thaw_zone_format = shared_format.merge({
|
|
|
|
'data' => {}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("put_zone('#{@domain}', 'thaw' => true)").formats(thaw_zone_format) do
|
|
|
|
@dns.put_zone(@domain, 'thaw' => true).body
|
2011-02-08 21:47:44 -05:00
|
|
|
end
|
2011-06-16 17:51:13 -04:00
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
get_node_list_format = shared_format.merge({
|
|
|
|
'data' => [String]
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("get_node_list('#{@domain}')").formats(get_node_list_format) do
|
|
|
|
@dns.get_node_list(@domain).body
|
2011-06-17 06:17:02 -04:00
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
get_records_format = shared_format.merge({
|
|
|
|
'data' => [String]
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("get_record('A', '#{@domain}', '#{@fqdn}')").formats(get_records_format) do
|
|
|
|
data = @dns.get_record('A', @domain, @fqdn).body
|
|
|
|
@record_id = data['data'].first.split('/').last
|
|
|
|
data
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
|
|
|
|
2011-09-08 17:25:22 -04:00
|
|
|
sleep 5 unless Fog.mocking?
|
2011-09-03 16:41:53 -04:00
|
|
|
|
|
|
|
@dns.post_record('CNAME', @domain, "cname.#{@fqdn}", {'cname' => "#{@fqdn}."})
|
2011-09-01 19:11:14 -04:00
|
|
|
|
2011-09-03 16:41:53 -04:00
|
|
|
tests("get_record('ANY', '#{@domain}', 'cname.#{@fqdn}')").formats(get_records_format) do
|
|
|
|
@dns.get_record('ANY', @domain, "cname.#{@fqdn}").body
|
2011-09-01 19:11:14 -04:00
|
|
|
end
|
|
|
|
|
2011-08-30 12:40:43 -04:00
|
|
|
get_record_format = shared_format.merge({
|
|
|
|
'data' => {
|
|
|
|
'zone' => String,
|
|
|
|
'ttl' => Integer,
|
|
|
|
'fqdn' => String,
|
|
|
|
'record_type' => String,
|
|
|
|
'rdata' => {
|
|
|
|
'address' => String
|
|
|
|
},
|
|
|
|
'record_id' => Integer
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("get_record('A', '#{@domain}', '#{@fqdn}', 'record_id' => '#{@record_id}')").formats(get_record_format) do
|
|
|
|
@dns.get_record('A', @domain, @fqdn, 'record_id' => @record_id).body
|
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
delete_record_format = shared_format.merge({
|
|
|
|
'data' => {}
|
|
|
|
})
|
|
|
|
|
|
|
|
tests("delete_record('A', '#{@domain}', '#{@fqdn}', '#{@record_id}')").formats(delete_record_format) do
|
|
|
|
@dns.delete_record('A', @domain, "#{@fqdn}", @record_id).body
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
delete_zone_format = shared_format.merge({
|
|
|
|
'data' => {}
|
|
|
|
})
|
|
|
|
|
2011-09-08 17:25:22 -04:00
|
|
|
sleep 5 unless Fog.mocking?
|
2011-09-01 13:19:06 -04:00
|
|
|
|
2011-07-14 20:22:43 -04:00
|
|
|
tests("delete_zone('#{@domain}')").formats(delete_zone_format) do
|
|
|
|
@dns.delete_zone(@domain).body
|
2011-06-19 04:09:58 -04:00
|
|
|
end
|
2012-08-03 12:20:30 -04:00
|
|
|
|
|
|
|
tests("job handling") do
|
|
|
|
pending unless Fog.mocking?
|
|
|
|
|
|
|
|
old_mock_value = Excon.defaults[:mock]
|
|
|
|
Excon.stubs.clear
|
|
|
|
|
2012-08-13 10:13:52 -04:00
|
|
|
tests("returns final response from a complete job") do
|
|
|
|
begin
|
|
|
|
Excon.defaults[:mock] = true
|
2012-08-03 12:20:30 -04:00
|
|
|
|
2012-08-13 10:13:52 -04:00
|
|
|
Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
|
2012-08-03 12:20:30 -04:00
|
|
|
|
2012-08-13 10:13:52 -04:00
|
|
|
Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
|
|
|
|
Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 307, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
|
2012-08-03 12:20:30 -04:00
|
|
|
|
2012-08-13 10:13:52 -04:00
|
|
|
Fog::DNS::Dynect::Real.new.request(:method => :get, :path => "Zone/example.com").body.should == { "status" => "success" }
|
|
|
|
ensure
|
|
|
|
Excon.stubs.clear
|
|
|
|
Excon.defaults[:mock] = old_mock_value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tests("passes expects through when polling a job") do
|
|
|
|
begin
|
|
|
|
Excon.defaults[:mock] = true
|
|
|
|
|
|
|
|
Excon.stub({:method => :post, :path => "/REST/Session"}, {:body=>"{\"status\": \"success\", \"data\": {\"token\": \"foobar\", \"version\": \"2.3.1\"}, \"job_id\": 150583906, \"msgs\": [{\"INFO\": \"login: Login successful\", \"SOURCE\": \"BLL\", \"ERR_CD\": null, \"LVL\": \"INFO\"}]}", :headers=>{"Content-Type"=>"application/json"}, :status=>200})
|
|
|
|
|
|
|
|
Excon.stub({:method => :get, :path => "/REST/Zone/example.com"}, {:status => 307, :body => '/REST/Job/150576635', :headers => {'Content-Type' => 'text/html', 'Location' => '/REST/Job/150576635'}})
|
|
|
|
Excon.stub({:method => :get, :path => "/REST/Job/150576635"}, {:status => 404, :body => '{"status":"success"}', :headers => {'Content-Type' => 'application/json'}})
|
|
|
|
|
|
|
|
Fog::DNS::Dynect::Real.new.request(:method => :get, :expects => 404, :path => "Zone/example.com").body.should == { "status" => "success" }
|
|
|
|
ensure
|
|
|
|
Excon.stubs.clear
|
|
|
|
Excon.defaults[:mock] = old_mock_value
|
|
|
|
end
|
2012-08-03 12:20:30 -04:00
|
|
|
end
|
|
|
|
end
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|
2011-09-08 17:25:22 -04:00
|
|
|
|
|
|
|
tests('failure') do
|
2011-09-09 14:36:28 -04:00
|
|
|
tests("#auth_token with expired credentials").raises(Excon::Errors::BadRequest) do
|
2011-09-08 17:25:22 -04:00
|
|
|
pending if Fog.mocking?
|
|
|
|
@dns = Fog::DNS[:dynect]
|
|
|
|
@dns.instance_variable_get(:@connection).stub(:request) { raise Excon::Errors::BadRequest.new('Expected(200) <=> Actual(400 Bad Request) request => {:headers=>{"Content-Type"=>"application/json", "API-Version"=>"2.3.1", "Auth-Token"=>"auth-token", "Host"=>"api2.dynect.net:443", "Content-Length"=>0}, :host=>"api2.dynect.net", :mock=>nil, :path=>"/REST/CNAMERecord/domain.com/www.domain.com", :port=>"443", :query=>nil, :scheme=>"https", :expects=>200, :method=>:get} response => #<Excon::Response:0x00000008478b98 @body="{"status": "failure", "data": {}, "job_id": 21326025, "msgs": [{"INFO": "login: Bad or expired credentials", "SOURCE": "BLL", "ERR_CD": "INVALID_DATA", "LVL": "ERROR"}, {"INFO": "login: There was a problem with your credentials", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]}", @headers={"Server"=>"nginx/0.7.67", "Date"=>"Thu, 08 Sep 2011 20:04:21 GMT", "Content-Type"=>"application/json", "Transfer-Encoding"=>"chunked", "Connection"=>"keep-alive"}, @status=400>') }
|
|
|
|
@dns.instance_variable_get(:@connection).should_receive(:request).exactly(2).times
|
|
|
|
@dns.auth_token
|
|
|
|
end
|
2011-09-09 14:36:28 -04:00
|
|
|
|
|
|
|
tests("#auth_token with inactivity logout").raises(Excon::Errors::BadRequest) do
|
|
|
|
pending if Fog.mocking?
|
|
|
|
@dns = Fog::DNS[:dynect]
|
|
|
|
@dns.instance_variable_get(:@connection).stub(:request) { raise Excon::Errors::BadRequest.new('Expected(200) <=> Actual(400 Bad Request) request => {:headers=>{"Content-Type"=>"application/json", "API-Version"=>"2.3.1", "Auth-Token"=>"auth-token", "Host"=>"api2.dynect.net:443", "Content-Length"=>0}, :host=>"api2.dynect.net", :mock=>nil, :path=>"/REST/CNAMERecord/domain.com/www.domain.com", :port=>"443", :query=>nil, :scheme=>"https", :expects=>200, :method=>:get} response => #<Excon::Response:0x00000008478b98 @body="{"status": "failure", "data": {}, "job_id": 21326025, "msgs": [{"INFO": "login: inactivity logout", "SOURCE": "BLL", "ERR_CD": "INVALID_DATA", "LVL": "ERROR"}, {"INFO": "login: There was a problem with your credentials", "SOURCE": "BLL", "ERR_CD": null, "LVL": "INFO"}]}", @headers={"Server"=>"nginx/0.7.67", "Date"=>"Thu, 08 Sep 2011 20:04:21 GMT", "Content-Type"=>"application/json", "Transfer-Encoding"=>"chunked", "Connection"=>"keep-alive"}, @status=400>') }
|
|
|
|
@dns.instance_variable_get(:@connection).should_receive(:request).exactly(2).times
|
|
|
|
@dns.auth_token
|
|
|
|
end
|
2011-09-08 17:25:22 -04:00
|
|
|
end
|
2011-02-07 22:12:56 -05:00
|
|
|
end
|