prebid-server icon indicating copy to clipboard operation
prebid-server copied to clipboard

SeatBid Bid extensions are not asserted in end-to-end JSON tests

Open guscarreon opened this issue 9 months ago • 0 comments

We discovered a bug in our end-to-end auction endpoint test framework called from TestJsonSampleRequests. The issue is that we are not asserting the response.seatbid[i].bid[j].ext fields of the JSON tests that don't come with a populated expectedBidResponse.seatbid[i].bid[j].ext field. In other words, even if the response from the openrtb/auction endpoint comes with wrong seatbid[i].bid[j].ext data, our test framework won't assert it if it's corresponding JSON test file doesn't come with an expectedBidResponse.seatbid[i].bid[j].ext field.

Below is an excerpt from file endpoints/openrtb2/sample-requests/aliased/hard-alias.json. Given that the expectedBidResponse depicts an ext field in line 45, said ext data is correctly compared in TestJsonSampleRequests against the openrtb2/auction's ext value.

33   "expectedBidResponse": {
34     "id":"some-request-id",
35     "bidid":"test bid id",
36     "cur": "USD",
37     "nbr":0,
38     "seatbid": [
39       {
40         "bid": [
41           {
42             "id": "adform-bid",
43             "impid": "my-imp-id",
44             "price": 2,
45             "ext": {
46               "origbidcpm": 2,
47               "origbidcur": "USD",
48               "prebid": {
49                 "meta": {
50                   "adaptercode": "adform"
51                 },
52                 "type": "banner"
53               }
54             }
55           }
56         ],
57        "seat": "adform"
58       }
59     ]
60   },
61   "expectedReturnCode": 200
62 }
endpoints/openrtb2/sample-requests/aliased/hard-alias.json

The opposite happens in files like endpoints/openrtb2/sample-requests/aliased/multiple-alias.json where we can visualize that none of the bid array entries come with an ext field, therefore, even if our endpoint's response comes with wrong response.seatbid[i].bid[j].ext entries, it would go unnoticed by our test framework.

59   "expectedBidResponse": {
60     "id": "some-request-id",
61     "seatbid": [
62       {
63         "bid": [
64           {
65             "id": "appnexus-bid",
66             "impid": "my-imp-id",
67             "price": 0
68           }
69         ],
70         "seat": "alias1"
71       },
72       {
73         "bid": [
74           {
75             "id": "rubicon-bid",
76             "impid": "my-imp-id",
77             "price": 0
78           }
79         ],
80         "seat": "alias2",
81         "ext": {}
82       },
83       {
84         "bid": [
85           {
86             "id": "appnexus-bid",
87             "impid": "my-imp-id",
88             "price": 0
89           }
90         ],
91         "seat": "appnexus"
92       }
93     ],
94     "bidid": "test bid id",
95     "cur": "USD",
96     "nbr": 0
97   },
98   "expectedReturnCode": 200
99 }
endpoints/openrtb2/sample-requests/aliased/multiple-alias.json

The if statement in line 310 shown below should be modified:

303         for bidID, expectedBid := range expectedBidMap {
304             if !assert.Contains(t, actualBidMap, bidID, "BidResponse.SeatBid[%s].Bid[%s].ID doesn't match expected. Test: %s\n", bidderName, bidID, testFile) {
305                 continue
306             }
307             assert.Equalf(t, expectedBid.ImpID, actualBidMap[bidID].ImpID, "BidResponse.SeatBid[%s].Bid[%s].ImpID doesn't match expected. Test: %s\n", bidderName, bidID, testFile)
308             assert.Equalf(t, expectedBid.Price, actualBidMap[bidID].Price, "BidResponse.SeatBid[%s].Bid[%s].Price doesn't match expected. Test: %s\n", bidderName, bidID, testFile)
309
310             if len(expectedBid.Ext) > 0 {
311                 assert.JSONEq(t, string(expectedBid.Ext), string(actualBidMap[bidID].Ext), "Incorrect bid extension")
312             }
313         }
314     }
endpoints/openrtb2/auction_test.go

guscarreon avatar May 08 '24 20:05 guscarreon