Allow QA teams to use the Top Level Domain .test
QA teams have requested the ability to use the Top Level Domain (TLD) .test for webhook testing. Using .test is valid according to RFC-2606 but the Apache URL Validator does not allow it. Add an override for the .test TLD. Change-Id: Ie5801d0a84199a84b7121b002bda5398cfec3b89
This commit is contained in:
parent
f562aad151
commit
6f0c3b2da9
|
@ -17,11 +17,19 @@ import monasca.api.domain.model.notificationmethod.NotificationMethodType;
|
|||
import monasca.api.resource.exception.Exceptions;
|
||||
|
||||
import org.apache.commons.validator.routines.EmailValidator;
|
||||
import org.apache.commons.validator.routines.RegexValidator;
|
||||
import org.apache.commons.validator.routines.UrlValidator;
|
||||
|
||||
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$");
|
||||
private static final UrlValidator URL_VALIDATOR =
|
||||
new UrlValidator(SCHEMES,
|
||||
TEST_TLD_VALIDATOR,
|
||||
UrlValidator.ALLOW_LOCAL_URLS | UrlValidator.ALLOW_2_SLASHES);
|
||||
|
||||
public static void validate(NotificationMethodType type, String address, String period,
|
||||
List<Integer> validPeriods) {
|
||||
|
@ -34,9 +42,7 @@ public class NotificationMethodValidation {
|
|||
throw Exceptions.unprocessableEntity("Period can not be non zero for Email");
|
||||
} break;
|
||||
case WEBHOOK : {
|
||||
String[] schemes = {"http","https"};
|
||||
UrlValidator urlValidator = new UrlValidator(schemes, UrlValidator.ALLOW_LOCAL_URLS | UrlValidator.ALLOW_2_SLASHES);
|
||||
if (!urlValidator.isValid(address))
|
||||
if (!URL_VALIDATOR.isValid(address))
|
||||
throw Exceptions.unprocessableEntity("Address %s is not of correct format", address);
|
||||
} break;
|
||||
case PAGERDUTY : {
|
||||
|
|
|
@ -118,6 +118,19 @@ public class CreateNotificationMethodTest extends AbstractModelTest {
|
|||
newNotificationMethod.validate(validPeriods);
|
||||
}
|
||||
|
||||
public void testValidationTestDomainForWebhook() {
|
||||
CreateNotificationMethodCommand newNotificationMethod =
|
||||
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.test", "60");
|
||||
newNotificationMethod.validate(validPeriods);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = WebApplicationException.class)
|
||||
public void testValidationInvalidDomainForWebhook() {
|
||||
CreateNotificationMethodCommand newNotificationMethod =
|
||||
new CreateNotificationMethodCommand("MyWebhook", NotificationMethodType.WEBHOOK, "http://test.fred", "60");
|
||||
newNotificationMethod.validate(validPeriods);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = WebApplicationException.class)
|
||||
public void testValidationExceptionForWebhook() throws Exception {
|
||||
CreateNotificationMethodCommand newNotificationMethod =
|
||||
|
|
Loading…
Reference in New Issue