summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Utils
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/SimpleSAML/Utils')
-rw-r--r--tests/lib/SimpleSAML/Utils/ConfigTest.php2
-rw-r--r--tests/lib/SimpleSAML/Utils/CryptoTest.php78
2 files changed, 79 insertions, 1 deletions
diff --git a/tests/lib/SimpleSAML/Utils/ConfigTest.php b/tests/lib/SimpleSAML/Utils/ConfigTest.php
index 556e5d0..2fdc080 100644
--- a/tests/lib/SimpleSAML/Utils/ConfigTest.php
+++ b/tests/lib/SimpleSAML/Utils/ConfigTest.php
@@ -44,6 +44,6 @@ class Utils_ConfigTest extends PHPUnit_Framework_TestCase
'Given: "' . $invalidDir . '"'
);
- $configDir = \SimpleSAML\Utils\Config::getConfigDir();
+ \SimpleSAML\Utils\Config::getConfigDir();
}
}
diff --git a/tests/lib/SimpleSAML/Utils/CryptoTest.php b/tests/lib/SimpleSAML/Utils/CryptoTest.php
new file mode 100644
index 0000000..e2f0312
--- /dev/null
+++ b/tests/lib/SimpleSAML/Utils/CryptoTest.php
@@ -0,0 +1,78 @@
+<?php
+
+
+/**
+ * Tests for SimpleSAML\Utils\Crypto.
+ */
+class CryptoTest extends PHPUnit_Framework_TestCase
+{
+
+ /**
+ * Test invalid input provided to the aesDecrypt() method.
+ *
+ * @expectedException InvalidArgumentException
+ */
+ public function testAesDecryptBadInput()
+ {
+ $m = new ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesDecrypt');
+ $m->setAccessible(true);
+
+ $m->invokeArgs(null, array(array(), 'SECRET'));
+ }
+
+
+ /**
+ * Test invalid input provided to the aesEncrypt() method.
+ *
+ * @expectedException InvalidArgumentException
+ */
+ public function testAesEncryptBadInput()
+ {
+ $m = new ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesEncrypt');
+ $m->setAccessible(true);
+
+ $m->invokeArgs(null, array(array(), 'SECRET'));
+ }
+
+
+ /**
+ * Test that aesDecrypt() works properly, being able to decrypt some previously known (and correct)
+ * ciphertext.
+ */
+ public function testAesDecrypt()
+ {
+ if (!extension_loaded('openssl')) {
+ $this->setExpectedException('\SimpleSAML_Error_Exception');
+ }
+
+ $secret = 'SUPER_SECRET_SALT';
+ $m = new ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesDecrypt');
+ $m->setAccessible(true);
+
+ $plaintext = 'SUPER_SECRET_TEXT';
+ $ciphertext = 'NmRkODJlZGE2OTA3YTYwMm9En+KAReUk2z7Xi/b3c39kF/c1n6Vdj/zNARQt+UHU';
+ $this->assertEquals($plaintext, $m->invokeArgs(null, array(base64_decode($ciphertext), $secret)));
+ }
+
+
+ /**
+ * Test that aesEncrypt() produces ciphertexts that aesDecrypt() can decrypt.
+ */
+ public function testAesEncrypt()
+ {
+ if (!extension_loaded('openssl')) {
+ $this->setExpectedException('\SimpleSAML_Error_Exception');
+ }
+
+ $secret = 'SUPER_SECRET_SALT';
+ $e = new ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesEncrypt');
+ $d = new ReflectionMethod('\SimpleSAML\Utils\Crypto', '_aesDecrypt');
+ $e->setAccessible(true);
+ $d->setAccessible(true);
+
+ $original_plaintext = 'SUPER_SECRET_TEXT';
+ $ciphertext = $e->invokeArgs(null, array($original_plaintext, $secret));
+ $decrypted_plaintext = $d->invokeArgs(null, array($ciphertext, $secret));
+ $this->assertEquals($original_plaintext, $decrypted_plaintext);
+ }
+}