Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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),
Expand All @@ -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) {
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -157,7 +156,7 @@ public void createShareSession_SessionRequest_exception() throws Exception {
try (MockedStatic<ResourceMapper> 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);
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -281,7 +280,7 @@ public void fetchMatch_SessionRequest_exception() throws Exception {
try (MockedStatic<ResourceMapper> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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);
Expand Down