github.com/prebid/prebid-server/v2@v2.18.0/adapters/limelightDigital/params_test.go (about) 1 package limelightDigital 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 func TestValidParams(t *testing.T) { 11 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 12 if err != nil { 13 t.Fatalf("Failed to fetch the json schema. %v", err) 14 } 15 16 for _, p := range validParams { 17 if err := validator.Validate(openrtb_ext.BidderLimelightDigital, json.RawMessage(p)); err != nil { 18 t.Errorf("Schema rejected valid params: %s", p) 19 } 20 } 21 } 22 23 func TestInvalidParams(t *testing.T) { 24 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 25 if err != nil { 26 t.Fatalf("Failed to fetch the json schema. %v", err) 27 } 28 29 for _, p := range invalidParams { 30 if err := validator.Validate(openrtb_ext.BidderLimelightDigital, json.RawMessage(p)); err == nil { 31 t.Errorf("Schema allowed invalid params: %s", p) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{"host": "example.com", "publisherId": 1}`, 38 `{"host": "example.com", "publisherId": "1"}`, 39 `{"host": "example.com", "publisherId": 42}`, 40 `{"host": "example.com", "publisherId": "42"}`, 41 `{"host": "example.com", "publisherId": "42", "adUnitId": 123, "adUnitType": "banner"}`, 42 } 43 44 var invalidParams = []string{ 45 `null`, 46 `nil`, 47 ``, 48 `[]`, 49 `true`, 50 `{}`, 51 `{"host": "example.com". "publisherId": 1}`, 52 53 `{"host": "example.com"}`, 54 `{"publisherId": 42}`, 55 56 `{"host": "", "publisherId": 42}`, 57 `{"host": 42, "publisherId": 42}`, 58 `{"host": "example.com:42", "publisherId": 42}`, 59 `{"host": "example.com/test", "publisherId": 42}`, 60 `{"host": "example.com:42/test", "publisherId": 42}`, 61 `{"host": "example", "publisherId": 1}`, 62 `{"host": ".example", "publisherId": 1}`, 63 `{"host": ".example.com", "publisherId": 1}`, 64 `{"host": ".test.example.com", "publisherId": 1}`, 65 `{"host": "example.", "publisherId": 1}`, 66 `{"host": "example.com.", "publisherId": 1}`, 67 `{"host": "test.example.com.", "publisherId": 1}`, 68 `{"host": ".example.", "publisherId": 1}`, 69 `{"host": ".example.com.", "publisherId": 1}`, 70 `{"host": ".test.example.com.", "publisherId": 1}`, 71 72 `{"host": "example.com", "publisherId": ""}`, 73 `{"host": "example.com", "publisherId": 0}`, 74 `{"host": "example.com", "publisherId": "0"}`, 75 `{"host": "example.com", "publisherId": -1}`, 76 `{"host": "example.com", "publisherId": "-1"}`, 77 `{"host": "example.com", "publisherId": 01}`, 78 `{"host": "example.com", "publisherId": "01"}`, 79 `{"host": "example.com", "publisherId": -01}`, 80 `{"host": "example.com", "publisherId": "-01"}`, 81 `{"host": "example.com", "publisherId": -42}`, 82 `{"host": "example.com", "publisherId": "-42"}`, 83 }