diff --git a/exchange/gdpr.go b/exchange/gdpr.go index 2f94eefdae..fbba54da14 100644 --- a/exchange/gdpr.go +++ b/exchange/gdpr.go @@ -16,11 +16,11 @@ func getGDPR(req *openrtb_ext.RequestWrapper) (gdpr.Signal, error) { } return gdpr.SignalNo, nil } - re, err := req.GetRegExt() - if re == nil || re.GetGDPR() == nil || err != nil { - return gdpr.SignalAmbiguous, err + if req.Regs != nil && req.Regs.GDPR != nil { + return gdpr.IntSignalParse(int(*req.Regs.GDPR)) } - return gdpr.Signal(*re.GetGDPR()), nil + return gdpr.SignalAmbiguous, nil + } // getConsent will pull the consent string from an openrtb request @@ -29,11 +29,10 @@ func getConsent(req *openrtb_ext.RequestWrapper, gpp gpplib.GppContainer) (conse consent = gpp.Sections[i].GetValue() return } - ue, err := req.GetUserExt() - if ue == nil || ue.GetConsent() == nil || err != nil { - return + if req.User != nil { + return req.User.Consent, nil } - return *ue.GetConsent(), nil + return } // enforceGDPR determines if GDPR should be enforced based on the request signal and whether the channel is enabled diff --git a/exchange/gdpr_test.go b/exchange/gdpr_test.go index c73112be6f..7b58b67f34 100644 --- a/exchange/gdpr_test.go +++ b/exchange/gdpr_test.go @@ -1,7 +1,6 @@ package exchange import ( - "encoding/json" "testing" gpplib "github.com/prebid/go-gpp" @@ -9,6 +8,7 @@ import ( "github.com/prebid/openrtb/v20/openrtb2" "github.com/prebid/prebid-server/v2/gdpr" "github.com/prebid/prebid-server/v2/openrtb_ext" + "github.com/prebid/prebid-server/v2/util/ptrutil" "github.com/stretchr/testify/assert" ) @@ -21,17 +21,17 @@ func TestGetGDPR(t *testing.T) { }{ { description: "Regs Ext GDPR = 0", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": 0}`)}, + giveRegs: &openrtb2.Regs{GDPR: ptrutil.ToPtr[int8](0)}, wantGDPR: gdpr.SignalNo, }, { description: "Regs Ext GDPR = 1", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": 1}`)}, + giveRegs: &openrtb2.Regs{GDPR: ptrutil.ToPtr[int8](1)}, wantGDPR: gdpr.SignalYes, }, { description: "Regs Ext GDPR = null", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": null}`)}, + giveRegs: &openrtb2.Regs{GDPR: nil}, wantGDPR: gdpr.SignalAmbiguous, }, { @@ -39,30 +39,19 @@ func TestGetGDPR(t *testing.T) { giveRegs: nil, wantGDPR: gdpr.SignalAmbiguous, }, - { - description: "Regs Ext is nil", - giveRegs: &openrtb2.Regs{Ext: nil}, - wantGDPR: gdpr.SignalAmbiguous, - }, - { - description: "JSON unmarshal error", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"`)}, - wantGDPR: gdpr.SignalAmbiguous, - wantError: true, - }, { description: "Regs Ext GDPR = null, GPPSID has tcf2", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": null}`), GPPSID: []int8{2}}, + giveRegs: &openrtb2.Regs{GDPR: nil, GPPSID: []int8{2}}, wantGDPR: gdpr.SignalYes, }, { description: "Regs Ext GDPR = 1, GPPSID has uspv1", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": 1}`), GPPSID: []int8{6}}, + giveRegs: &openrtb2.Regs{GDPR: ptrutil.ToPtr[int8](1), GPPSID: []int8{6}}, wantGDPR: gdpr.SignalNo, }, { description: "Regs Ext GDPR = 0, GPPSID has tcf2", - giveRegs: &openrtb2.Regs{Ext: json.RawMessage(`{"gdpr": 0}`), GPPSID: []int8{2}}, + giveRegs: &openrtb2.Regs{GDPR: ptrutil.ToPtr[int8](0), GPPSID: []int8{2}}, wantGDPR: gdpr.SignalYes, }, { @@ -105,18 +94,13 @@ func TestGetConsent(t *testing.T) { wantError bool }{ { - description: "User Ext Consent is not empty", - giveUser: &openrtb2.User{Ext: json.RawMessage(`{"consent": "BOS2bx5OS2bx5ABABBAAABoAAAAAFA"}`)}, + description: "User Consent is not empty", + giveUser: &openrtb2.User{Consent: "BOS2bx5OS2bx5ABABBAAABoAAAAAFA"}, wantConsent: "BOS2bx5OS2bx5ABABBAAABoAAAAAFA", }, { description: "User Ext Consent is empty", - giveUser: &openrtb2.User{Ext: json.RawMessage(`{"consent": ""}`)}, - wantConsent: "", - }, - { - description: "User Ext is nil", - giveUser: &openrtb2.User{Ext: nil}, + giveUser: &openrtb2.User{Consent: ""}, wantConsent: "", }, { @@ -125,26 +109,20 @@ func TestGetConsent(t *testing.T) { wantConsent: "", }, { - description: "JSON unmarshal error", - giveUser: &openrtb2.User{Ext: json.RawMessage(`{`)}, - wantConsent: "", - wantError: true, - }, - { - description: "User Ext is nil, GPP has no GDPR", - giveUser: &openrtb2.User{Ext: nil}, + description: "User is nil, GPP has no GDPR", + giveUser: nil, giveGPP: gpplib.GppContainer{Version: 1, SectionTypes: []gppConstants.SectionID{6}, Sections: []gpplib.Section{&upsv1Section}}, wantConsent: "", }, { - description: "User Ext is nil, GPP has GDPR", - giveUser: &openrtb2.User{Ext: nil}, + description: "User is nil, GPP has GDPR", + giveUser: nil, giveGPP: gpplib.GppContainer{Version: 1, SectionTypes: []gppConstants.SectionID{2}, Sections: []gpplib.Section{&tcf1Section}}, wantConsent: "BOS2bx5OS2bx5ABABBAAABoAAAAAFA", }, { - description: "User Ext has GDPR, GPP has GDPR", - giveUser: &openrtb2.User{Ext: json.RawMessage(`{"consent": "BSOMECONSENT"}`)}, + description: "User has GDPR, GPP has GDPR", + giveUser: &openrtb2.User{Consent: "BSOMECONSENT"}, giveGPP: gpplib.GppContainer{Version: 1, SectionTypes: []gppConstants.SectionID{2}, Sections: []gpplib.Section{&tcf1Section}}, wantConsent: "BOS2bx5OS2bx5ABABBAAABoAAAAAFA", },