Skip to content
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

AMP additionalConsent #2378

Merged
merged 24 commits into from
Oct 24, 2022
Merged

AMP additionalConsent #2378

merged 24 commits into from
Oct 24, 2022

Conversation

guscarreon
Copy link
Contributor

This pull request implements the second part of issue #1817. Particularly, the addtl_consent query field described in point number 5 of the issue's description:

  1. If addtl_consent is supplied, copy its value to user.ext.ConsentedProvidersSettings.consented_providers

According to specs, is set independently of the consent_type. This pull request's core change happens inside the endpoints/openrtb2/amp_auction.go and is shown below:

436     setAmpExt(req.Site, "1")
437
438     setEffectiveAmpPubID(req, ampParams.Account)
439
440     if ampParams.Slot != "" {
441         req.Imp[0].TagID = ampParams.Slot
442     }
443
    +   if err := setConsentedProviders(req, ampParams); err != nil {
    +       return []error{err}
    +   }
    +
444     policyWriter, policyWriterErr := amp.ReadPolicy(ampParams, deps.cfg.GDPR.Enabled)
445     if policyWriterErr != nil {
446         return []error{policyWriterErr}
447     }
endpoints/openrtb2/amp_auction.go

All other changes are to support or test the addition shown above.

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, comments related to test coverage

Comment on lines 479 to 484
} else {
return err
}
if err := reqWrap.RebuildRequest(); err != nil {
return err
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to add tests to trigger these errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added two additional test cases.

Comment on lines 341 to 344
if hasCPSettings {
ue.consentedProvidersSettings = &ExtUserCPSettings{}
if err := json.Unmarshal(consentedProviderSettingsJson, ue.consentedProvidersSettings); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block isn't covered by tests, can this be covered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Added a bunch of tests to cover this entire function and some other scenarios.

Comment on lines 402 to 405
delete(ue.ext, "ConsentedProvidersSettings")
}
} else {
delete(ue.ext, "ConsentedProvidersSettings")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can these delete cases be covered?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Covered

Comment on lines 383 to 384
inAdditionalConsent string
inBidRequest *openrtb2.BidRequest
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick: Could these be renamed to givenAdditionalConsent and givenBidRequest?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}
reqWrap := &openrtb_ext.RequestWrapper{BidRequest: req}

// set GDPR value
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can delete this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed


if req.User == nil {
req.User = &openrtb2.User{}
// set Consent string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can delete this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleted

@@ -446,6 +446,10 @@ func (deps *endpointDeps) overrideWithParams(ampParams amp.Params, req *openrtb2
req.Imp[0].TagID = ampParams.Slot
}

if err := setConsentedProviders(req, ampParams); err != nil {
return []error{err}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error return isn't covered by tests, is it possible to cover/trigger this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TestOverrideWithParams to add coverage to various uncovered scenarios in the overrideWithParams function.

// this field is dirty
if ue.consentedProvidersDirty {
if ue.consentedProvidersSettings == nil {
ue.consentedProvidersSettings = &ExtUserCPSettings{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is not covered by tests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added test to cover line 385

@@ -10,6 +10,8 @@ type ExtUser struct {
// https://iabtechlab.com/wp-content/uploads/2018/02/OpenRTB_Advisory_GDPR_2018-02.pdf
Consent string `json:"consent,omitempty"`

ConsentedProvidersSettings *ExtUserCPSettings `json:"ConsentedProvidersSettings,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it a reason json mapping value starts from uppercase? Feels like it should start from lowercase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does look odd but I used the exact format described in issue #1817 and that's also how it was implemented in Prebid Server Java. Below an excerpt from a PBS-Java JSON test file:

 70   "user": {
 71     "buyeruid": "J5VLCWQP-26-CWFT",
 72     "ext": {
 73       "ConsentedProvidersSettings": {
 74         "consented_providers": "someConsent"
 75       }
 76     }
 77   },
./src/test/resources/org/prebid/server/it/amp/test-rubicon-bid-request.json

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

json mapping is not case sensitive, it should work with ConsentedProvidersSettings and consentedproviderssettings. We can discuss it with the team.

@@ -333,6 +337,13 @@ func (ue *UserExt) unmarshal(extJson json.RawMessage) error {
}
}

if consentedProviderSettingsJson, hasCPSettings := ue.ext["ConsentedProvidersSettings"]; hasCPSettings {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please extract this value to constant - you use it in many places. Also should it start from lowercase?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what value to put into a constant. consentedProviderSettingsJson? Inside (ue *UserExt) unmarshal(extJson json.RawMessage) error it is only used once.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I meant string constant "ConsentedProvidersSettings"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this string been extracted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has not, corrected

eidsDirty bool
consentedProvidersSettings *ExtUserCPSettings
consentedProvidersSettingsDirty bool
consentedProviders string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think it will be easier to handle consentedProvidersSettings *ExtUserCPSettings only? Keep track of consentedProviders looks redundant.
Look at `other fields - there is just one tracker for each object, no trackers for nested fields. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, modified to get rid of this unecessary field in openrtb_ext/request_wrapper.go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gus, I meant to keep track of object, not field.

consentedProvidersSettings      *ExtUserCPSettings -> leave this
	consentedProvidersSettingsDirty bool
	consentedProviders              string -> remove this
	consentedProvidersDirty         bool

In case you add more fields to the object - it will have everything to keep track of it without significant changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️
I misread your comment.

Copy link
Contributor

@AlexBVolcy AlexBVolcy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's looks good. Just left one comment

@@ -333,6 +337,13 @@ func (ue *UserExt) unmarshal(extJson json.RawMessage) error {
}
}

if consentedProviderSettingsJson, hasCPSettings := ue.ext["ConsentedProvidersSettings"]; hasCPSettings {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this string been extracted?

AlexBVolcy
AlexBVolcy previously approved these changes Oct 13, 2022
AlexBVolcy
AlexBVolcy previously approved these changes Oct 21, 2022
Copy link
Contributor

@VeronikaSolovei9 VeronikaSolovei9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit messages are pure gold. LGTM

@bsardo bsardo merged commit 718628c into prebid:master Oct 24, 2022
shunj-nb pushed a commit to ParticleMedia/prebid-server that referenced this pull request Nov 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants