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

Commit 07cff4e

Browse files
author
Shane Tomlinson
committed
feat(client): Pass along the resume parameter to the auth-server
Affects `signUp`, `recoveryEmailResendCode`, `passwordForgotSendCode`, `passwordForgotResendCode` fixes #131
1 parent c86b81d commit 07cff4e

File tree

5 files changed

+84
-11
lines changed

5 files changed

+84
-11
lines changed

client/FxAccountClient.js

+32
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
5050
* set email to be verified if possible
5151
* @param {String} [options.preVerifyToken]
5252
* Opaque alphanumeric token that can be used to pre-verify a user.
53+
* @param {String} [options.resume]
54+
* Opaque url-encoded string that will be included in the verification link
55+
* as a querystring parameter, useful for continuing an OAuth flow for
56+
* example.
5357
* @param {String} [options.lang]
5458
* set the language for the 'Accept-Language' header
5559
* @return {Promise} A promise that will be fulfilled with JSON `xhr.responseText` of the request
@@ -92,6 +96,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
9296
data.preVerifyToken = options.preVerifyToken;
9397
}
9498

99+
if (options.resume) {
100+
data.resume = options.resume;
101+
}
102+
95103
if (options.keys) {
96104
endpoint += '?keys=true';
97105
}
@@ -203,6 +211,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
203211
* Opaque alphanumeric token to be included in verification links
204212
* @param {String} [options.redirectTo]
205213
* a URL that the client should be redirected to after handling the request
214+
* @param {String} [options.resume]
215+
* Opaque url-encoded string that will be included in the verification link
216+
* as a querystring parameter, useful for continuing an OAuth flow for
217+
* example.
206218
* @param {String} [options.lang]
207219
* set the language for the 'Accept-Language' header
208220
* @return {Promise} A promise that will be fulfilled with JSON `xhr.responseText` of the request
@@ -223,6 +235,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
223235
data.redirectTo = options.redirectTo;
224236
}
225237

