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