Skip to content

UOE-12855: Fix [Google SDK]: Getting 400 bad request when consented_p… #1129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 69 additions & 23 deletions modules/pubmatic/openwrap/sdk/googlesdk/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,39 +238,85 @@ func modifyRequestWithGoogleFeature(request *openrtb2.BidRequest, features featu
}

func modifyRequestWithStaticData(request *openrtb2.BidRequest) {
if len(request.Imp) == 0 {
if request == nil {
return
}

// Always set secure to 1
request.Imp[0].Secure = ptrutil.ToPtr(int8(1))
if len(request.Imp) > 0 {
// Always set secure to 1
request.Imp[0].Secure = ptrutil.ToPtr(int8(1))

//Set gpid
if len(request.Imp[0].TagID) > 0 {
request.Imp[0].Ext, _ = jsonparser.Set(request.Imp[0].Ext, []byte(strconv.Quote(request.Imp[0].TagID)), "gpid")
}
//Set gpid
if len(request.Imp[0].TagID) > 0 {
request.Imp[0].Ext, _ = jsonparser.Set(request.Imp[0].Ext, []byte(strconv.Quote(request.Imp[0].TagID)), "gpid")
}

// Remove metric
request.Imp[0].Metric = nil
// Remove metric
request.Imp[0].Metric = nil

// Remove banner if impression is rewarded and banner and video both are present
if request.Imp[0].Rwdd == 1 && request.Imp[0].Banner != nil && request.Imp[0].Video != nil {
request.Imp[0].Banner = nil
}
// Remove banner if impression is rewarded and banner and video both are present
if request.Imp[0].Rwdd == 1 && request.Imp[0].Banner != nil && request.Imp[0].Video != nil {
request.Imp[0].Banner = nil
}

// Remove unsupported fields from banner
if request.Imp[0].Banner != nil {
request.Imp[0].Banner.WMin = 0
request.Imp[0].Banner.HMin = 0
request.Imp[0].Banner.WMax = 0
request.Imp[0].Banner.HMax = 0
// Remove unsupported fields from banner
if request.Imp[0].Banner != nil {
request.Imp[0].Banner.WMin = 0
request.Imp[0].Banner.HMin = 0
request.Imp[0].Banner.WMax = 0
request.Imp[0].Banner.HMax = 0
}

// Remove native from request
request.Imp[0].Native = nil

// Remove video from request
request.Imp[0].Video = nil
}

// Remove native from request
request.Imp[0].Native = nil
// change data type of user.ext.consented_providers_settings.consented_providers from []string to []int
if request.User != nil && request.User.Ext != nil {
var userExt map[string]interface{}
var err error

err = jsoniterator.Unmarshal(request.User.Ext, &userExt)
if err != nil {
return
}

providerSettings, ok := userExt["consented_providers_settings"].(map[string]interface{})
if !ok {
return
}

consentedProviders, ok := providerSettings["consented_providers"].([]interface{})
if !ok {
return
}

var consentedProvidersInt []int
for i := range consentedProviders {
provider, ok := consentedProviders[i].(string)
if !ok {
continue
}

providerInt, err := strconv.Atoi(provider)
if err != nil {
continue
}

consentedProvidersInt = append(consentedProvidersInt, providerInt)
}

// Remove video from request
request.Imp[0].Video = nil
providerSettings["consented_providers"] = consentedProvidersInt
userExt["consented_providers_settings"] = providerSettings

request.User.Ext, err = jsoniterator.Marshal(userExt)
if err != nil {
glog.Errorf("[GoogleSDK] [Error]: failed to marshal user ext %v", err)
}
}
}

func modifyRequestWithSignalData(request *openrtb2.BidRequest, signalData *openrtb2.BidRequest) {
Expand Down
116 changes: 116 additions & 0 deletions modules/pubmatic/openwrap/sdk/googlesdk/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1619,6 +1619,122 @@ func TestModifyRequestWithStaticData(t *testing.T) {
},
},
},
{
name: "Convert consented_providers from string array to int array",
request: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":["1","2","3"]}}`),
},
},
expectedResult: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":[1,2,3]}}`),
},
},
},
{
name: "Handle mixed valid and invalid string values in consented_providers",
request: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":["1","invalid","3"]}}`),
},
},
expectedResult: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":[1,3]}}`),
},
},
},
{
name: "No change when consented_providers_settings is missing",
request: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"other_field":"value"}`),
},
},
expectedResult: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"other_field":"value"}`),
},
},
},
{
name: "No change when consented_providers is not an array",
request: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":"not_an_array"}}`),
},
},
expectedResult: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Secure: ptrutil.ToPtr(int8(1)),
},
},
User: &openrtb2.User{
Ext: []byte(`{"consented_providers_settings":{"consented_providers":"not_an_array"}}`),
},
},
},
{
name: "Remove native and video from request",
request: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Native: &openrtb2.Native{
Request: `{"native":{"layout":1}}`,
},
Video: &openrtb2.Video{
MIMEs: []string{"video/mp4"},
},
},
},
},
expectedResult: &openrtb2.BidRequest{
Imp: []openrtb2.Imp{
{
Native: nil,
Video: nil,
Secure: ptrutil.ToPtr(int8(1)),
},
},
},
},
}

for _, tt := range tests {
Expand Down
Loading