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

Remove Legacy UIDs From Cookie #2818

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
12 changes: 3 additions & 9 deletions src/main/java/org/prebid/server/cookie/UidsCookieService.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ public UidsCookie parseFromRequest(HttpRequestContext httpRequest) {
UidsCookie parseFromCookies(Map<String, String> cookies) {
final Uids parsedUids = parseUids(cookies);

final Uids.UidsBuilder uidsBuilder = Uids.builder()
.uidsLegacy(Collections.emptyMap());

final Boolean optout;
final Map<String, UidWithExpiry> uidsMap;

Expand All @@ -120,7 +117,9 @@ UidsCookie parseFromCookies(Map<String, String> 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);
}

/**
Expand Down Expand Up @@ -197,11 +196,6 @@ private Map<String, UidWithExpiry> enrichAndSanitizeUids(Uids uids, Map<String,
workingUidsMap.putAll(originalUidsMap);
}

final Map<String, String> 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
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/org/prebid/server/cookie/proto/Uids.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
@Value
public class Uids {

@JsonProperty("uids")
Map<String, String> uidsLegacy;

@JsonProperty("tempUIDs")
Map<String, UidWithExpiry> uids; // transition to new UIDs format

Expand Down
75 changes: 42 additions & 33 deletions src/test/java/org/prebid/server/cookie/UidsCookieServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> cookies = singletonMap("uids",
"eyJ1aWRzIjp7InJ1Ymljb24iOiJKNVZMQ1dRUC0yNi1DV0ZUIiwiYWRueHMiOiIxMjM0NSJ9fQ==");
"eyAidGVtcFVJRHMiOnsgInJ1Ymljb24iOnsgInVpZCI6ICJKNVZMQ1dRUC0yNi1DV0ZUIiwg"
+ "ImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS4xMDMzMjktMDM6MDAiIH0sICJhZG5"
+ "4cyI6eyAidWlkIjogIjEyMzQ1IiwgImV4cGlyZXMiOiAiMjAyMy0xMi0wNVQxOTowMDowNS"
+ "4xMDMzMjktMDM6MDAiIH0gfSB9");

// when
final UidsCookie uidsCookie = uidsCookieService.parseFromCookies(cookies);
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -156,9 +166,15 @@ public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsMissingAndOptoutCo
public void shouldReturnUidsCookieWithOptoutTrueIfUidsCookieIsPresentAndOptoutCookieHasExpectedValue() {
// given
final Map<String, Cookie> 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);
Expand Down Expand Up @@ -224,9 +240,15 @@ public void toCookieShouldSetPath() {
public void shouldReturnUidsCookieWithOptoutFalseIfOptoutCookieHasNotExpectedValue() {
// given
final Map<String, Cookie> 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);
Expand Down Expand Up @@ -327,9 +349,14 @@ public void shouldReturnRubiconCookieValueFromHostCookieWhenUidValueIsPresentBut
jacksonMapper);

final Map<String, Cookie> 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);
Expand Down Expand Up @@ -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
Expand Down
30 changes: 18 additions & 12 deletions src/test/java/org/prebid/server/it/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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();
}

Expand Down Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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");

Expand Down
12 changes: 8 additions & 4 deletions src/test/java/org/prebid/server/it/DealsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/org/prebid/server/it/PrematureReturnTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Loading