Skip to content

Commit e8fda28

Browse files
authored
Default to Windows attribution when the os value is not "osx" (#204)
1 parent 2cc8938 commit e8fda28

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

stubservice/stubhandlers/stubhandler_test.go

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,10 +332,22 @@ func TestDirectFull(t *testing.T) {
332332
for _, params := range []struct {
333333
AttributionCode string
334334
ExpectedCode string
335+
OS string
335336
}{
336337
{
337338
AttributionCode: `campaign=%28not+set%29&content=%28not+set%29&medium=organic&source=www.google.com`,
338339
ExpectedCode: `campaign%3D%2528not%2Bset%2529%26content%3D%2528not%2Bset%2529%26dltoken%3D[\w\d-]+%26medium%3Dorganic%26source%3Dwww.google.com`,
340+
OS: "win",
341+
},
342+
{
343+
AttributionCode: `campaign=%28not+set%29&content=%28not+set%29&medium=organic&source=www.google.com`,
344+
ExpectedCode: `campaign%3D%2528not%2Bset%2529%26content%3D%2528not%2Bset%2529%26dltoken%3D[\w\d-]+%26medium%3Dorganic%26source%3Dwww.google.com`,
345+
OS: "win64",
346+
},
347+
{
348+
AttributionCode: `campaign=%28not+set%29&content=%28not+set%29&medium=organic&source=www.google.com`,
349+
ExpectedCode: `campaign%3D%2528not%2Bset%2529%26content%3D%2528not%2Bset%2529%26dltoken%3D[\w\d-]+%26medium%3Dorganic%26source%3Dwww.google.com`,
350+
OS: "win64-aarch64",
339351
},
340352
} {
341353
testHook.Reset()
@@ -346,7 +358,11 @@ func TestDirectFull(t *testing.T) {
346358
base64Code := base64.URLEncoding.WithPadding('.').EncodeToString([]byte(params.AttributionCode))
347359
req := httptest.NewRequest(
348360
"GET",
349-
`http://test/?product=firefox-stub&os=win&lang=en-US&attribution_code=`+url.QueryEscape(base64Code),
361+
fmt.Sprintf(
362+
"http://test/?product=firefox-stub&os=%s&lang=en-US&attribution_code=%s",
363+
params.OS,
364+
url.QueryEscape(base64Code),
365+
),
350366
nil,
351367
)
352368
svc.ServeHTTP(recorder, req)
@@ -467,4 +483,27 @@ func TestStubServiceErrorCases(t *testing.T) {
467483
t.Errorf("service did not return bouncer redirect status: %d loc: %s", code, location)
468484
}
469485
})
486+
487+
t.Run("unsupported OS", func(t *testing.T) {
488+
base64Code := base64.URLEncoding.WithPadding('.').EncodeToString([]byte("campaign=test"))
489+
490+
for _, params := range []struct{ OS string }{
491+
{OS: "linux"},
492+
{OS: "linux64"},
493+
} {
494+
expectedLocation := fmt.Sprintf("https://download.mozilla.org/?lang=en-US&os=%s&product=firefox-latest-ssl", params.OS)
495+
496+
recorder := fetchURL(fmt.Sprintf(
497+
"http://test/?product=firefox-latest-ssl&os=%s&lang=en-US&attribution_code=%s",
498+
params.OS,
499+
url.QueryEscape(base64Code),
500+
))
501+
code := recorder.Code
502+
location := recorder.HeaderMap.Get("Location")
503+
504+
if code != 302 || location != expectedLocation {
505+
t.Errorf("service did not return bouncer redirect status: %d loc: %s (os=%s)", code, location, params.OS)
506+
}
507+
}
508+
})
470509
}

stubservice/stubhandlers/stubservice.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func NewStubService(stubHandler StubHandler, validator *attributioncode.Validato
2121
return &stubService{
2222
Handler: stubHandler,
2323
AttributionCodeValidator: validator,
24-
BouncerBaseURL: bouncerBaseURL,
24+
BouncerBaseURL: bouncerBaseURL,
2525
}
2626
}
2727

stubservice/stubhandlers/utils.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ func modifyStub(st *stub, attributionCode string, os string) (res *stub, err err
104104
body := st.body
105105
if attributionCode != "" {
106106
switch os {
107-
case "win":
108-
// Windows exe attribution
109-
if body, err = stubmodify.WriteAttributionCode(st.body, []byte(attributionCode)); err != nil {
110-
return nil, &modifyStubError{err, attributionCode}
111-
}
112107
case "osx":
113108
// Mac DMG attribution
114109
dmgbody, err := dmglib.ParseDMG(bytes.NewReader(body))
@@ -122,15 +117,22 @@ func modifyStub(st *stub, attributionCode string, os string) (res *stub, err err
122117
}
123118
body = dmgbody.Data
124119
default:
125-
// Unknown OS
126-
return nil, &modifyStubError{err, attributionCode}
120+
// Windows exe attribution is the default since only macOS and Windows builds are attributable,
121+
// and macOS only has one "os" identifier.
122+
//
123+
// Note also that the bouncer service determines which build should be attributed.
124+
if body, err = stubmodify.WriteAttributionCode(st.body, []byte(attributionCode)); err != nil {
125+
return nil, &modifyStubError{err, attributionCode}
126+
}
127127
}
128128
}
129+
129130
logrus.WithFields(logrus.Fields{
130131
"original_filename": st.filename,
131132
"original_stub_sha256": fmt.Sprintf("%X", sha256.Sum256(st.body)),
132133
"modified_stub_sha256": fmt.Sprintf("%X", sha256.Sum256(body)),
133-
"attribution_code": attributionCode}).Info("Modified stub")
134+
"attribution_code": attributionCode,
135+
}).Info("Modified stub")
134136

135137
return &stub{
136138
body: body,

0 commit comments

Comments
 (0)