@Test public void testGeClientAuthenticationType1() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final String result = fixture.geClientAuthenticationType(); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result); } }
private static OAuth2HandlerError getError(final String contextMessage) { return BasicAuthenticationHandler.getError(contextMessage, null); }
@Test public void testAddOAuth2Authentication4() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNull(result); final String authHeader = request.getHeader("Authorization"); Assert.assertNotNull(authHeader); Assert.assertEquals("Basic: Y2xpZW50SWQxOmNsaWVudFNlY3JldDE=", authHeader); }
protected static List<ClientAuthenticationHandler> getDummyClientAuthHandlers() throws Exception { final List<ClientAuthenticationHandler> ret = new ArrayList<ClientAuthenticationHandler>(2); ret.add(new BasicAuthenticationHandler()); ret.add(new StandardAuthenticationHandler()); return ret; }
@Test public void testAddOAuth2Authentication4() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNull(result); final String authHeader = request.getHeader("Authorization"); Assert.assertNotNull(authHeader); Assert.assertEquals("Basic: Y2xpZW50SWQxOmNsaWVudFNlY3JldDE=", authHeader); }
protected static List<ClientAuthenticationHandler> getDummyClientAuthHandlers() throws Exception { final List<ClientAuthenticationHandler> ret = new ArrayList<ClientAuthenticationHandler>(2); ret.add(new BasicAuthenticationHandler()); ret.add(new StandardAuthenticationHandler()); return ret; }
@Test public void testAddOAuth2Authentication3() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals(OAuth2Error.AUTHENTICATION_PROBLEM, result.getError()); Assert.assertTrue(result.getContextMessage().startsWith("accessor is invalid")); }
@Test public void testGeClientAuthenticationType1() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final String result = fixture.geClientAuthenticationType(); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result); } }
@SuppressWarnings("unused") @Test public void testProvideClientAuthenticationHandlers_1() throws Exception { final OAuth2HandlerModule fixture = new OAuth2HandlerModule(); final BasicAuthenticationHandler basicAuthenticationHandler = new BasicAuthenticationHandler(); final StandardAuthenticationHandler standardAuthenticationHandler = new StandardAuthenticationHandler(); final List<ClientAuthenticationHandler> result = OAuth2HandlerModule .provideClientAuthenticationHandlers(basicAuthenticationHandler, standardAuthenticationHandler); Assert.assertNotNull(result); Assert.assertEquals(2, result.size()); }
public OAuth2HandlerError addOAuth2Authentication(final HttpRequest request, final OAuth2Accessor accessor) { try { if (request == null) { return BasicAuthenticationHandler.getError("request is null"); } if (accessor == null || !accessor.isValid() || accessor.isErrorResponse()) { return BasicAuthenticationHandler.getError("accessor is invalid " + accessor); } final String clientId = accessor.getClientId(); if (clientId == null) { return BasicAuthenticationHandler.getError("client_id is null"); } final byte[] secretBytes = accessor.getClientSecret(); if (secretBytes == null) { return BasicAuthenticationHandler.getError("client_secret is secret"); } final String secret = new String(secretBytes, "UTF-8"); final String authString = clientId + ':' + secret; final byte[] authBytes = Base64.encodeBase64(authString.getBytes()); request.setHeader(OAuth2Message.AUTHORIZATION_HEADER, "Basic: " + new String(authBytes)); return null; } catch (final Exception e) { return BasicAuthenticationHandler.getError("Exception adding basic auth headers", e); } }
@Test public void testAddOAuth2Authentication2() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = null; final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("accessor is invalid null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : accessor is invalid null : : :null", result.toString()); }
@Test public void testBasicAuthenticationHandler1() throws Exception { final BasicAuthenticationHandler result = new BasicAuthenticationHandler(); Assert.assertNotNull(result); Assert.assertTrue(ClientAuthenticationHandler.class.isInstance(result)); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result.geClientAuthenticationType()); }
@SuppressWarnings("unused") @Test public void testProvideClientAuthenticationHandlers_1() throws Exception { final OAuth2HandlerModule fixture = new OAuth2HandlerModule(); final BasicAuthenticationHandler basicAuthenticationHandler = new BasicAuthenticationHandler(); final StandardAuthenticationHandler standardAuthenticationHandler = new StandardAuthenticationHandler(); final List<ClientAuthenticationHandler> result = OAuth2HandlerModule .provideClientAuthenticationHandlers(basicAuthenticationHandler, standardAuthenticationHandler); Assert.assertNotNull(result); Assert.assertEquals(2, result.size()); }
@Test public void testAddOAuth2Authentication3() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Error(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals(OAuth2Error.AUTHENTICATION_PROBLEM, result.getError()); Assert.assertTrue(result.getContextMessage().startsWith("accessor is invalid")); }
@Test public void testBasicAuthenticationHandler1() throws Exception { final BasicAuthenticationHandler result = new BasicAuthenticationHandler(); Assert.assertNotNull(result); Assert.assertTrue(ClientAuthenticationHandler.class.isInstance(result)); Assert.assertEquals(OAuth2Message.BASIC_AUTH_TYPE, result.geClientAuthenticationType()); }
@Test public void testAddOAuth2Authentication2() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = new HttpRequest(Uri.fromJavaUri(new URI(""))); final OAuth2Accessor accessor = null; final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("accessor is invalid null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : accessor is invalid null : : :null", result.toString()); }
@Test public void testAddOAuth2Authentication1() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = null; final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("request is null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : request is null : : :null", result.toString()); }
@Test public void testAddOAuth2Authentication1() throws Exception { final BasicAuthenticationHandler fixture = new BasicAuthenticationHandler(); final HttpRequest request = null; final OAuth2Accessor accessor = MockUtils.getOAuth2Accessor_Code(); final OAuth2HandlerError result = fixture.addOAuth2Authentication(request, accessor); Assert.assertNotNull(result); Assert.assertEquals(null, result.getCause()); Assert.assertEquals("request is null", result.getContextMessage()); Assert.assertEquals( "org.apache.shindig.gadgets.oauth2.handler.OAuth2HandlerError : AUTHENTICATION_PROBLEM : request is null : : :null", result.toString()); }