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

Uoe 4837 v0.97.0 #15

Merged
merged 14 commits into from
Jan 30, 2020
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
16 changes: 13 additions & 3 deletions adapters/33across/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ import (
"text/template"

"github.com/PubMatic-OpenWrap/prebid-server/privacy"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/ccpa"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/gdpr"
"github.com/stretchr/testify/assert"
)

func Test33AcrossSyncer(t *testing.T) {
syncURL := "https://ic.tynt.com/r/d?m=xch&rt=html&ri=123&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz"
syncURL := "https://ic.tynt.com/r/d?m=xch&rt=html&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz"
syncURLTemplate := template.Must(
template.New("sync-template").Parse(syncURL),
)

syncer := New33AcrossSyncer(syncURLTemplate)
syncInfo, err := syncer.GetUsersyncInfo(privacy.Policies{})
syncInfo, err := syncer.GetUsersyncInfo(privacy.Policies{
GDPR: gdpr.Policy{
Signal: "A",
Consent: "B",
},
CCPA: ccpa.Policy{
Value: "C",
},
})

assert.NoError(t, err)
assert.Equal(t, "https://ic.tynt.com/r/d?m=xch&rt=html&ri=123&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz", syncInfo.URL)
assert.Equal(t, "https://ic.tynt.com/r/d?m=xch&rt=html&gdpr=A&gdpr_consent=B&us_privacy=C&ru=%2Fsetuid%3Fbidder%3D33across%26uid%3D33XUSERID33X&id=zzz000000000002zzz", syncInfo.URL)
assert.Equal(t, "iframe", syncInfo.Type)
assert.EqualValues(t, 58, syncer.GDPRVendorID())
assert.False(t, syncInfo.SupportCORS)
Expand Down
78 changes: 77 additions & 1 deletion adapters/adform/adform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (

"fmt"

"github.com/mxmCherry/openrtb"
"github.com/PubMatic-OpenWrap/prebid-server/adapters"
"github.com/PubMatic-OpenWrap/prebid-server/config"
"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext"
"github.com/mxmCherry/openrtb"

"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand Down Expand Up @@ -597,3 +599,77 @@ func TestPriceTypeUrlParameterCreation(t *testing.T) {
}
}
}

// Asserts that toOpenRtbBidResponse() creates a *adapters.BidderResponse with
// the currency of the last valid []*adformBid element and the expected number of bids
func TestToOpenRtbBidResponse(t *testing.T) {
expectedBids := 3
lastCurrency, anotherCurrency, emptyCurrency := "EUR", "USD", ""

request := &openrtb.BidRequest{
ID: "test-request-id",
Imp: []openrtb.Imp{
{
ID: "banner-imp-no1",
Ext: json.RawMessage(`{"bidder1": { "mid": "32341" }}`),
Banner: &openrtb.Banner{},
},
{
ID: "banner-imp-no2",
Ext: json.RawMessage(`{"bidder1": { "mid": "32342" }}`),
Banner: &openrtb.Banner{},
},
{
ID: "banner-imp-no3",
Ext: json.RawMessage(`{"bidder1": { "mid": "32343" }}`),
Banner: &openrtb.Banner{},
},
{
ID: "banner-imp-no4",
Ext: json.RawMessage(`{"bidder1": { "mid": "32344" }}`),
Banner: &openrtb.Banner{},
},
},
Device: &openrtb.Device{UA: "ua", IP: "ip"},
User: &openrtb.User{BuyerUID: "buyerUID"},
}

testAdformBids := []*adformBid{
{
ResponseType: "banner",
Banner: "banner-content1",
Price: 1.23,
Currency: anotherCurrency,
Width: 300,
Height: 200,
DealId: "dealId1",
CreativeId: "creativeId1",
},
{},
{
ResponseType: "banner",
Banner: "banner-content3",
Price: 1.24,
Currency: emptyCurrency,
Width: 300,
Height: 200,
DealId: "dealId3",
CreativeId: "creativeId3",
},
{
ResponseType: "banner",
Banner: "banner-content4",
Price: 1.25,
Currency: lastCurrency,
Width: 300,
Height: 200,
DealId: "dealId4",
CreativeId: "creativeId4",
},
}

actualBidResponse := toOpenRtbBidResponse(testAdformBids, request)

assert.Equalf(t, expectedBids, len(actualBidResponse.Bids), "bid count")
assert.Equalf(t, lastCurrency, actualBidResponse.Currency, "currency")
}
8 changes: 6 additions & 2 deletions adapters/adkernel/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"text/template"

