Skip to content

Commit

Permalink
IX: update required site id field to be more flexible (#1934)
Browse files Browse the repository at this point in the history
Co-authored-by: Joshua Gross <joshua.gross@indexexchange.com>
  • Loading branch information
grossjo and Joshua Gross authored Jul 29, 2021
1 parent 88589d5 commit bab487e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
59 changes: 59 additions & 0 deletions adapters/ix/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ix

import (
"encoding/json"
"testing"

"github.com/prebid/prebid-server/openrtb_ext"
)

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.BidderIx, json.RawMessage(validParam)); err != nil {
t.Errorf("Schema rejected ix params: %s", validParam)
}
}
}

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.BidderIx, json.RawMessage(invalidParam)); err == nil {
t.Errorf("Schema allowed unexpected params: %s", invalidParam)
}
}
}

var validParams = []string{
`{"siteid":"1234"}`,
`{"siteID":"12345"}`,
`{"siteId":"123456"}`,
`{"siteid":"1234567", "size": [640,480]}`,
}

var invalidParams = []string{
`{"siteid":""}`,
`{"siteID":""}`,
`{"siteId":""}`,
`{"siteid":"1234", "siteID":"12345"}`,
`{"siteid":"1234", "siteId":"123456"}`,
`{"siteid":123}`,
`{"siteids":"123"}`,
`{"notaparam":"123"}`,
`{"siteid":"123", "size": [1,2,3]}`,
`null`,
`true`,
`0`,
`abc`,
`[]`,
`{}`,
}
18 changes: 16 additions & 2 deletions static/bidder-params/ix.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@
"description": "A schema which validates params accepted by the Ix adapter",
"type": "object",
"properties": {
"siteid": {
"type": "string",
"minLength": 1,
"description": "An ID which identifies the site selling the impression, preferred."
},
"siteId": {
"type": "string",
"minLength": 1,
"description": "An ID which identifies the site selling the impression"
"description": "An ID which identifies the site selling the impression."
},
"siteID": {
"type": "string",
"minLength": 1,
"description": "An ID which identifies the site selling the impression."
},
"size": {
"type": "array",
Expand All @@ -19,5 +29,9 @@
"description": "An array of two integer containing the dimension"
}
},
"required": ["siteId"]
"oneOf": [
{"required": ["siteid"]},
{"required": ["siteId"]},
{"required": ["siteID"]}
]
}

0 comments on commit bab487e

Please sign in to comment.