Skip to content

Commit

Permalink
Fixed igi validations.
Browse files Browse the repository at this point in the history
  • Loading branch information
And1sS committed Jan 15, 2025
1 parent 5163003 commit 7fd613e
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 11 deletions.
20 changes: 13 additions & 7 deletions src/main/java/org/prebid/server/auction/BidResponseCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
import org.prebid.server.proto.openrtb.ext.response.ExtDebugTrace;
import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgb;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgs;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgsExt;
import org.prebid.server.proto.openrtb.ext.response.ExtResponseCache;
Expand Down Expand Up @@ -864,13 +865,18 @@ private ExtIgi prepareExtIgi(ExtIgi igi, String bidder) {
return null;
}

if (StringUtils.isEmpty(igi.getImpid())) {
conditionalLogger.warn("ExtIgi with absent impId", logSamplingRate);
return null;
boolean shouldDropIgb = StringUtils.isEmpty(igi.getImpid());
if (shouldDropIgb) {
conditionalLogger.warn("ExtIgi with absent impId from bidder: " + bidder, logSamplingRate);
}

final List<ExtIgiIgs> preparedIgs = prepareExtIgiIgs(igi.getIgs(), bidder);
return igi.toBuilder().igs(preparedIgs.isEmpty() ? null : preparedIgs).build();
final List<ExtIgiIgs> updatedIgs = prepareExtIgiIgs(igi.getIgs(), bidder);
final List<ExtIgiIgs> preparedIgs = updatedIgs.isEmpty() ? null : updatedIgs;
final List<ExtIgiIgb> preparedIgb = shouldDropIgb ? null : igi.getIgb();

return ObjectUtils.anyNotNull(preparedIgs, preparedIgb)
? igi.toBuilder().igs(preparedIgs).igb(preparedIgb).build()
: null;
}

private List<ExtIgiIgs> prepareExtIgiIgs(List<ExtIgiIgs> igiIgs, String bidder) {
Expand All @@ -885,12 +891,12 @@ private List<ExtIgiIgs> prepareExtIgiIgs(List<ExtIgiIgs> igiIgs, String bidder)
}

if (StringUtils.isEmpty(extIgiIgs.getImpId())) {
conditionalLogger.warn("ExtIgiIgs with absent impId", logSamplingRate);
conditionalLogger.warn("ExtIgiIgs with absent impId from bidder: " + bidder, logSamplingRate);
continue;
}

