Skip to content

Commit 17cc613

Browse files
authored
Merge pull request #324 from IABTechLab/tjm-UID2-4109-add-operator-type-attest-request
Add the operator type to the attestation request
2 parents 749a3e4 + f288c8a commit 17cc613

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>com.uid2</groupId>
77
<artifactId>uid2-shared</artifactId>
8-
<version>7.18.0</version>
8+
<version>7.18.1-alpha-149-SNAPSHOT</version>
99
<name>${project.groupId}:${project.artifactId}</name>
1010
<description>Library for all the shared uid2 operations</description>
1111
<url>https://github.com/IABTechLab/uid2docs</url>

src/main/java/com/uid2/shared/attest/AttestationResponseHandler.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class AttestationResponseHandler {
2929

3030
private final IAttestationProvider attestationProvider;
3131
private final String clientApiToken;
32+
private final String operatorType;
3233
private final ApplicationVersion appVersion;
3334
private final AtomicReference<String> attestationToken;
3435
private final AtomicReference<String> optOutJwt;
@@ -52,15 +53,17 @@ public class AttestationResponseHandler {
5253
public AttestationResponseHandler(Vertx vertx,
5354
String attestationEndpoint,
5455
String clientApiToken,
56+
String operatorType,
5557
ApplicationVersion appVersion,
5658
IAttestationProvider attestationProvider,
5759
Handler<Pair<Integer, String>> responseWatcher,
5860
Proxy proxy) {
59-
this(vertx, attestationEndpoint, clientApiToken, appVersion, attestationProvider, responseWatcher, proxy, new InstantClock(), null, null, 60000);
61+
this(vertx, attestationEndpoint, clientApiToken, operatorType, appVersion, attestationProvider, responseWatcher, proxy, new InstantClock(), null, null, 60000);
6062
}
6163
public AttestationResponseHandler(Vertx vertx,
6264
String attestationEndpoint,
6365
String clientApiToken,
66+
String operatorType,
6467
ApplicationVersion appVersion,
6568
IAttestationProvider attestationProvider,
6669
Handler<Pair<Integer, String>> responseWatcher,
@@ -73,6 +76,7 @@ public AttestationResponseHandler(Vertx vertx,
7376
this.attestationEndpoint = attestationEndpoint;
7477
this.encodedAttestationEndpoint = this.encodeStringUnicodeAttestationEndpoint(attestationEndpoint);
7578
this.clientApiToken = clientApiToken;
79+
this.operatorType = operatorType;
7680
this.appVersion = appVersion;
7781
this.attestationProvider = attestationProvider;
7882
this.attestationToken = new AtomicReference<>(null);
@@ -158,7 +162,8 @@ public void attest() throws IOException, AttestationResponseHandlerException {
158162
"attestation_request", Base64.getEncoder().encodeToString(attestationProvider.getAttestationRequest(publicKey, this.encodedAttestationEndpoint)),
159163
"public_key", Base64.getEncoder().encodeToString(publicKey),
160164
"application_name", appVersion.getAppName(),
161-
"application_version", appVersion.getAppVersion()
165+
"application_version", appVersion.getAppVersion(),
166+
"operator_type", this.operatorType
162167
);
163168
JsonObject components = new JsonObject();
164169
for (Map.Entry<String, String> kv : appVersion.getComponentVersions().entrySet()) {
@@ -178,7 +183,7 @@ public void attest() throws IOException, AttestationResponseHandlerException {
178183
notifyResponseWatcher(statusCode, responseBody);
179184

180185
if (statusCode < 200 || statusCode >= 300) {
181-
LOGGER.warn("attestation failed with UID2 Core returning statusCode=" + statusCode);
186+
LOGGER.warn("attestation failed with UID2 Core returning statusCode={}", statusCode);
182187
throw new AttestationResponseHandlerException(statusCode, "unexpected status code from uid core service");
183188
}
184189

src/test/java/com/uid2/shared/attest/AttestationResponseHandlerTest.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
@ExtendWith(VertxExtension.class)
3737
public class AttestationResponseHandlerTest {
3838
private static final String ATTESTATION_ENDPOINT = "https://core-test.uidapi.com/attest";
39+
private static final String OPERATOR_TYPE = "public";
3940
private byte[] ENCODED_ATTESTATION_ENDPOINT;
4041
private static final ApplicationVersion APP_VERSION = new ApplicationVersion("appName", "appVersion", new HashMap<String, String>()
4142
{{
@@ -303,7 +304,7 @@ public void attest_succeed_jwtsNull(Vertx vertx, VertxTestContext testContext) t
303304
}
304305

305306
@Test
306-
public void attest_succeed_jsonRequest_includes_attestUrl_in_attestation_request(Vertx vertx, VertxTestContext testContext) throws Exception{
307+
public void attest_succeed_jsonRequest_includes_expected_properties(Vertx vertx, VertxTestContext testContext) throws Exception{
307308
attestationResponseHandler = getAttestationTokenRetriever(vertx);
308309

309310
when(attestationProvider.isReady()).thenReturn(true);
@@ -331,12 +332,15 @@ public void attest_succeed_jsonRequest_includes_attestUrl_in_attestation_request
331332
String decodedUrl = new String(data, StandardCharsets.UTF_8);
332333
Assertions.assertEquals(ATTESTATION_ENDPOINT, decodedUrl);
333334

335+
Assertions.assertNotNull(jsonBody.getString("operator_type"));
336+
Assertions.assertEquals(OPERATOR_TYPE, jsonBody.getString("operator_type"));
337+
334338
verify(attestationProvider, times(1)).getAttestationRequest(any(), eq(ENCODED_ATTESTATION_ENDPOINT));
335339

336340
testContext.completeNow();
337341
}
338342

339343
private AttestationResponseHandler getAttestationTokenRetriever(Vertx vertx) {
340-
return new AttestationResponseHandler(vertx, ATTESTATION_ENDPOINT, "testApiKey", APP_VERSION, attestationProvider, responseWatcher, proxy, clock, mockHttpClient, mockAttestationTokenDecryptor, 250);
344+
return new AttestationResponseHandler(vertx, ATTESTATION_ENDPOINT, "testApiKey", OPERATOR_TYPE, APP_VERSION, attestationProvider, responseWatcher, proxy, clock, mockHttpClient, mockAttestationTokenDecryptor, 250);
341345
}
342346
}

0 commit comments

Comments
 (0)