summaryrefslogtreecommitdiffstats
path: root/tests/CSRFTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/CSRFTest.php')
-rw-r--r--tests/CSRFTest.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/CSRFTest.php b/tests/CSRFTest.php
new file mode 100644
index 0000000..39fda58
--- /dev/null
+++ b/tests/CSRFTest.php
@@ -0,0 +1,36 @@
+<?php
+
+use PHPUnit\Framework\TestCase;
+
+class CSRFTest extends TestCase
+{
+ public function testGetKey()
+ {
+ $this->temp_key = CSRF::getKey();
+ $this->assertIsString($this->temp_key);
+ $this->assertEquals(32, strlen($this->temp_key));
+ }
+
+ public function testGenerate()
+ {
+ $token = CSRF::generate("some-action");
+ $this->assertIsString($token);
+ $this->assertEquals(64, strlen($token));
+
+ $this->expectException(InvalidArgumentException::class);
+ CSRF::generate();
+ CSRF::generate(12);
+ CSRF::generate(null);
+ }
+
+ public function testVerify()
+ {
+ $token = CSRF::generate("some-action");
+ $this->assertEquals(CSRF::verify($token, "some-action"), true);
+ $this->assertEquals(CSRF::verify($token, "other-action"), false);
+ $this->assertEquals(CSRF::verify("anything-else", "some-action"), false);
+ $this->assertEquals(CSRF::verify(1, "string"), false);
+ $this->assertEquals(CSRF::verify("string", 2), false);
+ $this->assertEquals(CSRF::verify(null, null), false);
+ }
+}