-
Notifications
You must be signed in to change notification settings - Fork 749
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
Update Viper #1969
Update Viper #1969
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ import ( | |
|
||
"encoding/json" | ||
|
||
"github.com/prebid/prebid-server/errortypes" | ||
"github.com/prebid/prebid-server/openrtb_ext" | ||
"github.com/spf13/viper" | ||
"github.com/stretchr/testify/assert" | ||
|
@@ -213,6 +214,9 @@ func TestDefaults(t *testing.T) { | |
}, | ||
} | ||
assert.Equal(t, expectedTCF2, cfg.GDPR.TCF2, "gdpr.tcf2") | ||
|
||
// Assert User Sync Override Defaults To Nil | ||
assert.Nil(t, cfg.Adapters["appnexus"].Syncer, "User Sync") | ||
} | ||
|
||
var fullConfig = []byte(` | ||
|
@@ -323,10 +327,13 @@ adapters: | |
endpoint: http://ixtest.com/api | ||
rubicon: | ||
endpoint: http://rubitest.com/api | ||
usersync_url: http://pixel.rubiconproject.com/sync.php?p=prebid | ||
xapi: | ||
username: rubiuser | ||
password: rubipw23 | ||
usersync: | ||
redirect: | ||
url: http://rubitest.com/sync | ||
user_macro: "{UID}" | ||
brightroll: | ||
usersync_url: http://test-bh.ybp.yahoo.com/sync/appnexuspbs?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&url=%s | ||
endpoint: http://test-bid.ybp.yahoo.com/bid/appnexuspbs | ||
|
@@ -354,38 +361,16 @@ adapters: | |
tracker: anxsTrack | ||
disabled: true | ||
extra_info: "{\"native\":\"http://www.native.org/endpoint\",\"video\":\"http://www.video.org/endpoint\"}" | ||
audienceNetwork: | ||
endpoint: http://facebook.com/pbs | ||
usersync_url: http://facebook.com/ortb/prebid-s2s | ||
platform_id: abcdefgh1234 | ||
ix: | ||
endpoint: http://ixtest.com/api | ||
rubicon: | ||
endpoint: http://rubitest.com/api | ||
usersync_url: http://pixel.rubiconproject.com/sync.php?p=prebid | ||
xapi: | ||
username: rubiuser | ||
password: rubipw23 | ||
brightroll: | ||
usersync_url: http://test-bh.ybp.yahoo.com/sync/appnexuspbs?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&url=%s | ||
endpoint: http://test-bid.ybp.yahoo.com/bid/appnexuspbs | ||
adkerneladn: | ||
usersync_url: https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r= | ||
blacklisted_apps: ["spamAppID","sketchy-app-id"] | ||
`) | ||
|
||
var invalidAdapterEndpointConfig = []byte(` | ||
adapters: | ||
appnexus: | ||
endpoint: ib.adnxs.com/some/endpoint | ||
audienceNetwork: | ||
endpoint: http://facebook.com/pbs | ||
usersync_url: http://facebook.com/ortb/prebid-s2s | ||
platform_id: abcdefgh1234 | ||
brightroll: | ||
usersync_url: http://http://test-bh.ybp.yahoo.com/sync/appnexuspbs?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&url=%s | ||
adkerneladn: | ||
usersync_url: https://tag.adkernel.com/syncr?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&r= | ||
usersync: | ||
redirect: | ||
url: http://http://test-bh.ybp.yahoo.com/sync/appnexuspbs?gdpr={{.GDPR}}&euconsent={{.GDPRConsent}}&url=%s | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Updated to the new user sync config values. |
||
`) | ||
|
||
var oldStoredRequestsConfig = []byte(` | ||
|
@@ -409,6 +394,11 @@ func cmpBools(t *testing.T, key string, a bool, b bool) { | |
assert.Equal(t, a, b, "%s: %t != %t", key, a, b) | ||
} | ||
|
||
func cmpNils(t *testing.T, key string, a interface{}) { | ||
t.Helper() | ||
assert.Nilf(t, a, "%s: %t != nil", key, a) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept with the test pattern. I think we'll want to deprecate this approach in the future, but kept with the pattern for now. |
||
|
||
func TestFullConfig(t *testing.T) { | ||
v := viper.New() | ||
SetupViper(v, "") | ||
|
@@ -565,12 +555,16 @@ func TestFullConfig(t *testing.T) { | |
cmpStrings(t, "adapters.audiencenetwork.endpoint", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAudienceNetwork))].Endpoint, "http://facebook.com/pbs") | ||
cmpStrings(t, "adapters.audiencenetwork.platform_id", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAudienceNetwork))].PlatformID, "abcdefgh1234") | ||
cmpStrings(t, "adapters.audiencenetwork.app_secret", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAudienceNetwork))].AppSecret, "987abc") | ||
cmpStrings(t, "adapters.audiencenetwork.usersync_url", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderAudienceNetwork))].UserSyncURL, "http://facebook.com/ortb/prebid-s2s") | ||
cmpStrings(t, "adapters.beachfront.endpoint", cfg.Adapters[string(openrtb_ext.BidderBeachfront)].Endpoint, "https://display.bfmio.com/prebid_display") | ||
cmpStrings(t, "adapters.beachfront.extra_info", cfg.Adapters[string(openrtb_ext.BidderBeachfront)].ExtraAdapterInfo, "{\"video_endpoint\":\"https://reachms.bfmio.com/bid.json?exchange_id\"}") | ||
cmpStrings(t, "adapters.ix.endpoint", cfg.Adapters[strings.ToLower(string(openrtb_ext.BidderIx))].Endpoint, "http://ixtest.com/api") | ||
cmpStrings(t, "adapters.rubicon.endpoint", cfg.Adapters[string(openrtb_ext.BidderRubicon)].Endpoint, "http://rubitest.com/api") | ||
cmpStrings(t, "adapters.rubicon.xapi.username", cfg.Adapters[string(openrtb_ext.BidderRubicon)].XAPI.Username, "rubiuser") | ||
cmpStrings(t, "adapters.rubicon.xapi.password", cfg.Adapters[string(openrtb_ext.BidderRubicon)].XAPI.Password, "rubipw23") | ||
cmpStrings(t, "adapters.rubicon.usersync.redirect.url", cfg.Adapters[string(openrtb_ext.BidderRubicon)].Syncer.Redirect.URL, "http://rubitest.com/sync") | ||
cmpNils(t, "adapters.rubicon.usersync.iframe", cfg.Adapters[string(openrtb_ext.BidderRubicon)].Syncer.IFrame) | ||
cmpStrings(t, "adapters.rubicon.usersync.redirect.user_macro", cfg.Adapters[string(openrtb_ext.BidderRubicon)].Syncer.Redirect.UserMacro, "{UID}") | ||
cmpStrings(t, "adapters.brightroll.endpoint", cfg.Adapters[string(openrtb_ext.BidderBrightroll)].Endpoint, "http://test-bid.ybp.yahoo.com/bid/appnexuspbs") | ||
cmpStrings(t, "adapters.rhythmone.endpoint", cfg.Adapters[string(openrtb_ext.BidderRhythmone)].Endpoint, "http://tag.1rx.io/rmp") | ||
cmpBools(t, "account_required", cfg.AccountRequired, true) | ||
|
@@ -597,9 +591,6 @@ func TestUnmarshalAdapterExtraInfo(t *testing.T) { | |
// Assert correctly unmarshaled | ||
assert.NoError(t, err, "invalid endpoint in config should return an error") | ||
|
||
// Unescape quotes of JSON-formatted string | ||
strings.Replace(cfg.Adapters[string(openrtb_ext.BidderAppnexus)].ExtraAdapterInfo, "\\\"", "\"", -1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This actually performs no operation since it returns the new string which is ignored. Removed. The unescape isn't necessary. |
||
|
||
// Assert JSON-formatted string | ||
assert.JSONEqf(t, `{"native":"http://www.native.org/endpoint","video":"http://www.video.org/endpoint"}`, cfg.Adapters[string(openrtb_ext.BidderAppnexus)].ExtraAdapterInfo, "Unexpected value of the ExtraAdapterInfo String \n") | ||
|
||
|
@@ -619,7 +610,7 @@ func TestUnmarshalAdapterExtraInfo(t *testing.T) { | |
assert.Equal(t, "http://www.video.org/endpoint", AppNexusAdapterExtraInfo.VideoEndpoint) | ||
} | ||
|
||
func TestValidConfig(t *testing.T) { | ||
func TestValidateConfig(t *testing.T) { | ||
cfg := Configuration{ | ||
GDPR: GDPR{ | ||
DefaultValue: "1", | ||
|
@@ -757,7 +748,11 @@ func TestInvalidAdapterEndpointConfig(t *testing.T) { | |
v.SetConfigType("yaml") | ||
v.ReadConfig(bytes.NewBuffer(invalidAdapterEndpointConfig)) | ||
_, err := New(v) | ||
assert.Error(t, err, "invalid endpoint in config should return an error") | ||
|
||
if assert.IsType(t, errortypes.AggregateError{}, err) { | ||
aggErr := err.(errortypes.AggregateError) | ||
assert.ElementsMatch(t, []error{errors.New("The endpoint: ib.adnxs.com/some/endpoint for appnexus is not a valid URL")}, aggErr.Errors) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Verified the exact error to be sure it's catching the error we expect. |
||
} | ||
|
||
func TestNegativeRequestSize(t *testing.T) { | ||
|
@@ -936,6 +931,53 @@ func TestValidateAccountsConfigRestrictions(t *testing.T) { | |
assert.Contains(t, errs, errors.New("accounts.postgres: retrieving accounts via postgres not available, use accounts.files")) | ||
} | ||
|
||
func TestUserSyncFromEnv(t *testing.T) { | ||
truePtr := true | ||
|
||
// setup env vars for testing | ||
if oldval, ok := os.LookupEnv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_URL"); ok { | ||
defer os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_URL", oldval) | ||
} else { | ||
defer os.Unsetenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_URL") | ||
} | ||
|
||
if oldval, ok := os.LookupEnv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_USER_MACRO"); ok { | ||
defer os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_USER_MACRO", oldval) | ||
} else { | ||
defer os.Unsetenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_USER_MACRO") | ||
} | ||
|
||
if oldval, ok := os.LookupEnv("PBS_ADAPTERS_APPNEXUS_USERSYNC_SUPPORT_CORS"); ok { | ||
defer os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_SUPPORT_CORS", oldval) | ||
} else { | ||
defer os.Unsetenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_SUPPORT_CORS") | ||
} | ||
|
||
if oldval, ok := os.LookupEnv("PBS_ADAPTERS_RUBICON_USERSYNC_IFRAME_URL"); ok { | ||
defer os.Setenv("PBS_ADAPTERS_RUBICON_USERSYNC_IFRAME_URL", oldval) | ||
} else { | ||
defer os.Unsetenv("PBS_ADAPTERS_RUBICON_USERSYNC_IFRAME_URL") | ||
} | ||
|
||
// set new | ||
os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_URL", "http://some.url/sync?redirect={{.RedirectURL}}") | ||
os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_REDIRECT_USER_MACRO", "[UID]") | ||
os.Setenv("PBS_ADAPTERS_APPNEXUS_USERSYNC_SUPPORT_CORS", "true") | ||
os.Setenv("PBS_ADAPTERS_RUBICON_USERSYNC_IFRAME_URL", "http://somedifferent.url/sync?redirect={{.RedirectURL}}") | ||
|
||
cfg, _ := newDefaultConfig(t) | ||
assert.Equal(t, cfg.Adapters["appnexus"].Syncer.Redirect.URL, "http://some.url/sync?redirect={{.RedirectURL}}") | ||
assert.Equal(t, cfg.Adapters["appnexus"].Syncer.Redirect.UserMacro, "[UID]") | ||
assert.Nil(t, cfg.Adapters["appnexus"].Syncer.IFrame) | ||
assert.Equal(t, cfg.Adapters["appnexus"].Syncer.SupportCORS, &truePtr) | ||
|
||
assert.Equal(t, cfg.Adapters["rubicon"].Syncer.IFrame.URL, "http://somedifferent.url/sync?redirect={{.RedirectURL}}") | ||
assert.Nil(t, cfg.Adapters["rubicon"].Syncer.Redirect) | ||
assert.Nil(t, cfg.Adapters["rubicon"].Syncer.SupportCORS) | ||
|
||
assert.Nil(t, cfg.Adapters["brightroll"].Syncer) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensures the proper handling of pointers with nil defaults via BindEnv. |
||
|
||
func newDefaultConfig(t *testing.T) (*Configuration, *viper.Viper) { | ||
v := viper.New() | ||
SetupViper(v, "") | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ module github.com/prebid/prebid-server | |
go 1.16 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 // indirect | ||
github.com/DATA-DOG/go-sqlmock v1.3.0 | ||
github.com/NYTimes/gziphandler v1.1.1 | ||
github.com/OneOfOne/xxhash v1.2.5 // indirect | ||
|
@@ -19,31 +18,24 @@ require ( | |
github.com/evanphx/json-patch v0.0.0-20180720181644-f195058310bd | ||
github.com/gofrs/uuid v3.2.0+incompatible | ||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/influxdata/influxdb v1.6.1 | ||
github.com/julienschmidt/httprouter v1.1.0 | ||
github.com/lib/pq v1.0.0 | ||
github.com/magiconair/properties v1.8.0 | ||
github.com/magiconair/properties v1.8.5 | ||
github.com/mattn/go-colorable v0.1.2 // indirect | ||
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect | ||
github.com/mitchellh/copystructure v1.1.2 | ||
github.com/mitchellh/mapstructure v1.0.0 // indirect | ||
github.com/mxmCherry/openrtb/v15 v15.0.0 | ||
github.com/pelletier/go-toml v1.2.0 // indirect | ||
github.com/prebid/go-gdpr v0.9.0 | ||
github.com/prometheus/client_golang v0.0.0-20180623155954-77e8f2ddcfed | ||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910 | ||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 | ||
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e // indirect | ||
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 // indirect | ||
github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165 | ||
github.com/rs/cors v1.5.0 | ||
github.com/sergi/go-diff v1.0.0 // indirect | ||
github.com/spaolacci/murmur3 v1.1.0 // indirect | ||
github.com/spf13/afero v1.1.1 // indirect | ||
github.com/spf13/cast v1.2.0 // indirect | ||
github.com/spf13/jwalterweatherman v0.0.0-20180814060501-14d3d4c51834 // indirect | ||
github.com/spf13/pflag v1.0.2 // indirect | ||
github.com/spf13/viper v1.1.0 | ||
github.com/spf13/viper v1.8.1 | ||
github.com/stretchr/objx v0.1.1 // indirect | ||
github.com/stretchr/testify v1.7.0 | ||
github.com/vrischmann/go-metrics-influxdb v0.0.0-20160917065939-43af8332c303 | ||
|
@@ -53,7 +45,7 @@ require ( | |
github.com/yudai/gojsondiff v0.0.0-20170107030110-7b1b7adf999d | ||
github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 // indirect | ||
github.com/yudai/pp v2.0.1+incompatible // indirect | ||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb | ||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4 | ||
golang.org/x/text v0.3.6 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I only updated viper. The rest of the updates are transitive. |
||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These values are not important for this test case and have been removed.