Skip to content

Commit

Permalink
Merge branch 'master' into PBS-108
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon authored Jul 15, 2019
2 parents 44096ba + d97a465 commit 63dd6c1
Show file tree
Hide file tree
Showing 169 changed files with 6,089 additions and 410 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: go

go:
- '1.9'
- '1.10'
- '1.11.1'
- '1.12'

go_import_path: github.com/prebid/prebid-server

Expand Down
13 changes: 10 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
FROM ubuntu:18.04 AS build
WORKDIR /go/src/github.com/prebid/prebid-server/
RUN apt-get update && \
apt-get -y upgrade && \
apt-get install -y git golang go-dep && \
apt-get install -y wget
RUN cd /tmp && \
wget https://dl.google.com/go/go1.11.11.linux-amd64.tar.gz && \
tar -xf go1.11.11.linux-amd64.tar.gz && \
mv go /usr/local
WORKDIR /go/src/github.com/prebid/prebid-server/
ENV GOROOT=/usr/local/go
ENV GOPATH=/go
ENV PATH=$GOPATH/bin:$GOROOT/bin:$PATH
RUN apt-get install -y git go-dep && \
apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENV GOPATH /go
ENV CGO_ENABLED 0
COPY ./ ./
RUN dep ensure && \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ For more information, see:

## Installation

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.
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.

