Adding enclosures now treats type and length parameters as optional for Atom, but...
[zend.git] / tests / Zend / OpenIdTest.php
blob90c355e14b6496eef9aeeb6bb477bd1063f11176
1 <?php
2 /**
3 * Zend Framework
5 * LICENSE
7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
15 * @category Zend
16 * @package Zend_OpenId
17 * @subpackage UnitTests
18 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id$
24 /**
25 * Test helper
27 require_once dirname(__FILE__) . '/../TestHelper.php';
29 /**
30 * Zend_OpenId
32 require_once 'Zend/OpenId.php';
35 /**
36 * PHPUnit test case
38 require_once 'PHPUnit/Framework.php';
41 /**
42 * Zend_OpenId_ResponseHelper
44 require_once 'Zend/OpenId/ResponseHelper.php';
47 /**
48 * @category Zend
49 * @package Zend_OpenId
50 * @subpackage UnitTests
51 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
52 * @license http://framework.zend.com/license/new-bsd New BSD License
53 * @group Zend_OpenId
55 class Zend_OpenIdTest extends PHPUnit_Framework_TestCase
57 private $_serverVariables;
59 public function setUp()
61 $this->_serverVariables = $_SERVER;
64 public function tearDown()
66 $_SERVER = $this->_serverVariables;
70 /**
71 * testing testSelfUrl
74 public function testSelfUrl()
76 unset($_SERVER['SCRIPT_URI']);
77 unset($_SERVER['HTTPS']);
78 unset($_SERVER['HTTP_HOST']);
79 unset($_SERVER['SERVER_NAME']);
80 unset($_SERVER['SERVER_PORT']);
81 unset($_SERVER['SCRIPT_URL']);
82 unset($_SERVER['REDIRECT_URL']);
83 unset($_SERVER['PHP_SELF']);
84 unset($_SERVER['SCRIPT_NAME']);
85 unset($_SERVER['PATH_INFO']);
86 $this->assertSame( 'http://', Zend_OpenId::selfUrl() );
88 $_SERVER['SCRIPT_URI'] = "http://www.test.com/";
89 $this->assertSame( 'http://www.test.com/', Zend_OpenId::selfUrl() );
91 unset($_SERVER['SCRIPT_URI']);
92 $_SERVER['HTTP_HOST'] = "www.test.com";
93 $_SERVER['SERVER_NAME'] = "www.wrong.com";
94 $this->assertSame( 'http://www.test.com', Zend_OpenId::selfUrl() );
96 $_SERVER['HTTP_HOST'] = "www.test.com:80";
97 $this->assertSame( 'http://www.test.com', Zend_OpenId::selfUrl() );
99 $_SERVER['HTTP_HOST'] = "www.test.com:8080";
100 $this->assertSame( 'http://www.test.com:8080', Zend_OpenId::selfUrl() );
102 $_SERVER['HTTP_HOST'] = "www.test.com";
103 $_SERVER['SERVER_PORT'] = "80";
104 $this->assertSame( 'http://www.test.com', Zend_OpenId::selfUrl() );
106 $_SERVER['SERVER_PORT'] = "8080";
107 $this->assertSame( 'http://www.test.com:8080', Zend_OpenId::selfUrl() );
109 unset($_SERVER['HTTP_HOST']);
110 unset($_SERVER['SERVER_PORT']);
111 $_SERVER['SERVER_NAME'] = "www.test.com";
112 $this->assertSame( 'http://www.test.com', Zend_OpenId::selfUrl() );
114 $_SERVER['SERVER_PORT'] = "80";
115 $this->assertSame( 'http://www.test.com', Zend_OpenId::selfUrl() );
117 $_SERVER['SERVER_PORT'] = "8080";
118 $this->assertSame( 'http://www.test.com:8080', Zend_OpenId::selfUrl() );
120 unset($_SERVER['SERVER_PORT']);
121 $_SERVER['HTTPS'] = "on";
122 $this->assertSame( 'https://www.test.com', Zend_OpenId::selfUrl() );
124 $_SERVER['SERVER_PORT'] = "443";
125 $this->assertSame( 'https://www.test.com', Zend_OpenId::selfUrl() );
127 $_SERVER['SERVER_PORT'] = "8080";
128 $this->assertSame( 'https://www.test.com:8080', Zend_OpenId::selfUrl() );
130 unset($_SERVER['SERVER_PORT']);
131 unset($_SERVER['HTTPS']);
133 $_SERVER['SCRIPT_URL'] = '/test.php';
134 $_SERVER['PHP_SELF'] = '/bug.php';
135 $_SERVER['SCRIPT_NAME'] = '/bug.php';
136 $_SERVER['PATH_INFO'] = '/bug';
137 $this->assertSame( 'http://www.test.com/test.php', Zend_OpenId::selfUrl() );
139 unset($_SERVER['SCRIPT_URL']);
140 $_SERVER['REDIRECT_URL'] = '/ok';
141 $_SERVER['PHP_SELF'] = '/bug.php';
142 $_SERVER['SCRIPT_NAME'] = '/bug.php';
143 $_SERVER['PATH_INFO'] = '/bug';
144 $this->assertSame( 'http://www.test.com/ok', Zend_OpenId::selfUrl() );
146 unset($_SERVER['REDIRECT_URL']);
147 $_SERVER['PHP_SELF'] = '/test.php';
148 $this->assertSame( 'http://www.test.com/test.php', Zend_OpenId::selfUrl() );
150 unset($_SERVER['PHP_SELF']);
151 $_SERVER['SCRIPT_NAME'] = '/test.php';
152 $_SERVER['PATH_INFO'] = '/ok';
153 $this->assertSame( 'http://www.test.com/test.php/ok', Zend_OpenId::selfUrl() );
155 unset($_SERVER['PATH_INFO']);
156 $this->assertSame( 'http://www.test.com/test.php', Zend_OpenId::selfUrl() );
160 * testing testAbsolutefUrl
163 public function testAbsoluteUrl()
165 unset($_SERVER['SCRIPT_URI']);
166 unset($_SERVER['HTTPS']);
167 unset($_SERVER['HTTP_HOST']);
168 unset($_SERVER['SERVER_NAME']);
169 unset($_SERVER['SERVER_PORT']);
170 unset($_SERVER['SCRIPT_URL']);
171 unset($_SERVER['REDIRECT_URL']);
172 unset($_SERVER['PHP_SELF']);
173 unset($_SERVER['SCRIPT_NAME']);
174 unset($_SERVER['PATH_INFO']);
176 $_SERVER['HTTP_HOST'] = "www.test.com";
177 $_SERVER['SCRIPT_NAME'] = '/a/b/c/test.php';
179 $this->assertSame( 'http://www.test.com/a/b/c/test.php', Zend_OpenId::absoluteUrl("") );
181 $this->assertSame( 'http://www.test.com/a/b/c/ok.php', Zend_OpenId::absoluteUrl("ok.php") );
183 $this->assertSame( 'http://www.test.com/a/ok.php', Zend_OpenId::absoluteUrl("/a/ok.php") );
185 $this->assertSame( 'http://www.php.net/ok.php', Zend_OpenId::absoluteUrl("http://www.php.net/ok.php") );
187 $this->assertSame( 'https://www.php.net/ok.php', Zend_OpenId::absoluteUrl("https://www.php.net/ok.php") );
189 $_SERVER['SCRIPT_NAME'] = '/test.php';
190 $this->assertSame( 'http://www.test.com/a/b.php', Zend_OpenId::absoluteUrl("/a/b.php") );
192 $this->assertSame( 'http://www.test.com/a/b.php', Zend_OpenId::absoluteUrl("a/b.php") );
196 * testing testParamsToQuery
199 public function testParamsToQuery()
201 $this->assertSame( '', Zend_OpenId::paramsToQuery(array()) );
202 $this->assertSame( 'a=1', Zend_OpenId::paramsToQuery(array('a'=>1)) );
203 $this->assertSame( 'a=1&b=2', Zend_OpenId::paramsToQuery(array('a'=>1,'b'=>2)) );
204 $this->assertSame( 'a=x+y', Zend_OpenId::paramsToQuery(array('a'=>'x y')) );
208 * testing testNormalizeUrl
211 public function testNormalizeUrl()
213 $url = 'example://a/b/c/%7Bfoo%7D';
214 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
215 $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url );
217 $url = 'eXAMPLE://A/./b/../b/%63/%7bfoo%7d';
218 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
219 $this->assertSame( 'example://a/b/c/%7Bfoo%7D', $url );
221 $url = 'eXAMPLE://A/./b/../b/%63/%bbfoo%Bd';
222 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
223 $this->assertSame( 'example://a/b/c/%BBfoo%BD', $url );
225 $url = 'example://a/b/c/%1';
226 $this->assertFalse( Zend_OpenId::normalizeUrl($url) );
228 $url = 'example://a/b/c/%x1';
229 $this->assertFalse( Zend_OpenId::normalizeUrl($url) );
231 $url = 'example://a/b/c/%1x';
232 $this->assertFalse( Zend_OpenId::normalizeUrl($url) );
234 $url = 'eXAMPLE://A/b/c/x%20y';
235 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
236 $this->assertSame( 'example://a/b/c/x%20y', $url );
238 $url = 'example://host/.a/b/c';
239 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
240 $this->assertSame( 'example://host/.a/b/c', $url );
242 $url = 'a/b/c';
243 $this->assertFalse( Zend_OpenId::normalizeUrl($url) );
245 $url = 'example://:80/a/b/c';
246 $this->assertFalse( Zend_OpenId::normalizeUrl($url) );
248 $url = 'example://host/a/.b/c';
249 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
250 $this->assertSame( 'example://host/a/.b/c', $url );
252 $url = 'example://host/a/b/.c';
253 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
254 $this->assertSame( 'example://host/a/b/.c', $url );
256 $url = 'example://host/..a/b/c';
257 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
258 $this->assertSame( 'example://host/..a/b/c', $url );
260 $url = 'example://host/a/..b/c';
261 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
262 $this->assertSame( 'example://host/a/..b/c', $url );
264 $url = 'example://host/a/b/..c';
265 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
266 $this->assertSame( 'example://host/a/b/..c', $url );
268 $url = 'example://host/./b/c';
269 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
270 $this->assertSame( 'example://host/b/c', $url );
272 $url = 'example://host/a/./c';
273 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
274 $this->assertSame( 'example://host/a/c', $url );
276 $url = 'example://host/a/b/.';
277 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
278 $this->assertSame( 'example://host/a/b', $url );
280 $url = 'example://host/a/b/./';
281 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
282 $this->assertSame( 'example://host/a/b/', $url );
284 $url = 'example://host/../b/c';
285 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
286 $this->assertSame( 'example://host/b/c', $url );
288 $url = 'example://host/a/../c';
289 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
290 $this->assertSame( 'example://host/c', $url );
292 $url = 'example://host/a/b/..';
293 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
294 $this->assertSame( 'example://host/a', $url );
296 $url = 'example://host/a/b/../';
297 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
298 $this->assertSame( 'example://host/a/', $url );
300 $url = 'example://host/a/b/c/..';
301 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
302 $this->assertSame( 'example://host/a/b', $url );
304 $url = 'example://host/a/b/c/../..';
305 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
306 $this->assertSame( 'example://host/a', $url );
308 $url = 'example://host/a/b/c/../../..';
309 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
310 $this->assertSame( 'example://host/', $url );
312 $url = 'example://host///a///b///c///..///../d';
313 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
314 $this->assertSame( 'example://host/a/d', $url );
316 $url = 'example://host///a///b///c///.///./d';
317 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
318 $this->assertSame( 'example://host/a/b/c/d', $url );
320 $url = 'example://host///a///b///c///..///./d';
321 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
322 $this->assertSame( 'example://host/a/b/d', $url );
324 $url = 'example://host///a///b///c///.///../d';
325 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
326 $this->assertSame( 'example://host/a/b/d', $url );
328 $url = 'http://example.com';
329 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
330 $this->assertSame( 'http://example.com/', $url );
332 $url = 'http://example.com/';
333 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
334 $this->assertSame( 'http://example.com/', $url );
336 $url = 'http://example.com:';
337 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
338 $this->assertSame( 'http://example.com/', $url );
340 $url = 'http://example.com:80/';
341 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
342 $this->assertSame( 'http://example.com/', $url );
344 $url = 'https://example.com:443/';
345 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
346 $this->assertSame( 'https://example.com/', $url );
348 $url = 'http://example.com?';
349 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
350 $this->assertSame( 'http://example.com/?', $url );
352 $url = 'http://example.com/?';
353 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
354 $this->assertSame( 'http://example.com/?', $url );
356 $url = 'http://example.com/test.php?Foo=Bar#Baz';
357 $this->assertTrue( Zend_OpenId::normalizeUrl($url) );
358 $this->assertSame( 'http://example.com/test.php?Foo=Bar', $url );
362 * testing testNormalize
365 public function testNormalize()
367 $url = '';
368 $this->assertTrue( Zend_OpenId::normalize($url) );
369 $this->assertSame( '', $url );
371 $url = ' localhost ';
372 $this->assertTrue( Zend_OpenId::normalize($url) );
373 $this->assertSame( 'http://localhost/', $url );
375 $url = 'xri://$ip*127.0.0.1';
376 $this->assertTrue( Zend_OpenId::normalize($url) );
377 $this->assertSame( 'http://127.0.0.1/', $url );
379 $url = 'xri://$dns*localhost';
380 $this->assertTrue( Zend_OpenId::normalize($url) );
381 $this->assertSame( 'http://localhost/', $url );
383 $url = 'xri://localhost';
384 $this->assertTrue( Zend_OpenId::normalize($url) );
385 $this->assertSame( 'http://localhost/', $url );
387 $url = '=name';
388 $this->assertTrue( Zend_OpenId::normalize($url) );
389 $this->assertSame( '=name', $url );
391 $url = '@name';
392 $this->assertTrue( Zend_OpenId::normalize($url) );
393 $this->assertSame( '@name', $url );
395 $url = '+name';
396 $this->assertTrue( Zend_OpenId::normalize($url) );
397 $this->assertSame( '+name', $url );
399 $url = '$name';
400 $this->assertTrue( Zend_OpenId::normalize($url) );
401 $this->assertSame( '$name', $url );
403 $url = '!name';
404 $this->assertTrue( Zend_OpenId::normalize($url) );
405 $this->assertSame( '!name', $url );
407 $url = 'localhost';
408 $this->assertTrue( Zend_OpenId::normalize($url) );
409 $this->assertSame( 'http://localhost/', $url );
411 $url = 'http://localhost';
412 $this->assertTrue( Zend_OpenId::normalize($url) );
413 $this->assertSame( 'http://localhost/', $url );
415 $url = 'https://localhost';
416 $this->assertTrue( Zend_OpenId::normalize($url) );
417 $this->assertSame( 'https://localhost/', $url );
421 * testing testRedirect
424 public function testRedirect()
426 $response = new Zend_OpenId_ResponseHelper(true);
427 Zend_OpenId::redirect("http://www.test.com/", null, $response, 'GET');
428 $this->assertSame( 302, $response->getHttpResponseCode() );
429 $this->assertSame( array(), $response->getRawHeaders() );
430 $headers = $response->getHeaders();
431 $this->assertTrue( is_array($headers) );
432 $this->assertSame( 1, count($headers) );
433 $this->assertTrue( is_array($headers[0]) );
434 $this->assertSame( 3, count($headers[0]) );
435 $this->assertSame( 'Location', $headers[0]['name'] );
436 $this->assertSame( 'http://www.test.com/', $headers[0]['value'] );
437 $this->assertSame( true, $headers[0]['replace'] );
438 $this->assertSame( '', $response->getBody() );
440 $response = new Zend_OpenId_ResponseHelper(true);
441 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", null, $response, 'GET');
442 $headers = $response->getHeaders();
443 $this->assertSame( 'http://www.test.com/test.php?a=b', $headers[0]['value'] );
445 $response = new Zend_OpenId_ResponseHelper(true);
446 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b'), $response, 'GET');
447 $headers = $response->getHeaders();
448 $this->assertSame( 'http://www.test.com/test.php?a=b', $headers[0]['value'] );
450 $response = new Zend_OpenId_ResponseHelper(true);
451 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b', 'c'=>'d'), $response, 'GET');
452 $headers = $response->getHeaders();
453 $this->assertSame( 'http://www.test.com/test.php?a=b&c=d', $headers[0]['value'] );
455 $response = new Zend_OpenId_ResponseHelper(true);
456 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('c'=>'d'), $response, 'GET');
457 $headers = $response->getHeaders();
458 $this->assertSame( 'http://www.test.com/test.php?a=b&c=d', $headers[0]['value'] );
460 $response = new Zend_OpenId_ResponseHelper(true);
461 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'x y'), $response, 'GET');
462 $headers = $response->getHeaders();
463 $this->assertSame( 'http://www.test.com/test.php?a=x+y', $headers[0]['value'] );
465 $response = new Zend_OpenId_ResponseHelper(false);
466 Zend_OpenId::redirect("http://www.test.com/", null, $response, 'GET');
467 $this->assertSame( 200, $response->getHttpResponseCode() );
468 $this->assertSame( array(), $response->getRawHeaders() );
469 $this->assertSame( array(), $response->getHeaders() );
470 $this->assertSame(
471 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/';</script>",
472 $response->getBody() );
474 $response = new Zend_OpenId_ResponseHelper(false);
475 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", null, $response, 'GET');
476 $this->assertSame(
477 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b';</script>",
478 $response->getBody() );
480 $response = new Zend_OpenId_ResponseHelper(false);
481 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b'), $response, 'GET');
482 $this->assertSame(
483 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b';</script>",
484 $response->getBody() );
486 $response = new Zend_OpenId_ResponseHelper(false);
487 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'b','c'=>'d'), $response, 'GET');
488 $this->assertSame(
489 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b&c=d';</script>",
490 $response->getBody() );
492 $response = new Zend_OpenId_ResponseHelper(false);
493 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('c'=>'d'), $response, 'GET');
494 $this->assertSame(
495 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=b&c=d';</script>",
496 $response->getBody() );
498 $response = new Zend_OpenId_ResponseHelper(false);
499 Zend_OpenId::redirect("http://www.test.com/test.php", array('a'=>'x y'), $response, 'GET');
500 $this->assertSame(
501 "<script language=\"JavaScript\" type=\"text/javascript\">window.location='http://www.test.com/test.php?a=x+y';</script>",
502 $response->getBody() );
504 $response = new Zend_OpenId_ResponseHelper(true);
505 Zend_OpenId::redirect("http://www.test.com/", null, $response, 'POST');
506 $this->assertSame( 200, $response->getHttpResponseCode() );
507 $this->assertSame( array(), $response->getRawHeaders() );
508 $this->assertSame( array(), $response->getHeaders() );
509 $this->assertSame(
510 "<html><body onLoad=\"document.forms[0].submit();\">\n" .
511 "<form method=\"POST\" action=\"http://www.test.com/\">\n" .
512 "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
513 "</form></body></html>\n",
514 $response->getBody() );
516 $response = new Zend_OpenId_ResponseHelper(true);
517 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('a'=>'b'), $response, 'POST');
518 $this->assertSame(
519 "<html><body onLoad=\"document.forms[0].submit();\">\n" .
520 "<form method=\"POST\" action=\"http://www.test.com/test.php?a=b\">\n" .
521 "<input type=\"hidden\" name=\"a\" value=\"b\">\n" .
522 "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
523 "</form></body></html>\n",
524 $response->getBody() );
526 $response = new Zend_OpenId_ResponseHelper(true);
527 Zend_OpenId::redirect("http://www.test.com/test.php?a=b", array('a'=>'b','c'=>'d'), $response, 'POST');
528 $this->assertSame(
529 "<html><body onLoad=\"document.forms[0].submit();\">\n" .
530 "<form method=\"POST\" action=\"http://www.test.com/test.php?a=b\">\n" .
531 "<input type=\"hidden\" name=\"a\" value=\"b\">\n" .
532 "<input type=\"hidden\" name=\"c\" value=\"d\">\n" .
533 "<input type=\"submit\" value=\"Continue OpenID transaction\">\n" .
534 "</form></body></html>\n",
535 $response->getBody() );
539 * testing testRedirect
542 public function testRandomBytes()
544 $this->assertSame( '', Zend_OpenId::randomBytes(0) );
545 $x = Zend_OpenId::randomBytes(1);
546 $this->assertTrue( is_string($x) );
547 $this->assertSame( 1, strlen($x) );
548 $x = Zend_OpenId::randomBytes(1024);
549 $this->assertTrue( is_string($x) );
550 $this->assertSame( 1024, strlen($x) );
554 * testing testDigest
557 public function testDigest()
559 $this->assertSame(
560 'aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d',
561 bin2hex(Zend_OpenId::digest('sha1', 'hello')) );
562 $this->assertSame(
563 '2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824',
564 bin2hex(Zend_OpenId::digest('sha256', 'hello')) );
568 * testing testHashHmac
571 public function testHashHmac()
573 $key = 'password';
574 $this->assertSame(
575 '1f48abc79459fa853af681ddb3c73ff7f35c48fb',
576 bin2hex(Zend_OpenId::hashHmac('sha1', 'hello', $key)) );
577 $this->assertSame(
578 '7ae615e698567e5e1512dd8140e740bd4d65dfa4db195d80ca327de6302b4a63',
579 bin2hex(Zend_OpenId::hashHmac('sha256', 'hello', $key)) );
580 $key = str_repeat('x',128);
581 $this->assertSame(
582 '59c6c30dc9fb96b2cb2d7c41dbc6f96d1fbf67ac',
583 bin2hex(Zend_OpenId::hashHmac('sha1', 'hello', $key)) );
584 $this->assertSame(
585 'f5e0c31f7cdd272710052ac3ebcc40d7e82be2427b7e5e1e8373ef1e327515f4',
586 bin2hex(Zend_OpenId::hashHmac('sha256', 'hello', $key)) );
590 * testing testCreateDhKey
593 public function testCreateDhKey()
595 try {
596 $dh = Zend_OpenId::createDhKey(
597 pack('H*', '0233'),
598 pack('H*', '05'),
599 pack('H*', '09'));
600 $dh_details = Zend_OpenId::getDhKeyDetails($dh);
601 $this->assertTrue( is_array($dh_details) );
602 $this->assertSame( 4, count($dh_details));
603 $this->assertSame( '0233', bin2hex($dh_details['p']) );
604 $this->assertSame( '05', bin2hex($dh_details['g']) );
605 $this->assertSame( '09', bin2hex($dh_details['priv_key']) );
606 $this->assertSame( '4e', bin2hex($dh_details['pub_key']) );
608 $dh = Zend_OpenId::createDhKey(
609 pack('H*', '0233'),
610 pack('H*', '02'),
611 pack('H*', '09'));
612 $dh_details = Zend_OpenId::getDhKeyDetails($dh);
613 $this->assertTrue( is_array($dh_details) );
614 $this->assertSame( 4, count($dh_details) );
615 $this->assertSame( '0233', bin2hex($dh_details['p']) );
616 $this->assertSame( '02', bin2hex($dh_details['g']) );
617 $this->assertSame( '09', bin2hex($dh_details['priv_key']) );
618 $this->assertSame( '0200', bin2hex($dh_details['pub_key']) );
620 $dh = Zend_OpenId::createDhKey(
621 pack('H*', '0233'),
622 pack('H*', '02'));
623 $dh_details = Zend_OpenId::getDhKeyDetails($dh);
624 $this->assertTrue( is_array($dh_details) );
625 $this->assertSame( 4, count($dh_details) );
626 $this->assertSame( '0233', bin2hex($dh_details['p']) );
627 $this->assertSame( '02', bin2hex($dh_details['g']) );
628 $this->assertTrue( is_string($dh_details['priv_key']) );
629 $this->assertTrue( strlen($dh_details['priv_key']) > 0 );
630 $this->assertTrue( is_string($dh_details['pub_key']) );
631 $this->assertTrue( strlen($dh_details['pub_key']) > 0 );
632 } catch (Zend_OpenId_Exception $e) {
633 $this->markTestSkipped($e->getMessage());
638 * testing testComputeDhSecret
641 public function testComputeDhSecret()
643 try {
644 $alice = Zend_OpenId::createDhKey(
645 pack('H*', '0233'),
646 pack('H*', '05'),
647 pack('H*', '09'));
648 $alice_details = Zend_OpenId::getDhKeyDetails($alice);
649 $this->assertSame( '4e', bin2hex($alice_details['pub_key']) );
651 $bob = Zend_OpenId::createDhKey(
652 pack('H*', '0233'),
653 pack('H*', '05'),
654 pack('H*', '0e'));
655 $bob_details = Zend_OpenId::getDhKeyDetails($bob);
656 $this->assertSame( '0216', bin2hex($bob_details['pub_key']) );
658 $this->assertSame( '75',
659 bin2hex(Zend_OpenId::computeDhSecret($alice_details['pub_key'], $bob)) );
660 $this->assertSame( '75',
661 bin2hex(Zend_OpenId::computeDhSecret($bob_details['pub_key'], $alice)) );
662 } catch (Zend_OpenId_Exception $e) {
663 $this->markTestSkipped($e->getMessage());
668 * testing testBtwoc
671 public function testBtwoc()
673 $this->assertSame( '00', bin2hex(Zend_OpenId::btwoc(pack('H*', '00'))) );
674 $this->assertSame( '01', bin2hex(Zend_OpenId::btwoc(pack('H*', '01'))) );
675 $this->assertSame( '7e', bin2hex(Zend_OpenId::btwoc(pack('H*', '7e'))) );
676 $this->assertSame( '78', bin2hex(Zend_OpenId::btwoc(pack('H*', '78'))) );
677 $this->assertSame( '0080', bin2hex(Zend_OpenId::btwoc(pack('H*', '80'))) );
678 $this->assertSame( '0081', bin2hex(Zend_OpenId::btwoc(pack('H*', '81'))) );
679 $this->assertSame( '00fe', bin2hex(Zend_OpenId::btwoc(pack('H*', 'fe'))) );
680 $this->assertSame( '00ff', bin2hex(Zend_OpenId::btwoc(pack('H*', 'ff'))) );
684 * testing setSelfUrl
687 public function testSetSelfUrl()
689 unset($_SERVER['SCRIPT_URI']);
690 unset($_SERVER['HTTPS']);
691 unset($_SERVER['HTTP_HOST']);
692 unset($_SERVER['SERVER_NAME']);
693 unset($_SERVER['SERVER_PORT']);
694 unset($_SERVER['SCRIPT_URL']);
695 unset($_SERVER['REDIRECT_URL']);
696 unset($_SERVER['PHP_SELF']);
697 unset($_SERVER['SCRIPT_NAME']);
698 unset($_SERVER['PATH_INFO']);
699 $_SERVER['SCRIPT_URI'] = "http://www.test.com/";
701 $this->assertSame( 'http://www.test.com/', Zend_OpenId::selfUrl() );
703 $this->assertSame( null, Zend_OpenId::setSelfUrl("http://localhost/test") );
704 $this->assertSame( "http://localhost/test", Zend_OpenId::selfUrl() );
706 $this->assertSame( "http://localhost/test", Zend_OpenId::setSelfUrl() );
707 $this->assertSame( 'http://www.test.com/', Zend_OpenId::selfUrl() );
709 $this->assertSame( null, Zend_OpenId::setSelfUrl() );
710 $this->assertSame( 'http://www.test.com/', Zend_OpenId::selfUrl() );