From 7393f21d0185878e60fda908de53b167517e7d3e Mon Sep 17 00:00:00 2001 From: xisi Date: Fri, 24 Jan 2014 18:49:06 -0500 Subject: [PATCH] just pushing so I can rebase zzz --- public/index.php | 2 +- tests/config.dist.php | 10 ++++ tests/config.php | 1 - tests/phpunit.xml | 7 ++- .../unit/securityregress/SecurityRegress.php | 13 ------ .../securityregress/Security_CSRFToken.php | 46 +++++++++++++++++++ .../securityregress/Security_Sessions.php | 30 ++++++++++++ 7 files changed, 92 insertions(+), 17 deletions(-) create mode 100644 tests/config.dist.php delete mode 100644 tests/unit/securityregress/SecurityRegress.php create mode 100644 tests/unit/securityregress/Security_CSRFToken.php create mode 100644 tests/unit/securityregress/Security_Sessions.php diff --git a/public/index.php b/public/index.php index 0c1fbd09..30279049 100644 --- a/public/index.php +++ b/public/index.php @@ -118,4 +118,4 @@ if (!@$supress_master) $smarty->display($master_template, $smarty_cache_key); // Unset any temporary values here unset($_SESSION['POPUP']); -?> \ No newline at end of file +?> diff --git a/tests/config.dist.php b/tests/config.dist.php new file mode 100644 index 00000000..21da7475 --- /dev/null +++ b/tests/config.dist.php @@ -0,0 +1,10 @@ + \ No newline at end of file diff --git a/tests/config.php b/tests/config.php index a4beacb8..cbcdb1af 100644 --- a/tests/config.php +++ b/tests/config.php @@ -1,7 +1,6 @@ unit/config - - unit/securityregress/SecurityRegress.php + + unit/securityregress/Security_CSRFToken.php + + + unit/securityregress/Security_Sessions.php \ No newline at end of file diff --git a/tests/unit/securityregress/SecurityRegress.php b/tests/unit/securityregress/SecurityRegress.php deleted file mode 100644 index 6e40ce1d..00000000 --- a/tests/unit/securityregress/SecurityRegress.php +++ /dev/null @@ -1,13 +0,0 @@ - \ No newline at end of file diff --git a/tests/unit/securityregress/Security_CSRFToken.php b/tests/unit/securityregress/Security_CSRFToken.php new file mode 100644 index 00000000..beb01644 --- /dev/null +++ b/tests/unit/securityregress/Security_CSRFToken.php @@ -0,0 +1,46 @@ +getBasic($user->getCurrentIP(), 'test-token'); + $test_token = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token); + $this->assertTrue($test_token); + $this->assertAttributeEquals($csrftoken->valid, true); + } + + /** + * Tests if a CSRF token correctly fails + */ + function testCSRFToken_fail() { + global $config; + global $user; + global $csrftoken; + + // differing user + $created_token = $csrftoken->getBasic('not the same', 'test-token'); + $test_token = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token); + $this->assertFalse($test_token); + + // differing type + $created_token2 = $csrftoken->getBasic($user->getCurrentIP(), 'not the same'); + $test_token2 = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token2); + $this->assertFalse($test_token2); + + // token slightly shortened + $created_token3 = $csrftoken->getBasic($user->getCurrentIP(), 'test-token'); + $created_token3 = substr($created_token3, 0, (strlen($created_token3)-1)); + $test_token3 = $csrftoken->checkBasic($user->getCurrentIP(), 'test-token', $created_token3); + $this->assertFalse($test_token3); + } +} + +?> \ No newline at end of file diff --git a/tests/unit/securityregress/Security_Sessions.php b/tests/unit/securityregress/Security_Sessions.php new file mode 100644 index 00000000..5813f5a1 --- /dev/null +++ b/tests/unit/securityregress/Security_Sessions.php @@ -0,0 +1,30 @@ +assertNotEquals($mid, session_id()); + } + } +} + +?> \ No newline at end of file