Skip to content

Commit

Permalink
Revert "GPC: Set extension based on header (prebid#3895)"
Browse files Browse the repository at this point in the history
This reverts commit 96cbdb3.
  • Loading branch information
krdzo authored Oct 30, 2024
1 parent b65d549 commit 4d0d8e0
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 289 deletions.
28 changes: 0 additions & 28 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ const observeBrowsingTopicsValue = "?1"

var (
dntKey string = http.CanonicalHeaderKey("DNT")
secGPCKey string = http.CanonicalHeaderKey("Sec-GPC")
dntDisabled int8 = 0
dntEnabled int8 = 1
notAmp int8 = 0
Expand Down Expand Up @@ -1498,11 +1497,6 @@ func (deps *endpointDeps) setFieldsImplicitly(httpReq *http.Request, r *openrtb_

setAuctionTypeImplicitly(r)

err := setGPCImplicitly(httpReq, r)
if err != nil {
return []error{err}
}

errs := setSecBrowsingTopicsImplicitly(httpReq, r, account)
return errs
}
Expand All @@ -1522,28 +1516,6 @@ func setAuctionTypeImplicitly(r *openrtb_ext.RequestWrapper) {
}
}

func setGPCImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper) error {
secGPC := httpReq.Header.Get(secGPCKey)

if secGPC != "1" {
return nil
}

regExt, err := r.GetRegExt()
if err != nil {
return err
}

if regExt.GetGPC() != nil {
return nil
}

gpc := "1"
regExt.SetGPC(&gpc)

return nil
}

// setSecBrowsingTopicsImplicitly updates user.data with data from request header 'Sec-Browsing-Topics'
func setSecBrowsingTopicsImplicitly(httpReq *http.Request, r *openrtb_ext.RequestWrapper, account *config.Account) []error {
secBrowsingTopics := httpReq.Header.Get(secBrowsingTopics)
Expand Down
169 changes: 0 additions & 169 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5618,175 +5618,6 @@ func TestValidateOrFillCookieDeprecation(t *testing.T) {
}
}

func TestSetGPCImplicitly(t *testing.T) {
testCases := []struct {
description string
header string
regs *openrtb2.Regs
expectError bool
expectedRegs *openrtb2.Regs
}{
{
description: "regs_ext_gpc_not_set_and_header_is_1",
header: "1",
regs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
},
{
description: "sec_gpc_header_not_set_gpc_should_not_be_modified",
header: "",
regs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
},
{
description: "sec_gpc_header_set_to_2_gpc_should_not_be_modified",
header: "2",
regs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
},
{
description: "sec_gpc_header_set_to_1_and_regs_ext_contains_other_data",
header: "1",
regs: &openrtb2.Regs{
Ext: []byte(`{"some_other_field":"some_value"}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"some_other_field":"some_value","gpc":"1"}`),
},
},
{
description: "regs_ext_gpc_not_set_and_header_not_set",
header: "",
regs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
},
{
description: "regs_ext_gpc_not_set_and_header_not_1",
header: "0",
regs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{}`),
},
},
{
description: "regs_ext_gpc_is_1_and_header_is_1",
header: "1",
regs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
},
{
description: "regs_ext_gpc_is_1_and_header_not_1",
header: "0",
regs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
},
{
description: "regs_ext_other_data_and_header_is_1",
header: "1",
regs: &openrtb2.Regs{
Ext: []byte(`{"other":"value"}`),
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"other":"value","gpc":"1"}`),
},
},
{
description: "regs_nil_and_header_is_1",
header: "1",
regs: nil,
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: []byte(`{"gpc":"1"}`),
},
},
{
description: "regs_nil_and_header_not_set",
header: "",
regs: nil,
expectError: false,
expectedRegs: nil,
},
{
description: "regs_ext_is_nil_and_header_not_set",
header: "",
regs: &openrtb2.Regs{
Ext: nil,
},
expectError: false,
expectedRegs: &openrtb2.Regs{
Ext: nil,
},
},
}

for _, test := range testCases {
t.Run(test.description, func(t *testing.T) {
httpReq := &http.Request{
Header: http.Header{
http.CanonicalHeaderKey("Sec-GPC"): []string{test.header},
},
}

r := &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Regs: test.regs,
},
}

err := setGPCImplicitly(httpReq, r)

if test.expectError {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.NoError(t, r.RebuildRequest())
if test.expectedRegs == nil {
assert.Nil(t, r.BidRequest.Regs)
} else if test.expectedRegs.Ext == nil {
assert.Nil(t, r.BidRequest.Regs.Ext)
} else {
assert.JSONEq(t, string(test.expectedRegs.Ext), string(r.BidRequest.Regs.Ext))
}
})
}
}

