Skip to content

Commit

Permalink
Reverted SyncerKey placeholder name
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 committed Jul 24, 2023
1 parent fc8b684 commit c6a9bd5
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions config/bidderinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,13 @@ type SyncerEndpoint struct {
// startup:
//
// {{.ExternalURL}} - This will be replaced with the host server's externally reachable http path.
// {{.BidderName}} - This will be replaced with the bidder name.
// {{.SyncerKey}} - This will be replaced with the syncer key.
// {{.SyncType}} - This will be replaced with the sync type, either 'b' for iframe syncs or 'i'
// for redirect/image syncs.
// {{.UserMacro}} - This will be replaced with the bidder server's user id macro.
//
// The endpoint on the host server is usually Prebid Server's /setuid endpoint. The default value is:
// `{{.ExternalURL}}/setuid?bidder={{.BidderName}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}`
// `{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}`
RedirectURL string `yaml:"redirectUrl" mapstructure:"redirect_url"`

// ExternalURL is available as a macro to the RedirectURL template. If not specified, either the syncer configuration
Expand Down
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {

// some adapters append the user id to the end of the redirect url instead of using
// macro substitution. it is important for the uid to be the last query parameter.
v.SetDefault("user_sync.redirect_url", "{{.ExternalURL}}/setuid?bidder={{.BidderName}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}")
v.SetDefault("user_sync.redirect_url", "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&f={{.SyncType}}&uid={{.UserMacro}}")

v.SetDefault("max_request_size", 1024*256)
v.SetDefault("analytics.file.filename", "")
Expand Down
4 changes: 2 additions & 2 deletions usersync/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func resolveDefaultSyncType(syncerConfig config.Syncer) SyncType {
// macro substitution regex
var (
macroRegexExternalHost = regexp.MustCompile(`{{\s*\.ExternalURL\s*}}`)
macroRegexBidderName = regexp.MustCompile(`{{\s*\.BidderName\s*}}`)
macroRegexSyncerKey = regexp.MustCompile(`{{\s*\.SyncerKey\s*}}`)
macroRegexSyncType = regexp.MustCompile(`{{\s*\.SyncType\s*}}`)
macroRegexUserMacro = regexp.MustCompile(`{{\s*\.UserMacro\s*}}`)
macroRegexRedirect = regexp.MustCompile(`{{\s*\.RedirectURL\s*}}`)
Expand All @@ -128,7 +128,7 @@ func buildTemplate(bidderName, syncTypeValue string, hostConfig config.UserSync,

externalURL := chooseExternalURL(syncerEndpoint.ExternalURL, syncerExternalURL, hostConfig.ExternalURL)

redirectURL := macroRegexBidderName.ReplaceAllLiteralString(redirectTemplate, bidderName)
redirectURL := macroRegexSyncerKey.ReplaceAllLiteralString(redirectTemplate, bidderName)
redirectURL = macroRegexSyncType.ReplaceAllLiteralString(redirectURL, syncTypeValue)
redirectURL = macroRegexUserMacro.ReplaceAllLiteralString(redirectURL, syncerEndpoint.UserMacro)
redirectURL = macroRegexExternalHost.ReplaceAllLiteralString(redirectURL, externalURL)
Expand Down
4 changes: 2 additions & 2 deletions usersync/syncer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func TestBuildTemplate(t *testing.T) {
description: "All Composed Macros",
givenSyncerEndpoint: config.SyncerEndpoint{
URL: "https://bidder.com/sync?redirect={{.RedirectURL}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.BidderName}}&f={{.SyncType}}&gdpr={{.GDPR}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&uid={{.UserMacro}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&f={{.SyncType}}&gdpr={{.GDPR}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&uid={{.UserMacro}}",
ExternalURL: "http://syncer.com",
UserMacro: "$UID$",
},
Expand Down Expand Up @@ -265,7 +265,7 @@ func TestBuildTemplate(t *testing.T) {
description: "User Macro Is Go Template Macro-Like",
givenSyncerEndpoint: config.SyncerEndpoint{
URL: "https://bidder.com/sync?redirect={{.RedirectURL}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.BidderName}}&f={{.SyncType}}&gdpr={{.GDPR}}&uid={{.UserMacro}}",
RedirectURL: "{{.ExternalURL}}/setuid?bidder={{.SyncerKey}}&f={{.SyncType}}&gdpr={{.GDPR}}&uid={{.UserMacro}}",
UserMacro: "{{UID}}",
},
expectedRendered: "https://bidder.com/sync?redirect=http%3A%2F%2Fhost.com%2Fsetuid%3Fbidder%3DanyKey%26f%3Dx%26gdpr%3DA%26uid%3D%7B%7BUID%7D%7D",
Expand Down
4 changes: 2 additions & 2 deletions usersync/syncersbuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestSyncerBuildError(t *testing.T) {

func TestBuildSyncers(t *testing.T) {
var (
hostConfig = config.Configuration{ExternalURL: "http://host.com", UserSync: config.UserSync{RedirectURL: "{{.ExternalURL}}/{{.BidderName}}/host"}}
hostConfig = config.Configuration{ExternalURL: "http://host.com", UserSync: config.UserSync{RedirectURL: "{{.ExternalURL}}/{{.SyncerKey}}/host"}}
iframeConfig = &config.SyncerEndpoint{URL: "https://bidder.com/iframe?redirect={{.RedirectURL}}"}
iframeConfigError = &config.SyncerEndpoint{URL: "https://bidder.com/iframe?redirect={{xRedirectURL}}"} // Error caused by invalid macro
infoKeyAPopulated = config.BidderInfo{Disabled: false, Syncer: &config.Syncer{Key: "a", IFrame: iframeConfig}}
Expand Down Expand Up @@ -145,7 +145,7 @@ func TestBuildSyncers(t *testing.T) {
},
{
description: "ExternalURL Host User Sync Override",
givenConfig: config.Configuration{ExternalURL: "http://host.com", UserSync: config.UserSync{ExternalURL: "http://hostoverride.com", RedirectURL: "{{.ExternalURL}}/{{.BidderName}}/host"}},
givenConfig: config.Configuration{ExternalURL: "http://host.com", UserSync: config.UserSync{ExternalURL: "http://hostoverride.com", RedirectURL: "{{.ExternalURL}}/{{.SyncerKey}}/host"}},
givenBidderInfos: map[string]config.BidderInfo{"bidder1": infoKeyAPopulated},
expectedIFramesURLs: map[string]string{
"bidder1": "https://bidder.com/iframe?redirect=http%3A%2F%2Fhostoverride.com%2Fbidder1%2Fhost",
Expand Down

0 comments on commit c6a9bd5

Please sign in to comment.