-
Notifications
You must be signed in to change notification settings - Fork 151
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
Improve login accuracy event on Laravel>5 #2642
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ead93e1
Improve login accuracy event on Laravel>5
estringana 24105b7
Test bug is working
estringana 760c048
Amend Larvel 9x and 10x
estringana 4aa7c39
Update snapshots
estringana 874f9aa
Amend tests
estringana c9d2baa
Amend tests
estringana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,3 +60,4 @@ package.json | |
packages.json | ||
package-lock.json | ||
yarn.lock | ||
cookies.txt |
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 |
---|---|---|
|
@@ -21,12 +21,36 @@ abstract class WebFrameworkTestCase extends IntegrationTestCase | |
const PORT = 9999; | ||
|
||
const ERROR_LOG_NAME = 'phpunit_error.log'; | ||
const COOKIE_JAR = 'cookies.txt'; | ||
|
||
/** | ||
* @var WebServer|null | ||
*/ | ||
private static $appServer; | ||
protected $checkWebserverErrors = true; | ||
protected $cookiesFile; | ||
protected $maintainSession = false; | ||
|
||
protected function ddSetUp() | ||
{ | ||
parent::ddSetUp(); | ||
} | ||
|
||
protected function enableSession() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This PRs introduces integration tests in which a session need to be maintained in multiple consecutive calls. That's the reason for this |
||
{ | ||
$this->maintainSession = true; | ||
$this->cookiesFile = realpath(dirname(static::getAppIndexScript())) . '/' . static::COOKIE_JAR; | ||
$f = @fopen($this->cookiesFile, "r+"); | ||
if ($f !== false) { | ||
ftruncate($f, 0); | ||
fclose($f); | ||
} | ||
} | ||
|
||
protected function disableSession() | ||
{ | ||
$this->maintainSession = false; | ||
} | ||
|
||
public static function ddSetUpBeforeClass() | ||
{ | ||
|
@@ -215,6 +239,12 @@ protected function sendRequest($method, $url, $headers = [], $body = [], $change | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $options[CURLOPT_RETURNTRANSFER]); | ||
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); | ||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $options[CURLOPT_FOLLOWLOCATION]); | ||
if ($this->maintainSession) { | ||
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookiesFile); | ||
curl_setopt ($ch, CURLOPT_COOKIEFILE, $this->cookiesFile); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | ||
curl_setopt($ch, CURLOPT_HEADER, 1); | ||
} | ||
if ($method === 'POST') { | ||
curl_setopt($ch, CURLOPT_POST, true); | ||
curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($body) ? json_encode($body) : $body); | ||
|
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
58 changes: 58 additions & 0 deletions
58
tests/Frameworks/Laravel/Version_10_x/app/Http/Controllers/LoginTestController.php
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,58 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Auth\Events\Registered; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Http\RedirectResponse; | ||
use App\Providers\RouteServiceProvider; | ||
use App\Models\User; | ||
|
||
class LoginTestController extends Controller | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function auth(Request $request) | ||
{ | ||
$credentials = [ | ||
'email' => $request->get('email'), | ||
'password' => 'password', | ||
]; | ||
|
||
if (Auth::attempt($credentials)) { | ||
return response('Login successful', 200); | ||
} | ||
|
||
return response('Invalid credentials', 403); | ||
} | ||
|
||
public function register(Request $request): RedirectResponse | ||
{ | ||
$request->validate([ | ||
'name' => ['required'], | ||
'email' => ['required'], | ||
'password' => ['required'], | ||
]); | ||
|
||
$user = User::create([ | ||
'name' => $request->name, | ||
'email' => $request->email, | ||
'password' => Hash::make($request->password), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
Auth::login($user); | ||
|
||
return redirect('/simple'); | ||
} | ||
|
||
public function behind_auth() | ||
{ | ||
return "page behind auth"; | ||
} | ||
} |
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
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
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
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
58 changes: 58 additions & 0 deletions
58
tests/Frameworks/Laravel/Version_9_x/app/Http/Controllers/LoginTestController.php
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,58 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Auth; | ||
use Illuminate\Auth\Events\Registered; | ||
use Illuminate\Support\Facades\Hash; | ||
use Illuminate\Http\RedirectResponse; | ||
use App\Providers\RouteServiceProvider; | ||
use App\Models\User; | ||
|
||
class LoginTestController extends Controller | ||
{ | ||
/** | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function auth(Request $request) | ||
{ | ||
$credentials = [ | ||
'email' => $request->get('email'), | ||
'password' => 'password', | ||
]; | ||
|
||
if (Auth::attempt($credentials)) { | ||
return response('Login successful', 200); | ||
} | ||
|
||
return response('Invalid credentials', 403); | ||
} | ||
|
||
public function register(Request $request): RedirectResponse | ||
{ | ||
$request->validate([ | ||
'name' => ['required'], | ||
'email' => ['required'], | ||
'password' => ['required'], | ||
]); | ||
|
||
$user = User::create([ | ||
'name' => $request->name, | ||
'email' => $request->email, | ||
'password' => Hash::make($request->password), | ||
]); | ||
|
||
event(new Registered($user)); | ||
|
||
Auth::login($user); | ||
|
||
return redirect('/simple'); | ||
} | ||
|
||
public function behind_auth() | ||
{ | ||
return "page behind auth"; | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the only core change. Everything else is test code to ensure the fix is working