if (extIgiIgs.getConfig() == null) {
conditionalLogger.warn("ExtIgiIgs with absent config", logSamplingRate);
conditionalLogger.warn("ExtIgiIgs with absent config from bidder: " + bidder, logSamplingRate);
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
import org.prebid.server.proto.openrtb.ext.response.ExtDebugTrace;
import org.prebid.server.proto.openrtb.ext.response.ExtHttpCall;
import org.prebid.server.proto.openrtb.ext.response.ExtIgi;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgb;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgs;
import org.prebid.server.proto.openrtb.ext.response.ExtIgiIgsExt;
import org.prebid.server.proto.openrtb.ext.response.ExtResponseCache;
Expand Down Expand Up @@ -3744,14 +3745,16 @@ public void shouldDefaultToOriginalPaaFormat() {
}

@Test
public void shouldDropExtIgiIfAvailableAndExtIgiImpIdIsAbsent() {
public void shouldDropExtIgiIgbIfAvailableAndExtIgiImpIdIsAbsent() {
// given
given(bidderCatalog.resolveBaseBidder("bidder1")).willReturn("adapter1");
final Imp imp = givenImp("impId").toBuilder()
.ext(mapper.createObjectNode().put("ae", 1))
.build();
final BidRequest bidRequest = givenBidRequest(identity(), ext -> ext.paaFormat(PaaFormat.IAB), imp);
final ExtIgi igi = ExtIgi.builder()
.igs(singletonList(ExtIgiIgs.builder().impId("impId").config(mapper.createObjectNode()).build()))
.igb(singletonList(ExtIgiIgb.builder().build()))
.build();

final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(2.37)).impid("impId").build();
Expand All @@ -3774,7 +3777,16 @@ public void shouldDropExtIgiIfAvailableAndExtIgiImpIdIsAbsent() {
// then
assertThat(bidResponse.getExt())
.extracting(ExtBidResponse::getIgi)
.isNull();
.asList()
.containsExactly(
ExtIgi.builder()
.igs(singletonList(
ExtIgiIgs.builder()
.impId("impId")
.config(mapper.createObjectNode())
.ext(ExtIgiIgsExt.of("bidder1", "adapter1"))
.build()))
.build());
}

@Test
Expand All @@ -3787,6 +3799,7 @@ public void shouldDropExtIgiIgsIfAvailableAndExtIgiIgsImpIdIsAbsent() {
final ExtIgi igi = ExtIgi.builder()
.impid("impId")
.igs(singletonList(ExtIgiIgs.builder().config(mapper.createObjectNode()).build()))
.igb(singletonList(ExtIgiIgb.builder().build()))
.build();

final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(2.37)).impid("impId").build();
Expand All @@ -3810,7 +3823,11 @@ public void shouldDropExtIgiIgsIfAvailableAndExtIgiIgsImpIdIsAbsent() {
assertThat(bidResponse.getExt())
.extracting(ExtBidResponse::getIgi)
.asList()
.containsExactly(ExtIgi.builder().impid("impId").build());
.containsExactly(
ExtIgi.builder()
.impid("impId")
.igb(singletonList(ExtIgiIgb.builder().build()))
.build());
}

@Test
Expand All @@ -3823,6 +3840,7 @@ public void shouldDropExtIgiIgsIfAvailableAndExtIgiIgsConfigIsAbsent() {
final ExtIgi igi = ExtIgi.builder()
.impid("impId")
.igs(singletonList(ExtIgiIgs.builder().impId("impId").build()))
.igb(singletonList(ExtIgiIgb.builder().build()))
.build();

final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(2.37)).impid("impId").build();
Expand All @@ -3846,7 +3864,45 @@ public void shouldDropExtIgiIgsIfAvailableAndExtIgiIgsConfigIsAbsent() {
assertThat(bidResponse.getExt())
.extracting(ExtBidResponse::getIgi)
.asList()
.containsExactly(ExtIgi.builder().impid("impId").build());
.containsExactly(
ExtIgi.builder()
.impid("impId")
.igb(singletonList(ExtIgiIgb.builder().build()))
.build());
}

@Test
public void shouldDropExtIgiIfAvailableAndExtIgiIgsAndExtIgiIgbAreAbsent() {
// given
final Imp imp = givenImp("impId").toBuilder()
.ext(mapper.createObjectNode().put("ae", 1))
.build();
final BidRequest bidRequest = givenBidRequest(identity(), ext -> ext.paaFormat(PaaFormat.IAB), imp);
final ExtIgi igi = ExtIgi.builder()
.impid("impId")
.build();

final Bid bid = Bid.builder().id("bidId1").price(BigDecimal.valueOf(2.37)).impid("impId").build();
final List<BidderResponse> bidderResponses = singletonList(
BidderResponse.of("bidder1",
BidderSeatBid.builder()
.bids(List.of(BidderBid.of(bid, banner, "USD")))
.igi(singletonList(igi))
.build(), 100));

final AuctionContext auctionContext = givenAuctionContext(
bidRequest,
contextBuilder -> contextBuilder.auctionParticipations(toAuctionParticipant(bidderResponses)));

// when
final BidResponse bidResponse = target
.create(auctionContext, CACHE_INFO, MULTI_BIDS)
.result();

// then
assertThat(bidResponse.getExt())
.extracting(ExtBidResponse::getIgi)
.isNull();
}

@Test
Expand Down

0 comments on commit 7fd613e

Please sign in to comment.