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

[5.7] Do not pass the guard instance to the authentication events #25568

Merged
merged 1 commit into from
Sep 11, 2018
Merged
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
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/Events/Attempting.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Attempting
{
/**
* The authentication guard implementation.
* The authentication guard name.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
* @var string
*/
public $guard;

Expand All @@ -28,7 +28,7 @@ class Attempting
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param string $guard
* @param array $credentials
* @param bool $remember
* @return void
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/Events/Authenticated.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Authenticated
use SerializesModels;

/**
* The authentication guard implementation.
* The authentication guard name.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
* @var string
*/
public $guard;

Expand All @@ -25,7 +25,7 @@ class Authenticated
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/Events/Failed.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
class Failed
{
/**
* The authentication guard implementation.
* The authentication guard name.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
* @var string
*/
public $guard;

Expand All @@ -28,7 +28,7 @@ class Failed
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable|null $user
* @param array $credentials
* @return void
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/Events/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Login
use SerializesModels;

/**
* The authentication guard implementation.
* The authentication guard name.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
* @var string
*/
public $guard;

Expand All @@ -32,7 +32,7 @@ class Login
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @param bool $remember
* @return void
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Auth/Events/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Logout
use SerializesModels;

/**
* The authenticationg guard implementation.
* The authentication guard name.
*
* @var \Illuminate\Contracts\Auth\StatefulGuard
* @var string
*/
public $guard;

Expand All @@ -25,7 +25,7 @@ class Logout
/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\StatefulGuard $guard
* @param string $guard
* @param \Illuminate\Contracts\Auth\Authenticatable $user
* @return void
*/
Expand Down
10 changes: 5 additions & 5 deletions src/Illuminate/Auth/SessionGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ public function logout()
}

if (isset($this->events)) {
$this->events->dispatch(new Events\Logout($this, $user));
$this->events->dispatch(new Events\Logout($this->name, $user));
}

// Once we have fired the logout event we will clear the users out of memory
Expand Down Expand Up @@ -580,7 +580,7 @@ protected function fireAttemptEvent(array $credentials, $remember = false)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Attempting(
$this, $credentials, $remember
$this->name, $credentials, $remember
));
}
}
Expand All @@ -596,7 +596,7 @@ protected function fireLoginEvent($user, $remember = false)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Login(
$this, $user, $remember
$this->name, $user, $remember
));
}
}
Expand All @@ -611,7 +611,7 @@ protected function fireAuthenticatedEvent($user)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Authenticated(
$this, $user
$this->name, $user
));
}
}
Expand All @@ -627,7 +627,7 @@ protected function fireFailedEvent($user, array $credentials)
{
if (isset($this->events)) {
$this->events->dispatch(new Events\Failed(
$this, $user, $credentials
$this->name, $user, $credentials
));
}
}
Expand Down
51 changes: 46 additions & 5 deletions tests/Integration/Auth/AuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function basic_auth_fails_on_wrong_credentials()
/**
* @test
*/
public function logging_in_via_attempt()
public function logging_in_fails_via_attempt()
{
Event::fake();

Expand All @@ -123,16 +123,52 @@ public function logging_in_via_attempt()
);
$this->assertFalse($this->app['auth']->check());
$this->assertNull($this->app['auth']->user());
Event::assertDispatched(\Illuminate\Auth\Events\Failed::class);
Event::assertDispatched(\Illuminate\Auth\Events\Attempting::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(['email' => 'wrong', 'password' => 'password'], $event->credentials);

return true;
});
Event::assertDispatched(\Illuminate\Auth\Events\Failed::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(['email' => 'wrong', 'password' => 'password'], $event->credentials);
$this->assertNull($event->user);

return true;
});
}

/**
* @test
*/
public function logging_in_succeeds_via_attempt()
{
Event::fake();

$this->assertTrue(
$this->app['auth']->attempt(['email' => 'email', 'password' => 'password'])
);
$this->assertInstanceOf(AuthenticationTestUser::class, $this->app['auth']->user());
$this->assertTrue($this->app['auth']->check());

Event::assertDispatched(\Illuminate\Auth\Events\Login::class);
Event::assertDispatched(\Illuminate\Auth\Events\Authenticated::class);
Event::assertDispatched(\Illuminate\Auth\Events\Attempting::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(['email' => 'email', 'password' => 'password'], $event->credentials);

return true;
});
Event::assertDispatched(\Illuminate\Auth\Events\Login::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(1, $event->user->id);

return true;
});
Event::assertDispatched(\Illuminate\Auth\Events\Authenticated::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(1, $event->user->id);

return true;
});
}

/**
Expand All @@ -158,7 +194,12 @@ public function test_logging_out()

$this->app['auth']->logout();
$this->assertNull($this->app['auth']->user());
Event::assertDispatched(\Illuminate\Auth\Events\Logout::class);
Event::assertDispatched(\Illuminate\Auth\Events\Logout::class, function ($event) {
$this->assertEquals('web', $event->guard);
$this->assertEquals(1, $event->user->id);

return true;
});
}

/**
Expand Down