Skip to content

Commit

Permalink
Merge pull request #74 from creative-commoners/pulls/3/fix-namespace
Browse files Browse the repository at this point in the history
FIX Use correct namespace for session manager controller
  • Loading branch information
GuySartorelli authored Apr 25, 2024
2 parents 0cfd55e + 7a1b7b1 commit d72b429
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
2 changes: 1 addition & 1 deletion _config/session-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ Name: auditor-session-manager
Only:
moduleexists: silverstripe/session-manager
---
SilverStripe\SessionManager\Control\LoginSessionController:
SilverStripe\SessionManager\Controllers\LoginSessionController:
extensions:
- SilverStripe\Auditor\AuditHookSessionManager
16 changes: 9 additions & 7 deletions tests/AuditHookSessionManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use SilverStripe\Security\Member;
use SilverStripe\Security\Security;
use SilverStripe\Security\SecurityToken;
use SilverStripe\SessionManager\Control\LoginSessionController;
use SilverStripe\SessionManager\Controllers\LoginSessionController;
use SilverStripe\SessionManager\Models\LoginSession;

class AuditHookSessionManagerTest extends SapphireTest
Expand Down Expand Up @@ -38,27 +38,29 @@ public function testOnBeforeRemoveLoginSession()
{
$this->logInWithPermission('ADMIN');

$currentUser = Security::getCurrentUser();

$member = new Member(array('FirstName' => 'Joe', 'Email' => 'joe3'));
$member->write();
$request = Controller::curr()->getRequest();
$loginSession = LoginSession::generate($member, false, $request);

// Only the current user is able to remove their login session, not even admin can do it
Security::setCurrentUser($member);

SecurityToken::disable();
$mockRequest = new HTTPRequest('DELETE', '');
$mockRequest->setRouteParams(['ID' => $loginSession->ID]);
$controller = new LoginSessionController();
$controller->removeLoginSession($mockRequest);
$controller->remove($mockRequest);

$message = sprintf(
'Login session (ID: %s) for Member "%s" (ID: %s) is being removed by Member "%s" (ID: %s)',
$loginSession->ID,
$member->Email,
$member->ID,
$currentUser->Email,
$currentUser->ID
$member->Email,
$member->ID
);
$this->assertContains($message, $this->writer->getLastMessage());

$this->assertStringContainsString($message, $this->writer->getLastMessage());
}
}

0 comments on commit d72b429

Please sign in to comment.