Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add eids parameter to url of HttpRequest in AdformBidder #866

Merged
merged 5 commits into from
Sep 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public Result<List<HttpRequest<Void>>> makeHttpRequests(BidRequest request) {
.gdprApplies(requestUtil.getGdprApplies(request.getRegs()))
.consent(requestUtil.getConsent(extUser))
.currency(currency)
.eids(requestUtil.getEids(extUser, mapper))
.build());

final MultiMap headers = httpUtil.buildAdformHeaders(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ String buildAdformUrl(UrlParameters parameters) {
params.add("gdpr=" + parameters.getGdprApplies());
params.add("gdpr_consent=" + parameters.getConsent());

final String eids = parameters.getEids();
if (StringUtils.isNotEmpty(eids)) {
params.add("eids=" + eids);
}

final List<String> encodedMids = new ArrayList<>();
final List<Long> masterTagIds = parameters.getMasterTagIds();
final List<String> keyValues = parameters.getKeyValues();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.prebid.server.bidder.adform;

import com.iab.openrtb.request.Regs;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.prebid.server.bidder.adform.model.AdformDigitrust;
import org.prebid.server.bidder.adform.model.AdformDigitrustPrivacy;
import org.prebid.server.json.JacksonMapper;
import org.prebid.server.proto.openrtb.ext.request.ExtRegs;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.ExtUserDigiTrust;
import org.prebid.server.proto.openrtb.ext.request.ExtUserEid;
import org.prebid.server.proto.openrtb.ext.request.ExtUserEidUid;

import java.util.Base64;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Util class to help {@link org.prebid.server.bidder.adform.AdformBidder} and
Expand Down Expand Up @@ -47,4 +56,27 @@ AdformDigitrust getAdformDigitrust(ExtUser extUser) {
AdformDigitrustPrivacy.of(extUserDigiTrust.getPref() != 0))
: null;
}

/**
* Retrieves eids from user.ext.eids and in case of any exception or invalid values return empty collection.
*/
String getEids(ExtUser extUser, JacksonMapper mapper) {
AndriyPavlyuk marked this conversation as resolved.
Show resolved Hide resolved
final List<ExtUserEid> eids = extUser != null ? extUser.getEids() : null;
final Map<String, Map<String, Integer>> eidsMap = new HashMap<>();
if (CollectionUtils.isNotEmpty(eids)) {
for (ExtUserEid eid : eids) {
AndriyPavlyuk marked this conversation as resolved.
Show resolved Hide resolved
final Map<String, Integer> uidMap = eidsMap.computeIfAbsent(eid.getSource(),
ignored -> new HashMap<>());
for (ExtUserEidUid uid : eid.getUids()) {
uidMap.put(uid.getId(), uid.getAtype());
}
}
}

final String encodedEids = mapper.encode(eidsMap);

return ObjectUtils
.defaultIfNull(Base64.getUrlEncoder().withoutPadding().encodeToString(encodedEids.getBytes()),
"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ public class UrlParameters {
String consent;

String currency;

String eids;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public class ExtUserEidUid {

String id;

Integer atype;

ExtUserEidUidExt ext;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.prebid.server.proto.openrtb.ext.request.ExtRegs;
import org.prebid.server.proto.openrtb.ext.request.ExtUser;
import org.prebid.server.proto.openrtb.ext.request.ExtUserDigiTrust;
import org.prebid.server.proto.openrtb.ext.request.ExtUserEid;
import org.prebid.server.proto.openrtb.ext.request.ExtUserEidUid;
import org.prebid.server.proto.openrtb.ext.request.adform.ExtImpAdform;
import org.prebid.server.proto.openrtb.ext.response.BidType;
import org.prebid.server.util.HttpUtil;
Expand Down Expand Up @@ -66,6 +68,8 @@ public void makeHttpRequestsShouldReturnHttpRequestWithoutErrors() {
.ext(ExtUser.builder()
.consent("consent")
.digitrust(ExtUserDigiTrust.of("id", 123, 1))
.eids(singletonList(ExtUserEid.of("test.com", "some_user_id",
singletonList(ExtUserEidUid.of("uId", 1, null)), null)))
.build())
.build())
.device(Device.builder().ua("ua").ip("ip").ifa("ifaId").build())
Expand All @@ -81,8 +85,9 @@ public void makeHttpRequestsShouldReturnHttpRequestWithoutErrors() {
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactly(
"http://adform.com/openrtb2d?CC=1&adid=ifaId&fd=1&gdpr=1&gdpr_consent=consent&ip=ip&pt=gross"
+ "&rp=4&stid=tid&bWlkPTE1JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQmbWt3PXJlZA");
"http://adform.com/openrtb2d?CC=1&adid=ifaId&eids=eyJ0ZXN0LmNvbSI6eyJ1SWQiOjF9fQ&fd=1&gdpr=1"
+ "&gdpr_consent=consent&ip=ip&pt=gross&rp=4&stid=tid"
+ "&bWlkPTE1JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQmbWt3PXJlZA");
assertThat(result.getValue()).extracting(HttpRequest::getMethod).containsExactly(HttpMethod.GET);

assertThat(result.getValue())
Expand Down Expand Up @@ -172,6 +177,15 @@ public void makeHttpRequestsShouldReturnHttpsUrlIfAtLeastOneImpIsSecured() {
.build(),
Imp.builder().build()))
.source(Source.builder().tid("tid").build())
.user(User.builder()
.buyeruid("buyeruid")
.ext(ExtUser.builder()
.consent("consent")
.digitrust(ExtUserDigiTrust.of("id", 123, 1))
.eids(singletonList(ExtUserEid.of("test.com", "some_user_id",
singletonList(ExtUserEidUid.of("uId", 1, null)), null)))
.build())
.build())
.build();

// when
Expand All @@ -180,8 +194,8 @@ public void makeHttpRequestsShouldReturnHttpsUrlIfAtLeastOneImpIsSecured() {
// then
assertThat(result.getValue()).hasSize(1)
.extracting(HttpRequest::getUri)
.containsExactly("https://adform.com/openrtb2d?CC=1&fd=1&gdpr=&gdpr_consent=&ip=&rp=4&"
+ "stid=tid&bWlkPTE1JnJjdXI9VVNE");
.containsExactly("https://adform.com/openrtb2d?CC=1&eids=eyJ0ZXN0LmNvbSI6eyJ1SWQiOjF9fQ&fd=1&gdpr="
+ "&gdpr_consent=consent&ip=&rp=4&stid=tid&bWlkPTE1JnJjdXI9VVNE");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ public void buildAdformUrlShouldReturnCorrectUrl() {
.consent("consent")
.secure(false)
.currency("USD")
.eids("eyJ0ZXN0LmNvbSI6eyJvdGh")
.build());

// then
// bWlkPTE1 is Base64 encoded mid=15 and bWlkPTE2 encoded mid=16, so bWlkPTE1&bWlkPTE2 = mid=15&mid=16
assertThat(url).isEqualTo(
"http://adx.adform.net/adx?CC=1&adid=adId&fd=1&gdpr=1&gdpr_consent=consent&ip=ip&pt=gross&rp=4"
"http://adx.adform.net/adx?CC=1&adid=adId&eids=eyJ0ZXN0LmNvbSI6eyJvdGh&"
+ "fd=1&gdpr=1&gdpr_consent=consent&ip=ip&pt=gross&rp=4"
+ "&stid=tid&bWlkPTE1JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQmbWt3PXJlZA"
+ "&bWlkPTE2JnJjdXI9VVNEJm1rdj1hZ2U6MzAtNDAmbWt3PWJsdWU");
}
Expand Down Expand Up @@ -291,4 +293,32 @@ public void buildAdformUrlShouldHasGrossPtParamIfGrossAndNetAndNotValidPriceType
.isEqualTo("http://adx.adform.net/adx?CC=1&fd=1&gdpr=&gdpr_consent=&ip=ip&pt=gross&rp=4"
+ "&stid=tid&bWlkPTE1JnJjdXI9VVNE&bWlkPTE2JnJjdXI9VVNE");
}

@Test
public void buildAdformUrlShouldNotContainEidsParamIfEmptyEids() {
// when
final String url = httpUtil.buildAdformUrl(
UrlParameters.builder()
.masterTagIds(asList(15L, 16L))
.keyValues(asList("color:red", "age:30-40"))
.keyWords(asList("red", "blue"))
.priceTypes(singletonList("gross"))
.endpointUrl("http://adx.adform.net/adx")
.tid("tid")
.ip("ip")
.advertisingId("adId")
.gdprApplies("1")
.consent("consent")
.secure(false)
.currency("USD")
.eids(null)
.build());

// then
// bWlkPTE1 is Base64 encoded mid=15 and bWlkPTE2 encoded mid=16, so bWlkPTE1&bWlkPTE2 = mid=15&mid=16
assertThat(url).isEqualTo(
"http://adx.adform.net/adx?CC=1&adid=adId&fd=1&gdpr=1&gdpr_consent=consent&ip=ip&pt=gross&rp=4"
+ "&stid=tid&bWlkPTE1JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQmbWt3PXJlZA"
+ "&bWlkPTE2JnJjdXI9VVNEJm1rdj1hZ2U6MzAtNDAmbWt3PWJsdWU");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,8 @@ public void makeHttpRequestsShouldCreateUserExtTpIdWithAdServerEidSource() {
.ext(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("adserver.org", null,
singletonList(
ExtUserEidUid.of("adServerUid", ExtUserEidUidExt.of("TDID"))), null)))
ExtUserEidUid.of("adServerUid", null, ExtUserEidUidExt.of("TDID"))),
null)))
.build())
.build()),
builder -> builder.video(Video.builder().build()), identity());
Expand All @@ -772,7 +773,8 @@ public void makeHttpRequestsShouldCreateUserExtTpIdWithAdServerEidSource() {
.eids(singletonList(ExtUserEid.of(
"adserver.org",
null,
singletonList(ExtUserEidUid.of("adServerUid", ExtUserEidUidExt.of("TDID"))),
singletonList(ExtUserEidUid.of("adServerUid", null,
ExtUserEidUidExt.of("TDID"))),
null)))
.build(),
RubiconUserExt.builder()
Expand All @@ -786,13 +788,13 @@ public void makeHttpRequestsShouldCreateUserExtTpIdForFirstLiveintentAndAdserver
final ObjectNode uidExt = mapper.createObjectNode();
uidExt.putArray("segments").add("999").add("888");
final ExtUserEid liveintentUid1 = ExtUserEid.of("liveintent.com", null,
singletonList(ExtUserEidUid.of("liveintentUid1", null)), uidExt);
singletonList(ExtUserEidUid.of("liveintentUid1", null, null)), uidExt);
final ExtUserEid liveintentUid2 = ExtUserEid.of("liveintent.com", null,
singletonList(ExtUserEidUid.of("liveintentUid2", null)), null);
singletonList(ExtUserEidUid.of("liveintentUid2", null, null)), null);
final ExtUserEid adserverUid = ExtUserEid.of("adserver.org", null,
singletonList(ExtUserEidUid.of("adServerUid", ExtUserEidUidExt.of("TDID"))), null);
singletonList(ExtUserEidUid.of("adServerUid", null, ExtUserEidUidExt.of("TDID"))), null);
final ExtUserEid notSpecialSource = ExtUserEid.of("notSpecialSource", null,
singletonList(ExtUserEidUid.of("notSpecialSource", ExtUserEidUidExt.of("TDID"))), null);
singletonList(ExtUserEidUid.of("notSpecialSource", null, ExtUserEidUidExt.of("TDID"))), null);
final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder()
.ext(ExtUser.builder()
.eids(Arrays.asList(liveintentUid1, liveintentUid2, adserverUid, notSpecialSource))
Expand Down Expand Up @@ -832,7 +834,7 @@ public void makeHttpRequestsShouldCreateUserExtTpIdWithLiveintentEidSourceAndRpF
.ext(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("liveintent.com", null,
singletonList(
ExtUserEidUid.of("liveintentUid", null)),
ExtUserEidUid.of("liveintentUid", null, null)),
uidExt)))
.build())
.build()),
Expand All @@ -852,7 +854,7 @@ public void makeHttpRequestsShouldCreateUserExtTpIdWithLiveintentEidSourceAndRpF
.containsOnly(jacksonMapper.fillExtension(
ExtUser.builder()
.eids(singletonList(ExtUserEid.of("liveintent.com", null,
singletonList(ExtUserEidUid.of("liveintentUid", null)), uidExt)))
singletonList(ExtUserEidUid.of("liveintentUid", null, null)), uidExt)))
.build(),
RubiconUserExt.builder()
.tpid(singletonList(ExtUserTpIdRubicon.of("liveintent.com", "liveintentUid")))
Expand All @@ -866,7 +868,7 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithAdServerEidSourceIfEid
final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder()
.ext(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("adserver.org", null,
singletonList(ExtUserEidUid.of("id", null)), null)))
singletonList(ExtUserEidUid.of("id", null, null)), null)))
.build())
.build()),
builder -> builder.video(Video.builder().build()), identity());
Expand All @@ -882,7 +884,7 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithAdServerEidSourceIfEid
.containsOnly(jacksonMapper.fillExtension(
ExtUser.builder()
.eids(singletonList(ExtUserEid.of("adserver.org", null,
singletonList(ExtUserEidUid.of("id", null)), null)))
singletonList(ExtUserEidUid.of("id", null, null)), null)))
.build(),
RubiconUserExt.builder()
.tpid(null)
Expand All @@ -895,7 +897,7 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithAdServerEidSourceIfExt
final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder()
.ext(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("adserver.org", null,
singletonList(ExtUserEidUid.of("id", ExtUserEidUidExt.of(null))), null)))
singletonList(ExtUserEidUid.of("id", null, ExtUserEidUidExt.of(null))), null)))
.build())
.build()),
builder -> builder.video(Video.builder().build()), identity());
Expand All @@ -910,7 +912,7 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithAdServerEidSourceIfExt
.extracting(request -> request.getUser().getExt())
.containsOnly(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("adserver.org", null,
singletonList(ExtUserEidUid.of("id", ExtUserEidUidExt.of(null))), null)))
singletonList(ExtUserEidUid.of("id", null, ExtUserEidUidExt.of(null))), null)))
.build());
}

