openid_integration_tests.js
5.82 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/* OpenID for node.js
*
* http://ox.no/software/node-openid
* http://github.com/havard/node-openid
*
* Copyright (C) 2010 by Håvard Stranden
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
*/
var constants = require('constants');
var https = require('https');
var openid = require('../openid');
var sinon = require('sinon');
// OpenSSL seems to have issues with some servers and causes some of the
// following test cases to fail in Node 0.10.x unless we disable TLS 1.2. See
// https://github.com/joyent/node/issues/5360
https.globalAgent.options.secureOptions = constants.SSL_OP_NO_TLSv1_2;
var clock;
exports.setUp = function(callback)
{
// By default the openid module save association data to memory and sets up
// a timer to expire stale entries. This timer prevents the test cases from
// exiting so we fake the timer implementation during the test run.
clock = sinon.useFakeTimers('setTimeout');
callback();
}
exports.tearDown = function(callback)
{
clock.restore();
delete clock;
callback();
}
exports.testResolveFailed = function(test)
{
openid.authenticate('example.com', 'http://example.com/verify', null, false, false,
function(error, url)
{
test.ok(error);
test.equal(null, url);
test.done();
});
}
exports.testEmptyUrl = function(test)
{
openid.discover('',
true,
function(error, providers)
{
test.ok(error);
test.equal(null, providers);
test.done();
});
}
exports.testResolveRyanXri = function(test)
{
openid.discover('=ryan',
true,
function(error, providers)
{
test.ok(!error);
test.equal(2, providers.length);
test.done();
});
}
exports.testResolveGoogle = function(test)
{
openid.discover('http://www.google.com/accounts/o8/id',
true,
function(error, providers)
{
test.ok(!error);
test.equal(1, providers.length);
test.done();
});
}
exports.testResolveLiveJournalUser = function(test)
{
openid.discover('http://omnifarious.livejournal.com/',
true,
function(error, providers)
{
test.ok(!error);
test.equal(1, providers.length);
test.done();
});
}
exports.testResolveOpenID11 = function(test)
{
// FIXME: relying on a third party for back-level protocol support is brittle.
openid.discover('http://pupeno.com/',
true,
function(error, providers)
{
test.ok(!error);
test.notEqual(null, providers);
test.equal(1, providers.length);
test.equal(providers[0].version, 'http://openid.net/signon/1.1');
test.done();
});
}
function associateTest(url, version, test)
{
if (arguments.length == 2)
{
test = version;
version = null;
}
openid.discover(url,
true,
function(error, providers)
{
var provider = providers[0];
openid.associate(provider, function(error, result)
{
test.ok(!error);
if (version)
{
test.equal(provider.version, version);
}
test.ok(result.expires_in);
test.done();
});
}
);
}
exports.testAssociateWithGoogle = function(test)
{
associateTest('http://www.google.com/accounts/o8/id', test);
}
exports.testAssociateWithLiveJournal = function(test)
{
associateTest('http://omnifarious.livejournal.com/', test);
}
exports.testAssociateWithOpenID11 = function(test)
{
// FIXME: relying on a third party for back-level protocol support is brittle.
associateTest('https://matt.wordpress.com/', 'http://openid.net/signon/1.1', test);
}
exports.testImmediateAuthenticationWithGoogle = function(test)
{
openid.authenticate('http://www.google.com/accounts/o8/id',
'http://example.com/verify', null, true, false, function(error, url)
{
test.ok(!error, error);
test.ok(url.indexOf('checkid_immediate') !== -1);
test.done();
});
}
exports.testImmediateAuthenticationWithGoogleAppsForDomains = function(test)
{
// domain must be a valid google apps domain with openid enabled.
openid.authenticate('https://www.google.com/accounts/o8/site-xrds?hd=opower.com',
'http://example.com/verify', null, true, false, function(error, url)
{
test.ok(!error, error);
test.ok(url.indexOf('checkid_immediate') !== -1);
test.done();
});
}
exports.testSetupAuthenticationWithGoogle = function(test)
{
openid.authenticate('http://www.google.com/accounts/o8/id',
'http://example.com/verify', null, false, false, function(error, url)
{
test.ok(!error);
test.ok(url.indexOf('checkid_setup') !== -1);
test.done();
});
}
exports.testAuthenticationWithGoogleUsingRelyingPartyObject = function(test)
{
var rp = new openid.RelyingParty(
'http://example.com/verify',
null,
false,
false,
null);
rp.authenticate('http://www.google.com/accounts/o8/id', false, function(error, url)
{
test.ok(!error);
test.ok(url.indexOf('checkid_setup') !== -1);
test.done();
});
}