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

Tests: Increase test coverage for cookie_sync #2570

Merged
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -5,7 +5,7 @@ import net.minidev.json.annotate.JsonIgnore

enum BidderName {

ALIAS, GENERIC, RUBICON, APPNEXUS, BOGUS, OPENX
ALIAS, GENERIC, RUBICON, APPNEXUS, BOGUS, OPENX, ACEEX, ACUITYADS, GRID, AAX, ADKERNEL, MEDIANET
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rearrange the list and put BOGUS somewhere at the beginning.


@JsonValue
String getValue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package org.prebid.server.functional.model.mock.services.vendorlist

import org.prebid.server.functional.util.PBSUtils
import org.prebid.server.functional.util.privacy.TcfConsent

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

import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID
import static org.prebid.server.functional.util.privacy.TcfConsent.VENDOR_LIST_VERSION

class VendorListResponse {

Expand All @@ -19,9 +18,8 @@ class VendorListResponse {
static VendorListResponse getDefaultVendorListResponse() {
new VendorListResponse().tap {
it.gvlSpecificationVersion = 2
it.tcfPolicyVersion = 2
it.vendorListVersion = VENDOR_LIST_VERSION
it.lastUpdated = ZonedDateTime.now(Clock.systemUTC()).minusWeeks(2)
it.vendors = [(GENERIC_VENDOR_ID): Vendor.defaultVendor]
}
}

Expand All @@ -43,9 +41,9 @@ class VendorListResponse {
Boolean usesNonCookieAccess
Boolean deviceStorageDisclosureUrl

static Vendor getDefaultVendor() {
static Vendor getDefaultVendor(Integer id) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

id can be null? If not, please use int to signify this.

new Vendor().tap {
it.id = GENERIC_VENDOR_ID
it.id = id
it.name = PBSUtils.randomString
it.purposes = [1, 3, 4, 5]
it.legIntPurposes = [2, 7, 10]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.prebid.server.functional.model.request.cookiesync

import groovy.transform.ToString
import org.prebid.server.functional.model.bidder.BidderName

@ToString(includeNames = true, ignoreNulls = true)
class MethodFilter {
class MethodFilter<T> {

List<BidderName> bidders
// Here we use wildcard for different compatibility
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what you meant by this comment.

T bidders
FilterType filter
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package org.prebid.server.functional.model.response.setuid

import groovy.transform.ToString
import io.restassured.http.Headers
import org.prebid.server.functional.model.UidsCookie

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

Headers headers
Map<String, String> headers
UidsCookie uidsCookie
Byte[] responseBody
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class PrebidServerService implements ObjectMapperWrapper {

@Step("[POST] /cookie_sync with headers")
CookieSyncResponse sendCookieSyncRequest(CookieSyncRequest request, Map<String, String> headers) {
def response = postCookieSync(request, headers)
def response = postCookieSync(request, null, headers)

checkResponseStatusCode(response)
response.as(CookieSyncResponse)
Expand All @@ -141,6 +141,14 @@ class PrebidServerService implements ObjectMapperWrapper {
response.as(CookieSyncResponse)
}

@Step("[POST] /cookie_sync with uids cookie")
CookieSyncResponse sendCookieSyncRequest(CookieSyncRequest request, String uidsCookie) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the point of duplicating the method, but using a String instead of POJO?

def response = postCookieSync(request, null, null, null, uidsCookie)

checkResponseStatusCode(response)
response.as(CookieSyncResponse)
}

@Step("[POST] /cookie_sync with uids and additional cookies")
CookieSyncResponse sendCookieSyncRequest(CookieSyncRequest request,
UidsCookie uidsCookie,
Expand All @@ -165,7 +173,7 @@ class PrebidServerService implements ObjectMapperWrapper {
def setuidResponse = new SetuidResponse()
setuidResponse.uidsCookie = getDecodedUidsCookie(response)
setuidResponse.responseBody = response.asByteArray()
setuidResponse.headers = response.headers()
setuidResponse.headers = getHeaders(response)
setuidResponse
}

Expand Down Expand Up @@ -310,25 +318,22 @@ class PrebidServerService implements ObjectMapperWrapper {
.post(AUCTION_ENDPOINT)
}

private Response postCookieSync(CookieSyncRequest cookieSyncRequest, Map<String, String> header) {
postCookieSync(cookieSyncRequest, null, header)
}

private Response postCookieSync(CookieSyncRequest cookieSyncRequest,
UidsCookie uidsCookie = null,
Map<String, ?> additionalCookies = null,
Map<String, String> header = null) {

def cookies = [:]
Map<String, String> header = null,
String uidsAudit = null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here at all.


if (additionalCookies) {
cookies.putAll(additionalCookies)
}
def cookies = additionalCookies ?: [:]

if (uidsCookie) {
cookies.put(UIDS_COOKIE_NAME, Base64.urlEncoder.encodeToString(encode(uidsCookie).bytes))
}

if (uidsAudit) {
cookies.put("uids-audit", uidsAudit)
}

postCookieSync(cookieSyncRequest, cookies, header)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import org.mockserver.matchers.TimeToLive
import org.mockserver.matchers.Times
import org.mockserver.model.HttpRequest
import org.mockserver.model.HttpResponse
import org.prebid.server.functional.model.mock.services.vendorlist.VendorListResponse
import org.testcontainers.containers.MockServerContainer

import static org.mockserver.model.HttpRequest.request
import static org.mockserver.model.HttpResponse.response
import static org.mockserver.model.HttpStatusCode.OK_200
import static org.prebid.server.functional.model.mock.services.vendorlist.VendorListResponse.getDefaultVendorListResponse
import static org.prebid.server.functional.model.mock.services.vendorlist.VendorListResponse.Vendor
import static org.prebid.server.functional.util.privacy.TcfConsent.GENERIC_VENDOR_ID
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion
import static org.prebid.server.functional.util.privacy.TcfConsent.TcfPolicyVersion.TCF_POLICY_V2

class VendorList extends NetworkScaffolding {

Expand All @@ -30,18 +33,17 @@ class VendorList extends NetworkScaffolding {
request().withPath(VENDOR_LIST_ENDPOINT)
}

@Override
void setResponse(){}

void setResponse(TcfPolicyVersion tcfPolicyVersion) {
void setResponse(TcfPolicyVersion tcfPolicyVersion = TCF_POLICY_V2,
Map<Integer, Vendor> vendors = [(GENERIC_VENDOR_ID): Vendor.getDefaultVendor(GENERIC_VENDOR_ID)]) {
def prepareEndpoint = endpoint.replace("{TCF_POLICY}", "v" + tcfPolicyVersion.vendorListVersion)
def prepareEncodeResponseBody = encode(VendorListResponse.defaultVendorListResponse.tap {
it.vendorListVersion = tcfPolicyVersion.vendorListVersion
def prepareEncodeResponseBody = encode(defaultVendorListResponse.tap {
it.tcfPolicyVersion = tcfPolicyVersion.vendorListVersion
it.vendors = vendors
})

mockServerClient.when(request().withPath(prepareEndpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond {request -> request.withPath(endpoint)
? response().withStatusCode(OK_200.code()).withBody(prepareEncodeResponseBody)
: HttpResponse.notFoundResponse()}
.respond { request -> request.withPath(endpoint)
? response().withStatusCode(OK_200.code()).withBody(prepareEncodeResponseBody)
: HttpResponse.notFoundResponse()}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.prebid.server.functional.testcontainers.Dependencies
import org.prebid.server.functional.testcontainers.PbsServiceFactory
import org.prebid.server.functional.testcontainers.scaffolding.Bidder
import org.prebid.server.functional.testcontainers.scaffolding.PrebidCache
import org.prebid.server.functional.testcontainers.scaffolding.VendorList
import org.prebid.server.functional.util.ObjectMapperWrapper
import org.prebid.server.functional.util.PBSUtils
import spock.lang.Specification
Expand All @@ -22,6 +23,7 @@ abstract class BaseSpec extends Specification implements ObjectMapperWrapper {

protected static final PbsServiceFactory pbsServiceFactory = new PbsServiceFactory(networkServiceContainer)
protected static final Bidder bidder = new Bidder(networkServiceContainer)
protected static final VendorList vendorList = new VendorList(networkServiceContainer)
protected static final PrebidCache prebidCache = new PrebidCache(networkServiceContainer)

protected static final HibernateRepositoryService repository = new HibernateRepositoryService(Dependencies.mysqlContainer)
Expand All @@ -40,12 +42,14 @@ abstract class BaseSpec extends Specification implements ObjectMapperWrapper {
def setupSpec() {
prebidCache.setResponse()
bidder.setResponse()
vendorList.setResponse()
}

def cleanupSpec() {
bidder.reset()
prebidCache.reset()
repository.removeAllDatabaseData()
vendorList.reset()
}

protected static int getRandomTimeout() {
Expand Down
Loading
Loading