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
@@ -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+ 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+ 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
4034402140354022 "true,+61400000000,Phone" ,
403640234037- "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 ({
417341594174- "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