From f2f3a897a5ba2d1c8fa7382f05616d819d30d434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Sun, 10 Jun 2018 21:30:01 +0200 Subject: [PATCH] Unit tests for Crypto package --- lib/Crypto/AbstractCrypt.php | 2 +- lib/Crypto/CryptArgon2.php | 6 +++ lib/Crypto/Joomla.php | 9 ++--- lib/Crypto/SSHA.php | 2 +- tests/Crypto/CleartextTest.php | 51 ++++++++++++++++++++++++ tests/Crypto/CourierMD5RawTest.php | 55 ++++++++++++++++++++++++++ tests/Crypto/CourierMD5Test.php | 55 ++++++++++++++++++++++++++ tests/Crypto/CourierSHA1Test.php | 55 ++++++++++++++++++++++++++ tests/Crypto/CourierSHA256Test.php | 56 +++++++++++++++++++++++++++ tests/Crypto/CryptArgon2Test.php | 56 +++++++++++++++++++++++++++ tests/Crypto/CryptBlowfishTest.php | 56 +++++++++++++++++++++++++++ tests/Crypto/CryptExtendedDESTest.php | 53 +++++++++++++++++++++++++ tests/Crypto/CryptMD5Test.php | 55 ++++++++++++++++++++++++++ tests/Crypto/CryptSHA256Test.php | 56 +++++++++++++++++++++++++++ tests/Crypto/CryptSHA512Test.php | 56 +++++++++++++++++++++++++++ tests/Crypto/CryptStandardDESTest.php | 53 +++++++++++++++++++++++++ tests/Crypto/CryptTest.php | 56 +++++++++++++++++++++++++++ tests/Crypto/JoomlaTest.php | 56 +++++++++++++++++++++++++++ tests/Crypto/MD5Test.php | 55 ++++++++++++++++++++++++++ tests/Crypto/SHA1Test.php | 55 ++++++++++++++++++++++++++ tests/Crypto/SSHA256Test.php | 56 +++++++++++++++++++++++++++ tests/Crypto/SSHA512Test.php | 56 +++++++++++++++++++++++++++ 22 files changed, 1003 insertions(+), 7 deletions(-) create mode 100644 tests/Crypto/CleartextTest.php create mode 100644 tests/Crypto/CourierMD5RawTest.php create mode 100644 tests/Crypto/CourierMD5Test.php create mode 100644 tests/Crypto/CourierSHA1Test.php create mode 100644 tests/Crypto/CourierSHA256Test.php create mode 100644 tests/Crypto/CryptArgon2Test.php create mode 100644 tests/Crypto/CryptBlowfishTest.php create mode 100644 tests/Crypto/CryptExtendedDESTest.php create mode 100644 tests/Crypto/CryptMD5Test.php create mode 100644 tests/Crypto/CryptSHA256Test.php create mode 100644 tests/Crypto/CryptSHA512Test.php create mode 100644 tests/Crypto/CryptStandardDESTest.php create mode 100644 tests/Crypto/CryptTest.php create mode 100644 tests/Crypto/JoomlaTest.php create mode 100644 tests/Crypto/MD5Test.php create mode 100644 tests/Crypto/SHA1Test.php create mode 100644 tests/Crypto/SSHA256Test.php create mode 100644 tests/Crypto/SSHA512Test.php diff --git a/lib/Crypto/AbstractCrypt.php b/lib/Crypto/AbstractCrypt.php index 9d053ec..c13e1b5 100644 --- a/lib/Crypto/AbstractCrypt.php +++ b/lib/Crypto/AbstractCrypt.php @@ -48,7 +48,7 @@ abstract class AbstractCrypt extends AbstractAlgorithm */ public function getPasswordHash($password) { - return crypt($password, self::getSalt()); + return crypt($password, $this->getSalt()); } /** diff --git a/lib/Crypto/CryptArgon2.php b/lib/Crypto/CryptArgon2.php index 736b68d..a8c2d3e 100644 --- a/lib/Crypto/CryptArgon2.php +++ b/lib/Crypto/CryptArgon2.php @@ -59,6 +59,12 @@ class CryptArgon2 extends AbstractAlgorithm $timeCost = PASSWORD_ARGON2_DEFAULT_TIME_COST, $threads = PASSWORD_ARGON2_DEFAULT_THREADS ) { + if (version_compare(PHP_VERSION, "7.2.0") === -1) { + throw new \RuntimeException( + "PASSWORD_ARGON2I requires PHP 7.2.0 or above." + ); + } + parent::__construct($localization); $this->memoryCost = $memoryCost; $this->timeCost = $timeCost; diff --git a/lib/Crypto/Joomla.php b/lib/Crypto/Joomla.php index abc9a72..e5dd2ca 100644 --- a/lib/Crypto/Joomla.php +++ b/lib/Crypto/Joomla.php @@ -45,12 +45,11 @@ class Joomla extends AbstractAlgorithm */ public function getPasswordHash($password) { - return md5( - $password . ":" . Utils::randomString( - 32, - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" - ) + $salt = Utils::randomString( + 32, "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" ); + + return md5($password . $salt) . ":" . $salt; } /** diff --git a/lib/Crypto/SSHA.php b/lib/Crypto/SSHA.php index cfe7119..8e3642e 100644 --- a/lib/Crypto/SSHA.php +++ b/lib/Crypto/SSHA.php @@ -48,7 +48,7 @@ abstract class SSHA extends AbstractAlgorithm $saltedPassword = base64_decode( preg_replace("/" . $this->getPrefix() . "/i", "", $dbHash) ); - $salt = substr($saltedPassword, -(strlen($saltedPassword) - 32)); + $salt = substr($saltedPassword, -32); $hash = self::ssha($password, $salt); return hash_equals($dbHash, $hash); diff --git a/tests/Crypto/CleartextTest.php b/tests/Crypto/CleartextTest.php new file mode 100644 index 0000000..d4eaaef --- /dev/null +++ b/tests/Crypto/CleartextTest.php @@ -0,0 +1,51 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\Cleartext; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class Cleartext. + * + * @author Marcin Łojewski + */ +class CleartextTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue($this->crypto->checkPassword("password", "password")); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new Cleartext($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CourierMD5RawTest.php b/tests/Crypto/CourierMD5RawTest.php new file mode 100644 index 0000000..fe30008 --- /dev/null +++ b/tests/Crypto/CourierMD5RawTest.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CourierMD5Raw; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CourierMD5Raw. + * + * @author Marcin Łojewski + */ +class CourierMD5RawTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "{MD5RAW}5f4dcc3b5aa765d61d8327deb882cf99" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CourierMD5Raw($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CourierMD5Test.php b/tests/Crypto/CourierMD5Test.php new file mode 100644 index 0000000..0d1e82d --- /dev/null +++ b/tests/Crypto/CourierMD5Test.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CourierMD5; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CourierMD5. + * + * @author Marcin Łojewski + */ +class CourierMD5Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "{MD5}X03MO1qnZdYdgyfeuILPmQ==" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CourierMD5($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CourierSHA1Test.php b/tests/Crypto/CourierSHA1Test.php new file mode 100644 index 0000000..0621655 --- /dev/null +++ b/tests/Crypto/CourierSHA1Test.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CourierSHA1; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CourierSHA1. + * + * @author Marcin Łojewski + */ +class CourierSHA1Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CourierSHA1($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CourierSHA256Test.php b/tests/Crypto/CourierSHA256Test.php new file mode 100644 index 0000000..ee86310 --- /dev/null +++ b/tests/Crypto/CourierSHA256Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CourierSHA256; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CourierSHA256. + * + * @author Marcin Łojewski + */ +class CourierSHA256Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "{SHA256}XohImNooBHFR0OVvjcYpJ3NgPQ1qq73WKhHvch0VQtg=" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CourierSHA256($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptArgon2Test.php b/tests/Crypto/CryptArgon2Test.php new file mode 100644 index 0000000..7a44ddd --- /dev/null +++ b/tests/Crypto/CryptArgon2Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptArgon2; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptArgon2. + * + * @author Marcin Łojewski + */ +class CryptArgon2Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "\$argon2i\$v=19\$m=1024,t=2,p=2\$NnpSNlRNLlZobnJHUDh0Sw\$oW5E1cfdPzLWfkTvQFUyzTR00R0aLwEdYwldcqW6Pmo" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptArgon2($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptBlowfishTest.php b/tests/Crypto/CryptBlowfishTest.php new file mode 100644 index 0000000..ea4dc0c --- /dev/null +++ b/tests/Crypto/CryptBlowfishTest.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptBlowfish; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptBlowfish. + * + * @author Marcin Łojewski + */ +class CryptBlowfishTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "$2y$10$5rsN1fmoSkaRy9bqhozAXOr0mn0QiVIfd2L04Bbk1Go9MjdvotwBq" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptBlowfish($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptExtendedDESTest.php b/tests/Crypto/CryptExtendedDESTest.php new file mode 100644 index 0000000..31ca7c1 --- /dev/null +++ b/tests/Crypto/CryptExtendedDESTest.php @@ -0,0 +1,53 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptExtendedDES; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptExtendedDES. + * + * @author Marcin Łojewski + */ +class CryptExtendedDESTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword("password", "..UZoIyj/Hy/c") + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptExtendedDES($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptMD5Test.php b/tests/Crypto/CryptMD5Test.php new file mode 100644 index 0000000..0a6f405 --- /dev/null +++ b/tests/Crypto/CryptMD5Test.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptMD5; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptMD5. + * + * @author Marcin Łojewski + */ +class CryptMD5Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "$1\$RzaFbNcU\$u9adfTY/Q6za6nu0Ogrl1/" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptMD5($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptSHA256Test.php b/tests/Crypto/CryptSHA256Test.php new file mode 100644 index 0000000..020bb61 --- /dev/null +++ b/tests/Crypto/CryptSHA256Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptSHA256; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptSHA256. + * + * @author Marcin Łojewski + */ +class CryptSHA256Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "$5\$rounds=5000\$VIYD0iHkg7uY9SRc\$v2XLS/9dvfFN84mzGvW9wxnVt9Xd/urXaaTkpW8EwD1" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptSHA256($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptSHA512Test.php b/tests/Crypto/CryptSHA512Test.php new file mode 100644 index 0000000..7667d1f --- /dev/null +++ b/tests/Crypto/CryptSHA512Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptSHA512; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptSHA512. + * + * @author Marcin Łojewski + */ +class CryptSHA512Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "$6\$rounds=5000\$yH.Q0OL4qbCOUJ3q\$Xry5EVFva3wKnfo8/ktrugmBd8tcl34NK6rXInv1HhmdSUNLEm0La9JnA57rqwQ.9/Bz513MD4tvmmISLUIHs/" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptSHA512($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptStandardDESTest.php b/tests/Crypto/CryptStandardDESTest.php new file mode 100644 index 0000000..ca8712b --- /dev/null +++ b/tests/Crypto/CryptStandardDESTest.php @@ -0,0 +1,53 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\CryptStandardDES; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class CryptStandardDES. + * + * @author Marcin Łojewski + */ +class CryptStandardDESTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword("password", "yTBnb7ab/N072") + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new CryptStandardDES($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/CryptTest.php b/tests/Crypto/CryptTest.php new file mode 100644 index 0000000..f556289 --- /dev/null +++ b/tests/Crypto/CryptTest.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\Crypt; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class Crypt. + * + * @author Marcin Łojewski + */ +class CryptTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "$2y$10$5rsN1fmoSkaRy9bqhozAXOr0mn0QiVIfd2L04Bbk1Go9MjdvotwBq" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new Crypt($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/JoomlaTest.php b/tests/Crypto/JoomlaTest.php new file mode 100644 index 0000000..feaa96e --- /dev/null +++ b/tests/Crypto/JoomlaTest.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCA\UserSQL\Crypto\Joomla; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class Joomla. + * + * @author Marcin Łojewski + */ +class JoomlaTest extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "14d21b49b0f13e2acba962b6b0039edd:haJK0yTvBXTNMh76xwEw5RYEVpJsN8us" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new Joomla($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/MD5Test.php b/tests/Crypto/MD5Test.php new file mode 100644 index 0000000..d8f2950 --- /dev/null +++ b/tests/Crypto/MD5Test.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\MD5; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class MD5. + * + * @author Marcin Łojewski + */ +class MD5Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "5f4dcc3b5aa765d61d8327deb882cf99" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new MD5($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/SHA1Test.php b/tests/Crypto/SHA1Test.php new file mode 100644 index 0000000..2ed51ab --- /dev/null +++ b/tests/Crypto/SHA1Test.php @@ -0,0 +1,55 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\SHA1; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class SHA1. + * + * @author Marcin Łojewski + */ +class SHA1Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", "5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new SHA1($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/SSHA256Test.php b/tests/Crypto/SSHA256Test.php new file mode 100644 index 0000000..f26b0e7 --- /dev/null +++ b/tests/Crypto/SSHA256Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\SSHA256; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class SSHA256. + * + * @author Marcin Łojewski + */ +class SSHA256Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "{SSHA256}+WxTB3JxprNteeovsuSYtgI+UkVPA9lfwGoYkz3Ff7hjd1FSdmlTMkNsSExyR21KM3NvNTZ5V0p4WXJMUjFzUg==" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new SSHA256($this->createMock(IL10N::class)); + } +} diff --git a/tests/Crypto/SSHA512Test.php b/tests/Crypto/SSHA512Test.php new file mode 100644 index 0000000..10cfbd7 --- /dev/null +++ b/tests/Crypto/SSHA512Test.php @@ -0,0 +1,56 @@ + + * @author Marcin Łojewski + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace Tests\UserSQL\Crypto; + +use OCA\UserSQL\Crypto\SSHA512; +use OCA\UserSQL\Crypto\IPasswordAlgorithm; +use OCP\IL10N; +use Test\TestCase; + +/** + * Unit tests for class SSHA512. + * + * @author Marcin Łojewski + */ +class SSHA512Test extends TestCase +{ + /** + * @var IPasswordAlgorithm + */ + private $crypto; + + public function testCheckPassword() + { + $this->assertTrue( + $this->crypto->checkPassword( + "password", + "{SSHA512}It+v1kAEUBbhMJYJ2swAtz+RLE6ispv/FB6G/ALhK/YWwEmrloY+0jzrWIfmu+rWUXp8u0Tg4jLXypC5oXAW00IyYnRVdEZJbE9wak96bkNRVWFCYmlJNWxrdTA0QmhL" + ) + ); + } + + protected function setUp() + { + parent::setUp(); + $this->crypto = new SSHA512($this->createMock(IL10N::class)); + } +}