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

Rename Blacklisted Apps to Blocked Apps #3620

Merged
merged 3 commits into from
Oct 29, 2024
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
17 changes: 8 additions & 9 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ type Configuration struct {

VideoStoredRequestRequired bool `mapstructure:"video_stored_request_required"`

// Array of blacklisted apps that is used to create the hash table BlacklistedAppMap so App.ID's can be instantly accessed.
BlacklistedApps []string `mapstructure:"blacklisted_apps,flow"`
BlacklistedAppMap map[string]bool
// Array of blocked apps that is used to create the hash table BlockedAppsLookup so App.ID's can be instantly accessed.
BlockedApps []string `mapstructure:"blocked_apps,flow"`
BlockedAppsLookup map[string]bool
// Is publisher/account ID required to be submitted in the OpenRTB2 request
AccountRequired bool `mapstructure:"account_required"`
// AccountDefaults defines default settings for valid accounts that are partially defined
Expand Down Expand Up @@ -796,10 +796,10 @@ func New(v *viper.Viper, bidderInfos BidderInfos, normalizeBidderName openrtb_ex
}

// To look for a request's app_id in O(1) time, we fill this hash table located in the
// the BlacklistedApps field of the Configuration struct defined in this file
c.BlacklistedAppMap = make(map[string]bool)
for i := 0; i < len(c.BlacklistedApps); i++ {
c.BlacklistedAppMap[c.BlacklistedApps[i]] = true
// the BlockedApps field of the Configuration struct defined in this file
c.BlockedAppsLookup = make(map[string]bool)
for i := 0; i < len(c.BlockedApps); i++ {
c.BlockedAppsLookup[c.BlockedApps[i]] = true
}

// Migrate combo stored request config to separate stored_reqs and amp stored_reqs configs.
Expand Down Expand Up @@ -1148,8 +1148,7 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("default_request.type", "")
v.SetDefault("default_request.file.name", "")
v.SetDefault("default_request.alias_info", false)
v.SetDefault("blacklisted_apps", []string{""})
v.SetDefault("blacklisted_accts", []string{""})
SyntaxNode marked this conversation as resolved.
Show resolved Hide resolved
v.SetDefault("blocked_apps", []string{""})
v.SetDefault("account_required", false)
v.SetDefault("account_defaults.disabled", false)
v.SetDefault("account_defaults.debug_allow", true)
Expand Down
12 changes: 6 additions & 6 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ metrics:
adapter_buyeruid_scrubbed: false
adapter_gdpr_request_blocked: true
account_modules_metrics: true
blacklisted_apps: ["spamAppID","sketchy-app-id"]
blocked_apps: ["spamAppID","sketchy-app-id"]
account_required: true
auto_gen_source_tid: false
certificates_file: /etc/ssl/cert.pem
Expand Down Expand Up @@ -714,12 +714,12 @@ func TestFullConfig(t *testing.T) {
cmpBools(t, "lmt.enforce", true, cfg.LMT.Enforce)

//Assert the NonStandardPublishers was correctly unmarshalled
cmpStrings(t, "blacklisted_apps", "spamAppID", cfg.BlacklistedApps[0])
cmpStrings(t, "blacklisted_apps", "sketchy-app-id", cfg.BlacklistedApps[1])
cmpStrings(t, "blocked_apps", "spamAppID", cfg.BlockedApps[0])
cmpStrings(t, "blocked_apps", "sketchy-app-id", cfg.BlockedApps[1])

//Assert the BlacklistedAppMap hash table was built correctly
for i := 0; i < len(cfg.BlacklistedApps); i++ {
cmpBools(t, "cfg.BlacklistedAppMap", true, cfg.BlacklistedAppMap[cfg.BlacklistedApps[i]])
//Assert the BlockedAppsLookup hash table was built correctly
for i := 0; i < len(cfg.BlockedApps); i++ {
cmpBools(t, "cfg.BlockedAppsLookup", true, cfg.BlockedAppsLookup[cfg.BlockedApps[i]])
}

//Assert purpose VendorExceptionMap hash tables were built correctly
Expand Down
2 changes: 1 addition & 1 deletion endpoints/events/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func HandleAccountServiceErrors(errs []error) (status int, messages []string) {

errCode := errortypes.ReadCode(er)

if errCode == errortypes.BlacklistedAppErrorCode || errCode == errortypes.AccountDisabledErrorCode {
if errCode == errortypes.BlockedAppErrorCode || errCode == errortypes.AccountDisabledErrorCode {
status = http.StatusServiceUnavailable
}
if errCode == errortypes.MalformedAcctErrorCode {
Expand Down
4 changes: 2 additions & 2 deletions endpoints/openrtb2/amp_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ func (deps *endpointDeps) AmpAuction(w http.ResponseWriter, r *http.Request, _ h
metricsStatus := metrics.RequestStatusBadInput
for _, er := range errL {
errCode := errortypes.ReadCode(er)
if errCode == errortypes.BlacklistedAppErrorCode || errCode == errortypes.AccountDisabledErrorCode {
if errCode == errortypes.BlockedAppErrorCode || errCode == errortypes.AccountDisabledErrorCode {
httpStatus = http.StatusServiceUnavailable
metricsStatus = metrics.RequestStatusBlacklisted
metricsStatus = metrics.RequestStatusBlockedApp
break
}
if errCode == errortypes.MalformedAcctErrorCode {
Expand Down
4 changes: 2 additions & 2 deletions endpoints/openrtb2/amp_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ func TestGoodAmpRequests(t *testing.T) {
GDPR: config.GDPR{Enabled: true},
}
if test.Config != nil {
cfg.BlacklistedApps = test.Config.BlacklistedApps
cfg.BlacklistedAppMap = test.Config.getBlacklistedAppMap()
cfg.BlockedApps = test.Config.BlockedApps
cfg.BlockedAppsLookup = test.Config.getBlockedAppLookup()
cfg.AccountRequired = test.Config.AccountRequired
}

Expand Down
8 changes: 4 additions & 4 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1230,8 +1230,8 @@ func (deps *endpointDeps) validateApp(req *openrtb_ext.RequestWrapper) error {
}

if req.App.ID != "" {
if _, found := deps.cfg.BlacklistedAppMap[req.App.ID]; found {
return &errortypes.BlacklistedApp{Message: fmt.Sprintf("Prebid-server does not process requests from App ID: %s", req.App.ID)}
if _, found := deps.cfg.BlockedAppsLookup[req.App.ID]; found {
return &errortypes.BlockedApp{Message: fmt.Sprintf("Prebid-server does not process requests from App ID: %s", req.App.ID)}
}
}

Expand Down Expand Up @@ -1898,9 +1898,9 @@ func writeError(errs []error, w http.ResponseWriter, labels *metrics.Labels) boo
metricsStatus := metrics.RequestStatusBadInput
for _, err := range errs {
erVal := errortypes.ReadCode(err)
if erVal == errortypes.BlacklistedAppErrorCode || erVal == errortypes.AccountDisabledErrorCode {
if erVal == errortypes.BlockedAppErrorCode || erVal == errortypes.AccountDisabledErrorCode {
httpStatus = http.StatusServiceUnavailable
metricsStatus = metrics.RequestStatusBlacklisted
metricsStatus = metrics.RequestStatusBlockedApp
break
} else if erVal == errortypes.MalformedAcctErrorCode {
httpStatus = http.StatusInternalServerError
Expand Down
4 changes: 2 additions & 2 deletions endpoints/openrtb2/auction_benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func BenchmarkValidWholeExemplary(b *testing.B) {

cfg := &config.Configuration{
MaxRequestSize: maxSize,
BlacklistedApps: test.Config.BlacklistedApps,
BlacklistedAppMap: test.Config.getBlacklistedAppMap(),
BlockedApps: test.Config.BlockedApps,
BlockedAppsLookup: test.Config.getBlockedAppLookup(),
AccountRequired: test.Config.AccountRequired,
}

Expand Down
8 changes: 4 additions & 4 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ func TestJsonSampleRequests(t *testing.T) {
"account-malformed",
},
{
"Asserts we return 503s on requests with blacklisted accounts and apps.",
"blacklisted",
"Asserts we return 503s on requests with blocked apps.",
"blocked",
},
{
"Assert that requests that come with no user id nor app id return error if the `AccountRequired` field in the `config.Configuration` structure is set to true",
Expand Down Expand Up @@ -169,8 +169,8 @@ func runJsonBasedTest(t *testing.T, filename, desc string) {
// Build endpoint for testing. If no error, run test case
cfg := &config.Configuration{MaxRequestSize: maxSize}
if test.Config != nil {
cfg.BlacklistedApps = test.Config.BlacklistedApps
cfg.BlacklistedAppMap = test.Config.getBlacklistedAppMap()
cfg.BlockedApps = test.Config.BlockedApps
cfg.BlockedAppsLookup = test.Config.getBlockedAppLookup()
cfg.AccountRequired = test.Config.AccountRequired
}
cfg.MarshalAccountDefaults()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"description": "This is a perfectly valid request except that it comes from a blacklisted App",
"description": "This is a perfectly valid request except that it comes from a blocked app",
"config": {
"blacklistedApps": ["spam_app"]
"blockedApps": ["spam_app"]
},
"mockBidRequest": {
"id": "some-request-id",
Expand Down
16 changes: 8 additions & 8 deletions endpoints/openrtb2/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type testCase struct {
type testConfigValues struct {
AccountRequired bool `json:"accountRequired"`
AliasJSON string `json:"aliases"`
BlacklistedApps []string `json:"blacklistedApps"`
BlockedApps []string `json:"blockedApps"`
DisabledAdapters []string `json:"disabledAdapters"`
CurrencyRates map[string]map[string]float64 `json:"currencyRates"`
MockBidders []mockBidderHandler `json:"mockBidders"`
Expand Down Expand Up @@ -1164,16 +1164,16 @@ func parseTestData(fileData []byte, testFile string) (testCase, error) {
return parsedTestData, nil
}

func (tc *testConfigValues) getBlacklistedAppMap() map[string]bool {
var blacklistedAppMap map[string]bool
func (tc *testConfigValues) getBlockedAppLookup() map[string]bool {
var blockedAppLookup map[string]bool

if len(tc.BlacklistedApps) > 0 {
blacklistedAppMap = make(map[string]bool, len(tc.BlacklistedApps))
for _, app := range tc.BlacklistedApps {
blacklistedAppMap[app] = true
if len(tc.BlockedApps) > 0 {
blockedAppLookup = make(map[string]bool, len(tc.BlockedApps))
for _, app := range tc.BlockedApps {
blockedAppLookup[app] = true
}
}
return blacklistedAppMap
return blockedAppLookup
}

// exchangeTestWrapper is a wrapper that asserts the openrtb2 bid request just before the HoldAuction call
Expand Down
8 changes: 4 additions & 4 deletions endpoints/openrtb2/video_auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ func handleError(labels *metrics.Labels, w http.ResponseWriter, errL []error, vo
var status int = http.StatusInternalServerError
for _, er := range errL {
erVal := errortypes.ReadCode(er)
if erVal == errortypes.BlacklistedAppErrorCode || erVal == errortypes.AccountDisabledErrorCode {
if erVal == errortypes.BlockedAppErrorCode || erVal == errortypes.AccountDisabledErrorCode {
status = http.StatusServiceUnavailable
labels.RequestStatus = metrics.RequestStatusBlacklisted
labels.RequestStatus = metrics.RequestStatusBlockedApp
break
} else if erVal == errortypes.AcctRequiredErrorCode {
status = http.StatusBadRequest
Expand Down Expand Up @@ -813,8 +813,8 @@ func (deps *endpointDeps) validateVideoRequest(req *openrtb_ext.BidRequestVideo)
errL = append(errL, err)
} else if req.App != nil {
if req.App.ID != "" {
if _, found := deps.cfg.BlacklistedAppMap[req.App.ID]; found {
err := &errortypes.BlacklistedApp{Message: fmt.Sprintf("Prebid-server does not process requests from App ID: %s", req.App.ID)}
if _, found := deps.cfg.BlockedAppsLookup[req.App.ID]; found {
err := &errortypes.BlockedApp{Message: fmt.Sprintf("Prebid-server does not process requests from App ID: %s", req.App.ID)}
errL = append(errL, err)
return errL, podErrors
}
Expand Down
6 changes: 3 additions & 3 deletions endpoints/openrtb2/video_auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,15 +814,15 @@ func TestHandleError(t *testing.T) {
&errortypes.AccountDisabled{},
},
wantCode: 503,
wantMetricsStatus: metrics.RequestStatusBlacklisted,
wantMetricsStatus: metrics.RequestStatusBlockedApp,
},
{
description: "Blocked app - return 503 with blocked metrics status",
giveErrors: []error{
&errortypes.BlacklistedApp{},
&errortypes.BlockedApp{},
},
wantCode: 503,
wantMetricsStatus: metrics.RequestStatusBlacklisted,
wantMetricsStatus: metrics.RequestStatusBlockedApp,
},
{
description: "Account required error - return 400 with bad input metrics status",
Expand Down
2 changes: 1 addition & 1 deletion errortypes/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const (
UnknownErrorCode = 999
TimeoutErrorCode = iota
BadInputErrorCode
BlacklistedAppErrorCode
BlockedAppErrorCode
BadServerResponseErrorCode
FailedToRequestBidsErrorCode
BidderTemporarilyDisabledErrorCode
Expand Down
15 changes: 6 additions & 9 deletions errortypes/errortypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,20 @@ func (err *BadInput) Severity() Severity {
return SeverityFatal
}

// BlacklistedApp should be used when a request App.ID matches an entry in the BlacklistedApps
// environment variable array
//
// These errors will be written to http.ResponseWriter before canceling execution
type BlacklistedApp struct {
// BlockedApp should be used when a request App.ID matches an entry in the BlockedApp configuration.
type BlockedApp struct {
Message string
}

func (err *BlacklistedApp) Error() string {
func (err *BlockedApp) Error() string {
return err.Message
}

func (err *BlacklistedApp) Code() int {
return BlacklistedAppErrorCode
func (err *BlockedApp) Code() int {
return BlockedAppErrorCode
}

func (err *BlacklistedApp) Severity() Severity {
func (err *BlockedApp) Severity() Severity {
return SeverityFatal
}

Expand Down
22 changes: 10 additions & 12 deletions metrics/config/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,14 @@ func TestGoMetricsEngine(t *testing.T) {
}
}

// Test the multiengine
func TestMultiMetricsEngine(t *testing.T) {
cfg := mainConfig.Configuration{}
cfg.Metrics.Influxdb.Host = "localhost"
adapterList := openrtb_ext.CoreBidderNames()
goEngine := metrics.NewMetrics(gometrics.NewPrefixedRegistry("prebidserver."), adapterList, mainConfig.DisabledMetrics{}, nil, modulesStages)
engineList := make(MultiMetricsEngine, 2)
engineList[0] = goEngine
engineList[1] = &NilMetricsEngine{}
var metricsEngine metrics.MetricsEngine = &engineList
metricsEngine := make(MultiMetricsEngine, 2)
metricsEngine[0] = goEngine
metricsEngine[1] = &NilMetricsEngine{}
labels := metrics.Labels{
Source: metrics.DemandWeb,
RType: metrics.ReqTypeORTB2Web,
Expand Down Expand Up @@ -108,23 +106,23 @@ func TestMultiMetricsEngine(t *testing.T) {
metricsEngine.RecordModuleExecutionError(module)
metricsEngine.RecordModuleTimeout(module)
}
labelsBlacklist := []metrics.Labels{
labelsBlocked := []metrics.Labels{
{
Source: metrics.DemandWeb,
RType: metrics.ReqTypeAMP,
PubID: "test2",
CookieFlag: metrics.CookieFlagYes,
RequestStatus: metrics.RequestStatusBlacklisted,
RequestStatus: metrics.RequestStatusBlockedApp,
},
{
Source: metrics.DemandWeb,
RType: metrics.ReqTypeVideo,
PubID: "test2",
CookieFlag: metrics.CookieFlagYes,
RequestStatus: metrics.RequestStatusBlacklisted,
RequestStatus: metrics.RequestStatusBlockedApp,
},
}
for _, label := range labelsBlacklist {
for _, label := range labelsBlocked {
metricsEngine.RecordRequest(label)
}
impTypeLabels.BannerImps = false
Expand All @@ -150,14 +148,14 @@ func TestMultiMetricsEngine(t *testing.T) {
//Make the metrics engine, instantiated here with goEngine, fill its RequestStatuses[RequestType][metrics.RequestStatusXX] with the new boolean values added to metrics.Labels
VerifyMetrics(t, "RequestStatuses.OpenRTB2.OK", goEngine.RequestStatuses[metrics.ReqTypeORTB2Web][metrics.RequestStatusOK].Count(), 5)
VerifyMetrics(t, "RequestStatuses.AMP.OK", goEngine.RequestStatuses[metrics.ReqTypeAMP][metrics.RequestStatusOK].Count(), 0)
VerifyMetrics(t, "RequestStatuses.AMP.BlacklistedAcctOrApp", goEngine.RequestStatuses[metrics.ReqTypeAMP][metrics.RequestStatusBlacklisted].Count(), 1)
VerifyMetrics(t, "RequestStatuses.AMP.BlockedApp", goEngine.RequestStatuses[metrics.ReqTypeAMP][metrics.RequestStatusBlockedApp].Count(), 1)
VerifyMetrics(t, "RequestStatuses.Video.OK", goEngine.RequestStatuses[metrics.ReqTypeVideo][metrics.RequestStatusOK].Count(), 0)
VerifyMetrics(t, "RequestStatuses.Video.Error", goEngine.RequestStatuses[metrics.ReqTypeVideo][metrics.RequestStatusErr].Count(), 0)
VerifyMetrics(t, "RequestStatuses.Video.BadInput", goEngine.RequestStatuses[metrics.ReqTypeVideo][metrics.RequestStatusBadInput].Count(), 0)
VerifyMetrics(t, "RequestStatuses.Video.BlacklistedAcctOrApp", goEngine.RequestStatuses[metrics.ReqTypeVideo][metrics.RequestStatusBlacklisted].Count(), 1)
VerifyMetrics(t, "RequestStatuses.Video.BlockedApp", goEngine.RequestStatuses[metrics.ReqTypeVideo][metrics.RequestStatusBlockedApp].Count(), 1)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.Error", goEngine.RequestStatuses[metrics.ReqTypeORTB2Web][metrics.RequestStatusErr].Count(), 0)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.BadInput", goEngine.RequestStatuses[metrics.ReqTypeORTB2Web][metrics.RequestStatusBadInput].Count(), 0)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.BlacklistedAcctOrApp", goEngine.RequestStatuses[metrics.ReqTypeORTB2Web][metrics.RequestStatusBlacklisted].Count(), 0)
VerifyMetrics(t, "RequestStatuses.OpenRTB2.BlockedApp", goEngine.RequestStatuses[metrics.ReqTypeORTB2Web][metrics.RequestStatusBlockedApp].Count(), 0)

VerifyMetrics(t, "ImpsTypeBanner", goEngine.ImpsTypeBanner.Count(), 5)
VerifyMetrics(t, "ImpsTypeVideo", goEngine.ImpsTypeVideo.Count(), 3)
Expand Down
4 changes: 2 additions & 2 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const (
RequestStatusBadInput RequestStatus = "badinput"
RequestStatusErr RequestStatus = "err"
RequestStatusNetworkErr RequestStatus = "networkerr"
RequestStatusBlacklisted RequestStatus = "blacklistedacctorapp"
RequestStatusBlockedApp RequestStatus = "blockedapp"
RequestStatusQueueTimeout RequestStatus = "queuetimeout"
RequestStatusAccountConfigErr RequestStatus = "acctconfigerr"
)
Expand All @@ -245,7 +245,7 @@ func RequestStatuses() []RequestStatus {
RequestStatusBadInput,
RequestStatusErr,
RequestStatusNetworkErr,
RequestStatusBlacklisted,
RequestStatusBlockedApp,
RequestStatusQueueTimeout,
RequestStatusAccountConfigErr,
}
Expand Down
6 changes: 3 additions & 3 deletions metrics/prometheus/prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func TestConnectionMetrics(t *testing.T) {
func TestRequestMetric(t *testing.T) {
m := createMetricsForTesting()
requestType := metrics.ReqTypeORTB2Web
requestStatus := metrics.RequestStatusBlacklisted
requestStatus := metrics.RequestStatusBlockedApp

m.RecordRequest(metrics.Labels{
RType: requestType,
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestRequestMetricWithoutCookie(t *testing.T) {
performTest := func(m *Metrics, cookieFlag metrics.CookieFlag) {
m.RecordRequest(metrics.Labels{
RType: requestType,
RequestStatus: metrics.RequestStatusBlacklisted,
RequestStatus: metrics.RequestStatusBlockedApp,
CookieFlag: cookieFlag,
})
}
Expand Down Expand Up @@ -337,7 +337,7 @@ func TestAccountMetric(t *testing.T) {
performTest := func(m *Metrics, pubID string) {
m.RecordRequest(metrics.Labels{
RType: metrics.ReqTypeORTB2Web,
RequestStatus: metrics.RequestStatusBlacklisted,
RequestStatus: metrics.RequestStatusBlockedApp,
PubID: pubID,
})
}
Expand Down
Loading