```bash
export GOPATH=$(go env GOPATH)
Expand Down
2 changes: 1 addition & 1 deletion adapters/33across/33across.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type ext struct {
}

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

Expand Down
18 changes: 12 additions & 6 deletions adapters/adapterstest/test_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,14 @@ import (
// }
//
func RunJSONBidderTest(t *testing.T, rootDir string, bidder adapters.Bidder) {
runTests(t, fmt.Sprintf("%s/exemplary", rootDir), bidder, false)
runTests(t, fmt.Sprintf("%s/supplemental", rootDir), bidder, true)
runTests(t, fmt.Sprintf("%s/exemplary", rootDir), bidder, false, false)
runTests(t, fmt.Sprintf("%s/supplemental", rootDir), bidder, true, false)
runTests(t, fmt.Sprintf("%s/amp", rootDir), bidder, true, true)
}

// runTests runs all the *.json files in a directory. If allowErrors is false, and one of the test files
// expects errors from the bidder, then the test will fail.
func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowErrors bool) {
func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowErrors bool, isAmpTest bool) {
if specFiles, err := ioutil.ReadDir(directory); err == nil {
for _, specFile := range specFiles {
fileName := fmt.Sprintf("%s/%s", directory, specFile.Name())
Expand All @@ -68,7 +69,7 @@ func runTests(t *testing.T, directory string, bidder adapters.Bidder, allowError
if !allowErrors && specData.expectsErrors() {
t.Fatalf("Exemplary spec %s must not expect errors.", fileName)
}
runSpec(t, fileName, specData, bidder)
runSpec(t, fileName, specData, bidder, isAmpTest)
}
}
}
Expand Down Expand Up @@ -96,8 +97,13 @@ func loadFile(filename string) (*testSpec, error) {
// - That the Bidder's errors match the spec's expectations
//
// More assertions will almost certainly be added in the future, as bugs come up.
func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidder) {
actualReqs, errs := bidder.MakeRequests(&spec.BidRequest)
func runSpec(t *testing.T, filename string, spec *testSpec, bidder adapters.Bidder, isAmpTest bool) {
reqInfo := adapters.ExtraRequestInfo{}
if isAmpTest {
// simulates AMP entry point
reqInfo.PbsEntryPoint = "amp"
}
actualReqs, errs := bidder.MakeRequests(&spec.BidRequest, &reqInfo)
diffErrorLists(t, fmt.Sprintf("%s: MakeRequests", filename), errs, spec.MakeRequestErrors)
diffHttpRequestLists(t, filename, actualReqs, spec.HttpCalls)

Expand Down
16 changes: 13 additions & 3 deletions adapters/adform/adform.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package adform

import (
"bytes"
"context"
"encoding/base64"
"encoding/json"
Expand Down Expand Up @@ -57,6 +58,8 @@ type adformDigitrustPrivacy struct {
type adformAdUnit struct {
MasterTagId json.Number `json:"mid"`
PriceType string `json:"priceType,omitempty"`
KeyValues string `json:"mkv,omitempty"`
KeyWords string `json:"mkw,omitempty"`

bidId string
adUnitCode string
Expand Down Expand Up @@ -287,8 +290,15 @@ func (r *adformRequest) buildAdformUrl(a *AdformAdapter) string {

adUnitsParams := make([]string, 0, len(r.adUnits))
for _, adUnit := range r.adUnits {
str := fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.currency)
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString([]byte(str)))
var buffer bytes.Buffer
buffer.WriteString(fmt.Sprintf("mid=%s&rcur=%s", adUnit.MasterTagId, r.currency))
if adUnit.KeyValues != "" {
buffer.WriteString(fmt.Sprintf("&mkv=%s", adUnit.KeyValues))
}
if adUnit.KeyWords != "" {
buffer.WriteString(fmt.Sprintf("&mkw=%s", adUnit.KeyWords))
}
adUnitsParams = append(adUnitsParams, base64.URLEncoding.WithPadding(base64.NoPadding).EncodeToString(buffer.Bytes()))
}

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

func (a *AdformAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
func (a *AdformAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
adformRequest, errors := openRtbToAdformRequest(request)
if len(adformRequest.adUnits) == 0 {
return nil, errors
Expand Down
65 changes: 30 additions & 35 deletions adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ func TestJsonSamples(t *testing.T) {
type aTagInfo struct {
mid uint32
priceType string
keyValues string
keyWords string
code string

price float64
Expand Down Expand Up @@ -161,22 +163,7 @@ func TestAdformBasicResponse(t *testing.T) {
}

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

// prepare adapter
conf := *adapters.DefaultHTTPAdapterConfig
Expand Down Expand Up @@ -253,7 +240,7 @@ func preparePrebidRequestBody(requestData aBidInfo, t *testing.T) *bytes.Buffer
{
BidderCode: "adform",
BidID: fmt.Sprintf("random-id-from-pbjs-%d", i),
Params: json.RawMessage(fmt.Sprintf("{\"mid\": %d%s}", tag.mid, getPriceTypeString(tag.priceType))),
Params: json.RawMessage(formatAdUnitJson(tag)),
},
},
}
Expand All @@ -273,10 +260,10 @@ func preparePrebidRequestBody(requestData aBidInfo, t *testing.T) *bytes.Buffer
func TestOpenRTBRequest(t *testing.T) {
bidder := NewAdformBidder(nil, "http://adx.adform.net")

testData := createTestData()
request := createOpenRtbRequest(testData)
testData := createTestData(true)
request := createOpenRtbRequest(&testData)

httpRequests, errs := bidder.MakeRequests(request)
httpRequests, errs := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})

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

errorString := assertAdformServerRequest(*testData, r, true)
errorString := assertAdformServerRequest(testData, r, true)
if errorString != nil {
t.Errorf("Request error: %s", *errorString)
}
Expand All @@ -311,7 +298,7 @@ func TestOpenRTBIncorrectRequest(t *testing.T) {
User: &openrtb.User{BuyerUID: "buyerUID"},
}

httpRequests, errs := bidder.MakeRequests(request)
httpRequests, errs := bidder.MakeRequests(request, &adapters.ExtraRequestInfo{})

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

func createTestData() *aBidInfo {
testData := &aBidInfo{
func createTestData(secure bool) aBidInfo {
testData := aBidInfo{
deviceIP: "111.111.111.111",
deviceUA: "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E8301",
deviceIFA: "6D92078A-8246-4BA4-AE5B-76104861E7DC",
referrer: "http://test.com",
tid: "transaction-id",
buyerUID: "user-id",
tags: []aTagInfo{
{mid: 32344, priceType: "gross", code: "code1", price: 1.23, content: "banner-content1", dealId: "dealId1", creativeId: "creativeId1"},
{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"},
{mid: 32345, priceType: "net", code: "code2"}, // no bid for ad unit
{mid: 32346, code: "code3", price: 1.24, content: "banner-content2", dealId: "dealId2"},
},
secure: true,
secure: secure,
currency: "EUR",
}
return testData
Expand Down Expand Up @@ -368,7 +355,7 @@ func createOpenRtbRequest(testData *aBidInfo) *openrtb.BidRequest {
bidRequest.Imp[i] = openrtb.Imp{
ID: tag.code,
Secure: &secure,
Ext: json.RawMessage(fmt.Sprintf("{\"bidder\": { \"mid\": %d%s}}", tag.mid, getPriceTypeString(tag.priceType))),
Ext: json.RawMessage(fmt.Sprintf("{\"bidder\": %s}", formatAdUnitJson(tag))),
Banner: &openrtb.Banner{},
}
}
Expand All @@ -384,10 +371,10 @@ func createOpenRtbRequest(testData *aBidInfo) *openrtb.BidRequest {
}

func TestOpenRTBStandardResponse(t *testing.T) {
testData := createTestData()
request := createOpenRtbRequest(testData)
testData := createTestData(true)
request := createOpenRtbRequest(&testData)

responseBody, err := createAdformServerResponse(*testData)
responseBody, err := createAdformServerResponse(testData)
if err != nil {
t.Fatalf("Unable to create server response: %v", err)
return
Expand Down Expand Up @@ -502,9 +489,17 @@ func getUserExt() []byte {
return nil
}

func getPriceTypeString(priceType string) string {
if priceType != "" {
return fmt.Sprintf(", \"priceType\": \"%s\"", priceType)
func formatAdUnitJson(tag aTagInfo) string {
return fmt.Sprintf("{ \"mid\": %d%s%s%s}",
tag.mid,
formatAdUnitParam("priceType", tag.priceType),
formatAdUnitParam("mkv", tag.keyValues),
formatAdUnitParam("mkw", tag.keyWords))
}

func formatAdUnitParam(fieldName string, fieldValue string) string {
if fieldValue != "" {
return fmt.Sprintf(", \"%s\": \"%s\"", fieldName, fieldValue)
}

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

var midsWithCurrency = ""
if isOpenRtb {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVS&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9RVVSJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9RVVS&bWlkPTMyMzQ2JnJjdXI9RVVS"
} else {
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNE&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
midsWithCurrency = "bWlkPTMyMzQ0JnJjdXI9VVNEJm1rdj1jb2xvcjpyZWQsYWdlOjMwLTQwJm1rdz1yZWQsYmx1ZQ&bWlkPTMyMzQ1JnJjdXI9VVNE&bWlkPTMyMzQ2JnJjdXI9VVNE" // no way to pass currency in legacy adapter
}

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 {
Expand Down
11 changes: 11 additions & 0 deletions adapters/adform/params_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ var validParams = []string{
`{"mid":"123"}`,
`{"mid":123,"priceType":"gross"}`,
`{"mid":"123","priceType":"net"}`,
`{"mid":"123","mkv":" color :blue , length : 350"}`,
`{"mid":"123","mkv":"color:"}`,
`{"mid":"123","mkw":"green,male"}`,
`{"mid":"123","mkv":" ","mkw":" "}`,
}

var invalidParams = []string{
Expand All @@ -55,4 +59,11 @@ var invalidParams = []string{
`[]`,
`{}`,
`{"notmid":"123"}`,
`{"mid":"123","priceType":"ne"}`,
`{"mid":"123","mkv":"color:blue,:350"}`,
`{"mid":"123","mkv":"color:blue;length:350"}`,
`{"mid":"123","mkv":"color"}`,
`{"mid":"123","mkv":"color:blue,l&ngth:350"}`,
`{"mid":"123","mkv":"color::blue"}`,
`{"mid":"123","mkw":"fem&le"}`,
}
2 changes: 1 addition & 1 deletion adapters/adkernelAdn/adkernelAdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type adkernelAdnAdapter struct {
}

//MakeRequests prepares request information for prebid-server core
func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest) ([]*adapters.RequestData, []error) {
func (adapter *adkernelAdnAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
errs := make([]error, 0, len(request.Imp))
if len(request.Imp) == 0 {
errs = append(errs, newBadInputError("No impression in the bid request"))
Expand Down
2 changes: 1 addition & 1 deletion adapters/adtelligent/adtelligent.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type adtelligentImpExt struct {
Adtelligent openrtb_ext.ExtImpAdtelligent `json:"adtelligent"`
}

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

totalImps := len(request.Imp)
errors := make([]error, 0, totalImps)
Expand Down
Loading

0 comments on commit 63dd6c1

Please sign in to comment.