@@ -375,14 +375,33 @@ public void callShouldReturnFailureWhenRequestingEidsIsFailed() {
375375 }
376376
377377 @ Test
378- public void biddersConfiguredRestrictionShouldBeRespected () {
378+ public void shouldRestrictExistingEidPermissionsByIntersectionAndKeepGlobalBiddersUnchanged () {
379+ // given
379380 final Uid givenUid = Uid .builder ().id ("id1" ).atype (2 ).build ();
380381 final Eid givenEid = Eid .builder ().source ("some.source.com" ).uids (singletonList (givenUid )).build ();
381382 final User givenUser = User .builder ().eids (singletonList (givenEid )).build ();
382- final BidRequest givenBidRequest = BidRequest .builder ().id ("request" ).user (givenUser ).build ();
383383
384- final ExtRequestPrebidData expectedData = ExtRequestPrebidData .of (configuredBidders , List .of (
385- ExtRequestPrebidDataEidPermissions .of ("liveintent.com" , configuredBidders )));
384+ // existing global bidders and eid permissions including liveintent.com
385+ final ExtRequestPrebidData givenData = ExtRequestPrebidData .of (
386+ List .of ("bidderX" ),
387+ List .of (
388+ ExtRequestPrebidDataEidPermissions .of ("some.other-source.com" , List .of ("bidderY" )),
389+ ExtRequestPrebidDataEidPermissions .of ("liveintent.com" , List .of ("bidder2" , "bidder3" ))
390+ ));
391+
392+ final BidRequest givenBidRequest = BidRequest .builder ()
393+ .id ("request" )
394+ .user (givenUser )
395+ .ext (ExtRequest .of (ExtRequestPrebid .builder ().data (givenData ).build ()))
396+ .build ();
397+
398+ // expected: global bidders unchanged, liveintent.com bidders intersected with configuredBidders => [bidder2]
399+ final ExtRequestPrebidData expectedData = ExtRequestPrebidData .of (
400+ List .of ("bidderX" ),
401+ List .of (
402+ ExtRequestPrebidDataEidPermissions .of ("some.other-source.com" , List .of ("bidderY" )),
403+ ExtRequestPrebidDataEidPermissions .of ("liveintent.com" , List .of ("bidder2" ))
404+ ));
386405
387406 final Eid expectedEid = Eid .builder ().source ("liveintent.com" ).build ();
388407
@@ -418,7 +437,7 @@ public void biddersConfiguredRestrictionShouldBeRespected() {
418437 }
419438
420439 @ Test
421- public void biddersConfiguredRestrictionShouldBeMergedWithProvided () {
440+ public void shouldNotAddNewEidPermissionsOrModifyGlobalBiddersWhenSourceNotPresent () {
422441 // given
423442 final Uid givenUid = Uid .builder ().id ("id1" ).atype (2 ).build ();
424443 final Eid givenEid = Eid .builder ().source ("some.source.com" ).uids (singletonList (givenUid )).build ();
@@ -429,12 +448,10 @@ public void biddersConfiguredRestrictionShouldBeMergedWithProvided() {
429448 ExtRequestPrebidDataEidPermissions .of ("some.source.com" , List .of ("bidder3" ))))
430449 ).build ())).build ();
431450
432- final List <String > expectedBidders = List .of ("bidder3" , "bidder2" , "bidder1" );
433-
434- final ExtRequestPrebidData expectedData = ExtRequestPrebidData .of (expectedBidders , List .of (
451+ // expected: unchanged, because there is no existing permission for liveintent.com
452+ final ExtRequestPrebidData expectedData = ExtRequestPrebidData .of (List .of ("bidder3" ), List .of (
435453 ExtRequestPrebidDataEidPermissions .of ("some.other-source.com" , List .of ("bidder3" )),
436- ExtRequestPrebidDataEidPermissions .of ("some.source.com" , List .of ("bidder3" )),
437- ExtRequestPrebidDataEidPermissions .of ("liveintent.com" , configuredBidders )));
454+ ExtRequestPrebidDataEidPermissions .of ("some.source.com" , List .of ("bidder3" ))));
438455
439456 final Eid expectedEid = Eid .builder ().source ("liveintent.com" ).build ();
440457
@@ -468,4 +485,64 @@ public void biddersConfiguredRestrictionShouldBeMergedWithProvided() {
468485 eq (MAPPER .encodeToString (givenBidRequest )),
469486 eq (5L ));
470487 }
488+
489+ @ Test
490+ public void shouldRemovePermissionWhenIntersectionIsEmpty () {
491+ // given
492+ final Uid givenUid = Uid .builder ().id ("id1" ).atype (2 ).build ();
493+ final Eid givenEid = Eid .builder ().source ("some.source.com" ).uids (singletonList (givenUid )).build ();
494+ final User givenUser = User .builder ().eids (singletonList (givenEid )).build ();
495+
496+ final ExtRequestPrebidData givenData = ExtRequestPrebidData .of (
497+ List .of ("bidderGlobal" ),
498+ List .of (
499+ ExtRequestPrebidDataEidPermissions .of ("liveintent.com" , List .of ("not-allowed" )),
500+ ExtRequestPrebidDataEidPermissions .of ("keep.com" , List .of ("bidderGlobal" ))
501+ ));
502+
503+ final BidRequest givenBidRequest = BidRequest .builder ()
504+ .id ("request" )
505+ .user (givenUser )
506+ .ext (ExtRequest .of (ExtRequestPrebid .builder ().data (givenData ).build ()))
507+ .build ();
508+
509+ // Respond with liveintent.com so that restriction is applied and becomes empty -> remove entry
510+ final Eid expectedEid = Eid .builder ().source ("liveintent.com" ).build ();
511+ final String responseBody = MAPPER .encodeToString (IdResResponse .of (List .of (expectedEid )));
512+ given (httpClient .post (any (), any (), any (), anyLong ()))
513+ .willReturn (Future .succeededFuture (HttpClientResponse .of (200 , null , responseBody )));
514+
515+ given (auctionInvocationContext .auctionContext ()).willReturn (auctionContext );
516+ given (auctionContext .getActivityInfrastructure ()).willReturn (activityInfrastructure );
517+ given (activityInfrastructure .isAllowed (any (), any ())).willReturn (true );
518+ given (userFpdActivityMask .maskUser (any (), eq (false ), eq (false )))
519+ .willAnswer (invocation -> invocation .getArgument (0 ));
520+ given (userFpdActivityMask .maskDevice (any (), eq (false ), eq (false )))
521+ .willAnswer (invocation -> invocation .getArgument (0 ));
522+
523+ // when
524+ final InvocationResult <AuctionRequestPayload > result =
525+ target .call (AuctionRequestPayloadImpl .of (givenBidRequest ), auctionInvocationContext ).result ();
526+
527+ // then
528+ final ExtRequestPrebidData expectedData = ExtRequestPrebidData .of (
529+ List .of ("bidderGlobal" ),
530+ List .of (
531+ ExtRequestPrebidDataEidPermissions .of ("keep.com" , List .of ("bidderGlobal" ))
532+ ));
533+
534+ assertThat (result .status ()).isEqualTo (InvocationStatus .success );
535+ assertThat (result .payloadUpdate ().apply (AuctionRequestPayloadImpl .of (givenBidRequest )))
536+ .extracting (AuctionRequestPayload ::bidRequest )
537+ .extracting (BidRequest ::getExt )
538+ .extracting (ExtRequest ::getPrebid )
539+ .extracting (ExtRequestPrebid ::getData )
540+ .isEqualTo (expectedData );
541+
542+ verify (httpClient ).post (
543+ eq ("https://test.com/idres" ),
544+ argThat (headers -> headers .contains ("Authorization" , "Bearer auth_token" , true )),
545+ eq (MAPPER .encodeToString (givenBidRequest )),
546+ eq (5L ));
547+ }
471548}
0 commit comments