Skip to content

Commit 63dd6c1

Browse files
authored
Merge branch 'master' into PBS-108
2 parents 44096ba + d97a465 commit 63dd6c1

File tree

169 files changed

+6089
-410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+6089
-410
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
language: go
22

33
go:
4-
- '1.9'
5-
- '1.10'
64
- '1.11.1'
5+
- '1.12'
76

87
go_import_path: github.com/prebid/prebid-server
98

Dockerfile

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
FROM ubuntu:18.04 AS build
2-
WORKDIR /go/src/github.com/prebid/prebid-server/
32
RUN apt-get update && \
43
apt-get -y upgrade && \
5-
apt-get install -y git golang go-dep && \
4+
apt-get install -y wget
5+
RUN cd /tmp && \
6+
wget https://dl.google.com/go/go1.11.11.linux-amd64.tar.gz && \
7+
tar -xf go1.11.11.linux-amd64.tar.gz && \
8+
mv go /usr/local
9+
WORKDIR /go/src/github.com/prebid/prebid-server/
10+
ENV GOROOT=/usr/local/go
11+
ENV GOPATH=/go
12+
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
13+
RUN apt-get install -y git go-dep && \
614
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
7-
ENV GOPATH /go
815
ENV CGO_ENABLED 0
916
COPY ./ ./
1017
RUN dep ensure && \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ For more information, see:
1818

1919
## Installation
2020