"github.com/PubMatic-OpenWrap/prebid-server/privacy"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/ccpa"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/gdpr"
"github.com/stretchr/testify/assert"
)

func TestAdkernelAdnSyncer(t *testing.T) {
syncURL := "https://sync.adkernel.com/user-sync?t=image&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3Dadkernel%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7BUID%7D"
syncURL := "https://sync.adkernel.com/user-sync?t=image&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3Dadkernel%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7BUID%7D"
syncURLTemplate := template.Must(
template.New("sync-template").Parse(syncURL),
)
Expand All @@ -21,10 +22,13 @@ func TestAdkernelAdnSyncer(t *testing.T) {
Signal: "1",
Consent: "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw",
},
CCPA: ccpa.Policy{
Value: "1NYN",
},
})

assert.NoError(t, err)
assert.Equal(t, "https://sync.adkernel.com/user-sync?t=image&gdpr=1&gdpr_consent=BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3Dadkernel%26gdpr%3D1%26gdpr_consent%3DBONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw%26uid%3D%7BUID%7D", syncInfo.URL)
assert.Equal(t, "https://sync.adkernel.com/user-sync?t=image&gdpr=1&gdpr_consent=BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw&us_privacy=1NYN&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3Dadkernel%26gdpr%3D1%26gdpr_consent%3DBONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw%26uid%3D%7BUID%7D", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, adkernelGDPRVendorID, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
Expand Down
8 changes: 6 additions & 2 deletions adapters/adkernelAdn/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ import (
"text/template"

"github.com/PubMatic-OpenWrap/prebid-server/privacy"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/ccpa"
"github.com/PubMatic-OpenWrap/prebid-server/privacy/gdpr"
"github.com/stretchr/testify/assert"
)

func TestAdkernelAdnSyncer(t *testing.T) {
syncURL := "https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3DadkernelAdn%26uid%3D%7BUID%7D"
syncURL := "https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3DadkernelAdn%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7BUID%7D"
syncURLTemplate := template.Must(
template.New("sync-template").Parse(syncURL),
)
Expand All @@ -21,10 +22,13 @@ func TestAdkernelAdnSyncer(t *testing.T) {
Signal: "1",
Consent: "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw",
},
CCPA: ccpa.Policy{
Value: "1NYN",
},
})

