This repository has been archived by the owner on May 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 264
/
used-address-as-primary-test.js
102 lines (87 loc) · 2.5 KB
/
used-address-as-primary-test.js
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
#!/usr/bin/env node
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
require('./lib/test_env.js');
const assert = require('assert'),
db = require('../lib/db.js'),
email = require('../lib/email.js'),
jwcrypto = require('jwcrypto'),
primary = require('./lib/primary.js'),
start_stop = require('./lib/start-stop.js'),
vows = require('vows'),
wsapi = require('./lib/wsapi.js');
var suite = vows.describe('forgotten-email');
// algs
require("jwcrypto/lib/algs/ds");
require("jwcrypto/lib/algs/rs");
start_stop.addStartupBatches(suite);
// every time a new token is sent out, let's update the global
// var 'token'
var token;
const TEST_DOMAIN = 'example.domain',
TEST_EMAIL = 'testuser@' + TEST_DOMAIN,
TEST_ORIGIN = 'http://127.0.0.1:10002';
var primaryUser = new primary({
email: TEST_EMAIL,
domain: TEST_DOMAIN
});
suite.addBatch({
"set things up": {
topic: function() {
primaryUser.setup(this.callback);
},
"works": function() {
// nothing to do here
}
}
});
// now let's generate an assertion using this user
suite.addBatch({
"generating an assertion": {
topic: function() {
primaryUser.getAssertion(TEST_ORIGIN, this.callback);
},
"succeeds": function(err, r) {
assert.isString(r);
},
"and logging in with the assertion succeeds": {
topic: function(err, assertion) {
wsapi.post('/wsapi/auth_with_assertion', {
assertion: assertion,
ephemeral: true
}).call(this);
},
"works": function(err, r) {
var resp = JSON.parse(r.body);
assert.isObject(resp);
assert.isTrue(resp.success);
}
}
}
});
suite.addBatch({
"Mark a transition as having been seen": {
topic: wsapi.post('/wsapi/used_address_as_primary', {
email: TEST_EMAIL
}),
"request successful": function(err, r) {
assert.equal(r.code, 200);
assert.strictEqual(true, JSON.parse(r.body).success);
token = undefined;
},
"db updated": {
topic: function () {
db.emailLastUsedAs(TEST_EMAIL, this.callback);
},
"lastUseAs updated": function (err, lastUsedAs) {
assert.isNull(err);
assert.equal(lastUsedAs, 'primary');
}
}
}
});
start_stop.addShutdownBatches(suite);
// run or export the suite.
if (process.argv[1] === __filename) suite.run();
else suite.export(module);