5353import org .mockito .ArgumentCaptor ;
5454import org .mockito .Mock ;
5555import org .mockito .MockitoAnnotations ;
56+ import org .mockito .junit .jupiter .MockitoExtension ;
57+ import org .mockito .junit .jupiter .MockitoSettings ;
58+ import org .mockito .quality .Strictness ;
5659import org .slf4j .LoggerFactory ;
5760import static org .assertj .core .api .Assertions .*;
5861
7982import static org .mockito .ArgumentMatchers .any ;
8083import static org .mockito .Mockito .*;
8184
82- @ ExtendWith (VertxExtension .class )
85+ @ ExtendWith ({VertxExtension .class , MockitoExtension .class })
86+ @ MockitoSettings (strictness = Strictness .LENIENT )
8387public class UIDOperatorVerticleTest {
8488 private final Instant now = Instant .now ().truncatedTo (ChronoUnit .MILLIS );
8589 private static final Instant legacyClientCreationDateTime = Instant .ofEpochSecond (OPT_OUT_CHECK_CUTOFF_DATE ).minus (1 , ChronoUnit .SECONDS );
@@ -102,21 +106,34 @@ public class UIDOperatorVerticleTest {
102106
103107 private static final int optOutStatusMaxRequestSize = 1000 ;
104108
105- private AutoCloseable mocks ;
106- @ Mock private ISiteStore siteProvider ;
107- @ Mock private IClientKeyProvider clientKeyProvider ;
108- @ Mock private IClientSideKeypairStore clientSideKeypairProvider ;
109- @ Mock private IClientSideKeypairStore .IClientSideKeypairStoreSnapshot clientSideKeypairSnapshot ;
110- @ Mock private IKeysetKeyStore keysetKeyStore ;
111- @ Mock private RotatingKeysetProvider keysetProvider ;
112- @ Mock private ISaltProvider saltProvider ;
113- @ Mock private SecureLinkValidatorService secureLinkValidatorService ;
114- @ Mock private ISaltProvider .ISaltSnapshot saltProviderSnapshot ;
115- @ Mock private IOptOutStore optOutStore ;
116- @ Mock private Clock clock ;
117- @ Mock private IStatsCollectorQueue statsCollectorQueue ;
118- @ Mock private OperatorShutdownHandler shutdownHandler ;
119- @ Mock private IConfigStore configStore ;
109+ @ Mock
110+ private ISiteStore siteProvider ;
111+ @ Mock
112+ private IClientKeyProvider clientKeyProvider ;
113+ @ Mock
114+ private IClientSideKeypairStore clientSideKeypairProvider ;
115+ @ Mock
116+ private IClientSideKeypairStore .IClientSideKeypairStoreSnapshot clientSideKeypairSnapshot ;
117+ @ Mock
118+ private IKeysetKeyStore keysetKeyStore ;
119+ @ Mock
120+ private RotatingKeysetProvider keysetProvider ;
121+ @ Mock
122+ private ISaltProvider saltProvider ;
123+ @ Mock
124+ private SecureLinkValidatorService secureLinkValidatorService ;
125+ @ Mock
126+ private ISaltProvider .ISaltSnapshot saltProviderSnapshot ;
127+ @ Mock
128+ private IOptOutStore optOutStore ;
129+ @ Mock
130+ private Clock clock ;
131+ @ Mock
132+ private IStatsCollectorQueue statsCollectorQueue ;
133+ @ Mock
134+ private OperatorShutdownHandler shutdownHandler ;
135+ @ Mock
136+ private IConfigStore configStore ;
120137
121138 private SimpleMeterRegistry registry ;
122139 private ExtendedUIDOperatorVerticle uidOperatorVerticle ;
@@ -125,7 +142,6 @@ public class UIDOperatorVerticleTest {
125142
126143 @ BeforeEach
127144 public void deployVerticle (Vertx vertx , VertxTestContext testContext , TestInfo testInfo ) {
128- mocks = MockitoAnnotations .openMocks (this );
129145 when (saltProvider .getSnapshot (any ())).thenReturn (saltProviderSnapshot );
130146 when (saltProviderSnapshot .getExpires ()).thenReturn (Instant .now ().plus (1 , ChronoUnit .HOURS ));
131147 when (clock .instant ()).thenAnswer (i -> now );
@@ -156,7 +172,6 @@ public void deployVerticle(Vertx vertx, VertxTestContext testContext, TestInfo t
156172 @ AfterEach
157173 public void teardown () throws Exception {
158174 Metrics .globalRegistry .remove (registry );
159- mocks .close ();
160175 }
161176
162177 private RuntimeConfig setupRuntimeConfig (JsonObject config ) {
@@ -885,7 +900,7 @@ void identityMapNewClientNoPolicySpecified(String apiVersion, Vertx vertx, Vertx
885900
886901 // the clock value shouldn't matter here
887902 when (optOutStore .getLatestEntry (any (UserIdentity .class )))
888- .thenReturn (now .minus (1 , ChronoUnit .HOURS ));
903+ .thenReturn (now .minus (1 , ChronoUnit .HOURS ));
889904
890905 JsonObject req = new JsonObject ();
891906 JsonArray emails = new JsonArray ();
@@ -912,7 +927,7 @@ void identityMapNewClientWrongPolicySpecified(String apiVersion, String policyPa
912927 setupKeys ();
913928 // the clock value shouldn't matter here
914929 when (optOutStore .getLatestEntry (any (UserIdentity .class )))
915- .thenReturn (now .minus (1 , ChronoUnit .HOURS ));
930+ .thenReturn (now .minus (1 , ChronoUnit .HOURS ));
916931 JsonObject req = new JsonObject ();
917932 JsonArray emails = new JsonArray ();
918933 emails .add ("random-optout-user@email.io" );
@@ -1146,7 +1161,7 @@ void tokenGenerateNewClientWrongPolicySpecifiedOlderKeySuccessful(String policyP
11461161 "optout_check,someoptout@example.com,Email" ,
11471162 "optout_check,+01234567890,Phone" })
11481163 void tokenGenerateOptOutToken (String policyParameterKey , String identity , IdentityType identityType ,
1149- Vertx vertx , VertxTestContext testContext ) {
1164+ Vertx vertx , VertxTestContext testContext ) {
11501165 ClientKey oldClientKey = new ClientKey (
11511166 null ,
11521167 null ,
@@ -1229,7 +1244,7 @@ void tokenGenerateOptOutToken(String policyParameterKey, String identity, Identi
12291244 "optout_check,someoptout@example.com,Email" ,
12301245 "optout_check,+01234567890,Phone" })
12311246 void tokenGenerateOptOutTokenWithDisableOptoutTokenFF (String policyParameterKey , String identity , IdentityType identityType ,
1232- Vertx vertx , VertxTestContext testContext ) {
1247+ Vertx vertx , VertxTestContext testContext ) {
12331248 ClientKey oldClientKey = new ClientKey (
12341249 null ,
12351250 null ,
@@ -2321,9 +2336,9 @@ void identityMapBatchRequestTooLarge(String apiVersion, Vertx vertx, VertxTestCo
23212336
23222337 private static Stream <Arguments > optOutStatusRequestData () {
23232338 List <String > rawUIDS = Arrays .asList ("RUQbFozFwnmPVjDx8VMkk9vJoNXUJImKnz2h9RfzzM24" ,
2324- "qAmIGxqLk_RhOtm4f1nLlqYewqSma8fgvjEXYnQ3Jr0K" ,
2325- "r3wW2uvJkwmeFcbUwSeM6BIpGF8tX38wtPfVc4wYyo71" ,
2326- "e6SA-JVAXnvk8F1MUtzsMOyWuy5Xqe15rLAgqzSGiAbz" );
2339+ "qAmIGxqLk_RhOtm4f1nLlqYewqSma8fgvjEXYnQ3Jr0K" ,
2340+ "r3wW2uvJkwmeFcbUwSeM6BIpGF8tX38wtPfVc4wYyo71" ,
2341+ "e6SA-JVAXnvk8F1MUtzsMOyWuy5Xqe15rLAgqzSGiAbz" );
23272342 Map <String , Long > optedOutIdsCase1 = new HashMap <>();
23282343
23292344 optedOutIdsCase1 .put (rawUIDS .get (0 ), Instant .now ().minus (1 , ChronoUnit .DAYS ).getEpochSecond ());
@@ -2335,10 +2350,10 @@ private static Stream<Arguments> optOutStatusRequestData() {
23352350 optedOutIdsCase2 .put (rawUIDS .get (2 ), -1L );
23362351 optedOutIdsCase2 .put (rawUIDS .get (3 ), -1L );
23372352 return Stream .of (
2338- Arguments .arguments (optedOutIdsCase1 , 2 , Role .MAPPER ),
2339- Arguments .arguments (optedOutIdsCase1 , 2 , Role .ID_READER ),
2340- Arguments .arguments (optedOutIdsCase1 , 2 , Role .SHARER ),
2341- Arguments .arguments (optedOutIdsCase2 , 0 , Role .MAPPER )
2353+ Arguments .arguments (optedOutIdsCase1 , 2 , Role .MAPPER ),
2354+ Arguments .arguments (optedOutIdsCase1 , 2 , Role .ID_READER ),
2355+ Arguments .arguments (optedOutIdsCase1 , 2 , Role .SHARER ),
2356+ Arguments .arguments (optedOutIdsCase2 , 0 , Role .MAPPER )
23422357 );
23432358 }
23442359
@@ -3554,15 +3569,15 @@ void cstgNoBody(Vertx vertx, VertxTestContext testContext) {
35543569 setupCstgBackend ("cstg.co.uk" );
35553570
35563571 postCstg (vertx ,
3557- "v2/token/client-generate" ,
3558- "https://cstg.co.uk" ,
3559- null ,
3560- testContext .succeeding (result -> testContext .verify (() -> {
3561- JsonObject response = result .bodyAsJsonObject ();
3562- assertEquals ("client_error" , response .getString ("status" ));
3563- assertEquals ("json payload expected but not found" , response .getString ("message" ));
3564- testContext .completeNow ();
3565- })));
3572+ "v2/token/client-generate" ,
3573+ "https://cstg.co.uk" ,
3574+ null ,
3575+ testContext .succeeding (result -> testContext .verify (() -> {
3576+ JsonObject response = result .bodyAsJsonObject ();
3577+ assertEquals ("client_error" , response .getString ("status" ));
3578+ assertEquals ("json payload expected but not found" , response .getString ("message" ));
3579+ testContext .completeNow ();
3580+ })));
35663581 }
35673582
35683583 @ Test
@@ -3571,12 +3586,12 @@ void cstgForInvalidJsonPayloadReturns400(Vertx vertx, VertxTestContext testConte
35713586
35723587 WebClient client = WebClient .create (vertx );
35733588 client .postAbs (getUrlForEndpoint ("v2/token/client-generate" ))
3574- .putHeader (ORIGIN_HEADER , "https://cstg.co.uk" )
3575- .putHeader ("Content-Type" , "application/json" )
3576- .sendBuffer (Buffer .buffer ("not a valid json payload" ), result -> testContext .verify (() -> {
3577- assertEquals (400 , result .result ().statusCode ());
3578- testContext .completeNow ();
3579- }));
3589+ .putHeader (ORIGIN_HEADER , "https://cstg.co.uk" )
3590+ .putHeader ("Content-Type" , "application/json" )
3591+ .sendBuffer (Buffer .buffer ("not a valid json payload" ), result -> testContext .verify (() -> {
3592+ assertEquals (400 , result .result ().statusCode ());
3593+ testContext .completeNow ();
3594+ }));
35803595 }
35813596
35823597 @ ParameterizedTest
@@ -4023,7 +4038,7 @@ else if(identityType == IdentityType.Phone) {
40234038 else { //can't be other types
40244039 assertFalse (true );
40254040 }
4026-
4041+
40274042 return createClientSideTokenGenerateRequestWithPayload (identity , timestamp , appName );
40284043 }
40294044
@@ -4071,7 +4086,7 @@ void cstgUserOptsOutAfterTokenGenerate(String id, IdentityType identityType, Ver
40714086
40724087 // When we refresh the token the user has opted out.
40734088 when (optOutStore .getLatestEntry (any (UserIdentity .class )))
4074- .thenReturn (advertisingToken .userIdentity .establishedAt .plusSeconds (1 ));
4089+ .thenReturn (advertisingToken .userIdentity .establishedAt .plusSeconds (1 ));
40754090
40764091 sendTokenRefresh ("v2" , vertx , testContext , genBody .getString ("refresh_token" ), genBody .getString ("refresh_response_key" ), 200 , refreshRespJson -> {
40774092 assertEquals ("optout" , refreshRespJson .getString ("status" ));
@@ -4092,7 +4107,7 @@ void cstgUserOptsOutAfterTokenGenerate(String id, IdentityType identityType, Ver
40924107 "false,+61400000000,Phone" ,
40934108 })
40944109 void cstgSuccessForBothOptedAndNonOptedOutTest (boolean optOutExpected , String id , IdentityType identityType ,
4095- Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
4110+ Vertx vertx , VertxTestContext testContext ) throws NoSuchAlgorithmException , InvalidKeyException {
40964111 setupCstgBackend ("cstg.co.uk" );
40974112
40984113 Tuple .Tuple2 <JsonObject , SecretKey > data = createClientSideTokenGenerateRequest (identityType , id , Instant .now ().toEpochMilli ());
@@ -4716,20 +4731,20 @@ private static Stream<Arguments> testKeyDownloadEndpointKeysetsData_IDREADER() {
47164731 Map <Integer , Site > emptySites = new HashMap <>();
47174732 return Stream .of (
47184733 // Both domains and app names should be present in response
4719- Arguments .of ("true" , KeyDownloadEndpoint .SHARING , mockSitesWithBoth , expectedSitesWithBoth ),
4720- Arguments .of ("true" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithBoth , expectedSitesWithBoth ),
4734+ Arguments .of ("true" , KeyDownloadEndpoint .SHARING , mockSitesWithBoth , expectedSitesWithBoth ),
4735+ Arguments .of ("true" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithBoth , expectedSitesWithBoth ),
47214736
4722- // only domains should be present in response
4723- Arguments .of ("false" , KeyDownloadEndpoint .SHARING , mockSitesWithDomainsOnly , expectedSitesDomainsOnly ),
4724- Arguments .of ("false" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithDomainsOnly , expectedSitesDomainsOnly ),
4737+ // only domains should be present in response
4738+ Arguments .of ("false" , KeyDownloadEndpoint .SHARING , mockSitesWithDomainsOnly , expectedSitesDomainsOnly ),
4739+ Arguments .of ("false" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithDomainsOnly , expectedSitesDomainsOnly ),
47254740
4726- // only app names should be present in response
4727- Arguments .of ("true" , KeyDownloadEndpoint .SHARING , mockSitesWithAppNamesOnly , expectedSitesWithAppNamesOnly ),
4728- Arguments .of ("true" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithAppNamesOnly , expectedSitesWithAppNamesOnly ),
4741+ // only app names should be present in response
4742+ Arguments .of ("true" , KeyDownloadEndpoint .SHARING , mockSitesWithAppNamesOnly , expectedSitesWithAppNamesOnly ),
4743+ Arguments .of ("true" , KeyDownloadEndpoint .BIDSTREAM , mockSitesWithAppNamesOnly , expectedSitesWithAppNamesOnly ),
47294744
4730- // None
4731- Arguments .of ("false" , KeyDownloadEndpoint .SHARING , emptySites , emptySites ),
4732- Arguments .of ("false" , KeyDownloadEndpoint .BIDSTREAM , emptySites , emptySites )
4745+ // None
4746+ Arguments .of ("false" , KeyDownloadEndpoint .SHARING , emptySites , emptySites ),
4747+ Arguments .of ("false" , KeyDownloadEndpoint .BIDSTREAM , emptySites , emptySites )
47334748 );
47344749 }
47354750
@@ -4809,7 +4824,7 @@ void keySharingKeysets_SHARER_CustomMaxSharingLifetimeSeconds(Vertx vertx, Vertx
48094824 this .runtimeConfig = this .runtimeConfig .toBuilder ().withMaxSharingLifetimeSeconds (999999 ).build ();
48104825 keySharingKeysets_SHARER (true , true , vertx , testContext , 999999 );
48114826 }
4812-
4827+
48134828 @ ParameterizedTest
48144829 @ CsvSource ({
48154830 "true, true" ,
@@ -5226,7 +5241,7 @@ void keySharingRespectsConfigValues(Vertx vertx, VertxTestContext testContext) {
52265241 @ Test
52275242 void keyBidstreamRespectsConfigValues (Vertx vertx , VertxTestContext testContext ) {
52285243 int newMaxBidstreamLifetimeSeconds = 999999 ;
5229-
5244+
52305245 this .runtimeConfig = this .runtimeConfig
52315246 .toBuilder ()
52325247 .withMaxBidstreamLifetimeSeconds (newMaxBidstreamLifetimeSeconds )
@@ -5272,7 +5287,7 @@ void tokenGenerateRespectsConfigValuesWithRemoteConfig(Vertx vertx, VertxTestCon
52725287 .withRefreshTokenExpiresAfterSeconds ((int ) newRefreshExpiresAfter .toSeconds ())
52735288 .withRefreshIdentityTokenAfterSeconds ((int ) newRefreshIdentityAfter .toSeconds ())
52745289 .build ();
5275-
5290+
52765291 sendTokenGenerate ("v2" , vertx ,
52775292 null , v2Payload , 200 ,
52785293 respJson -> {
@@ -5297,7 +5312,7 @@ void keySharingRespectsConfigValuesWithRemoteConfig(Vertx vertx, VertxTestContex
52975312 .withSharingTokenExpirySeconds (newSharingTokenExpiry )
52985313 .withMaxSharingLifetimeSeconds (newMaxSharingLifetimeSeconds )
52995314 .build ();
5300-
5315+
53015316 String apiVersion = "v2" ;
53025317 int siteId = 5 ;
53035318 fakeAuth (siteId , Role .SHARER );
@@ -5325,12 +5340,12 @@ void keySharingRespectsConfigValuesWithRemoteConfig(Vertx vertx, VertxTestContex
53255340 @ Test
53265341 void keyBidstreamRespectsConfigValuesWithRemoteConfig (Vertx vertx , VertxTestContext testContext ) {
53275342 int newMaxBidstreamLifetimeSeconds = 999999 ;
5328-
5343+
53295344 this .runtimeConfig = this .runtimeConfig
53305345 .toBuilder ()
53315346 .withMaxBidstreamLifetimeSeconds (newMaxBidstreamLifetimeSeconds )
53325347 .build ();
5333-
5348+
53345349 final String apiVersion = "v2" ;
53355350 final KeyDownloadEndpoint endpoint = KeyDownloadEndpoint .BIDSTREAM ;
53365351
0 commit comments