Skip to content

Commit

Permalink
prc
Browse files Browse the repository at this point in the history
  • Loading branch information
pm-nilesh-chate committed Feb 28, 2024
1 parent c7bee8e commit a09ead0
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 8 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,8 @@ func SetupViper(v *viper.Viper, filename string, bidderInfos BidderInfos) {
v.SetDefault("account_defaults.price_floors.fetch.max_age_sec", 86400)
v.SetDefault("account_defaults.price_floors.fetch.period_sec", 3600)
v.SetDefault("account_defaults.price_floors.fetch.max_schema_dims", 0)
v.SetDefault("account_defaults.privacy.privacysandbox.cookiedeprecation.enabled", false)
v.SetDefault("account_defaults.privacy.privacysandbox.cookiedeprecation.ttl_sec", 604800)

v.SetDefault("account_defaults.events_enabled", false)
v.SetDefault("account_defaults.privacy.ipv6.anon_keep_bits", 56)
Expand Down
2 changes: 2 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,8 @@ func TestDefaults(t *testing.T) {
cmpInts(t, "account_defaults.price_floors.fetch.period_sec", 3600, cfg.AccountDefaults.PriceFloors.Fetcher.Period)
cmpInts(t, "account_defaults.price_floors.fetch.max_age_sec", 86400, cfg.AccountDefaults.PriceFloors.Fetcher.MaxAge)
cmpInts(t, "account_defaults.price_floors.fetch.max_schema_dims", 0, cfg.AccountDefaults.PriceFloors.Fetcher.MaxSchemaDims)
cmpBools(t, "account_defaults.privacy.privacysandbox.cookiedeprecation.enabled", false, cfg.AccountDefaults.Privacy.PrivacySandbox.CookieDeprecation.Enabled)
cmpInts(t, "account_defaults.privacy.privacysandbox.cookiedeprecation.ttl_sec", 604800, cfg.AccountDefaults.Privacy.PrivacySandbox.CookieDeprecation.TTLSec)

cmpBools(t, "account_defaults.events.enabled", false, cfg.AccountDefaults.Events.Enabled)

Expand Down
6 changes: 3 additions & 3 deletions endpoints/cookie_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,11 @@ func (c *cookieSyncEndpoint) setCookieDeprecationHeader(w http.ResponseWriter, r
SameSite: http.SameSiteNoneMode,
Expires: c.time.Now().Add(time.Second * time.Duration(account.Privacy.PrivacySandbox.CookieDeprecation.TTLSec)),
}
setCookie(w, cookie)
setCookiePartitioned(w, cookie)
}

// setCookie temporary substitute for http.SetCookie(w, cookie) until it supports Partitioned cookie type. Refer https://github.com/golang/go/issues/62490
func setCookie(w http.ResponseWriter, cookie *http.Cookie) {
// setCookiePartitioned temporary substitute for http.SetCookie(w, cookie) until it supports Partitioned cookie type. Refer https://github.com/golang/go/issues/62490
func setCookiePartitioned(w http.ResponseWriter, cookie *http.Cookie) {
if v := cookie.String(); v != "" {
w.Header().Add("Set-Cookie", v+"; Partitioned;")
}
Expand Down
2 changes: 2 additions & 0 deletions endpoints/cookie_sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2289,6 +2289,7 @@ func TestSetCookieDeprecationHeader(t *testing.T) {
name: "not-present-account-nil",
request: getTestRequest(false),
responseWriter: httptest.NewRecorder(),
account: nil,
expectedCookieDeprecationHeader: false,
},
{
Expand Down Expand Up @@ -2342,6 +2343,7 @@ func TestSetCookieDeprecationHeader(t *testing.T) {
name: "present-account-nil",
request: getTestRequest(true),
responseWriter: httptest.NewRecorder(),
account: nil,
expectedCookieDeprecationHeader: false,
},
{
Expand Down
14 changes: 9 additions & 5 deletions endpoints/openrtb2/auction.go
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,15 @@ func validateOrFillCDep(httpReq *http.Request, req *openrtb_ext.RequestWrapper,
return nil
}

deviceExt, err := req.GetDeviceExt()
if err != nil {
return err
}

if deviceExt.GetCDep() != "" {
return nil
}

secCookieDeprecation := httpReq.Header.Get(secCookieDeprecation)
if secCookieDeprecation == "" {
return nil
Expand All @@ -1943,11 +1952,6 @@ func validateOrFillCDep(httpReq *http.Request, req *openrtb_ext.RequestWrapper,
}
}

deviceExt, err := req.GetDeviceExt()
if err != nil {
return err
}

deviceExt.SetCDep(secCookieDeprecation)
return nil
}
Expand Down
29 changes: 29 additions & 0 deletions endpoints/openrtb2/auction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6169,6 +6169,9 @@ func TestValidateOrFillCDep(t *testing.T) {
name: "cookie-deprecation-enabled-header-not-present-in-request",
args: args{
httpReq: &http.Request{},
req: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{},
},
account: config.Account{
Privacy: config.AccountPrivacy{
PrivacySandbox: config.PrivacySandbox{
Expand Down Expand Up @@ -6285,6 +6288,32 @@ func TestValidateOrFillCDep(t *testing.T) {
WarningCode: errortypes.SecCookieDeprecationLenWarningCode,
},
},
{
name: "header-present-request-device-ext-cdep-present",
args: args{
httpReq: &http.Request{
Header: http.Header{secCookieDeprecation: []string{"example_label_1"}},
},
req: &openrtb_ext.RequestWrapper{
BidRequest: &openrtb2.BidRequest{
Device: &openrtb2.Device{
Ext: json.RawMessage(`{"foo":"bar","cdep":"example_label_2"}`),
},
},
},
account: config.Account{
Privacy: config.AccountPrivacy{
PrivacySandbox: config.PrivacySandbox{
CookieDeprecation: config.CookieDeprecation{
Enabled: true,
},
},
},
},
},
wantDeviceExt: json.RawMessage(`{"foo":"bar","cdep":"example_label_2"}`),
wantErr: nil,
},
{
name: "header-present-request-device-ext-invalid",
args: args{
Expand Down

0 comments on commit a09ead0

Please sign in to comment.