-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from OrifInformatique:update_azure_login
Update azure login
- Loading branch information
Showing
5 changed files
with
169 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace User\Controllers; | ||
|
||
use CodeIgniter\Test\DatabaseTestTrait; | ||
use CodeIgniter\Test\FeatureTestTrait; | ||
use CodeIgniter\Test\CIUnitTestCase; | ||
|
||
use User\Models\User_model; | ||
|
||
class AuthHttpTest extends CIUnitTestCase | ||
{ | ||
use DatabaseTestTrait; | ||
use FeatureTestTrait; | ||
|
||
protected $migrate = true; | ||
protected $migrateOnce = false; | ||
protected $refresh = true; | ||
protected $namespace = null; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
} | ||
|
||
protected function tearDown(): void | ||
{ | ||
parent::tearDown(); | ||
} | ||
|
||
private function test_azure_login_begin(): void | ||
{ | ||
$url = substr(url_to('Auth::azure_login_begin'), strlen(base_url())); | ||
$result = $this->call('get', $url); | ||
$redirectUrl = $result->getRedirectUrl(); | ||
$html = file_get_contents($redirectUrl, false); | ||
dd($html); | ||
} | ||
|
||
public function test_azure_mail_with_correct_code_new_user(): void | ||
{ | ||
$firstName = 'Firstname'; | ||
$lastName = 'Lastname'; | ||
$userName = "$firstName.$lastName"; | ||
$_POST['user_verification_code'] = 'correct'; | ||
$_SESSION['verification_code'] = 'correct'; | ||
$_SESSION['verification_attempts'] = 3; | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$_SESSION['new_user'] = true; | ||
$_SESSION['azure_mail'] = "$userName@azurefake.fake"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$_SESSION['timer_end'] = time() + 300; | ||
$url = substr(url_to('verify_verification_code'), strlen(site_url())); | ||
$result = $this->withSession()->call('get', $url); | ||
$userModel = model(User_model::class); | ||
$name = $userModel->select('username')->where('username=', $userName) | ||
->findAll()[0]['username']; | ||
$this->assertEquals($userName, $name); | ||
} | ||
|
||
public function test_azure_mail_existed_user_variable_created(): void | ||
{ | ||
$userId = 2; | ||
$noAzureMail = '[email protected]'; | ||
$userModel = model(User_model::class); | ||
$userModel->update($userId, ['email' => $noAzureMail]); | ||
|
||
$_SESSION['after_login_redirect'] = base_url(); | ||
$_POST['user_email'] = $noAzureMail; | ||
|
||
$azureMail = '[email protected]'; | ||
$_SESSION['azure_mail'] = $azureMail; | ||
|
||
$url = substr(url_to('handle_mail_form'), strlen(site_url())); | ||
$result = $this->withSession()->post($url); | ||
|
||
$result->assertSee(lang('user_lang.user_validation_code')); | ||
} | ||
|
||
public function test_azure_mail_with_correct_code_existing_user(): void | ||
{ | ||
$userId = 2; | ||
$noAzureMail = '[email protected]'; | ||
$userModel = model(User_model::class); | ||
$userModel->update($userId, ['email' => $noAzureMail]); | ||
|
||
$_POST['user_verification_code'] = 'correct'; | ||
$_SESSION['verification_code'] = 'correct'; | ||
$_SESSION['verification_attempts'] = 3; | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$_SESSION['new_user'] = false; | ||
$_SESSION['form_email'] = $noAzureMail; | ||
$_SESSION['timer_end'] = time() + 300; | ||
$azureMail = '[email protected]'; | ||
$_SESSION['azure_mail'] = $azureMail; | ||
|
||
$url = substr(url_to('verify_verification_code'), strlen(site_url())); | ||
$result = $this->withSession()->call('get', $url); | ||
|
||
$azureMailInDb = $userModel->select('azure_mail') | ||
->find($userId)['azure_mail']; | ||
$this->assertEquals($azureMail, $azureMailInDb); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -608,9 +608,13 @@ public function test_azure_mail_without_code(): void | |
{ | ||
$_POST['user_verification_code'] = null; | ||
$_SESSION['verification_code'] = null; | ||
$form_email = '[email protected]'; | ||
$result = $this->controller(Auth::class) | ||
->execute('generate_send_verification_code', $form_email); | ||
$_SESSION['verification_attempts'] = 3; | ||
$_SESSION['timer_end'] = time() + 300; | ||
$_SESSION['new_user'] = true; | ||
$_SESSION['azure_mail'] = "[email protected]"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$result = $this->controller(Auth::class)->execute('verify_verification_code'); | ||
$result->assertSee(lang('user_lang.user_validation_code')); | ||
} | ||
|
||
|
@@ -624,11 +628,13 @@ public function test_azure_mail_with_fake_code(): void | |
{ | ||
$_POST['user_verification_code'] = 'fake1'; | ||
$_SESSION['verification_code'] = 'fake2'; | ||
$_SESSION['verification_attempts'] = 3; // 3 attempts left | ||
$_SESSION['timer_end'] = time() + 300; // force timer_end to be greater than time() | ||
$form_email = '[email protected]'; | ||
$result = $this->controller(Auth::class) | ||
->execute('verify_verification_code', $form_email); | ||
$_SESSION['verification_attempts'] = 3; | ||
$_SESSION['timer_end'] = time() + 300; | ||
$_SESSION['new_user'] = true; | ||
$_SESSION['azure_mail'] = "[email protected]"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$result = $this->controller(Auth::class)->execute('verify_verification_code'); | ||
$result->assertSee(lang('user_lang.msg_err_validation_code')); | ||
} | ||
|
||
|
@@ -637,11 +643,12 @@ public function test_azure_mail_with_fake_code_all_attemps_done(): void | |
$_POST['user_verification_code'] = 'fake1'; | ||
$_SESSION['verification_code'] = 'fake2'; | ||
$_SESSION['verification_attempts'] = 1; | ||
$_SESSION['timer_end'] = time() - 300; // force timer_end to be expired | ||
$_SESSION['timer_end'] = time() + 300; | ||
$_SESSION['new_user'] = true; | ||
$_SESSION['azure_mail'] = "[email protected]"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$form_email = '[email protected]'; | ||
$result = $this->controller(Auth::class) | ||
->execute('verify_verification_code', $form_email); | ||
$result = $this->controller(Auth::class)->execute('verify_verification_code'); | ||
$this->assert_redirect($result); | ||
} | ||
|
||
|
@@ -711,15 +718,24 @@ public function test_azure_mail_with_correct_code_existing_user(): void | |
$_SESSION['timer_end'] = time() + 300; // force timer_end to be greater than time() | ||
$_SESSION['after_login_redirect'] = base_url(); | ||
$_SESSION['new_user'] = false; | ||
$_SESSION['azure_mail'] = "[email protected]"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$_SESSION['azure_mail'] = "[email protected]"; | ||
$_SESSION['form_email'] = "[email protected]"; | ||
$redirect_url = $_SESSION['after_login_redirect']; | ||
|
||
$result = $this->controller(Auth::class) | ||
->execute('verify_verification_code'); | ||
|
||
/* Check that user's azure_mail has been updated in the DB */ | ||
$azureMailInDb = $userModel->select('azure_mail') | ||
->find($userId)['azure_mail']; | ||
$this->assertEquals($_SESSION['azure_mail'], $azureMailInDb); | ||
|
||
/* Check that the user is logged in */ | ||
$result->assertSessionHas('logged_in', true); | ||
|
||
/* Check if user has been redirected correctly */ | ||
$result->assertRedirect(); | ||
$result->assertRedirectTo($redirect_url); | ||
} | ||
|
||
/** | ||
|