protected Authenticator getAuthenticator(final String name) { if (AUTHENTICATOR_TEST_TOKEN.equals(name)) { return new SimpleTestTokenAuthenticator(); } else if (AUTHENTICATOR_TEST_USERNAME_PASSWORD.equals(name)) { return new SimpleTestUsernamePasswordAuthenticator(); } else { return authenticators.get(name); } } }
@Test public void testHasDefaultProfileCreator() { final IpClient client = new IpClient(new SimpleTestTokenAuthenticator()); client.init(); }
@Test public void testHasDefaultProfileCreator() { final HeaderClient client = new HeaderClient(HEADER_NAME, new SimpleTestTokenAuthenticator()); client.init(); }
@Test public void testMissingParameterName() { final ParameterClient client = new ParameterClient(null, new SimpleTestTokenAuthenticator()); TestsHelper.initShouldFail(client, "parameterName cannot be blank"); }
@Test public void testHasDefaultProfileCreator() { final DirectBearerAuthClient bearerAuthClient = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator()); bearerAuthClient.init(); }
@Test public void testMissingHeaderName() { final HeaderClient client = new HeaderClient(null, new SimpleTestTokenAuthenticator()); TestsHelper.initShouldFail(client, "headerName cannot be blank"); }
@Test public void testHasDefaultProfileCreator() { final DirectDigestAuthClient digestAuthClient = new DirectDigestAuthClient(new SimpleTestTokenAuthenticator()); digestAuthClient.init(); }
@Test public void testHasDefaultProfileCreator() { final CookieClient cookieClient = new CookieClient("testcookie", new SimpleTestTokenAuthenticator()); cookieClient.init(); }
@Test(expected=Exception.class) public void testMissingCookieName() { final CookieClient cookieClient = new CookieClient(null, new SimpleTestTokenAuthenticator()); cookieClient.init(); }
@Test public void testHasDefaultProfileCreator() { final ParameterClient client = new ParameterClient(null, new SimpleTestTokenAuthenticator()); client.setParameterName(PARAMETER_NAME); client.init(); }
@Test public void testAuthentication() { final CookieClient client = new CookieClient(USERNAME, new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); final Cookie c = new Cookie(USERNAME, Base64.getEncoder().encodeToString(getClass().getName().getBytes(StandardCharsets.UTF_8))); context.getRequestCookies().add(c); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(c.getValue(), profile.getId()); } }
@Test public void testMissingProfileCreator() { final ParameterClient client = new ParameterClient(PARAMETER_NAME, new SimpleTestTokenAuthenticator(), null); TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final DirectBearerAuthClient bearerAuthClient = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator(), null); TestsHelper.expectException(() -> bearerAuthClient.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final DirectDigestAuthClient digestAuthClient = new DirectDigestAuthClient(new SimpleTestTokenAuthenticator(), null); TestsHelper.expectException(() -> digestAuthClient.getUserProfile(new DigestCredentials(TOKEN, HTTP_METHOD.POST.name(), null, null, null, null, null, null, null), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final HeaderClient client = new HeaderClient(NAME, new SimpleTestTokenAuthenticator()); client.setProfileCreator(null); TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final IpClient client = new IpClient(new SimpleTestTokenAuthenticator()); client.setProfileCreator(null); TestsHelper.expectException(() -> client.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testMissingProfileCreator() { final CookieClient cookieClient = new CookieClient("testcookie", new SimpleTestTokenAuthenticator()); cookieClient.setProfileCreator(null); TestsHelper.expectException(() -> cookieClient.getUserProfile(new TokenCredentials(TOKEN), MockWebContext.create()), TechnicalException.class, "profileCreator cannot be null"); }
@Test public void testAuthentication() { final DirectBearerAuthClient client = new DirectBearerAuthClient(new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, HttpConstants.BEARER_HEADER_PREFIX + TOKEN); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = (CommonProfile) client.getUserProfile(credentials, context); assertEquals(TOKEN, profile.getId()); }
@Test public void testAuthentication() { final IpClient client = new IpClient(new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); context.setRemoteAddress(IP); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(IP, profile.getId()); } }
@Test public void testAuthentication() { final HeaderClient client = new HeaderClient(HEADER_NAME, PREFIX_HEADER, new SimpleTestTokenAuthenticator()); final MockWebContext context = MockWebContext.create(); context.addRequestHeader(HEADER_NAME, PREFIX_HEADER + VALUE); final TokenCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(VALUE, profile.getId()); } }