|
16 | 16 | use ReflectionClass; |
17 | 17 | use phpseclib\Crypt\RSA; |
18 | 18 | use PHPUnit\Framework\TestCase; |
| 19 | +use SessionHandlerInterface; |
19 | 20 | use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException; |
20 | 21 | use Staffbase\plugins\sdk\Exceptions\SSOException; |
21 | 22 | use Staffbase\plugins\sdk\PluginSession; |
@@ -469,4 +470,41 @@ public function testSessionIdCheck() { |
469 | 470 | $this->assertEquals($sessionId, session_id()); |
470 | 471 | } |
471 | 472 |
|
| 473 | + public function testDestroyOtherSession() { |
| 474 | + |
| 475 | + $sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg='; |
| 476 | + $sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-'; |
| 477 | + |
| 478 | + $tokenData = $this->tokenData; |
| 479 | + $tokenData[PluginSession::CLAIM_SESSION_ID] = $sessionHash; |
| 480 | + $token = SSOTokenTest::createSignedTokenFromData($this->privateKey, $tokenData); |
| 481 | + |
| 482 | + // successfull remote call handler mock |
| 483 | + $handler = $this->getMockBuilder(SessionHandlerInterface::class) |
| 484 | + ->setMethodsExcept() |
| 485 | + ->getMock(); |
| 486 | + |
| 487 | + $handler->method('close')->willReturn(true); |
| 488 | + $handler->method('destroy')->willReturn(true); |
| 489 | + $handler->method('open')->willReturn(true); |
| 490 | + $handler->method('write')->willReturn(true); |
| 491 | + $handler->method('read')->willReturn($sessionId); |
| 492 | + |
| 493 | + $this->setupEnvironment(null, $token, true); |
| 494 | + |
| 495 | + /** @var SessionHandlerInterface $handler */ |
| 496 | + new PluginSession($this->pluginId, $this->publicKey); |
| 497 | + |
| 498 | + $this->setupEnvironment(null, $this->token, false); |
| 499 | + |
| 500 | + /** @var PluginSession $session */ |
| 501 | + $session = new PluginSession($this->pluginId, $this->publicKey, $handler); |
| 502 | + |
| 503 | + $handler->expects($this->once()) |
| 504 | + ->method('destroy') |
| 505 | + ->with($sessionId); |
| 506 | + |
| 507 | + $session->destroySession($sessionHash); |
| 508 | + } |
| 509 | + |
472 | 510 | } |
0 commit comments