-
Notifications
You must be signed in to change notification settings - Fork 742
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: Mirko Feddern <[email protected]> Signed-off-by: Alex Klinkert <[email protected]> Co-authored-by: Alexander Pinnecke <[email protected]> Co-authored-by: Alex Klinkert <[email protected]> Co-authored-by: Mirko Feddern <[email protected]>
- Loading branch information
1 parent
748e2d0
commit d00ff3f
Showing
22 changed files
with
1,147 additions
and
68 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
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,7 @@ | ||
package yieldlab | ||
|
||
const adSlotIdSeparator = "," | ||
const adsizeSeparator = "x" | ||
const adSourceBanner = "<script src=\"%v\"></script>" | ||
const adSourceURL = "https://ad.yieldlab.net/d/%v/%v/%v?%v" | ||
const creativeID = "%v%v%v" |
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,63 @@ | ||
package yieldlab | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/prebid/prebid-server/openrtb_ext" | ||
) | ||
|
||
// This file actually intends to test static/bidder-params/yieldlab.json | ||
// | ||
// These also validate the format of the external API: request.imp[i].ext.yieldlab | ||
|
||
// TestValidParams makes sure that the yieldlab schema accepts all imp.ext fields which we intend to support. | ||
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.BidderYieldlab, json.RawMessage(validParam)); err != nil { | ||
t.Errorf("Schema rejected yieldlab params: %s", validParam) | ||
} | ||
} | ||
} | ||
|
||
// TestInvalidParams makes sure that the yieldlab schema rejects all the imp.ext fields we don't support. | ||
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.BidderYieldlab, json.RawMessage(invalidParam)); err == nil { | ||
t.Errorf("Schema allowed unexpected params: %s", invalidParam) | ||
} | ||
} | ||
} | ||
|
||
var validParams = []string{ | ||
`{"adslotId": "123","supplyId":"23456","adSize":"100x100"}`, | ||
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","extId":"asdf"}`, | ||
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","extId":"asdf","targeting":{"a":"b"}}`, | ||
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","targeting":{"a":"b"}}`, | ||
`{"adslotId": "123","supplyId":"23456","adSize":"100x100","targeting":{"a":"b"}}`, | ||
} | ||
|
||
var invalidParams = []string{ | ||
`{"supplyId":"23456","adSize":"100x100"}`, | ||
`{"adslotId": "123","adSize":"100x100","extId":"asdf"}`, | ||
`{"adslotId": "123","supplyId":"23456","extId":"asdf","targeting":{"a":"b"}}`, | ||
`{"adslotId": "123","supplyId":"23456"}`, | ||
`{"adSize":"100x100","supplyId":"23456"}`, | ||
`{"adslotId": "123","adSize":"100x100"}`, | ||
`{"supplyId":"23456"}`, | ||
`{"adslotId": "123"}`, | ||
`{}`, | ||
`[]`, | ||
`{"a":"b"}`, | ||
`null`, | ||
} |
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,29 @@ | ||
package yieldlab | ||
|
||
import ( | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type bidResponse struct { | ||
ID uint64 `json:"id"` | ||
Price uint `json:"price"` | ||
Advertiser string `json:"advertiser"` | ||
Adsize string `json:"adsize"` | ||
Pid uint64 `json:"pid"` | ||
Did uint64 `json:"did"` | ||
Pvid string `json:"pvid"` | ||
} | ||
|
||
type cacheBuster func() string | ||
|
||
type weekGenerator func() string | ||
|
||
var defaultCacheBuster cacheBuster = func() string { | ||
return strconv.FormatInt(time.Now().Unix(), 10) | ||
} | ||
|
||
var defaultWeekGenerator weekGenerator = func() string { | ||
_, week := time.Now().ISOWeek() | ||
return strconv.Itoa(week) | ||
} |
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,12 @@ | ||
package yieldlab | ||
|
||
import ( | ||
"text/template" | ||
|
||
"github.com/prebid/prebid-server/adapters" | ||
"github.com/prebid/prebid-server/usersync" | ||
) | ||
|
||
func NewYieldlabSyncer(temp *template.Template) usersync.Usersyncer { | ||
return adapters.NewSyncer("yieldlab", 70, temp, adapters.SyncTypeRedirect) | ||
} |
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,26 @@ | ||
package yieldlab | ||
|
||
import ( | ||
"testing" | ||
"text/template" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/prebid/prebid-server/privacy" | ||
"github.com/prebid/prebid-server/privacy/gdpr" | ||
) | ||
|
||
func TestYieldlabSyncer(t *testing.T) { | ||
temp := template.Must(template.New("sync-template").Parse("https://ad.yieldlab.net/mr?t=2&pid=9140838&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&redirectUri=http%3A%2F%2Flocalhost%2F%2Fsetuid%3Fbidder%3Dyieldlab%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%25%25YL_UID%25%25")) | ||
syncer := NewYieldlabSyncer(temp) | ||
syncInfo, err := syncer.GetUsersyncInfo(privacy.Policies{ | ||
GDPR: gdpr.Policy{ | ||
Signal: "0", | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.Equal(t, "https://ad.yieldlab.net/mr?t=2&pid=9140838&gdpr=0&gdpr_consent=&redirectUri=http%3A%2F%2Flocalhost%2F%2Fsetuid%3Fbidder%3Dyieldlab%26gdpr%3D0%26gdpr_consent%3D%26uid%3D%25%25YL_UID%25%25", syncInfo.URL) | ||
assert.Equal(t, "redirect", syncInfo.Type) | ||
assert.EqualValues(t, 70, syncer.GDPRVendorID()) | ||
assert.False(t, syncInfo.SupportCORS) | ||
} |
Oops, something went wrong.