Skip to content

Commit

Permalink
Merge pull request #324 from IABTechLab/tjm-UID2-4109-add-operator-ty…
Browse files Browse the repository at this point in the history
…pe-attest-request

Add the operator type to the attestation request
  • Loading branch information
thomasm-ttd authored Sep 13, 2024
2 parents 749a3e4 + f288c8a commit 17cc613
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.uid2</groupId>
<artifactId>uid2-shared</artifactId>
<version>7.18.0</version>
<version>7.18.1-alpha-149-SNAPSHOT</version>
<name>${project.groupId}:${project.artifactId}</name>
<description>Library for all the shared uid2 operations</description>
<url>https://github.com/IABTechLab/uid2docs</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class AttestationResponseHandler {

private final IAttestationProvider attestationProvider;
private final String clientApiToken;
private final String operatorType;
private final ApplicationVersion appVersion;
private final AtomicReference<String> attestationToken;
private final AtomicReference<String> optOutJwt;
Expand All @@ -52,15 +53,17 @@ public class AttestationResponseHandler {
public AttestationResponseHandler(Vertx vertx,
String attestationEndpoint,
String clientApiToken,
String operatorType,
ApplicationVersion appVersion,
IAttestationProvider attestationProvider,
Handler<Pair<Integer, String>> responseWatcher,
Proxy proxy) {
this(vertx, attestationEndpoint, clientApiToken, appVersion, attestationProvider, responseWatcher, proxy, new InstantClock(), null, null, 60000);
this(vertx, attestationEndpoint, clientApiToken, operatorType, appVersion, attestationProvider, responseWatcher, proxy, new InstantClock(), null, null, 60000);
}
public AttestationResponseHandler(Vertx vertx,
String attestationEndpoint,
String clientApiToken,
String operatorType,
ApplicationVersion appVersion,
IAttestationProvider attestationProvider,
Handler<Pair<Integer, String>> responseWatcher,
Expand All @@ -73,6 +76,7 @@ public AttestationResponseHandler(Vertx vertx,
this.attestationEndpoint = attestationEndpoint;
this.encodedAttestationEndpoint = this.encodeStringUnicodeAttestationEndpoint(attestationEndpoint);
this.clientApiToken = clientApiToken;
this.operatorType = operatorType;
this.appVersion = appVersion;
this.attestationProvider = attestationProvider;
this.attestationToken = new AtomicReference<>(null);
Expand Down Expand Up @@ -158,7 +162,8 @@ public void attest() throws IOException, AttestationResponseHandlerException {
"attestation_request", Base64.getEncoder().encodeToString(attestationProvider.getAttestationRequest(publicKey, this.encodedAttestationEndpoint)),
"public_key", Base64.getEncoder().encodeToString(publicKey),
"application_name", appVersion.getAppName(),
"application_version", appVersion.getAppVersion()
"application_version", appVersion.getAppVersion(),
"operator_type", this.operatorType
);
JsonObject components = new JsonObject();
for (Map.Entry<String, String> kv : appVersion.getComponentVersions().entrySet()) {
Expand All @@ -178,7 +183,7 @@ public void attest() throws IOException, AttestationResponseHandlerException {
notifyResponseWatcher(statusCode, responseBody);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
@ExtendWith(VertxExtension.class)
public class AttestationResponseHandlerTest {
private static final String ATTESTATION_ENDPOINT = "https://core-test.uidapi.com/attest";
private static final String OPERATOR_TYPE = "public";
private byte[] ENCODED_ATTESTATION_ENDPOINT;
private static final ApplicationVersion APP_VERSION = new ApplicationVersion("appName", "appVersion", new HashMap<String, String>()
{{
Expand Down Expand Up @@ -303,7 +304,7 @@ public void attest_succeed_jwtsNull(Vertx vertx, VertxTestContext testContext) t
}

@Test
public void attest_succeed_jsonRequest_includes_attestUrl_in_attestation_request(Vertx vertx, VertxTestContext testContext) throws Exception{
public void attest_succeed_jsonRequest_includes_expected_properties(Vertx vertx, VertxTestContext testContext) throws Exception{
attestationResponseHandler = getAttestationTokenRetriever(vertx);

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

Assertions.assertNotNull(jsonBody.getString("operator_type"));
Assertions.assertEquals(OPERATOR_TYPE, jsonBody.getString("operator_type"));

verify(attestationProvider, times(1)).getAttestationRequest(any(), eq(ENCODED_ATTESTATION_ENDPOINT));

testContext.completeNow();
}

private AttestationResponseHandler getAttestationTokenRetriever(Vertx vertx) {
return new AttestationResponseHandler(vertx, ATTESTATION_ENDPOINT, "testApiKey", APP_VERSION, attestationProvider, responseWatcher, proxy, clock, mockHttpClient, mockAttestationTokenDecryptor, 250);
return new AttestationResponseHandler(vertx, ATTESTATION_ENDPOINT, "testApiKey", OPERATOR_TYPE, APP_VERSION, attestationProvider, responseWatcher, proxy, clock, mockHttpClient, mockAttestationTokenDecryptor, 250);
}
}

0 comments on commit 17cc613

Please sign in to comment.