Skip to content
This repository was archived by the owner on Apr 3, 2019. It is now read-only.

Commit 6401431

Browse files
committed
fix(token): Allow the UA for a specific partner device.
Details in https://bugzilla.mozilla.org/show_bug.cgi?id=1263504
1 parent a0f856a commit 6401431

File tree

2 files changed

+36
-14
lines changed

2 files changed

+36
-14
lines changed

config/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ var conf = convict({
117117
},
118118
allowedUARegex: {
119119
doc: 'An array of STRING regexes. Passing any one will get through.',
120-
default: ['\\((?:Mobile|Tablet|TV);.+Firefox']
120+
default: ['\\((?:Mobile|Tablet|TV|FreeBSD; Viera);.+Firefox']
121121
}
122122
},
123123
smtp: {

test/local/contentToken_tests.js

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ var extend = require('util')._extend
66

77
var test = require('../ptaptest')
88
var contentToken = require('../../lib/crypto/contentToken')
9+
var defaultConfig = require('../../config').getProperties()
910

1011
// Token generated from default settings
1112
var DEFAULT_TOKEN = '3134353939393439353832393581370469b241f38edcd281c3b69bc835ba1b9810'
1213
var HEADERS = {
1314
'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36'
1415
}
1516

16-
var defaultConfig = {
17+
var testConfig = {
1718
required: true,
1819
key: 'YOU MUST CHANGE ME',
1920
expiry: Date.now()
@@ -22,7 +23,7 @@ var defaultConfig = {
2223
test(
2324
'contentToken basic',
2425
function (t) {
25-
return contentToken(DEFAULT_TOKEN, HEADERS, defaultConfig)
26+
return contentToken(DEFAULT_TOKEN, HEADERS, testConfig)
2627
.then(
2728
function (result) {
2829
t.ok(result.valid, 'token is valid')
@@ -38,7 +39,7 @@ test(
3839
var HEADERS = {
3940
'user-agent': 'MSIE'
4041
}
41-
return contentToken(DEFAULT_TOKEN, HEADERS, defaultConfig)
42+
return contentToken(DEFAULT_TOKEN, HEADERS, testConfig)
4243
.then(
4344
function (result) {
4445
t.notOk(result.valid, 'token is not valid')
@@ -51,7 +52,7 @@ test(
5152
test(
5253
'contentToken fails if token is bad length',
5354
function (t) {
54-
return contentToken(DEFAULT_TOKEN.substr(0, 3), HEADERS, defaultConfig)
55+
return contentToken(DEFAULT_TOKEN.substr(0, 3), HEADERS, testConfig)
5556
.then(function (result) {
5657
t.notOk(result.valid, 'token is not valid')
5758
t.equal(result.reason, 'Bad request or token length')
@@ -62,7 +63,7 @@ test(
6263
test(
6364
'contentToken fails if bad key',
6465
function (t) {
65-
var config = extend({}, defaultConfig)
66+
var config = extend({}, testConfig)
6667
config.key = 'something else'
6768
return contentToken(DEFAULT_TOKEN, HEADERS, config)
6869
.then(function (result) {
@@ -75,7 +76,7 @@ test(
7576
test(
7677
'contentToken if timestamp is NaN',
7778
function (t) {
78-
var config = extend({}, defaultConfig)
79+
var config = extend({}, testConfig)
7980
config.expiry = 1
8081

8182
return contentToken(DEFAULT_TOKEN, HEADERS, config)
@@ -89,7 +90,7 @@ test(
8990
test(
9091
'contentToken fails if wrong token',
9192
function (t) {
92-
return contentToken('31343539393831323734393931f00f00f00eefa2ead4427c5de811a570a8e539d6', HEADERS, defaultConfig)
93+
return contentToken('31343539393831323734393931f00f00f00eefa2ead4427c5de811a570a8e539d6', HEADERS, testConfig)
9394
.then(function (result) {
9495
t.notOk(result.valid, 'token is not valid for bad key')
9596
t.equal(result.reason, 'Invalid HMAC')
@@ -98,14 +99,14 @@ test(
9899
)
99100

100101
test(
101-
'contentToken allow firefox os devices',
102+
'contentToken default config allow firefox os devices',
102103
function (t) {
103104
var HEADERS = {
104105
'user-agent': 'Mozilla/5.0 (TV; rv:44.0) Gecko/44.0 Firefox/44.0'
105106
}
106107

107-
var config = extend({}, defaultConfig)
108-
config.allowedUARegex = ['\\((?:Mobile|Tablet|TV);.+Firefox']
108+
var config = extend({}, testConfig)
109+
config.allowedUARegex = defaultConfig.contentToken.allowedUARegex
109110
config.compiledRegexList = config.allowedUARegex.map(function(re) {
110111
return new RegExp(re)
111112
})
@@ -119,14 +120,35 @@ test(
119120
)
120121

121122
test(
122-
'contentToken blocks fennec UAs',
123+
'contentToken default config allows a specific partner device',
124+
function (t) {
125+
var HEADERS = {
126+
'user-agent': 'Mozilla/5.0 (FreeBSD; Viera; rv:44.0) Gecko/20100101 Firefox/44.0'
127+
}
128+
129+
var config = extend({}, testConfig)
130+
config.allowedUARegex = defaultConfig.contentToken.allowedUARegex
131+
config.compiledRegexList = config.allowedUARegex.map(function(re) {
132+
return new RegExp(re)
133+
})
134+
135+
return contentToken(DEFAULT_TOKEN, HEADERS, config)
136+
.then(function (result) {
137+
t.ok(result.valid, 'token is valid')
138+
t.equal(result.reason, 'Allowed user agent')
139+
})
140+
}
141+
)
142+
143+
test(
144+
'contentToken default config does not allow fennec UAs',
123145
function (t) {
124146
var HEADERS = {
125147
'user-agent': 'Mozilla/5.0 (Android 4.4; Mobile; rv:41.0) Gecko/41.0 Firefox/41.0'
126148
}
127149

128-
var config = extend({}, defaultConfig)
129-
config.allowedUARegex = ['\\((?:Mobile|Tablet|TV);.+Firefox']
150+
var config = extend({}, testConfig)
151+
config.allowedUARegex = defaultConfig.contentToken.allowedUARegex
130152
config.compiledRegexList = config.allowedUARegex.map(function(re) {
131153
return new RegExp(re)
132154
})

0 commit comments

Comments
 (0)