6464
6565import javax .crypto .SecretKey ;
6666import java .math .BigInteger ;
67- import java .net .URLEncoder ;
6867import java .nio .charset .StandardCharsets ;
6968import java .security .*;
7069import 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
@@ -233,14 +231,6 @@ private void clearAuth() {
233231 when (clientKeyProvider .get (any ())).thenReturn (null );
234232 }
235233
236- private static String urlEncode (String value ) {
237- try {
238- return URLEncoder .encode (value , StandardCharsets .UTF_8 );
239- } catch (Exception e ) {
240- return null ;
241- }
242- }
243-
244234 private String getUrlForEndpoint (String endpoint ) {
245235 return String .format ("http://127.0.0.1:%d/%s" , Const .Port .ServicePortForOperator + Utils .getPortOffset (), endpoint );
246236 }
@@ -282,7 +272,6 @@ protected void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expe
282272 sendTokenGenerate (vertx , v2PostPayload , expectedHttpCode , null , handler , true , Collections .emptyMap ());
283273 }
284274
285-
286275 protected void sendTokenGenerate (Vertx vertx , JsonObject v2PostPayload , int expectedHttpCode ,
287276 Handler <JsonObject > handler , Map <String , String > additionalHeaders ) {
288277 sendTokenGenerate (vertx , v2PostPayload , expectedHttpCode , null , handler , true , additionalHeaders );
@@ -298,7 +287,6 @@ private void sendTokenGenerate(Vertx vertx, JsonObject v2PostPayload, int expect
298287 }
299288
300289 private void sendTokenGenerate (Vertx vertx , JsonObject v2PostPayload , int expectedHttpCode , String referer , Handler <JsonObject > handler , boolean additionalParams , Map <String , String > additionalHeaders ) {
301-
302290 ClientKey ck = (ClientKey ) clientKeyProvider .get ("" );
303291
304292 long nonce = new BigInteger (Random .getBytes (8 )).longValue ();
@@ -1204,7 +1192,8 @@ void v3IdentityMapMissingValidInputKeys(String inputPayload, Vertx vertx, VertxT
12041192 }
12051193
12061194 @ ParameterizedTest
1207- @ ValueSource (strings = {"{\" invalid_key\" : []}" ,
1195+ @ ValueSource (strings = {
1196+ "{\" invalid_key\" : []}" ,
12081197 "{\" email\" : [ null ]}" ,
12091198 "{\" email\" : [ \" some_email\" , null ]}"
12101199 })
@@ -1409,10 +1398,12 @@ void tokenGenerateNewClientWrongPolicySpecifiedOlderKeySuccessful(String policyP
14091398 }
14101399
14111400 @ ParameterizedTest // TODO: remove test after optout check phase 3
1412- @ CsvSource ({"policy,someoptout@example.com,Email" ,
1401+ @ CsvSource ({
1402+ "policy,someoptout@example.com,Email" ,
14131403 "policy,+01234567890,Phone" ,
14141404 "optout_check,someoptout@example.com,Email" ,
1415- "optout_check,+01234567890,Phone" })
1405+ "optout_check,+01234567890,Phone"
1406+ })
14161407 void tokenGenerateOptOutToken (String policyParameterKey , String identity , IdentityType identityType ,
14171408 Vertx vertx , VertxTestContext testContext ) {
14181409 ClientKey oldClientKey = new ClientKey (
@@ -1476,8 +1467,7 @@ void tokenGenerateOptOutToken(String policyParameterKey, String identity, Identi
14761467 TokenResponseStatsCollector .ResponseStatus .Success ,
14771468 TokenResponseStatsCollector .PlatformType .Other );
14781469
1479- sendTokenRefresh (vertx , testContext , body .getString ("refresh_token" ), body .getString ("refresh_response_key" ), 200 , refreshRespJson ->
1480- {
1470+ sendTokenRefresh (vertx , testContext , body .getString ("refresh_token" ), body .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
14811471 assertEquals ("optout" , refreshRespJson .getString ("status" ));
14821472 JsonObject refreshBody = refreshRespJson .getJsonObject ("body" );
14831473 assertNull (refreshBody );
@@ -1492,10 +1482,12 @@ void tokenGenerateOptOutToken(String policyParameterKey, String identity, Identi
14921482 }
14931483
14941484 @ ParameterizedTest // TODO: remove test after optout check phase 3
1495- @ CsvSource ({"policy,someoptout@example.com,Email" ,
1485+ @ CsvSource ({
1486+ "policy,someoptout@example.com,Email" ,
14961487 "policy,+01234567890,Phone" ,
14971488 "optout_check,someoptout@example.com,Email" ,
1498- "optout_check,+01234567890,Phone" })
1489+ "optout_check,+01234567890,Phone"
1490+ })
14991491 void tokenGenerateOptOutTokenWithDisableOptoutTokenFF (String policyParameterKey , String identity , IdentityType identityType ,
15001492 Vertx vertx , VertxTestContext testContext ) {
15011493 ClientKey oldClientKey = new ClientKey (
@@ -1638,8 +1630,7 @@ void tokenGenerateThenRefresh(String contentType, Vertx vertx, VertxTestContext
16381630
16391631 when (this .optOutStore .getLatestEntry (any ())).thenReturn (null );
16401632
1641- sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson ->
1642- {
1633+ sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
16431634 assertEquals ("success" , refreshRespJson .getString ("status" ));
16441635 JsonObject refreshBody = refreshRespJson .getJsonObject ("body" );
16451636 assertNotNull (refreshBody );
@@ -1698,8 +1689,7 @@ void tokenGenerateThenRefreshSaltsExpired(Vertx vertx, VertxTestContext testCont
16981689
16991690 when (this .optOutStore .getLatestEntry (any ())).thenReturn (null );
17001691
1701- sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson ->
1702- {
1692+ sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
17031693 assertEquals ("success" , refreshRespJson .getString ("status" ));
17041694 JsonObject refreshBody = refreshRespJson .getJsonObject ("body" );
17051695 assertNotNull (refreshBody );
@@ -1761,16 +1751,14 @@ void tokenGenerateThenRefreshNoActiveKey(Vertx vertx, VertxTestContext testConte
17611751 String genRefreshToken = bodyJson .getString ("refresh_token" );
17621752
17631753 setupKeys (true );
1764- sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 500 , refreshRespJson ->
1765- {
1754+ sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 500 , refreshRespJson -> {
17661755 assertFalse (refreshRespJson .containsKey ("body" ));
17671756 assertEquals ("No active encryption key available" , refreshRespJson .getString ("message" ));
17681757 testContext .completeNow ();
17691758 }, Map .of (ClientVersionHeader , androidClientVersionHeaderValue ));
17701759 });
17711760 }
17721761
1773-
17741762 @ Test
17751763 void tokenGenerateThenValidateWithEmail_Match (Vertx vertx , VertxTestContext testContext ) {
17761764 final int clientSiteId = 201 ;
@@ -2714,8 +2702,7 @@ void tokenGenerateThenRefreshForPhone(Vertx vertx, VertxTestContext testContext)
27142702
27152703 when (this .optOutStore .getLatestEntry (any ())).thenReturn (null );
27162704
2717- sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson ->
2718- {
2705+ sendTokenRefresh (vertx , testContext , genRefreshToken , bodyJson .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
27192706 assertEquals ("success" , refreshRespJson .getString ("status" ));
27202707 JsonObject refreshBody = refreshRespJson .getJsonObject ("body" );
27212708 assertNotNull (refreshBody );
@@ -3217,7 +3204,7 @@ void cstgNoIdentityHashProvided(Vertx vertx, VertxTestContext testContext) throw
32173204 @ ParameterizedTest
32183205 @ CsvSource ({
32193206 "https://blahblah.com" ,
3220- "http://local1host:8080" , //intentionally spelling localhost wrong here!
3207+ "http://local1host:8080" //intentionally spelling localhost wrong here!
32213208 })
32223209 void cstgDomainNameCheckFails (String httpOrigin , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
32233210 setupCstgBackend ();
@@ -3246,7 +3233,7 @@ void cstgDomainNameCheckFails(String httpOrigin, Vertx vertx, VertxTestContext t
32463233 @ CsvSource ({
32473234 "''" , // An empty quoted value results in the empty string.
32483235 "com.123" ,
3249- "com." ,
3236+ "com."
32503237 })
32513238 void cstgAppNameCheckFails (String appName , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
32523239 setupCstgBackend (Collections .emptyList (), List .of ("com.123.Game.App.android" ));
@@ -3276,7 +3263,7 @@ void cstgAppNameCheckFails(String appName, Vertx vertx, VertxTestContext testCon
32763263
32773264 @ ParameterizedTest
32783265 @ CsvSource ({
3279- "http://gototest.com" ,
3266+ "http://gototest.com"
32803267 })
32813268 void cstgDomainNameCheckFailsAndLogInvalidHttpOrigin (String httpOrigin , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
32823269 ListAppender <ILoggingEvent > logWatcher = new ListAppender <>();
@@ -3383,7 +3370,7 @@ void cstgDisabledAsUnauthorized(Vertx vertx, VertxTestContext testContext) throw
33833370
33843371 @ ParameterizedTest
33853372 @ CsvSource ({
3386- "http://gototest.com" ,
3373+ "http://gototest.com"
33873374 })
33883375 void cstgDomainNameCheckFailsAndLogSeveralInvalidHttpOrigin (String httpOrigin , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
33893376 ListAppender <ILoggingEvent > logWatcher = new ListAppender <>();
@@ -3426,7 +3413,7 @@ void cstgDomainNameCheckFailsAndLogSeveralInvalidHttpOrigin(String httpOrigin, V
34263413 @ CsvSource ({
34273414 "https://cstg.co.uk" ,
34283415 "https://cstg2.com" ,
3429- "http://localhost:8080" ,
3416+ "http://localhost:8080"
34303417 })
34313418 void cstgDomainNameCheckPasses (String httpOrigin , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
34323419 setupCstgBackend ("cstg.co.uk" , "cstg2.com" , "localhost" );
@@ -3453,7 +3440,7 @@ void cstgDomainNameCheckPasses(String httpOrigin, Vertx vertx, VertxTestContext
34533440 @ CsvSource ({
34543441 "com.123.Game.App.android" ,
34553442 "com.123.game.app.android" ,
3456- "123456789" ,
3443+ "123456789"
34573444 })
34583445 void cstgAppNameCheckPasses (String appName , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
34593446 setupCstgBackend (Collections .emptyList (), List .of ("com.123.Game.App.android" , "123456789" ));
@@ -4035,7 +4022,7 @@ void cstgUserOptsOutAfterTokenGenerate(String id, IdentityType identityType, Ver
40354022 "true,abc@abc.com,Email" ,
40364023 "true,+61400000000,Phone" ,
40374024 "false,abc@abc.com,Email" ,
4038- "false,+61400000000,Phone" ,
4025+ "false,+61400000000,Phone"
40394026 })
40404027 void cstgSuccessForBothOptedAndNonOptedOutTest (boolean optOutExpected , String id , IdentityType identityType ,
40414028 Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
@@ -4089,8 +4076,7 @@ void cstgSuccessForBothOptedAndNonOptedOutTest(boolean optOutExpected, String id
40894076
40904077 String genRefreshToken = genBody .getString ("refresh_token" );
40914078 //test a subsequent refresh from this cstg call and see if it still works
4092- sendTokenRefresh (vertx , testContext , genRefreshToken , genBody .getString ("refresh_response_key" ), 200 , refreshRespJson ->
4093- {
4079+ sendTokenRefresh (vertx , testContext , genRefreshToken , genBody .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
40944080 assertEquals ("success" , refreshRespJson .getString ("status" ));
40954081 JsonObject refreshBody = refreshRespJson .getJsonObject ("body" );
40964082 assertNotNull (refreshBody );
@@ -4123,7 +4109,7 @@ void cstgSuccessForBothOptedAndNonOptedOutTest(boolean optOutExpected, String id
41234109 @ CsvSource ({
41244110 "https://cstg.co.uk" ,
41254111 "https://cstg2.com" ,
4126- "http://localhost:8080" ,
4112+ "http://localhost:8080"
41274113 })
41284114 void cstgSaltsExpired (String httpOrigin , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
41294115 when (saltProviderSnapshot .getExpires ()).thenReturn (Instant .now ().minus (1 , ChronoUnit .HOURS ));
@@ -4172,7 +4158,7 @@ void cstgNoActiveKey(Vertx vertx, VertxTestContext testContext) throws NoSuchAlg
41724158 @ ParameterizedTest
41734159 @ CsvSource ({
41744160 "email_hash,random@unifiedid.com" ,
4175- "phone_hash,1234567890" ,
4161+ "phone_hash,1234567890"
41764162 })
41774163 void cstgInvalidInput (String identityType , String rawUID , Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
41784164 setupCstgBackend ("cstg.co.uk" );
@@ -5308,7 +5294,7 @@ void identityBucketsAlwaysReturnMilliseconds(Vertx vertx, VertxTestContext testC
53085294
53095295 // SaltEntry with a lastUpdated that has 0 milliseconds
53105296 long lastUpdatedMillis = Instant .parse ("2024-01-01T00:00:00Z" ).toEpochMilli ();
5311- SaltEntry bucketEntry = new SaltEntry (456 , "hashed456" , lastUpdatedMillis , "salt456" , null , null , null , null );
5297+ SaltEntry bucketEntry = new SaltEntry (456 , "hashed456" , lastUpdatedMillis , "salt456" , 1000L , null , null , null );
53125298 when (saltProviderSnapshot .getModifiedSince (any ())).thenReturn (List .of (bucketEntry ));
53135299
53145300 String sinceTimestamp = "2023-12-31T00:00:00" ; // earlier timestamp
0 commit comments