21-
First install [Go 1.9.1](https://golang.org/doc/install) or later and [dep](https://golang.github.io/dep/docs/installation.html). Note that dep requires an explicit GOPATH to be set.
21+
First install [Go 1.11](https://golang.org/doc/install) or later and [dep](https://golang.github.io/dep/docs/installation.html). Note that dep requires an explicit GOPATH to be set.
2222

2323
```bash
2424
export GOPATH=$(go env GOPATH)

adapters/33across/33across.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ type ext struct {
2525
}
2626

2727
// MakeRequests create the object for TTX Reqeust.
28-
func (a *TtxAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
28+
func (a *TtxAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
2929
var errs []error
3030
var adapterRequests []*adapters.RequestData
3131

adapters/adapterstest/test_json.go

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,14 @@ import (
5050
// }
5151
//
5252
func RunJSONBidderTest(t *testing.T, rootDir string, bidder adapters.Bidder) {
53-
runTests(t, fmt.Sprintf("%s/exemplary", rootDir), bidder, false)
54-
runTests(t, fmt.Sprintf("%s/supplemental", rootDir), bidder, true)
53+
runTests(t, fmt.Sprintf("%s/exemplary", rootDir), bidder, false, false)
54+
runTests(t, fmt.Sprintf("%s/supplemental", rootDir), bidder, true, false)
55+
runTests(t, fmt.Sprintf("%s/amp", rootDir), bidder, true, true)
5556
}
5657

5758
// runTests runs all the *.json files in a directory. If allowErrors is false, and one of the test files
5859
// expects errors from the bidder, then the test will fail.
59-
func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowErrors bool) {
60+
func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowErrors bool, isAmpTest bool) {
6061
if specFiles, err := ioutil.ReadDir(directory); err == nil {
6162
for _, specFile := range specFiles {
6263
fileName := fmt.Sprintf("%s/%s", directory, specFile.Name())
@@ -68,7 +69,7 @@ func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowError
6869
if !allowErrors && specData.expectsErrors() {
6970
t.Fatalf("Exemplary spec %s must not expect errors.", fileName)
7071
}
71-
runSpec(t, fileName, specData, bidder)
72+
runSpec(t, fileName, specData, bidder, isAmpTest)
7273
}
7374
}
7475
}
@@ -96,8 +97,13 @@ func loadFile(filename string) (*testSpec, error) {
9697
// - That the Bidder's errors match the spec's expectations
9798
//
9899
// More assertions will almost certainly be added in the future, as bugs come up.
99-
func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidder) {
100-
actualReqs, errs := bidder.MakeRequests(&spec.BidRequest)
100+
func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidder, isAmpTest bool) {
101+
reqInfo := adapters.ExtraRequestInfo{}
102+
if isAmpTest {
103+
// simulates AMP entry point
104+
reqInfo.PbsEntryPoint = "amp"
105+
}
106+
actualReqs, errs := bidder.MakeRequests(&spec.BidRequest, &reqInfo)
101107
diffErrorLists(t, fmt.Sprintf("%s: MakeRequests", filename), errs, spec.MakeRequestErrors)
102108
diffHttpRequestLists(t, filename, actualReqs, spec.HttpCalls)
103109

adapters/adform/adform.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adform
22

33
import (
4+
"bytes"
45
"context"
56
"encoding/base64"
67
"encoding/json"
@@ -57,6 +58,8 @@ type adformDigitrustPrivacy struct {
5758
type adformAdUnit struct {
5859
MasterTagId json.Number `json:"mid"`
5960
PriceType string `json:"priceType,omitempty"`
61+
KeyValues string `json:"mkv,omitempty"`
62+
KeyWords string `json:"mkw,omitempty"`
6063

6164
bidId string
6265
adUnitCode string
@@ -287,8 +290,15 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {
287290

288291
adUnitsParams := make([]string, 0, len(r.adUnits))
289292
for _, adUnit := range r.adUnits {
290-
str := fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.currency)
291-
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte(str)))
293+
var buffer bytes.Buffer
294+
buffer.WriteString(fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.currency))
295+
if adUnit.KeyValues != "" {
296+
buffer.WriteString(fmt.Sprintf("&mkv=%s", adUnit.KeyValues))
297+
}
298+
if adUnit.KeyWords != "" {
299+
buffer.WriteString(fmt.Sprintf("&mkw=%s", adUnit.KeyWords))
300+
}
301+
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(buffer.Bytes()))
292302
}
293303

294304
return fmt.Sprintf("%s&%s", uri, strings.Join(adUnitsParams, "&"))
@@ -371,7 +381,7 @@ func NewAdformBidder(client *http.Client, endpointURL string) *AdformAdapter {
371381
}
372382
}
373383

374-
func (a *AdformAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
384+
func (a *AdformAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
375385
adformRequest, errors := openRtbToAdformRequest(request)
376386
if len(adformRequest.adUnits) == 0 {
377387
return nil, errors

adapters/adform/adform_test.go

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ func TestJsonSamples(t *testing.T) {
3030
type aTagInfo struct {
3131
mid uint32
3232
priceType string
33+
keyValues string
34+
keyWords string
3335
code string
3436

3537
price float64
@@ -161,22 +163,7 @@ func TestAdformBasicResponse(t *testing.T) {
161163
}
162164

163165
func initTestData(server *httptest.Server, t *testing.T) (*AdformAdapter, context.Context, *pbs.PBSRequest) {
164-
adformTestData = aBidInfo{
165-
deviceIP: "111.111.111.111",
166-
deviceUA: "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301",
167-
deviceIFA: "6D92078A-8246-4BA4-AE5B-76104861E7DC",
168-
tags: make([]aTagInfo, 3),
169-
referrer: "http://test.com",
170-
width: 200,
171-
height: 300,
172-
tid: "transaction-id",
173-
buyerUID: "user-id",
174-
secure: false,
175-
currency: "EUR",
176-
}
177-
adformTestData.tags[0] = aTagInfo{mid: 32344, priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"}
178-
adformTestData.tags[1] = aTagInfo{mid: 32345, priceType: "net", code: "code2"} // no bid for ad unit
179-
adformTestData.tags[2] = aTagInfo{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"}
166+
adformTestData = createTestData(false)
180167

181168
// prepare adapter
182169
conf := *adapters.DefaultHTTPAdapterConfig
@@ -253,7 +240,7 @@ func preparePrebidRequestBody(requestData aBidInfo, t *testing.T) *bytes.Buffer
253240
{
254241
BidderCode: "adform",
255242
BidID: fmt.Sprintf("random-id-from-pbjs-%d", i),
256-
Params: json.RawMessage(fmt.Sprintf("{\"mid\": %d%s}", tag.mid, getPriceTypeString(tag.priceType))),
243+
Params: json.RawMessage(formatAdUnitJson(tag)),
257244
},
258245
},
259246
}
@@ -273,10 +260,10 @@ func preparePrebidRequestBody(requestData aBidInfo, t *testing.T) *bytes.Buffer
273260
func TestOpenRTBRequest(t *testing.T) {
274261
bidder := NewAdformBidder(nil, "http://adx.adform.net")
275262

276-
testData := createTestData()
277-
request := createOpenRtbRequest(testData)
263+
testData := createTestData(true)
264+
request := createOpenRtbRequest(&testData)
278265

279-
httpRequests, errs := bidder.MakeRequests(request)
266+
httpRequests, errs := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})
280267

281268
if len(errs) > 0 {
282269
t.Errorf("Got unexpected errors while building HTTP requests: %v", errs)
@@ -291,7 +278,7 @@ func TestOpenRTBRequest(t *testing.T) {
291278
}
292279
r.Header = httpRequests[0].Headers
293280

294-
errorString := assertAdformServerRequest(*testData, r, true)
281+
errorString := assertAdformServerRequest(testData, r, true)
295282
if errorString != nil {
296283
t.Errorf("Request error: %s", *errorString)
297284
}
@@ -311,7 +298,7 @@ func TestOpenRTBIncorrectRequest(t *testing.T) {
311298
User: &openrtb.User{BuyerUID: "buyerUID"},
312299
}
313300

314-
httpRequests, errs := bidder.MakeRequests(request)
301+
httpRequests, errs := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})
315302

316303
if len(errs) != len(request.Imp) {
317304
t.Errorf("%d Imp objects should have errors. but was %d errors", len(request.Imp), len(errs))
@@ -321,20 +308,20 @@ func TestOpenRTBIncorrectRequest(t *testing.T) {
321308
}
322309
}
323310

324-
func createTestData() *aBidInfo {
325-
testData := &aBidInfo{
311+
func createTestData(secure bool) aBidInfo {
312+
testData := aBidInfo{
326313
deviceIP: "111.111.111.111",
327314
deviceUA: "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301",
328315
deviceIFA: "6D92078A-8246-4BA4-AE5B-76104861E7DC",
329316
referrer: "http://test.com",
330317
tid: "transaction-id",
331318
buyerUID: "user-id",
332319
tags: []aTagInfo{
333-
{mid: 32344, priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
320+
{mid: 32344, keyValues: "color:red,age:30-40", keyWords: "red,blue", priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
334321
{mid: 32345, priceType: "net", code: "code2"}, // no bid for ad unit
335322
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"},
336323
},
337-
secure: true,
324+
secure: secure,
338325
currency: "EUR",
339326
}
340327
return testData
@@ -368,7 +355,7 @@ func createOpenRtbRequest(testData *aBidInfo) *openrtb.BidRequest {
368355
bidRequest.Imp[i] = openrtb.Imp{
369356
ID: tag.code,
370357
Secure: &secure,
371-
Ext: json.RawMessage(fmt.Sprintf("{\"bidder\": { \"mid\": %d%s}}", tag.mid, getPriceTypeString(tag.priceType))),
358+
Ext: json.RawMessage(fmt.Sprintf("{\"bidder\": %s}", formatAdUnitJson(tag))),
372359
Banner: &openrtb.Banner{},
373360
}
374361
}
@@ -384,10 +371,10 @@ func createOpenRtbRequest(testData *aBidInfo) *openrtb.BidRequest {
384371
}
385372

386373
func TestOpenRTBStandardResponse(t *testing.T) {
387-
testData := createTestData()
388-
request := createOpenRtbRequest(testData)
374+
testData := createTestData(true)
375+
request := createOpenRtbRequest(&testData)
389376

390-
responseBody, err := createAdformServerResponse(*testData)
377+
responseBody, err := createAdformServerResponse(testData)
391378
if err != nil {
392379
t.Fatalf("Unable to create server response: %v", err)
393380
return
@@ -502,9 +489,17 @@ func getUserExt() []byte {
502489
return nil
503490
}
504491

505-
func getPriceTypeString(priceType string) string {
506-
if priceType != "" {
507-
return fmt.Sprintf(", \"priceType\": \"%s\"", priceType)
492+
func formatAdUnitJson(tag aTagInfo) string {
493+
return fmt.Sprintf("{ \"mid\": %d%s%s%s}",
494+
tag.mid,
495+
formatAdUnitParam("priceType", tag.priceType),
496+
formatAdUnitParam("mkv", tag.keyValues),
497+
formatAdUnitParam("mkw", tag.keyWords))
498+
}
499+
500+
func formatAdUnitParam(fieldName string, fieldValue string) string {
501+
if fieldValue != "" {
502+
return fmt.Sprintf(", \"%s\": \"%s\"", fieldName, fieldValue)
508503
}
509504

510505
return ""
@@ -522,9 +517,9 @@ func assertAdformServerRequest(testData aBidInfo, r *http.Request, isOpenRtb boo
522517

523518
var midsWithCurrency = ""
524519
if isOpenRtb {
525-
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVS&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
520+
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
526521
} else {
527-
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNE&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
522+
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
528523
}
529524

530525
if ok, err := equal("CC=1&adid=6D92078A-8246-4BA4-AE5B-76104861E7DC&fd=1&gdpr=1&gdpr_consent=abc&ip=111.111.111.111&pt=gross&rp=4&stid=transaction-id&"+midsWithCurrency, r.URL.RawQuery, "Query string"); !ok {

adapters/adform/params_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ var validParams = []string{
4444
`{"mid":"123"}`,
4545
`{"mid":123,"priceType":"gross"}`,
4646
`{"mid":"123","priceType":"net"}`,
47+
`{"mid":"123","mkv":" color :blue , length : 350"}`,
48+
`{"mid":"123","mkv":"color:"}`,
49+
`{"mid":"123","mkw":"green,male"}`,
50+
`{"mid":"123","mkv":" ","mkw":" "}`,
4751
}
4852

4953
var invalidParams = []string{
@@ -55,4 +59,11 @@ var invalidParams = []string{
5559
`[]`,
5660
`{}`,
5761
`{"notmid":"123"}`,
62+
`{"mid":"123","priceType":"ne"}`,
63+
`{"mid":"123","mkv":"color:blue,:350"}`,
64+
`{"mid":"123","mkv":"color:blue;length:350"}`,
65+
`{"mid":"123","mkv":"color"}`,
66+
`{"mid":"123","mkv":"color:blue,l&ngth:350"}`,
67+
`{"mid":"123","mkv":"color::blue"}`,
68+
`{"mid":"123","mkw":"fem&le"}`,
5869
}

adapters/adkernelAdn/adkernelAdn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type adkernelAdnAdapter struct {
2121
}
2222

2323
//MakeRequests prepares request information for prebid-server core
24-
func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
24+
func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
2525
errs := make([]error, 0, len(request.Imp))
2626
if len(request.Imp) == 0 {
2727
errs = append(errs, newBadInputError("No impression in the bid request"))

adapters/adtelligent/adtelligent.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type adtelligentImpExt struct {
1919
Adtelligent openrtb_ext.ExtImpAdtelligent `json:"adtelligent"`
2020
}
2121

22-
func (a *AdtelligentAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
22+
func (a *AdtelligentAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
2323

2424
totalImps := len(request.Imp)
2525
errors := make([]error, 0, totalImps)

0 commit comments

Comments
 (0)