Skip to content

Commit

Permalink
add error handling; prettify
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvialiu404 committed Jun 8, 2023
1 parent ef7d015 commit bf2a6be
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 104 deletions.
13 changes: 4 additions & 9 deletions gpp_parsed_consent.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,10 @@ func MapGppSectionToParser(s string) ([]GppSectionParser, error) {
gppSection = NewMspaUT(segments[i])
case SectionIDUSCT:
gppSection = NewMspaCT(segments[i])
default:
// Skip if no matching struct, as Section ID is not supported yet.
// Any newly supported Section IDs should be added as cases here.
// TODO: GPP error handling
}
if gppSection != nil {
gppSections = append(gppSections, gppSection)
}

// when the section id is not supported, append nullptr to indicate that this section is invalid
gppSections = append(gppSections, gppSection)
}
return gppSections, nil
}
Expand All @@ -163,8 +159,7 @@ func ParseGppConsent(s string) (map[int]GppParsedConsent, error) {
var consentErr error
consent, consentErr = gpp.ParseConsent()
if consentErr != nil {
// TODO: GPP error handling
// If an error, quietly do not add the consent value to map.
return nil, consentErr
} else {
gppConsents[gpp.GetSectionId()] = consent
}
Expand Down
54 changes: 27 additions & 27 deletions gpp_parsed_consent_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,37 +385,37 @@ var gppParsedMixedConsent = map[string]map[int]iabconsent.GppParsedConsent{
},
iabconsent.SectionIDUSNAT: &iabconsent.MspaParsedConsent{
Version: 1,
SharingNotice: 0,
SaleOptOutNotice: 1,
SharingOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 0,
SensitiveDataProcessingOptOutNotice: 0,
SensitiveDataLimitUseNotice: 1,
SaleOptOut: 0,
SharingOptOut: 0,
TargetedAdvertisingOptOut: 0,
SharingNotice: iabconsent.NoticeNotApplicable,
SaleOptOutNotice: iabconsent.NoticeProvided,
SharingOptOutNotice: iabconsent.NoticeNotApplicable,
TargetedAdvertisingOptOutNotice: iabconsent.NoticeNotApplicable,
SensitiveDataProcessingOptOutNotice: iabconsent.NoticeNotApplicable,
SensitiveDataLimitUseNotice: iabconsent.NoticeProvided,
SaleOptOut: iabconsent.OptOutNotApplicable,
SharingOptOut: iabconsent.OptOutNotApplicable,
TargetedAdvertisingOptOut: iabconsent.OptOutNotApplicable,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
2: 0,
3: 1,
4: 0,
5: 0,
6: 0,
7: 0,
8: 0,
9: 0,
10: 0,
11: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
2: iabconsent.ConsentNotApplicable,
3: iabconsent.NoConsent,
4: iabconsent.ConsentNotApplicable,
5: iabconsent.ConsentNotApplicable,
6: iabconsent.ConsentNotApplicable,
7: iabconsent.ConsentNotApplicable,
8: iabconsent.ConsentNotApplicable,
9: iabconsent.ConsentNotApplicable,
10: iabconsent.ConsentNotApplicable,
11: iabconsent.ConsentNotApplicable,
},
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
},
PersonalDataConsents: 0,
MspaCoveredTransaction: 2,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 0,
PersonalDataConsents: iabconsent.ConsentNotApplicable,
MspaCoveredTransaction: iabconsent.MspaNo,
MspaOptOutOptionMode: iabconsent.MspaYes,
MspaServiceProviderMode: iabconsent.MspaNotApplicable,
Gpc: false,
},
},
Expand Down
136 changes: 68 additions & 68 deletions mspa_parsed_consent_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ var usCAConsentFixtures = map[string]*iabconsent.MspaParsedConsent{
Version: 1,
SaleOptOutNotice: iabconsent.NoticeProvided,
SharingOptOutNotice: iabconsent.NoticeProvided,
SensitiveDataLimitUseNotice: 1,
SensitiveDataLimitUseNotice: iabconsent.NoticeProvided,
SaleOptOut: 2,
SharingOptOut: 2,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
Expand Down Expand Up @@ -233,106 +233,106 @@ var usCAConsentFixtures = map[string]*iabconsent.MspaParsedConsent{
var usCOConsentFixtures = map[string]*iabconsent.MspaParsedConsent{
"BAAAAAA.QA": {
Version: 1,
SharingNotice: 0,
SaleOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 0,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 0,
SharingNotice: iabconsent.NoticeNotApplicable,
SaleOptOutNotice: iabconsent.NoticeNotApplicable,
TargetedAdvertisingOptOutNotice: iabconsent.NoticeNotApplicable,
SaleOptOut: iabconsent.OptOutNotApplicable,
TargetedAdvertisingOptOut: iabconsent.OptOutNotApplicable,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
2: iabconsent.ConsentNotApplicable,
3: iabconsent.ConsentNotApplicable,
4: iabconsent.ConsentNotApplicable,
5: iabconsent.ConsentNotApplicable,
6: iabconsent.ConsentNotApplicable,
},
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{
0: iabconsent.ConsentNotApplicable,
},
MspaCoveredTransaction: 0,
MspaOptOutOptionMode: 0,
MspaServiceProviderMode: 0,
MspaCoveredTransaction: iabconsent.MspaNotApplicable,
MspaOptOutOptionMode: iabconsent.MspaNotApplicable,
MspaServiceProviderMode: iabconsent.MspaNotApplicable,
Gpc: false,
},
"BAABAFA.QA": {
Version: 1,
SharingNotice: 0,
SaleOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 0,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 0,
SharingNotice: iabconsent.NoticeNotApplicable,
SaleOptOutNotice: iabconsent.NoticeNotApplicable,
TargetedAdvertisingOptOutNotice: iabconsent.NoticeNotApplicable,
SaleOptOut: iabconsent.OptOutNotApplicable,
TargetedAdvertisingOptOut: iabconsent.OptOutNotApplicable,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
2: 0,
3: 1,
4: 0,
5: 0,
6: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
2: iabconsent.ConsentNotApplicable,
3: iabconsent.NoConsent,
4: iabconsent.ConsentNotApplicable,
5: iabconsent.ConsentNotApplicable,
6: iabconsent.ConsentNotApplicable,
},
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{
0: iabconsent.ConsentNotApplicable,
},
MspaCoveredTransaction: 1,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 0,
MspaCoveredTransaction: iabconsent.MspaYes,
MspaOptOutOptionMode: iabconsent.MspaYes,
MspaServiceProviderMode: iabconsent.MspaNotApplicable,
Gpc: false,
},
}

