From cfa9177af1f8291536f5f50a9a6da7435bd02e6f Mon Sep 17 00:00:00 2001 From: soh_cah_toa Date: Thu, 6 Jun 2013 23:58:12 -0400 Subject: [PATCH] Added 4 new tests for bad POST /api/dns/rule requests. --- test/integration/tc_dns_rest.rb | 46 ++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/test/integration/tc_dns_rest.rb b/test/integration/tc_dns_rest.rb index 3e5eda166..898d2f16a 100644 --- a/test/integration/tc_dns_rest.rb +++ b/test/integration/tc_dns_rest.rb @@ -26,7 +26,7 @@ class TC_DnsRest < Test::Unit::TestCase end - def test_1_add_rule + def test_1_add_rule_good pattern = 'foo.bar' type = 'A' dns_response = ['1.2.3.4'] @@ -46,4 +46,48 @@ class TC_DnsRest < Test::Unit::TestCase assert(result['id']) end + def test_2_add_rule_bad + pattern = '' + type = 'A' + dns_response = ['1.1.1.1'] + + hash = {:pattern => pattern, :type => type, :response => dns_response} + + # Test that an empty "pattern" key returns 400 + assert_raise RestClient::BadRequest do + rest_response = RestClient.post("#{RESTAPI_DNS}/rule?token=#{@@token}", + hash.to_json, + @@headers) + end + + hash['pattern'] = 'foo.bar.baz' + hash['type'] = '' + + # Test that an empty "type" key returns 400 + assert_raise RestClient::BadRequest do + rest_response = RestClient.post("#{RESTAPI_DNS}/rule?token=#{@@token}", + hash.to_json, + @@headers) + end + + hash['type'] = 'A' + hash['response'] = [] + + # Test that an empty "response" key returns 400 + assert_raise RestClient::BadRequest do + rest_response = RestClient.post("#{RESTAPI_DNS}/rule?token=#{@@token}", + hash.to_json, + @@headers) + end + + hash['response'] = 42 + + # Test that a non-array "response" key returns 400 + assert_raise RestClient::BadRequest do + rest_response = RestClient.post("#{RESTAPI_DNS}/rule?token=#{@@token}", + hash.to_json, + @@headers) + end + end + end