Skip to content

Commit

Permalink
getGDPR and getConsent update
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 committed Sep 20, 2024
1 parent 57d9a48 commit 3e02d6b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 46 deletions.
15 changes: 7 additions & 8 deletions exchange/gdpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
54 changes: 16 additions & 38 deletions exchange/gdpr_test.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package exchange

import (
"encoding/json"
"testing"

gpplib "github.com/prebid/go-gpp"
gppConstants "github.com/prebid/go-gpp/constants"
"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"
)

Expand All @@ -21,48 +21,37 @@ 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,
},
{
description: "Regs is nil",
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,
},
{
Expand Down Expand Up @@ -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: "",
},
{
Expand All @@ -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",
},
Expand Down

0 comments on commit 3e02d6b

Please sign in to comment.