Skip to content

Commit

Permalink
Adocean: Use partially dynamic hostnames instead of fully dynamic (#2585
Browse files Browse the repository at this point in the history
)
  • Loading branch information
And1sS authored Sep 4, 2023
1 parent 05857d0 commit 2b95029
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 37 deletions.
12 changes: 10 additions & 2 deletions src/main/java/org/prebid/server/bidder/adocean/AdoceanBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public class AdoceanBidder implements Bidder<Void> {
private static final TypeReference<ExtPrebid<?, ExtImpAdocean>> ADOCEAN_EXT_TYPE_REFERENCE =
new TypeReference<>() {
};
private static final String VERSION = "1.2.0";
private static final String VERSION = "1.3.0";
private static final int MAX_URI_LENGTH = 8000;
private static final String MEASUREMENT_CODE_TEMPLATE = """
<script> +function() {
Expand Down Expand Up @@ -83,6 +83,8 @@ public Result<List<HttpRequest<Void>>> makeHttpRequests(BidRequest request) {
for (Imp imp : request.getImp()) {
try {
final ExtImpAdocean extImpAdocean = parseImpExt(imp);
validateImpExt(extImpAdocean);

final Map<String, String> slaveSizes = new HashMap<>();
slaveSizes.put(extImpAdocean.getSlaveId(), getImpSizes(imp));
if (addRequestAndCheckIfDuplicates(httpRequests, extImpAdocean, imp.getId(), slaveSizes,
Expand All @@ -107,6 +109,12 @@ private ExtImpAdocean parseImpExt(Imp imp) {
}
}

private static void validateImpExt(ExtImpAdocean impExt) {
if (StringUtils.isEmpty(impExt.getEmitterPrefix())) {
throw new PreBidException("No emitterPrefix param");
}
}

private boolean addRequestAndCheckIfDuplicates(List<HttpRequest<Void>> httpRequests, ExtImpAdocean extImpAdocean,
String impid, Map<String, String> slaveSizes, Integer test) {
for (HttpRequest<Void> request : httpRequests) {
Expand Down Expand Up @@ -254,7 +262,7 @@ private String buildUrl(String impId, ExtImpAdocean extImpAdocean, String consen
}

private String resolveEndpointUrl(ExtImpAdocean extImpAdocean, Integer test) {
final String url = endpointUrl.replace("{{Host}}", Objects.toString(extImpAdocean.getEmitterDomain(), ""));
final String url = endpointUrl.replace("{{Host}}", extImpAdocean.getEmitterPrefix());
final int randomizedPart = Objects.equals(test, 1) ? 10000000 : 10000000 + (int) (Math.random() * 89999999);
return "%s/_%s/ad.json".formatted(url, randomizedPart);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
@Value
public class ExtImpAdocean {

@JsonProperty("emiter")
String emitterDomain;
@JsonProperty("emitterPrefix")
String emitterPrefix;

@JsonProperty("masterId")
String masterId;
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/bidder-config/adocean.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
adapters:
adocean:
endpoint: https://{{Host}}
endpoint: https://{{Host}}.adocean.pl
meta-info:
maintainer-email: [email protected]
app-media-types:
Expand Down
24 changes: 22 additions & 2 deletions src/main/resources/static/bidder-params/adocean.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@
"properties": {
"emiter": {
"type": "string",
"description": "AdOcean emiter",
"description": "Deprecated, use emitterPrefix instead. AdOcean emiter",
"pattern": ".+"
},
"emitterPrefix": {
"type": "string",
"description": "AdOcean emitter prefix",
"pattern": "^[\\w\\-]+$"
},
"masterId": {
"type": "string",
"description": "Master's id",
Expand All @@ -20,5 +25,20 @@
"pattern": "^adocean[\\w.]+$"
}
},
"required": ["emiter", "masterId", "slaveId"]
"oneOf": [
{
"required": [
"emiter",
"masterId",
"slaveId"
]
},
{
"required": [
"emitterPrefix",
"masterId",
"slaveId"
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.prebid.server.bidder.model.HttpRequest;
import org.prebid.server.bidder.model.HttpResponse;
import org.prebid.server.bidder.model.Result;
import org.prebid.server.bidder.smartrtb.SmartrtbBidder;
import org.prebid.server.proto.openrtb.ext.ExtPrebid;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.adocean.ExtImpAdocean;
Expand All @@ -46,18 +45,16 @@ public class AdoceanBidderTest extends VertxTest {

private static final String ENDPOINT_URL = "https://{{Host}}";

private AdoceanBidder adoceanBidder;
private AdoceanBidder target;

@Before
public void setUp() {
adoceanBidder = new AdoceanBidder(ENDPOINT_URL, jacksonMapper);
target = new AdoceanBidder(ENDPOINT_URL, jacksonMapper);
}

@Test
public void creationShouldFailOnInvalidEndpointUrl() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new SmartrtbBidder("invalid_url", jacksonMapper))
.withMessage("URL supplied is not valid: invalid_url");
assertThatIllegalArgumentException().isThrownBy(() -> new AdoceanBidder("invalid_url", jacksonMapper));
}

@Test
Expand All @@ -68,7 +65,7 @@ public void makeHttpRequestsShouldReturnErrorIfImpExtCouldNotBeParsed() {
.id("123")
.ext(mapper.valueToTree(ExtPrebid.of(null, mapper.createArrayNode()))));
// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors())
Expand All @@ -93,7 +90,7 @@ public void makeHttpRequestsShouldReturnErrorIfEndpointUrlComposingFails() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).hasSize(1)
Expand All @@ -103,6 +100,54 @@ public void makeHttpRequestsShouldReturnErrorIfEndpointUrlComposingFails() {
});
}

@Test
public void makeHttpRequestsShouldReturnErrorIfExtImpEmitterPrefixIsEmpty() {
// given
final BidRequest bidRequest = BidRequest.builder()
.user(User.builder()
.ext(ExtUser.builder()
.consent("consent").build())
.build())
.imp(singletonList(Imp.builder()
.id("ao-test")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpAdocean.of("", "masterId", "adoceanmyaozpniqismex")))).build()))
.test(1)
.build();

// when
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).containsExactly(BidderError.badInput("No emitterPrefix param"));
}

@Test
public void makeHttpRequestsShouldReturnErrorIfExtImpEmitterPrefixIsNotSupplied() {
// given
final BidRequest bidRequest = BidRequest.builder()
.user(User.builder()
.ext(ExtUser.builder()
.consent("consent").build())
.build())
.imp(singletonList(Imp.builder()
.id("ao-test")
.banner(Banner.builder().build())
.ext(mapper.valueToTree(ExtPrebid.of(null,
ExtImpAdocean.of(null, "masterId", "adoceanmyaozpniqismex")))).build()))
.test(1)
.build();

// when
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).containsExactly(BidderError.badInput("No emitterPrefix param"));
}

@Test
public void makeHttpRequestsShouldCreateRequestForEveryValidImp() {
// given
Expand Down Expand Up @@ -132,18 +177,18 @@ public void makeHttpRequestsShouldCreateRequestForEveryValidImp() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors())
.containsExactly(BidderError.badInput("Error parsing adOceanExt parameters, "
+ "in imp with id : notValidImp"));
assertThat(result.getValue()).hasSize(2)
.extracting(HttpRequest::getUri)
.containsExactly("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0&id=masterId&nc=1"
.containsExactly("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0&id=masterId&nc=1"
+ "&nosecure=1&aid=adoceanmyaozpniqismex%3Aao-test&gdpr_consent=consent&gdpr=1"
+ "&hcuserid=testBuyerUid&aosspsizes=myaozpniqismex"
+ "%7E300x250_600x320", "https://em.dom/_10000000/ad.json?pbsrv_v=1.2.0&id="
+ "%7E300x250_600x320", "https://em.dom/_10000000/ad.json?pbsrv_v=1.3.0&id="
+ "masterId2&nc=1&nosecure=1&aid=slaveId%3Ai2-test&gdpr_consent=consent&gdpr=1"
+ "&hcuserid=testBuyerUid&aosspsizes=slaveId%7E577x333");
}
Expand Down Expand Up @@ -174,7 +219,7 @@ public void makeHttpRequestsShouldCreateUniqueRequestIfMasterIdEqualsAndSlaveIdE
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(2);
Expand All @@ -198,13 +243,13 @@ public void makeHttpRequestsShouldCreateRequestWithoutSizeIfBannerSizesNotPresen
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue())
.extracting(HttpRequest::getUri)
.containsExactly("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0&id=masterId&nc=1&nosecure=1"
.containsExactly("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0&id=masterId&nc=1&nosecure=1"
+ "&aid=adoceanmyaozpniqismex%3Aao-test&gdpr_consent=consent&gdpr=1");
}

Expand Down Expand Up @@ -234,12 +279,12 @@ public void makeHttpRequestsShouldUpdateRequestsForSimilarSlaveIds() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0&id=masterId&nc=1"
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0&id=masterId&nc=1"
+ "&nosecure=1&aid=slaveId%3Aao-test&gdpr_consent=consent&gdpr=1&hcuserid=testBuyerUid"
+ "&aosspsizes=slaveId%7E300x250_600x320&aid=slaveId2%3Ai2-test&aosspsizes=slaveId2%7E577x333");
}
Expand Down Expand Up @@ -267,7 +312,7 @@ public void makeHttpRequestsShouldSetExpectedHeadersIfDeviceIpIsPresent() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue().get(0).getHeaders()).isNotNull()
Expand Down Expand Up @@ -298,7 +343,7 @@ public void makeHttpRequestsShouldSetExpectedHeadersIfDeviceIpv6IsPresent() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue().get(0).getHeaders()).isNotNull()
Expand All @@ -315,7 +360,7 @@ public void makeBidsShouldReturnErrorIfResponseBodyCouldNotBeParsed() throws Jso
final BidderCall<Void> httpCall = givenHttpCall(null, "");

// when
final Result<List<BidderBid>> result = adoceanBidder.makeBids(httpCall, null);
final Result<List<BidderBid>> result = target.makeBids(httpCall, null);

// then
assertThat(result.getErrors()).hasSize(1)
Expand All @@ -341,7 +386,7 @@ public void makeBidsShouldReturnCorrectBidderBid() throws JsonProcessingExceptio
final BidderCall<Void> httpCall = givenHttpCall(null, mapper.writeValueAsString(adoceanResponseAdUnit));

// when
final Result<List<BidderBid>> result = adoceanBidder.makeBids(httpCall, bidRequest);
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
final String adm = """
Expand Down Expand Up @@ -383,7 +428,7 @@ public void makeBidsShouldReturnEmptyListOfBids() throws JsonProcessingException
final BidderCall<Void> httpCall = givenHttpCall(null, mapper.writeValueAsString(adoceanResponseAdUnit));

// when
final Result<List<BidderBid>> result = adoceanBidder.makeBids(httpCall, bidRequest);
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getErrors()).isEmpty();
Expand All @@ -409,12 +454,12 @@ public void makeHttpRequestsShouldBuildUrlIfAppIsPresent() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0"
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0"
+ "&id=tmYF.DMl7ZBq.Nqt2Bq4FutQTJfTpxCOmtNPZoQUDcL.G7&nc=1&nosecure=1"
+ "&aid=adoceanmyaozpniqismex%3Aao-test&gdpr_consent=consent"
+ "&gdpr=1&app=1&appname=name&appbundle=bundle&appdomain=domain");
Expand All @@ -439,12 +484,12 @@ public void makeHttpRequestsShouldBuildUrlIfDeviceWithIfaIsPresent() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0"
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0"
+ "&id=tmYF.DMl7ZBq.Nqt2Bq4FutQTJfTpxCOmtNPZoQUDcL.G7"
+ "&nc=1&nosecure=1&aid=adoceanmyaozpniqismex%3Aao-test"
+ "&gdpr_consent=consent&gdpr=1&ifa=ifa&devos=os&devosv=osv&devmodel=model&devmake=make");
Expand All @@ -469,12 +514,12 @@ public void makeHttpRequestsShouldBuildUrlIfDeviceWithIfaIsNotPresent() {
.build();

// when
final Result<List<HttpRequest<Void>>> result = adoceanBidder.makeHttpRequests(bidRequest);
final Result<List<HttpRequest<Void>>> result = target.makeHttpRequests(bidRequest);

// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.2.0"
.containsExactlyInAnyOrder("https://myao.adocean.pl/_10000000/ad.json?pbsrv_v=1.3.0"
+ "&id=tmYF.DMl7ZBq.Nqt2Bq4FutQTJfTpxCOmtNPZoQUDcL.G7"
+ "&nc=1&nosecure=1&aid=adoceanmyaozpniqismex%3Aao-test"
+ "&gdpr_consent=consent&gdpr=1&dpidmd5=dpidmd5&devos=os&devosv=osv"
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/org/prebid/server/it/AdoceanTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void openrtb2AuctionShouldRespondWithBidsFromAdocean() throws IOException
Endpoint.openrtb2_auction);

// then
assertJsonEquals("openrtb2/adocean/test-auction-adocean-response.json", response,
singletonList("adocean"));
assertJsonEquals("openrtb2/adocean/test-auction-adocean-response.json", response, singletonList("adocean"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"prebid": {
"bidder": {
"adocean": {
"emiter": "myao.adocean.pl",
"emitterPrefix": "myao",
"masterId": "tmYF.DMl7ZBq.Nqt2Bq4FutQTJfTpxCOmtNPZoQUDcL.G7",
"slaveId": "adoceanmyaozpniqismex"
}
Expand Down

0 comments on commit 2b95029

Please sign in to comment.