var usCTConsentFixtures = map[string]*iabconsent.MspaParsedConsent{
"BBABAACQ.YA": {
Version: 1,
SharingNotice: 0,
SaleOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 1,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 0,
SharingNotice: iabconsent.NoticeNotApplicable,
SaleOptOutNotice: iabconsent.NoticeNotApplicable,
TargetedAdvertisingOptOutNotice: iabconsent.NoticeProvided,
SaleOptOut: iabconsent.OptOutNotApplicable,
TargetedAdvertisingOptOut: iabconsent.OptOutNotApplicable,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
2: 0,
3: 1,
4: 0,
5: 0,
6: 0,
7: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
2: iabconsent.ConsentNotApplicable,
3: iabconsent.NoConsent,
4: iabconsent.ConsentNotApplicable,
5: iabconsent.ConsentNotApplicable,
6: iabconsent.ConsentNotApplicable,
7: iabconsent.ConsentNotApplicable,
},
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{
0: 0,
1: 0,
2: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.ConsentNotApplicable,
2: iabconsent.ConsentNotApplicable,
},
MspaCoveredTransaction: 0,
MspaOptOutOptionMode: 2,
MspaServiceProviderMode: 1,
MspaCoveredTransaction: iabconsent.MspaNotApplicable,
MspaOptOutOptionMode: iabconsent.MspaNo,
MspaServiceProviderMode: iabconsent.MspaYes,
Gpc: true,
},
}

var usUTConsentFixtures = map[string]*iabconsent.MspaParsedConsent{
"BGBEQRkA": {
Version: 1,
SharingNotice: 0,
SaleOptOutNotice: 1,
TargetedAdvertisingOptOutNotice: 2,
SensitiveDataProcessingOptOutNotice: 0,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 1,
SharingNotice: iabconsent.NoticeNotApplicable,
SaleOptOutNotice: iabconsent.NoticeProvided,
TargetedAdvertisingOptOutNotice: iabconsent.NoticeNotProvided,
SensitiveDataProcessingOptOutNotice: iabconsent.NoticeNotApplicable,
SaleOptOut: iabconsent.OptOutNotApplicable,
TargetedAdvertisingOptOut: iabconsent.OptedOut,
SensitiveDataProcessing: map[int]iabconsent.MspaConsent{
0: 0,
1: 1,
2: 0,
3: 1,
4: 0,
5: 0,
6: 1,
7: 0,
0: iabconsent.ConsentNotApplicable,
1: iabconsent.NoConsent,
2: iabconsent.ConsentNotApplicable,
3: iabconsent.NoConsent,
4: iabconsent.ConsentNotApplicable,
5: iabconsent.ConsentNotApplicable,
6: iabconsent.NoConsent,
7: iabconsent.ConsentNotApplicable,
},
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{0: 1},
MspaCoveredTransaction: 2,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 0,
KnownChildSensitiveDataConsents: map[int]iabconsent.MspaConsent{0: iabconsent.NoConsent},
MspaCoveredTransaction: iabconsent.MspaNo,
MspaOptOutOptionMode: iabconsent.MspaYes,
MspaServiceProviderMode: iabconsent.MspaNotApplicable,
},
}

0 comments on commit bf2a6be

Please sign in to comment.