Skip to content

Commit 202c23d

Browse files
committed
NFS-616: converts spaces to tabs
1 parent 30f73e5 commit 202c23d

2 files changed

Lines changed: 132 additions & 132 deletions

File tree

src/PluginSession.php

Lines changed: 73 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ class PluginSession extends SSOData
4242
*/
4343
private $userView = true;
4444

45-
/**
46-
* @var SSOToken token data from the parsed jwt
47-
*/
45+
/**
46+
* @var SSOToken token data from the parsed jwt
47+
*/
4848
private $sso = null;
4949

5050
/**
@@ -93,24 +93,24 @@ public function __construct($pluginId, $appSecret, SessionHandlerInterface $sess
9393
$this->pluginInstanceId = $this->sso->getInstanceId();
9494
}
9595

96-
// dispatch remote calls from Staffbase
97-
if ($this->sso) {
98-
$this->deleteInstance($remoteCallHandler);
99-
}
96+
// dispatch remote calls from Staffbase
97+
if ($this->sso) {
98+
$this->deleteInstance($remoteCallHandler);
99+
}
100100

101101
// decide if we are in user view or not
102-
$this->userView = !$this->isAdminView();
102+
$this->userView = !$this->isAdminView();
103103

104-
$this->openSession($pluginId);
104+
$this->openSession($pluginId);
105105

106-
if ($this->sso !== null) {
107-
$_SESSION[$this->pluginInstanceId][self::KEY_SSO] = $this->sso->getData();
108-
}
106+
if ($this->sso !== null) {
107+
$_SESSION[$this->pluginInstanceId][self::KEY_SSO] = $this->sso->getData();
108+
}
109109

110-
// requests with spoofed PID are not allowed
111-
if (!isset($_SESSION[$this->pluginInstanceId][self::KEY_SSO])
112-
|| empty($_SESSION[$this->pluginInstanceId][self::KEY_SSO]))
113-
throw new SSOAuthenticationException('Tried to access an instance without previous authentication.');
110+
// requests with spoofed PID are not allowed
111+
if (!isset($_SESSION[$this->pluginInstanceId][self::KEY_SSO])
112+
|| empty($_SESSION[$this->pluginInstanceId][self::KEY_SSO]))
113+
throw new SSOAuthenticationException('Tried to access an instance without previous authentication.');
114114
}
115115

116116
/**
@@ -122,38 +122,38 @@ public function __destruct() {
122122
}
123123

124124
private function isAdminView() {
125-
return $this->isEditor() && (!isset($_GET[self::QUERY_PARAM_USERVIEW]) || $_GET[self::QUERY_PARAM_USERVIEW] !== 'true');
126-
}
125+
return $this->isEditor() && (!isset($_GET[self::QUERY_PARAM_USERVIEW]) || $_GET[self::QUERY_PARAM_USERVIEW] !== 'true');
126+
}
127127

128128
private function deleteInstance($remoteCallHandler){
129-
if (!$this->sso->isDeleteInstanceCall() || !$remoteCallHandler) {
130-
return;
131-
}
132-
133-
$instanceId = $this->sso->getInstanceId();
134-
135-
if ($remoteCallHandler instanceOf DeleteInstanceCallHandlerInterface) {
136-
$result = $remoteCallHandler->deleteInstance($instanceId);
137-
} else {
138-
// we will accept unhandled calls with a warning
139-
$result = true;
140-
error_log("Warning: An instance deletion call for instance $instanceId was not handled.");
141-
}
142-
143-
// finish the remote call
144-
if($result)
145-
$remoteCallHandler->exitSuccess();
146-
else
147-
$remoteCallHandler->exitFailure();
148-
149-
$this->exitRemoteCall();
150-
}
151-
152-
private function createCompatibleSessionId(String $string): String
153-
{
154-
$allowedChars = '/[^a-zA-Z0-9,-]/';
155-
return preg_replace($allowedChars, '-', $string);
156-
}
129+
if (!$this->sso->isDeleteInstanceCall() || !$remoteCallHandler) {
130+
return;
131+
}
132+
133+
$instanceId = $this->sso->getInstanceId();
134+
135+
if ($remoteCallHandler instanceOf DeleteInstanceCallHandlerInterface) {
136+
$result = $remoteCallHandler->deleteInstance($instanceId);
137+
} else {
138+
// we will accept unhandled calls with a warning
139+
$result = true;
140+
error_log("Warning: An instance deletion call for instance $instanceId was not handled.");
141+
}
142+
143+
// finish the remote call
144+
if($result)
145+
$remoteCallHandler->exitSuccess();
146+
else
147+
$remoteCallHandler->exitFailure();
148+
149+
$this->exitRemoteCall();
150+
}
151+
152+
private function createCompatibleSessionId(String $string): String
153+
{
154+
$allowedChars = '/[^a-zA-Z0-9,-]/';
155+
return preg_replace($allowedChars, '-', $string);
156+
}
157157

158158
/**
159159
* Exit the script
@@ -165,16 +165,16 @@ protected function exitRemoteCall() {
165165
exit;
166166
}
167167

168-
/**
169-
* Open a session.
170-
*
171-
* @param string $name of the session
172-
*/
168+
/**
169+
* Open a session.
170+
*
171+
* @param string $name of the session
172+
*/
173173
protected function openSession($name) {
174174

175-
$sessionId = $this->createCompatibleSessionId($this->sso->getSessionId());
175+
$sessionId = $this->createCompatibleSessionId($this->sso->getSessionId());
176176

177-
session_id($sessionId);
177+
session_id($sessionId);
178178
session_name($name);
179179
session_start();
180180
}
@@ -196,7 +196,7 @@ protected function closeSession() {
196196
*/
197197
public static function base64ToPEMPublicKey($data) {
198198

199-
error_log("Warning: PluginSession::base64ToPEMPublicKey() is deprecated. Please switch over to SSOToken::base64ToPEMPublicKey().");
199+
error_log("Warning: PluginSession::base64ToPEMPublicKey() is deprecated. Please switch over to SSOToken::base64ToPEMPublicKey().");
200200

201201
return SSOToken::base64ToPEMPublicKey($data);
202202
}
@@ -284,24 +284,24 @@ public function isUserView() {
284284
return $this->userView;
285285
}
286286

287-
/**
288-
* Destroy the session with the given id
289-
*
290-
* @param String $sessionId
291-
* @return bool true on success or false on failure.
292-
*/
293-
public function destroySession(String $sessionId) {
294-
$currentId = session_id();
295-
session_write_close();
296-
297-
session_id($this->createCompatibleSessionId($sessionId));
298-
session_start();
299-
$result = session_destroy();
300-
301-
session_id($currentId);
302-
session_start();
303-
304-
return $result;
305-
}
287+
/**
288+
* Destroy the session with the given id
289+
*
290+
* @param String $sessionId
291+
* @return bool true on success or false on failure.
292+
*/
293+
public function destroySession(String $sessionId) {
294+
$currentId = session_id();
295+
session_write_close();
296+
297+
session_id($this->createCompatibleSessionId($sessionId));
298+
session_start();
299+
$result = session_destroy();
300+
301+
session_id($currentId);
302+
session_start();
303+
304+
return $result;
305+
}
306306

307307
}

