Skip to content

Commit 6a1751e

Browse files
author
w00522253
committed
* 'master' of https://github.com/wwwyyy/prebid-server: Axonix: enabled by default (prebid#1936) IX: update required site id field to be more flexible (prebid#1934) New adapter: Adagio (prebid#1907) Smaato: Split multiple media types (prebid#1930) Fix CVE-2020-35381 (prebid#1942) Tappx: new bidder params (prebid#1931) InMobi: adding native support (prebid#1928) Admixer: Fix for bid floor issue#1787 (prebid#1872)
2 parents 2ea353e + ff14df4 commit 6a1751e

File tree

92 files changed

+2986
-112
lines changed

Some content is hidden

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

92 files changed

+2986
-112
lines changed

adapters/adagio/adagio.go

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package adagio
2+
3+
import (
4+
"bytes"
5+
"compress/gzip"
6+
"encoding/json"
7+
"fmt"
8+
"github.com/mxmCherry/openrtb/v15/openrtb2"
9+
"github.com/prebid/prebid-server/adapters"
10+
"github.com/prebid/prebid-server/config"
11+
"github.com/prebid/prebid-server/errortypes"
12+
"github.com/prebid/prebid-server/openrtb_ext"
13+
"net/http"
14+
)
15+
16+
// Builder builds a new instance of the Adagio adapter for the given bidder with the given config.
17+
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters.Bidder, error) {
18+
bidder := &adapter{
19+
endpoint: config.Endpoint,
20+
}
21+
return bidder, nil
22+
}
23+
24+
type adapter struct {
25+
endpoint string
26+
}
27+
28+
type extBid struct {
29+
Prebid *openrtb_ext.ExtBidPrebid
30+
}
31+
32+
// MakeRequests prepares the HTTP requests which should be made to fetch bids.
33+
func (a *adapter) MakeRequests(request *openrtb2.BidRequest, _ *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
34+
json, err := json.Marshal(request)
35+
if err != nil {
36+
return nil, []error{err}
37+
}
38+
39+
headers := http.Header{}
40+
headers.Add("Content-Type", "application/json;charset=utf-8")
41+
headers.Add("Accept", "application/json")
42+
43+
if request.Device != nil {
44+
if len(request.Device.IPv6) > 0 {
45+
headers.Add("X-Forwarded-For", request.Device.IPv6)
46+
}
47+
if len(request.Device.IP) > 0 {
48+
headers.Add("X-Forwarded-For", request.Device.IP)
49+
}
50+
}
51+
52+
if request.Test == 0 {
53+
// Gzip the body
54+
// Note: Gzipping could be handled natively later: https://github.com/prebid/prebid-server/issues/1812
55+
var bodyBuf bytes.Buffer
56+
gz := gzip.NewWriter(&bodyBuf)
57+
if _, err = gz.Write(json); err == nil {
58+
if err = gz.Close(); err == nil {
59+
json = bodyBuf.Bytes()
60+
headers.Add("Content-Encoding", "gzip")
61+
// /!\ Go already sets the `Accept-Encoding: gzip` header. Never add it manually, or Go won't decompress the response.
62+
//headers.Add("Accept-Encoding", "gzip")
63+
}
64+
}
65+
}
66+
67+
requestToBidder := &adapters.RequestData{
68+
Method: "POST",
69+
Uri: a.endpoint,
70+
Body: json,
71+
Headers: headers,
72+
}
73+
74+
return []*adapters.RequestData{requestToBidder}, nil
75+
}
76+
77+
const unexpectedStatusCodeFormat = "Unexpected status code: %d. Run with request.debug = 1 for more info"
78+
79+
// MakeBids unpacks the server's response into Bids.
80+
func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, _ *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) {
81+
switch response.StatusCode {
82+
case http.StatusOK:
83+
break
84+
case http.StatusNoContent:
85+
return nil, nil
86+
case http.StatusServiceUnavailable:
87+
fallthrough
88+
case http.StatusBadRequest:
89+
fallthrough
90+
case http.StatusUnauthorized:
91+
fallthrough
92+
case http.StatusForbidden:
93+
err := &errortypes.BadInput{
94+
Message: fmt.Sprintf(unexpectedStatusCodeFormat, response.StatusCode),
95+
}
96+
return nil, []error{err}
97+
default:
98+
err := &errortypes.BadServerResponse{
99+
Message: fmt.Sprintf(unexpectedStatusCodeFormat, response.StatusCode),
100+
}
101+
return nil, []error{err}
102+
}
103+
104+
var openRTBBidderResponse openrtb2.BidResponse
105+
if err := json.Unmarshal(response.Body, &openRTBBidderResponse); err != nil {
106+
return nil, []error{err}
107+
}
108+
109+
bidsCapacity := len(internalRequest.Imp)
110+
errs := make([]error, 0, bidsCapacity)
111+
bidderResponse := adapters.NewBidderResponseWithBidsCapacity(bidsCapacity)
112+
var typedBid *adapters.TypedBid
113+
for _, seatBid := range openRTBBidderResponse.SeatBid {
114+
for _, bid := range seatBid.Bid {
115+
activeBid := bid
116+
117+
activeExt := &extBid{}
118+
if err := json.Unmarshal(activeBid.Ext, activeExt); err != nil {
119+
errs = append(errs, err)
120+
}
121+
122+
var bidType openrtb_ext.BidType
123+
if activeExt.Prebid != nil && activeExt.Prebid.Type != "" {
124+
bidType = activeExt.Prebid.Type
125+
} else {
126+
err := &errortypes.BadServerResponse{
127+
Message: fmt.Sprintf("Failed to find native/banner/video mediaType \"%s\" ", activeBid.ImpID),
128+
}
129+
errs = append(errs, err)
130+
continue
131+
}
132+
133+
typedBid = &adapters.TypedBid{Bid: &activeBid, BidType: bidType}
134+
bidderResponse.Bids = append(bidderResponse.Bids, typedBid)
135+
}
136+
}
137+
138+
return bidderResponse, nil
139+
}

