Allow TLD test with port in Notification Webhook Address

To allow notification webhooks to access the Top Level Domain (TLD) of test,
the validation of Webhook addresses was changed to allow urls of the form
http://test.test.  However, the validation incorrectly rejects urls with
a port, for example, http://test.test:4343

Changed the regular expression to handle the optional port. I think the
UrlValidator should have stripped it off before presenting it to
the validator, but it doesn't so the regular expression has to handle the
port

Added tempest test to verify API works with a TLD of test with and without
port

Change-Id: Ie95b4ec3c13f3f6b54aab390e234227bc81d8be9
Closes-bug: 1597070
This commit is contained in:
Craig Bryant 2016-06-28 14:24:27 -06:00
parent e214ae5ebe
commit b50b87af51
3 changed files with 61 additions and 1 deletions

View File

@ -25,7 +25,8 @@ import java.util.List;
public class NotificationMethodValidation {
private static final String[] SCHEMES = {"http","https"};
// Allow QA to use the TLD .test. This is valid according to RFC-2606
private static final RegexValidator TEST_TLD_VALIDATOR = new RegexValidator(".+\\.test$");
// The UrlValidator does not take the port off of the authority so have to handle that
private static final RegexValidator TEST_TLD_VALIDATOR = new RegexValidator(".+\\.test(:[0-9]+)?$");
private static final UrlValidator URL_VALIDATOR =
new UrlValidator(SCHEMES,
TEST_TLD_VALIDATOR,

View File

@ -124,6 +124,33 @@ public class CreateNotificationMethodTest extends AbstractModelTest {
newNotificationMethod.validate(validPeriods);
}
public void testValidationTestDomainWithPortForWebhook() {
CreateNotificationMethodCommand newNotificationMethod =
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.test:4522", "60");
newNotificationMethod.validate(validPeriods);
}
@Test(expectedExceptions = WebApplicationException.class)
public void testValidationInvalidTestDomainForWebhook() {
CreateNotificationMethodCommand newNotificationMethod =
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.invalid:4522", "60");
newNotificationMethod.validate(validPeriods);
}
@Test(expectedExceptions = WebApplicationException.class)
public void testValidationTestDomainWithInvalidPortForWebhook() {
CreateNotificationMethodCommand newNotificationMethod =
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.test:4522AA/mywebhook", "60");
newNotificationMethod.validate(validPeriods);
}
@Test(expectedExceptions = WebApplicationException.class)
public void testValidationTestDomainWithInvalidMultiplePortsForWebhook() {
CreateNotificationMethodCommand newNotificationMethod =
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.test:4522:33/mywebhook", "60");
newNotificationMethod.validate(validPeriods);
}
@Test(expectedExceptions = WebApplicationException.class)
public void testValidationInvalidDomainForWebhook() {
CreateNotificationMethodCommand newNotificationMethod =

View File

@ -76,6 +76,38 @@ class TestNotificationMethods(base.BaseMonascaTest):
delete_notification_method(id)
self.assertEqual(204, resp.status)
@test.attr(type="gate")
def test_create_notification_method_webhook_test_tld(self):
name = data_utils.rand_name('notification-')
notification = helpers.create_notification(name=name,
type='WEBHOOK',
address='http://mytest.test/webhook',
period=60)
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_test_tld_and_port(self):
name = data_utils.rand_name('notification-')
notification = helpers.create_notification(name=name,
type='WEBHOOK',
address='http://mytest.test:4533/webhook',
period=60)
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_no_name(self):