test/PluginSessionTest.php

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ private function setupEnvironment($queryParamPid = null, $queryParamJwt = null,
6565
$_GET[PluginSession::QUERY_PARAM_JWT] = $queryParamJwt;
6666

6767
if($clearSession) {
68-
session_write_close();
69-
session_abort();
70-
$_SESSION = [];
71-
}
68+
session_write_close();
69+
session_abort();
70+
$_SESSION = [];
71+
}
7272
}
7373

7474
/**
@@ -417,15 +417,15 @@ public function testDeleteFailedCallInterface() {
417417
new $Session($this->pluginId, $this->publicKey, null, 0, $handler);
418418
}
419419

420-
/**
421-
* @test
422-
*
423-
* Test that a session is created.
424-
*
425-
* @covers \Staffbase\plugins\sdk\PluginSession::__construct
426-
*/
420+
/**
421+
* @test
422+
*
423+
* Test that a session is created.
424+
*
425+
* @covers \Staffbase\plugins\sdk\PluginSession::__construct
426+
*/
427427
public function testSessionIsCreated() {
428-
$tokenData = $this->tokenData;
428+
$tokenData = $this->tokenData;
429429
$this->setupEnvironment(null, $this->token, true);
430430

431431
$mock = $this->getMockBuilder($this->classname)
@@ -436,72 +436,72 @@ public function testSessionIsCreated() {
436436
$constructor = $reflectedClass->getConstructor();
437437

438438
$this->assertEquals(PHP_SESSION_NONE, session_status());
439-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
440-
$this->assertEquals(PHP_SESSION_ACTIVE, session_status());
439+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
440+
$this->assertEquals(PHP_SESSION_ACTIVE, session_status());
441441

442-
$this->assertEquals($tokenData[PluginSession::CLAIM_SESSION_ID], session_id());
443-
}
442+
$this->assertEquals($tokenData[PluginSession::CLAIM_SESSION_ID], session_id());
443+
}
444444

