Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: using a more precise return #1146

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/Authentication/Actions/EmailActivator.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ public function verify(IncomingRequest $request)

// No match - let them try again.
if (! $authenticator->checkAction($identity, $postedToken)) {
session()->setFlashdata('error', lang('Auth.invalidActivateToken'));

return $this->view(setting('Auth.views')['action_email_activate_show']);
return redirect()->back()->with('error', lang('Auth.invalidActivateToken'));
}

$user = $authenticator->getUser();
Expand Down
29 changes: 29 additions & 0 deletions tests/Controllers/RegisterTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.70s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccess

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.69s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.69s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.68s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccessWithNoEmailLogin

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.67s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.67s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 1 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - MySQLi - lowest

Took 0.66s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined

declare(strict_types=1);

Expand Down Expand Up @@ -53,7 +53,7 @@
Factories::injectMock('config', 'Validation', $config);
}

public function testRegisterActionSuccess(): void

Check warning on line 56 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.65s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccess

Check warning on line 56 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.53s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccess

Check warning on line 56 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.61s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccess

Check warning on line 56 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.69s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccess
{
$result = $this->withSession()->post('/register', [
'username' => 'JohnDoe',
Expand Down Expand Up @@ -91,7 +91,7 @@
$this->assertTrue($user->active);
}

public function testRegisterActionSuccessWithNoEmailLogin(): void

Check warning on line 94 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.65s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccessWithNoEmailLogin

Check warning on line 94 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.54s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccessWithNoEmailLogin

Check warning on line 94 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.60s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccessWithNoEmailLogin

Check warning on line 94 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.71s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionSuccessWithNoEmailLogin
{
/** @var Auth $config */
$config = config('Auth');
Expand Down Expand Up @@ -183,7 +183,7 @@
$this->assertCount(4, session('errors'));
}

public function testRegisterRedirectsToActionIfDefined(): void

Check warning on line 186 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.66s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined

Check warning on line 186 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.54s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined

Check warning on line 186 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.61s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined

Check warning on line 186 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.68s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterRedirectsToActionIfDefined
{
// Ensure our action is defined
$config = config('Auth');
Expand All @@ -207,7 +207,7 @@
]);
}

public function testRegisteredButNotActivatedAndLogin(): void

Check warning on line 210 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.65s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin

Check warning on line 210 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.52s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin

Check warning on line 210 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.61s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin

Check warning on line 210 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.70s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndLogin
{
// Ensure our action is defined
$config = config('Auth');
Expand All @@ -231,7 +231,7 @@
$result->assertRedirectTo('/auth/a/show');
}

public function testRegisteredButNotActivatedAndRegisterAgain(): void

Check warning on line 234 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.65s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain

Check warning on line 234 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.51s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain

Check warning on line 234 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.62s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain

Check warning on line 234 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.69s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredButNotActivatedAndRegisterAgain
{
// Ensure our action is defined
$config = config('Auth');
Expand All @@ -257,7 +257,7 @@
$result->assertRedirectTo('/auth/a/show');
}

public function testRegisteredAndSessionExpiredAndLogin(): void

Check warning on line 260 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.65s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin

Check warning on line 260 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.54s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin

Check warning on line 260 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.61s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin

Check warning on line 260 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.70s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisteredAndSessionExpiredAndLogin
{
// Ensure our action is defined
$config = config('Auth');
Expand Down Expand Up @@ -313,7 +313,7 @@
$result->assertRedirectTo(config('Auth')->registerRedirect());
}

public function testRegisterActionWithBadEmailValue(): void

Check warning on line 316 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 7.4 - Postgre

Took 0.63s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 316 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - SQLite3

Took 0.51s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 316 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.0 - MySQLi

Took 0.59s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue

Check warning on line 316 in tests/Controllers/RegisterTest.php

View workflow job for this annotation

GitHub Actions / phpunit / PHP 8.2 - MySQLi

Took 0.66s from 0.50s limit to run Tests\\Controllers\\RegisterTest::testRegisterActionWithBadEmailValue
{
$result = $this->withSession()->post('/register', [
'username' => 'JohnDoe',
Expand All @@ -331,6 +331,35 @@
);
}

public function testRegisterActionRedirectsIfTokenNotMatch(): void
{
// Ensure our action is defined
$config = config('Auth');
$config->actions['register'] = EmailActivator::class;
Factories::injectMock('config', 'Auth', $config);

// Already registered but not yet activated and logged in.
$result = $this->post('/register', [
'email' => '[email protected]',
'username' => 'foo',
'password' => 'abkdhflkjsdflkjasd;lkjf',
'password_confirm' => 'abkdhflkjsdflkjasd;lkjf',
]);

// Should have been redirected to the action's page.
$result->assertRedirectTo('/auth/a/show');

// Attempted to send an invalid token.
$result = $this->withSession()->post('/auth/a/verify', [
'token' => 'invalid-token',
]);

// Should have been redirected to the previous page.
$result->assertStatus(302);
$result->assertRedirect();
$result->assertSee(lang('Auth.invalidActivateToken'));
}

protected function setupConfig(): void
{
$config = config('Validation');
Expand Down
Loading