Browse Source

updated Tests to 100%

v3-dev
REJack 6 years ago
parent
commit
50155803ad
No known key found for this signature in database
GPG Key ID: 4A44B48700429F46
  1. 8
      app/Libraries/Aauth.php
  2. 11
      tests/Aauth/Database/LoginAttemptModelTest.php
  3. 21
      tests/Aauth/Libraries/Aauth/CallTest.php
  4. 2
      tests/Aauth/Libraries/Aauth/PermTest.php
  5. 4
      tests/Aauth/Libraries/Aauth/TOTPTest.php

8
app/Libraries/Aauth.php

@ -857,9 +857,11 @@ class Aauth
if ($userModel->transStatus() === false)
{
// @codeCoverageIgnoreStart
$userModel->transRollback();
return false;
// @codeCoverageIgnoreEnd
}
else
{
@ -1709,9 +1711,11 @@ class Aauth
if ($groupModel->transStatus() === false)
{
// @codeCoverageIgnoreStart
$groupModel->transRollback();
return false;
// @codeCoverageIgnoreEnd
}
else
{
@ -2360,9 +2364,11 @@ class Aauth
if ($permModel->transStatus() === false)
{
// @codeCoverageIgnoreStart
$permModel->transRollback();
return false;
// @codeCoverageIgnoreEnd
}
else
{
@ -2977,6 +2983,6 @@ class Aauth
}
}
trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR);
return trigger_error('Call to undefined method ' . __CLASS__ . '::' . $name . '()', E_USER_ERROR);
}
}

11
tests/Aauth/Database/LoginAttemptModelTest.php

@ -62,8 +62,10 @@ class LoginAttemptModelTest extends CIDatabaseTestCase
$config = new \Config\Aauth();
$config->loginAttemptCookie = true;
$this->model = new LoginAttemptModel($this->db, $config);
$loginAttempt = $this->model->find();
$this->assertEquals(0, $loginAttempt);
$this->assertEquals(0, $this->model->find());
$this->model->save();
$this->assertEquals(1, $this->model->find());
}
public function testSaveCookie()
@ -76,6 +78,11 @@ class LoginAttemptModelTest extends CIDatabaseTestCase
$this->assertEquals(1, $this->model->find());
$this->assertTrue($this->model->save());
$this->response = new \CodeIgniter\HTTP\Response(new App());
$this->response->setCookie('logins', 10, 4000);
$this->model = new LoginAttemptModel($this->db, $config, $this->response);
$this->assertFalse($this->model->save());
}
public function testDeleteCookie()

21
tests/Aauth/Libraries/Aauth/CallTest.php

@ -0,0 +1,21 @@
<?php namespace Tests\Aauth\Libraries\Aauth;
use App\Libraries\Aauth;
class CallTest extends \CIUnitTestCase
{
public function setUp()
{
parent::setUp();
$this->library = new Aauth();
}
//--------------------------------------------------------------------
public function testFailCall()
{
$this->expectException('ErrorException'); // Or whichever exception it is
$this->library->getNotExistingFunc();
}
}

2
tests/Aauth/Libraries/Aauth/PermTest.php

@ -517,5 +517,7 @@ class PermTest extends CIDatabaseTestCase
$groupPermsOrderBy = $this->library->listGroupPermsPaginated(2, 10, 'id DESC');
$this->assertEquals('testPerm2', $groupPermsOrderBy['perms'][0]['name']);
$this->assertEquals('testPerm1', $groupPermsOrderBy['perms'][1]['name']);
$this->assertFalse($this->library->listGroupPermsPaginated(99));
}
}

4
tests/Aauth/Libraries/Aauth/TOTPTest.php

@ -94,7 +94,6 @@ class TOTPTest extends CIDatabaseTestCase
$totp = TOTP::create('JBSWY3DPEHPK3PXP');
$totpCode = $totp->now();
usleep(1000);
$this->assertTrue($this->library->login('admin@example.com', 'password123456', null, $totpCode));
$userModel = new UserModel();
@ -110,6 +109,8 @@ class TOTPTest extends CIDatabaseTestCase
$this->library = new Aauth($config, $session);
$this->library = new Aauth($config, $session);
$totp = TOTP::create('JBSWY3DPEHPK3PXP');
$totpCode = $totp->now();
$this->assertTrue($this->library->login('admin@example.com', 'password123456', null, $totpCode));
$userModel->protect(false)->update(1, ['last_ip_address' => '99.99.99.99']);
@ -202,7 +203,6 @@ class TOTPTest extends CIDatabaseTestCase
$totp = TOTP::create('JBSWY3DPEHPK3PXP');
$totpCode = $totp->now();
usleep(1000);
$this->assertTrue($this->library->verifyUserTotpCode($totpCode));
$this->assertTrue($this->library->verifyUserTotpCode($totpCode, 1));

Loading…
Cancel
Save