AuthenticationInfoValidator { public static void validate(AuthenticationInfo info) { LOGGER.info("--- Validating authentication information ---"); LOGGER.info("Authentication information provided: {}", info); if (info == null) { String message = "AuthenticationInfo cannot be null."; LOGGER.error(message); throw new AuthenticationInfoValidationException(message); } checkRequiredParameter(info.getType(), "type"); checkRequiredParameter(info.getUsername(), "username"); checkRequiredParameter(info.getPassword(), "password"); if (info.getType() != AuthenticationType.HTTP) { checkRequiredParameter(info.getLoginUrl(), "loginUrl"); } List<String> warnings = new ArrayList<>(); switch (info.getType()) { case HTTP: validateHttpAuthenticationInfo(info, warnings); break; case FORM: validateFormAuthenticationInfo(info, warnings); break; case CAS: validateCasAuthenticationInfo(info, warnings); break; case SELENIUM: } if (warnings.isEmpty()) { LOGGER.info("The authentication information provided was successfully validated."); } else { LOGGER.warn("Some warnings were generated while validating the authentication information provided:"); for (String warning : warnings) { LOGGER.warn("\t{}", warning); } } LOGGER.info("--- Finished validating authentication information ---\n"); } private  AuthenticationInfoValidator(); static void validate(AuthenticationInfo info);  }
@Test(expectedExceptions = AuthenticationInfoValidationException.class) public void infoMustNotBeNull() { AuthenticationInfoValidator.validate(null); }
@Test(expectedExceptions=AuthenticationInfoValidationException.class) public void protectedPagesMustNotBeVoidInCasAuthentication() { AuthenticationInfo simpleCasInfo = AuthenticationInfo.builder() .loggedOutRegex("loggedOutRegex") .buildCasAuthenticationInfo("loginUrl", "username", "password"); AuthenticationInfoValidator.validate(simpleCasInfo); }
@Test(expectedExceptions = AuthenticationInfoValidationException.class) public void typeMustNotBeNull() { AuthenticationInfoValidator.validate(AuthenticationInfo.builder().build()); }
@Test(expectedExceptions = AuthenticationInfoValidationException.class) public void usernameMustNotBeNull() { AuthenticationInfo info = AuthenticationInfo.builder().type(AuthenticationType.FORM).build(); AuthenticationInfoValidator.validate(info); }
@Test(expectedExceptions = AuthenticationInfoValidationException.class) public void passwordMustNotBeNull() { AuthenticationInfo info = AuthenticationInfo.builder() .type(AuthenticationType.FORM) .username("username") .build(); AuthenticationInfoValidator.validate(info); }
@Test(expectedExceptions = AuthenticationInfoValidationException.class) public void loginUrlMustNotBeNull() { AuthenticationInfo info = AuthenticationInfo.builder() .type(AuthenticationType.FORM) .username("username") .username("password") .build(); AuthenticationInfoValidator.validate(info); }
@Test public void testSimpleFormAuthenticationInfo() { AuthenticationInfo simpleFormInfo = AuthenticationInfo.builder() .loggedInRegex("loggedInRegex") .buildFormAuthenticationInfo("loginUrl", "username", "password"); AuthenticationInfoValidator.validate(simpleFormInfo); assertFalse(appender.hasWarn()); }
@Test public void warningShouldBeGeneratedIfProtectedPageIsNotNullInFormAuthentication() { AuthenticationInfo simpleFormInfo = AuthenticationInfo.builder() .protectedPages("protectedPage") .buildFormAuthenticationInfo("loginUrl", "username", "password"); AuthenticationInfoValidator.validate(simpleFormInfo); assertTrue(appender.hasWarn()); }
@Test public void warningShouldBeGeneratedIfNoReauthenticationIsPossibleInFormAuthentication() { AuthenticationInfo info = AuthenticationInfo.builder() .buildFormAuthenticationInfo("loginUrl", "username", "password"); AuthenticationInfoValidator.validate(info); assertTrue(appender.hasWarn()); }
@Test public void testSimpleCasAuthenticationInfo() { AuthenticationInfo simpleCasInfo = AuthenticationInfo.builder() .loggedOutRegex("loggedOutRegex") .buildCasAuthenticationInfo("loginUrl", "username", "password", "protectedPage"); AuthenticationInfoValidator.validate(simpleCasInfo); assertFalse(appender.hasWarn()); }
@Test public void warningShouldBeGeneratedIfNoReauthenticationIsPossibleInCasAuthentication() { AuthenticationInfo simpleCasInfo = AuthenticationInfo.builder() .buildCasAuthenticationInfo("loginUrl", "username", "password", "protectedPage"); AuthenticationInfoValidator.validate(simpleCasInfo); assertTrue(appender.hasWarn()); }