From c3f23f23b6547b73547602427ea4e667f44d3278 Mon Sep 17 00:00:00 2001 From: Dominique Fournier Date: Thu, 25 Apr 2019 12:42:04 +0000 Subject: [PATCH] Add CSRF and UUID tests git-svn-id: https://svn.fournier38.fr/svn/ProgSVN/trunk@5231 bf3deb0d-5f1a-0410-827f-c0cc1f45334c --- Tests/csrfTest.php | 63 ++++++++++++++++++++++++++++++++++++++++++++++ Tests/uuidTest.php | 22 ++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 Tests/csrfTest.php create mode 100644 Tests/uuidTest.php diff --git a/Tests/csrfTest.php b/Tests/csrfTest.php new file mode 100644 index 0000000..5166e07 --- /dev/null +++ b/Tests/csrfTest.php @@ -0,0 +1,63 @@ + + */ + +/** Test the csrf.php file */ +class test_csrf extends PHPUnit_Framework_TestCase +{ + public function test_csrf1 () + { + $csrf = new csrf (); + $res = $csrf->createToken (); + $this->assertSame (30, strlen ($res)); + } + + public function test_csrf2 () + { + $csrf = new csrf (); + $res = $csrf->createToken (); + $this->assertSame ( + strspn ($res, + "abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ") , strlen ($res)); + } + + public function test_csrf3 () + { + $csrf = new csrf (); + $this->setExpectedException ("Exception"); + $res = $csrf->checkToken ("NOT VALID TOKEN"); + } + + public function test_csrf4 () + { + $csrf = new csrf (); + $token = $csrf->createToken (); + $res = $csrf->checkToken ($token); + $this->assertSame (true, $res); + } + + public function test_csrf5 () + { + $csrf = new csrf (); + $token = $csrf->createToken (); + $res = $csrf->extendToken ($token); + $this->assertSame (true, $res); + } + + public function test_csrf6 () + { + $csrf = new csrf (); + $token = $csrf->createToken (); + $res = $csrf->getToken (); + $this->assertSame ($token, $res); + } + + public function test_csrf7 () + { + $csrf = new csrf (); + $res = $csrf->getToken (); + $this->assertSame (30, strlen ($res)); + } +} diff --git a/Tests/uuidTest.php b/Tests/uuidTest.php new file mode 100644 index 0000000..e661585 --- /dev/null +++ b/Tests/uuidTest.php @@ -0,0 +1,22 @@ + + */ + +/** Test the uuid.php file */ +class test_uuid extends PHPUnit_Framework_TestCase +{ + public function test_uuid1 () + { + $res = uuid::uuid4 (); + $this->assertRegExp (36, strlen ($res)); + } + + public function test_uuid2 () + { + $res = uuid::uuid4 (); + $this->assertRegExp (true, strspn ("0123456789abcdef-", $res) == + strlen ($res)); + } +}