From 46fc6b0e8cb0e1eaf52db3f02469a082142b0970 Mon Sep 17 00:00:00 2001 From: rpanchyk Date: Thu, 24 Sep 2020 18:19:41 +0300 Subject: [PATCH] Fix Rubicon eids striping (#928) --- .../server/bidder/rubicon/RubiconBidder.java | 10 ++--- .../bidder/rubicon/RubiconBidderTest.java | 43 +++++++++++++++---- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java index 91ce7bc0f0e..1a5581105a9 100644 --- a/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java +++ b/src/main/java/org/prebid/server/bidder/rubicon/RubiconBidder.java @@ -722,7 +722,7 @@ private User makeUser(User user, ExtImpRubicon rubiconImpExt) { final User.UserBuilder userBuilder = user != null ? user.toBuilder() : User.builder(); return userBuilder - .id(resolvedId) + .id(ObjectUtils.defaultIfNull(resolvedId, userId)) .gender(null) .yob(null) .geo(null) @@ -783,10 +783,10 @@ private static ExtUserEid prepareExtUserEid(ExtUserEid extUserEid) { private static ExtUserEidUid cleanExtUserEidUidStype(ExtUserEidUid extUserEidUid) { final ExtUserEidUidExt extUserEidUidExt = extUserEidUid.getExt(); - return STYPE_TO_REMOVE.contains(extUserEidUidExt.getStype()) - ? ExtUserEidUid.of(extUserEidUid.getId(), extUserEidUid.getAtype(), - ExtUserEidUidExt.of(extUserEidUidExt.getRtiPartner(), null)) - : extUserEidUid; + return extUserEidUidExt == null || !STYPE_TO_REMOVE.contains(extUserEidUidExt.getStype()) + ? extUserEidUid + : ExtUserEidUid.of(extUserEidUid.getId(), extUserEidUid.getAtype(), + ExtUserEidUidExt.of(extUserEidUidExt.getRtiPartner(), null)); } private static Map> specialExtUserEids(List eids) { diff --git a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java index 1140a6ce84e..63b951cf785 100644 --- a/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java +++ b/src/test/java/org/prebid/server/bidder/rubicon/RubiconBidderTest.java @@ -782,6 +782,31 @@ public void makeHttpRequestsShouldCreateUserExtTpIdWithAdServerEidSource() { .build())); } + @Test + public void makeHttpRequestsShouldUseGivenUserIdIfOtherExtUserFieldsPassed() { + // given + final ExtUser extUser = ExtUser.builder() + .eids(singletonList(ExtUserEid.of("liveramp.com", null, + singletonList(ExtUserEidUid.of("firstId", null, null)), null))) + .build(); + final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder() + .id("userId") + .ext(extUser) + .build()), + builder -> builder.video(Video.builder().build()), identity()); + + // when + final Result>> result = rubiconBidder.makeHttpRequests(bidRequest); + + // then + assertThat(result.getErrors()).isEmpty(); + assertThat(result.getValue()).hasSize(1).doesNotContainNull() + .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) + .extracting(BidRequest::getUser) + .extracting(User::getId) + .containsOnly("userId"); + } + @Test public void makeHttpRequestsShouldCreateUserIdIfMissingFromFirstUidStypePpuid() { // given @@ -809,7 +834,7 @@ public void makeHttpRequestsShouldCreateUserIdIfMissingFromFirstUidStypePpuid() } @Test - public void makeHttpRequestsShouldNotCreateUseIdIfMissingWhenNoUidWithPpuidType() { + public void makeHttpRequestsShouldNotCreateUserIdIfMissingWhenNoUidWithPpuidType() { // given final BidRequest bidRequest = givenBidRequest(builder -> builder.user(User.builder() .ext(ExtUser.builder() @@ -857,14 +882,14 @@ public void makeHttpRequestsShouldRemoveStypesPpuidSha256emailDmp() { .extracting(httpRequest -> mapper.readValue(httpRequest.getBody(), BidRequest.class)) .extracting(request -> request.getUser().getExt()).hasSize(1).element(0) .isEqualTo(ExtUser.builder() - .eids(singletonList(ExtUserEid.of("source", "id", - asList( - ExtUserEidUid.of("id1", null, ExtUserEidUidExt.of(null, "other")), - ExtUserEidUid.of("id2", null, ExtUserEidUidExt.of(null, null)), - ExtUserEidUid.of("id3", null, ExtUserEidUidExt.of(null, null)), - ExtUserEidUid.of("id4", null, ExtUserEidUidExt.of(null, null))), - null))) - .build()); + .eids(singletonList(ExtUserEid.of("source", "id", + asList( + ExtUserEidUid.of("id1", null, ExtUserEidUidExt.of(null, "other")), + ExtUserEidUid.of("id2", null, ExtUserEidUidExt.of(null, null)), + ExtUserEidUid.of("id3", null, ExtUserEidUidExt.of(null, null)), + ExtUserEidUid.of("id4", null, ExtUserEidUidExt.of(null, null))), + null))) + .build()); } @Test