diff options
author | Dominik Eckelmann <deckelmann@gmail.com> | 2012-04-01 18:45:19 +0200 |
---|---|---|
committer | Dominik Eckelmann <deckelmann@gmail.com> | 2012-04-01 18:45:19 +0200 |
commit | 9afc28a2ae123ae8a1d88d2a4ebf8b47c61963bf (patch) | |
tree | bd914c690133c00de48fa764211658e1afaaefdc | |
parent | 739071715cb5267191e4a5b5824fbc28a2fa3ef4 (diff) | |
download | rpg-9afc28a2ae123ae8a1d88d2a4ebf8b47c61963bf.tar.gz rpg-9afc28a2ae123ae8a1d88d2a4ebf8b47c61963bf.tar.bz2 |
transformed auth unit tests
-rw-r--r-- | _testing/README | 7 | ||||
-rw-r--r-- | _testing/unittests/inc/auth_admincheck.test.php | 130 | ||||
-rw-r--r-- | _testing/unittests/inc/auth_nameencode.test.php | 50 | ||||
-rw-r--r-- | _testing/unittests/inc/auth_password.test.php | 70 |
4 files changed, 256 insertions, 1 deletions
diff --git a/_testing/README b/_testing/README index 02f00fd5d..5b55639cb 100644 --- a/_testing/README +++ b/_testing/README @@ -12,4 +12,9 @@ The easiest way to install phpunit is via pear: pear install pear.phpunit.de/PHPUnit ==== Run unit tests ==== - phpunit -c _testing/unittest.xml
\ No newline at end of file + phpunit -c _testing/unittest.xml + +==== Bad tests ==== +Bad tests are tests that do not run out of the box. + + * inc/auth_aclcheck
\ No newline at end of file diff --git a/_testing/unittests/inc/auth_admincheck.test.php b/_testing/unittests/inc/auth_admincheck.test.php new file mode 100644 index 000000000..b3ead7d23 --- /dev/null +++ b/_testing/unittests/inc/auth_admincheck.test.php @@ -0,0 +1,130 @@ +<?php + +require_once DOKU_INC.'inc/init.php'; +require_once DOKU_INC.'inc/auth.php'; +require_once DOKU_INC.'inc/auth/basic.class.php'; + +class auth_admin_test_AuthInSensitive extends auth_basic { + function isCaseSensitive(){ + return false; + } +} + +class auth_admin_test extends PHPUnit_Framework_TestCase { + + private $oldauth; + + function setup() { + global $auth; + $this->oldauth = $auth; + } + + function setSensitive() { + global $auth; + $auth = new auth_basic(); + } + + function setInSensitive() { + global $auth; + $auth = new auth_admin_test_AuthInSensitive(); + } + + function teardown() { + global $auth; + global $conf; + global $AUTH_ACL; + unset($conf); + unset($AUTH_ACL); + $auth = $this->oldauth; + } + + function test_ismanager_insensitive(){ + $this->setInSensitive(); + global $conf; + $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte'; + $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny'; + + // anonymous user + $this->assertEquals(auth_ismanager('jill', null,false), false); + + // admin or manager users + $this->assertEquals(auth_ismanager('john', null,false), true); + $this->assertEquals(auth_ismanager('doe', null,false), true); + + $this->assertEquals(auth_ismanager('dörte', null,false), true); + $this->assertEquals(auth_ismanager('dänny', null,false), true); + + // admin or manager groups + $this->assertEquals(auth_ismanager('jill', array('admin'),false), true); + $this->assertEquals(auth_ismanager('jill', array('managers'),false), true); + + $this->assertEquals(auth_ismanager('jill', array('mötly görls'),false), true); + $this->assertEquals(auth_ismanager('jill', array('mötly böys'),false), true); + } + + function test_isadmin_insensitive(){ + $this->setInSensitive(); + global $conf; + $conf['superuser'] = 'john,@admin,doe,@roots'; + + // anonymous user + $this->assertEquals(auth_ismanager('jill', null,true), false); + + // admin user + $this->assertEquals(auth_ismanager('john', null,true), true); + $this->assertEquals(auth_ismanager('doe', null,true), true); + + // admin groups + $this->assertEquals(auth_ismanager('jill', array('admin'),true), true); + $this->assertEquals(auth_ismanager('jill', array('roots'),true), true); + $this->assertEquals(auth_ismanager('john', array('admin'),true), true); + $this->assertEquals(auth_ismanager('doe', array('admin'),true), true); + } + + function test_ismanager_sensitive(){ + $this->setSensitive(); + global $conf; + $conf['superuser'] = 'john,@admin,@Mötly Görls, Dörte'; + $conf['manager'] = 'john,@managers,doe, @Mötly Böys, Dänny'; + + // anonymous user + $this->assertEquals(auth_ismanager('jill', null,false), false); + + // admin or manager users + $this->assertEquals(auth_ismanager('john', null,false), true); + $this->assertEquals(auth_ismanager('doe', null,false), true); + + $this->assertEquals(auth_ismanager('dörte', null,false), false); + $this->assertEquals(auth_ismanager('dänny', null,false), false); + + // admin or manager groups + $this->assertEquals(auth_ismanager('jill', array('admin'),false), true); + $this->assertEquals(auth_ismanager('jill', array('managers'),false), true); + + $this->assertEquals(auth_ismanager('jill', array('mötly görls'),false), false); + $this->assertEquals(auth_ismanager('jill', array('mötly böys'),false), false); + } + + function test_isadmin_sensitive(){ + $this->setSensitive(); + global $conf; + $conf['superuser'] = 'john,@admin,doe,@roots'; + + // anonymous user + $this->assertEquals(auth_ismanager('jill', null,true), false); + + // admin user + $this->assertEquals(auth_ismanager('john', null,true), true); + $this->assertEquals(auth_ismanager('Doe', null,true), false); + + // admin groups + $this->assertEquals(auth_ismanager('jill', array('admin'),true), true); + $this->assertEquals(auth_ismanager('jill', array('roots'),true), true); + $this->assertEquals(auth_ismanager('john', array('admin'),true), true); + $this->assertEquals(auth_ismanager('doe', array('admin'),true), true); + $this->assertEquals(auth_ismanager('Doe', array('admin'),true), true); + } + +} + +//Setup VIM: ex: et ts=4 : diff --git a/_testing/unittests/inc/auth_nameencode.test.php b/_testing/unittests/inc/auth_nameencode.test.php new file mode 100644 index 000000000..12a333f66 --- /dev/null +++ b/_testing/unittests/inc/auth_nameencode.test.php @@ -0,0 +1,50 @@ +<?php + +require_once DOKU_INC.'inc/init.php'; +require_once DOKU_INC.'inc/auth.php'; + +class auth_nameencode_test extends PHPUnit_Framework_TestCase { + + function teardown() { + global $cache_authname; + $cache_authname = array(); + } + + function test_simple(){ + $in = 'hey$you'; + $out = 'hey%24you'; + $this->assertEquals(auth_nameencode($in),$out); + } + + function test_quote(){ + $in = 'hey"you'; + $out = 'hey%22you'; + $this->assertEquals(auth_nameencode($in),$out); + } + + function test_complex(){ + $in = 'hey $ you !$%! foo '; + $out = 'hey%20%24%20you%20%21%24%25%21%20foo%20'; + $this->assertEquals(auth_nameencode($in),$out); + } + + function test_complexutf8(){ + $in = 'häü $ yü !$%! foo '; + $out = 'häü%20%24%20yü%20%21%24%25%21%20foo%20'; + $this->assertEquals(auth_nameencode($in),$out); + } + + function test_groupskipon(){ + $in = '@hey$you'; + $out = '@hey%24you'; + $this->assertEquals(auth_nameencode($in,true),$out); + } + + function test_groupskipoff(){ + $in = '@hey$you'; + $out = '%40hey%24you'; + $this->assertEquals(auth_nameencode($in),$out); + } +} + +//Setup VIM: ex: et ts=4 : diff --git a/_testing/unittests/inc/auth_password.test.php b/_testing/unittests/inc/auth_password.test.php new file mode 100644 index 000000000..4c922d0e3 --- /dev/null +++ b/_testing/unittests/inc/auth_password.test.php @@ -0,0 +1,70 @@ +<?php + +require_once DOKU_INC.'inc/init.php'; +require_once DOKU_INC.'inc/auth.php'; + +class auth_password_test extends PHPUnit_Framework_TestCase { + + // hashes for the password foo$method, using abcdefgh as salt + var $passes = array( + 'smd5' => '$1$abcdefgh$SYbjm2AEvSoHG7Xapi8so.', + 'apr1' => '$apr1$abcdefgh$C/GzYTF4kOVByYLEoD5X4.', + 'md5' => '8fa22d62408e5351553acdd91c6b7003', + 'sha1' => 'b456d3b0efd105d613744ffd549514ecafcfc7e1', + 'ssha' => '{SSHA}QMHG+uC7bHNYKkmoLbNsNI38/dJhYmNk', + 'lsmd5' => '{SMD5}HGbkPrkWgy9KgcRGWlrsUWFiY2RlZmdo', + 'crypt' => 'ablvoGr1hvZ5k', + 'mysql' => '4a1fa3780bd6fd55', + 'my411' => '*e5929347e25f82e19e4ebe92f1dc6b6e7c2dbd29', + 'kmd5' => 'a579299436d7969791189acadd86fcb716', + 'pmd5' => '$P$abcdefgh1RC6Fd32heUzl7EYCG9uGw.', + 'hmd5' => '$H$abcdefgh1ZbJodHxmeXVAhEzTG7IAp.', + 'djangomd5' => 'md5$abcde$d0fdddeda8cd92725d2b54148ac09158', + 'djangosha1' => 'sha1$abcde$c8e65a7f0acc9158843048a53dcc5a6bc4d17678', + ); + + + function test_cryptPassword(){ + foreach($this->passes as $method => $hash){ + $info = "testing method $method"; + $this->assertEquals(auth_cryptPassword('foo'.$method, $method,'abcdefgh12345678912345678912345678'), + $hash, $info); + } + } + + function test_verifyPassword(){ + foreach($this->passes as $method => $hash){ + $info = "testing method $method"; + $this->assertTrue(auth_verifyPassword('foo'.$method, $hash), $info); + } + } + + function test_verifySelf(){ + foreach($this->passes as $method => $hash){ + $info = "testing method $method"; + $hash = auth_cryptPassword('foo'.$method,$method); + $this->assertTrue(auth_verifyPassword('foo'.$method, $hash), $info); + } + } + + function test_bcrypt_self(){ + $hash = auth_cryptPassword('foobcrypt','bcrypt'); + $this->assertTrue(auth_verifyPassword('foobcrypt',$hash)); + } + + function test_verifyPassword_fixedbcrypt(){ + $this->assertTrue(auth_verifyPassword('foobcrypt','$2a$12$uTWercxbq4sjp2xAzv3we.ZOxk51m5V/Bv5bp2H27oVFJl5neFQoC')); + } + + function test_verifyPassword_nohash(){ + $this->assertTrue(auth_verifyPassword('foo','$1$$n1rTiFE0nRifwV/43bVon/')); + } + + function test_verifyPassword_fixedpmd5(){ + $this->assertTrue(auth_verifyPassword('test12345','$P$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); + $this->assertTrue(auth_verifyPassword('test12345','$H$9IQRaTwmfeRo7ud9Fh4E2PdI0S3r.L0')); + } + +} + +//Setup VIM: ex: et ts=4 : |