Skip to content

Commit 2e80651

Browse files
authored
Adding copying of gdpr consent string to openrtb bid request (#1189)
* Adding copying of gdpr consent string to openrtb bid request * Updated video request to use OpenRTB Video and User objects * Fixing unit test failure message * Updates from code review comments * Updating unit test initialization * Updated mimes array construction
1 parent 6a26430 commit 2e80651

File tree

3 files changed

+81
-122
lines changed

3 files changed

+81
-122
lines changed

endpoints/openrtb2/video_auction.go

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,12 @@ func max(a, b int) int {
328328
return b
329329
}
330330

331-
func createImpressionTemplate(imp openrtb.Imp, video openrtb_ext.SimplifiedVideo) openrtb.Imp {
331+
func createImpressionTemplate(imp openrtb.Imp, video *openrtb.Video) openrtb.Imp {
332332
imp.Video = &openrtb.Video{}
333333
imp.Video.W = video.W
334334
imp.Video.H = video.H
335335
imp.Video.Protocols = video.Protocols
336-
imp.Video.MIMEs = video.Mimes
336+
imp.Video.MIMEs = video.MIMEs
337337
return imp
338338
}
339339

@@ -471,14 +471,7 @@ func mergeData(videoRequest *openrtb_ext.BidRequestVideo, bidRequest *openrtb.Bi
471471
bidRequest.Device = &videoRequest.Device
472472
}
473473

474-
if &videoRequest.User != nil {
475-
bidRequest.User = &openrtb.User{
476-
BuyerUID: videoRequest.User.Buyeruids["appnexus"], //TODO: map to string merging
477-
Yob: videoRequest.User.Yob,
478-
Gender: videoRequest.User.Gender,
479-
Keywords: videoRequest.User.Keywords,
480-
}
481-
}
474+
bidRequest.User = videoRequest.User
482475

483476
if len(videoRequest.BCat) != 0 {
484477
bidRequest.BCat = videoRequest.BCat
@@ -660,27 +653,30 @@ func (deps *endpointDeps) validateVideoRequest(req *openrtb_ext.BidRequestVideo)
660653
}
661654
}
662655

663-
if len(req.Video.Mimes) == 0 {
664-
err := errors.New("request missing required field: Video.Mimes")
665-
errL = append(errL, err)
666-
} else {
667-
mimes := make([]string, 0, 0)
668-
for _, mime := range req.Video.Mimes {
669-
if mime != "" {
670-
mimes = append(mimes, mime)
656+
if req.Video != nil {
657+
if len(req.Video.MIMEs) == 0 {
658+
err := errors.New("request missing required field: Video.Mimes")
659+
errL = append(errL, err)
660+
} else {
661+
mimes := make([]string, 0, len(req.Video.MIMEs))
662+
for _, mime := range req.Video.MIMEs {
663+
if mime != "" {
664+
mimes = append(mimes, mime)
665+
}
671666
}
667+
if len(mimes) == 0 {
668+
err := errors.New("request missing required field: Video.Mimes, mime types contains empty strings only")
669+
errL = append(errL, err)
670+
}
671+
req.Video.MIMEs = mimes
672672
}
673-
if len(mimes) == 0 {
674-
err := errors.New("request missing required field: Video.Mimes, mime types contains empty strings only")
673+
674+
if len(req.Video.Protocols) == 0 {
675+
err := errors.New("request missing required field: Video.Protocols")
675676
errL = append(errL, err)
676677
}
677-
if len(mimes) > 0 {
678-
req.Video.Mimes = mimes
679-
}
680-
}
681-
682-
if len(req.Video.Protocols) == 0 {
683-
err := errors.New("request missing required field: Video.Protocols")
678+
} else {
679+
err := errors.New("request missing required field: Video")
684680
errL = append(errL, err)
685681
}
686682

endpoints/openrtb2/video_auction_test.go

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ func TestVideoEndpointValidationsPositive(t *testing.T) {
233233
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
234234
PrimaryAdserver: 1,
235235
},
236-
Video: openrtb_ext.SimplifiedVideo{
237-
Mimes: mimes,
236+
Video: &openrtb.Video{
237+
MIMEs: mimes,
238238
Protocols: videoProtocols,
239239
},
240240
}
@@ -271,8 +271,8 @@ func TestVideoEndpointValidationsCritical(t *testing.T) {
271271
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
272272
PrimaryAdserver: 0,
273273
},
274-
Video: openrtb_ext.SimplifiedVideo{
275-
Mimes: mimes,
274+
Video: &openrtb.Video{
275+
MIMEs: mimes,
276276
Protocols: videoProtocols,
277277
},
278278
}
@@ -345,8 +345,8 @@ func TestVideoEndpointValidationsPodErrors(t *testing.T) {
345345
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
346346
PrimaryAdserver: 1,
347347
},
348-
Video: openrtb_ext.SimplifiedVideo{
349-
Mimes: mimes,
348+
Video: &openrtb.Video{
349+
MIMEs: mimes,
350350
Protocols: videoProtocols,
351351
},
352352
}
@@ -418,8 +418,8 @@ func TestVideoEndpointValidationsSiteAndApp(t *testing.T) {
418418
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
419419
PrimaryAdserver: 1,
420420
},
421-
Video: openrtb_ext.SimplifiedVideo{
422-
Mimes: mimes,
421+
Video: &openrtb.Video{
422+
MIMEs: mimes,
423423
Protocols: videoProtocols,
424424
},
425425
}
@@ -473,8 +473,8 @@ func TestVideoEndpointValidationsSiteMissingRequiredField(t *testing.T) {
473473
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
474474
PrimaryAdserver: 1,
475475
},
476-
Video: openrtb_ext.SimplifiedVideo{
477-
Mimes: mimes,
476+
Video: &openrtb.Video{
477+
MIMEs: mimes,
478478
Protocols: videoProtocols,
479479
},
480480
}
@@ -484,6 +484,43 @@ func TestVideoEndpointValidationsSiteMissingRequiredField(t *testing.T) {
484484
assert.Len(t, podErrors, 0, "Pod errors should be empty")
485485
}
486486

487+
func TestVideoEndpointValidationsMissingVideo(t *testing.T) {
488+
ex := &mockExchangeVideo{}
489+
deps := mockDeps(t, ex)
490+
deps.cfg.VideoStoredRequestRequired = true
491+
492+
req := openrtb_ext.BidRequestVideo{
493+
StoredRequestId: "123",
494+
PodConfig: openrtb_ext.PodConfig{
495+
DurationRangeSec: []int{15, 30},
496+
RequireExactDuration: true,
497+
Pods: []openrtb_ext.Pod{
498+
{
499+
PodId: 1,
500+
AdPodDurationSec: 30,
501+
ConfigId: "qwerty",
502+
},
503+
{
504+
PodId: 2,
505+
AdPodDurationSec: 30,
506+
ConfigId: "qwerty",
507+
},
508+
},
509+
},
510+
App: &openrtb.App{
511+
Bundle: "pbs.com",
512+
},
513+
IncludeBrandCategory: &openrtb_ext.IncludeBrandCategory{
514+
PrimaryAdserver: 1,
515+
},
516+
}
517+
518+
errors, podErrors := deps.validateVideoRequest(&req)
519+
assert.Len(t, podErrors, 0, "Pod errors should be empty")
520+
assert.Len(t, errors, 1, "Errors array should contain 1 error message")
521+
assert.Equal(t, "request missing required field: Video", errors[0].Error(), "Errors array should contain message regarding missing Video field")
522+
}
523+
487524
func TestVideoBuildVideoResponseMissedCacheForOneBid(t *testing.T) {
488525
openRtbBidResp := openrtb.BidResponse{}
489526
podErrors := make([]PodError, 0)
@@ -633,6 +670,13 @@ func TestMergeOpenRTBToVideoRequest(t *testing.T) {
633670
Ext: json.RawMessage(`{"gdpr":1,"us_privacy":"1NYY","existing":"any","consent":"anyConsent"}`),
634671
}
635672

673+
videoReq.User = &openrtb.User{
674+
BuyerUID: "test UID",
675+
Yob: 1980,
676+
Keywords: "test keywords",
677+
Ext: json.RawMessage(`{"consent":"test string"}`),
678+
}
679+
636680
mergeData(videoReq, bidReq)
637681

638682
assert.Equal(t, videoReq.BCat, bidReq.BCat, "BCat is incorrect")
@@ -647,6 +691,8 @@ func TestMergeOpenRTBToVideoRequest(t *testing.T) {
647691
assert.Equal(t, videoReq.Site.Page, bidReq.Site.Page, "Device.Site.Page is incorrect")
648692

649693
assert.Equal(t, videoReq.Regs, bidReq.Regs, "Regs is incorrect")
694+
695+
assert.Equal(t, videoReq.User, bidReq.User, "User is incorrect")
650696
}
651697

652698
func TestHandleError(t *testing.T) {

openrtb_ext/bid_request_video.go

Lines changed: 2 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type BidRequestVideo struct {
4343
// object; optional
4444
// Description:
4545
// Container object for the user of of the actual device
46-
User SimplifiedUser `json:"user,omitempty"`
46+
User *openrtb.User `json:"user,omitempty"`
4747

4848
// Attribute:
4949
// device
@@ -67,7 +67,7 @@ type BidRequestVideo struct {
6767
// object; required
6868
// Description:
6969
// Player container object
70-
Video SimplifiedVideo `json:"video,omitempty"`
70+
Video *openrtb.Video `json:"video,omitempty"`
7171

7272
// Attribute:
7373
// content
@@ -225,86 +225,3 @@ type Cacheconfig struct {
225225
// Time to Live for a cache entry specified in seconds
226226
Ttl int `json:"ttl"`
227227
}
228-
229-
type Gdpr struct {
230-
// Attribute:
231-
// consentrequired
232-
// Type:
233-
// boolean; optional
234-
// Indicates whether GDPR is in effect
235-
ConsentRequired bool `json:"consentrequired"`
236-
237-
// Attribute:
238-
// consentstring
239-
// Type:
240-
// string; optional
241-
// Contains the data structure developed by the GDPR
242-
ConsentString string `json:"consentstring"`
243-
}
244-
245-
type SimplifiedUser struct {
246-
// Attribute:
247-
// buyeruids
248-
// Type:
249-
// map; optional
250-
// ID of the stored config that corresponds to a single pod request
251-
Buyeruids map[string]string `json:"buyeruids"`
252-
253-
// Attribute:
254-
// gdpr
255-
// Type:
256-
// object; optional
257-
// Container object for GDPR
258-
Gdpr Gdpr `json:"gdpr"`
259-
260-
// Attribute:
261-
// yob
262-
// Type:
263-
// int; optional
264-
// Year of birth as a 4-digit integer
265-
Yob int64 `json:"yob"`
266-
267-
// Attribute:
268-
// gender
269-
// Type:
270-
// string; optional
271-
// Gender, where “M” = male, “F” = female, “O” = known to be other
272-
Gender string `json:"gender"`
273-
274-
// Attribute:
275-
// keywords
276-
// Type:
277-
// string; optional
278-
// Comma separated list of keywords, interests, or intent.
279-
Keywords string `json:"keywords"`
280-
}
281-
282-
type SimplifiedVideo struct {
283-
// Attribute:
284-
// w
285-
// Type:
286-
// uint64; optional
287-
// Width of video
288-
W uint64 `json:"w"`
289-
290-
// Attribute:
291-
// h
292-
// Type:
293-
// uint64; optional
294-
// Height of video
295-
H uint64 `json:"h"`
296-
297-
// Attribute:
298-
// mimes
299-
// Type:
300-
// array of strings; optional
301-
// Video mime types
302-
Mimes []string `json:"mimes"`
303-
304-
// Attribute:
305-
// protocols
306-
// Type:
307-
// array of objects; optional
308-
// protocols
309-
Protocols []openrtb.Protocol `json:"protocols"`
310-
}

0 commit comments

Comments
 (0)