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

Fix missing Request parameter for Adgeneration Adapter #1525

Merged
merged 2 commits into from
Oct 13, 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
12 changes: 9 additions & 3 deletions adapters/adgeneration/adgeneration.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (adg *AdgenerationAdapter) MakeRequests(request *openrtb.BidRequest, reqInf
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
if request.Device != nil && len(request.Device.UA) > 0 {
headers.Add("User-Agent", request.Device.UA)
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
}

bidRequestArray := make([]*adapters.RequestData, 0, numRequests)

Expand Down Expand Up @@ -106,11 +109,14 @@ func (adg *AdgenerationAdapter) getRawQuery(id string, request *openrtb.BidReque
v.Set("adapterver", adg.version)
adSize := getSizes(imp)
if adSize != "" {
v.Set("size", adSize)
v.Set("sizes", adSize)
}
if request.Site != nil && request.Site.Page != "" {
v.Set("tp", request.Site.Page)
}
if request.Source != nil && request.Source.TID != "" {
v.Set("transactionid", request.Source.TID)
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
}
return &v
}

Expand All @@ -135,7 +141,7 @@ func getSizes(imp *openrtb.Imp) string {
}
var sizeStr string
for _, v := range imp.Banner.Format {
sizeStr += strconv.FormatUint(v.W, 10) + "×" + strconv.FormatUint(v.H, 10) + ","
sizeStr += strconv.FormatUint(v.W, 10) + "x" + strconv.FormatUint(v.H, 10) + ","
}
if len(sizeStr) > 0 && strings.LastIndex(sizeStr, ",") == len(sizeStr)-1 {
sizeStr = sizeStr[:len(sizeStr)-1]
Expand Down Expand Up @@ -255,7 +261,7 @@ func removeWrapper(ad string) string {
func NewAdgenerationAdapter(endpoint string) *AdgenerationAdapter {
return &AdgenerationAdapter{
endpoint,
"1.0.1",
"1.0.2",
"JPY",
}
}
48 changes: 24 additions & 24 deletions adapters/adgeneration/adgeneration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestJsonSamples(t *testing.T) {
adapterstest.RunJSONBidderTest(t, "adgenerationtest", NewAdgenerationAdapter("https://d.socdm.com/adsv/v1"))
}

func TestgetRequestUri(t *testing.T) {
func TestGetRequestUri(t *testing.T) {
bidder := NewAdgenerationAdapter("https://d.socdm.com/adsv/v1")
// Test items
failedRequest := &openrtb.BidRequest{
Expand All @@ -24,6 +24,7 @@ func TestgetRequestUri(t *testing.T) {
{ID: "extImpBidder-failed-test", Banner: &openrtb.Banner{Format: []openrtb.Format{{W: 300, H: 250}}}, Ext: json.RawMessage(`{"_bidder": { "id": "58278" }}`)},
{ID: "extImpAdgeneration-failed-test", Banner: &openrtb.Banner{Format: []openrtb.Format{{W: 300, H: 250}}}, Ext: json.RawMessage(`{"bidder": { "_id": "58278" }}`)},
},
Source: &openrtb.Source{TID: "SourceTID"},
Device: &openrtb.Device{UA: "testUA", IP: "testIP"},
Site: &openrtb.Site{Page: "https://supership.com"},
User: &openrtb.User{BuyerUID: "buyerID"},
Expand All @@ -33,6 +34,7 @@ func TestgetRequestUri(t *testing.T) {
Imp: []openrtb.Imp{
{ID: "bidRequest-success-test", Banner: &openrtb.Banner{Format: []openrtb.Format{{W: 300, H: 250}}}, Ext: json.RawMessage(`{"bidder": { "id": "58278" }}`)},
},
Source: &openrtb.Source{TID: "SourceTID"},
Device: &openrtb.Device{UA: "testUA", IP: "testIP"},
Site: &openrtb.Site{Page: "https://supership.com"},
User: &openrtb.User{BuyerUID: "buyerID"},
Expand All @@ -50,42 +52,40 @@ func TestgetRequestUri(t *testing.T) {
}
numRequests = len(successRequest.Imp)
for index := 0; index < numRequests; index++ {
// RequestUri Test.
httpRequests, err := bidder.getRequestUri(successRequest, index)
if err != nil {
t.Errorf("getRequestUri: %v did throw an error: %v", successRequest.Imp[index], err)
}
if httpRequests == "adapterver="+bidder.version+"&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&size=300%C3%97250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html" {
t.Errorf("getRequestUri: %v did return Request: %s", successRequest.Imp[index], httpRequests)
}
// getRawQuery Test.
adgExt, err := unmarshalExtImpAdgeneration(&successRequest.Imp[index])
if err != nil {
t.Errorf("unmarshalExtImpAdgeneration: %v did throw an error: %v", successRequest.Imp[index], err)
}
rawQuery := bidder.getRawQuery(adgExt.Id, successRequest, &successRequest.Imp[index])
expectQueries := map[string]string{
"posall": "SSPLOC",
"id": adgExt.Id,
"sdktype": "0",
"hb": "true",
"currency": bidder.getCurrency(successRequest),
"sdkname": "prebidserver",
"adapterver": bidder.version,
"size": getSizes(&successRequest.Imp[index]),
"tp": successRequest.Site.Name,
"posall": "SSPLOC",
"id": adgExt.Id,
"sdktype": "0",
"hb": "true",
"currency": bidder.getCurrency(successRequest),
"sdkname": "prebidserver",
"adapterver": bidder.version,
"sizes": getSizes(&successRequest.Imp[index]),
"tp": successRequest.Site.Page,
"transactionid": successRequest.Source.TID,
}
for key, expectedValue := range expectQueries {
actualValue := rawQuery.Get(key)
if actualValue == "" {
if !(key == "size" || key == "tp") {
t.Errorf("getRawQuery: key %s is required value.", key)
}
}
if actualValue != expectedValue {
t.Errorf("getRawQuery: %s value does not match expected %s, actual %s", key, expectedValue, actualValue)
}
}

// RequestUri Test.
actualUri, err := bidder.getRequestUri(successRequest, index)
if err != nil {
t.Errorf("getRequestUri: %v did throw an error: %v", successRequest.Imp[index], err)
}
expectedUri := "https://d.socdm.com/adsv/v1?adapterver=" + bidder.version + "&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=https%3A%2F%2Fsupership.com&transactionid=SourceTID"
if actualUri != expectedUri {
t.Errorf("getRequestUri: does not match expected %s, actual %s", expectedUri, actualUri)
}
}
}

Expand All @@ -99,7 +99,7 @@ func TestGetSizes(t *testing.T) {

request = &openrtb.Imp{Banner: multiFormatBanner}
size = getSizes(request)
if size != "300×250,320×50" {
if size != "300x250,320x50" {
t.Errorf("%v does not match size.", multiFormatBanner)
}
request = &openrtb.Imp{Banner: noFormatBanner}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"site": {
"page": "http://example.com/test.html"
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
},
"imp": [
{
"id": "some-impression-id",
Expand Down Expand Up @@ -52,13 +55,16 @@
"tmax": 500
},
"expectedRequest":{
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.1&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&size=300%C3%97250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.2&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"site": {
"page": "http://example.com/test.html"
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
},
"imp": [
{
"id": "some-impression-id",
Expand Down Expand Up @@ -52,13 +55,16 @@
"tmax": 500
},
"expectedRequest":{
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.1&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&size=300%C3%97250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.2&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"site": {
"page": "http://example.com/test.html"
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
},
"imp": [
{
"id": "some-impression-id",
Expand Down Expand Up @@ -52,13 +55,16 @@
"tmax": 500
},
"expectedRequest":{
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.1&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&size=300%C3%97250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.2&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
]
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
"site": {
"page": "http://example.com/test.html"
},
"device": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
},
"imp": [
{
"id": "some-impression-id",
Expand Down Expand Up @@ -52,13 +55,16 @@
"tmax": 500
},
"expectedRequest":{
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.1&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&size=300%C3%97250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"uri": "https://d.socdm.com/adsv/v1?adapterver=1.0.2&currency=JPY&hb=true&id=58278&posall=SSPLOC&sdkname=prebidserver&sdktype=0&sizes=300x250&t=json3&tp=http%3A%2F%2Fexample.com%2Ftest.html",
"headers": {
"Accept": [
"application/json"
],
"Content-Type": [
"application/json;charset=utf-8"
],
"User-Agent": [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36"
]
}
},
Expand Down