Skip to content
This repository has been archived by the owner on Dec 22, 2022. It is now read-only.

Commit

Permalink
Configurable sync URLs (prebid#763)
Browse files Browse the repository at this point in the history
* Added a config property for base usersync url. Updated the syncers to use it.

* Added tests for the new config.

* Made sync URLs fully configurable.

* Updated the gumgum syncer, and fixed some broken tests.

* Handled the errors.

* Cleaned up a test.

* Polished the grid syncer test a bit.

* Fixed a bug related to bidder ID string cases.
  • Loading branch information
dbemiller authored Jan 7, 2019
1 parent b84d354 commit 4eb9e7b
Show file tree
Hide file tree
Showing 53 changed files with 433 additions and 538 deletions.
18 changes: 3 additions & 15 deletions adapters/33across/usersync.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
package ttx

import (
"net/url"
"strings"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"
)

func New33AcrossSyncer(cfg *config.Configuration) usersync.Usersyncer {
externalURL := strings.TrimRight(cfg.ExternalURL, "/")
adapterConfig := cfg.Adapters[string(openrtb_ext.Bidder33Across)]
redirectURL := url.QueryEscape(externalURL) + "%2Fsetuid%3Fbidder%3Dttx%26uid%3D33XUSERID33X"
syncerURL := adapterConfig.UserSyncURL + "/?ri=" + adapterConfig.PartnerId + "&ru=" + redirectURL

if adapterConfig.PartnerId == "" {
syncerURL = "/"
}

return adapters.NewSyncer("ttx", 58, adapters.ResolveMacros(syncerURL), adapters.SyncTypeRedirect)
func New33AcrossSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("ttx", 58, temp, adapters.SyncTypeRedirect)
}
18 changes: 6 additions & 12 deletions adapters/33across/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,18 @@ package ttx

import (
"testing"

"github.com/prebid/prebid-server/config"
"text/template"

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

func Test33AcrossSyncer(t *testing.T) {
ttx := New33AcrossSyncer(&config.Configuration{
ExternalURL: "localhost",
Adapters: map[string]config.Adapter{
"33across": {
UserSyncURL: "https://ssc-cms.33across.com/ps",
PartnerId: "123",
},
},
})
syncInfo := ttx.GetUsersyncInfo("", "")
temp := template.Must(template.New("sync-template").Parse("https://ssc-cms.33across.com/ps/?ri=123&ru=localhost%2Fsetuid%3Fbidder%3Dttx%26uid%3D33XUSERID33X"))
syncer := New33AcrossSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("", "")
assert.NoError(t, err)
assert.Equal(t, "https://ssc-cms.33across.com/ps/?ri=123&ru=localhost%2Fsetuid%3Fbidder%3Dttx%26uid%3D33XUSERID33X", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 58, syncer.GDPRVendorID())
assert.False(t, syncInfo.SupportCORS)
}
10 changes: 3 additions & 7 deletions adapters/adform/usersync.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package adform

import (
"net/url"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"
)

func NewAdformSyncer(cfg *config.Configuration) usersync.Usersyncer {
usersyncURL := cfg.Adapters[string(openrtb_ext.BidderAdform)].UserSyncURL
redirectURI := url.QueryEscape(cfg.ExternalURL) + "%2Fsetuid%3Fbidder%3Dadform%26gdpr%3D{{gdpr}}%26gdpr_consent%3D{{gdpr_consent}}%26uid%3D%24UID"
return adapters.NewSyncer("adform", 50, adapters.ResolveMacros(usersyncURL+redirectURI), adapters.SyncTypeRedirect)
func NewAdformSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("adform", 50, temp, adapters.SyncTypeRedirect)
}
22 changes: 9 additions & 13 deletions adapters/adform/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ package adform

import (
"testing"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"text/template"

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

func TestAdformSyncer(t *testing.T) {
syncer := NewAdformSyncer(&config.Configuration{ExternalURL: "localhost", Adapters: map[string]config.Adapter{
string(openrtb_ext.BidderAdform): {
UserSyncURL: "//cm.adform.net?return_url=",
},
}})
u := syncer.GetUsersyncInfo("1", "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw")
assert.Equal(t, "//cm.adform.net?return_url=localhost%2Fsetuid%3Fbidder%3Dadform%26gdpr%3D1%26gdpr_consent%3DBONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw%26uid%3D%24UID", u.URL)
assert.Equal(t, "redirect", u.Type)
assert.Equal(t, uint16(50), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("//cm.adform.net?return_url=localhost%2Fsetuid%3Fbidder%3Dadform%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID"))
syncer := NewAdformSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("1", "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw")
assert.NoError(t, err)
assert.Equal(t, "//cm.adform.net?return_url=localhost%2Fsetuid%3Fbidder%3Dadform%26gdpr%3D1%26gdpr_consent%3DBONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw%26uid%3D%24UID", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 50, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
12 changes: 3 additions & 9 deletions adapters/adkernelAdn/usersync.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
package adkernelAdn

import (
"net/url"
"strings"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"
)

const adkernelGDPRVendorID = uint16(14)

func NewAdkernelAdnSyncer(cfg *config.Configuration) usersync.Usersyncer {
// Fixes #736
usersyncURL := cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAdkernelAdn))].UserSyncURL
externalURL := strings.TrimRight(cfg.ExternalURL, "/") + "/setuid?bidder=adkernelAdn&uid={UID}"
return adapters.NewSyncer("adkernelAdn", adkernelGDPRVendorID, adapters.ResolveMacros(usersyncURL+url.QueryEscape(externalURL)), adapters.SyncTypeRedirect)
func NewAdkernelAdnSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("adkernelAdn", 14, temp, adapters.SyncTypeRedirect)
}
23 changes: 9 additions & 14 deletions adapters/adkernelAdn/usersync_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package adkernelAdn

import (
"strings"
"testing"
"text/template"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/stretchr/testify/assert"
)

func TestAdkernelAdnSyncer(t *testing.T) {
syncer := NewAdkernelAdnSyncer(&config.Configuration{ExternalURL: "https://localhost:8888", Adapters: map[string]config.Adapter{
// Prevents #736
strings.ToLower(string(openrtb_ext.BidderAdkernelAdn)): {
UserSyncURL: "https://tag.adkernel.com/syncr?gdpr={{gdpr}}&gdpr_consent={{gdpr_consent}}&r=",
},
}})
u := syncer.GetUsersyncInfo("1", "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw")
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", u.URL)
assert.Equal(t, "redirect", u.Type)
assert.Equal(t, adkernelGDPRVendorID, syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r=https%3A%2F%2Flocalhost%3A8888%2Fsetuid%3Fbidder%3DadkernelAdn%26uid%3D%7BUID%7D"))
syncer := NewAdkernelAdnSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("1", "BONciguONcjGKADACHENAOLS1rAHDAFAAEAASABQAMwAeACEAFw")
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, "redirect", syncInfo.Type)
assert.EqualValues(t, adkernelGDPRVendorID, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
9 changes: 3 additions & 6 deletions adapters/adtelligent/usersync.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package adtelligent

import (
"net/url"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/usersync"
)

func NewAdtelligentSyncer(cfg *config.Configuration) usersync.Usersyncer {
redirectURI := url.QueryEscape(cfg.ExternalURL) + "%2Fsetuid%3Fbidder%3Dadtelligent%26gdpr%3D{{gdpr}}%26gdpr_consent%3D{{gdpr_consent}}%26uid%3D%7Buid%7D"
usersyncURL := "//sync.adtelligent.com/csync?t=p&ep=0&redir="
return adapters.NewSyncer("adtelligent", 0, adapters.ResolveMacros(usersyncURL+redirectURI), adapters.SyncTypeRedirect)
func NewAdtelligentSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("adtelligent", 0, temp, adapters.SyncTypeRedirect)
}
17 changes: 9 additions & 8 deletions adapters/adtelligent/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package adtelligent

import (
"testing"

"github.com/prebid/prebid-server/config"
"text/template"

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

func TestAdtelligentSyncer(t *testing.T) {
syncer := NewAdtelligentSyncer(&config.Configuration{ExternalURL: "localhost"})
u := syncer.GetUsersyncInfo("0", "")
assert.Equal(t, "//sync.adtelligent.com/csync?t=p&ep=0&redir=localhost%2Fsetuid%3Fbidder%3Dadtelligent%26gdpr%3D0%26gdpr_consent%3D%26uid%3D%7Buid%7D", u.URL)
assert.Equal(t, "redirect", u.Type)
assert.Equal(t, uint16(0), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("//sync.adtelligent.com/csync?t=p&ep=0&redir=localhost%2Fsetuid%3Fbidder%3Dadtelligent%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%7Buid%7D"))
syncer := NewAdtelligentSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("0", "")
assert.NoError(t, err)
assert.Equal(t, "//sync.adtelligent.com/csync?t=p&ep=0&redir=localhost%2Fsetuid%3Fbidder%3Dadtelligent%26gdpr%3D0%26gdpr_consent%3D%26uid%3D%7Buid%7D", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 0, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
9 changes: 3 additions & 6 deletions adapters/appnexus/usersync.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package appnexus

import (
"net/url"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/usersync"
)

func NewAppnexusSyncer(cfg *config.Configuration) usersync.Usersyncer {
redirectURI := url.QueryEscape(cfg.ExternalURL) + "%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D{{gdpr}}%26gdpr_consent%3D{{gdpr_consent}}%26uid%3D%24UID"
usersyncURL := "//ib.adnxs.com/getuid?"
return adapters.NewSyncer("adnxs", 32, adapters.ResolveMacros(usersyncURL+redirectURI), adapters.SyncTypeRedirect)
func NewAppnexusSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("adnxs", 32, temp, adapters.SyncTypeRedirect)
}
17 changes: 9 additions & 8 deletions adapters/appnexus/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ package appnexus

import (
"testing"

"github.com/prebid/prebid-server/config"
"text/template"

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

func TestAppNexusSyncer(t *testing.T) {
syncer := NewAppnexusSyncer(&config.Configuration{ExternalURL: "https://prebid.adnxs.com/pbs/v1"})
u := syncer.GetUsersyncInfo("", "")
assert.Equal(t, "//ib.adnxs.com/getuid?https%3A%2F%2Fprebid.adnxs.com%2Fpbs%2Fv1%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D%26gdpr_consent%3D%26uid%3D%24UID", u.URL)
assert.Equal(t, "redirect", u.Type)
assert.Equal(t, uint16(32), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("//ib.adnxs.com/getuid?https%3A%2F%2Fprebid.adnxs.com%2Fpbs%2Fv1%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID"))
syncer := NewAppnexusSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("", "")
assert.NoError(t, err)
assert.Equal(t, "//ib.adnxs.com/getuid?https%3A%2F%2Fprebid.adnxs.com%2Fpbs%2Fv1%2Fsetuid%3Fbidder%3Dadnxs%26gdpr%3D%26gdpr_consent%3D%26uid%3D%24UID", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 32, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
9 changes: 3 additions & 6 deletions adapters/audienceNetwork/usersync.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package audienceNetwork

import (
"strings"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/usersync"
)

func NewFacebookSyncer(cfg *config.Configuration) usersync.Usersyncer {
syncURL := cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderFacebook))].UserSyncURL
return adapters.NewSyncer("audienceNetwork", 0, adapters.ResolveMacros(syncURL), adapters.SyncTypeRedirect)
func NewFacebookSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("audienceNetwork", 0, temp, adapters.SyncTypeRedirect)
}
23 changes: 9 additions & 14 deletions adapters/audienceNetwork/usersync_test.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
package audienceNetwork

import (
"strings"
"testing"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"text/template"

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

func TestFacebookSyncer(t *testing.T) {
syncer := NewFacebookSyncer(&config.Configuration{Adapters: map[string]config.Adapter{
strings.ToLower(string(openrtb_ext.BidderFacebook)): {
UserSyncURL: "https://www.facebook.com/audiencenetwork/idsync/?partner=partnerId&callback=localhost%2Fsetuid%3Fbidder%3DaudienceNetwork%26gdpr%3D{{gdpr}}%26gdpr_consent%3D{{gdpr_consent}}%26uid%3D%24UID",
},
}})
u := syncer.GetUsersyncInfo("", "")
assert.Equal(t, "https://www.facebook.com/audiencenetwork/idsync/?partner=partnerId&callback=localhost%2Fsetuid%3Fbidder%3DaudienceNetwork%26gdpr%3D%26gdpr_consent%3D%26uid%3D%24UID", u.URL)
assert.Equal(t, "redirect", u.Type)
assert.Equal(t, uint16(0), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("https://www.facebook.com/audiencenetwork/idsync/?partner=partnerId&callback=localhost%2Fsetuid%3Fbidder%3DaudienceNetwork%26gdpr%3D{{.GDPR}}%26gdpr_consent%3D{{.GDPRConsent}}%26uid%3D%24UID"))
syncer := NewFacebookSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("", "")
assert.NoError(t, err)
assert.Equal(t, "https://www.facebook.com/audiencenetwork/idsync/?partner=partnerId&callback=localhost%2Fsetuid%3Fbidder%3DaudienceNetwork%26gdpr%3D%26gdpr_consent%3D%26uid%3D%24UID", syncInfo.URL)
assert.Equal(t, "redirect", syncInfo.Type)
assert.EqualValues(t, 0, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
17 changes: 3 additions & 14 deletions adapters/beachfront/usersync.go
Original file line number Diff line number Diff line change
@@ -1,23 +1,12 @@
package beachfront

import (
"fmt"

"github.com/prebid/prebid-server/openrtb_ext"
"text/template"

"github.com/prebid/prebid-server/adapters"
"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/usersync"
)

func NewBeachfrontSyncer(cfg *config.Configuration) usersync.Usersyncer {
b := string(openrtb_ext.BidderBeachfront)
usersyncURL := cfg.Adapters[b].UserSyncURL
platformID := cfg.Adapters[b].PlatformID

url := ""
if len(usersyncURL) > 0 {
url = fmt.Sprintf("%s%s", usersyncURL, platformID)
}
return adapters.NewSyncer("beachfront", 0, adapters.ResolveMacros(url), adapters.SyncTypeIframe)
func NewBeachfrontSyncer(temp *template.Template) usersync.Usersyncer {
return adapters.NewSyncer("beachfront", 0, temp, adapters.SyncTypeIframe)
}
35 changes: 9 additions & 26 deletions adapters/beachfront/usersync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,18 @@ package beachfront

import (
"testing"

"github.com/prebid/prebid-server/config"
"github.com/prebid/prebid-server/openrtb_ext"
"text/template"

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

func TestBeachfrontSyncer(t *testing.T) {
syncer := NewBeachfrontSyncer(&config.Configuration{ExternalURL: "localhost", Adapters: map[string]config.Adapter{
string(openrtb_ext.BidderBeachfront): {
UserSyncURL: "localhost",
},
}})
u := syncer.GetUsersyncInfo("0", "")
assert.Equal(t, "localhost", u.URL)
assert.Equal(t, "iframe", u.Type)
assert.Equal(t, uint16(0), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
}

func TestBeachfrontNullSyncer(t *testing.T) {
syncer := NewBeachfrontSyncer(&config.Configuration{ExternalURL: "localhost", Adapters: map[string]config.Adapter{
string(openrtb_ext.BidderBeachfront): {
PlatformID: "142",
},
}})
u := syncer.GetUsersyncInfo("0", "")
assert.Equal(t, "", u.URL)
assert.Equal(t, "iframe", u.Type)
assert.Equal(t, uint16(0), syncer.GDPRVendorID())
assert.Equal(t, false, u.SupportCORS)
temp := template.Must(template.New("sync-template").Parse("localhost"))
syncer := NewBeachfrontSyncer(temp)
syncInfo, err := syncer.GetUsersyncInfo("", "")
assert.NoError(t, err)
assert.Equal(t, "localhost", syncInfo.URL)
assert.Equal(t, "iframe", syncInfo.Type)
assert.EqualValues(t, 0, syncer.GDPRVendorID())
assert.Equal(t, false, syncInfo.SupportCORS)
}
Loading

0 comments on commit 4eb9e7b

Please sign in to comment.