Refine search
@Test public void testMissingUsernamePasswordAuthenticator() { final IndirectBasicAuthClient basicAuthClient = new IndirectBasicAuthClient(NAME, null); basicAuthClient.setCallbackUrl(CALLBACK_URL); TestsHelper.expectException(() -> basicAuthClient.getCredentials(MockWebContext.create()), TechnicalException.class, "authenticator cannot be null"); }
@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 testParsingError() { final RestAuthenticator authenticator = new RestAuthenticator("http://localhost:" + PORT + "?r=pe"); final UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(GOOD_USERNAME, PASSWORD); TestsHelper.expectException(() -> authenticator.validate(credentials, MockWebContext.create()), TechnicalException.class, "com.fasterxml.jackson.core.JsonParseException: Unrecognized token 'bad': was expecting ('true', 'false' or 'null')\n" + " at [Source: (String)\"bad\"; line: 1, column: 7]"); }
@Test public void testAuthentication() { final DirectBasicAuthClient client = new DirectBasicAuthClient(new SimpleTestUsernamePasswordAuthenticator()); final MockWebContext context = MockWebContext.create(); final String header = USERNAME + ":" + USERNAME; context.addRequestHeader(HttpConstants.AUTHORIZATION_HEADER, "Basic " + Base64.getEncoder().encodeToString(header.getBytes(StandardCharsets.UTF_8))); final UsernamePasswordCredentials credentials = client.getCredentials(context); final CommonProfile profile = client.getUserProfile(credentials, context); assertEquals(USERNAME, profile.getId()); }
@Test public void testRetrievePostParameterNotSupported() { final MockWebContext context = MockWebContext.create().setRequestMethod(HTTP_METHOD.POST.name()) .addRequestParameter(GOOD_PARAMETER, VALUE); TestsHelper.expectException(() -> getExtractor.extract(context), CredentialsException.class, "POST requests not supported"); }