Skip to content

Commit

Permalink
Update Go-GPP Library (prebid#3425)
Browse files Browse the repository at this point in the history
  • Loading branch information
SyntaxNode authored Jan 30, 2024
1 parent 3404652 commit 929ba61
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 30 deletions.
8 changes: 4 additions & 4 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func extractPrivacyPolicies(request cookieSyncRequest, usersyncDefaultGDPRValue

var gpp gpplib.GppContainer
if len(request.GPP) > 0 {
var err error
gpp, err = gpplib.Parse(request.GPP)
if err != nil {
return macros.UserSyncPrivacy{}, gdpr.SignalNo, privacy.Policies{}, err
var errs []error
gpp, errs = gpplib.Parse(request.GPP)
if len(errs) > 0 {
return macros.UserSyncPrivacy{}, gdpr.SignalNo, privacy.Policies{}, errs[0]
}
}

Expand Down
7 changes: 4 additions & 3 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -844,10 +844,11 @@ func (deps *endpointDeps) validateRequest(req *openrtb_ext.RequestWrapper, isAmp
}
var gpp gpplib.GppContainer
if req.BidRequest.Regs != nil && len(req.BidRequest.Regs.GPP) > 0 {
gpp, err = gpplib.Parse(req.BidRequest.Regs.GPP)
if err != nil {
var errs []error
gpp, errs = gpplib.Parse(req.BidRequest.Regs.GPP)
if len(errs) > 0 {
errL = append(errL, &errortypes.Warning{
Message: fmt.Sprintf("GPP consent string is invalid and will be ignored. (%v)", err),
Message: fmt.Sprintf("GPP consent string is invalid and will be ignored. (%v)", errs[0]),
WarningCode: errortypes.InvalidPrivacyConsentWarningCode})
}
}
Expand Down
20 changes: 8 additions & 12 deletions endpoints/setuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,14 @@ func extractGDPRInfo(query url.Values) (reqInfo gdpr.RequestInfo, err error) {

// parseGDPRFromGPP parses and validates the "gpp_sid" and "gpp" query fields.
func parseGDPRFromGPP(query url.Values) (gdpr.RequestInfo, error) {
var gdprSignal gdpr.Signal = gdpr.SignalAmbiguous
var gdprConsent string = ""
var err error

gdprSignal, err = parseSignalFromGppSidStr(query.Get("gpp_sid"))
gdprSignal, err := parseSignalFromGppSidStr(query.Get("gpp_sid"))
if err != nil {
return gdpr.RequestInfo{GDPRSignal: gdpr.SignalAmbiguous}, err
}

gdprConsent, err = parseConsentFromGppStr(query.Get("gpp"))
if err != nil {
return gdpr.RequestInfo{GDPRSignal: gdpr.SignalAmbiguous}, err
gdprConsent, errs := parseConsentFromGppStr(query.Get("gpp"))
if len(errs) > 0 {
return gdpr.RequestInfo{GDPRSignal: gdpr.SignalAmbiguous}, errs[0]
}

return gdpr.RequestInfo{
Expand Down Expand Up @@ -305,13 +301,13 @@ func parseSignalFromGppSidStr(strSID string) (gdpr.Signal, error) {
return gdprSignal, nil
}

func parseConsentFromGppStr(gppQueryValue string) (string, error) {
func parseConsentFromGppStr(gppQueryValue string) (string, []error) {
var gdprConsent string

if len(gppQueryValue) > 0 {
gpp, err := gpplib.Parse(gppQueryValue)
if err != nil {
return "", err
gpp, errs := gpplib.Parse(gppQueryValue)
if len(errs) > 0 {
return "", errs
}

if i := gppPrivacy.IndexOfSID(gpp, gppConstants.SectionTCFEU2); i >= 0 {
Expand Down
10 changes: 5 additions & 5 deletions endpoints/setuid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ func TestParseSignalFromGPPSID(t *testing.T) {
func TestParseConsentFromGppStr(t *testing.T) {
type testOutput struct {
gdprConsent string
err error
err []error
}
testCases := []struct {
desc string
Expand All @@ -595,7 +595,7 @@ func TestParseConsentFromGppStr(t *testing.T) {
inGppQuery: "malformed",
expected: testOutput{
gdprConsent: "",
err: errors.New(`error parsing GPP header, base64 decoding: illegal base64 data at input byte 8`),
err: []error{errors.New(`error parsing GPP header, header must have type=3`)},
},
},
{
Expand All @@ -619,7 +619,7 @@ func TestParseConsentFromGppStr(t *testing.T) {
outConsent, outErr := parseConsentFromGppStr(tc.inGppQuery)

assert.Equal(t, tc.expected.gdprConsent, outConsent, tc.desc)
assert.Equal(t, tc.expected.err, outErr, tc.desc)
assert.ElementsMatch(t, tc.expected.err, outErr, tc.desc)
}
}

Expand Down Expand Up @@ -658,7 +658,7 @@ func TestParseGDPRFromGPP(t *testing.T) {
inUri: "/setuid?gpp=malformed",
expected: testOutput{
reqInfo: gdpr.RequestInfo{GDPRSignal: gdpr.SignalAmbiguous},
err: errors.New("error parsing GPP header, base64 decoding: illegal base64 data at input byte 8"),
err: errors.New("error parsing GPP header, header must have type=3"),
},
},
{
Expand Down Expand Up @@ -933,7 +933,7 @@ func TestExtractGDPRInfo(t *testing.T) {
inUri: "/setuid?gpp=malformed&gpp_sid=2",
expected: testOutput{
requestInfo: gdpr.RequestInfo{GDPRSignal: gdpr.SignalAmbiguous},
err: errors.New("error parsing GPP header, base64 decoding: illegal base64 data at input byte 8"),
err: errors.New("error parsing GPP header, header must have type=3"),
},
},
{
Expand Down
4 changes: 4 additions & 0 deletions exchange/gdpr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,7 @@ func (ms mockGPPSection) GetID() gppConstants.SectionID {
func (ms mockGPPSection) GetValue() string {
return ms.value
}

func (ms mockGPPSection) Encode(bool) []byte {
return nil
}
7 changes: 4 additions & 3 deletions exchange/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ func (rs *requestSplitter) cleanOpenRTBRequests(ctx context.Context,

var gpp gpplib.GppContainer
if req.BidRequest.Regs != nil && len(req.BidRequest.Regs.GPP) > 0 {
gpp, err = gpplib.Parse(req.BidRequest.Regs.GPP)
if err != nil {
errs = append(errs, err)
var gppErrs []error
gpp, gppErrs = gpplib.Parse(req.BidRequest.Regs.GPP)
if len(gppErrs) > 0 {
errs = append(errs, gppErrs[0])
}
}

Expand Down
4 changes: 4 additions & 0 deletions exchange/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3685,6 +3685,10 @@ func (gs GPPMockSection) GetValue() string {
return gs.value
}

func (gs GPPMockSection) Encode(bool) []byte {
return nil
}

func TestGdprFromGPP(t *testing.T) {
testCases := []struct {
name string
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ require (
github.com/mitchellh/copystructure v1.2.0
github.com/pkg/errors v0.9.1
github.com/prebid/go-gdpr v1.12.0
github.com/prebid/go-gpp v0.1.1
github.com/prebid/go-gpp v0.2.0
github.com/prebid/openrtb/v20 v20.1.0
github.com/prometheus/client_golang v1.12.1
github.com/prometheus/client_model v0.2.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,8 @@ github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndr
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
github.com/prebid/go-gdpr v1.12.0 h1:OrjQ7Uc+lCRYaOirQ48jjG/PBMvZsKNAaRTgzxN6iZ0=
github.com/prebid/go-gdpr v1.12.0/go.mod h1:mPZAdkRxn+iuSjaUuJAi9+0SppBOdM1PCzv/55UH3pY=
github.com/prebid/go-gpp v0.1.1 h1:uTMJ+eHmKWL9WvDuxFT4LDoOeJW1yOsfWITqi49ZuY0=
github.com/prebid/go-gpp v0.1.1/go.mod h1:b0TLoVln+HXFD9L9xeimxIH3FN8WDKPJ42auslxEkow=
github.com/prebid/go-gpp v0.2.0 h1:41Ssxd4Zxr50WgwG1q/1+6awGU3pFnwV7FR4XCLQSuM=
github.com/prebid/go-gpp v0.2.0/go.mod h1:b0TLoVln+HXFD9L9xeimxIH3FN8WDKPJ42auslxEkow=
github.com/prebid/openrtb/v20 v20.1.0 h1:Rb+Z3H3UxiqqnjgJK3R9Wt73ibrh7HPzG7ikBckQNqc=
github.com/prebid/openrtb/v20 v20.1.0/go.mod h1:hLBrA/APkSrxs5MaW639l+y/EAHivDfRagO2TX/wbSc=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
Expand Down
4 changes: 4 additions & 0 deletions privacy/ccpa/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,3 +922,7 @@ func (ms mockGPPSection) GetID() gppConstants.SectionID {
func (ms mockGPPSection) GetValue() string {
return ms.value
}

func (ms mockGPPSection) Encode(bool) []byte {
return nil
}

0 comments on commit 929ba61

Please sign in to comment.