forked from prebid/go-gpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse_test.go
148 lines (142 loc) · 4.5 KB
/
parse_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package gpp
import (
"fmt"
"testing"
"github.com/prebid/go-gpp/constants"
"github.com/prebid/go-gpp/sections"
"github.com/prebid/go-gpp/sections/uspca"
"github.com/prebid/go-gpp/sections/uspva"
"github.com/stretchr/testify/assert"
)
type gppTestData struct {
description string
gppString string
expected GppContainer
expectedError []error
}
func TestParse(t *testing.T) {
testData := map[string]gppTestData{
"GPP-tcf": {
description: "GPP string with EU TCF V2",
gppString: "DBABMA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{2},
Sections: []Section{GenericSection{sectionID: 2,
value: "CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA"}},
},
},
"GPP-tcv-usp": {
description: "GPP string with EU TCF v2 and US Privacy",
gppString: "DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{2, 6},
Sections: []Section{GenericSection{sectionID: 2,
value: "CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA"},
GenericSection{sectionID: 6,
value: "1YNN"}},
},
},
"GPP-tcfca-usp": {
description: "GPP string with Canadian TCF and US Privacy",
gppString: "DBABjw~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{5, 6},
Sections: []Section{GenericSection{sectionID: 5,
value: "CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA"},
GenericSection{sectionID: 6,
value: "1YNN"}},
},
},
"GPP-uspca": {
description: "GPP string with USPCA",
gppString: "DBABBgA~xlgWEYCZAA",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{8},
Sections: []Section{uspca.USPCA{
CoreSegment: uspca.USPCACoreSegment{
Version: 49,
SaleOptOutNotice: 2,
SharingOptOutNotice: 1,
SensitiveDataLimitUseNotice: 1,
SaleOptOut: 2,
SharingOptOut: 0,
SensitiveDataProcessing: []byte{
0, 1, 1, 2, 0, 1, 0, 1, 2,
},
KnownChildSensitiveDataConsents: []byte{
0, 0,
},
PersonalDataConsents: 0,
MspaCoveredTransaction: 2,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 2,
},
GPCSegment: sections.CommonUSGPCSegment{
SubsectionType: 1,
Gpc: false,
},
SectionID: 8,
Value: "xlgWEYCZAA"},
},
},
},
"GPP-uspva": {
description: "GPP string with USPVA",
gppString: "DBABRgA~bSFgmiU",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{9},
Sections: []Section{uspva.USPVA{
CoreSegment: sections.CommonUSCoreSegment{
Version: 27,
SharingNotice: 1,
SaleOptOutNotice: 0,
TargetedAdvertisingOptOutNotice: 2,
SaleOptOut: 0,
TargetedAdvertisingOptOut: 1,
SensitiveDataProcessing: []byte{
1, 2, 0, 0, 2, 1, 2, 2,
},
KnownChildSensitiveDataConsents: []byte{0},
MspaCoveredTransaction: 2,
MspaOptOutOptionMode: 1,
MspaServiceProviderMode: 1,
},
SectionID: 9,
Value: "bSFgmiU"},
},
},
},
"GPP-tcf-error": {
description: "GPP string with EU TCF V2",
gppString: "DBGBMA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA",
expected: GppContainer{
Version: 1,
SectionTypes: []constants.SectionID{2},
Sections: []Section{GenericSection{sectionID: 2,
value: "CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA"}},
},
expectedError: []error{fmt.Errorf("error parsing GPP header, section identifiers: error reading an int offset value in a Range(Fibonacci) entry(1): error reading bit 4 of Integer(Fibonacci): expected 1 bit at bit 32, but the byte array was only 4 bytes long")},
},
"GPP-uspca-error": {
description: "GPP string with USPCA",
gppString: "DBABBgA~xlgWE",
expectedError: []error{fmt.Errorf("error parsing uspca consent string: illegal base64 data at input byte 4")},
},
}
for name, test := range testData {
t.Run(name, func(t *testing.T) {
result, err := Parse(test.gppString)
if len(test.expectedError) == 0 {
assert.Nil(t, err)
assert.Equal(t, test.expected, result)
} else {
assert.Equal(t, test.expectedError, err)
}
})
}
}