summaryrefslogtreecommitdiffstats
path: root/tests/JWTTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/JWTTest.php')
-rw-r--r--tests/JWTTest.php31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/JWTTest.php b/tests/JWTTest.php
new file mode 100644
index 0000000..4549f1b
--- /dev/null
+++ b/tests/JWTTest.php
@@ -0,0 +1,31 @@
+<?php
+
+class JWTTests extends PHPUnit_Framework_TestCase {
+ function testEncodeDecode() {
+ $msg = JWT::encode('abc', 'my_key');
+ $this->assertEquals(JWT::decode($msg, 'my_key'), 'abc');
+ }
+
+ function testDecodeFromPython() {
+ $msg = 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.Iio6aHR0cDovL2FwcGxpY2F0aW9uL2NsaWNreT9ibGFoPTEuMjMmZi5vbz00NTYgQUMwMDAgMTIzIg.E_U8X2YpMT5K1cEiT_3-IvBYfrdIFIeVYeOqre_Z5Cg';
+ $this->assertEquals(
+ JWT::decode($msg, 'my_key'),
+ '*:http://application/clicky?blah=1.23&f.oo=456 AC000 123'
+ );
+ }
+
+ function testUrlSafeCharacters() {
+ $encoded = JWT::encode('f?', 'a');
+ $this->assertEquals('f?', JWT::decode($encoded, 'a'));
+ }
+
+ function testMalformedUtf8StringsFail() {
+ $this->setExpectedException('DomainException');
+ JWT::encode(pack('c', 128), 'a');
+ }
+
+ function testMalformedJsonThrowsException() {
+ $this->setExpectedException('DomainException');
+ JWT::jsonDecode('this is not valid JSON string');
+ }
+}