diff --git a/endpoints/info/bidders.go b/endpoints/info/bidders.go index 7cbad5e26f6..d1a100f8e8f 100644 --- a/endpoints/info/bidders.go +++ b/endpoints/info/bidders.go @@ -15,8 +15,8 @@ var invalidEnabledOnlyMsg = []byte(`Invalid value for 'enabledonly' query param, var invalidBaseAdaptersOnlyMsg = []byte(`Invalid value for 'baseadaptersonly' query param, must be of boolean type`) // NewBiddersEndpoint builds a handler for the /info/bidders endpoint. -func NewBiddersEndpoint(bidders config.BidderInfos, aliases map[string]string) httprouter.Handle { - responseAll, err := prepareBiddersResponseAll(bidders, aliases) +func NewBiddersEndpoint(bidders config.BidderInfos) httprouter.Handle { + responseAll, err := prepareBiddersResponseAll(bidders) if err != nil { glog.Fatalf("error creating /info/bidders endpoint all bidders response: %v", err) } @@ -26,7 +26,7 @@ func NewBiddersEndpoint(bidders config.BidderInfos, aliases map[string]string) h glog.Fatalf("error creating /info/bidders endpoint all bidders (base adapters only) response: %v", err) } - responseEnabledOnly, err := prepareBiddersResponseEnabledOnly(bidders, aliases) + responseEnabledOnly, err := prepareBiddersResponseEnabledOnly(bidders) if err != nil { glog.Fatalf("error creating /info/bidders endpoint enabled only response: %v", err) } @@ -76,7 +76,6 @@ func readQueryFlag(r *http.Request, queryParam string) (flag, ok bool) { q := r.URL.Query() v, exists := q[queryParam] - if !exists || len(v) == 0 { return false, true } @@ -91,26 +90,13 @@ func readQueryFlag(r *http.Request, queryParam string) (flag, ok bool) { } } -func prepareBiddersResponseAll(bidders config.BidderInfos, aliases map[string]string) ([]byte, error) { - bidderNames := make([]string, 0, len(bidders)+len(aliases)) - - for name := range bidders { - bidderNames = append(bidderNames, name) - } - - for name := range aliases { - bidderNames = append(bidderNames, name) - } - - sort.Strings(bidderNames) - return jsonutil.Marshal(bidderNames) -} +type bidderPredicate func(config.BidderInfo) bool -func prepareBiddersResponseAllBaseOnly(bidders config.BidderInfos) ([]byte, error) { +func prepareResponse(bidders config.BidderInfos, p bidderPredicate) ([]byte, error) { bidderNames := make([]string, 0, len(bidders)) for name, info := range bidders { - if len(info.AliasOf) == 0 { + if p(info) { bidderNames = append(bidderNames, name) } } @@ -119,36 +105,24 @@ func prepareBiddersResponseAllBaseOnly(bidders config.BidderInfos) ([]byte, erro return jsonutil.Marshal(bidderNames) } -func prepareBiddersResponseEnabledOnly(bidders config.BidderInfos, aliases map[string]string) ([]byte, error) { - bidderNames := make([]string, 0, len(bidders)+len(aliases)) - - for name, info := range bidders { - if info.IsEnabled() { - bidderNames = append(bidderNames, name) - } - } +func prepareBiddersResponseAll(bidders config.BidderInfos) ([]byte, error) { + filterNone := func(_ config.BidderInfo) bool { return true } + return prepareResponse(bidders, filterNone) +} - for name, bidder := range aliases { - if info, ok := bidders[bidder]; ok && info.IsEnabled() { - bidderNames = append(bidderNames, name) - } - } +func prepareBiddersResponseAllBaseOnly(bidders config.BidderInfos) ([]byte, error) { + filterBaseOnly := func(info config.BidderInfo) bool { return len(info.AliasOf) == 0 } + return prepareResponse(bidders, filterBaseOnly) +} - sort.Strings(bidderNames) - return jsonutil.Marshal(bidderNames) +func prepareBiddersResponseEnabledOnly(bidders config.BidderInfos) ([]byte, error) { + filterEnabledOnly := func(info config.BidderInfo) bool { return info.IsEnabled() } + return prepareResponse(bidders, filterEnabledOnly) } func prepareBiddersResponseEnabledOnlyBaseOnly(bidders config.BidderInfos) ([]byte, error) { - bidderNames := make([]string, 0, len(bidders)) - - for name, info := range bidders { - if info.IsEnabled() && len(info.AliasOf) == 0 { - bidderNames = append(bidderNames, name) - } - } - - sort.Strings(bidderNames) - return jsonutil.Marshal(bidderNames) + filterEnabledOnlyBaseOnly := func(info config.BidderInfo) bool { return info.IsEnabled() && len(info.AliasOf) == 0 } + return prepareResponse(bidders, filterEnabledOnlyBaseOnly) } func writeBadRequest(w http.ResponseWriter, data []byte) { diff --git a/endpoints/info/bidders_detail.go b/endpoints/info/bidders_detail.go index fbc9ab43486..ccdf805cb16 100644 --- a/endpoints/info/bidders_detail.go +++ b/endpoints/info/bidders_detail.go @@ -19,20 +19,21 @@ const ( ) // NewBiddersDetailEndpoint builds a handler for the /info/bidders/ endpoint. -func NewBiddersDetailEndpoint(bidders config.BidderInfos, aliases map[string]string) httprouter.Handle { - responses, err := prepareBiddersDetailResponse(bidders, aliases) +func NewBiddersDetailEndpoint(bidders config.BidderInfos) httprouter.Handle { + responses, err := prepareBiddersDetailResponse(bidders) if err != nil { glog.Fatalf("error creating /info/bidders/ endpoint response: %v", err) } return func(w http.ResponseWriter, _ *http.Request, ps httprouter.Params) { bidder := ps.ByName("bidderName") + bidderName, found := getNormalizedBidderName(bidder) - coreBidderName, found := getNormalisedBidderName(bidder, aliases) if !found { w.WriteHeader(http.StatusNotFound) } - if response, ok := responses[coreBidderName]; ok { + + if response, ok := responses[bidderName]; ok { w.Header().Set("Content-Type", "application/json") if _, err := w.Write(response); err != nil { glog.Errorf("error writing response to /info/bidders/%s: %v", bidder, err) @@ -43,25 +44,21 @@ func NewBiddersDetailEndpoint(bidders config.BidderInfos, aliases map[string]str } } -func getNormalisedBidderName(bidderName string, aliases map[string]string) (string, bool) { +func getNormalizedBidderName(bidderName string) (string, bool) { if strings.ToLower(bidderName) == "all" { return "all", true } - coreBidderName, ok := openrtb_ext.NormalizeBidderName(bidderName) - if !ok { //check default aliases if not found in coreBidders - if _, isDefaultAlias := aliases[bidderName]; isDefaultAlias { - return bidderName, true - } + + bidderNameNormalized, ok := openrtb_ext.NormalizeBidderName(bidderName) + if !ok { return "", false } - return coreBidderName.String(), true + + return bidderNameNormalized.String(), true } -func prepareBiddersDetailResponse(bidders config.BidderInfos, aliases map[string]string) (map[string][]byte, error) { - details, err := mapDetails(bidders, aliases) - if err != nil { - return nil, err - } +func prepareBiddersDetailResponse(bidders config.BidderInfos) (map[string][]byte, error) { + details := mapDetails(bidders) responses, err := marshalDetailsResponse(details) if err != nil { @@ -77,25 +74,14 @@ func prepareBiddersDetailResponse(bidders config.BidderInfos, aliases map[string return responses, nil } -func mapDetails(bidders config.BidderInfos, aliases map[string]string) (map[string]bidderDetail, error) { +func mapDetails(bidders config.BidderInfos) map[string]bidderDetail { details := map[string]bidderDetail{} for bidderName, bidderInfo := range bidders { details[bidderName] = mapDetailFromConfig(bidderInfo) } - for aliasName, bidderName := range aliases { - aliasBaseInfo, aliasBaseInfoFound := details[bidderName] - if !aliasBaseInfoFound { - return nil, fmt.Errorf("base adapter %s for alias %s not found", bidderName, aliasName) - } - - aliasInfo := aliasBaseInfo - aliasInfo.AliasOf = bidderName - details[aliasName] = aliasInfo - } - - return details, nil + return details } func marshalDetailsResponse(details map[string]bidderDetail) (map[string][]byte, error) { @@ -151,6 +137,8 @@ type platform struct { func mapDetailFromConfig(c config.BidderInfo) bidderDetail { var bidderDetail bidderDetail + bidderDetail.AliasOf = c.AliasOf + if c.Maintainer != nil { bidderDetail.Maintainer = &maintainer{ Email: c.Maintainer.Email, diff --git a/endpoints/info/bidders_detail_test.go b/endpoints/info/bidders_detail_test.go index 4965decef40..688b807043b 100644 --- a/endpoints/info/bidders_detail_test.go +++ b/endpoints/info/bidders_detail_test.go @@ -11,6 +11,7 @@ import ( "github.com/julienschmidt/httprouter" "github.com/prebid/prebid-server/v2/config" "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/ptrutil" "github.com/stretchr/testify/assert" ) @@ -34,124 +35,72 @@ func TestPrepareBiddersDetailResponse(t *testing.T) { allResponseBidderAB.WriteString(`}`) var testCases = []struct { - description string + name string givenBidders config.BidderInfos - givenAliases map[string]string expectedResponses map[string][]byte - expectedError string }{ { - description: "None", + name: "none", givenBidders: config.BidderInfos{}, - givenAliases: map[string]string{}, expectedResponses: map[string][]byte{"all": []byte(`{}`)}, }, { - description: "One", + name: "one", givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{}, expectedResponses: map[string][]byte{"a": bidderAResponse, "all": allResponseBidderA.Bytes()}, }, { - description: "Many", + name: "many", givenBidders: config.BidderInfos{"a": bidderAInfo, "b": bidderBInfo}, - givenAliases: map[string]string{}, expectedResponses: map[string][]byte{"a": bidderAResponse, "b": bidderBResponse, "all": allResponseBidderAB.Bytes()}, }, - { - description: "Error - Map Details", // Returns error due to invalid alias. - givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{"zAlias": "z"}, - expectedError: "base adapter z for alias zAlias not found", - }, } for _, test := range testCases { - responses, err := prepareBiddersDetailResponse(test.givenBidders, test.givenAliases) - - if test.expectedError == "" { - assert.Equal(t, test.expectedResponses, responses, test.description+":responses") - assert.NoError(t, err, test.expectedError, test.description+":err") - } else { - assert.Empty(t, responses, test.description+":responses") - assert.EqualError(t, err, test.expectedError, test.description+":err") - } + t.Run(test.name, func(t *testing.T) { + responses, err := prepareBiddersDetailResponse(test.givenBidders) + assert.NoError(t, err) + assert.Equal(t, test.expectedResponses, responses) + }) } } func TestMapDetails(t *testing.T) { - trueValue := true - falseValue := false + var ( + bidderAInfo = config.BidderInfo{Endpoint: "https://secureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderA"}} + bidderADetail = bidderDetail{Status: "ACTIVE", UsesHTTPS: ptrutil.ToPtr(true), Maintainer: &maintainer{Email: "bidderA"}} - bidderAInfo := config.BidderInfo{Endpoint: "https://secureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderA"}} - bidderADetail := bidderDetail{Status: "ACTIVE", UsesHTTPS: &trueValue, Maintainer: &maintainer{Email: "bidderA"}} - aliasADetail := bidderDetail{Status: "ACTIVE", UsesHTTPS: &trueValue, Maintainer: &maintainer{Email: "bidderA"}, AliasOf: "a"} - - bidderBInfo := config.BidderInfo{Endpoint: "http://unsecureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderB"}} - bidderBDetail := bidderDetail{Status: "ACTIVE", UsesHTTPS: &falseValue, Maintainer: &maintainer{Email: "bidderB"}} - aliasBDetail := bidderDetail{Status: "ACTIVE", UsesHTTPS: &falseValue, Maintainer: &maintainer{Email: "bidderB"}, AliasOf: "b"} + bidderBInfo = config.BidderInfo{Endpoint: "http://unsecureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderB"}} + bidderBDetail = bidderDetail{Status: "ACTIVE", UsesHTTPS: ptrutil.ToPtr(false), Maintainer: &maintainer{Email: "bidderB"}} + ) var testCases = []struct { - description string + name string givenBidders config.BidderInfos - givenAliases map[string]string expectedDetails map[string]bidderDetail - expectedError string }{ { - description: "None", + name: "none", givenBidders: config.BidderInfos{}, - givenAliases: map[string]string{}, expectedDetails: map[string]bidderDetail{}, }, { - description: "One Core Bidder", + name: "one", givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{}, expectedDetails: map[string]bidderDetail{"a": bidderADetail}, }, { - description: "Many Core Bidders", + name: "many", givenBidders: config.BidderInfos{"a": bidderAInfo, "b": bidderBInfo}, - givenAliases: map[string]string{}, expectedDetails: map[string]bidderDetail{"a": bidderADetail, "b": bidderBDetail}, }, - { - description: "One Alias", - givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{"aAlias": "a"}, - expectedDetails: map[string]bidderDetail{"a": bidderADetail, "aAlias": aliasADetail}, - }, - { - description: "Many Aliases - Same Core Bidder", - givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{"aAlias1": "a", "aAlias2": "a"}, - expectedDetails: map[string]bidderDetail{"a": bidderADetail, "aAlias1": aliasADetail, "aAlias2": aliasADetail}, - }, - { - description: "Many Aliases - Different Core Bidders", - givenBidders: config.BidderInfos{"a": bidderAInfo, "b": bidderBInfo}, - givenAliases: map[string]string{"aAlias": "a", "bAlias": "b"}, - expectedDetails: map[string]bidderDetail{"a": bidderADetail, "b": bidderBDetail, "aAlias": aliasADetail, "bAlias": aliasBDetail}, - }, - { - description: "Error - Alias Without Core Bidder", - givenBidders: config.BidderInfos{"a": bidderAInfo}, - givenAliases: map[string]string{"zAlias": "z"}, - expectedError: "base adapter z for alias zAlias not found", - }, } for _, test := range testCases { - details, err := mapDetails(test.givenBidders, test.givenAliases) - - if test.expectedError == "" { - assert.Equal(t, test.expectedDetails, details, test.description+":details") - assert.NoError(t, err, test.expectedError, test.description+":err") - } else { - assert.Empty(t, details, test.description+":details") - assert.EqualError(t, err, test.expectedError, test.description+":err") - } + t.Run(test.name, func(t *testing.T) { + details := mapDetails(test.givenBidders) + assert.Equal(t, test.expectedDetails, details) + }) } } @@ -165,32 +114,33 @@ func TestMarshalDetailsResponse(t *testing.T) { bidderDetailBResponse := []byte(`{"status":"ACTIVE","maintainer":{"email":"bidderB"},"capabilities":{"app":{"mediaTypes":["banner"]}}}`) var testCases = []struct { - description string + name string givenDetails map[string]bidderDetail expectedResponse map[string][]byte }{ { - description: "None", + name: "none", givenDetails: map[string]bidderDetail{}, expectedResponse: map[string][]byte{}, }, { - description: "One", + name: "one", givenDetails: map[string]bidderDetail{"a": bidderDetailA}, expectedResponse: map[string][]byte{"a": bidderDetailAResponse}, }, { - description: "Many", + name: "many", givenDetails: map[string]bidderDetail{"a": bidderDetailA, "b": bidderDetailB}, expectedResponse: map[string][]byte{"a": bidderDetailAResponse, "b": bidderDetailBResponse}, }, } for _, test := range testCases { - response, err := marshalDetailsResponse(test.givenDetails) - - assert.NoError(t, err, test.description+":err") - assert.Equal(t, test.expectedResponse, response, test.description+":response") + t.Run(test.name, func(t *testing.T) { + response, err := marshalDetailsResponse(test.givenDetails) + assert.NoError(t, err) + assert.Equal(t, test.expectedResponse, response) + }) } } @@ -211,12 +161,12 @@ func TestMapDetailFromConfig(t *testing.T) { falseValue := false var testCases = []struct { - description string + name string givenBidderInfo config.BidderInfo expected bidderDetail }{ { - description: "Enabled - All Values Present", + name: "enabled-all-values", givenBidderInfo: config.BidderInfo{ Endpoint: "http://anyEndpoint", Disabled: false, @@ -244,7 +194,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Disabled - All Values Present", + name: "disabled-all-values", givenBidderInfo: config.BidderInfo{ Endpoint: "http://anyEndpoint", Disabled: true, @@ -267,7 +217,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Enabled - No Values Present", + name: "enabled-no-values", givenBidderInfo: config.BidderInfo{ Endpoint: "http://amyEndpoint", Disabled: false, @@ -278,7 +228,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Enabled - Protocol - HTTP", + name: "enabled-protocol-http", givenBidderInfo: config.BidderInfo{ Endpoint: "http://amyEndpoint", Disabled: false, @@ -289,7 +239,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Enabled - Protocol - HTTPS", + name: "enabled-protocol-https", givenBidderInfo: config.BidderInfo{ Endpoint: "https://amyEndpoint", Disabled: false, @@ -300,7 +250,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Enabled - Protocol - HTTPS - Case Insensitive", + name: "enabled-protocol-https-case-insensitive", givenBidderInfo: config.BidderInfo{ Disabled: false, Endpoint: "https://amyEndpoint", @@ -311,7 +261,7 @@ func TestMapDetailFromConfig(t *testing.T) { }, }, { - description: "Enabled - Protocol - Unknown", + name: "enabled-protocol-unknown", givenBidderInfo: config.BidderInfo{ Endpoint: "endpointWithoutProtocol", Disabled: false, @@ -324,125 +274,132 @@ func TestMapDetailFromConfig(t *testing.T) { } for _, test := range testCases { - result := mapDetailFromConfig(test.givenBidderInfo) - assert.Equal(t, test.expected, result, test.description) + t.Run(test.name, func(t *testing.T) { + result := mapDetailFromConfig(test.givenBidderInfo) + assert.Equal(t, test.expected, result) + }) } } func TestMapMediaTypes(t *testing.T) { var testCases = []struct { - description string - mediaTypes []openrtb_ext.BidType - expected []string + name string + mediaTypes []openrtb_ext.BidType + expected []string }{ { - description: "Nil", - mediaTypes: nil, - expected: nil, + name: "nil", + mediaTypes: nil, + expected: nil, }, { - description: "None", - mediaTypes: []openrtb_ext.BidType{}, - expected: []string{}, + name: "none", + mediaTypes: []openrtb_ext.BidType{}, + expected: []string{}, }, { - description: "One", - mediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner}, - expected: []string{"banner"}, + name: "one", + mediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner}, + expected: []string{"banner"}, }, { - description: "Many", - mediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner, openrtb_ext.BidTypeVideo}, - expected: []string{"banner", "video"}, + name: "many", + mediaTypes: []openrtb_ext.BidType{openrtb_ext.BidTypeBanner, openrtb_ext.BidTypeVideo}, + expected: []string{"banner", "video"}, }, } for _, test := range testCases { - result := mapMediaTypes(test.mediaTypes) - assert.ElementsMatch(t, test.expected, result, test.description) + t.Run(test.name, func(t *testing.T) { + result := mapMediaTypes(test.mediaTypes) + assert.ElementsMatch(t, test.expected, result) + }) } } func TestBiddersDetailHandler(t *testing.T) { bidderAInfo := config.BidderInfo{Endpoint: "https://secureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderA"}} bidderAResponse := []byte(`{"status":"ACTIVE","usesHttps":true,"maintainer":{"email":"bidderA"}}`) - aliasAResponse := []byte(`{"status":"ACTIVE","usesHttps":true,"maintainer":{"email":"bidderA"},"aliasOf":"appnexus"}`) bidderBInfo := config.BidderInfo{Endpoint: "http://unsecureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "bidderB"}} bidderBResponse := []byte(`{"status":"ACTIVE","usesHttps":false,"maintainer":{"email":"bidderB"}}`) + aliasInfo := config.BidderInfo{AliasOf: "appnexus", Endpoint: "https://secureEndpoint.com", Disabled: false, Maintainer: &config.MaintainerInfo{Email: "alias"}} + aliasResponse := []byte(`{"status":"ACTIVE","usesHttps":true,"maintainer":{"email":"alias"},"aliasOf":"appnexus"}`) + allResponse := bytes.Buffer{} allResponse.WriteString(`{"aAlias":`) - allResponse.Write(aliasAResponse) + allResponse.Write(aliasResponse) allResponse.WriteString(`,"appnexus":`) allResponse.Write(bidderAResponse) allResponse.WriteString(`,"rubicon":`) allResponse.Write(bidderBResponse) allResponse.WriteString(`}`) - bidders := config.BidderInfos{"appnexus": bidderAInfo, "rubicon": bidderBInfo} - aliases := map[string]string{"aAlias": "appnexus"} + bidders := config.BidderInfos{"aAlias": aliasInfo, "appnexus": bidderAInfo, "rubicon": bidderBInfo} + + handler := NewBiddersDetailEndpoint(bidders) - handler := NewBiddersDetailEndpoint(bidders, aliases) + openrtb_ext.SetAliasBidderName("aAlias", "appnexus") var testCases = []struct { - description string + name string givenBidder string expectedStatus int expectedHeaders http.Header expectedResponse []byte }{ { - description: "Bidder A", + name: "bidder-a", givenBidder: "appnexus", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, expectedResponse: bidderAResponse, }, { - description: "Bidder B", + name: "bidder-b", givenBidder: "rubicon", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, expectedResponse: bidderBResponse, }, { - description: "Bidder B - case insensitive", + name: "bidder-b-case-insensitive", givenBidder: "RUBICON", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, expectedResponse: bidderBResponse, }, { - description: "Bidder A Alias", + name: "bidder-a-alias", givenBidder: "aAlias", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, - expectedResponse: aliasAResponse, + expectedResponse: aliasResponse, }, { - description: "Bidder A Alias - case insensitive", + name: "bidder-a-alias-case-insensitive", givenBidder: "aAlias", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, - expectedResponse: aliasAResponse, + expectedResponse: aliasResponse, }, { - description: "All Bidders", + name: "all-bidders", givenBidder: "all", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, expectedResponse: allResponse.Bytes(), }, { - description: "All Bidders - Case insensitive", + name: "all-bidders-case-insensitive", givenBidder: "All", expectedStatus: http.StatusOK, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, expectedResponse: allResponse.Bytes(), }, { - description: "Invalid Bidder", + name: "invalid", givenBidder: "doesntExist", expectedStatus: http.StatusNotFound, expectedHeaders: http.Header{}, @@ -451,7 +408,7 @@ func TestBiddersDetailHandler(t *testing.T) { } for _, test := range testCases { - t.Run(test.description, func(t *testing.T) { + t.Run(test.name, func(t *testing.T) { responseRecorder := httptest.NewRecorder() handler(responseRecorder, nil, httprouter.Params{{ Key: "bidderName", @@ -459,14 +416,14 @@ func TestBiddersDetailHandler(t *testing.T) { }}) result := responseRecorder.Result() - assert.Equal(t, result.StatusCode, test.expectedStatus, test.description+":statuscode") + assert.Equal(t, test.expectedStatus, result.StatusCode, "statuscode") resultBody, _ := io.ReadAll(result.Body) fmt.Println(string(test.expectedResponse)) - assert.Equal(t, test.expectedResponse, resultBody, test.description+":body") + assert.Equal(t, test.expectedResponse, resultBody, "body") resultHeaders := result.Header - assert.Equal(t, test.expectedHeaders, resultHeaders, test.description+":headers") + assert.Equal(t, test.expectedHeaders, resultHeaders, "headers") }) } } diff --git a/endpoints/info/bidders_test.go b/endpoints/info/bidders_test.go index 189eb865551..6183c969a67 100644 --- a/endpoints/info/bidders_test.go +++ b/endpoints/info/bidders_test.go @@ -19,88 +19,65 @@ func TestPrepareBiddersResponseAll(t *testing.T) { ) testCases := []struct { - name string - givenBidders config.BidderInfos - givenRequestAliases map[string]string - expected string + name string + givenBidders config.BidderInfos + expected string }{ { - name: "none", - givenBidders: config.BidderInfos{}, - givenRequestAliases: nil, - expected: `[]`, - }, - { - name: "core-one-enabled", - givenBidders: config.BidderInfos{"a": enabledCore}, - givenRequestAliases: nil, - expected: `["a"]`, - }, - { - name: "core-one-disabled", - givenBidders: config.BidderInfos{"a": disabledCore}, - givenRequestAliases: nil, - expected: `["a"]`, + name: "none", + givenBidders: config.BidderInfos{}, + expected: `[]`, }, { - name: "core-one-mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, - givenRequestAliases: nil, - expected: `["a","b"]`, + name: "core-one-enabled", + givenBidders: config.BidderInfos{"a": enabledCore}, + expected: `["a"]`, }, { - name: "core-one-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, - givenRequestAliases: nil, - expected: `["a","z"]`, + name: "core-one-disabled", + givenBidders: config.BidderInfos{"a": disabledCore}, + expected: `["a"]`, }, { - name: "alias-one", - givenBidders: config.BidderInfos{"a": enabledAlias}, - givenRequestAliases: nil, - expected: `["a"]`, + name: "core-many-mixed", + givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, + expected: `["a","b"]`, }, { - name: "alias-mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, - givenRequestAliases: nil, - expected: `["a","b","c","d"]`, + name: "core-many-sorted", + givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, + expected: `["a","z"]`, }, { - name: "alias-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledAlias, "a": enabledCore}, - givenRequestAliases: nil, - expected: `["a","z"]`, + name: "alias-one-enabled", + givenBidders: config.BidderInfos{"a": enabledAlias}, + expected: `["a"]`, }, { - name: "defaultrequest-one", - givenBidders: config.BidderInfos{"a": enabledCore}, - givenRequestAliases: map[string]string{"b": "a"}, - expected: `["a","b"]`, + name: "alias-one-disabled", + givenBidders: config.BidderInfos{"a": disabledAlias}, + expected: `["a"]`, }, { - name: "defaultrequest-mixed", - givenBidders: config.BidderInfos{"a": enabledCore, "b": disabledCore}, - givenRequestAliases: map[string]string{"x": "a", "y": "b"}, - expected: `["a","b","x","y"]`, + name: "alias-many-mixed", + givenBidders: config.BidderInfos{"a": enabledAlias, "b": disabledAlias}, + expected: `["a","b"]`, }, { - name: "defaultrequest-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledCore}, - givenRequestAliases: map[string]string{"a": "z"}, - expected: `["a","z"]`, + name: "alias-many-sorted", + givenBidders: config.BidderInfos{"z": enabledAlias, "a": enabledCore}, + expected: `["a","z"]`, }, { - name: "mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, - givenRequestAliases: map[string]string{"z": "a"}, - expected: `["a","b","c","d","z"]`, + name: "mixed", + givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, + expected: `["a","b","c","d"]`, }, } for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - result, err := prepareBiddersResponseAll(test.givenBidders, test.givenRequestAliases) + result, err := prepareBiddersResponseAll(test.givenBidders) assert.NoError(t, err) assert.Equal(t, []byte(test.expected), result) }) @@ -136,22 +113,32 @@ func TestPrepareBiddersResponseAllBaseOnly(t *testing.T) { expected: `["a"]`, }, { - name: "core-one-mixed", + name: "core-many-mixed", givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, expected: `["a","b"]`, }, { - name: "core-one-mixed-sorted", + name: "core-many-sorted", givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, expected: `["a","z"]`, }, { - name: "alias-one", + name: "alias-one-enabled", givenBidders: config.BidderInfos{"a": enabledAlias}, expected: `[]`, }, { - name: "alias-mixed", + name: "alias-one-disabled", + givenBidders: config.BidderInfos{"a": disabledAlias}, + expected: `[]`, + }, + { + name: "alias-many", + givenBidders: config.BidderInfos{"a": enabledAlias, "b": enabledAlias}, + expected: `[]`, + }, + { + name: "mixed", givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, expected: `["a","c"]`, }, @@ -175,88 +162,65 @@ func TestPrepareBiddersResponseEnabledOnly(t *testing.T) { ) testCases := []struct { - name string - givenBidders config.BidderInfos - givenRequestAliases map[string]string - expected string + name string + givenBidders config.BidderInfos + expected string }{ { - name: "none", - givenBidders: config.BidderInfos{}, - givenRequestAliases: nil, - expected: `[]`, - }, - { - name: "core-one-enabled", - givenBidders: config.BidderInfos{"a": enabledCore}, - givenRequestAliases: nil, - expected: `["a"]`, - }, - { - name: "core-one-disabled", - givenBidders: config.BidderInfos{"a": disabledCore}, - givenRequestAliases: nil, - expected: `[]`, + name: "none", + givenBidders: config.BidderInfos{}, + expected: `[]`, }, { - name: "core-one-mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, - givenRequestAliases: nil, - expected: `["b"]`, + name: "core-one-enabled", + givenBidders: config.BidderInfos{"a": enabledCore}, + expected: `["a"]`, }, { - name: "core-one-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, - givenRequestAliases: nil, - expected: `["a","z"]`, + name: "core-one-disabled", + givenBidders: config.BidderInfos{"a": disabledCore}, + expected: `[]`, }, { - name: "alias-one", - givenBidders: config.BidderInfos{"a": enabledAlias}, - givenRequestAliases: nil, - expected: `["a"]`, + name: "core-many-mixed", + givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, + expected: `["b"]`, }, { - name: "alias-mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, - givenRequestAliases: nil, - expected: `["c","d"]`, + name: "core-many-sorted", + givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, + expected: `["a","z"]`, }, { - name: "alias-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledAlias, "a": enabledCore}, - givenRequestAliases: nil, - expected: `["a","z"]`, + name: "alias-one-enabled", + givenBidders: config.BidderInfos{"a": enabledAlias}, + expected: `["a"]`, }, { - name: "defaultrequest-one", - givenBidders: config.BidderInfos{"a": enabledCore}, - givenRequestAliases: map[string]string{"b": "a"}, - expected: `["a","b"]`, + name: "alias-one-disabled", + givenBidders: config.BidderInfos{"a": disabledAlias}, + expected: `[]`, }, { - name: "defaultrequest-mixed", - givenBidders: config.BidderInfos{"a": enabledCore, "b": disabledCore}, - givenRequestAliases: map[string]string{"x": "a", "y": "b"}, - expected: `["a","x"]`, + name: "alias-many-mixed", + givenBidders: config.BidderInfos{"a": enabledAlias, "b": disabledAlias}, + expected: `["a"]`, }, { - name: "defaultrequest-mixed-sorted", - givenBidders: config.BidderInfos{"z": enabledCore}, - givenRequestAliases: map[string]string{"a": "z"}, - expected: `["a","z"]`, + name: "alias-many-sorted", + givenBidders: config.BidderInfos{"z": enabledAlias, "a": enabledCore}, + expected: `["a","z"]`, }, { - name: "mixed", - givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, - givenRequestAliases: map[string]string{"z": "a"}, - expected: `["c","d"]`, + name: "mixed", + givenBidders: config.BidderInfos{"a": disabledCore, "b": disabledAlias, "c": enabledCore, "d": enabledAlias}, + expected: `["c","d"]`, }, } for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - result, err := prepareBiddersResponseEnabledOnly(test.givenBidders, test.givenRequestAliases) + result, err := prepareBiddersResponseEnabledOnly(test.givenBidders) assert.NoError(t, err) assert.Equal(t, []byte(test.expected), result) }) @@ -292,17 +256,27 @@ func TestPrepareBiddersResponseEnabledOnlyBaseOnly(t *testing.T) { expected: `[]`, }, { - name: "core-one-mixed", + name: "core-many", + givenBidders: config.BidderInfos{"a": enabledCore, "b": enabledCore}, + expected: `["a","b"]`, + }, + { + name: "core-many-mixed", givenBidders: config.BidderInfos{"a": disabledCore, "b": enabledCore}, expected: `["b"]`, }, { - name: "core-one-mixed-sorted", + name: "core-many-sorted", givenBidders: config.BidderInfos{"z": enabledCore, "a": enabledCore}, expected: `["a","z"]`, }, { - name: "alias-one", + name: "alias-one-enabled", + givenBidders: config.BidderInfos{"a": enabledAlias}, + expected: `[]`, + }, + { + name: "alias-one-disabled", givenBidders: config.BidderInfos{"a": enabledAlias}, expected: `[]`, }, @@ -336,7 +310,6 @@ func TestBiddersHandler(t *testing.T) { ) bidders := config.BidderInfos{"a": enabledCore, "b": enabledAlias, "c": disabledCore, "d": disabledAlias} - aliases := map[string]string{"x": "a", "y": "c"} testCases := []struct { name string @@ -349,35 +322,35 @@ func TestBiddersHandler(t *testing.T) { name: "simple", givenURL: "/info/bidders", expectedStatus: http.StatusOK, - expectedBody: `["a","b","c","d","x","y"]`, + expectedBody: `["a","b","c","d"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { name: "enabledonly-false", givenURL: "/info/bidders?enabledonly=false", expectedStatus: http.StatusOK, - expectedBody: `["a","b","c","d","x","y"]`, + expectedBody: `["a","b","c","d"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { name: "enabledonly-false-caseinsensitive", givenURL: "/info/bidders?enabledonly=fAlSe", expectedStatus: http.StatusOK, - expectedBody: `["a","b","c","d","x","y"]`, + expectedBody: `["a","b","c","d"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { name: "enabledonly-true", givenURL: "/info/bidders?enabledonly=true", expectedStatus: http.StatusOK, - expectedBody: `["a","b","x"]`, + expectedBody: `["a","b"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { name: "enabledonly-true-caseinsensitive", givenURL: "/info/bidders?enabledonly=TrUe", expectedStatus: http.StatusOK, - expectedBody: `["a","b","x"]`, + expectedBody: `["a","b"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { @@ -398,14 +371,14 @@ func TestBiddersHandler(t *testing.T) { name: "baseonly-false", givenURL: "/info/bidders?baseadaptersonly=false", expectedStatus: http.StatusOK, - expectedBody: `["a","b","c","d","x","y"]`, + expectedBody: `["a","b","c","d"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { name: "baseonly-false-caseinsensitive", givenURL: "/info/bidders?baseadaptersonly=fAlSe", expectedStatus: http.StatusOK, - expectedBody: `["a","b","c","d","x","y"]`, + expectedBody: `["a","b","c","d"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { @@ -440,7 +413,7 @@ func TestBiddersHandler(t *testing.T) { name: "enabledonly-true-baseonly-false", givenURL: "/info/bidders?enabledonly=true&baseadaptersonly=false", expectedStatus: http.StatusOK, - expectedBody: `["a","b","x"]`, + expectedBody: `["a","b"]`, expectedHeaders: http.Header{"Content-Type": []string{"application/json"}}, }, { @@ -461,7 +434,7 @@ func TestBiddersHandler(t *testing.T) { for _, test := range testCases { t.Run(test.name, func(t *testing.T) { - handler := NewBiddersEndpoint(bidders, aliases) + handler := NewBiddersEndpoint(bidders) request := httptest.NewRequest("GET", test.givenURL, nil) diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index 2ef86f13252..0071f82bcb1 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -1670,9 +1670,9 @@ func (deps *endpointDeps) processStoredRequests(requestJson []byte, impInfo []Im } } - // Apply default aliases, if they are provided + // apply default stored request if deps.defaultRequest { - aliasedRequest, err := jsonpatch.MergePatch(deps.defReqJSON, resolvedRequest) + merged, err := jsonpatch.MergePatch(deps.defReqJSON, resolvedRequest) if err != nil { hasErr, Err := getJsonSyntaxError(resolvedRequest) if hasErr { @@ -1685,7 +1685,7 @@ func (deps *endpointDeps) processStoredRequests(requestJson []byte, impInfo []Im } return nil, nil, []error{err} } - resolvedRequest = aliasedRequest + resolvedRequest = merged } // Apply any Stored Imps, if they exist. Since the JSON Merge Patch overrides arrays, diff --git a/router/router.go b/router/router.go index 867c856b06c..85603a3e87b 100644 --- a/router/router.go +++ b/router/router.go @@ -10,6 +10,7 @@ import ( "strings" "time" + openrtb2model "github.com/prebid/openrtb/v20/openrtb2" analyticsBuild "github.com/prebid/prebid-server/v2/analytics/build" "github.com/prebid/prebid-server/v2/config" "github.com/prebid/prebid-server/v2/currency" @@ -57,11 +58,11 @@ import ( // // This function stores the file contents in memory, and should not be used on large directories. // If the root directory, or any of the files in it, cannot be read, then the program will exit. -func NewJsonDirectoryServer(schemaDirectory string, validator openrtb_ext.BidderParamValidator, aliases map[string]string) httprouter.Handle { - return newJsonDirectoryServer(schemaDirectory, validator, aliases, openrtb_ext.GetAliasBidderToParent()) +func NewJsonDirectoryServer(schemaDirectory string, validator openrtb_ext.BidderParamValidator) httprouter.Handle { + return newJsonDirectoryServer(schemaDirectory, validator, openrtb_ext.GetAliasBidderToParent()) } -func newJsonDirectoryServer(schemaDirectory string, validator openrtb_ext.BidderParamValidator, aliases map[string]string, yamlAliases map[openrtb_ext.BidderName]openrtb_ext.BidderName) httprouter.Handle { +func newJsonDirectoryServer(schemaDirectory string, validator openrtb_ext.BidderParamValidator, aliases map[openrtb_ext.BidderName]openrtb_ext.BidderName) httprouter.Handle { // Slurp the files into memory first, since they're small and it minimizes request latency. files, err := os.ReadDir(schemaDirectory) if err != nil { @@ -81,19 +82,10 @@ func newJsonDirectoryServer(schemaDirectory string, validator openrtb_ext.Bidder } // Add in any aliases - for aliasName, parentBidder := range yamlAliases { + for aliasName, parentBidder := range aliases { data[string(aliasName)] = json.RawMessage(validator.Schema(parentBidder)) } - // Add in any default aliases - for aliasName, bidderName := range aliases { - bidderData, ok := data[bidderName] - if !ok { - glog.Fatalf("Default alias (%s) exists referencing unknown bidder: %s", aliasName, bidderName) - } - data[aliasName] = bidderData - } - response, err := jsonutil.Marshal(data) if err != nil { glog.Fatalf("Failed to marshal bidder param JSON-schema: %v", err) @@ -216,10 +208,7 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R activeBidders := exchange.GetActiveBidders(cfg.BidderInfos) disabledBidders := exchange.GetDisabledBidderWarningMessages(cfg.BidderInfos) - defaultAliases, defReqJSON := readDefaultRequest(cfg.DefReqConfig) - if err := validateDefaultAliases(defaultAliases); err != nil { - return nil, err - } + defReqJSON := readDefaultRequest(cfg.DefReqConfig) gvlVendorIDs := cfg.BidderInfos.ToGVLVendorIDMap() vendorListFetcher := gdpr.NewVendorListFetcher(context.Background(), cfg.GDPR, generalHttpClient, gdpr.VendorListURLMaker) @@ -269,9 +258,9 @@ func New(cfg *config.Configuration, rateConvertor *currency.RateConverter) (r *R r.POST("/openrtb2/auction", openrtbEndpoint) r.POST("/openrtb2/video", videoEndpoint) r.GET("/openrtb2/amp", ampEndpoint) - r.GET("/info/bidders", infoEndpoints.NewBiddersEndpoint(cfg.BidderInfos, defaultAliases)) - r.GET("/info/bidders/:bidderName", infoEndpoints.NewBiddersDetailEndpoint(cfg.BidderInfos, defaultAliases)) - r.GET("/bidders/params", NewJsonDirectoryServer(schemaDirectory, paramsValidator, defaultAliases)) + r.GET("/info/bidders", infoEndpoints.NewBiddersEndpoint(cfg.BidderInfos)) + r.GET("/info/bidders/:bidderName", infoEndpoints.NewBiddersDetailEndpoint(cfg.BidderInfos)) + r.GET("/bidders/params", NewJsonDirectoryServer(schemaDirectory, paramsValidator)) r.POST("/cookie_sync", endpoints.NewCookieSyncEndpoint(syncersByBidder, cfg, gdprPermsBuilder, tcf2CfgBuilder, r.MetricsEngine, analyticsRunner, accounts, activeBidders).Handle) r.GET("/status", endpoints.NewStatusEndpoint(cfg.StatusResponse)) r.GET("/", serveIndex) @@ -362,56 +351,31 @@ func SupportCORS(handler http.Handler) http.Handler { return c.Handler(handler) } -type defReq struct { - Ext defExt `json:"ext"` -} -type defExt struct { - Prebid defaultAliases `json:"prebid"` -} -type defaultAliases struct { - Aliases map[string]string `json:"aliases"` -} - -func readDefaultRequest(defReqConfig config.DefReqConfig) (map[string]string, []byte) { - defReq := &defReq{} - aliases := make(map[string]string) - if defReqConfig.Type == "file" { - if len(defReqConfig.FileSystem.FileName) == 0 { - return aliases, []byte{} - } - defReqJSON, err := os.ReadFile(defReqConfig.FileSystem.FileName) - if err != nil { - glog.Fatalf("error reading aliases from file %s: %v", defReqConfig.FileSystem.FileName, err) - return aliases, []byte{} - } - - if err := jsonutil.UnmarshalValid(defReqJSON, defReq); err != nil { - // we might not have aliases defined, but will at least show that the JSON file is parsable. - glog.Fatalf("error parsing alias json in file %s: %v", defReqConfig.FileSystem.FileName, err) - return aliases, []byte{} - } - - // Read in the alias map if we want to populate the info endpoints with aliases. - if defReqConfig.AliasInfo { - aliases = defReq.Ext.Prebid.Aliases - } - return aliases, defReqJSON +func readDefaultRequest(defReqConfig config.DefReqConfig) []byte { + switch defReqConfig.Type { + case "file": + return readDefaultRequestFromFile(defReqConfig) + default: + return []byte{} } - return aliases, []byte{} } -func validateDefaultAliases(aliases map[string]string) error { - var errs []error +func readDefaultRequestFromFile(defReqConfig config.DefReqConfig) []byte { + if len(defReqConfig.FileSystem.FileName) == 0 { + return []byte{} + } - for alias := range aliases { - if openrtb_ext.IsBidderNameReserved(alias) { - errs = append(errs, fmt.Errorf("alias %s is a reserved bidder name and cannot be used", alias)) - } + defaultRequestJSON, err := os.ReadFile(defReqConfig.FileSystem.FileName) + if err != nil { + glog.Fatalf("error reading default request from file %s: %v", defReqConfig.FileSystem.FileName, err) + return []byte{} } - if len(errs) > 0 { - return errortypes.NewAggregateError("default request alias errors", errs) + // validate json is valid + if err := jsonutil.UnmarshalValid(defaultRequestJSON, &openrtb2model.BidRequest{}); err != nil { + glog.Fatalf("error parsing default request from file %s: %v", defReqConfig.FileSystem.FileName, err) + return []byte{} } - return nil + return defaultRequestJSON } diff --git a/router/router_test.go b/router/router_test.go index 866a8440f3f..6df782dcb11 100644 --- a/router/router_test.go +++ b/router/router_test.go @@ -44,9 +44,8 @@ func ensureHasKey(t *testing.T, data map[string]json.RawMessage, key string) { } func TestNewJsonDirectoryServer(t *testing.T) { - defaultAlias := map[string]string{"aliastest": "appnexus"} - yamlAlias := map[openrtb_ext.BidderName]openrtb_ext.BidderName{openrtb_ext.BidderName("alias"): openrtb_ext.BidderName("parentAlias")} - handler := newJsonDirectoryServer("../static/bidder-params", &testValidator{}, defaultAlias, yamlAlias) + alias := map[openrtb_ext.BidderName]openrtb_ext.BidderName{openrtb_ext.BidderName("alias"): openrtb_ext.BidderName("parentAlias")} + handler := newJsonDirectoryServer("../static/bidder-params", &testValidator{}, alias) recorder := httptest.NewRecorder() request, _ := http.NewRequest("GET", "/whatever", nil) handler(recorder, request, nil) @@ -66,7 +65,6 @@ func TestNewJsonDirectoryServer(t *testing.T) { } } - ensureHasKey(t, data, "aliastest") ensureHasKey(t, data, "alias") } @@ -211,77 +209,6 @@ func TestNoCache(t *testing.T) { } } -var testDefReqConfig = config.DefReqConfig{ - Type: "file", - FileSystem: config.DefReqFiles{ - FileName: "test_aliases.json", - }, - AliasInfo: true, -} - -func TestLoadDefaultAliases(t *testing.T) { - defAliases, aliasJSON := readDefaultRequest(testDefReqConfig) - expectedJSON := []byte(`{"ext":{"prebid":{"aliases": {"test1": "appnexus", "test2": "rubicon", "test3": "openx"}}}}`) - expectedAliases := map[string]string{ - "test1": "appnexus", - "test2": "rubicon", - "test3": "openx", - } - - assert.JSONEq(t, string(expectedJSON), string(aliasJSON)) - assert.Equal(t, expectedAliases, defAliases) -} - -func TestLoadDefaultAliasesNoInfo(t *testing.T) { - noInfoConfig := testDefReqConfig - noInfoConfig.AliasInfo = false - defAliases, aliasJSON := readDefaultRequest(noInfoConfig) - expectedJSON := []byte(`{"ext":{"prebid":{"aliases": {"test1": "appnexus", "test2": "rubicon", "test3": "openx"}}}}`) - expectedAliases := map[string]string{} - - assert.JSONEq(t, string(expectedJSON), string(aliasJSON)) - assert.Equal(t, expectedAliases, defAliases) -} - -func TestValidateDefaultAliases(t *testing.T) { - var testCases = []struct { - description string - givenAliases map[string]string - expectedError string - }{ - { - description: "None", - givenAliases: map[string]string{}, - expectedError: "", - }, - { - description: "Valid", - givenAliases: map[string]string{"aAlias": "a"}, - expectedError: "", - }, - { - description: "Invalid", - givenAliases: map[string]string{"all": "a"}, - expectedError: "default request alias errors (1 error):\n 1: alias all is a reserved bidder name and cannot be used\n", - }, - { - description: "Mixed", - givenAliases: map[string]string{"aAlias": "a", "all": "a"}, - expectedError: "default request alias errors (1 error):\n 1: alias all is a reserved bidder name and cannot be used\n", - }, - } - - for _, test := range testCases { - err := validateDefaultAliases(test.givenAliases) - - if test.expectedError == "" { - assert.NoError(t, err, test.description) - } else { - assert.EqualError(t, err, test.expectedError, test.description) - } - } -} - func TestBidderParamsCompactedOutput(t *testing.T) { expectedFormattedResponse := `{"appnexus":{"$schema":"http://json-schema.org/draft-04/schema#","title":"Sample schema","description":"A sample schema to test the bidder/params endpoint","type":"object","properties":{"integer_param":{"type":"integer","minimum":1,"description":"A customer id"},"string_param_1":{"type":"string","minLength":1,"description":"Text with blanks in between"},"string_param_2":{"type":"string","minLength":1,"description":"Text_with_no_blanks_in_between"}},"required":["integer_param","string_param_2"]}}` @@ -290,7 +217,7 @@ func TestBidderParamsCompactedOutput(t *testing.T) { paramsValidator, err := openrtb_ext.NewBidderParamsValidator(inSchemaDirectory) assert.NoError(t, err, "Error initialing validator") - handler := newJsonDirectoryServer(inSchemaDirectory, paramsValidator, nil, nil) + handler := newJsonDirectoryServer(inSchemaDirectory, paramsValidator, nil) recorder := httptest.NewRecorder() request, err := http.NewRequest("GET", "/bidder/params", nil) assert.NoError(t, err, "Error creating request") diff --git a/router/test_aliases.json b/router/test_aliases.json deleted file mode 100644 index e1be6455664..00000000000 --- a/router/test_aliases.json +++ /dev/null @@ -1,12 +0,0 @@ - -{ - "ext": { - "prebid": { - "aliases": { - "test1": "appnexus", - "test2": "rubicon", - "test3": "openx" - } - } - } -} \ No newline at end of file