Skip to content

Commit

Permalink
Make context field in imp.ext to be not required if null
Browse files Browse the repository at this point in the history
  • Loading branch information
rpanchyk committed Jun 3, 2020
1 parent 5db231d commit 815e083
Show file tree
Hide file tree
Showing 46 changed files with 71 additions and 126 deletions.
5 changes: 4 additions & 1 deletion src/main/java/org/prebid/server/auction/ExchangeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ private ObjectNode prepareImpExt(String bidder, ObjectNode impExt, boolean useFi
final ObjectNode result = mapper.mapper().valueToTree(ExtPrebid.of(impExt.get(PREBID_EXT), impExt.get(bidder)));

if (useFirstPartyData) {
result.set(CONTEXT_EXT, impExt.get(CONTEXT_EXT));
final JsonNode contextNode = impExt.get(CONTEXT_EXT);
if (contextNode != null && !contextNode.isNull()) {
result.set(CONTEXT_EXT, contextNode);
}
}

return result;
Expand Down
40 changes: 15 additions & 25 deletions src/test/java/org/prebid/server/auction/ExchangeServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,10 @@ public void shouldTolerateMissingPrebidImpExtension() {
exchangeService.holdAuction(givenRequestContext(bidRequest));

// then
final ObjectNode expectedExtImp = mapper.valueToTree(ExtPrebid.of(null, 1));
expectedExtImp.set("context", null);
final BidRequest capturedBidRequest = captureBidRequest();
assertThat(capturedBidRequest.getImp()).hasSize(1)
.element(0).returns(expectedExtImp, Imp::getExt);
.element(0)
.returns(mapper.valueToTree(ExtPrebid.of(null, 1)), Imp::getExt);
}

@Test
Expand All @@ -294,8 +293,6 @@ public void shouldExtractRequestWithBidderSpecificExtension() {

// then
final BidRequest capturedBidRequest = captureBidRequest();
final ObjectNode expectedExtImp = mapper.valueToTree(ExtPrebid.of(0, 1));
expectedExtImp.set("context", null);
assertThat(capturedBidRequest).isEqualTo(BidRequest.builder()
.id("requestId")
.cur(singletonList("USD"))
Expand All @@ -304,10 +301,9 @@ public void shouldExtractRequestWithBidderSpecificExtension() {
.banner(Banner.builder()
.format(singletonList(Format.builder().w(400).h(300).build()))
.build())
.ext(expectedExtImp)
.ext(mapper.valueToTree(ExtPrebid.of(0, 1)))
.build()))
.tmax(500L)

.build());
}

