forked from prebid/prebid-server
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Andreas Schubert <[email protected]> Co-authored-by: schubert-sc <[email protected]>
- Loading branch information
1 parent
8cdfe48
commit 23bc394
Showing
13 changed files
with
649 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package smartx | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
var validParams = []string{ | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986", "siteId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986", "appId":"22860"}`, | ||
} | ||
|
||
func TestValidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, validParam := range validParams { | ||
if err := validator.Validate(openrtb_ext.BidderSmartx, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected smartx params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
var invalidParams = []string{ | ||
``, | ||
`null`, | ||
`true`, | ||
`5`, | ||
`[]`, | ||
`{}`, | ||
`{"anyparam": "anyvalue"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A"}`, | ||
`{"publisherId":"11986"}`, | ||
`{"siteId":"22860"}`, | ||
`{"appId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "publisherId":"11986"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "siteId":"22860"}`, | ||
`{"tagId":"Nu68JuOWAvrbzoyrOR9a7A", "appId":"22860"}`, | ||
`{"publisherId":"11986", "appId":"22860"}`, | ||
`{"publisherId":"11986", "appId":"22860"}`, | ||
} | ||
|
||
func TestInvalidParams(t *testing.T) { | ||
validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") | ||
if err != nil { | ||
t.Fatalf("Failed to fetch the json-schemas. %v", err) | ||
} | ||
|
||
for _, invalidParam := range invalidParams { | ||
if err := validator.Validate(openrtb_ext.BidderSmartHub, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package smartx | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/http" | ||
|
||
"github.com/prebid/openrtb/v19/openrtb2" | ||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
type adapter struct { | ||
endpointURL string | ||
} | ||
|
||
func Builder(_ openrtb_ext.BidderName, config config.Adapter, _ config.Server) (adapters.Bidder, error) { | ||
return &adapter{ | ||
endpointURL: config.Endpoint, | ||
}, nil | ||
} | ||
|
||
func (a *adapter) MakeRequests(openRTBRequest *openrtb2.BidRequest, requestInfo *adapters.ExtraRequestInfo) (requestsToBidder []*adapters.RequestData, errs []error) { | ||
openRTBRequestJSON, err := json.Marshal(openRTBRequest) | ||
if err != nil { | ||
errs = append(errs, fmt.Errorf("marshal bidRequest: %w", err)) | ||
return nil, errs | ||
} | ||
|
||
headers := http.Header{} | ||
headers.Add("Content-Type", "application/json;charset=utf-8") | ||
headers.Add("x-openrtb-version", "2.5") | ||
|
||
if openRTBRequest.Device != nil { | ||
if openRTBRequest.Device.UA != "" { | ||
headers.Set("User-Agent", openRTBRequest.Device.UA) | ||
} | ||
|
||
if openRTBRequest.Device.IP != "" { | ||
headers.Set("Forwarded", "for="+openRTBRequest.Device.IP) | ||
headers.Set("X-Forwarded-For", openRTBRequest.Device.IP) | ||
} | ||
} | ||
|
||
return append(requestsToBidder, &adapters.RequestData{ | ||
Method: http.MethodPost, | ||
Uri: a.endpointURL, | ||
Body: openRTBRequestJSON, | ||
Headers: headers, | ||
}), nil | ||
} | ||
|
||
func (a *adapter) MakeBids(request *openrtb2.BidRequest, _ *adapters.RequestData, responseData *adapters.ResponseData) (*adapters.BidderResponse, []error) { | ||
if adapters.IsResponseStatusCodeNoContent(responseData) { | ||
return nil, nil | ||
} | ||
|
||
if err := adapters.CheckResponseStatusCodeForErrors(responseData); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
var response openrtb2.BidResponse | ||
if err := json.Unmarshal(responseData.Body, &response); err != nil { | ||
return nil, []error{err} | ||
} | ||
|
||
if len(response.SeatBid) == 0 { | ||
return nil, []error{errors.New("no bidders found in JSON response")} | ||
} | ||
|
||
bidResponse := adapters.NewBidderResponseWithBidsCapacity(len(request.Imp)) | ||
if response.Cur != "" { | ||
bidResponse.Currency = response.Cur | ||
} | ||
|
||
var errs []error | ||
|
||
for _, seatBid := range response.SeatBid { | ||
for i := range seatBid.Bid { | ||
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ | ||
Bid: &seatBid.Bid[i], | ||
BidType: openrtb_ext.BidTypeVideo, | ||
}) | ||
} | ||
} | ||
|
||
return bidResponse, errs | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package smartx | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/adapters/adapterstest" | ||
"github.com/prebid/prebid-server/config" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
const testsDir = "smartxtest" | ||
const testsBidderEndpoint = "https://bid.smartclip.net/bid/1005" | ||
|
||
func TestJsonSamples(t *testing.T) { | ||
bidder, buildErr := Builder( | ||
openrtb_ext.BidderRise, | ||
config.Adapter{Endpoint: testsBidderEndpoint}, | ||
config.Server{ExternalUrl: "http://hosturl.com", GvlID: 115, DataCenter: "2"}) | ||
if buildErr != nil { | ||
t.Fatalf("Builder returned unexpected error %v", buildErr) | ||
} | ||
|
||
adapterstest.RunJSONBidderTest(t, testsDir, bidder) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
{ | ||
"mockBidRequest":{ | ||
"id":"test-request-id-video", | ||
"imp":[ | ||
{ | ||
"id":"test-imp-id", | ||
"video":{ | ||
"mimes":[ | ||
"video/mp4" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"httpCalls":[ | ||
{ | ||
"expectedRequest":{ | ||
"uri":"https://bid.smartclip.net/bid/1005", | ||
"body":{ | ||
"id":"test-request-id-video", | ||
"imp":[ | ||
{ | ||
"id":"test-imp-id", | ||
"video":{ | ||
"mimes":[ | ||
"video/mp4" | ||
] | ||
} | ||
} | ||
] | ||
} | ||
}, | ||
"mockResponse":{ | ||
"status":200, | ||
"body":{ | ||
"id":"test-request-id-video", | ||
"seatbid":[ | ||
{ | ||
"seat":"smartadserver", | ||
"bid":[ | ||
{ | ||
"id":"8ee514f1-b2b8-4abb-89fd-084437d1e800", | ||
"impid":"test-imp-id-video", | ||
"price":0.500000, | ||
"adm":"some-test-ad", | ||
"crid":"crid_10", | ||
"h":576, | ||
"w":1024, | ||
"mtype":2 | ||
} | ||
] | ||
} | ||
], | ||
"cur":"EUR" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses":[ | ||
{ | ||
"bids":[{ | ||
"bid":{ | ||
"id":"8ee514f1-b2b8-4abb-89fd-084437d1e800", | ||
"impid":"test-imp-id-video", | ||
"price":0.500000, | ||
"adm":"some-test-ad", | ||
"crid":"crid_10", | ||
"h":576, | ||
"w":1024, | ||
"mtype":2 | ||
}, | ||
"currency":"EUR", | ||
"type": "video" | ||
}] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
{ | ||
"mockBidRequest": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"prebid": { | ||
"bidder": { | ||
"smartx": { | ||
"publisherId": "11986", | ||
"tagId": "Nu68JuOWAvrbzoyrOR9a7A", | ||
"siteId": "22860" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"user": { | ||
"ext": { | ||
"consent": "COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw" | ||
} | ||
} | ||
}, | ||
"httpCalls": [ | ||
{ | ||
"expectedRequest": { | ||
"uri": "https://bid.smartclip.net/bid/1005", | ||
"body": { | ||
"id": "test-request-id", | ||
"imp": [ | ||
{ | ||
"id": "test-imp-id", | ||
"banner": { | ||
"w": 300, | ||
"h": 250 | ||
}, | ||
"ext": { | ||
"prebid": { | ||
"bidder": { | ||
"smartx": { | ||
"publisherId": "11986", | ||
"tagId": "Nu68JuOWAvrbzoyrOR9a7A", | ||
"siteId": "22860" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
], | ||
"user": { | ||
"ext": { | ||
"consent": "COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw" | ||
} | ||
} | ||
} | ||
}, | ||
"mockResponse": { | ||
"status": 200, | ||
"body": { | ||
"id": "test-request-id", | ||
"seatbid": [ | ||
{ | ||
"seat": "958", | ||
"bid": [ | ||
{ | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adid": "29681110", | ||
"adm": "some-test-ad", | ||
"adomain": [ | ||
"https://advertiser.example.com" | ||
], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"h": 250, | ||
"w": 300, | ||
"ext": { | ||
"ix": {} | ||
} | ||
} | ||
] | ||
} | ||
], | ||
"bidid": "5778926625248726496", | ||
"cur": "USD" | ||
} | ||
} | ||
} | ||
], | ||
"expectedBidResponses": [ | ||
{ | ||
"currency": "USD", | ||
"bids": [ | ||
{ | ||
"bid": { | ||
"id": "7706636740145184841", | ||
"impid": "test-imp-id", | ||
"price": 0.5, | ||
"adm": "some-test-ad", | ||
"adid": "29681110", | ||
"adomain": [ | ||
"https://advertiser.example.com" | ||
], | ||
"cid": "958", | ||
"crid": "29681110", | ||
"w": 300, | ||
"h": 250, | ||
"ext": { | ||
"ix": {} | ||
} | ||
}, | ||
"type": "video" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.