assert.NoError(t, err)
assert.Equal(t, "https://tag.adkernel.com/syncr?gdpr=1&gdpr_consent=BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3DadkernelAdn%26uid%3D%7BUID%7D", syncInfo.URL)
assert.Equal(t, "https://tag.adkernel.com/syncr?gdpr=1&gdpr_consent=BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw&us_privacy=1NYN&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3DadkernelAdn%26gdpr%3D1%26gdpr_consent%3DBONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw%26uid%3D%7BUID%7D", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, adkernelGDPRVendorID, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"ext": {
"bidder": {
"placementId": 10433394
"placementId": 1
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
},
"ext": {
"bidder": {
"placementId": 10433394
"placementId": 1
}
}
}
Expand Down
160 changes: 160 additions & 0 deletions adapters/applogy/applogy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package applogy

import (
"encoding/json"
"errors"
"net/http"
"strconv"

"github.com/mxmCherry/openrtb"
"github.com/PubMatic-OpenWrap/prebid-server/adapters"
"github.com/PubMatic-OpenWrap/prebid-server/errortypes"
"github.com/PubMatic-OpenWrap/prebid-server/openrtb_ext"
)

type ApplogyAdapter struct {
endpoint string
}

func (a *ApplogyAdapter) MakeRequests(request *openrtb.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
impressions := request.Imp
result := make([]*adapters.RequestData, 0, len(impressions))
errs := make([]error, 0, len(impressions))

for i, impression := range impressions {
if impression.Banner == nil && impression.Video == nil && impression.Native == nil {
errs = append(errs, &errortypes.BadInput{
Message: "Applogy only supports banner, video or native ads",
})
continue
}
if impression.Banner != nil {
banner := impression.Banner
if banner.W == nil || banner.H == nil || *banner.W == 0 || *banner.H == 0 {
if len(banner.Format) == 0 {
errs = append(errs, &errortypes.BadInput{
Message: "banner size information missing",
})
continue
}
format := banner.Format[0]
banner.W = &format.W
banner.H = &format.H
}
}
if len(impression.Ext) == 0 {
errs = append(errs, errors.New("impression extensions required"))
continue
}
var bidderExt adapters.ExtImpBidder
err := json.Unmarshal(impression.Ext, &bidderExt)
if err != nil {
errs = append(errs, err)
continue
}
if len(bidderExt.Bidder) == 0 {
errs = append(errs, errors.New("bidder required"))
continue
}
var impressionExt openrtb_ext.ExtImpApplogy
err = json.Unmarshal(bidderExt.Bidder, &impressionExt)
if err != nil {
errs = append(errs, err)
continue
}
if impressionExt.Token == "" {
errs = append(errs, errors.New("Applogy token required"))
continue
}
request.Imp = impressions[i : i+1]
body, err := json.Marshal(request)
if err != nil {
errs = append(errs, err)
continue
}
result = append(result, &adapters.RequestData{
Method: "POST",
Uri: a.endpoint + "/" + impressionExt.Token,
Body: body,
Headers: headers,
})
}

request.Imp = impressions

if len(result) == 0 {
return nil, errs
}
return result, errs
}

func (a *ApplogyAdapter) MakeBids(request *openrtb.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) {
var errs []error

switch responseData.StatusCode {
case http.StatusNoContent:
return nil, nil
case http.StatusBadRequest:
return nil, []error{&errortypes.BadInput{
Message: "unexpected status code: " + strconv.Itoa(responseData.StatusCode),
}}
case http.StatusOK:
break
default:
return nil, []error{&errortypes.BadServerResponse{
Message: "unexpected status code: " + strconv.Itoa(responseData.StatusCode),
}}
}

var bidResponse openrtb.BidResponse
err := json.Unmarshal(responseData.Body, &bidResponse)
if err != nil {
return nil, []error{&errortypes.BadServerResponse{
Message: err.Error(),
}}
}

response := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp))

for _, seatBid := range bidResponse.SeatBid {
for _, bid := range seatBid.Bid {
bid := bid // pin https://github.com/kyoh86/scopelint#whats-this
var bidType openrtb_ext.BidType
for _, impression := range request.Imp {
if impression.ID != bid.ImpID {
continue
}
switch {
case impression.Banner != nil:
bidType = openrtb_ext.BidTypeBanner
case impression.Video != nil:
bidType = openrtb_ext.BidTypeVideo
case impression.Native != nil:
bidType = openrtb_ext.BidTypeNative
}
break
}
if bidType == "" {
errs = append(errs, &errortypes.BadServerResponse{
Message: "ignoring bid id=" + bid.ID + ", request doesn't contain any valid impression with id=" + bid.ImpID,
})
continue
}
response.Bids = append(response.Bids, &adapters.TypedBid{
Bid: &bid,
BidType: bidType,
})
}
}

return response, errs
}

func NewApplogyBidder(endpoint string) *ApplogyAdapter {
return &ApplogyAdapter{
endpoint: endpoint,
}
}
11 changes: 11 additions & 0 deletions adapters/applogy/applogy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package applogy

import (
"testing"

"github.com/PubMatic-OpenWrap/prebid-server/adapters/adapterstest"
)

func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "applogytest", NewApplogyBidder("http://example.com/prebid"))
}
Loading