func TestValidateRequestCookieDeprecation(t *testing.T) {
testCases :=
[]struct {
Expand Down
38 changes: 1 addition & 37 deletions openrtb_ext/request_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const (
schainKey = "schain"
us_privacyKey = "us_privacy"
cdepKey = "cdep"
gpcKey = "gpc"
)

// LenImp returns the number of impressions without causing the creation of ImpWrapper objects.
Expand Down Expand Up @@ -1202,8 +1201,6 @@ type RegExt struct {
dsaDirty bool
gdpr *int8
gdprDirty bool
gpc *string
gpcDirty bool
usPrivacy string
usPrivacyDirty bool
}
Expand Down Expand Up @@ -1247,13 +1244,6 @@ func (re *RegExt) unmarshal(extJson json.RawMessage) error {
}
}

gpcJson, hasGPC := re.ext[gpcKey]
if hasGPC && gpcJson != nil {
if err := jsonutil.Unmarshal(gpcJson, &re.gpc); err != nil {
return err
}
}

return nil
}

Expand Down Expand Up @@ -1297,19 +1287,6 @@ func (re *RegExt) marshal() (json.RawMessage, error) {
re.usPrivacyDirty = false
}

if re.gpcDirty {
if re.gpc != nil {
rawjson, err := jsonutil.Marshal(re.gpc)
if err != nil {
return nil, err
}
re.ext[gpcKey] = rawjson
} else {
delete(re.ext, gpcKey)
}
re.gpcDirty = false
}

re.extDirty = false
if len(re.ext) == 0 {
return nil, nil
Expand All @@ -1318,7 +1295,7 @@ func (re *RegExt) marshal() (json.RawMessage, error) {
}

func (re *RegExt) Dirty() bool {
return re.extDirty || re.dsaDirty || re.gdprDirty || re.usPrivacyDirty || re.gpcDirty
return re.extDirty || re.dsaDirty || re.gdprDirty || re.usPrivacyDirty
}

func (re *RegExt) GetExt() map[string]json.RawMessage {
Expand Down Expand Up @@ -1360,19 +1337,6 @@ func (re *RegExt) SetGDPR(gdpr *int8) {
re.gdprDirty = true
}

func (re *RegExt) GetGPC() *string {
if re.gpc == nil {
return nil
}
gpc := *re.gpc
return &gpc
}

func (re *RegExt) SetGPC(gpc *string) {
re.gpc = gpc
re.gpcDirty = true
}

func (re *RegExt) GetUSPrivacy() string {
uSPrivacy := re.usPrivacy
return uSPrivacy
Expand Down
55 changes: 0 additions & 55 deletions openrtb_ext/request_wrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2174,30 +2174,6 @@ func TestRebuildRegExt(t *testing.T) {
regExt: RegExt{usPrivacy: "", usPrivacyDirty: true},
expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}},
},
{
name: "req_regs_gpc_populated_-_not_dirty_-_no_change",
request: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
regExt: RegExt{},
expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
},
{
name: "req_regs_gpc_populated_-_dirty_and_different-_change",
request: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
regExt: RegExt{gpc: &strB, gpcDirty: true},
expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"b"}`)}},
},
{
name: "req_regs_gpc_populated_-_dirty_and_same_-_no_change",
request: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
regExt: RegExt{gpc: &strA, gpcDirty: true},
expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
},
{
name: "req_regs_gpc_populated_-_dirty_and_nil_-_cleared",
request: openrtb2.BidRequest{Regs: &openrtb2.Regs{Ext: json.RawMessage(`{"gpc":"a"}`)}},
regExt: RegExt{gpc: nil, gpcDirty: true},
expectedRequest: openrtb2.BidRequest{Regs: &openrtb2.Regs{}},
},
}

for _, tt := range tests {
Expand All @@ -2218,7 +2194,6 @@ func TestRegExtUnmarshal(t *testing.T) {
extJson json.RawMessage
expectDSA *ExtRegsDSA
expectGDPR *int8
expectGPC *string
expectUSPrivacy string
expectError bool
}{
Expand Down Expand Up @@ -2278,21 +2253,6 @@ func TestRegExtUnmarshal(t *testing.T) {
expectGDPR: ptrutil.ToPtr[int8](0),
expectError: true,
},
// GPC
{
name: "valid_gpc_json",
regExt: &RegExt{},
extJson: json.RawMessage(`{"gpc":"some_value"}`),
expectGPC: ptrutil.ToPtr("some_value"),
expectError: false,
},
{
name: "malformed_gpc_json",
regExt: &RegExt{},
extJson: json.RawMessage(`{"gpc":nill}`),
expectGPC: nil,
expectError: true,
},
// us_privacy
{
name: "valid_usprivacy_json",
Expand Down Expand Up @@ -2388,18 +2348,3 @@ func TestRegExtGetGDPRSetGDPR(t *testing.T) {
assert.Equal(t, regExtGDPR, gdpr)
assert.NotSame(t, regExtGDPR, gdpr)
}

func TestRegExtGetGPCSetGPC(t *testing.T) {
regExt := &RegExt{}
regExtGPC := regExt.GetGPC()
assert.Nil(t, regExtGPC)
assert.False(t, regExt.Dirty())

gpc := ptrutil.ToPtr("Gpc")
regExt.SetGPC(gpc)
assert.True(t, regExt.Dirty())

regExtGPC = regExt.GetGPC()
assert.Equal(t, regExtGPC, gpc)
assert.NotSame(t, regExtGPC, gpc)
}

0 comments on commit 4d0d8e0

Please sign in to comment.