diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileService.java index 2bc2f9a2..b018efe3 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileService.java @@ -66,7 +66,7 @@ public ProfileResponse getProfile(KeyPair keyPair, String connectToken) throws P try { String authKey = Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()); - YotiHttpRequest yotiHttpRequest = createSignedRequest(path, authKey); + YotiHttpRequest yotiHttpRequest = createRequest(path, authKey); return fetchReceipt(yotiHttpRequest); } catch (IOException ioe) { throw new ProfileException("Error calling service to get profile", ioe); @@ -91,7 +91,7 @@ private ProfileResponse fetchReceipt(YotiHttpRequest yotiHttpRequest) throws IOE } } - YotiHttpRequest createSignedRequest(String path, String authKey) throws ProfileException { + YotiHttpRequest createRequest(String path, String authKey) throws ProfileException { try { return yotiHttpRequestBuilderFactory.create() .withAuthStrategy(profileSignedRequestStrategy) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlService.java index d0a7c780..eeac2314 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlService.java @@ -63,7 +63,7 @@ public AmlResult performCheck(AmlProfile amlProfile) throws AmlException { String resourcePath = unsignedPathFactory.createAmlPath(); byte[] body = objectMapper.writeValueAsString(amlProfile).getBytes(DEFAULT_CHARSET); - YotiHttpRequest yotiHttpRequest = createSignedRequest(resourcePath, body); + YotiHttpRequest yotiHttpRequest = createRequest(resourcePath, body); return yotiHttpRequest.execute(AmlResult.class); } catch (IOException ioException) { throw new AmlException("Error communicating with AML endpoint", ioException); @@ -85,7 +85,7 @@ private AmlException createExceptionFromStatusCode(ResourceException ex) { } } - YotiHttpRequest createSignedRequest(String resourcePath, byte[] body) throws AmlException { + YotiHttpRequest createRequest(String resourcePath, byte[] body) throws AmlException { try { return yotiHttpRequestBuilderFactory.create() .withAuthStrategy(amlSignedRequestStrategy) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityService.java index 5fced117..22a6c405 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityService.java @@ -72,7 +72,7 @@ public ShareSession createShareSession(ShareSessionRequest shareSessionRequest) try { byte[] payload = ResourceMapper.writeValueAsString(shareSessionRequest); - return createSignedRequest(path, HTTP_POST, payload).execute(ShareSession.class); + return createRequest(path, HTTP_POST, payload).execute(ShareSession.class); } catch (IOException ex) { throw new DigitalIdentityException("Error while parsing the share session creation request ", ex); } catch (URISyntaxException ex) { @@ -90,7 +90,7 @@ public ShareSession fetchShareSession(String sessionId) throws DigitalIdentityEx LOG.debug("Requesting share session '{}' at '{}'", sessionId, path); try { - return createSignedRequest(path).execute(ShareSession.class); + return createRequest(path).execute(ShareSession.class); } catch (Exception ex) { throw new DigitalIdentityException( String.format("Error while fetching the share session '{%s}' ", sessionId), @@ -107,7 +107,7 @@ public ShareSessionQrCode createShareQrCode(String sessionId) throws DigitalIden LOG.debug("Requesting share session '{}' QR code creation at '{}'", sessionId, path); try { - return createSignedRequest(path, HTTP_POST, EMPTY_JSON).execute(ShareSessionQrCode.class); + return createRequest(path, HTTP_POST, EMPTY_JSON).execute(ShareSessionQrCode.class); } catch (GeneralSecurityException ex) { throw new DigitalIdentityException("Error while signing the share QR code creation request ", ex); } catch (IOException | URISyntaxException | ResourceException ex) { @@ -123,7 +123,7 @@ public ShareSessionQrCode fetchShareQrCode(String qrCodeId) throws DigitalIdenti LOG.debug("Requesting share session QR code '{} at '{}'", qrCodeId, path); try { - return createSignedRequest(path).execute(ShareSessionQrCode.class); + return createRequest(path).execute(ShareSessionQrCode.class); } catch (Exception ex) { throw new DigitalIdentityException( String.format("Error while fetching the share session QR code '{%s}' ", qrCodeId), @@ -149,7 +149,7 @@ private WrappedReceipt doFetchShareReceipt(String receiptId) { LOG.debug("Requesting share session receipt '{}' at '{}'", receiptId, path); try { - return createSignedRequest(path).execute(WrappedReceipt.class); + return createRequest(path).execute(WrappedReceipt.class); } catch (Exception ex) { throw new DigitalIdentityException( String.format("Error while fetching the share session QR code '{%s}' ", receiptId), @@ -164,7 +164,7 @@ private ReceiptItemKey fetchShareReceiptKey(WrappedReceipt wrappedReceipt) throw LOG.debug("Requesting share session receipt item key '{}' at '{}'", wrappedItemKeyId, path); try { - return createSignedRequest(path).execute(ReceiptItemKey.class); + return createRequest(path).execute(ReceiptItemKey.class); } catch (Exception ex) { throw new DigitalIdentityException( String.format("Error while fetching the share session receipt key '{%s}' ", wrappedItemKeyId), @@ -180,7 +180,7 @@ public MatchResult fetchMatch(MatchRequest matchRequest) throws DigitalIdentityE try { byte[] payload = ResourceMapper.writeValueAsString(matchRequest); - return createSignedRequest(path, HTTP_POST, payload).execute(MatchResult.class); + return createRequest(path, HTTP_POST, payload).execute(MatchResult.class); } catch (IOException ex) { throw new DigitalIdentityException("Error while parsing the DID Match request", ex); } catch (URISyntaxException ex) { @@ -192,11 +192,11 @@ public MatchResult fetchMatch(MatchRequest matchRequest) throws DigitalIdentityE } } - YotiHttpRequest createSignedRequest(String path) throws GeneralSecurityException, UnsupportedEncodingException, URISyntaxException { - return createSignedRequest(path, HTTP_GET, null); + YotiHttpRequest createRequest(String path) throws GeneralSecurityException, UnsupportedEncodingException, URISyntaxException { + return createRequest(path, HTTP_GET, null); } - YotiHttpRequest createSignedRequest(String path, String method, byte[] payload) + YotiHttpRequest createRequest(String path, String method, byte[] payload) throws GeneralSecurityException, UnsupportedEncodingException, URISyntaxException { YotiHttpRequestBuilder request = requestBuilderFactory.create() .withAuthStrategy(authStrategy) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingService.java index 190bca43..55cb0c59 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingService.java @@ -66,7 +66,7 @@ public ShareUrlResult createShareUrl(String appId, DynamicScenario dynamicScenar try { byte[] body = objectMapper.writeValueAsString(dynamicScenario).getBytes(DEFAULT_CHARSET); - YotiHttpRequest yotiHttpRequest = createSignedRequest(path, body); + YotiHttpRequest yotiHttpRequest = createRequest(path, body); return yotiHttpRequest.execute(ShareUrlResult.class); } catch (ResourceException ex) { @@ -76,7 +76,7 @@ public ShareUrlResult createShareUrl(String appId, DynamicScenario dynamicScenar } } - YotiHttpRequest createSignedRequest(String path, byte[] body) throws DynamicShareException { + YotiHttpRequest createRequest(String path, byte[] body) throws DynamicShareException { try { return yotiHttpRequestBuilderFactory.create() .withAuthStrategy(simpleSignedRequestStrategy) diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/ProfileServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/ProfileServiceTest.java index a4277fe8..0b50dca5 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/ProfileServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/ProfileServiceTest.java @@ -62,7 +62,7 @@ public void setUp() { @Test public void shouldReturnReceiptForCorrectRequest() throws Exception { - doReturn(yotiHttpRequest).when(testObj).createSignedRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); + doReturn(yotiHttpRequest).when(testObj).createRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); when(yotiHttpRequest.execute(ProfileResponse.class)).thenReturn(PROFILE_RESPONSE); Receipt result = testObj.getReceipt(KEY_PAIR, TOKEN); @@ -73,7 +73,7 @@ public void shouldReturnReceiptForCorrectRequest() throws Exception { @Test public void shouldThrowExceptionForIOError() throws Exception { IOException ioException = new IOException("Test exception"); - doReturn(yotiHttpRequest).when(testObj).createSignedRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); + doReturn(yotiHttpRequest).when(testObj).createRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); when(yotiHttpRequest.execute(ProfileResponse.class)).thenThrow(ioException); try { @@ -87,7 +87,7 @@ public void shouldThrowExceptionForIOError() throws Exception { @Test public void shouldThrowExceptionWithResourceExceptionCause() throws Throwable { ResourceException resourceException = new ResourceException(404, "Not Found", "Test exception"); - doReturn(yotiHttpRequest).when(testObj).createSignedRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); + doReturn(yotiHttpRequest).when(testObj).createRequest(GENERATED_PROFILE_PATH, B64_PUBLIC_KEY); when(yotiHttpRequest.execute(ProfileResponse.class)).thenThrow(resourceException); try { diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlServiceTest.java index 1345fb79..52dee545 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/aml/RemoteAmlServiceTest.java @@ -59,7 +59,7 @@ public void setUp() { @Test public void shouldPerformAmlCheck() throws Exception { when(objectMapperMock.writeValueAsString(amlProfileMock)).thenReturn(SERIALIZED_BODY); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(GENERATED_PATH, BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(GENERATED_PATH, BODY_BYTES); when(yotiHttpRequestMock.execute(AmlResult.class)).thenReturn(amlResultMock); AmlResult result = testObj.performCheck(amlProfileMock); @@ -71,7 +71,7 @@ public void shouldPerformAmlCheck() throws Exception { public void shouldWrapIOException() throws Exception { IOException ioException = new IOException(); when(objectMapperMock.writeValueAsString(amlProfileMock)).thenReturn(SERIALIZED_BODY); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(GENERATED_PATH, BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(GENERATED_PATH, BODY_BYTES); when(yotiHttpRequestMock.execute(AmlResult.class)).thenThrow(ioException); try { @@ -86,7 +86,7 @@ public void shouldWrapIOException() throws Exception { public void shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(HTTP_UNAUTHORIZED, "Unauthorized", "failed verification"); when(objectMapperMock.writeValueAsString(amlProfileMock)).thenReturn(SERIALIZED_BODY); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(GENERATED_PATH, BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(GENERATED_PATH, BODY_BYTES); when(yotiHttpRequestMock.execute(AmlResult.class)).thenThrow(resourceException); try { diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityServiceTest.java index 7bf57793..bdf8fd93 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/identity/DigitalIdentityServiceTest.java @@ -21,7 +21,6 @@ import com.yoti.api.client.spi.remote.call.YotiHttpRequest; import com.yoti.api.client.spi.remote.call.YotiHttpRequestBuilder; import com.yoti.api.client.spi.remote.call.YotiHttpRequestBuilderFactory; -import com.yoti.api.client.spi.remote.call.factory.DigitalIdentitySignedRequestStrategy; import com.yoti.api.client.spi.remote.call.factory.UnsignedPathFactory; import com.yoti.json.ResourceMapper; @@ -99,7 +98,7 @@ public void createShareSession_BuildingRequestWithWrongUri_Exception() throws Ex String exMessage = "URI wrong format"; URISyntaxException causeEx = new URISyntaxException("", exMessage); - when(testObj.createSignedRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); + when(testObj.createRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); DigitalIdentityException ex = assertThrows( DigitalIdentityException.class, @@ -119,7 +118,7 @@ public void createShareSession_BuildingRequestWithWrongQueryParams_Exception() t String exMessage = "Wrong query params format"; UnsupportedEncodingException causeEx = new UnsupportedEncodingException(exMessage); - when(testObj.createSignedRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); + when(testObj.createRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); DigitalIdentityException ex = assertThrows( DigitalIdentityException.class, @@ -139,7 +138,7 @@ public void createShareSession_BuildingRequestWithWrongDigest_Exception() throws String exMessage = "Wrong digest"; GeneralSecurityException causeEx = new GeneralSecurityException(exMessage); - when(testObj.createSignedRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); + when(testObj.createRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); DigitalIdentityException ex = assertThrows( DigitalIdentityException.class, @@ -157,7 +156,7 @@ public void createShareSession_SessionRequest_exception() throws Exception { try (MockedStatic mapper = Mockito.mockStatic(ResourceMapper.class)) { mapper.when(() -> ResourceMapper.writeValueAsString(shareSessionRequest)).thenReturn(A_BODY_BYTES); - when(testObj.createSignedRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenReturn(yotiHttpRequest); + when(testObj.createRequest(SESSION_CREATION_PATH, POST, A_BODY_BYTES)).thenReturn(yotiHttpRequest); when(yotiHttpRequest.execute(ShareSession.class)).thenReturn(shareSession); ShareSession result = testObj.createShareSession(shareSessionRequest); @@ -221,7 +220,7 @@ public void fetchMatch_BuildingRequestWithWrongEndpoint_Exception() throws Excep String exMessage = "URI wrong format"; URISyntaxException causeEx = new URISyntaxException("", exMessage); - when(testObj.createSignedRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); + when(testObj.createRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)).thenThrow(causeEx); DigitalIdentityException ex = assertThrows( DigitalIdentityException.class, @@ -241,7 +240,7 @@ public void fetchMatch_BuildingRequestWithWrongQueryParams_Exception() throws Ex String exMessage = "Wrong query params format"; UnsupportedEncodingException causeEx = new UnsupportedEncodingException(exMessage); - when(testObj.createSignedRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) + when(testObj.createRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) .thenThrow(causeEx); DigitalIdentityException ex = assertThrows( @@ -262,7 +261,7 @@ public void fetchMatch_BuildingRequestWithWrongDigest_Exception() throws Excepti String exMessage = "Wrong digest"; GeneralSecurityException causeEx = new GeneralSecurityException(exMessage); - when(testObj.createSignedRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) + when(testObj.createRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) .thenThrow(causeEx); DigitalIdentityException ex = assertThrows( @@ -281,7 +280,7 @@ public void fetchMatch_SessionRequest_exception() throws Exception { try (MockedStatic mapper = Mockito.mockStatic(ResourceMapper.class)) { mapper.when(() -> ResourceMapper.writeValueAsString(matchRequest)).thenReturn(A_BODY_BYTES); - when(testObj.createSignedRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) + when(testObj.createRequest(DIGITAL_ID_MATCH_PATH, POST, A_BODY_BYTES)) .thenReturn(yotiHttpRequest); when(yotiHttpRequest.execute(MatchResult.class)).thenReturn(matchResult); diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingServiceTest.java index f56e1af2..6d7c79f5 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/spi/remote/call/qrcode/DynamicSharingServiceTest.java @@ -85,7 +85,7 @@ public void shouldThrowDynamicShareExceptionWhenParsingFails() throws Exception public void shouldThrowExceptionForIOError() throws Exception { when(objectMapperMock.writeValueAsString(simpleDynamicScenarioMock)).thenReturn(SOME_BODY); IOException ioException = new IOException(); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); when(yotiHttpRequestMock.execute(ShareUrlResult.class)).thenThrow(ioException); try { @@ -100,7 +100,7 @@ public void shouldThrowExceptionForIOError() throws Exception { public void shouldThrowExceptionWithResourceExceptionCause() throws Exception { when(objectMapperMock.writeValueAsString(simpleDynamicScenarioMock)).thenReturn(SOME_BODY); ResourceException resourceException = new ResourceException(404, "Not Found", "Test exception"); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); when(yotiHttpRequestMock.execute(ShareUrlResult.class)).thenThrow(resourceException); try { @@ -114,7 +114,7 @@ public void shouldThrowExceptionWithResourceExceptionCause() throws Exception { @Test public void shouldReturnReceiptForCorrectRequest() throws Exception { when(objectMapperMock.writeValueAsString(simpleDynamicScenarioMock)).thenReturn(SOME_BODY); - doReturn(yotiHttpRequestMock).when(testObj).createSignedRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); + doReturn(yotiHttpRequestMock).when(testObj).createRequest(DYNAMIC_QRCODE_PATH, SOME_BODY_BYTES); when(yotiHttpRequestMock.execute(ShareUrlResult.class)).thenReturn(shareUrlResultMock); ShareUrlResult result = testObj.createShareUrl(APP_ID, simpleDynamicScenarioMock);