Expand All @@ -921,10 +923,10 @@ public void makeHttpRequestsShouldCreateUserExtLiverampId() {
.eids(asList(
ExtUserEid.of("liveramp.com", null,
asList(
ExtUserEidUid.of("firstId", null),
ExtUserEidUid.of("ignored", null)), null),
ExtUserEidUid.of("firstId", null, null),
ExtUserEidUid.of("ignored", null, null)), null),
ExtUserEid.of("liveramp.com", null,
singletonList(ExtUserEidUid.of("ignored", null)), null)))
singletonList(ExtUserEidUid.of("ignored", null, null)), null)))
.build();
final BidRequest bidRequest = givenBidRequest(
builder -> builder.user(User.builder().ext(extUser).build()),
Expand Down Expand Up @@ -976,7 +978,8 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithUnknownEidSource() {
final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder()
.ext(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("unknownSource", null,
singletonList(ExtUserEidUid.of("id", ExtUserEidUidExt.of("eidUidId"))), null)))
singletonList(ExtUserEidUid.of("id", null, ExtUserEidUidExt.of("eidUidId"))),
null)))
.build())
.build()),
builder -> builder.video(Video.builder().build()), identity());
Expand All @@ -991,7 +994,7 @@ public void makeHttpRequestsShouldNotCreateUserExtTpIdWithUnknownEidSource() {
.extracting(request -> request.getUser().getExt())
.containsOnly(ExtUser.builder()
.eids(singletonList(ExtUserEid.of("unknownSource", null,
singletonList(ExtUserEidUid.of("id", ExtUserEidUidExt.of("eidUidId"))), null)))
singletonList(ExtUserEidUid.of("id", null, ExtUserEidUidExt.of("eidUidId"))), null)))
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ public void makeHttpRequestsShouldReturnRequestWithCorrectUriAndHeadersDefaultPa
throws JsonProcessingException {
// given
final List<ExtUserEidUid> uids = Arrays.asList(
ExtUserEidUid.of("first", null),
ExtUserEidUid.of("second", null));
ExtUserEidUid.of("first", null, null),
ExtUserEidUid.of("second", null, null));
final ExtUserEid extUserEid = ExtUserEid.of("adserver.org", null, uids, null);
final ExtUser extUser = ExtUser.builder()
.consent("consent")
Expand Down
Loading