Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package org.prebid.server.functional.model.response.vtrack

import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import org.prebid.server.functional.util.PBSUtils

@ToString(includeNames = true, ignoreNulls = true)
@EqualsAndHashCode
class TransferValue {

String adm
Integer width
Integer height

static final TransferValue getTransferValue(){
return new TransferValue().tap {
adm = PBSUtils.randomString
width = 300
height = 250
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.prebid.server.functional.model.response.getuids.GetuidResponse
import org.prebid.server.functional.model.response.infobidders.BidderInfoResponse
import org.prebid.server.functional.model.response.setuid.SetuidResponse
import org.prebid.server.functional.model.response.status.StatusResponse
import org.prebid.server.functional.model.response.vtrack.TransferValue
import org.prebid.server.functional.testcontainers.container.PrebidServerContainer
import org.prebid.server.functional.util.ObjectMapperWrapper
import org.prebid.server.functional.util.PBSUtils
Expand Down Expand Up @@ -73,7 +74,7 @@ class PrebidServerService implements ObjectMapperWrapper {
authenticationScheme.password = pbsContainer.ADMIN_ENDPOINT_PASSWORD
this.pbsContainer = pbsContainer
requestSpecification = new RequestSpecBuilder().setBaseUri(pbsContainer.rootUri)
.build()
.build()
adminRequestSpecification = buildAndGetRequestSpecification(pbsContainer.adminRootUri, authenticationScheme)
prometheusRequestSpecification = buildAndGetRequestSpecification(pbsContainer.prometheusRootUri, authenticationScheme)
}
Expand Down Expand Up @@ -198,30 +199,39 @@ class PrebidServerService implements ObjectMapperWrapper {
def uidsCookieAsEncodedJson = Base64.urlEncoder.encodeToString(uidsCookieAsJson.bytes)

def response = given(requestSpecification).cookie(UIDS_COOKIE_NAME, uidsCookieAsEncodedJson)
.get(GET_UIDS_ENDPOINT)
.get(GET_UIDS_ENDPOINT)

checkResponseStatusCode(response)
decode(response.body.asString(), GetuidResponse)
}

byte[] sendEventRequest(EventRequest eventRequest, Map<String, String> headers = [:]) {
def response = given(requestSpecification).headers(headers)
.queryParams(toMap(eventRequest))
.get(EVENT_ENDPOINT)
.queryParams(toMap(eventRequest))
.get(EVENT_ENDPOINT)

checkResponseStatusCode(response)
response.body.asByteArray()
}

PrebidCacheResponse sendVtrackRequest(VtrackRequest request, String account) {
PrebidCacheResponse sendPostVtrackRequest(VtrackRequest request, String account) {
def response = given(requestSpecification).queryParam("a", account)
.body(request)
.post(VTRACK_ENDPOINT)
.body(request)
.post(VTRACK_ENDPOINT)

checkResponseStatusCode(response)
decode(response.body.asString(), PrebidCacheResponse)
}

TransferValue sendGetVtrackRequest(Map<String, Object> parameters) {
def response = given(requestSpecification)
.queryParams(parameters)
.get(VTRACK_ENDPOINT)

checkResponseStatusCode(response)
decode(response.body.asString(), TransferValue)
}

StatusResponse sendStatusRequest() {
def response = given(requestSpecification).get(STATUS_ENDPOINT)

Expand Down Expand Up @@ -267,7 +277,7 @@ class PrebidServerService implements ObjectMapperWrapper {

String sendLoggingHttpInteractionRequest(HttpInteractionRequest httpInteractionRequest) {
def response = given(adminRequestSpecification).queryParams(toMap(httpInteractionRequest))
.get(HTTP_INTERACTION_ENDPOINT)
.get(HTTP_INTERACTION_ENDPOINT)

checkResponseStatusCode(response)
response.body().asString()
Expand Down Expand Up @@ -296,8 +306,8 @@ class PrebidServerService implements ObjectMapperWrapper {
def payload = encode(bidRequest)

given(requestSpecification).headers(headers)
.body(payload)
.post(AUCTION_ENDPOINT)
.body(payload)
.post(AUCTION_ENDPOINT)
}

private Response postCookieSync(CookieSyncRequest cookieSyncRequest,
Expand Down Expand Up @@ -388,7 +398,7 @@ class PrebidServerService implements ObjectMapperWrapper {
throw new IllegalArgumentException("The end time of the test is less than the start time")
}
def formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss")
.withZone(ZoneId.from(UTC))
.withZone(ZoneId.from(UTC))
def logs = Arrays.asList(pbsContainer.logs.split("\n"))
def filteredLogs = []

Expand Down Expand Up @@ -441,7 +451,7 @@ class PrebidServerService implements ObjectMapperWrapper {

private static RequestSpecification buildAndGetRequestSpecification(String uri, AuthenticationScheme authScheme) {
new RequestSpecBuilder().setBaseUri(uri)
.setAuth(authScheme)
.build()
.setAuth(authScheme)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,17 @@ abstract class NetworkScaffolding implements ObjectMapperWrapper {

int getRequestCount(HttpRequest httpRequest) {
mockServerClient.retrieveRecordedRequests(httpRequest)
.size()
.size()
}

int getRequestCount(String value) {
mockServerClient.retrieveRecordedRequests(getRequest(value))
.size()
.size()
}

int getRequestCount() {
mockServerClient.retrieveRecordedRequests(request)
.size()
.size()
}

void setResponse(HttpRequest httpRequest,
Expand All @@ -56,8 +56,8 @@ abstract class NetworkScaffolding implements ObjectMapperWrapper {
Times times = Times.exactly(1)) {
def mockResponse = encode(responseModel)
mockServerClient.when(httpRequest, times)
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON))
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON))
}

void setResponse(String value,
Expand All @@ -73,9 +73,9 @@ abstract class NetworkScaffolding implements ObjectMapperWrapper {
def responseHeaders = headers.collect { new Header(it.key, it.value) }
def mockResponse = encode(responseModel)
mockServerClient.when(getRequest(value), Times.unlimited())
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON)
.withHeaders(responseHeaders))
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON)
.withHeaders(responseHeaders))
}

void setResponse(String value,
Expand All @@ -86,39 +86,39 @@ abstract class NetworkScaffolding implements ObjectMapperWrapper {
def responseHeaders = headers.collect { new Header(it.key, it.value) }
def mockResponse = encode(responseModel)
mockServerClient.when(getRequest(value), Times.unlimited())
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON)
.withHeaders(responseHeaders)
.withDelay(TimeUnit.MILLISECONDS, responseDelay))
.respond(response().withStatusCode(statusCode.code())
.withBody(mockResponse, APPLICATION_JSON)
.withHeaders(responseHeaders)
.withDelay(TimeUnit.MILLISECONDS, responseDelay))
}

void setResponse(String value, String mockResponse) {
mockServerClient.when(getRequest(value), Times.exactly(1))
.respond(response().withStatusCode(OK_200.code())
.withBody(mockResponse, APPLICATION_JSON))
.respond(response().withStatusCode(OK_200.code())
.withBody(mockResponse, APPLICATION_JSON))
}

void setResponse(ResponseModel responseModel) {
def mockResponse = encode(responseModel)
mockServerClient.when(request().withPath(endpoint))
.respond(response().withStatusCode(OK_200.code())
.withBody(mockResponse, APPLICATION_JSON))
.respond(response().withStatusCode(OK_200.code())
.withBody(mockResponse, APPLICATION_JSON))
}

void setResponse(String value, HttpStatusCode httpStatusCode) {
mockServerClient.when(getRequest(value), Times.exactly(1))
.respond(response().withStatusCode(httpStatusCode.code()))
.respond(response().withStatusCode(httpStatusCode.code()))
}

void setResponse(String value, HttpStatusCode httpStatusCode, String errorText) {
mockServerClient.when(getRequest(value), Times.exactly(1))
.respond(response().withStatusCode(httpStatusCode.code())
.withBody(errorText, APPLICATION_JSON))
.respond(response().withStatusCode(httpStatusCode.code())
.withBody(errorText, APPLICATION_JSON))
}

void setResponseWithTimeout(String value, int timeoutSec = 5) {
mockServerClient.when(getRequest(value), Times.exactly(1))
.respond(response().withDelay(SECONDS, timeoutSec))
.respond(response().withDelay(SECONDS, timeoutSec))
}

protected def getRequestAndResponse() {
Expand All @@ -130,14 +130,19 @@ abstract class NetworkScaffolding implements ObjectMapperWrapper {
.collect { it.body.toString() }
}

String getRecordedRequestsQueryParameters(HttpRequest httpRequest) {
mockServerClient.retrieveRecordedRequests(httpRequest)
.collect { it -> it.queryStringParameters.multimap.toString()}
}

List<String> getRecordedRequestsBody(String value) {
mockServerClient.retrieveRecordedRequests(getRequest(value))
.collect { it.body.toString() }
.collect { it.body.toString() }
}

List<String> getRecordedRequestsBody() {
mockServerClient.retrieveRecordedRequests(request)
.collect { it.body.toString() }
.collect { it.body.toString() }
}

Map<String, List<String>> getLastRecordedRequestHeaders(HttpRequest httpRequest) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ import org.mockserver.model.HttpResponse
import org.prebid.server.functional.model.mock.services.prebidcache.response.CacheObject
import org.prebid.server.functional.model.mock.services.prebidcache.response.PrebidCacheResponse
import org.prebid.server.functional.model.request.cache.BidCacheRequest
import org.prebid.server.functional.model.response.vtrack.TransferValue
import org.prebid.server.functional.util.PBSUtils
import org.testcontainers.containers.MockServerContainer

import java.util.stream.Stream

import static org.mockserver.model.HttpRequest.request
import static org.mockserver.model.HttpResponse.response
import static org.mockserver.model.HttpStatusCode.INTERNAL_SERVER_ERROR_500
import static org.mockserver.model.HttpStatusCode.OK_200
import static org.mockserver.model.JsonPathBody.jsonPath

Expand All @@ -24,6 +27,11 @@ class PrebidCache extends NetworkScaffolding {
super(mockServerContainer, CACHE_ENDPOINT)
}

String getVTracGetRequestParams() {
getRecordedRequestsQueryParameters(request().withMethod("GET")
.withPath(CACHE_ENDPOINT))
}

void setXmlCacheResponse(String payload, PrebidCacheResponse prebidCacheResponse) {
setResponse(getXmlCacheRequest(payload), prebidCacheResponse)
}
Expand All @@ -43,8 +51,8 @@ class PrebidCache extends NetworkScaffolding {
@Override
protected HttpRequest getRequest(String impId) {
request().withMethod("POST")
.withPath(CACHE_ENDPOINT)
.withBody(jsonPath("\$.puts[?(@.value.impid == '$impId')]"))
.withPath(CACHE_ENDPOINT)
.withBody(jsonPath("\$.puts[?(@.value.impid == '$impId')]"))
}

List<BidCacheRequest> getRecordedRequests(String impId) {
Expand All @@ -59,21 +67,52 @@ class PrebidCache extends NetworkScaffolding {
@Override
HttpRequest getRequest() {
request().withMethod("POST")
.withPath(CACHE_ENDPOINT)
.withPath(CACHE_ENDPOINT)
}

@Override
void setResponse() {
mockServerClient.when(request().withPath(endpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond{request -> request.withPath(endpoint)
? response().withStatusCode(OK_200.code()).withBody(getBodyByRequest(request))
: HttpResponse.notFoundResponse()}
mockServerClient.when(request()
.withMethod("POST")
.withPath(endpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond { request ->
request.withPath(endpoint)
? response().withStatusCode(OK_200.code()).withBody(getBodyByRequest(request))
: HttpResponse.notFoundResponse()
}
}

void setGetResponse(TransferValue vTrackResponse) {
mockServerClient.when(request()
.withMethod("GET")
.withPath(endpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond { request ->
request.withPath(endpoint)
? response().withStatusCode(OK_200.code()).withBody(encode(vTrackResponse))
: HttpResponse.notFoundResponse()
}
}

void setInvalidPostResponse() {
mockServerClient.when(request()
.withMethod("POST")
.withPath(endpoint), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond { response().withStatusCode(INTERNAL_SERVER_ERROR_500.code()) }
}

void setInvalidGetResponse(String uuid, String errorMessage = PBSUtils.randomString) {
mockServerClient.when(request()
.withMethod("GET")
.withPath(endpoint)
.withQueryStringParameter("uuid", uuid), Times.unlimited(), TimeToLive.unlimited(), -10)
.respond { response().withBody(errorMessage).withStatusCode(INTERNAL_SERVER_ERROR_500.code()) }

}

private static HttpRequest getXmlCacheRequest(String payload) {
request().withMethod("POST")
.withPath(CACHE_ENDPOINT)
.withBody(jsonPath("\$.puts[?(@.value =~/^.*$payload.*\$/)]"))
.withPath(CACHE_ENDPOINT)
.withBody(jsonPath("\$.puts[?(@.value =~/^.*$payload.*\$/)]"))
}

private String getBodyByRequest(HttpRequest request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class BidderParamsSpec extends BaseSpec {
accountDao.save(account)

when: "PBS processes vtrack request"
pbsService.sendVtrackRequest(request, accountId.toString())
pbsService.sendPostVtrackRequest(request, accountId.toString())

then: "vast xml is modified"
def prebidCacheRequest = prebidCache.getXmlRecordedRequestsBody(payload)
Expand Down Expand Up @@ -172,7 +172,7 @@ class BidderParamsSpec extends BaseSpec {
accountDao.save(account)

when: "PBS processes vtrack request"
pbsService.sendVtrackRequest(request, accountId.toString())
pbsService.sendPostVtrackRequest(request, accountId.toString())

then: "vast xml is not modified"
def prebidCacheRequest = prebidCache.getXmlRecordedRequestsBody(payload)
Expand Down
Loading