238+
if (options.resume) {
239+
data.resume = options.resume;
240+
}
241+
226242
if (options.lang) {
227243
requestOpts.headers = {
228244
'Accept-Language': options.lang
@@ -247,6 +263,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
247263
* Opaque alphanumeric token to be included in verification links
248264
* @param {String} [options.redirectTo]
249265
* a URL that the client should be redirected to after handling the request
266+
* @param {String} [options.resume]
267+
* Opaque url-encoded string that will be included in the verification link
268+
* as a querystring parameter, useful for continuing an OAuth flow for
269+
* example.
250270
* @param {String} [options.lang]
251271
* set the language for the 'Accept-Language' header
252272
* @return {Promise} A promise that will be fulfilled with JSON `xhr.responseText` of the request
@@ -268,6 +288,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
268288
data.redirectTo = options.redirectTo;
269289
}
270290

291+
if (options.resume) {
292+
data.resume = options.resume;
293+
}
294+
271295
if (options.lang) {
272296
requestOpts.headers = {
273297
'Accept-Language': options.lang
@@ -290,6 +314,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
290314
* Opaque alphanumeric token to be included in verification links
291315
* @param {String} [options.redirectTo]
292316
* a URL that the client should be redirected to after handling the request
317+
* @param {String} [options.resume]
318+
* Opaque url-encoded string that will be included in the verification link
319+
* as a querystring parameter, useful for continuing an OAuth flow for
320+
* example.
293321
* @param {String} [options.lang]
294322
* set the language for the 'Accept-Language' header
295323
* @return {Promise} A promise that will be fulfilled with JSON `xhr.responseText` of the request
@@ -313,6 +341,10 @@ define(['./lib/request', 'sjcl', 'p', './lib/credentials', './lib/hawkCredential
313341
data.redirectTo = options.redirectTo;
314342
}
315343

344+
if (options.resume) {
345+
data.resume = options.resume;
346+
}
347+
316348
if (options.lang) {
317349
requestOpts.headers = {
318350
'Accept-Language': options.lang

tests/lib/account.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,12 @@ define([
164164
)
165165
});
166166

167-
test('#passwordForgotSendCode with service and redirectTo', function () {
167+
test('#passwordForgotSendCode with service, redirectTo, and resume', function () {
168168
var account;
169169
var opts = {
170170
service: 'sync',
171-
redirectTo: 'https://sync.firefox.com/after_reset'
171+
redirectTo: 'https://sync.firefox.com/after_reset',
172+
resume: 'resumejwt'
172173
};
173174

174175
return accountHelper.newVerifiedAccount()
@@ -189,19 +190,23 @@ define([
189190
assert.ok(service, 'service found');
190191
var redirectTo = emails[1].html.match(/redirectTo=([A-Za-z0-9]+)/);
191192
assert.ok(redirectTo, 'redirectTo found');
193+
var resume = emails[1].html.match(/resume=([A-Za-z0-9]+)/);
194+
assert.ok(resume, 'resume found');
192195

193196
assert.ok(code[1], 'code is returned');
194197
assert.equal(service[1], 'sync', 'service is returned');
195198
assert.equal(redirectTo[1], 'https', 'redirectTo is returned');
199+
assert.equal(resume[1], 'resumejwt', 'resume is returned');
196200
})
197201
});
198202

199-
test('#passwordForgotResendCode with service and redirectTo', function () {
203+
test('#passwordForgotResendCode with service, redirectTo, and resume', function () {
200204
var account;
201205
var passwordForgotToken;
202206
var opts = {
203207
service: 'sync',
204-
redirectTo: 'https://sync.firefox.com/after_reset'
208+
redirectTo: 'https://sync.firefox.com/after_reset',
209+
resume: 'resumejwt'
205210
};
206211

207212
return accountHelper.newVerifiedAccount()
@@ -234,10 +239,13 @@ define([
234239
assert.ok(service, 'service found');
235240
var redirectTo = emails[2].html.match(/redirectTo=([A-Za-z0-9]+)/);
236241
assert.ok(redirectTo, 'redirectTo found');
242+
var resume = emails[2].html.match(/resume=([A-Za-z0-9]+)/);
243+
assert.ok(resume, 'resume found');
237244

238245
assert.ok(code[1], 'code is returned');
239246
assert.equal(service[1], 'sync', 'service is returned');
240247
assert.equal(redirectTo[1], 'https', 'redirectTo is returned');
248+
assert.equal(resume[1], 'resumejwt', 'resume is returned');
241249
})
242250
});
243251

tests/lib/recoveryEmail.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,12 @@ define([
5252
);
5353
});
5454

55-
test('#recoveryEmailResendCode with service and redirectTo', function () {
55+
test('#recoveryEmailResendCode with service, redirectTo, and resume', function () {
5656
var user;
5757
var opts = {
5858
service: 'sync',
59-
redirectTo: 'https://sync.firefox.com/after_reset'
59+
redirectTo: 'https://sync.firefox.com/after_reset',
60+
resume: 'resumejwt'
6061
};
6162

6263
return accountHelper.newUnverifiedAccount()
@@ -80,10 +81,13 @@ define([
8081
assert.ok(service, 'service found');
8182
var redirectTo = emails[1].html.match(/redirectTo=([A-Za-z0-9]+)/);
8283
assert.ok(redirectTo, 'redirectTo found');
84+
var resume = emails[1].html.match(/resume=([A-Za-z0-9]+)/);
85+
assert.ok(resume, 'resume found');
8386

8487
assert.ok(code[1], 'code is returned');
8588
assert.equal(service[1], 'sync', 'service is returned');
8689
assert.equal(redirectTo[1], 'https', 'redirectTo is returned');
90+
assert.equal(resume[1], 'resumejwt', 'resume is returned');
8791
},
8892
assert.notOk
8993
);

tests/lib/signUp.js

+31-2
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,14 @@ define([
6161
);
6262
});
6363

64-
test('#create account with service and redirectTo', function () {
64+
test('#create account with service, redirectTo, and resume', function () {
6565
var user = "test" + new Date().getTime();
6666
var email = user + "@restmail.net";
6767
var password = "iliketurtles";
6868
var opts = {
6969
service: 'sync',
70-
redirectTo: 'https://sync.firefox.com/after_reset'
70+
redirectTo: 'https://sync.firefox.com/after_reset',
71+
resume: 'resumejwt'
7172
};
7273

7374
return respond(client.signUp(email, password, opts), RequestMocks.signUp)
@@ -80,10 +81,12 @@ define([
8081
var code = emails[0].html.match(/code=([A-Za-z0-9]+)/)[1];
8182
var service = emails[0].html.match(/service=([A-Za-z0-9]+)/)[1];
8283
var redirectTo = emails[0].html.match(/redirectTo=([A-Za-z0-9]+)/)[1];
84+
var resume = emails[0].html.match(/resume=([A-Za-z0-9]+)/)[1];
8385

8486
assert.ok(code, 'code is returned');
8587
assert.ok(service, 'service is returned');
8688
assert.ok(redirectTo, 'redirectTo is returned');
89+
assert.ok(resume, 'resume is returned');
8790

8891
},
8992
assert.notOk
@@ -141,6 +144,32 @@ define([
141144
);
142145
});
143146

147+
test('#withResume', function () {
148+
var user = "test" + new Date().getTime();
149+
var email = user + "@restmail.net";
150+
var password = "iliketurtles";
151+
var opts = {
152+
resume: 'resumejwt'
153+
};
154+
155+
return respond(client.signUp(email, password, opts), RequestMocks.signUp)
156+
.then(function (res) {
157+
assert.ok(res.uid);
158+
return respond(mail.wait(user), RequestMocks.mailServiceAndRedirect);
159+
})
160+
.then(
161+
function (emails) {
162+
var code = emails[0].html.match(/code=([A-Za-z0-9]+)/)[1];
163+
var resume = emails[0].html.match(/resume=([A-Za-z0-9]+)/)[1];
164+
165+
assert.ok(code, 'code is returned');
166+
assert.ok(resume, 'resume is returned');
167+
168+
},
169+
assert.notOk
170+
);
171+
});
172+
144173
test('#preVerified', function () {
145174
var email = "test" + new Date().getTime() + "@restmail.net";
146175
var password = "iliketurtles";

tests/mocks/request.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,19 @@ define(['client/lib/errors'], function (ERRORS) {
4747
},
4848
mailServiceAndRedirect: {
4949
status: 200,
50-
body: '[{"html":"Mocked code=9001 service=sync redirectTo=https"}]'
50+
body: '[{"html":"Mocked code=9001 service=sync redirectTo=https resume=resumejwt"}]'
5151
},
5252
resetMail: {
5353
status: 200,
5454
body: '[{"html":"Mocked code=9001"}, {"html":"Mocked code=9001"}]'
5555
},
5656
resetMailWithServiceAndRedirect: {
5757
status: 200,
58-
body: '[{"html":"Mocked code=9001"}, {"html":"Mocked code=9001 service=sync redirectTo=https"}]'
58+
body: '[{"html":"Mocked code=9001"}, {"html":"Mocked code=9001 service=sync redirectTo=https resume=resumejwt"}]'
5959
},
6060
resetMailResendWithServiceAndRedirect: {
6161
status: 200,
62-
body: '[{"html":"Mocked code=9001"}, {"html":"Mocked code=9001 service=sync redirectTo=https"}, {"html":"Mocked code=9001 service=sync redirectTo=https"}]'
62+
body: '[{"html":"Mocked code=9001"}, {"html":"Mocked code=9001 service=sync redirectTo=https"}, {"html":"Mocked code=9001 service=sync redirectTo=https resume=resumejwt"}]'
6363
},
6464
resetMailLang: {
6565
status: 200,

0 commit comments

Comments
 (0)