github.com/prebid/prebid-server/v2@v2.18.0/adapters/openx/params_test.go (about) 1 package openx 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // This file actually intends to test static/bidder-params/openx.json 11 // 12 // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.openx 13 14 // TestValidParams makes sure that the openx schema accepts all imp.ext fields which we intend to support. 15 func TestValidParams(t *testing.T) { 16 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 17 if err != nil { 18 t.Fatalf("Failed to fetch the json-schemas. %v", err) 19 } 20 21 for _, validParam := range validParams { 22 if err := validator.Validate(openrtb_ext.BidderOpenx, json.RawMessage(validParam)); err != nil { 23 t.Errorf("Schema rejected openx params: %s", validParam) 24 } 25 } 26 } 27 28 // TestInvalidParams makes sure that the openx schema rejects all the imp.ext fields we don't support. 29 func TestInvalidParams(t *testing.T) { 30 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 31 if err != nil { 32 t.Fatalf("Failed to fetch the json-schemas. %v", err) 33 } 34 35 for _, invalidParam := range invalidParams { 36 if err := validator.Validate(openrtb_ext.BidderOpenx, json.RawMessage(invalidParam)); err == nil { 37 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 38 } 39 } 40 } 41 42 var validParams = []string{ 43 `{"unit": "123", "delDomain": "foo.ba"}`, 44 `{"unit": "123", "delDomain": "foo.bar"}`, 45 `{"unit": "123", "delDomain": "foo.bar", "customFloor": 0.1}`, 46 `{"unit": "123", "delDomain": "foo.bar", "customParams": {"foo": "bar"}}`, 47 `{"unit": "123", "delDomain": "foo.bar", "customParams": {"foo": ["bar", "baz"]}}`, 48 } 49 50 var invalidParams = []string{ 51 `{"unit": "123"}`, 52 `{"delDomain": "foo.bar"}`, 53 `{"unit": "", "delDomain": "foo.bar"}`, 54 `{"unit": "123", "delDomain": ""}`, 55 `{"unit": "123a", "delDomain": "foo.bar"}`, 56 `{"unit": "123", "delDomain": "foo.b"}`, 57 `{"unit": "123", "delDomain": "foo.barr"}`, 58 `{"unit": "123", "delDomain": ".bar"}`, 59 `{"unit": "123", "delDomain": "foo.bar", "customFloor": "0.1"}`, 60 `{"unit": "123", "delDomain": "foo.bar", "customFloor": -0.1}`, 61 `{"unit": "123", "delDomain": "foo.bar", "customParams": "foo: bar"}`, 62 }