summaryrefslogtreecommitdiffstats
path: root/tests/lib/SimpleSAML/Utils
diff options
context:
space:
mode:
authorJaime Perez Crespo <jaime.perez@uninett.no>2015-06-14 16:22:04 +0200
committerJaime Perez Crespo <jaime.perez@uninett.no>2015-06-14 16:22:04 +0200
commitaec9571dc85c861ac0b6e081782aae30f9b6d2c1 (patch)
treeb187919430520dea7973500854935385349bc508 /tests/lib/SimpleSAML/Utils
parent4b6ea53fe41f80ecbcd1d2f505bb00d463ad45a9 (diff)
downloadsimplesamlphp-aec9571dc85c861ac0b6e081782aae30f9b6d2c1.zip
simplesamlphp-aec9571dc85c861ac0b6e081782aae30f9b6d2c1.tar.gz
simplesamlphp-aec9571dc85c861ac0b6e081782aae30f9b6d2c1.tar.bz2
Add some tests for SimpleSAML\Utils\Crypto.
Diffstat (limited to 'tests/lib/SimpleSAML/Utils')
-rw-r--r--tests/lib/SimpleSAML/Utils/CryptoTest.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/lib/SimpleSAML/Utils/CryptoTest.php b/tests/lib/SimpleSAML/Utils/CryptoTest.php
new file mode 100644
index 0000000..3b0ad14
--- /dev/null
+++ b/tests/lib/SimpleSAML/Utils/CryptoTest.php
@@ -0,0 +1,48 @@
+<?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() {
+ SimpleSAML\Utils\Crypto::aesDecrypt(array());
+ }
+
+
+ /**
+ * Test that aesDecrypt() works properly, being able to decrypt some previously known (and correct)
+ * ciphertext.
+ */
+ public function testAesDecrypt() {
+ $c = SimpleSAML_Configuration::loadFromArray(array(
+ 'secretsalt' => 'SUPER_SECRET_SALT',
+ ));
+
+ $plaintext = 'SUPER_SECRET_TEXT';
+ $ciphertext = 'GA5lvW9TbAErqGvHFfZMUkdIg6zCJYmjFSGERAhByYNcMts70N4fWLjUm7/aVygPm55GbGhEG2himXJUHR1Ibg==';
+ $this->assertEquals($plaintext, SimpleSAML\Utils\Crypto::aesDecrypt(base64_decode($ciphertext)));
+ }
+
+
+ /**
+ * Test that aesEncrypt() produces ciphertexts that aesDecrypt() can decrypt.
+ */
+ public function testAesEncrypt() {
+ $c = SimpleSAML_Configuration::loadFromArray(array(
+ 'secretsalt' => 'SUPER_SECRET_SALT',
+ ));
+
+ $original_plaintext = 'SUPER_SECRET_TEXT';
+ $ciphertext = SimpleSAML\Utils\Crypto::aesEncrypt($original_plaintext);
+ $decrypted_plaintext = SimpleSAML\Utils\Crypto::aesDecrypt($ciphertext);
+ $this->assertEquals($original_plaintext, $decrypted_plaintext);
+ }
+}