Merge lp:~canonical-isd-hackers/drupal-openid/unittests into lp:drupal-openid/6.x
- unittests
- Merge into 6.x-trunk
Proposed by
Anthony Lenton
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~canonical-isd-hackers/drupal-openid/unittests |
Merge into: | lp:drupal-openid/6.x |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~canonical-isd-hackers/drupal-openid/unittests |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Łukasz Czyżykowski (community) | Approve | ||
Review via email: mp+6480@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Anthony Lenton (elachuni) wrote : | # |
- 15. By Anthony Lenton
-
Code review fixes, plus updated the README.
Revision history for this message
Łukasz Czyżykowski (lukasz-czyzykowski) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === removed file 'openid.test' |
2 | --- openid.test 2009-05-08 17:27:16 +0000 |
3 | +++ openid.test 1970-01-01 00:00:00 +0000 |
4 | @@ -1,50 +0,0 @@ |
5 | -<?php |
6 | - |
7 | -class DrupalOpenIDHelpTestCase extends DrupalWebTestCase { |
8 | - function getInfo() { |
9 | - return array( |
10 | - 'name' => t('OpenID Help'), |
11 | - 'description' => t('Openid module Help unit tests'), |
12 | - 'group' => t('OpenID'), |
13 | - ); |
14 | - } |
15 | - |
16 | - function setUp() { |
17 | - parent::setUp('openid'); |
18 | - } |
19 | - /* Fetch all pages that show relevant OpenID help information */ |
20 | - function testDrupalOpenIDHelp() { |
21 | - $user = $this->drupalCreateUser(array('access content', 'access administration pages')); |
22 | - $this->drupalLogin($user); |
23 | - $path = 'user/'. $user->uid.'/openid'; |
24 | - $this->drupalGet($path); |
25 | - $this->assertText(t('This site supports OpenID'), |
26 | - t('Make sure the right help text appears on the user\'s OpenID page.')); |
27 | - $this->drupalGet('admin/help/openid'); |
28 | - $this->assertText(t('OpenID is a secure method for logging into many websites'), |
29 | - t('Make sure the right help text appears on the admin help page.')); |
30 | - } |
31 | -} |
32 | - |
33 | -class DrupalOpenIDBeginTestCase extends DrupalWebTestCase { |
34 | - function getInfo() { |
35 | - return array( |
36 | - 'name' => t('OpenID Begin'), |
37 | - 'description' => t('Openid begin unit tests'), |
38 | - 'group' => t('OpenID'), |
39 | - ); |
40 | - } |
41 | - |
42 | - function setUp() { |
43 | - parent::setUp('openid'); |
44 | - } |
45 | - |
46 | - /* Start an OpenID Authentication process */ |
47 | - function testOpenIDBegin() { |
48 | - $edit = array('openid_identifier' => 'https://login.launchpad.net/'); |
49 | - $this->drupalPost('/user', $edit, 'Log in'); |
50 | - $this->assertFieldById('edit-openid-redirect-form', 'openid_redirect_form', |
51 | - t('Ensure clicking login produces a OpenID redirect form')); |
52 | - } |
53 | - |
54 | -} |
55 | |
56 | === added directory 'tests' |
57 | === added file 'tests/authentication.test' |
58 | --- tests/authentication.test 1970-01-01 00:00:00 +0000 |
59 | +++ tests/authentication.test 2009-05-12 18:23:43 +0000 |
60 | @@ -0,0 +1,56 @@ |
61 | +<?php |
62 | + |
63 | +class DrupalOpenIDAuthenticationTestCase extends DrupalWebTestCase { |
64 | + function getInfo() { |
65 | + return array( |
66 | + 'name' => t('OpenID Authentication'), |
67 | + 'description' => t('openid_authentication unit tests'), |
68 | + 'group' => t('OpenID'), |
69 | + ); |
70 | + } |
71 | + |
72 | + function setUp() { |
73 | + parent::setUp('openid', 'openid_test'); |
74 | + } |
75 | + |
76 | + /* Fail to register a new account due to automatic user registration |
77 | + * being disabled */ |
78 | + function testOpenIDFailAuthentication() { |
79 | + variable_set('user_register', FALSE); |
80 | + $this->drupalGet('openid/test/login/doesntexist'); |
81 | + $this->assertText('Only site administrators can create new user accounts', |
82 | + 'Ensure that a user account is *not* created'); |
83 | + } |
84 | + |
85 | + /* Fail to register a new account due to not providing an email */ |
86 | + function testOpenIDNoEmailAuthentication() { |
87 | + variable_set('user_register', TRUE); |
88 | + variable_set('user_email_verification', FALSE); |
89 | + $this->drupalGet('openid/test/loginnoemail/doesntexist'); |
90 | + $this->assertText('You must enter an e-mail address', |
91 | + 'Ensure registration fails when an email is not provided'); |
92 | + } |
93 | + |
94 | + function testOpenIDRegisterAuthentication() { |
95 | + variable_set('user_register', TRUE); |
96 | + $this->drupalGet('openid/test/login/doesntexist'); |
97 | + $this->assertText('My account', |
98 | + 'Ensure an account was successfully created'); |
99 | + } |
100 | + |
101 | + function testOpenIDVerifyEmailAuthentication() { |
102 | + variable_set('user_register', TRUE); |
103 | + variable_set('user_email_verification', TRUE); |
104 | + $name = $this->randomName(); |
105 | + $mail = "$name@mail.com"; |
106 | + $this->drupalGet('openid/test/loginnoemail/' . $name); |
107 | + $this->assertText('You must enter an e-mail address', |
108 | + 'Ensure registration fails when an email is not provided'); |
109 | + $edit = array('name' => $name, |
110 | + 'mail' => $mail); |
111 | + $this->drupalPost(NULL, $edit, 'Create new account'); |
112 | + $this->assertText('Once you have verified your email address, you may log in via OpenID', |
113 | + 'Ensure an email notification warning is displayed'); |
114 | + } |
115 | + |
116 | +} |
117 | |
118 | === added file 'tests/begin.test' |
119 | --- tests/begin.test 1970-01-01 00:00:00 +0000 |
120 | +++ tests/begin.test 2009-05-12 18:23:43 +0000 |
121 | @@ -0,0 +1,32 @@ |
122 | +<?php |
123 | + |
124 | +class DrupalOpenIDBeginTestCase extends DrupalWebTestCase { |
125 | + function getInfo() { |
126 | + return array( |
127 | + 'name' => t('OpenID Begin'), |
128 | + 'description' => t('openid_begin unit tests'), |
129 | + 'group' => t('OpenID'), |
130 | + ); |
131 | + } |
132 | + |
133 | + function setUp() { |
134 | + parent::setUp('openid'); |
135 | + } |
136 | + |
137 | + /* Start a good OpenID Authentication process */ |
138 | + function testOpenIDBegin() { |
139 | + $edit = array('openid_identifier' => 'https://login.launchpad.net/'); |
140 | + $this->drupalPost('/user', $edit, 'Log in'); |
141 | + $this->assertFieldById('edit-openid-redirect-form', 'openid_redirect_form', |
142 | + t('Ensure clicking login produces a OpenID redirect form')); |
143 | + } |
144 | + |
145 | + /* Start an incorrect OpenID Authentication process */ |
146 | + function testOpenIDFailBegin() { |
147 | + $edit = array('openid_identifier' => 'http://www.google.com/'); |
148 | + $this->drupalPost('/user', $edit, 'Log in'); |
149 | + $this->assertText('Sorry, that is not a valid OpenID.', |
150 | + 'Ensure providing an invalid OpenID prints an error'); |
151 | + } |
152 | + |
153 | +} |
154 | |
155 | === added file 'tests/complete.test' |
156 | --- tests/complete.test 1970-01-01 00:00:00 +0000 |
157 | +++ tests/complete.test 2009-05-12 18:23:43 +0000 |
158 | @@ -0,0 +1,57 @@ |
159 | +<?php |
160 | + |
161 | +class DrupalOpenIDCompleteTestCase extends DrupalWebTestCase { |
162 | + function getInfo() { |
163 | + return array( |
164 | + 'name' => t('OpenID Complete'), |
165 | + 'description' => t('openid_complete unit tests'), |
166 | + 'group' => t('OpenID'), |
167 | + ); |
168 | + } |
169 | + |
170 | + function setUp() { |
171 | + parent::setUp('openid'); |
172 | + } |
173 | + |
174 | + function testOpenIDCompleteEmpty() { |
175 | + $response = array(); |
176 | + $result = openid_complete($response); |
177 | + $this->assertEqual('failed', $result['status'], |
178 | + 'Ensure that an empty request results in a "failed" status'); |
179 | + } |
180 | + |
181 | + function testOpenIDCompleteCancelled() { |
182 | + $response = array(); |
183 | + $response['openid.mode'] = 'cancel'; |
184 | + $_SESSION['openid']['service']['uri'] = 'http://provider.net'; |
185 | + $_SESSION['openid']['claimed_id'] = 'http://provider.net/myid'; |
186 | + |
187 | + $result = openid_complete($response); |
188 | + $this->assertEqual('cancel', $result['status'], |
189 | + 'Ensure that a cancelled request results in a "cancel" status'); |
190 | + } |
191 | + |
192 | + function testOpenIDCompleteSuccess() { |
193 | + $response = array(); |
194 | + $response['openid.mode'] = 'success'; |
195 | + $response['openid.signed'] = 'afield,bfield'; |
196 | + $response['afield'] = 'aValue'; |
197 | + $response['bfield'] = 'bValue'; |
198 | + $_SESSION['openid']['service']['uri'] = 'http://provider.net'; |
199 | + $_SESSION['openid']['claimed_id'] = 'http://provider.net/myid'; |
200 | + $assoc = '{HMAC-SHA1}{01234567}{PHONEY==}'; |
201 | + $response['openid.assoc_handle'] = $assoc; |
202 | + db_query("INSERT INTO {openid_association} (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)", |
203 | + 'http://provider.net/', 'DH-SHA1', $assoc, 'HMAC-SHA1', 1209600, 'tHisIsATotaLlyFakeMACKeyYay=', time()); |
204 | + module_load_include('inc', 'openid'); |
205 | + $association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $assoc)); |
206 | + $keys_to_sign = explode(',', $response['openid.signed']); |
207 | + $self_sig = _openid_signature($association, $response, $keys_to_sign); |
208 | + $response['openid.sig'] = $self_sig; |
209 | + |
210 | + $result = openid_complete($response); |
211 | + $this->assertEqual('success', $result['status'], |
212 | + 'Ensure that a correct request results in a "success" status'); |
213 | + } |
214 | +} |
215 | + |
216 | |
217 | === added file 'tests/help.test' |
218 | --- tests/help.test 1970-01-01 00:00:00 +0000 |
219 | +++ tests/help.test 2009-05-12 18:23:43 +0000 |
220 | @@ -0,0 +1,28 @@ |
221 | +<?php |
222 | + |
223 | +class DrupalOpenIDHelpTestCase extends DrupalWebTestCase { |
224 | + function getInfo() { |
225 | + return array( |
226 | + 'name' => t('OpenID Help'), |
227 | + 'description' => t('Openid module Help unit tests'), |
228 | + 'group' => t('OpenID'), |
229 | + ); |
230 | + } |
231 | + |
232 | + function setUp() { |
233 | + parent::setUp('openid'); |
234 | + } |
235 | + /* Fetch all pages that show relevant OpenID help information */ |
236 | + function testDrupalOpenIDHelp() { |
237 | + $user = $this->drupalCreateUser(array('access content', 'access administration pages')); |
238 | + $this->drupalLogin($user); |
239 | + $path = 'user/'. $user->uid.'/openid'; |
240 | + $this->drupalGet($path); |
241 | + $this->assertText(t('This site supports OpenID'), |
242 | + t('Make sure the right help text appears on the user\'s OpenID page.')); |
243 | + $this->drupalGet('admin/help/openid'); |
244 | + $this->assertText(t('OpenID is a secure method for logging into many websites'), |
245 | + t('Make sure the right help text appears on the admin help page.')); |
246 | + } |
247 | +} |
248 | + |
249 | |
250 | === added file 'tests/lowlevel.test' |
251 | --- tests/lowlevel.test 1970-01-01 00:00:00 +0000 |
252 | +++ tests/lowlevel.test 2009-05-12 18:23:43 +0000 |
253 | @@ -0,0 +1,94 @@ |
254 | +<?php |
255 | + |
256 | +class DrupalOpenIDLowLevelTestCase extends DrupalWebTestCase { |
257 | + function getInfo() { |
258 | + return array( |
259 | + 'name' => t('OpenID Low Level'), |
260 | + 'description' => t('Exercises low-level OpenID functions'), |
261 | + 'group' => t('OpenID'), |
262 | + ); |
263 | + } |
264 | + |
265 | + function setUp() { |
266 | + parent::setUp('openid'); |
267 | + } |
268 | + |
269 | + function testOpenIDIsXRI() { |
270 | + module_load_include('inc', 'openid'); |
271 | + $this->assertTrue(_openid_is_xri('@myid'), '@myid is a valid XRI'); |
272 | + $this->assertTrue(_openid_is_xri('=family'), '=family is a valid XRI'); |
273 | + $this->assertTrue(_openid_is_xri('xri://google'), 'xri://google is a valid XRI'); |
274 | + $this->assertFalse(_openid_is_xri('http://www.google.com'), |
275 | + 'http://www.google.com is not a valid XRI'); |
276 | + } |
277 | + |
278 | + function testOpenIDNormalizeXRI() { |
279 | + module_load_include('inc', 'openid'); |
280 | + $this->assertEqual('@myid', _openid_normalize_xri('xri://@myid'), |
281 | + 'xri://@myid is normalized to @myid'); |
282 | + $this->assertEqual('@myid', _openid_normalize_xri('@myid'), |
283 | + '@myid is normalized to @myid'); |
284 | + } |
285 | + |
286 | + function testOpenIDNormalizeURL() { |
287 | + module_load_include('inc', 'openid'); |
288 | + $this->assertEqual('http://lala/', _openid_normalize_url('lala'), |
289 | + 'lala is normalized to http://lala/'); |
290 | + $this->assertEqual('http://lala/', _openid_normalize_url('http://lala'), |
291 | + 'http://lala is normalized to http://lala/'); |
292 | + $this->assertEqual('http://lala/', _openid_normalize_url('http://lala/'), |
293 | + 'http://lala/ is normalized to http://lala/'); |
294 | + } |
295 | + |
296 | + function testOpenIDNormalize() { |
297 | + module_load_include('inc', 'openid'); |
298 | + $this->assertEqual('@myid', _openid_normalize('xri://@myid'), |
299 | + 'xri://@myid is normalized to @myid'); |
300 | + $this->assertEqual('http://lala/', _openid_normalize('lala'), |
301 | + 'lala is normalized to http://lala/'); |
302 | + } |
303 | + |
304 | + function testOpenIDCreateMessage() { |
305 | + module_load_include('inc', 'openid'); |
306 | + $data = array("bad:data\n"=>"value\n"); |
307 | + $this->assertNull(_openid_create_message($data), |
308 | + 'Bad data returns a NULL OpenID message'); |
309 | + } |
310 | + |
311 | + function testOpenIDNonce() { |
312 | + module_load_include('inc', 'openid'); |
313 | + $this->assertTrue(is_string(_openid_nonce()), |
314 | + 'A nonce is generated'); |
315 | + } |
316 | + |
317 | + function testOpenIDMetaLinkHref() { |
318 | + module_load_include('inc', 'openid'); |
319 | + $html = '<link rel="stylesheet" href="style.css" />'; |
320 | + $rel = 'stylesheet'; |
321 | + $this->assertEqual('style.css', _openid_link_href($equiv, $html), |
322 | + 'Ensure HRef is correctly extracted'); |
323 | + $this->assertFalse(_openid_link_href('openid.delegate', $html), |
324 | + 'Ensure no HRef is extracted when not present'); |
325 | + |
326 | + } |
327 | + |
328 | + function testOpenIDMetaHTTPEquiv() { |
329 | + module_load_include('inc', 'openid'); |
330 | + $html = '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'; |
331 | + $equiv = 'Content-Type'; |
332 | + $this->assertEqual('text/html; charset=utf-8', |
333 | + _openid_meta_httpequiv($equiv, $html), |
334 | + 'Ensure HTTP-Equiv is correctly extracted'); |
335 | + $this->assertFalse(_openid_meta_httpequiv('X-XRDS-Location', $html), |
336 | + 'No HTTP-Equiv is extracted when not present'); |
337 | + |
338 | + } |
339 | + |
340 | + function testOpenIDGetBytes() { |
341 | + module_load_include('inc', 'openid'); |
342 | + $bytes = _openid_get_bytes(10); |
343 | + $this->assertTrue(is_string($bytes) && strlen($bytes) == 10, |
344 | + '_openid_get_bytes returns the correct amount of random data'); |
345 | + } |
346 | + |
347 | +} |
348 | |
349 | === added file 'tests/openid_test.info' |
350 | --- tests/openid_test.info 1970-01-01 00:00:00 +0000 |
351 | +++ tests/openid_test.info 2009-05-12 18:23:43 +0000 |
352 | @@ -0,0 +1,8 @@ |
353 | +; $Id$ |
354 | +name = "OpenID Test" |
355 | +description = "Support module for OpenID tests" |
356 | +package = Testing |
357 | +version = VERSION |
358 | +core = 6.x |
359 | +files[] = openid_test.module |
360 | +hidden = TRUE |
361 | |
362 | === added file 'tests/openid_test.module' |
363 | --- tests/openid_test.module 1970-01-01 00:00:00 +0000 |
364 | +++ tests/openid_test.module 2009-05-12 18:23:43 +0000 |
365 | @@ -0,0 +1,58 @@ |
366 | +<?php |
367 | +function openid_test_menu() { |
368 | + return array( |
369 | + 'openid/test/login' => array( |
370 | + 'title' => 'Fake login', |
371 | + 'page callback' => 'fake_login_with_email', |
372 | + 'access arguments' => array('access content'), |
373 | + ), |
374 | + 'openid/test/loginnoemail' => array( |
375 | + 'title' => 'Fake login w/o providing email', |
376 | + 'page callback' => 'fake_login_no_email', |
377 | + 'access arguments' => array('access content'), |
378 | + ), |
379 | + ); |
380 | +} |
381 | + |
382 | +function fake_login_with_email($claimed_id) { |
383 | + openid_test_fake_login($claimed_id, "{$claimed_id}@email.com"); |
384 | +} |
385 | + |
386 | +function fake_login_no_email($claimed_id) { |
387 | + openid_test_fake_login($claimed_id, ''); |
388 | +} |
389 | + |
390 | +function openid_test_fake_login($claimed_id, $email) { |
391 | + $_SESSION['openid']['service']['uri'] = $provider; |
392 | + $_SESSION['openid']['claimed_id'] = $claimed_id; |
393 | + $assoc = '{HMAC-SHA1}{01234567}{PHONEY==}'; |
394 | + $response['openid.assoc_handle'] = $assoc; |
395 | + $provider = 'http://provider.net'; |
396 | + $response['openid.claimed_id'] = "{$provider}/{$claimed_id}"; |
397 | + $response['openid.identity'] = "{$provider}/{$claimed_id}"; |
398 | + $response['openid.mode'] = 'id_res'; |
399 | + //http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0 |
400 | + $response['openid.ns'] = 'http://specs.openid.net/auth/2.0'; |
401 | + //http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1 |
402 | + $response['openid.ns.sreg'] = 'http://openid.net/extensions/sreg/1.1'; |
403 | + $response['openid.op_endpoint'] = "{$provider}/+openid"; |
404 | + $response['openid.response_nonce'] = 'noncense'; |
405 | + //http%3A%2F%2Flocalhost%2Fdrupal6%2Fopenid%2Fauthenticate%3Fdestination%3Dnode; |
406 | + $response['openid.return_to'] = 'http://localhost/openid/authenticate/'; |
407 | + //assoc_handle%2Cclaimed_id%2Cidentity%2Cmode%2Cns%2Cns.sreg%2Cop_endpoint%2Cresponse_nonce%2Creturn_to%2Csigned%2Csreg.nickname |
408 | + $response['openid.signed'] = 'assoc_handle,claimed_id,identity,mode,ns,ns.sreg,op_endpoint,response_nonce,return_to,signed,sreg.nickname,sreg.email'; |
409 | + $response['openid.sreg.nickname'] = $claimed_id; |
410 | + $response['openid.sreg.email'] = $email; |
411 | + |
412 | + db_query("DELETE FROM {openid_association} WHERE idp_endpoint_uri = '%s'", $provider); |
413 | + db_query("INSERT INTO {openid_association} (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)", |
414 | + $provider, 'DH-SHA1', $assoc, 'HMAC-SHA1', 1209600, 'tHisIsATotaLlyFakeMACKeyYay=', time()); |
415 | + module_load_include('inc', 'openid'); |
416 | + $association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $assoc)); |
417 | + $keys_to_sign = explode(',', $response['openid.signed']); |
418 | + $self_sig = _openid_signature($association, $response, $keys_to_sign); |
419 | + $keys_to_sign = explode(',', $response['openid.signed']); |
420 | + |
421 | + openid_authentication($response); |
422 | +} |
423 | + |
424 | |
425 | === added file 'tests/pages.test' |
426 | --- tests/pages.test 1970-01-01 00:00:00 +0000 |
427 | +++ tests/pages.test 2009-05-12 18:23:43 +0000 |
428 | @@ -0,0 +1,77 @@ |
429 | +<?php |
430 | + |
431 | +class DrupalOpenIDPagesTestCase extends DrupalWebTestCase { |
432 | + function getInfo() { |
433 | + return array( |
434 | + 'name' => t('OpenID Pages'), |
435 | + 'description' => t('OpenID Form generation unittests'), |
436 | + 'group' => t('OpenID'), |
437 | + ); |
438 | + } |
439 | + |
440 | + function setUp() { |
441 | + parent::setUp('openid', 'openid_test'); |
442 | + $this->uid = 12345; |
443 | + $this->aid = 432; |
444 | + $this->authname = 'http://provider.net/myid'; |
445 | + $this->name = 'somebody'; |
446 | + } |
447 | + |
448 | + function setUpAssociation() { |
449 | + db_query("INSERT INTO {authmap} (uid, aid, authname, module) VALUES (%d, %d, '%s', '%s')", |
450 | + $this->uid, $this->aid, $this->authname, 'openid'); |
451 | + } |
452 | + |
453 | + function testOpenIDUserAdd() { |
454 | + module_load_include('inc', 'openid', 'openid.pages'); |
455 | + variable_set('user_register', TRUE); |
456 | + $this->drupalGet('openid/test/login/doesntexist'); |
457 | + $this->assertText('My account', |
458 | + 'Ensure an account was successfully created'); |
459 | + $form = openid_user_add(); |
460 | + $this->assertTrue(is_array($form), 'Ensure a form was generated'); |
461 | + } |
462 | + |
463 | + function testOpenIDUserDeleteForm() { |
464 | + module_load_include('inc', 'openid', 'openid.pages.inc'); |
465 | + $form_state = array(); |
466 | + $account = (object)array('uid'=>$uid, 'name'=>$name); |
467 | + $form = openid_user_delete_form($form_state, $account, $aid); |
468 | + $this->assertEqual("Are you sure you want to delete the OpenID <em>{$authname}</em> for <em>{$name}</em>?", |
469 | + drupal_get_title(), |
470 | + 'Ensure a confirmation screen is shown'); |
471 | + $form_state['values']['uid'] = $uid; |
472 | + $form_state['values']['aid'] = $aid; |
473 | + openid_user_delete_form_submit(array(), $form_state); |
474 | + $this->assertEqual($form_state['redirect'], "user/{$uid}/openid", |
475 | + 'Ensure we are redirected back to the OpenID management screen'); |
476 | + } |
477 | + |
478 | + function testOpenIDUserIdentities() { |
479 | + module_load_include('inc', 'openid', 'openid.pages.inc'); |
480 | + $account = (object)array('uid'=>$uid, 'name'=>$name); |
481 | + $form = openid_user_identities($account); |
482 | + $this->setUpAssociation(); |
483 | + $form = openid_user_identities($account); |
484 | + |
485 | + } |
486 | + |
487 | + function testOpenIDUserAddSubmit() { |
488 | + module_load_include('inc', 'openid', 'openid.pages.inc'); |
489 | + $form = array(); |
490 | + $form['openid_identifier']['#value'] = $this->authname; |
491 | + $form_state = array(); |
492 | + openid_user_add_submit($form, $form_state); |
493 | + } |
494 | + |
495 | + function testOpenIDUserAddValidate() { |
496 | + $form_state['values']['openid_identifier'] = $this->authname; |
497 | + openid_user_add_validate(array(), $form_state); |
498 | + } |
499 | + |
500 | + function tearDown() { |
501 | + db_query("DELETE FROM {authmap} WHERE uid=%d AND aid=%d AND authname='%s' AND module='%s'", |
502 | + $this->uid, $this->aid, $this->authname, 'openid'); |
503 | + parent::tearDown(); |
504 | + } |
505 | +} |
506 | |
507 | === added file 'tests/verify_assertion.test' |
508 | --- tests/verify_assertion.test 1970-01-01 00:00:00 +0000 |
509 | +++ tests/verify_assertion.test 2009-05-12 18:23:43 +0000 |
510 | @@ -0,0 +1,53 @@ |
511 | +<?php |
512 | + |
513 | +/** |
514 | + * Verify openid_verify_assertion |
515 | + */ |
516 | +class DrupalOpenIDVerifyAssertionTestCase extends DrupalWebTestCase { |
517 | + function getInfo() { |
518 | + return array( |
519 | + 'name' => t('OpenID Verify Assertion'), |
520 | + 'description' => t('openid_verify_assertion unit tests'), |
521 | + 'group' => t('OpenID'), |
522 | + ); |
523 | + } |
524 | + function setUp() { |
525 | + parent::setUp('openid'); |
526 | + $this->assoc = '{HMAC-SHA1}{01234567}{PHONEY==}'; |
527 | + $this->response = array('openid.assoc_handle' => $this->assoc, |
528 | + 'openid.signed' => 'afield,bfield', |
529 | + 'afield' => 'aValue', |
530 | + 'bfield' => 'bValue'); |
531 | + } |
532 | + |
533 | + function setUpAssociation() { |
534 | + // Create an association |
535 | + db_query("INSERT INTO {openid_association} (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)", |
536 | + 'http://provider.net/', 'DH-SHA1', $this->assoc, 'HMAC-SHA1', 1209600, 'tHisIsATotaLlyFakeMACKeyYay=', time()); |
537 | + } |
538 | + |
539 | + function testOpenIDFailAssertion() { |
540 | + $this->setUpAssociation(); |
541 | + $this->response['openid.sig'] = 'notAValidSignature'; |
542 | + $this->assertFalse(openid_verify_assertion('endpoint', $this->response), |
543 | + 'Make sure openid_verify_assertion fails for an invalid signature'); |
544 | + } |
545 | + |
546 | + function testOpenIDSucceedAssertion() { |
547 | + $this->setUpAssociation(); |
548 | + module_load_include('inc', 'openid'); |
549 | + $association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $this->assoc)); |
550 | + $keys_to_sign = explode(',', $this->response['openid.signed']); |
551 | + $self_sig = _openid_signature($association, $this->response, $keys_to_sign); |
552 | + $this->response['openid.sig'] = $self_sig; |
553 | + $this->assertTrue(openid_verify_assertion('endpoint', $this->response), |
554 | + 'Make sure openid_verify_assertion succeeds for a valid signature'); |
555 | + } |
556 | + |
557 | + function testOpenIDCheckAssertion() { |
558 | + $this->assertFalse(openid_verify_assertion('endpoint', $this->response), |
559 | + 'openid_verify_assertion fails when unable to check authentication'); |
560 | + } |
561 | + |
562 | +} |
563 | + |
Added quite a few unittests, so tests are now split out in to multiple files in the tests/ folder.
No feature changes.