Skip to content

Commit 30f73e5

Browse files
committed
Merge branch 'NFS-616-session-flow' into NFS-616-session-id-from-token
2 parents 6109224 + fa2ef83 commit 30f73e5

2 files changed

Lines changed: 135 additions & 138 deletions

File tree

test/PluginSessionTest.php

Lines changed: 43 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
*
88
* @category Authentication
99
* @copyright 2017-2019 Staffbase, GmbH.
10-
* @author Vitaliy Ivanov
11-
* @license http://www.apache.org/licenses/LICENSE-2.0
12-
* @link https://github.com/staffbase/plugins-sdk-php
10+
* @author Vitaliy Ivanov
11+
* @license http://www.apache.org/licenses/LICENSE-2.0
12+
* @link https://github.com/staffbase/plugins-sdk-php
1313
*/
1414
namespace Staffbase\plugins\test;
1515

@@ -39,7 +39,7 @@ class PluginSessionTest extends TestCase
3939
*/
4040
public function __construct() {
4141

42-
parent::__construct();
42+
parent::__construct();
4343
$rsa = new RSA();
4444
$keypair = $rsa->createKey();
4545

@@ -89,13 +89,13 @@ public function testConstructorWorksAsExpected() {
8989
->onlyMethods(array('openSession', 'closeSession'))
9090
->getMock();
9191

92-
$mock->expects($this->exactly(2))
93-
->method('openSession')
94-
->with($this->pluginId);
92+
$mock->expects($this->exactly(2))
93+
->method('openSession')
94+
->with($this->pluginId);
9595

9696
$reflectedClass = new ReflectionClass($this->classname);
9797
$constructor = $reflectedClass->getConstructor();
98-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
98+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
9999

100100
$this->setupEnvironment($this->pluginInstanceId, null, false);
101101

@@ -118,11 +118,11 @@ public function testConstructorRejectsSpoofedPID() {
118118

119119
$this->setupEnvironment($this->pluginInstanceId. 'spoof', null, false);
120120

121-
$this->expectException(SSOException::class);
121+
$this->expectException(SSOException::class);
122122

123-
$reflectedClass = new ReflectionClass($this->classname);
124-
$constructor = $reflectedClass->getConstructor();
125-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
123+
$reflectedClass = new ReflectionClass($this->classname);
124+
$constructor = $reflectedClass->getConstructor();
125+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
126126
}
127127

128128
/**
@@ -141,12 +141,12 @@ public function testConstructorRefuseEmptyPluginId() {
141141
->onlyMethods(array('openSession', 'closeSession'))
142142
->getMock();
143143

144-
$this->expectException(SSOException::class);
145-
$this->expectExceptionMessage('Empty plugin ID.');
144+
$this->expectException(SSOException::class);
145+
$this->expectExceptionMessage('Empty plugin ID.');
146146

147-
$reflectedClass = new ReflectionClass($this->classname);
148-
$constructor = $reflectedClass->getConstructor();
149-
$constructor->invoke($mock, '', $this->publicKey);
147+
$reflectedClass = new ReflectionClass($this->classname);
148+
$constructor = $reflectedClass->getConstructor();
149+
$constructor->invoke($mock, '', $this->publicKey);
150150
}
151151

152152
/**
@@ -165,12 +165,12 @@ public function testConstructorRefuseEmptySecret() {
165165
->onlyMethods(array('openSession', 'closeSession'))
166166
->getMock();
167167

168-
$this->expectException(SSOException::class);
169-
$this->expectExceptionMessage('Empty app secret.');
168+
$this->expectException(SSOException::class);
169+
$this->expectExceptionMessage('Empty app secret.');
170170

171-
$reflectedClass = new ReflectionClass($this->classname);
172-
$constructor = $reflectedClass->getConstructor();
173-
$constructor->invoke($mock, $this->pluginId, '');
171+
$reflectedClass = new ReflectionClass($this->classname);
172+
$constructor = $reflectedClass->getConstructor();
173+
$constructor->invoke($mock, $this->pluginId, '');
174174
}
175175

176176
/**
@@ -189,12 +189,12 @@ public function testConstructorRefuseEmptyEnv() {
189189
->onlyMethods(array('openSession', 'closeSession'))
190190
->getMock();
191191

192-
$this->expectException(SSOAuthenticationException::class);
193-
$this->expectExceptionMessage('Missing PID or JWT query parameter in Request.');
192+
$this->expectException(SSOAuthenticationException::class);
193+
$this->expectExceptionMessage('Missing PID or JWT query parameter in Request.');
194194

195-
$reflectedClass = new ReflectionClass($this->classname);
196-
$constructor = $reflectedClass->getConstructor();
197-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
195+
$reflectedClass = new ReflectionClass($this->classname);
196+
$constructor = $reflectedClass->getConstructor();
197+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
198198
}
199199

200200
/**
@@ -213,12 +213,12 @@ public function testConstructorRefuseHavingBothJwtAndPid() {
213213
->onlyMethods(array('openSession', 'closeSession'))
214214
->getMock();
215215

216-
$this->expectException(SSOAuthenticationException::class);
217-
$this->expectExceptionMessage('Tried to initialize the session with both PID and JWT provided.');
216+
$this->expectException(SSOAuthenticationException::class);
217+
$this->expectExceptionMessage('Tried to initialize the session with both PID and JWT provided.');
218218

219-
$reflectedClass = new ReflectionClass($this->classname);
220-
$constructor = $reflectedClass->getConstructor();
221-
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
219+
$reflectedClass = new ReflectionClass($this->classname);
220+
$constructor = $reflectedClass->getConstructor();
221+
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
222222
}
223223

224224
/**
@@ -237,8 +237,8 @@ public function testConstructorUpdatesInfoOnJwt() {
237237
->onlyMethods(array('openSession', 'closeSession'))
238238
->getMock();
239239

240-
/** @var PluginSession $session */
241-
$session = new $mock($this->pluginId, $this->publicKey);
240+
/** @var PluginSession $session */
241+
$session = new $mock($this->pluginId, $this->publicKey);
242242

243243
$this->assertEquals($session->getRole(), $this->tokenData[PluginSession::CLAIM_USER_ROLE]);
244244

@@ -248,10 +248,7 @@ public function testConstructorUpdatesInfoOnJwt() {
248248

249249
$this->setupEnvironment(null, $newToken, false);
250250

251-
/** @var PluginSession $newSession */
252-
$newSession = new $mock($this->pluginId, $this->publicKey);
253-
254-
/** @var PluginSession $newSession */
251+
/** @var PluginSession $newSession */
255252
$newSession = new $mock($this->pluginId, $this->publicKey);
256253

257254
$this->assertEquals($newSession->getRole(), $tokenData[PluginSession::CLAIM_USER_ROLE]);
@@ -276,8 +273,8 @@ public function testConstructorSupportMultipleInstances() {
276273
->onlyMethods(array('openSession', 'closeSession'))
277274
->getMock();
278275

279-
/** @var PluginSession $session */
280-
$session = new $mock($this->pluginId, $this->publicKey);
276+
/** @var PluginSession $session */
277+
$session = new $mock($this->pluginId, $this->publicKey);
281278

282279

283280
$tokenData = $this->tokenData;
@@ -287,14 +284,14 @@ public function testConstructorSupportMultipleInstances() {
287284

288285
$this->setupEnvironment(null, $newToken, false);
289286

290-
/** @var PluginSession $newSession */
291-
$newSession = new $mock($this->pluginId, $this->publicKey);
287+
/** @var PluginSession $newSession */
288+
$newSession = new $mock($this->pluginId, $this->publicKey);
292289

293290
$this->assertEquals($newSession->getRole(), $tokenData[PluginSession::CLAIM_USER_ROLE]);
294291
$this->assertNotEquals($session->getRole(), $newSession->getRole());
295292

296-
$sessionVar = 'myvariable';
297-
$sessionVal = 'mysessiontestvalue';
293+
$sessionVar = 'myvariable';
294+
$sessionVal = 'mysessiontestvalue';
298295
$sessionVal2 = 'mysessiontestvalue2';
299296

300297
$session->setSessionVar($sessionVar, $sessionVal);
@@ -322,8 +319,8 @@ public function testGetSessionData() {
322319
->onlyMethods(array('openSession', 'closeSession'))
323320
->getMock();
324321

325-
/** @var PluginSession $session */
326-
$session = new $mock($this->pluginId, $this->publicKey);
322+
/** @var PluginSession $session */
323+
$session = new $mock($this->pluginId, $this->publicKey);
327324

328325
$sessionData = [
329326
'test1' => 'val1',

0 commit comments

Comments
 (0)