From 78320a28791d54c0ae76e9f489771493d366fd9d Mon Sep 17 00:00:00 2001 From: vyniciuspontes Date: Tue, 5 Dec 2023 12:25:28 -0300 Subject: [PATCH] [S2S-1417] Remove Legacy UIDs From Cookie and fix tests --- .../server/cookie/UidsCookieService.java | 12 +-- .../org/prebid/server/cookie/proto/Uids.java | 3 - .../server/cookie/UidsCookieServiceTest.java | 75 +++++++++++-------- .../org/prebid/server/it/ApplicationTest.java | 30 +++++--- .../java/org/prebid/server/it/DealsTest.java | 12 ++- .../prebid/server/it/PrematureReturnTest.java | 6 +- 6 files changed, 75 insertions(+), 63 deletions(-) diff --git a/src/main/java/org/prebid/server/cookie/UidsCookieService.java b/src/main/java/org/prebid/server/cookie/UidsCookieService.java index c2312e35bc1..7416abfdfa2 100644 --- a/src/main/java/org/prebid/server/cookie/UidsCookieService.java +++ b/src/main/java/org/prebid/server/cookie/UidsCookieService.java @@ -106,9 +106,6 @@ public UidsCookie parseFromRequest(HttpRequestContext httpRequest) { UidsCookie parseFromCookies(Map cookies) { final Uids parsedUids = parseUids(cookies); - final Uids.UidsBuilder uidsBuilder = Uids.builder() - .uidsLegacy(Collections.emptyMap()); - final Boolean optout; final Map uidsMap; @@ -120,7 +117,9 @@ UidsCookie parseFromCookies(Map cookies) { uidsMap = enrichAndSanitizeUids(parsedUids, cookies); } - return new UidsCookie(uidsBuilder.uids(uidsMap).optout(optout).build(), mapper); + final Uids uids = Uids.builder().uids(uidsMap).optout(optout).build(); + + return new UidsCookie(uids, mapper); } /** @@ -197,11 +196,6 @@ private Map enrichAndSanitizeUids(Uids uids, Map legacyUids = uids != null ? uids.getUidsLegacy() : null; - if (workingUidsMap.isEmpty() && legacyUids != null) { - legacyUids.forEach((key, value) -> workingUidsMap.put(key, UidWithExpiry.expired(value))); - } - final String hostCookie = parseHostCookie(cookies); if (hostCookie != null && hostCookieDiffers(hostCookie, workingUidsMap.get(hostCookieFamily))) { // make host cookie precedence over uids diff --git a/src/main/java/org/prebid/server/cookie/proto/Uids.java b/src/main/java/org/prebid/server/cookie/proto/Uids.java index aa0eed855e2..e6251942f3a 100644 --- a/src/main/java/org/prebid/server/cookie/proto/Uids.java +++ b/src/main/java/org/prebid/server/cookie/proto/Uids.java @@ -11,9 +11,6 @@ @Value public class Uids { - @JsonProperty("uids") - Map uidsLegacy; - @JsonProperty("tempUIDs") Map uids; // transition to new UIDs format diff --git a/src/test/java/org/prebid/server/cookie/UidsCookieServiceTest.java b/src/test/java/org/prebid/server/cookie/UidsCookieServiceTest.java index fe0bc176f42..ae56ea9adc6 100644 --- a/src/test/java/org/prebid/server/cookie/UidsCookieServiceTest.java +++ b/src/test/java/org/prebid/server/cookie/UidsCookieServiceTest.java @@ -75,9 +75,14 @@ public void setUp() { @Test public void shouldReturnNonEmptyUidsCookieFromCookiesMap() { // given - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } final Map cookies = singletonMap("uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ=="); + "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg" + + "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9"); // when final UidsCookie uidsCookie = uidsCookieService.parseFromCookies(cookies); @@ -91,10 +96,15 @@ public void shouldReturnNonEmptyUidsCookieFromCookiesMap() { @Test public void shouldReturnNonEmptyUidsCookie() { // given - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie( - "uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ=="))); + "tempUIDs", + "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg" + + "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9"))); // when final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext); @@ -130,7 +140,7 @@ public void shouldReturnNonNullUidsCookieIfUidsCookieIsNonBase64() { public void shouldReturnNonNullUidsCookieIfUidsCookieIsNonJson() { // given // this uids cookie value stands for "abcde" - given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie("uids", "bm9uLWpzb24="))); + given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie("tempUIDs", "bm9uLWpzb24="))); // when final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext); @@ -156,9 +166,15 @@ public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsMissingAndOptoutCo public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsPresentAndOptoutCookieHasExpectedValue() { // given final Map cookies = new HashMap<>(); - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} - cookies.put("uids", Cookie.cookie("uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==")); + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } + cookies.put("uids", + Cookie.cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0" + + "ZUIiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9")); + cookies.put(OPT_OUT_COOKIE_NAME, Cookie.cookie(OPT_OUT_COOKIE_NAME, OPT_OUT_COOKIE_VALUE)); given(routingContext.cookieMap()).willReturn(cookies); @@ -224,9 +240,15 @@ public void toCookieShouldSetPath() { public void shouldReturnUidsCookieWithOptoutFalseIfOptoutCookieHasNotExpectedValue() { // given final Map cookies = new HashMap<>(); - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} - cookies.put("uids", Cookie.cookie("uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==")); + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } + cookies.put("uids", Cookie.cookie( + "tempUIDs", + "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg" + + "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9")); cookies.put(OPT_OUT_COOKIE_NAME, Cookie.cookie(OPT_OUT_COOKIE_NAME, "dummy")); given(routingContext.cookieMap()).willReturn(cookies); @@ -327,9 +349,14 @@ public void shouldReturnRubiconCookieValueFromHostCookieWhenUidValueIsPresentBut jacksonMapper); final Map cookies = new HashMap<>(); - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} - cookies.put("uids", Cookie.cookie("uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==")); + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } + cookies.put("uids", + Cookie.cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0" + + "ZUIiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9")); cookies.put("khaos", Cookie.cookie("khaos", "abc123")); given(routingContext.cookieMap()).willReturn(cookies); @@ -407,24 +434,6 @@ public void toCookieShouldReturnCookieWithExpectedDomain() { assertThat(cookie.getDomain()).isEqualTo(HOST_COOKIE_DOMAIN); } - @Test - public void shouldCreateUidsFromLegacyUidsIfUidsAreMissed() { - // given - // this uids cookie value stands for - // {"uids":{"rubicon":"J5VLCWQP-26-CWFT"},"tempUIDs":{}},"bday":"2017-08-15T19:47:59.523908376Z"} - given(routingContext.cookieMap()).willReturn(singletonMap("uids", Cookie.cookie( - "uids", - "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIn0sInRlbXBVSURzIjp7fX0sImJkYXkiOiIyMDE3LTA" - + "4LTE1VDE5OjQ3OjU5LjUyMzkwODM3NloifQ=="))); - - // when - final UidsCookie uidsCookie = uidsCookieService.parseFromRequest(routingContext); - - // then - assertThat(uidsCookie).isNotNull(); - assertThat(uidsCookie.uidFrom(RUBICON)).isEqualTo("J5VLCWQP-26-CWFT"); - } - @Test public void shouldParseHostCookie() { // given diff --git a/src/test/java/org/prebid/server/it/ApplicationTest.java b/src/test/java/org/prebid/server/it/ApplicationTest.java index 20780451833..9d75f080b3c 100644 --- a/src/test/java/org/prebid/server/it/ApplicationTest.java +++ b/src/test/java/org/prebid/server/it/ApplicationTest.java @@ -252,8 +252,13 @@ public void optoutShouldSetOptOutFlagAndRedirectToOptOutUrl() throws IOException // when final Response response = given(SPEC) .header("Content-Type", "application/x-www-form-urlencoded") - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg" + + "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9") .body("g-recaptcha-response=recaptcha1&optout=1") .post("/optout"); @@ -267,7 +272,6 @@ public void optoutShouldSetOptOutFlagAndRedirectToOptOutUrl() throws IOException // this uids cookie value stands for {"uids":{},"optout":true} final Uids uids = decodeUids(cookie.getValue()); assertThat(uids.getUids()).isEmpty(); - assertThat(uids.getUidsLegacy()).isEmpty(); assertThat(uids.getOptout()).isTrue(); } @@ -345,10 +349,10 @@ public void cookieSyncShouldReturnBidderStatusWithExpectedUsersyncInfo() { public void setuidShouldUpdateRubiconUidInUidCookie() throws IOException { // when final Cookie uidsCookie = given(SPEC) - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}, - // "bday":"2017-08-15T19:47:59.523908376Z"} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0" - + "NSJ9LCJiZGF5IjoiMjAxNy0wOC0xNVQxOTo0Nzo1OS41MjM5MDgzNzZaIn0=") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid":"J5VLCWQP-26-CWFT", + // "expires":"2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6Iko1VkxDV1FQ" + + "LTI2LUNXRlQiLCAiZXhwaXJlcyI6IjIwMjMtMTItMDVUMTk6MDA6MDUuMTAzMzI5LTAzOjAwIiB9IH0gfQ==") // this constant is ok to use as long as it coincides with family name .queryParam("bidder", RUBICON) .queryParam("uid", "updatedUid") @@ -367,7 +371,6 @@ public void setuidShouldUpdateRubiconUidInUidCookie() throws IOException { .isCloseTo(Instant.now().plus(90, ChronoUnit.DAYS), within(10, ChronoUnit.SECONDS)); final Uids uids = decodeUids(uidsCookie.getValue()); - assertThat(uids.getUidsLegacy()).isEmpty(); assertThat(uids.getUids()) .extracting(Map::keySet) .extracting(ArrayList::new) @@ -382,10 +385,13 @@ public void setuidShouldUpdateRubiconUidInUidCookie() throws IOException { public void getuidsShouldReturnJsonWithUids() throws JSONException, IOException { // given and when final Response response = given(SPEC) - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT","adnxs":"12345"}, - // "bday":"2017-08-15T19:47:59.523908376Z"} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0" - + "NSJ9LCJiZGF5IjoiMjAxNy0wOC0xNVQxOTo0Nzo1OS41MjM5MDgzNzZaIn0=") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid": "J5VLCWQP-26-CWFT", + // "expires": "2023-12-05T19:00:05.103329-03:00" }, "adnxs":{ "uid": "12345", + // "expires": "2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg" + + "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5" + + "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS" + + "4xMDMzMjktMDM6MDAiIH0gfSB9") .when() .get("/getuids"); diff --git a/src/test/java/org/prebid/server/it/DealsTest.java b/src/test/java/org/prebid/server/it/DealsTest.java index 643a2eab455..78f775288d8 100644 --- a/src/test/java/org/prebid/server/it/DealsTest.java +++ b/src/test/java/org/prebid/server/it/DealsTest.java @@ -155,8 +155,10 @@ public void openrtb2AuctionShouldRespondWithDealBids() throws IOException, JSONE .header("Referer", "http://www.example.com") .header("User-Agent", "userAgent") .header("X-Forwarded-For", "185.199.110.153") - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT"}} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIn19") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid":"J5VLCWQP-26-CWFT", + // "expires":"2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6Iko1VkxDV1FQ" + + "LTI2LUNXRlQiLCAiZXhwaXJlcyI6IjIwMjMtMTItMDVUMTk6MDA6MDUuMTAzMzI5LTAzOjAwIiB9IH0gfQ==") .body(jsonFrom("deals/test-auction-request.json")) .post("/openrtb2/auction"); @@ -174,8 +176,10 @@ public void openrtb2AuctionShouldRespondWithDealBids() throws IOException, JSONE .queryParam("a", "14062") .queryParam("l", "lineItem1") .queryParam("f", "i") - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT"}} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIn19") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid":"J5VLCWQP-26-CWFT", + // "expires":"2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6Iko1VkxDV1FQ" + + "LTI2LUNXRlQiLCAiZXhwaXJlcyI6IjIwMjMtMTItMDVUMTk6MDA6MDUuMTAzMzI5LTAzOjAwIiB9IH0gfQ==") .get("/event"); // then diff --git a/src/test/java/org/prebid/server/it/PrematureReturnTest.java b/src/test/java/org/prebid/server/it/PrematureReturnTest.java index 4834837fffc..dec6e307a14 100644 --- a/src/test/java/org/prebid/server/it/PrematureReturnTest.java +++ b/src/test/java/org/prebid/server/it/PrematureReturnTest.java @@ -373,8 +373,10 @@ private Response givenResponse() throws IOException { .header("Referer", "http://www.example.com") .header("User-Agent", "userAgent") .header("X-Forwarded-For", "185.199.110.153") - // this uids cookie value stands for {"uids":{"rubicon":"J5VLCWQP-26-CWFT"}} - .cookie("uids", "eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIn19") + // this uids cookie value stands for { "tempUIDs":{ "rubicon":{ "uid":"J5VLCWQP-26-CWFT", + // "expires":"2023-12-05T19:00:05.103329-03:00" } } } + .cookie("uids", "eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6Iko1VkxDV1FQ" + + "LTI2LUNXRlQiLCAiZXhwaXJlcyI6IjIwMjMtMTItMDVUMTk6MDA6MDUuMTAzMzI5LTAzOjAwIiB9IH0gfQ==") .body(IntegrationTest.jsonFrom("deals/premature/test-auction-request.json")) .post("/openrtb2/auction"); }