Expand Down Expand Up @@ -337,8 +333,6 @@ public void shouldExtractRequestWithCurrencyRatesExtension() {

// then
final BidRequest capturedBidRequest = captureBidRequest();
final ObjectNode expectedExtImp = mapper.valueToTree(ExtPrebid.of(0, 1));
expectedExtImp.set("context", null);
assertThat(capturedBidRequest).isEqualTo(BidRequest.builder()
.id("requestId")
.cur(singletonList("USD"))
Expand All @@ -347,7 +341,7 @@ public void shouldExtractRequestWithCurrencyRatesExtension() {
.banner(Banner.builder()
.format(singletonList(Format.builder().w(400).h(300).build()))
.build())
.ext(expectedExtImp)
.ext(mapper.valueToTree(ExtPrebid.of(0, 1)))
.build()))
.ext(mapper.valueToTree(
ExtRequestPrebid.builder().currency(ExtRequestCurrency.of(currencyRates)).build()))
Expand Down Expand Up @@ -630,21 +624,19 @@ public void shouldTolerateBidderResultWithoutBids() {
@Test
public void shouldReturnSeparateSeatBidsForTheSameBidderIfBiddersAliasAndBidderWereUsedWithingSingleImp() {
// given
final ObjectNode expectedExtImp1 = mapper.valueToTree(ExtPrebid.of(null, 1));
expectedExtImp1.set("context", null);
given(httpBidderRequester.requestBids(any(), eq(givenBidRequest(givenSingleImp(expectedExtImp1),
builder -> builder.ext(mapper.valueToTree(ExtBidRequest.of(ExtRequestPrebid.builder()
.auctiontimestamp(1000L)
.aliases(singletonMap("bidderAlias", "bidder")).build()))))), any(), anyBoolean()))
given(httpBidderRequester.requestBids(any(),
eq(givenBidRequest(givenSingleImp(mapper.valueToTree(ExtPrebid.of(null, 1))),
builder -> builder.ext(mapper.valueToTree(ExtBidRequest.of(ExtRequestPrebid.builder()
.auctiontimestamp(1000L)
.aliases(singletonMap("bidderAlias", "bidder")).build()))))), any(), anyBoolean()))
.willReturn(Future.succeededFuture(givenSeatBid(singletonList(
givenBid(Bid.builder().price(BigDecimal.ONE).build())))));

final ObjectNode expectedExtImp2 = mapper.valueToTree(ExtPrebid.of(null, 2));
expectedExtImp2.set("context", null);
given(httpBidderRequester.requestBids(any(), eq(givenBidRequest(givenSingleImp(expectedExtImp2),
builder -> builder.ext(mapper.valueToTree(ExtBidRequest.of(ExtRequestPrebid.builder()
.auctiontimestamp(1000L)
.aliases(singletonMap("bidderAlias", "bidder")).build()))))), any(), anyBoolean()))
given(httpBidderRequester.requestBids(any(),
eq(givenBidRequest(givenSingleImp(mapper.valueToTree(ExtPrebid.of(null, 2))),
builder -> builder.ext(mapper.valueToTree(ExtBidRequest.of(ExtRequestPrebid.builder()
.auctiontimestamp(1000L)
.aliases(singletonMap("bidderAlias", "bidder")).build()))))), any(), anyBoolean()))
.willReturn(Future.succeededFuture(givenSeatBid(singletonList(
givenBid(Bid.builder().price(BigDecimal.ONE).build())))));

Expand Down Expand Up @@ -954,8 +946,6 @@ public void shouldCreateRequestsFromImpsReturnedByStoredResponseProcessor() {

// then
final BidRequest capturedBidRequest = captureBidRequest();
final ObjectNode expectedExtImp = mapper.valueToTree(ExtPrebid.of(0, 1));
expectedExtImp.set("context", null);
assertThat(capturedBidRequest).isEqualTo(BidRequest.builder()
.id("requestId")
.cur(singletonList("USD"))
Expand All @@ -964,7 +954,7 @@ public void shouldCreateRequestsFromImpsReturnedByStoredResponseProcessor() {
.banner(Banner.builder()
.format(singletonList(Format.builder().w(400).h(300).build()))
.build())
.ext(expectedExtImp)
.ext(mapper.valueToTree(ExtPrebid.of(0, 1)))
.build()))
.tmax(500L)
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"ext": {
"bidder": {
"placementId": "some_placement_id"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"ext": {
"bidder": {
"token": "1234"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"ext": {
"bidder": {
"token": "12345"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
"ext": {
"bidder": {
"publisher": "businessinsider"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"ext": {
"bidder": {
"site_id": "siteId2"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"ext": {
"bidder": {
"site_id": "siteId"
},
"context": null
}
}
},
{
Expand All @@ -36,8 +35,7 @@
"ext": {
"bidder": {
"site_id": "siteId"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,13 @@
"datablocks": [
{
"uri": "{{ datablocks.exchange_uri }}?sid=2",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId002\",\"video\":{\"mimes\":[\"video/mp4\"],\"w\":300,\"h\":250,\"pos\":1},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":2},\"context\":null}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"DB-UID\",\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId002\",\"video\":{\"mimes\":[\"video/mp4\"],\"w\":300,\"h\":250,\"pos\":1},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":2}}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"DB-UID\",\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid002\",\"impid\":\"impId002\",\"price\":9.99,\"crid\":\"crid002\",\"cid\":\"cid002\",\"adomain\":[\"psacentral.org\"],\"h\":250,\"w\":300}],\"seat\":\"datablocks\"}]}",
"status": 200
},
{
"uri": "{{ datablocks.exchange_uri }}?sid=1",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId001\",\"banner\":{\"format\":[{\"w\":300,\"h\":250}]},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":1},\"context\":null}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"DB-UID\",\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"impId001\",\"banner\":{\"format\":[{\"w\":300,\"h\":250}]},\"ext\":{\"bidder\":{\"host\":\"localhost:8090\",\"sourceId\":1}}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"buyeruid\":\"DB-UID\",\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"bid001\",\"impid\":\"impId001\",\"price\":7.77,\"adid\":\"adid001\",\"crid\":\"crid001\",\"cid\":\"cid001\",\"adm\":\"adm001\",\"h\":250,\"w\":300}],\"seat\":\"datablocks\"}]}",
"status": 200
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"bidder": {
"host": "localhost:8090",
"sourceId": 1
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
"bidder": {
"host": "localhost:8090",
"sourceId": 2
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
"ext": {
"bidder": {
"sspid": "99999"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"ext": {
"bidder": {
"sspid": "88888"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"ext": {
"bidder": {
"supplyPartnerId": "1701"
},
"context": null
}
}
},
{
Expand All @@ -36,8 +35,7 @@
"ext": {
"bidder": {
"supplyPartnerId": "1707"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
]
},
"ext": {
"bidder": {},
"context": null
"bidder": {}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"ext": {
"bidder": {
"zone": "first_zone"
},
"context": null
}
}
},
{
Expand All @@ -35,8 +34,7 @@
"ext": {
"bidder": {
"zone": "second_zone"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"w": 300,
"h": 250
}
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"ext": {
"bidder": {
"siteId": "10002"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
"ext": {
"bidder": {
"siteId": "10002"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"kubient": [
{
"uri": "{{ kubient.exchange_uri }}",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"test-imp-banner-id\",\"banner\":{\"format\":[{\"w\":300,\"h\":250}],\"w\":500,\"h\":400},\"ext\":{\"bidder\":{},\"context\":null}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"aliases\":{\"appnexusAlias\":\"appnexus\",\"conversantAlias\":\"conversant\"},\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"requestbody": "{\"id\":\"tid\",\"imp\":[{\"id\":\"test-imp-banner-id\",\"banner\":{\"format\":[{\"w\":300,\"h\":250}],\"w\":500,\"h\":400},\"ext\":{\"bidder\":{}}}],\"site\":{\"domain\":\"example.com\",\"page\":\"http://www.example.com\",\"publisher\":{\"id\":\"publisherId\"},\"ext\":{\"amp\":0}},\"device\":{\"ua\":\"userAgent\",\"dnt\":2,\"ip\":\"193.168.244.1\",\"pxratio\":4.2,\"language\":\"en\",\"ifa\":\"ifaId\"},\"user\":{\"ext\":{\"consent\":\"consentValue\",\"digitrust\":{\"id\":\"id\",\"keyv\":123,\"pref\":0}}},\"at\":1,\"tmax\":5000,\"cur\":[\"USD\"],\"source\":{\"fd\":1,\"tid\":\"tid\"},\"regs\":{\"ext\":{\"gdpr\":0}},\"ext\":{\"prebid\":{\"debug\":1,\"aliases\":{\"appnexusAlias\":\"appnexus\",\"conversantAlias\":\"conversant\"},\"currency\":{\"rates\":{\"EUR\":{\"USD\":1.2406},\"USD\":{\"EUR\":0.811}}},\"targeting\":{\"pricegranularity\":{\"precision\":2,\"ranges\":[{\"max\":20,\"increment\":0.1}]},\"includewinners\":true,\"includebidderkeys\":true},\"cache\":{\"bids\":{},\"vastxml\":{\"ttlseconds\":120}},\"auctiontimestamp\":1000}}}",
"responsebody": "{\"id\":\"tid\",\"seatbid\":[{\"bid\":[{\"id\":\"7706636740145184841\",\"impid\":\"test-imp-banner-id\",\"price\":0.5,\"adid\":\"29681110\",\"adm\":\"some-test-ad\",\"adomain\":[\"advertsite.com\"],\"cid\":\"772\",\"crid\":\"29681110\",\"h\":576,\"w\":1024}]}]}",
"status": 200
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"h": 400
},
"ext": {
"bidder": {},
"context": null
"bidder": {}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"ext": {
"bidder": {
"slot_tag": "slot.tag"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"ext": {
"bidder": {
"slot_tag": "slot.tag"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
"ext": {
"bidder": {
"adUnitId": "test_adUnitId"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
"ext": {
"bidder": {
"zone": "zone_1"
},
"context": null
}
}
},
{
Expand All @@ -32,8 +31,7 @@
"ext": {
"bidder": {
"zone": "zone_2"
},
"context": null
}
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
"placementId": "456",
"bidfloor": 1.1,
"cur": "GBP"
},
"context": null
}
}
}
],
Expand Down
Loading

0 comments on commit 815e083

Please sign in to comment.