Repository: prebid/prebid-server
Pull request #2388 (2022-09-22 23:31:09)

Load bidders names from file system in lowercase
Bugfix: modified code to load bidder names from the file system in lowercase


Patch:
diff --git a/config/bidderinfo.go b/config/bidderinfo.go
index b4e9e74e..74122bdf 100644
--- a/config/bidderinfo.go
+++ b/config/bidderinfo.go
@@ -197,7 +197,11 @@ func LoadBidderInfo(path string) (BidderInfos, error) {
 
 		bidderName := strings.Split(fileName, ".")
 		if len(bidderName) == 2 && bidderName[1] == "yaml" {
-			infos[(bidderName[0])] = info
+			// all bidder names loaded from the file system should be in lowercase
+			// to match bidder names in Viper config bidder infos
+			// this will prevent from missing bidder config overrides
+			// in func applyBidderInfoConfigOverrides
+			infos[(strings.ToLower(bidderName[0]))] = info
 		}
 	}
 	return infos, nil
diff --git a/exchange/adapter_util.go b/exchange/adapter_util.go
index 81f744cd..729aa742 100644
--- a/exchange/adapter_util.go
+++ b/exchange/adapter_util.go
@@ -30,19 +30,13 @@ func buildBidders(infos config.BidderInfos, builders map[openrtb_ext.BidderName]
 	bidders := make(map[openrtb_ext.BidderName]adapters.Bidder)
 	var errs []error
 
-	for bidder := range infos {
+	for bidder, info := range infos {
 		bidderName, bidderNameFound := openrtb_ext.NormalizeBidderName(bidder)
 		if !bidderNameFound {
 			errs = append(errs, fmt.Errorf("%v: unknown bidder", bidder))
 			continue
 		}
 
-		info, infoFound := infos[string(bidderName)]
-		if !infoFound {
-			errs = append(errs, fmt.Errorf("%v: bidder info not found", bidder))
-			continue
-		}
-
 		builder, builderFound := builders[bidderName]
 		if !builderFound {
 			errs = append(errs, fmt.Errorf("%v: builder not registered", bidder))
@@ -59,7 +53,6 @@ func buildBidders(infos config.BidderInfos, builders map[openrtb_ext.BidderName]
 			bidders[bidderName] = adapters.BuildInfoAwareBidder(bidderInstance, info)
 		}
 	}
-
 	return bidders, errs
 }
 


Test patch:
diff --git a/config/bidderinfo_test.go b/config/bidderinfo_test.go
index ffc73edc..85e15323 100644
--- a/config/bidderinfo_test.go
+++ b/config/bidderinfo_test.go
@@ -36,7 +36,8 @@ endpointCompression: "GZIP"
 `
 
 func TestLoadBidderInfoFromDisk(t *testing.T) {
-	bidder := "someBidder"
+	// should appear in result in lowercase
+	bidder := "somebidder"
 	trueValue := true
 
 	adapterConfigs := make(map[string]Adapter)
diff --git a/exchange/adapter_util_test.go b/exchange/adapter_util_test.go
index fd22e3c5..082f978a 100644
--- a/exchange/adapter_util_test.go
+++ b/exchange/adapter_util_test.go
@@ -64,7 +64,6 @@ func TestBuildAdapters(t *testing.T) {
 			description: "Invalid - Builder Errors",
 			bidderInfos: map[string]config.BidderInfo{"unknown": {}, "appNexus": {}},
 			expectedErrors: []error{
-				errors.New("appNexus: bidder info not found"),
 				errors.New("unknown: unknown bidder"),
 			},
 		},
@@ -101,14 +100,6 @@ func TestBuildBidders(t *testing.T) {
 				errors.New("unknown: unknown bidder"),
 			},
 		},
-		{
-			description: "Invalid - No Bidder Info",
-			bidderInfos: map[string]config.BidderInfo{"appNexus": {}},
-			builders:    map[openrtb_ext.BidderName]adapters.Builder{openrtb_ext.BidderAppnexus: appnexusBuilder},
-			expectedErrors: []error{
-				errors.New("appNexus: bidder info not found"),
-			},
-		},
 		{
 			description: "Invalid - No Builder",
 			bidderInfos: map[string]config.BidderInfo{"appnexus": infoEnabled},
diff --git a/exchange/exchange_test.go b/exchange/exchange_test.go
index bf31a8be..866e4d77 100644
--- a/exchange/exchange_test.go
+++ b/exchange/exchange_test.go
@@ -80,7 +80,7 @@ func TestNewExchange(t *testing.T) {
 	e := NewExchange(adapters, nil, cfg, map[string]usersync.Syncer{}, &metricsConf.NilMetricsEngine{}, biddersInfo, gdprPermsBuilder, tcf2ConfigBuilder, currencyConverter, nilCategoryFetcher{}, &adscert.NilSigner{}).(*exchange)
 	for _, bidderName := range knownAdapters {
 		if _, ok := e.adapterMap[bidderName]; !ok {
-			if biddersInfo[string(bidderName)].IsEnabled() {
+			if biddersInfo[strings.ToLower(string(bidderName))].IsEnabled() {
 				t.Errorf("NewExchange produced an Exchange without bidder %s", bidderName)
 			}
 		}