Skip to content

Commit

Permalink
Make sure that if AdVerification is empty, drop it
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-kosolapov-zattoo committed Jul 19, 2024
1 parent 6ae503b commit 3274613
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
11 changes: 5 additions & 6 deletions extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ type Extension struct {
Type string `xml:"type,attr,omitempty"`
CustomTracking []Tracking `xml:"CustomTracking>Tracking,omitempty" json:",omitempty"`
// AdVerifications are IAB Open Measurement tags backported to VAST 2 and 3 as an extension
// TODO: Fix marshal to conditionally remove it?
AdVerifications []Verification `xml:"AdVerifications>Verification,omitempty" json:",omitempty"`
Data string `xml:",innerxml" json:",omitempty"`
AdVerifications *[]Verification `xml:"AdVerifications>Verification,omitempty" json:",omitempty"`
Data string `xml:",innerxml" json:",omitempty"`
}

// the extension type as a middleware in the encoding process.
Expand All @@ -27,8 +26,8 @@ func (e Extension) MarshalXML(enc *xml.Encoder, start xml.StartElement) error {
// it and return it's encoding.
var e2 interface{}
// if we have custom trackers or ad verifications, we should ignore the data, if not, then we
// should consider only the data.
if len(e.CustomTracking) == 0 || len(e.AdVerifications) == 0 {
// should consider only the data
if len(e.CustomTracking) == 0 && (e.AdVerifications == nil || len(*e.AdVerifications) == 0) {
e2 = extensionOnlyData{Type: e.Type, Data: e.Data}
} else {
e2 = extension{Type: e.Type, CustomTracking: e.CustomTracking, AdVerifications: e.AdVerifications}
Expand All @@ -52,7 +51,7 @@ func (e *Extension) UnmarshalXML(dec *xml.Decoder, start xml.StartElement) error
e.AdVerifications = e2.AdVerifications

// copy the data only if customTracking and adVerifications are empty
if len(e.CustomTracking) == 0 && len(e.AdVerifications) == 0 {
if len(e.CustomTracking) == 0 && (e.AdVerifications == nil || len(*e.AdVerifications) == 0) {
e.Data = e2.Data
}
return nil
Expand Down
24 changes: 12 additions & 12 deletions extension_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@ func TestExtensionCustomAdVerification(t *testing.T) {
// assert the resulting extension
assert.Equal(t, "AdVerifications", e.Type)
assert.Empty(t, e.Data)
if assert.Len(t, e.AdVerifications, 1) {
assert.Equal(t, "doubleclickbygoogle.com-omid-video", e.AdVerifications[0].Vendor)
if assert.Len(t, e.AdVerifications[0].JavaScriptResource, 1) {
if assert.NotNil(t, e.AdVerifications) && assert.Len(t, *e.AdVerifications, 1) {
assert.Equal(t, "doubleclickbygoogle.com-omid-video", (*e.AdVerifications)[0].Vendor)
if assert.Len(t, (*e.AdVerifications)[0].JavaScriptResource, 1) {
assert.Equal(t, JavaScriptResource{
ApiFramework: "omid",
BrowserOptional: true,
URI: "https://example.com/verify.js",
}, e.AdVerifications[0].JavaScriptResource[0])
}, (*e.AdVerifications)[0].JavaScriptResource[0])
}
if assert.Len(t, e.AdVerifications[0].TrackingEvents, 1) {
if assert.Len(t, (*e.AdVerifications)[0].TrackingEvents, 1) {
assert.Equal(t, Tracking{
Event: "verificationNotExecuted",
URI: "https://pagead2.googlesyndication.com/pagead/interaction/?ai=Bt7src9CCZofvMqChiM0Pi8qQkAPFnbOVRgAAABABII64hW84AVjUt8DBgwRglfrwgYwHsgETZ29vZ2xlYWRzLmdpdGh1Yi5pb7oBCjcyOHg5MF94bWzIAQXaATRodHRwczovL2dvb2dsZWFkcy5naXRodWIuaW8vZ29vZ2xlYWRzLWltYS1odG1sNS92c2kvwAIC4AIA6gIlLzIxNzc1NzQ0OTIzL2V4dGVybmFsL3V0aWxpdHlfc2FtcGxlc_gC8NEegAMBkAPIBpgD4AOoAwHgBAHSBQYQj6GjiRagBiOoB7i-sQKoB5oGqAfz0RuoB5bYG6gHqpuxAqgHg62xAqgH4L2xAqgH_56xAqgH35-xAqgH-MKxAqgH-8KxAtgHAdIIMQiR4YBwEAEYHTIH64uA7r-AAToPgNCAgICAhAiAgICAgJQuSL39wTpY1cHtiZmGhwPYCAKACgWYCwGqDQJERdAVAfgWAYAXAQ&sigh=UTbooye19j8&label=active_view_verification_rejected&errorcode=%5BREASON%5D",
}, e.AdVerifications[0].TrackingEvents[0])
}, (*e.AdVerifications)[0].TrackingEvents[0])
}
}
}
Expand Down Expand Up @@ -137,20 +137,20 @@ func TestMultipleExtensions(t *testing.T) {
e := extensions[1]
assert.Equal(t, "AdVerifications", e.Type)
assert.Empty(t, e.Data)
if assert.Len(t, e.AdVerifications, 1) {
assert.Equal(t, "doubleclickbygoogle.com-omid-video", e.AdVerifications[0].Vendor)
if assert.Len(t, e.AdVerifications[0].JavaScriptResource, 1) {
if assert.NotNil(t, e.AdVerifications) && assert.Len(t, *e.AdVerifications, 1) {
assert.Equal(t, "doubleclickbygoogle.com-omid-video", (*e.AdVerifications)[0].Vendor)
if assert.Len(t, (*e.AdVerifications)[0].JavaScriptResource, 1) {
assert.Equal(t, JavaScriptResource{
ApiFramework: "omid",
BrowserOptional: true,
URI: "https://example.com/verify.js",
}, e.AdVerifications[0].JavaScriptResource[0])
}, (*e.AdVerifications)[0].JavaScriptResource[0])
}
if assert.Len(t, e.AdVerifications[0].TrackingEvents, 1) {
if assert.Len(t, (*e.AdVerifications)[0].TrackingEvents, 1) {
assert.Equal(t, Tracking{
Event: "verificationNotExecuted",
URI: "https://pagead2.googlesyndication.com/pagead/interaction/?ai=Bt7src9CCZofvMqChiM0Pi8qQkAPFnbOVRgAAABABII64hW84AVjUt8DBgwRglfrwgYwHsgETZ29vZ2xlYWRzLmdpdGh1Yi5pb7oBCjcyOHg5MF94bWzIAQXaATRodHRwczovL2dvb2dsZWFkcy5naXRodWIuaW8vZ29vZ2xlYWRzLWltYS1odG1sNS92c2kvwAIC4AIA6gIlLzIxNzc1NzQ0OTIzL2V4dGVybmFsL3V0aWxpdHlfc2FtcGxlc_gC8NEegAMBkAPIBpgD4AOoAwHgBAHSBQYQj6GjiRagBiOoB7i-sQKoB5oGqAfz0RuoB5bYG6gHqpuxAqgHg62xAqgH4L2xAqgH_56xAqgH35-xAqgH-MKxAqgH-8KxAtgHAdIIMQiR4YBwEAEYHTIH64uA7r-AAToPgNCAgICAhAiAgICAgJQuSL39wTpY1cHtiZmGhwPYCAKACgWYCwGqDQJERdAVAfgWAYAXAQ&sigh=UTbooye19j8&label=active_view_verification_rejected&errorcode=%5BREASON%5D",
}, e.AdVerifications[0].TrackingEvents[0])
}, (*e.AdVerifications)[0].TrackingEvents[0])
}
}
}
Expand Down

0 comments on commit 3274613

Please sign in to comment.