From cf14306c2b3f82a81f8d56669a71633b4d4b5fce Mon Sep 17 00:00:00 2001
From: marvin-borner@live.com
Date: Mon, 16 Apr 2018 21:09:05 +0200
Subject: Main merge to user management system - files are now at /main/public/

---
 .../sprinkles/account/tests/Unit/FactoriesTest.php | 30 +++++++++
 .../sprinkles/account/tests/Unit/HasherTest.php    | 71 ++++++++++++++++++++++
 2 files changed, 101 insertions(+)
 create mode 100755 main/app/sprinkles/account/tests/Unit/FactoriesTest.php
 create mode 100755 main/app/sprinkles/account/tests/Unit/HasherTest.php

(limited to 'main/app/sprinkles/account/tests/Unit')

diff --git a/main/app/sprinkles/account/tests/Unit/FactoriesTest.php b/main/app/sprinkles/account/tests/Unit/FactoriesTest.php
new file mode 100755
index 0000000..ee2bf23
--- /dev/null
+++ b/main/app/sprinkles/account/tests/Unit/FactoriesTest.php
@@ -0,0 +1,30 @@
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link      https://github.com/userfrosting/UserFrosting
+ * @license   https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+namespace UserFrosting\Tests\Unit;
+
+use UserFrosting\Tests\TestCase;
+use UserFrosting\Tests\DatabaseTransactions;
+
+/**
+ * FactoriesTest class.
+ * Tests the factories defined in this sprinkle are working
+ *
+ * @extends TestCase
+ */
+class FactoriesTest extends TestCase
+{
+    use DatabaseTransactions;
+
+    function testUserFactory()
+    {
+        $fm = $this->ci->factory;
+
+        $user = $fm->create('UserFrosting\Sprinkle\Account\Database\Models\User');
+        $this->assertInstanceOf('UserFrosting\Sprinkle\Account\Database\Models\User', $user);
+    }
+}
diff --git a/main/app/sprinkles/account/tests/Unit/HasherTest.php b/main/app/sprinkles/account/tests/Unit/HasherTest.php
new file mode 100755
index 0000000..711e3cb
--- /dev/null
+++ b/main/app/sprinkles/account/tests/Unit/HasherTest.php
@@ -0,0 +1,71 @@
+<?php
+/**
+ * UserFrosting (http://www.userfrosting.com)
+ *
+ * @link      https://github.com/userfrosting/UserFrosting
+ * @license   https://github.com/userfrosting/UserFrosting/blob/master/licenses/UserFrosting.md (MIT License)
+ */
+namespace UserFrosting\Tests\Unit;
+
+use UserFrosting\Sprinkle\Account\Authenticate\Hasher;
+use UserFrosting\Tests\TestCase;
+
+/**
+ * Tests the password Hasher class.
+ *
+ * @extends TestCase
+ */
+class HasherTest extends TestCase
+{
+    protected $plainText = 'hodleth';
+
+    /**
+     * @var string Legacy hash from UserCake (sha1)
+     */
+    protected $userCakeHash = '87e995bde9ebdc73fc58cc75a9fadc4ae630d8207650fbe94e148ccc8058d5de5';
+
+    /**
+     * @var string Legacy hash from UF 0.1.x
+     */
+    protected $legacyHash = '$2y$12$rsXGznS5Ky23lX9iNzApAuDccKRhQFkiy5QfKWp0ACyDWBPOylPB.rsXGznS5Ky23lX9iNzApA9';
+
+    /**
+     * @var string Modern hash that uses password_hash()
+     */
+    protected $modernHash = '$2y$10$ucxLwloFso6wJoct1baBQefdrttws/taEYvavi6qoPsw/vd1u4Mha';
+
+    public function testGetHashType()
+    {
+        $hasher = new Hasher;
+
+        $type = $hasher->getHashType($this->modernHash);
+
+        $this->assertEquals('modern', $type);
+
+        $type = $hasher->getHashType($this->legacyHash);
+
+        $this->assertEquals('legacy', $type);
+
+        $type = $hasher->getHashType($this->userCakeHash);
+
+        $this->assertEquals('sha1', $type);
+    }
+
+    public function testVerify()
+    {
+        $hasher = new Hasher;
+
+        $this->assertTrue($hasher->verify($this->plainText, $this->modernHash));
+        $this->assertTrue($hasher->verify($this->plainText, $this->legacyHash));
+        $this->assertTrue($hasher->verify($this->plainText, $this->userCakeHash));
+    }
+
+    public function testVerifyReject()
+    {
+        $hasher = new Hasher;
+
+        $this->assertFalse($hasher->verify('selleth', $this->modernHash));
+        $this->assertFalse($hasher->verify('selleth', $this->legacyHash));
+        $this->assertFalse($hasher->verify('selleth', $this->userCakeHash));
+    }
+}
-- 
cgit v1.2.3