private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
@Test public void testGetOAuthAccessor_useToken_noOAuthInSpec() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setUseToken(UseToken.IF_AVAILABLE); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
private String getDetails(Throwable e) { String error = null; if (null != e) { if(e instanceof OAuthRequestException) { OAuthRequestException reqException = ((OAuthRequestException) e); error = reqException.getError() + ", " + reqException.getErrorText(); } else { error = e.getMessage(); } } return "OAuth error [" + error + "] for application " + securityToken.getAppUrl() + ". Request trace:" + getRequestTrace(); }
} catch (OAuthRequestException e) { if (OAuthError.UNAUTHENTICATED.name().equals(e.getError())) { responseParams.logDetailedInfo("Unauthenticated OAuth fetch", e); } else if (OAuthError.BAD_OAUTH_TOKEN_URL.name().equals(e.getError())) { responseParams.logDetailedInfo("Invalid OAuth fetch request", e); } else {
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
} catch (OAuthRequestException e) { if (OAuthError.UNAUTHENTICATED.name().equals(e.getError())) { responseParams.logDetailedInfo(classname,"fetchNoThrow",MessageKeys.UNAUTHENTICATED_OAUTH, e); } else if (OAuthError.BAD_OAUTH_TOKEN_URL.name().equals(e.getError())) { responseParams.logDetailedInfo(classname,"fetchNoThrow",MessageKeys.INVALID_OAUTH, e); } else {
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
@Test public void testGetOAuthAccessor_serviceNotFound() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setServiceName("no such service"); arguments.setUseToken(UseToken.ALWAYS); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
/** * Update a response with additional data to be returned to the application. */ public void addToResponse(HttpResponseBuilder response, OAuthRequestException e) { if (!newClientState.isEmpty()) { try { response.setMetadata(CLIENT_STATE, newClientState.getEncryptedState()); } catch (BlobCrypterException cryptException) { // Configuration error somewhere, this should never happen. throw new RuntimeException(cryptException); } } if (aznUrl != null) { response.setMetadata(APPROVAL_URL, aznUrl); } if (e != null || sendTraceToClient) { StringBuilder verboseError = new StringBuilder(); if (e != null) { response.setMetadata(ERROR_CODE, e.getError()); verboseError.append(e.getErrorText()); } if (sendTraceToClient) { verboseError.append('\n'); verboseError.append(getRequestTrace()); } response.setMetadata(ERROR_TEXT, verboseError.toString()); } }
@Test public void testGetOAuthAccessor_serviceNotFound() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setServiceName("no such service"); arguments.setUseToken(UseToken.ALWAYS); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
@Test public void testGetOAuthAccessor_serviceNotFound() throws Exception { OAuthArguments arguments = new OAuthArguments(); arguments.setServiceName("no such service"); arguments.setUseToken(UseToken.ALWAYS); try { store.getOAuthAccessor(socialToken, arguments, clientState, responseParams, fetcherConfig); fail(); } catch (OAuthRequestException e) { assertEquals("BAD_OAUTH_CONFIGURATION", e.getError()); } }
@Test public void testWrongDomain() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andReturn(gadget); expect(lockedDomainService.isGadgetValidForHost("renderinghost", gadget, "default")) .andReturn(false); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }
@Test public void testWrongDomain() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andReturn(gadget); expect(lockedDomainService.gadgetCanRender("renderinghost", gadget, "default")) .andReturn(false); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }
@Test public void testWrongDomain() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andReturn(gadget); expect(lockedDomainService.isGadgetValidForHost("renderinghost", gadget, "default")) .andReturn(false); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }
@Test public void testBadGadget() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andThrow(new ProcessingException("doh", HttpServletResponse.SC_BAD_REQUEST)); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }
@Test public void testBadGadget() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andThrow(new ProcessingException("doh", HttpServletResponse.SC_BAD_REQUEST)); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }
@Test public void testBadGadget() throws Exception { HttpRequest request = new HttpRequest(DEST_URL); request.setSecurityToken(securityToken); request.setOAuthArguments(new OAuthArguments()); expect(processor.process(eqContext(securityToken, request.getOAuthArguments()))) .andThrow(new ProcessingException("doh", HttpServletResponse.SC_BAD_REQUEST)); control.replay(); try { getGenerator().generateCallback(fetcherConfig, "base", request, responseParams); fail("Should have thrown"); } catch (OAuthRequestException e) { assertEquals(OAuthError.UNKNOWN_PROBLEM.name(), e.getError()); } control.verify(); }