adapters/adagio/adagio_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package adagio
2+
3+
import (
4+
"encoding/json"
5+
"github.com/mxmCherry/openrtb/v15/openrtb2"
6+
"github.com/stretchr/testify/assert"
7+
"testing"
8+
9+
"github.com/prebid/prebid-server/adapters/adapterstest"
10+
"github.com/prebid/prebid-server/config"
11+
"github.com/prebid/prebid-server/openrtb_ext"
12+
)
13+
14+
func buildFakeBidRequest() openrtb2.BidRequest {
15+
imp1 := openrtb2.Imp{
16+
ID: "some-impression-id",
17+
Banner: &openrtb2.Banner{},
18+
Ext: json.RawMessage(`{"bidder": {"organizationId": "1000", "site": "site-name", "placement": "ban_atf"}}`),
19+
}
20+
21+
fakeBidRequest := openrtb2.BidRequest{
22+
ID: "some-request-id",
23+
Imp: []openrtb2.Imp{imp1},
24+
}
25+
26+
return fakeBidRequest
27+
}
28+
29+
func TestJsonSamples(t *testing.T) {
30+
bidder, buildErr := Builder(openrtb_ext.BidderAdagio, config.Adapter{
31+
Endpoint: "http://localhost/prebid_server"})
32+
33+
if buildErr != nil {
34+
t.Fatalf("Builder returned unexpected error %v", buildErr)
35+
}
36+
37+
adapterstest.RunJSONBidderTest(t, "adagiotest", bidder)
38+
}
39+
40+
func TestMakeRequests_NoGzip(t *testing.T) {
41+
fakeBidRequest := buildFakeBidRequest()
42+
fakeBidRequest.Test = 1 // Do not use Gzip in Test Mode.
43+
44+
bidder, buildErr := Builder(openrtb_ext.BidderAdagio, config.Adapter{
45+
Endpoint: "http://localhost/prebid_server"})
46+
47+
if buildErr != nil {
48+
t.Fatalf("Builder returned unexpected error %v", buildErr)
49+
}
50+
51+
requestData, errs := bidder.MakeRequests(&fakeBidRequest, nil)
52+
53+
assert.Nil(t, errs)
54+
assert.Equal(t, 1, len(requestData))
55+
56+
body := &openrtb2.BidRequest{}
57+
err := json.Unmarshal(requestData[0].Body, body)
58+
assert.NoError(t, err, "Request body unmarshalling error should be nil")
59+
assert.Equal(t, 1, len(body.Imp))
60+
}
61+
62+
func TestMakeRequests_Gzip(t *testing.T) {
63+
fakeBidRequest := buildFakeBidRequest()
64+
65+
bidder, buildErr := Builder(openrtb_ext.BidderAdagio, config.Adapter{
66+
Endpoint: "http://localhost/prebid_server"})
67+
68+
if buildErr != nil {
69+
t.Fatalf("Builder returned unexpected error %v", buildErr)
70+
}
71+
72+
requestData, errs := bidder.MakeRequests(&fakeBidRequest, nil)
73+
assert.Empty(t, errs, "Got errors while making requests")
74+
assert.Equal(t, []string{"gzip"}, requestData[0].Headers["Content-Encoding"])
75+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
{
2+
"mockBidRequest": {
3+
"test": 1,
4+
"id": "some-request-id",
5+
"device": {
6+
"ua": "test-user-agent",
7+
"ip": "123.123.123.123",
8+
"language": "en",
9+
"dnt": 0
10+
},
11+
"tmax": 1000,
12+
"user": {
13+
"buyeruid": "awesome-user"
14+
},
15+
"site": {
16+
"page": "test.com",
17+
"publisher": {
18+
"id": "123456789"
19+
}
20+
},
21+
"imp": [
22+
{
23+
"id": "some-impression-id",
24+
"banner": {
25+
"w":320,
26+
"h":50
27+
},
28+
"ext": {
29+
"bidder": {
30+
"organizationId": "1000",
31+
"site": "site-name",
32+
"placement": "ban_atf"
33+
}
34+
}
35+
}
36+
]
37+
},
38+
"httpCalls": [
39+
{
40+
"expectedRequest": {
41+
"headers": {
42+
"Content-Type": [
43+
"application/json;charset=utf-8"
44+
],
45+
"Accept": [
46+
"application/json"
47+
],
48+
"X-Forwarded-For": [
49+
"123.123.123.123"
50+
]
51+
},
52+
"uri": "http://localhost/prebid_server",
53+
"body": {
54+
"test": 1,
55+
"id": "some-request-id",
56+
"device": {
57+
"ua": "test-user-agent",
58+
"ip": "123.123.123.123",
59+
"language": "en",
60+
"dnt": 0
61+
},
62+
"imp": [
63+
{
64+
"id": "some-impression-id",
65+
"banner": {
66+
"w":320,
67+
"h":50
68+
},
69+
"ext": {
70+
"bidder": {
71+
"organizationId": "1000",
72+
"site": "site-name",
73+
"placement": "ban_atf"
74+
}
75+
}
76+
}
77+
],
78+
"site": {
79+
"page": "test.com",
80+
"publisher": {
81+
"id": "123456789"
82+
}
83+
},
84+
"user": {
85+
"buyeruid": "awesome-user"
86+
},
87+
"tmax": 1000
88+
}
89+
},
90+
"mockResponse": {
91+
"status": 200,
92+
"body": {
93+
"id": "awesome-resp-id",
94+
"seatbid": [
95+
{
96+
"bid": [
97+
{
98+
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
99+
"impid": "some-impression-id",
100+
"price": 3.5,
101+
"adm": "awesome-markup",
102+
"adomain": [
103+
"awesome.com"
104+
],
105+
"crid": "20",
106+
"w": 320,
107+
"h": 50,
108+
"ext": {
109+
"prebid": {
110+
"type": "banner"
111+
}
112+
}
113+
}
114+
],
115+
"seat": "adagio"
116+
}
117+
],
118+
"cur": "USD",
119+
"ext": {
120+
"responsetimemillis": {
121+
"adagio": 154
122+
},
123+
"tmaxrequest": 1000
124+
}
125+
}
126+
}
127+
}
128+
],
129+
"expectedBidResponses": [
130+
{
131+
"bids":[
132+
{
133+
"bid": {
134+
"id": "a3ae1b4e2fc24a4fb45540082e98e161",
135+
"impid": "some-impression-id",
136+
"price": 3.5,
137+
"adm": "awesome-markup",
138+
"crid": "20",
139+
"adomain": [
140+
"awesome.com"
141+
],
142+
"w": 320,
143+
"h": 50,
144+
"ext": {
145+
"prebid": {
146+
"type": "banner"
147+
}
148+
}
149+
},
150+
"type": "banner"
151+
}
152+
]
153+
}
154+
]
155+
}

0 commit comments

Comments
 (0)