445-
public function testSessionIdCheck() {
445+
public function testSessionIdCheck() {
446446

447-
$sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg=';
448-
$sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-';
447+
$sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg=';
448+
$sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-';
449449

450-
$tokenData = $this->tokenData;
451-
$tokenData[PluginSession::CLAIM_SESSION_ID] = $sessionHash;
452-
$token = SSOTokenTest::createSignedTokenFromData($this->privateKey, $tokenData);
450+
$tokenData = $this->tokenData;
451+
$tokenData[PluginSession::CLAIM_SESSION_ID] = $sessionHash;
452+
$token = SSOTokenTest::createSignedTokenFromData($this->privateKey, $tokenData);
453453

454-
$this->setupEnvironment(null, $token, true);
454+
$this->setupEnvironment(null, $token, true);
455455

456-
$mock = $this->getMockBuilder($this->classname)
457-
->disableOriginalConstructor()
458-
->getMock();
456+
$mock = $this->getMockBuilder($this->classname)
457+
->disableOriginalConstructor()
458+
->getMock();
459459

460-
$reflectedClass = new ReflectionClass($this->classname);
461-
$constructor = $reflectedClass->getConstructor();
460+
$reflectedClass = new ReflectionClass($this->classname);
461+
$constructor = $reflectedClass->getConstructor();
462462

463-
$this->assertEquals(PHP_SESSION_NONE, session_status());
464-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
465-
$this->assertEquals(PHP_SESSION_ACTIVE, session_status());
463+
$this->assertEquals(PHP_SESSION_NONE, session_status());
464+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
465+
$this->assertEquals(PHP_SESSION_ACTIVE, session_status());
466466

467-
$this->assertEquals($sessionId, session_id());
468-
}
467+
$this->assertEquals($sessionId, session_id());
468+
}
469469

470-
public function testDestroyOtherSession() {
470+
public function testDestroyOtherSession() {
471471

472-
$sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg=';
473-
$sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-';
472+
$sessionHash = 'HOjLTR6+D5YIY0/waqJQp3Bg=';
473+
$sessionId = 'HOjLTR6-D5YIY0-waqJQp3Bg-';
474474

475-
$tokenData = $this->tokenData;
476-
$tokenData[PluginSession::CLAIM_SESSION_ID] = $sessionHash;
477-
$token = SSOTokenTest::createSignedTokenFromData($this->privateKey, $tokenData);
475+
$tokenData = $this->tokenData;
476+
$tokenData[PluginSession::CLAIM_SESSION_ID] = $sessionHash;
477+
$token = SSOTokenTest::createSignedTokenFromData($this->privateKey, $tokenData);
478478

479-
// successfull remote call handler mock
480-
$handler = $this->getMockBuilder(SessionHandlerInterface::class)
481-
->setMethodsExcept()
482-
->getMock();
479+
// successfull remote call handler mock
480+
$handler = $this->getMockBuilder(SessionHandlerInterface::class)
481+
->setMethodsExcept()
482+
->getMock();
483483

484-
$handler->method('close')->willReturn(true);
485-
$handler->method('destroy')->willReturn(true);
486-
$handler->method('open')->willReturn(true);
487-
$handler->method('write')->willReturn(true);
488-
$handler->method('read')->willReturn($sessionId);
484+
$handler->method('close')->willReturn(true);
485+
$handler->method('destroy')->willReturn(true);
486+
$handler->method('open')->willReturn(true);
487+
$handler->method('write')->willReturn(true);
488+
$handler->method('read')->willReturn($sessionId);
489489

490-
$this->setupEnvironment(null, $token, true);
490+
$this->setupEnvironment(null, $token, true);
491491

492-
/** @var SessionHandlerInterface $handler */
493-
new PluginSession($this->pluginId, $this->publicKey);
492+
/** @var SessionHandlerInterface $handler */
493+
new PluginSession($this->pluginId, $this->publicKey);
494494

495-
$this->setupEnvironment(null, $this->token, false);
495+
$this->setupEnvironment(null, $this->token, false);
496496

497-
/** @var PluginSession $session */
498-
$session = new PluginSession($this->pluginId, $this->publicKey, $handler);
497+
/** @var PluginSession $session */
498+
$session = new PluginSession($this->pluginId, $this->publicKey, $handler);
499499

500-
$handler->expects($this->once())
501-
->method('destroy')
502-
->with($sessionId);
500+
$handler->expects($this->once())
501+
->method('destroy')
502+
->with($sessionId);
503503

504-
$session->destroySession($sessionHash);
505-
}
504+
$session->destroySession($sessionHash);
505+
}
506506

507507
}

0 commit comments

Comments
 (0)