Skip to content

Commit 7f531f2

Browse files
committed
SDK-2478: Allow the Relying Business to delete tracked device metadata for a given session
1 parent 234f730 commit 7f531f2

File tree

6 files changed

+137
-4
lines changed

6 files changed

+137
-4
lines changed

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,18 +245,30 @@ public SessionConfigurationResponse getSessionConfiguration(String sessionId) th
245245
}
246246

247247
/**
248-
* Fetches the tracked devices used by the end user, to interact with the given sessionID.
248+
* Fetches details of the devices tracked at key points in completing the session.
249249
*
250250
* @param sessionId the session ID
251251
*
252-
* @return the session configuration
252+
* @return the list of tracked devices information
253253
* @throws DocScanException if an error has occurred
254254
*/
255255
public List<MetadataResponse> getTrackedDevices(String sessionId) throws DocScanException {
256256
LOG.debug("Fetching tracked devices for session '{}'", sessionId);
257257
return docScanService.getTrackedDevices(sdkId, keyPair, sessionId);
258258
}
259259

260+
/**
261+
* Deletes the tracked devices metadata for the given sessionID.
262+
*
263+
* @param sessionId the session ID
264+
*
265+
* @throws DocScanException if an error has occurred
266+
*/
267+
public void deleteTrackedDevices(String sessionId) throws DocScanException {
268+
LOG.debug("Deleting tracked devices for session '{}'", sessionId);
269+
docScanService.deleteTrackedDevices(sdkId, keyPair, sessionId);
270+
}
271+
260272
private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException {
261273
try {
262274
LOG.debug("Loading key pair from '{}'", kpSource);

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,29 @@ public List<MetadataResponse> getTrackedDevices(String sdkId, KeyPair keyPair, S
556556
}
557557
}
558558

559+
public void deleteTrackedDevices(String sdkId, KeyPair keyPair, String sessionId) throws DocScanException {
560+
notNullOrEmpty(sdkId, "SDK ID");
561+
notNull(keyPair, "Application key Pair");
562+
notNullOrEmpty(sessionId, "sessionId");
563+
564+
String path = unsignedPathFactory.createDeleteTrackedDevices(sdkId, sessionId);
565+
LOG.info("Deleting tracked devices at '{}'", path);
566+
567+
try {
568+
signedRequestBuilderFactory.create()
569+
.withKeyPair(keyPair)
570+
.withBaseUrl(apiUrl)
571+
.withEndpoint(path)
572+
.withHttpMethod(HTTP_DELETE)
573+
.build()
574+
.execute();
575+
} catch (GeneralSecurityException | ResourceException ex) {
576+
throw new DocScanException("Error executing the GET: " + ex.getMessage(), ex);
577+
} catch (IOException | URISyntaxException ex) {
578+
throw new DocScanException("Error building the request: " + ex.getMessage(), ex);
579+
}
580+
}
581+
559582
private String findContentType(SignedRequestResponse response) {
560583
List<String> contentTypeValues = null;
561584
for (Map.Entry<String, List<String>> entry : response.getResponseHeaders().entrySet()) {

yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ public class MetadataResponse {
77
@JsonProperty("event")
88
private String event;
99

10+
@JsonProperty("resource_id")
11+
private String resourceId;
12+
1013
@JsonProperty("created")
1114
private String created;
1215

@@ -17,6 +20,10 @@ public String getEvent() {
1720
return event;
1821
}
1922

23+
public String getResourceId() {
24+
return resourceId;
25+
}
26+
2027
public String getCreated() {
2128
return created;
2229
}

yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class UnsignedPathFactory {
3232
private static final String DOCS_NEW_FACE_CAPTURE_RESOURCE = "/sessions/%s/resources/face-capture?sdkId=%s";
3333
private static final String DOCS_UPLOAD_FACE_CAPTURE_IMAGE = "/sessions/%s/resources/face-capture/%s/image?sdkId=%s";
3434
private static final String DOCS_TRIGGER_IBV_NOTIFICATION = "/sessions/%s/instructions/email?sdkId=%s";
35-
private static final String DOCS_FETCH_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s";
35+
private static final String DOCS_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s";
3636

3737
public String createAmlPath(String appId) {
3838
return format(AML, appId);
@@ -123,7 +123,11 @@ public String createTriggerIbvEmailNotificationPath(String sdkId, String session
123123
}
124124

125125
public String createFetchTrackedDevices(String sdkId, String sessionId) {
126-
return format(DOCS_FETCH_TRACKED_DEVICES, sessionId, sdkId);
126+
return format(DOCS_TRACKED_DEVICES, sessionId, sdkId);
127+
}
128+
129+
public String createDeleteTrackedDevices(String sdkId, String sessionId) {
130+
return format(DOCS_TRACKED_DEVICES, sessionId, sdkId);
127131
}
128132

129133
}

yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,15 @@ public void getTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throw
197197
assertThat(thrown, is(original));
198198
}
199199

200+
@Test
201+
public void deleteTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throws Exception {
202+
DocScanException original = new DocScanException("Test exception");
203+
doThrow(original).when(docScanServiceMock).deleteTrackedDevices(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID));
204+
DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock);
205+
206+
DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteTrackedDevices(SOME_SESSION_ID));
207+
208+
assertThat(thrown, is(original));
209+
}
210+
200211
}

yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,4 +1538,80 @@ public void getTrackedDevices_shouldReturnTrackedDevices() throws Exception {
15381538
assertThat(result.get(0), is(metadataResponseMock));
15391539
}
15401540

1541+
@Test
1542+
public void deleteTrackedDevices_shouldThrowExceptionWhenSdkIdIsNull() {
1543+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(null, KEY_PAIR, SOME_SESSION_ID));
1544+
assertThat(exception.getMessage(), containsString("SDK ID"));
1545+
}
1546+
1547+
@Test
1548+
public void deleteTrackedDevices_shouldThrowExceptionWhenSdkIdIsEmpty() {
1549+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices("", KEY_PAIR, SOME_SESSION_ID));
1550+
assertThat(exception.getMessage(), containsString("SDK ID"));
1551+
}
1552+
1553+
@Test
1554+
public void deleteTrackedDevices_shouldThrowExceptionWhenKeyPairIsNull() {
1555+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, null, SOME_SESSION_ID));
1556+
assertThat(exception.getMessage(), containsString("Application key Pair"));
1557+
}
1558+
1559+
@Test
1560+
public void deleteTrackedDevices_shouldThrowExceptionWhenSessionIdIsNull() {
1561+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, null));
1562+
assertThat(exception.getMessage(), containsString("sessionId"));
1563+
}
1564+
1565+
@Test
1566+
public void deleteTrackedDevices_shouldThrowExceptionWhenSessionIdIsEmpty() {
1567+
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, ""));
1568+
assertThat(exception.getMessage(), containsString("sessionId"));
1569+
}
1570+
1571+
@Test
1572+
public void deleteTrackedDevices_shouldWrapGeneralSecurityException() throws Exception {
1573+
GeneralSecurityException gse = new GeneralSecurityException("some gse");
1574+
when(signedRequestBuilderMock.build()).thenThrow(gse);
1575+
1576+
DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID));
1577+
1578+
assertSame(ex.getCause(), gse);
1579+
assertThat(ex.getMessage(), containsString("Error executing the GET: some gse"));
1580+
}
1581+
1582+
@Test
1583+
public void deleteTrackedDevices_shouldWrapResourceException() throws Exception {
1584+
ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API");
1585+
when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock);
1586+
when(signedRequestMock.execute()).thenThrow(resourceException);
1587+
1588+
DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID));
1589+
1590+
assertSame(ex.getCause(), resourceException);
1591+
assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request"));
1592+
}
1593+
1594+
@Test
1595+
public void deleteTrackedDevices_shouldWrapIOException() throws Exception {
1596+
IOException ioException = new IOException("Some io exception");
1597+
when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock);
1598+
when(signedRequestMock.execute()).thenThrow(ioException);
1599+
1600+
DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID));
1601+
1602+
assertSame(ex.getCause(), ioException);
1603+
assertThat(ex.getMessage(), containsString("Error building the request: Some io exception"));
1604+
}
1605+
1606+
@Test
1607+
public void deleteTrackedDevices_shouldWrapURISyntaxException() throws Exception {
1608+
URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI");
1609+
when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException);
1610+
1611+
DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID));
1612+
1613+
assertSame(ex.getCause(), uriSyntaxException);
1614+
assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl"));
1615+
}
1616+
15411617
}

0 commit comments

Comments
 (0)