Skip to content

Commit 19509fe

Browse files
authored
Merge pull request #1974 from IABTechLab/gdm-hotfix
Made refreshFrom not nullable
2 parents ba0591f + 196f5f4 commit 19509fe

File tree

3 files changed

+34
-52
lines changed

3 files changed

+34
-52
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<enclave-aws.version>2.1.0</enclave-aws.version>
2323
<enclave-azure.version>2.1.13</enclave-azure.version>
2424
<enclave-gcp.version>2.1.0</enclave-gcp.version>
25-
<uid2-shared.version>10.9.0</uid2-shared.version>
25+
<uid2-shared.version>11.0.4</uid2-shared.version>
2626
<image.version>${project.version}</image.version>
2727
<maven.compiler.source>21</maven.compiler.source>
2828
<maven.compiler.target>21</maven.compiler.target>

src/main/java/com/uid2/operator/service/UIDOperatorService.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
import io.vertx.core.AsyncResult;
1111
import io.vertx.core.Future;
1212
import io.vertx.core.Handler;
13-
import org.slf4j.Logger;
14-
import org.slf4j.LoggerFactory;
1513

1614
import java.time.Clock;
1715
import java.time.Duration;
@@ -28,7 +26,6 @@ public class UIDOperatorService implements IUIDOperatorService {
2826
public static final String IDENTITY_TOKEN_EXPIRES_AFTER_SECONDS = "identity_token_expires_after_seconds";
2927
public static final String REFRESH_TOKEN_EXPIRES_AFTER_SECONDS = "refresh_token_expires_after_seconds";
3028
public static final String REFRESH_IDENTITY_TOKEN_AFTER_SECONDS = "refresh_identity_token_after_seconds";
31-
private static final Logger LOGGER = LoggerFactory.getLogger(UIDOperatorService.class);
3229

3330
private static final Instant REFRESH_CUTOFF = LocalDateTime.parse("2021-03-08T17:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME).toInstant(ZoneOffset.UTC);
3431
private static final long DAY_IN_MS = Duration.ofDays(1).toMillis();
@@ -174,7 +171,7 @@ public List<SaltEntry> getModifiedBuckets(Instant sinceTimestamp) {
174171

175172
private ISaltProvider.ISaltSnapshot getSaltProviderSnapshot(Instant asOf) {
176173
ISaltProvider.ISaltSnapshot snapshot = this.saltProvider.getSnapshot(asOf);
177-
if(snapshot.getExpires().isBefore(Instant.now())) {
174+
if (snapshot.getExpires().isBefore(Instant.now())) {
178175
saltRetrievalResponseHandler.handle(true);
179176
} else {
180177
saltRetrievalResponseHandler.handle(false);
@@ -255,8 +252,8 @@ private byte[] getPreviousAdvertisingId(UserIdentity firstLevelHashIdentity, Sal
255252
}
256253

257254
private long getRefreshFrom(SaltEntry rotatingSalt, Instant asOf) {
258-
Long refreshFrom = rotatingSalt.refreshFrom();
259-
if (refreshFrom == null || refreshFrom < asOf.toEpochMilli()) {
255+
long refreshFrom = rotatingSalt.refreshFrom();
256+
if (refreshFrom < asOf.toEpochMilli()) {
260257
return asOf.truncatedTo(DAYS).plus(1, DAYS).toEpochMilli();
261258
}
262259
return refreshFrom;
@@ -297,8 +294,7 @@ static protected class GlobalOptoutResult {
297294
private final Instant time;
298295

299296
//providedTime can be null if isOptedOut is false!
300-
GlobalOptoutResult(Instant providedTime)
301-
{
297+
GlobalOptoutResult(Instant providedTime) {
302298
isOptedOut = providedTime != null;
303299
time = providedTime;
304300
}

src/test/java/com/uid2/operator/UIDOperatorVerticleTest.java

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@
6464

6565
import javax.crypto.SecretKey;
6666
import java.math.BigInteger;
67-
import java.net.URLEncoder;
6867
import java.nio.charset.StandardCharsets;
6968
import java.security.*;
7069
import java.time.*;
@@ -91,7 +90,7 @@ public class UIDOperatorVerticleTest {
9190
private static final Instant legacyClientCreationDateTime = Instant.ofEpochSecond(OPT_OUT_CHECK_CUTOFF_DATE).minus(1, ChronoUnit.SECONDS);
9291
private static final Instant newClientCreationDateTime = Instant.ofEpochSecond(OPT_OUT_CHECK_CUTOFF_DATE).plus(1, ChronoUnit.SECONDS);
9392
private static final String firstLevelSalt = "first-level-salt";
94-
private static final SaltEntry rotatingSalt123 = new SaltEntry(123, "hashed123", 0, "salt123", null, null, null, null);
93+
private static final SaltEntry rotatingSalt123 = new SaltEntry(123, "hashed123", 0, "salt123", 1000L, "prevSalt123", null, null);
9594
private static final Duration identityExpiresAfter = Duration.ofMinutes(10);
9695
private static final Duration refreshExpiresAfter = Duration.ofMinutes(15);
9796
private static final Duration refreshIdentityAfter = Duration.ofMinutes(5);
@@ -105,7 +104,6 @@ public class UIDOperatorVerticleTest {
105104
private static final String iosClientVersionHeaderValue = "ios-1.2.3";
106105
private static final String tvosClientVersionHeaderValue = "tvos-1.2.3";
107106
private static final int clientSideTokenGenerateSiteId = 123;
108-
109107
private static final int optOutStatusMaxRequestSize = 1000;
110108

111109
@Mock
@@ -144,7 +142,7 @@ public class UIDOperatorVerticleTest {
144142
private final JsonObject config = new JsonObject();
145143

146144
@BeforeEach
147-
public void deployVerticle(Vertx vertx, VertxTestContext testContext, TestInfo testInfo) {
145+
void deployVerticle(Vertx vertx, VertxTestContext testContext, TestInfo testInfo) {
148146
when(saltProvider.getSnapshot(any())).thenReturn(saltProviderSnapshot);
149147
when(saltProviderSnapshot.getExpires()).thenReturn(Instant.now().plus(1, ChronoUnit.HOURS));
150148
when(clock.instant()).thenAnswer(i -> now);
@@ -174,7 +172,7 @@ public void deployVerticle(Vertx vertx, VertxTestContext testContext, TestInfo t
174172
}
175173

176174
@AfterEach
177-
public void teardown() throws Exception {
175+
void teardown() {
178176
Metrics.globalRegistry.remove(registry);
179177
}
180178

@@ -232,14 +230,6 @@ private void clearAuth() {
232230
when(clientKeyProvider.get(any())).thenReturn(null);
233231
}
234232

235-
private static String urlEncode(String value) {
236-
try {
237-
return URLEncoder.encode(value, StandardCharsets.UTF_8);
238-
} catch (Exception e) {
239-
return null;
240-
}
241-
}
242-
243233
private String getUrlForEndpoint(String endpoint) {
244234
return String.format("http://127.0.0.1:%d/%s", Const.Port.ServicePortForOperator + Utils.getPortOffset(), endpoint);
245235
}
@@ -281,7 +271,6 @@ protected void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expe
281271
sendTokenGenerate(vertx, v2PostPayload, expectedHttpCode, null, handler, true, Collections.emptyMap());
282272
}
283273

284-
285274
protected void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expectedHttpCode,
286275
Handler<JsonObject> handler, Map<String, String> additionalHeaders) {
287276
sendTokenGenerate(vertx, v2PostPayload, expectedHttpCode, null, handler, true, additionalHeaders);
@@ -297,7 +286,6 @@ private void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expect
297286
}
298287

299288
private void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expectedHttpCode, String referer, Handler<JsonObject> handler, boolean additionalParams, Map<String, String> additionalHeaders) {
300-
301289
ClientKey ck = (ClientKey) clientKeyProvider.get("");
302290

303291
long nonce = new BigInteger(Random.getBytes(8)).longValue();
@@ -1203,7 +1191,8 @@ void v3IdentityMapMissingValidInputKeys(String inputPayload, Vertx vertx, VertxT
12031191
}
12041192

12051193
@ParameterizedTest
1206-
@ValueSource(strings = {"{\"invalid_key\": []}",
1194+
@ValueSource(strings = {
1195+
"{\"invalid_key\": []}",
12071196
"{\"email\": [ null ]}",
12081197
"{\"email\": [ \"some_email\", null ]}"
12091198
})
@@ -1408,10 +1397,12 @@ void tokenGenerateNewClientWrongPolicySpecifiedOlderKeySuccessful(String policyP
14081397
}
14091398

14101399
@ParameterizedTest // TODO: remove test after optout check phase 3
1411-
@CsvSource({"policy,[email protected],Email",
1400+
@CsvSource({
1401+
"policy,[email protected],Email",
14121402
"policy,+01234567890,Phone",
14131403
"optout_check,[email protected],Email",
1414-
"optout_check,+01234567890,Phone"})
1404+
"optout_check,+01234567890,Phone"
1405+
})
14151406
void tokenGenerateOptOutToken(String policyParameterKey, String identity, IdentityType identityType,
14161407
Vertx vertx, VertxTestContext testContext) {
14171408
ClientKey oldClientKey = new ClientKey(
@@ -1475,8 +1466,7 @@ void tokenGenerateOptOutToken(String policyParameterKey, String identity, Identi
14751466
TokenResponseStatsCollector.ResponseStatus.Success,
14761467
TokenResponseStatsCollector.PlatformType.Other);
14771468

1478-
sendTokenRefresh(vertx, testContext, body.getString("refresh_token"), body.getString("refresh_response_key"), 200, refreshRespJson ->
1479-
{
1469+
sendTokenRefresh(vertx, testContext, body.getString("refresh_token"), body.getString("refresh_response_key"), 200, refreshRespJson -> {
14801470
assertEquals("optout", refreshRespJson.getString("status"));
14811471
JsonObject refreshBody = refreshRespJson.getJsonObject("body");
14821472
assertNull(refreshBody);
@@ -1491,10 +1481,12 @@ void tokenGenerateOptOutToken(String policyParameterKey, String identity, Identi
14911481
}
14921482

14931483
@ParameterizedTest // TODO: remove test after optout check phase 3
1494-
@CsvSource({"policy,[email protected],Email",
1484+
@CsvSource({
1485+
"policy,[email protected],Email",
14951486
"policy,+01234567890,Phone",
14961487
"optout_check,[email protected],Email",
1497-
"optout_check,+01234567890,Phone"})
1488+
"optout_check,+01234567890,Phone"
1489+
})
14981490
void tokenGenerateOptOutTokenWithDisableOptoutTokenFF(String policyParameterKey, String identity, IdentityType identityType,
14991491
Vertx vertx, VertxTestContext testContext) {
15001492
ClientKey oldClientKey = new ClientKey(
@@ -1637,8 +1629,7 @@ void tokenGenerateThenRefresh(String contentType, Vertx vertx, VertxTestContext
16371629

16381630
when(this.optOutStore.getLatestEntry(any())).thenReturn(null);
16391631

1640-
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson ->
1641-
{
1632+
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson -> {
16421633
assertEquals("success", refreshRespJson.getString("status"));
16431634
JsonObject refreshBody = refreshRespJson.getJsonObject("body");
16441635
assertNotNull(refreshBody);
@@ -1697,8 +1688,7 @@ void tokenGenerateThenRefreshSaltsExpired(Vertx vertx, VertxTestContext testCont
16971688

16981689
when(this.optOutStore.getLatestEntry(any())).thenReturn(null);
16991690

1700-
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson ->
1701-
{
1691+
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson -> {
17021692
assertEquals("success", refreshRespJson.getString("status"));
17031693
JsonObject refreshBody = refreshRespJson.getJsonObject("body");
17041694
assertNotNull(refreshBody);
@@ -1760,16 +1750,14 @@ void tokenGenerateThenRefreshNoActiveKey(Vertx vertx, VertxTestContext testConte
17601750
String genRefreshToken = bodyJson.getString("refresh_token");
17611751

17621752
setupKeys(true);
1763-
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 500, refreshRespJson ->
1764-
{
1753+
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 500, refreshRespJson -> {
17651754
assertFalse(refreshRespJson.containsKey("body"));
17661755
assertEquals("No active encryption key available", refreshRespJson.getString("message"));
17671756
testContext.completeNow();
17681757
}, Map.of(ClientVersionHeader, androidClientVersionHeaderValue));
17691758
});
17701759
}
17711760

1772-
17731761
@Test
17741762
void tokenGenerateThenValidateWithEmail_Match(Vertx vertx, VertxTestContext testContext) {
17751763
final int clientSiteId = 201;
@@ -2713,8 +2701,7 @@ void tokenGenerateThenRefreshForPhone(Vertx vertx, VertxTestContext testContext)
27132701

27142702
when(this.optOutStore.getLatestEntry(any())).thenReturn(null);
27152703

2716-
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson ->
2717-
{
2704+
sendTokenRefresh(vertx, testContext, genRefreshToken, bodyJson.getString("refresh_response_key"), 200, refreshRespJson -> {
27182705
assertEquals("success", refreshRespJson.getString("status"));
27192706
JsonObject refreshBody = refreshRespJson.getJsonObject("body");
27202707
assertNotNull(refreshBody);
@@ -3216,7 +3203,7 @@ void cstgNoIdentityHashProvided(Vertx vertx, VertxTestContext testContext) throw
32163203
@ParameterizedTest
32173204
@CsvSource({
32183205
"https://blahblah.com",
3219-
"http://local1host:8080", //intentionally spelling localhost wrong here!
3206+
"http://local1host:8080" //intentionally spelling localhost wrong here!
32203207
})
32213208
void cstgDomainNameCheckFails(String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
32223209
setupCstgBackend();
@@ -3245,7 +3232,7 @@ void cstgDomainNameCheckFails(String httpOrigin, Vertx vertx, VertxTestContext t
32453232
@CsvSource({
32463233
"''", // An empty quoted value results in the empty string.
32473234
"com.123",
3248-
"com.",
3235+
"com."
32493236
})
32503237
void cstgAppNameCheckFails(String appName, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
32513238
setupCstgBackend(Collections.emptyList(), List.of("com.123.Game.App.android"));
@@ -3275,7 +3262,7 @@ void cstgAppNameCheckFails(String appName, Vertx vertx, VertxTestContext testCon
32753262

32763263
@ParameterizedTest
32773264
@CsvSource({
3278-
"http://gototest.com",
3265+
"http://gototest.com"
32793266
})
32803267
void cstgDomainNameCheckFailsAndLogInvalidHttpOrigin(String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
32813268
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>();
@@ -3382,7 +3369,7 @@ void cstgDisabledAsUnauthorized(Vertx vertx, VertxTestContext testContext) throw
33823369

33833370
@ParameterizedTest
33843371
@CsvSource({
3385-
"http://gototest.com",
3372+
"http://gototest.com"
33863373
})
33873374
void cstgDomainNameCheckFailsAndLogSeveralInvalidHttpOrigin(String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
33883375
ListAppender<ILoggingEvent> logWatcher = new ListAppender<>();
@@ -3425,7 +3412,7 @@ void cstgDomainNameCheckFailsAndLogSeveralInvalidHttpOrigin(String httpOrigin, V
34253412
@CsvSource({
34263413
"https://cstg.co.uk",
34273414
"https://cstg2.com",
3428-
"http://localhost:8080",
3415+
"http://localhost:8080"
34293416
})
34303417
void cstgDomainNameCheckPasses(String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
34313418
setupCstgBackend("cstg.co.uk", "cstg2.com", "localhost");
@@ -3452,7 +3439,7 @@ void cstgDomainNameCheckPasses(String httpOrigin, Vertx vertx, VertxTestContext
34523439
@CsvSource({
34533440
"com.123.Game.App.android",
34543441
"com.123.game.app.android",
3455-
"123456789",
3442+
"123456789"
34563443
})
34573444
void cstgAppNameCheckPasses(String appName, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
34583445
setupCstgBackend(Collections.emptyList(), List.of("com.123.Game.App.android", "123456789"));
@@ -4034,7 +4021,7 @@ void cstgUserOptsOutAfterTokenGenerate(String id, IdentityType identityType, Ver
40344021
"true,[email protected],Email",
40354022
"true,+61400000000,Phone",
40364023
"false,[email protected],Email",
4037-
"false,+61400000000,Phone",
4024+
"false,+61400000000,Phone"
40384025
})
40394026
void cstgSuccessForBothOptedAndNonOptedOutTest(boolean optOutExpected, String id, IdentityType identityType,
40404027
Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
@@ -4088,8 +4075,7 @@ void cstgSuccessForBothOptedAndNonOptedOutTest(boolean optOutExpected, String id
40884075

40894076
String genRefreshToken = genBody.getString("refresh_token");
40904077
//test a subsequent refresh from this cstg call and see if it still works
4091-
sendTokenRefresh(vertx, testContext, genRefreshToken, genBody.getString("refresh_response_key"), 200, refreshRespJson ->
4092-
{
4078+
sendTokenRefresh(vertx, testContext, genRefreshToken, genBody.getString("refresh_response_key"), 200, refreshRespJson -> {
40934079
assertEquals("success", refreshRespJson.getString("status"));
40944080
JsonObject refreshBody = refreshRespJson.getJsonObject("body");
40954081
assertNotNull(refreshBody);
@@ -4122,7 +4108,7 @@ void cstgSuccessForBothOptedAndNonOptedOutTest(boolean optOutExpected, String id
41224108
@CsvSource({
41234109
"https://cstg.co.uk",
41244110
"https://cstg2.com",
4125-
"http://localhost:8080",
4111+
"http://localhost:8080"
41264112
})
41274113
void cstgSaltsExpired(String httpOrigin, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
41284114
when(saltProviderSnapshot.getExpires()).thenReturn(Instant.now().minus(1, ChronoUnit.HOURS));
@@ -4171,7 +4157,7 @@ void cstgNoActiveKey(Vertx vertx, VertxTestContext testContext) throws NoSuchAlg
41714157
@ParameterizedTest
41724158
@CsvSource({
41734159
"email_hash,[email protected]",
4174-
"phone_hash,1234567890",
4160+
"phone_hash,1234567890"
41754161
})
41764162
void cstgInvalidInput(String identityType, String rawUID, Vertx vertx, VertxTestContext testContext) throws NoSuchAlgorithmException, InvalidKeyException {
41774163
setupCstgBackend("cstg.co.uk");
@@ -5307,7 +5293,7 @@ void identityBucketsAlwaysReturnMilliseconds(Vertx vertx, VertxTestContext testC
53075293

53085294
// SaltEntry with a lastUpdated that has 0 milliseconds
53095295
long lastUpdatedMillis = Instant.parse("2024-01-01T00:00:00Z").toEpochMilli();
5310-
SaltEntry bucketEntry = new SaltEntry(456, "hashed456", lastUpdatedMillis, "salt456", null, null, null, null);
5296+
SaltEntry bucketEntry = new SaltEntry(456, "hashed456", lastUpdatedMillis, "salt456", 1000L, null, null, null);
53115297
when(saltProviderSnapshot.getModifiedSince(any())).thenReturn(List.of(bucketEntry));
53125298

53135299
String sinceTimestamp = "2023-12-31T00:00:00"; // earlier timestamp

0 commit comments

Comments
 (0)