From 9eaff5a7f4a06dfad59f0e1c058917251b143df3 Mon Sep 17 00:00:00 2001 From: dbemiller <27972385+dbemiller@users.noreply.github.com> Date: Fri, 12 Oct 2018 09:54:03 -0400 Subject: [PATCH] Required some size to exist on banner requests (#646) * Required some size to exist on banner requests. * Added more tests. Fixed the code a bit. --- endpoints/openrtb2/auction.go | 5 ++++ .../invalid-whole/banner-h-only.json | 22 ++++++++++++++++++ .../invalid-whole/banner-h-zero.json | 23 +++++++++++++++++++ .../invalid-whole/banner-w-only.json | 22 ++++++++++++++++++ .../invalid-whole/banner-w-zero.json | 23 +++++++++++++++++++ .../invalid-whole/format-empty-array.json | 16 +++++++++---- 6 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 endpoints/openrtb2/sample-requests/invalid-whole/banner-h-only.json create mode 100644 endpoints/openrtb2/sample-requests/invalid-whole/banner-h-zero.json create mode 100644 endpoints/openrtb2/sample-requests/invalid-whole/banner-w-only.json create mode 100644 endpoints/openrtb2/sample-requests/invalid-whole/banner-w-zero.json diff --git a/endpoints/openrtb2/auction.go b/endpoints/openrtb2/auction.go index 51ecaf8e994..b21308e9a6a 100644 --- a/endpoints/openrtb2/auction.go +++ b/endpoints/openrtb2/auction.go @@ -355,6 +355,11 @@ func validateBanner(banner *openrtb.Banner, impIndex int) error { return fmt.Errorf("request.imp[%d].banner uses unsupported property: \"hmax\". Use the \"format\" array instead.", impIndex) } + hasRootSize := banner.H != nil && banner.W != nil && *banner.H > 0 && *banner.W > 0 + if !hasRootSize && len(banner.Format) == 0 { + return fmt.Errorf("request.imp[%d].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.", impIndex) + } + for fmtIndex, format := range banner.Format { if err := validateFormat(&format, impIndex, fmtIndex); err != nil { return err diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-only.json b/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-only.json new file mode 100644 index 00000000000..7040e8dfc3c --- /dev/null +++ b/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-only.json @@ -0,0 +1,22 @@ +{ + "message": "Invalid request: request.imp[0].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.\n", + "requestPayload": { + "id":"req-id", + "site": { + "id": "some-site" + }, + "imp": [ + { + "id":"imp-id", + "banner":{ + "h": 300 + }, + "ext": { + "appnexus": { + "placementId": 10433394 + } + } + } + ] + } +} diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-zero.json b/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-zero.json new file mode 100644 index 00000000000..d98cfba100b --- /dev/null +++ b/endpoints/openrtb2/sample-requests/invalid-whole/banner-h-zero.json @@ -0,0 +1,23 @@ +{ + "message": "Invalid request: request.imp[0].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.\n", + "requestPayload": { + "id":"req-id", + "site": { + "id": "some-site" + }, + "imp": [ + { + "id":"imp-id", + "banner":{ + "h": 0, + "w": 250 + }, + "ext": { + "appnexus": { + "placementId": 10433394 + } + } + } + ] + } +} diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-only.json b/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-only.json new file mode 100644 index 00000000000..52a7bdd2ba2 --- /dev/null +++ b/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-only.json @@ -0,0 +1,22 @@ +{ + "message": "Invalid request: request.imp[0].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.\n", + "requestPayload": { + "id":"req-id", + "site": { + "id": "some-site" + }, + "imp": [ + { + "id":"imp-id", + "banner":{ + "w": 50 + }, + "ext": { + "appnexus": { + "placementId": 10433394 + } + } + } + ] + } +} diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-zero.json b/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-zero.json new file mode 100644 index 00000000000..0b927f26e3c --- /dev/null +++ b/endpoints/openrtb2/sample-requests/invalid-whole/banner-w-zero.json @@ -0,0 +1,23 @@ +{ + "message": "Invalid request: request.imp[0].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.\n", + "requestPayload": { + "id":"req-id", + "site": { + "id": "some-site" + }, + "imp": [ + { + "id": "imp-id", + "banner": { + "h": 300, + "w": 0 + }, + "ext": { + "appnexus": { + "placementId": 10433394 + } + } + } + ] + } +} diff --git a/endpoints/openrtb2/sample-requests/invalid-whole/format-empty-array.json b/endpoints/openrtb2/sample-requests/invalid-whole/format-empty-array.json index a44b4a47b2e..e159601b6e8 100644 --- a/endpoints/openrtb2/sample-requests/invalid-whole/format-empty-array.json +++ b/endpoints/openrtb2/sample-requests/invalid-whole/format-empty-array.json @@ -1,12 +1,20 @@ { - "message": "Invalid request: request.imp[0].ext is required\n", + "message": "Invalid request: request.imp[0].banner has no sizes. Define \"w\" and \"h\", or include \"format\" elements.\n", "requestPayload": { "id":"req-id", + "site": { + "id": "some-site" + }, "imp": [ { - "id":"imp-id", - "banner":{ - "format":[] + "id": "imp-id", + "banner": { + "format": [] + }, + "ext": { + "appnexus": { + "placementId": 10433394 + } } } ]