github.com/prebid/prebid-server/v2@v2.18.0/openrtb_ext/convert_down_test.go (about) 1 package openrtb_ext 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/openrtb/v20/adcom1" 8 "github.com/prebid/openrtb/v20/openrtb2" 9 "github.com/prebid/prebid-server/v2/errortypes" 10 "github.com/prebid/prebid-server/v2/util/ptrutil" 11 "github.com/stretchr/testify/assert" 12 ) 13 14 func TestConvertDownTo25(t *testing.T) { 15 testCases := []struct { 16 name string 17 givenRequest openrtb2.BidRequest 18 expectedRequest openrtb2.BidRequest 19 expectedErrType error 20 }{ 21 { 22 name: "2.6-to-2.5", 23 givenRequest: openrtb2.BidRequest{ 24 ID: "anyID", 25 Imp: []openrtb2.Imp{{Rwdd: 1}}, 26 Source: &openrtb2.Source{SChain: &openrtb2.SupplyChain{Complete: 1, Nodes: []openrtb2.SupplyChainNode{}, Ver: "2"}}, 27 Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(1), USPrivacy: "3"}, 28 User: &openrtb2.User{Consent: "1", EIDs: []openrtb2.EID{{Source: "42"}}}, 29 }, 30 expectedRequest: openrtb2.BidRequest{ 31 ID: "anyID", 32 Imp: []openrtb2.Imp{{Ext: json.RawMessage(`{"prebid":{"is_rewarded_inventory":1}}`)}}, 33 Source: &openrtb2.Source{Ext: json.RawMessage(`{"schain":{"complete":1,"nodes":[],"ver":"2"}}`)}, 34 Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr":1,"us_privacy":"3"}`)}, 35 User: &openrtb2.User{Ext: json.RawMessage(`{"consent":"1","eids":[{"source":"42"}]}`)}, 36 }, 37 }, 38 { 39 name: "2.6-dropped", // integration with clear26Fields 40 givenRequest: openrtb2.BidRequest{ 41 ID: "anyID", 42 CatTax: adcom1.CatTaxIABContent10, 43 Device: &openrtb2.Device{LangB: "anyLang"}, 44 }, 45 expectedRequest: openrtb2.BidRequest{ 46 ID: "anyID", 47 Device: &openrtb2.Device{}, 48 }, 49 }, 50 { 51 name: "2.6-202211-dropped", // integration with clear202211Fields 52 givenRequest: openrtb2.BidRequest{ 53 ID: "anyID", 54 App: &openrtb2.App{InventoryPartnerDomain: "anyDomain"}, 55 }, 56 expectedRequest: openrtb2.BidRequest{ 57 ID: "anyID", 58 App: &openrtb2.App{}, 59 }, 60 }, 61 { 62 name: "2.6-202303-dropped", // integration with clear202303Fields 63 givenRequest: openrtb2.BidRequest{ 64 ID: "anyID", 65 Imp: []openrtb2.Imp{{ID: "1", Refresh: &openrtb2.Refresh{Count: ptrutil.ToPtr(1)}}}, 66 }, 67 expectedRequest: openrtb2.BidRequest{ 68 ID: "anyID", 69 Imp: []openrtb2.Imp{{ID: "1"}}, 70 }, 71 }, 72 { 73 name: "2.6-202309-dropped", // integration with clear202309Fields 74 givenRequest: openrtb2.BidRequest{ 75 ID: "anyID", 76 ACat: []string{"anyACat"}, 77 }, 78 expectedRequest: openrtb2.BidRequest{ 79 ID: "anyID", 80 }, 81 }, 82 { 83 name: "2.6-to-2.5-OtherExtFields", 84 givenRequest: openrtb2.BidRequest{ 85 ID: "anyID", 86 Imp: []openrtb2.Imp{{Rwdd: 1, Ext: json.RawMessage(`{"other":"otherImp"}`)}}, 87 Ext: json.RawMessage(`{"other":"otherExt"}`), 88 Source: &openrtb2.Source{SChain: &openrtb2.SupplyChain{Complete: 1, Nodes: []openrtb2.SupplyChainNode{}, Ver: "2"}, Ext: json.RawMessage(`{"other":"otherSource"}`)}, 89 Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(1), USPrivacy: "3", Ext: json.RawMessage(`{"other":"otherRegs"}`)}, 90 User: &openrtb2.User{Consent: "1", EIDs: []openrtb2.EID{{Source: "42"}}, Ext: json.RawMessage(`{"other":"otherUser"}`)}, 91 }, 92 expectedRequest: openrtb2.BidRequest{ 93 ID: "anyID", 94 Imp: []openrtb2.Imp{{Ext: json.RawMessage(`{"other":"otherImp","prebid":{"is_rewarded_inventory":1}}`)}}, 95 Ext: json.RawMessage(`{"other":"otherExt"}`), 96 Source: &openrtb2.Source{Ext: json.RawMessage(`{"other":"otherSource","schain":{"complete":1,"nodes":[],"ver":"2"}}`)}, 97 Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr":1,"other":"otherRegs","us_privacy":"3"}`)}, 98 User: &openrtb2.User{Ext: json.RawMessage(`{"consent":"1","eids":[{"source":"42"}],"other":"otherUser"}`)}, 99 }, 100 }, 101 { 102 name: "malformed-schain", 103 givenRequest: openrtb2.BidRequest{ 104 ID: "anyID", 105 Source: &openrtb2.Source{SChain: &openrtb2.SupplyChain{Complete: 1, Nodes: []openrtb2.SupplyChainNode{}, Ver: "2"}, Ext: json.RawMessage(`malformed`)}, 106 }, 107 expectedErrType: &errortypes.FailedToUnmarshal{}, 108 }, 109 { 110 name: "malformed-gdpr", 111 givenRequest: openrtb2.BidRequest{ 112 ID: "anyID", 113 Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(1), Ext: json.RawMessage(`malformed`)}, 114 }, 115 expectedErrType: &errortypes.FailedToUnmarshal{}, 116 }, 117 { 118 name: "malformed-consent", 119 givenRequest: openrtb2.BidRequest{ 120 ID: "anyID", 121 User: &openrtb2.User{Consent: "1", Ext: json.RawMessage(`malformed`)}, 122 }, 123 expectedErrType: &errortypes.FailedToUnmarshal{}, 124 }, 125 { 126 name: "malformed-usprivacy", 127 givenRequest: openrtb2.BidRequest{ 128 ID: "anyID", 129 Regs: &openrtb2.Regs{USPrivacy: "3", Ext: json.RawMessage(`malformed`)}, 130 }, 131 expectedErrType: &errortypes.FailedToUnmarshal{}, 132 }, 133 { 134 name: "malformed-eid", 135 givenRequest: openrtb2.BidRequest{ 136 ID: "anyID", 137 User: &openrtb2.User{EIDs: []openrtb2.EID{{Source: "42"}}, Ext: json.RawMessage(`malformed`)}, 138 }, 139 expectedErrType: &errortypes.FailedToUnmarshal{}, 140 }, 141 { 142 name: "malformed-imp", 143 givenRequest: openrtb2.BidRequest{ 144 ID: "anyID", 145 Imp: []openrtb2.Imp{{Rwdd: 1, Ext: json.RawMessage(`malformed`)}}, 146 }, 147 expectedErrType: &errortypes.FailedToUnmarshal{}, 148 }, 149 } 150 151 for _, test := range testCases { 152 t.Run(test.name, func(t *testing.T) { 153 w := &RequestWrapper{BidRequest: &test.givenRequest} 154 err := ConvertDownTo25(w) 155 156 if test.expectedErrType != nil { 157 assert.IsType(t, test.expectedErrType, err) 158 } else { 159 assert.NoError(t, w.RebuildRequest(), "error") 160 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 161 } 162 }) 163 } 164 } 165 166 func TestMoveSupplyChainFrom26To25(t *testing.T) { 167 var ( 168 schain1 = &openrtb2.SupplyChain{Complete: 1, Nodes: []openrtb2.SupplyChainNode{}, Ver: "1"} 169 schain1Json = json.RawMessage(`{"schain":{"complete":1,"nodes":[],"ver":"1"}}`) 170 schain2Json = json.RawMessage(`{"schain":{"complete":1,"nodes":[],"ver":"2"}}`) 171 ) 172 173 testCases := []struct { 174 name string 175 givenRequest openrtb2.BidRequest 176 expectedRequest openrtb2.BidRequest 177 expectedErrType error 178 }{ 179 { 180 name: "notpresent-source", 181 givenRequest: openrtb2.BidRequest{}, 182 expectedRequest: openrtb2.BidRequest{}, 183 }, 184 { 185 name: "notpresent-source-schain", 186 givenRequest: openrtb2.BidRequest{Source: &openrtb2.Source{}}, 187 expectedRequest: openrtb2.BidRequest{Source: &openrtb2.Source{}}, 188 }, 189 { 190 name: "2.6-migratedto-2.5", 191 givenRequest: openrtb2.BidRequest{Source: &openrtb2.Source{SChain: schain1}}, 192 expectedRequest: openrtb2.BidRequest{Source: &openrtb2.Source{Ext: schain1Json}}, 193 }, 194 { 195 name: "2.5-overwritten", 196 givenRequest: openrtb2.BidRequest{Source: &openrtb2.Source{SChain: schain1, Ext: schain2Json}}, 197 expectedRequest: openrtb2.BidRequest{Source: &openrtb2.Source{Ext: schain1Json}}, 198 }, 199 { 200 name: "malformed", 201 givenRequest: openrtb2.BidRequest{Source: &openrtb2.Source{SChain: schain1, Ext: json.RawMessage(`malformed`)}}, 202 expectedErrType: &errortypes.FailedToUnmarshal{}, 203 }, 204 } 205 206 for _, test := range testCases { 207 t.Run(test.name, func(t *testing.T) { 208 w := &RequestWrapper{BidRequest: &test.givenRequest} 209 err := moveSupplyChainFrom26To25(w) 210 211 if test.expectedErrType != nil { 212 assert.IsType(t, test.expectedErrType, err) 213 } else { 214 assert.NoError(t, w.RebuildRequest(), "error") 215 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 216 } 217 }) 218 } 219 } 220 221 func TestMoveGDPRFrom26To25(t *testing.T) { 222 testCases := []struct { 223 name string 224 givenRequest openrtb2.BidRequest 225 expectedRequest openrtb2.BidRequest 226 expectedErrType error 227 }{ 228 { 229 name: "notpresent-regs", 230 givenRequest: openrtb2.BidRequest{}, 231 expectedRequest: openrtb2.BidRequest{}, 232 }, 233 { 234 name: "notpresent-regs-gdpr", 235 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}}, 236 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}}, 237 }, 238 { 239 name: "2.6-migratedto-2.5", 240 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(0)}}, 241 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr":0}`)}}, 242 }, 243 { 244 name: "2.5-overwritten", 245 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(0), Ext: json.RawMessage(`{"gdpr":1}`)}}, 246 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr":0}`)}}, 247 }, 248 { 249 name: "malformed", 250 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{GDPR: openrtb2.Int8Ptr(0), Ext: json.RawMessage(`malformed`)}}, 251 expectedErrType: &errortypes.FailedToUnmarshal{}, 252 }, 253 } 254 255 for _, test := range testCases { 256 t.Run(test.name, func(t *testing.T) { 257 w := &RequestWrapper{BidRequest: &test.givenRequest} 258 err := moveGDPRFrom26To25(w) 259 260 if test.expectedErrType != nil { 261 assert.IsType(t, test.expectedErrType, err) 262 } else { 263 assert.NoError(t, w.RebuildRequest(), "error") 264 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 265 } 266 }) 267 } 268 } 269 270 func TestMoveConsentFrom26To25(t *testing.T) { 271 testCases := []struct { 272 name string 273 givenRequest openrtb2.BidRequest 274 expectedRequest openrtb2.BidRequest 275 expectedErrType error 276 }{ 277 { 278 name: "notpresent-user", 279 givenRequest: openrtb2.BidRequest{}, 280 expectedRequest: openrtb2.BidRequest{}, 281 }, 282 { 283 name: "notpresent-user-consent", 284 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{}}, 285 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{}}, 286 }, 287 { 288 name: "2.6-migratedto-2.5", 289 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{Consent: "1"}}, 290 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{Ext: json.RawMessage(`{"consent":"1"}`)}}, 291 }, 292 { 293 name: "2.5-overwritten", 294 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{Consent: "1", Ext: json.RawMessage(`{"consent":"2"}`)}}, 295 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{Ext: json.RawMessage(`{"consent":"1"}`)}}, 296 }, 297 { 298 name: "malformed", 299 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{Consent: "1", Ext: json.RawMessage(`malformed`)}}, 300 expectedErrType: &errortypes.FailedToUnmarshal{}, 301 }, 302 } 303 304 for _, test := range testCases { 305 t.Run(test.name, func(t *testing.T) { 306 w := &RequestWrapper{BidRequest: &test.givenRequest} 307 err := moveConsentFrom26To25(w) 308 309 if test.expectedErrType != nil { 310 assert.IsType(t, test.expectedErrType, err) 311 } else { 312 assert.NoError(t, w.RebuildRequest(), "error") 313 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 314 } 315 }) 316 } 317 } 318 319 func TestMoveUSPrivacyFrom26To25(t *testing.T) { 320 testCases := []struct { 321 name string 322 givenRequest openrtb2.BidRequest 323 expectedRequest openrtb2.BidRequest 324 expectedErrType error 325 }{ 326 { 327 name: "notpresent-regs", 328 givenRequest: openrtb2.BidRequest{}, 329 expectedRequest: openrtb2.BidRequest{}, 330 }, 331 { 332 name: "notpresent-regs-usprivacy", 333 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}}, 334 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}}, 335 }, 336 { 337 name: "2.6-migratedto-2.5", 338 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{USPrivacy: "1"}}, 339 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"us_privacy":"1"}`)}}, 340 }, 341 { 342 name: "2.5-overwritten", 343 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{USPrivacy: "1", Ext: json.RawMessage(`{"us_privacy":"2"}`)}}, 344 expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"us_privacy":"1"}`)}}, 345 }, 346 { 347 name: "malformed", 348 givenRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{USPrivacy: "1", Ext: json.RawMessage(`malformed`)}}, 349 expectedErrType: &errortypes.FailedToUnmarshal{}, 350 }, 351 } 352 353 for _, test := range testCases { 354 t.Run(test.name, func(t *testing.T) { 355 w := &RequestWrapper{BidRequest: &test.givenRequest} 356 err := moveUSPrivacyFrom26To25(w) 357 358 if test.expectedErrType != nil { 359 assert.IsType(t, test.expectedErrType, err) 360 } else { 361 assert.NoError(t, w.RebuildRequest(), "error") 362 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 363 } 364 }) 365 } 366 } 367 368 func TestMoveEIDFrom26To25(t *testing.T) { 369 var ( 370 eid1 = []openrtb2.EID{{Source: "1"}} 371 eid1Json = json.RawMessage(`{"eids":[{"source":"1"}]}`) 372 eid2Json = json.RawMessage(`{"eids":[{"source":"2"}]}`) 373 ) 374 375 testCases := []struct { 376 name string 377 givenRequest openrtb2.BidRequest 378 expectedRequest openrtb2.BidRequest 379 expectedErrType error 380 }{ 381 { 382 name: "notpresent-user", 383 givenRequest: openrtb2.BidRequest{}, 384 expectedRequest: openrtb2.BidRequest{}, 385 }, 386 { 387 name: "notpresent-user-eids", 388 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{}}, 389 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{}}, 390 }, 391 { 392 name: "2.6-migratedto-2.5", 393 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1}}, 394 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{Ext: eid1Json}}, 395 }, 396 { 397 name: "2.6-migratedto-2.5-empty", 398 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: []openrtb2.EID{}}}, 399 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{}}, 400 }, 401 { 402 name: "2.5-overwritten", 403 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1, Ext: eid2Json}}, 404 expectedRequest: openrtb2.BidRequest{User: &openrtb2.User{Ext: eid1Json}}, 405 }, 406 { 407 name: "malformed", 408 givenRequest: openrtb2.BidRequest{User: &openrtb2.User{EIDs: eid1, Ext: json.RawMessage(`malformed`)}}, 409 expectedErrType: &errortypes.FailedToUnmarshal{}, 410 }, 411 } 412 413 for _, test := range testCases { 414 t.Run(test.name, func(t *testing.T) { 415 w := &RequestWrapper{BidRequest: &test.givenRequest} 416 err := moveEIDFrom26To25(w) 417 418 if test.expectedErrType != nil { 419 assert.IsType(t, test.expectedErrType, err) 420 } else { 421 assert.NoError(t, w.RebuildRequest(), "error") 422 assert.Equal(t, test.expectedRequest, *w.BidRequest, "result") 423 } 424 }) 425 } 426 } 427 428 func TestMoveRewardedFrom26ToPrebidExt(t *testing.T) { 429 testCases := []struct { 430 name string 431 givenImp openrtb2.Imp 432 expectedImp openrtb2.Imp 433 expectedErrType error 434 }{ 435 { 436 name: "notpresent-prebid", 437 givenImp: openrtb2.Imp{}, 438 expectedImp: openrtb2.Imp{}, 439 }, 440 { 441 name: "2.6-migratedto-2.5", 442 givenImp: openrtb2.Imp{Rwdd: 1}, 443 expectedImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":{"is_rewarded_inventory":1}}`)}, 444 }, 445 { 446 name: "2.5-overwritten", 447 givenImp: openrtb2.Imp{Rwdd: 1, Ext: json.RawMessage(`{"prebid":{"is_rewarded_inventory":2}}`)}, 448 expectedImp: openrtb2.Imp{Ext: json.RawMessage(`{"prebid":{"is_rewarded_inventory":1}}`)}, 449 }, 450 { 451 name: "Malformed", 452 givenImp: openrtb2.Imp{Rwdd: 1, Ext: json.RawMessage(`malformed`)}, 453 expectedErrType: &errortypes.FailedToUnmarshal{}, 454 }, 455 } 456 457 for _, test := range testCases { 458 t.Run(test.name, func(t *testing.T) { 459 w := &ImpWrapper{Imp: &test.givenImp} 460 err := moveRewardedFrom26ToPrebidExt(w) 461 462 if test.expectedErrType != nil { 463 assert.IsType(t, test.expectedErrType, err) 464 } else { 465 assert.NoError(t, w.RebuildImp(), "error") 466 assert.Equal(t, test.expectedImp, *w.Imp, "result") 467 } 468 }) 469 } 470 } 471 472 func TestClear26Fields(t *testing.T) { 473 var int8_1 int8 = 1 474 475 given := &openrtb2.BidRequest{ 476 ID: "anyID", 477 WLangB: []string{"anyLang"}, 478 CatTax: adcom1.CatTaxIABAudience11, 479 App: &openrtb2.App{ 480 CatTax: adcom1.CatTaxIABAudience11, 481 KwArray: []string{"anyKeyword"}, 482 Content: &openrtb2.Content{ 483 ID: "anyContent", 484 CatTax: adcom1.CatTaxIABAudience11, 485 KwArray: []string{"anyKeyword"}, 486 LangB: "anyLang", 487 Network: &openrtb2.Network{ 488 ID: "anyNetwork", 489 }, 490 Channel: &openrtb2.Channel{ 491 ID: "anyChannel", 492 }, 493 Producer: &openrtb2.Producer{ 494 ID: "anyProcedure", 495 CatTax: adcom1.CatTaxIABAudience11, 496 }, 497 }, 498 Publisher: &openrtb2.Publisher{ 499 ID: "anyPublisher", 500 CatTax: adcom1.CatTaxIABAudience11, 501 }, 502 }, 503 Site: &openrtb2.Site{ 504 CatTax: adcom1.CatTaxIABAudience11, 505 KwArray: []string{"anyKeyword"}, 506 Content: &openrtb2.Content{ 507 ID: "anyContent", 508 CatTax: adcom1.CatTaxIABAudience11, 509 KwArray: []string{"anyKeyword"}, 510 LangB: "anyLang", 511 Network: &openrtb2.Network{ 512 ID: "anyNetwork", 513 }, 514 Channel: &openrtb2.Channel{ 515 ID: "anyChannel", 516 }, 517 Producer: &openrtb2.Producer{ 518 ID: "anyProcedure", 519 CatTax: adcom1.CatTaxIABAudience11, 520 }, 521 }, 522 Publisher: &openrtb2.Publisher{ 523 ID: "anyPublisher", 524 CatTax: adcom1.CatTaxIABAudience11, 525 }, 526 }, 527 Device: &openrtb2.Device{ 528 IP: "1.2.3.4", 529 LangB: "anyLang", 530 SUA: &openrtb2.UserAgent{ 531 Model: "PBS 2000", 532 }, 533 }, 534 Regs: &openrtb2.Regs{ 535 COPPA: 1, 536 GDPR: &int8_1, 537 USPrivacy: "anyCCPA", 538 }, 539 Source: &openrtb2.Source{ 540 TID: "anyTransactionID", 541 SChain: &openrtb2.SupplyChain{ 542 Complete: 1, 543 }, 544 }, 545 User: &openrtb2.User{ 546 ID: "anyUser", 547 KwArray: []string{"anyKeyword"}, 548 Consent: "anyConsent", 549 EIDs: []openrtb2.EID{{Source: "anySource"}}, 550 }, 551 Imp: []openrtb2.Imp{{ 552 ID: "imp1", 553 Rwdd: 1, 554 SSAI: openrtb2.AdInsertServer, 555 Audio: &openrtb2.Audio{ 556 MIMEs: []string{"any/audio"}, 557 PodDur: 30, 558 RqdDurs: []int64{15, 60}, 559 PodID: "1", 560 PodSeq: adcom1.PodSeqFirst, 561 SlotInPod: adcom1.SlotPosFirst, 562 MinCPMPerSec: 100.0, 563 }, 564 Video: &openrtb2.Video{ 565 MIMEs: []string{"any/video"}, 566 MaxSeq: 30, 567 PodDur: 30, 568 PodID: "1", 569 PodSeq: adcom1.PodSeqFirst, 570 RqdDurs: []int64{15, 60}, 571 SlotInPod: adcom1.SlotPosFirst, 572 MinCPMPerSec: 100.0, 573 }, 574 }}, 575 } 576 577 expected := &openrtb2.BidRequest{ 578 ID: "anyID", 579 App: &openrtb2.App{ 580 Content: &openrtb2.Content{ 581 ID: "anyContent", 582 Producer: &openrtb2.Producer{ 583 ID: "anyProcedure", 584 }, 585 }, 586 Publisher: &openrtb2.Publisher{ 587 ID: "anyPublisher", 588 }, 589 }, 590 Site: &openrtb2.Site{ 591 Content: &openrtb2.Content{ 592 ID: "anyContent", 593 Producer: &openrtb2.Producer{ 594 ID: "anyProcedure", 595 }, 596 }, 597 Publisher: &openrtb2.Publisher{ 598 ID: "anyPublisher", 599 }, 600 }, 601 Device: &openrtb2.Device{ 602 IP: "1.2.3.4", 603 }, 604 Regs: &openrtb2.Regs{ 605 COPPA: 1, 606 }, 607 Source: &openrtb2.Source{ 608 TID: "anyTransactionID", 609 }, 610 User: &openrtb2.User{ 611 ID: "anyUser", 612 }, 613 Imp: []openrtb2.Imp{{ 614 ID: "imp1", 615 Audio: &openrtb2.Audio{ 616 MIMEs: []string{"any/audio"}, 617 }, 618 Video: &openrtb2.Video{ 619 MIMEs: []string{"any/video"}, 620 }, 621 }}, 622 } 623 624 r := &RequestWrapper{BidRequest: given} 625 clear26Fields(r) 626 assert.Equal(t, expected, r.BidRequest) 627 } 628 629 func TestClear202211Fields(t *testing.T) { 630 testCases := []struct { 631 name string 632 given openrtb2.BidRequest 633 expected openrtb2.BidRequest 634 }{ 635 { 636 name: "app", 637 given: openrtb2.BidRequest{ 638 ID: "anyID", 639 App: &openrtb2.App{InventoryPartnerDomain: "anyDomain"}, 640 Imp: []openrtb2.Imp{{ID: "imp1", Qty: &openrtb2.Qty{Multiplier: 2.0}, DT: 42}}, 641 Regs: &openrtb2.Regs{GPP: "anyGPP", GPPSID: []int8{1, 2, 3}}, 642 }, 643 expected: openrtb2.BidRequest{ 644 ID: "anyID", 645 App: &openrtb2.App{}, 646 Imp: []openrtb2.Imp{{ID: "imp1"}}, 647 Regs: &openrtb2.Regs{}, 648 }, 649 }, 650 { 651 name: "site", 652 given: openrtb2.BidRequest{ 653 ID: "anyID", 654 Site: &openrtb2.Site{InventoryPartnerDomain: "anyDomain"}, 655 Imp: []openrtb2.Imp{{ID: "imp1", Qty: &openrtb2.Qty{Multiplier: 2.0}, DT: 42}}, 656 Regs: &openrtb2.Regs{GPP: "anyGPP", GPPSID: []int8{1, 2, 3}}, 657 }, 658 expected: openrtb2.BidRequest{ 659 ID: "anyID", 660 Site: &openrtb2.Site{}, 661 Imp: []openrtb2.Imp{{ID: "imp1"}}, 662 Regs: &openrtb2.Regs{}, 663 }, 664 }, 665 { 666 name: "dooh", 667 given: openrtb2.BidRequest{ 668 ID: "anyID", 669 DOOH: &openrtb2.DOOH{ID: "anyDOOH"}, 670 Imp: []openrtb2.Imp{{ID: "imp1", Qty: &openrtb2.Qty{Multiplier: 2.0}, DT: 42}}, 671 Regs: &openrtb2.Regs{GPP: "anyGPP", GPPSID: []int8{1, 2, 3}}, 672 }, 673 expected: openrtb2.BidRequest{ 674 ID: "anyID", 675 Imp: []openrtb2.Imp{{ID: "imp1"}}, 676 Regs: &openrtb2.Regs{}, 677 }, 678 }, 679 } 680 681 for _, test := range testCases { 682 t.Run(test.name, func(t *testing.T) { 683 r := &RequestWrapper{BidRequest: &test.given} 684 clear202211Fields(r) 685 assert.Equal(t, &test.expected, r.BidRequest) 686 }) 687 } 688 } 689 690 func TestClear202303Fields(t *testing.T) { 691 given := openrtb2.BidRequest{ 692 ID: "anyID", 693 Imp: []openrtb2.Imp{ 694 { 695 ID: "imp1", 696 Video: &openrtb2.Video{PodID: "1", Plcmt: adcom1.VideoPlcmtInstream}, 697 Refresh: &openrtb2.Refresh{Count: ptrutil.ToPtr(1)}, 698 }, 699 }, 700 } 701 702 expected := openrtb2.BidRequest{ 703 ID: "anyID", 704 Imp: []openrtb2.Imp{ 705 { 706 ID: "imp1", 707 Video: &openrtb2.Video{PodID: "1"}, 708 }, 709 }, 710 } 711 712 r := &RequestWrapper{BidRequest: &given} 713 clear202303Fields(r) 714 assert.Equal(t, expected, given) 715 } 716 717 func TestClear202309Fields(t *testing.T) { 718 givenDurFloors := []openrtb2.DurFloors{{MinDur: 15, MaxDur: 30, BidFloor: 100}} 719 720 given := openrtb2.BidRequest{ 721 ID: "anyID", 722 ACat: []string{"acat1", "acat2"}, 723 Imp: []openrtb2.Imp{ 724 { 725 ID: "imp1", 726 Audio: &openrtb2.Audio{PodID: "1", DurFloors: givenDurFloors}, 727 }, 728 { 729 ID: "imp2", 730 Video: &openrtb2.Video{PodID: "2", DurFloors: givenDurFloors}, 731 PMP: &openrtb2.PMP{ 732 PrivateAuction: 1, 733 Deals: []openrtb2.Deal{ 734 {ID: "deal1", BidFloor: 200, Guar: 1, MinCPMPerSec: 2, DurFloors: givenDurFloors}}, 735 }, 736 }, 737 }, 738 } 739 740 expected := openrtb2.BidRequest{ 741 ID: "anyID", 742 Imp: []openrtb2.Imp{ 743 { 744 ID: "imp1", 745 Audio: &openrtb2.Audio{PodID: "1"}, 746 }, 747 { 748 ID: "imp2", 749 Video: &openrtb2.Video{PodID: "2"}, 750 PMP: &openrtb2.PMP{ 751 PrivateAuction: 1, 752 Deals: []openrtb2.Deal{ 753 {ID: "deal1", BidFloor: 200}}, 754 }, 755 }, 756 }, 757 } 758 759 r := &RequestWrapper{BidRequest: &given} 760 clear202309Fields(r) 761 assert.Equal(t, expected, given) 762 }