Skip to content

Commit

Permalink
Сookie domain transition tests (#934)
Browse files Browse the repository at this point in the history
* Сookie domain transition tests

* fix after review
  • Loading branch information
mtuchkova authored and GitHub Enterprise committed Dec 9, 2021
1 parent 7d10e71 commit f7224df
Show file tree
Hide file tree
Showing 22 changed files with 247 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,28 @@ package org.prebid.server.functional.model

import com.fasterxml.jackson.annotation.JsonFormat
import groovy.transform.ToString
import org.prebid.server.functional.model.bidder.BidderName
import org.prebid.server.functional.model.request.setuid.UidWithExpiry

import java.time.Clock
import java.time.ZonedDateTime

import static org.prebid.server.functional.model.bidder.BidderName.GENERIC

@ToString(includeNames = true, ignoreNulls = true)
class UidsCookie {

Map<String, String> uids
Map<String, UidWithExpiry> tempUIDs
Boolean optout
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", timezone = "UTC")
ZonedDateTime bday

static UidsCookie getDefaultUidsCookie() {
static UidsCookie getDefaultUidsCookie(BidderName bidderName = GENERIC) {
def uidsCookie = new UidsCookie()
uidsCookie.uids = [generic: UUID.randomUUID().toString()]
uidsCookie.uids = [(bidderName.value): UUID.randomUUID().toString()]
uidsCookie.bday = ZonedDateTime.now(Clock.systemUTC())
uidsCookie.tempUIDs = ["generic": new UidWithExpiry(uid: UUID.randomUUID().toString(), expires: ZonedDateTime.now(Clock.systemUTC()).plusDays(2))]
uidsCookie.tempUIDs = [(bidderName.value): new UidWithExpiry(uid: UUID.randomUUID().toString(), expires: ZonedDateTime.now(Clock.systemUTC()).plusDays(2))]
uidsCookie
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class Format {
Integer wmin

static Format getDefaultFormat() {
new Format().tap {
w = 300
h = 250
}
new Format(w: 300, h: 250)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ class ImpExt {
AppNexus appNexus

static ImpExt getDefaultImpExt() {
new ImpExt().tap {
prebid = ImpExtPrebid.defaultImpExtPrebid
}
new ImpExt(prebid: ImpExtPrebid.defaultImpExtPrebid)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class ImpExtPrebid {
StoredAuctionResponse storedAuctionResponse

static ImpExtPrebid getDefaultImpExtPrebid() {
new ImpExtPrebid().tap {
bidder = Bidder.defaultBidder
}
new ImpExtPrebid(bidder: Bidder.defaultBidder)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class Publisher {
String domain

static Publisher getDefaultPublisher() {
new Publisher().tap {
id = PBSUtils.randomNumber.toString()
}
new Publisher(id: PBSUtils.randomNumber)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class Regs {
RegsExt ext

static Regs getDefaultRegs() {
new Regs().tap {
ext = new RegsExt(gdpr: 0)
}
new Regs(ext: new RegsExt(gdpr: 0))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ class Site {
SiteExt ext

static Site getDefaultSite() {
new Site().tap {
page = PBSUtils.randomString
publisher = Publisher.defaultPublisher
}
new Site(page: PBSUtils.randomString, publisher: Publisher.defaultPublisher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class CookieSyncRequest {
String account

static CookieSyncRequest getDefaultCookieSyncRequest() {
def request = new CookieSyncRequest()
request.bidders = [GENERIC]
request.gdpr = 0
request
new CookieSyncRequest(bidders: [GENERIC], gdpr: 0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.prebid.server.functional.model.bidder.BidderName
import org.prebid.server.functional.model.request.Format

import static org.prebid.server.functional.model.bidder.BidderName.GENERIC
import static org.prebid.server.functional.model.bidder.BidderName.RUBICON

@ToString(includeNames = true, ignoreNulls = true)
class SetuidRequest {
Expand All @@ -20,9 +21,10 @@ class SetuidRequest {
String account

static SetuidRequest getDefaultSetuidRequest() {
def request = new SetuidRequest()
request.bidder = GENERIC
request.gdpr = "0"
request
new SetuidRequest(bidder: GENERIC, gdpr: "0")
}

static SetuidRequest getRubiconSetuidRequest() {
new SetuidRequest(bidder: RUBICON, gdpr: "0")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ import java.time.ZonedDateTime
class UidWithExpiry {

String uid
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", timezone = "UTC")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'", timezone = "UTC")
ZonedDateTime expires
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Ad {
Wrapper wrapper

static Ad getDefaultAd(String payload) {
new Ad().tap {
wrapper = Wrapper.getDefaultWrapper(payload)
}
new Ad(wrapper: Wrapper.getDefaultWrapper(payload))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@ class Vast {
Ad ad

static Vast getDefaultVastModel(String payload) {
new Vast().tap {
version = "3.0"
ad = Ad.getDefaultAd(payload)
}
new Vast(version: "3.0", ad: Ad.getDefaultAd(payload))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import groovy.transform.ToString
class RawAmpResponse {

String responseBody
Map<String, String> headers
Map<String, List<String>> headers
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ import org.prebid.server.functional.model.ResponseModel
class RawAuctionResponse implements ResponseModel {

String responseBody
Map<String, String> headers
Map<String, List<String>> headers
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ class SetuidResponse {

UidsCookie uidsCookie
Byte[] responseBody
Map<String, List<String>> headers
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ class PrebidServerException extends Exception {

final int statusCode
final String responseBody
final Map<String, String> headers
final Map<String, List<String>> headers

PrebidServerException(int statusCode, String message, Map<String, String> headers) {
PrebidServerException(int statusCode, String message, Map<String, List<String>> headers) {
this.statusCode = statusCode
this.responseBody = message
this.headers = headers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,32 +136,55 @@ class PrebidServerService {
response.as(CookieSyncResponse)
}

@Step("[GET] /setuid")
SetuidResponse sendSetUidRequest(SetuidRequest request, UidsCookie uidsCookie) {
@Step("[GET] /getuids")
GetuidResponse sendGetUidRequest(UidsCookie uidsCookie) {
def uidsCookieAsJson = mapper.encode(uidsCookie)
def uidsCookieAsEncodedJson = Base64.urlEncoder.encodeToString(uidsCookieAsJson.bytes)

def response = given(requestSpecification).cookie("uids", uidsCookieAsEncodedJson)
.queryParams(mapper.toMap(request))
.get(GET_UIDS_ENDPOINT)

checkResponseStatusCode(response)
response.as(GetuidResponse)
}

@Step("[GET] /setuid")
SetuidResponse sendSetUidRequest(SetuidRequest request) {
def response = given(requestSpecification).queryParams(mapper.toMap(request))
.get(SET_UID_ENDPOINT)

checkResponseStatusCode(response)

def setuidResponse = new SetuidResponse()
setuidResponse.uidsCookie = getDecodedUidsCookie(response)
setuidResponse.responseBody = response.asByteArray()
setuidResponse
new SetuidResponse(headers: getHeaders(response),
uidsCookie: getDecodedUidsCookie(response),
responseBody: response.asByteArray())
}

@Step("[GET] /getuids")
GetuidResponse sendGetUidRequest(UidsCookie uidsCookie) {
def uidsCookieAsJson = mapper.encode(uidsCookie)
def uidsCookieAsEncodedJson = Base64.urlEncoder.encodeToString(uidsCookieAsJson.bytes)
@Step("[GET] /setuid")
SetuidResponse sendSetUidRequest(SetuidRequest request, UidsCookie uidsCookie) {
def response = given(requestSpecification).cookie("uids", encodeUidsCookie(uidsCookie))
.queryParams(mapper.toMap(request))
.get(SET_UID_ENDPOINT)

def response = given(requestSpecification).cookie("uids", uidsCookieAsEncodedJson)
.get(GET_UIDS_ENDPOINT)
checkResponseStatusCode(response)

new SetuidResponse(headers: getHeaders(response),
uidsCookie: getDecodedUidsCookie(response),
responseBody: response.asByteArray())
}

@Step("[GET] /setuid")
SetuidResponse sendSetUidRequest(SetuidRequest request, UidsCookie uidsCookie, String uidsAuditCookie) {
def response = given(requestSpecification).cookies(["uids" : encodeUidsCookie(uidsCookie),
"uids-audit": uidsAuditCookie])
.queryParams(mapper.toMap(request))
.get(SET_UID_ENDPOINT)

checkResponseStatusCode(response)
response.as(GetuidResponse)

new SetuidResponse(headers: getHeaders(response),
uidsCookie: getDecodedUidsCookie(response),
responseBody: response.asByteArray())
}

@Step("[GET] /event")
Expand Down Expand Up @@ -264,6 +287,11 @@ class PrebidServerService {
.get(AMP_ENDPOINT)
}

private String encodeUidsCookie(UidsCookie uidsCookie) {
def uidsCookieAsJson = mapper.encode(uidsCookie)
Base64.urlEncoder.encodeToString(uidsCookieAsJson.bytes)
}

private void checkResponseStatusCode(Response response) {
def statusCode = response.statusCode
if (statusCode != 200) {
Expand All @@ -273,8 +301,14 @@ class PrebidServerService {
}
}

private static Map<String, String> getHeaders(Response response) {
response.headers().collectEntries { [it.name, it.value] }
private static Map<String, List<String>> getHeaders(Response response) {
Map<String, List<String>> map = [:]
response.headers().each {
map.get(it.name)
? map.get(it.name).add(it.value)
: map.put(it.name, [it.value])
}
map
}

private UidsCookie getDecodedUidsCookie(Response response) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.prebid.server.functional.testcontainers.container

import org.prebid.server.functional.testcontainers.Dependencies
import org.prebid.server.functional.util.PBSUtils
import org.testcontainers.containers.GenericContainer
import org.testcontainers.containers.MySQLContainer
import org.testcontainers.containers.wait.strategy.Wait
Expand Down Expand Up @@ -133,8 +134,10 @@ LIMIT 1
}

void withRubiconSpecificConfig() {
withConfig(["gdpr.rubicon.rsid-cookie-encryption-key": "someRsidEncryptionKey"])
withConfig(["gdpr.rubicon.audit-cookie-encryption-key": "someAuditEncryptionKey"])
withConfig(["gdpr.rubicon.rsid-cookie-encryption-key" : PBSUtils.randomString,
"gdpr.rubicon.audit-cookie-encryption-key": PBSUtils.randomString,
"auction.enforce-random-bid-id": "false"
])
}

PrebidServerContainer withConfig(Map<String, String> config) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class AmpSpec extends BaseSpec {
def response = defaultPbsService.sendAmpRequestRaw(ampRequest)

then: "Response header should contain PBS version"
assert response.headers["x-prebid"] == PBS_VERSION_HEADER
assert response.headers["x-prebid"] == [PBS_VERSION_HEADER]

where:
ampRequest || description
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AuctionSpec extends BaseSpec {
def response = defaultPbsService.sendAuctionRequestRaw(bidRequest)

then: "Response header should contain PBS version"
assert response.headers["x-prebid"] == PBS_VERSION_HEADER
assert response.headers["x-prebid"] == [PBS_VERSION_HEADER]

where:
bidRequest || description
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.prebid.server.functional.tests.rubicon

import org.prebid.server.functional.service.PrebidServerService
import org.prebid.server.functional.testcontainers.PBSTest
import org.prebid.server.functional.tests.BaseSpec
import org.prebid.server.functional.util.PBSUtils

import static org.prebid.server.functional.testcontainers.Dependencies.networkServiceContainer

@PBSTest
abstract class RubiconBaseSpec extends BaseSpec {

private static final String RUBICON_VENDOR_ID = "52"
protected static final Map<String, String> RUBICON_CONFIG =
["gdpr.rubicon.rsid-cookie-encryption-key" : PBSUtils.randomString,
"gdpr.rubicon.audit-cookie-encryption-key": PBSUtils.randomString,
"gdpr.host-vendor-id" : RUBICON_VENDOR_ID,
"auction.enforce-random-bid-id" : "false",
"host-cookie.domain" : PBSUtils.randomString,
"host-cookie.ttl-days" : "60",
"adapters.rubicon.enabled" : "true",
"adapters.rubicon.endpoint" : "$networkServiceContainer.rootUri/auction" as String]

protected static final PrebidServerService rubiconPbsService = pbsServiceFactory.getService(RUBICON_CONFIG)
}
Loading

0 comments on commit f7224df

Please sign in to comment.