From 53c1220068fc54110e8028eb5c6656864efa8a6e Mon Sep 17 00:00:00 2001 From: Michael James Hoppal Date: Mon, 15 Aug 2016 13:16:41 -0600 Subject: [PATCH] Add tests for invalid webhook and email addresses This includes passing the type as not all upper case Change-Id: I9d4690dc01bd3e911743f558cf2536222c944fcc --- .../tests/api/test_notification_methods.py | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/monasca_tempest_tests/tests/api/test_notification_methods.py b/monasca_tempest_tests/tests/api/test_notification_methods.py index 6fe0c3a..d316a7e 100644 --- a/monasca_tempest_tests/tests/api/test_notification_methods.py +++ b/monasca_tempest_tests/tests/api/test_notification_methods.py @@ -48,6 +48,32 @@ class TestNotificationMethods(base.BaseMonascaTest): delete_notification_method(id) self.assertEqual(204, resp.status) + @test.attr(type="gate") + def test_create_email_notification_method_with_lower_case_type(self): + notification = helpers.create_notification(name='lower case email notification', + type='email') + resp, response_body = self.monasca_client.create_notifications( + notification) + self.assertEqual(201, resp.status) + id = response_body['id'] + + resp, response_body = self.monasca_client.\ + delete_notification_method(id) + self.assertEqual(204, resp.status) + + @test.attr(type="gate") + def test_create_email_notification_method_with_mixed_case_type(self): + notification = helpers.create_notification(name='mixed case email notification', + type='EmAil') + resp, response_body = self.monasca_client.create_notifications( + notification) + self.assertEqual(201, resp.status) + id = response_body['id'] + + resp, response_body = self.monasca_client.\ + delete_notification_method(id) + self.assertEqual(204, resp.status) + @test.attr(type="gate") def test_create_notification_method_period_not_defined(self): notification = helpers.create_notification(period=None) @@ -151,6 +177,96 @@ class TestNotificationMethods(base.BaseMonascaTest): self.monasca_client.create_notifications, notification) + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_email_address(self): + notification = helpers.create_notification(address="name@") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_scheme_webhook(self): + notification = helpers.create_notification(type="WEBHOOK", + address="ftp://localhost") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_webhook_address(self): + notification = helpers.create_notification(type="WEBHOOK", + address="localhost:123") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + # The below tests are making sure that we accept passing in case insensitive types and that we still validate the + # address if the types are case insensitive + @test.attr(type="gate") + def test_create_notification_method_webhook_with_lower_case_type(self): + notification = helpers.create_notification(type='webhook', + address='http://mytest.test:4533') + resp, response_body = self.monasca_client.create_notifications( + notification) + self.assertEqual(201, resp.status) + id = response_body['id'] + + resp, response_body = self.monasca_client.\ + delete_notification_method(id) + self.assertEqual(204, resp.status) + + @test.attr(type="gate") + def test_create_notification_method_webhook_with_mixed_case_type(self): + notification = helpers.create_notification(type='webHooK', + address='http://mytest.test:4533') + resp, response_body = self.monasca_client.create_notifications( + notification) + self.assertEqual(201, resp.status) + id = response_body['id'] + + resp, response_body = self.monasca_client.\ + delete_notification_method(id) + self.assertEqual(204, resp.status) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_email_address_type_all_lower_case(self): + notification = helpers.create_notification(type="email", + address="name@") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_email_address_type_all_mixed_case(self): + notification = helpers.create_notification(type="EmAil", + address="name@") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_webhook_address_type_mixed_case(self): + notification = helpers.create_notification(type="WebHook", + address="localhost:123") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + + @test.attr(type="gate") + @test.attr(type=['negative']) + def test_create_notification_method_with_invalid_webhook_address_type_lower_case(self): + notification = helpers.create_notification(type="webhook", + address="localhost:123") + self.assertRaises((exceptions.BadRequest, exceptions.UnprocessableEntity), + self.monasca_client.create_notifications, + notification) + @test.attr(type="gate") @test.attr(type=['negative']) def test_create_notification_method_with_invalid_type(self):