Skip to content

Commit f6d4bcb

Browse files
committed
NFS-616: fixes code style issues
1 parent e5b1278 commit f6d4bcb

6 files changed

Lines changed: 281 additions & 283 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
],
1414
"require": {
15-
"php": "^5.5 || ^7.3",
15+
"php": "^7.3",
1616
"lcobucci/jwt": "^3.2"
1717

1818
},

src/PluginSession.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
namespace Staffbase\plugins\sdk;
1616

1717
use SessionHandlerInterface;
18-
use Staffbase\plugins\sdk\SSOData;
19-
use Staffbase\plugins\sdk\SSOToken;
2018
use Staffbase\plugins\sdk\Exceptions\SSOException;
2119
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
2220
use Staffbase\plugins\sdk\RemoteCall\RemoteCallInterface;
@@ -35,12 +33,12 @@ class PluginSession extends SSOData
3533
const KEY_DATA = 'data';
3634

3735
/**
38-
* @var $pluginInstanceId the id of the currently used instance.
36+
* @var String $pluginInstanceId the id of the currently used instance.
3937
*/
4038
private $pluginInstanceId = null;
4139

4240
/**
43-
* @var $userView flag for userView mode.
41+
* @var boolean $userView flag for userView mode.
4442
*/
4543
private $userView = true;
4644

@@ -49,9 +47,9 @@ class PluginSession extends SSOData
4947
*
5048
* @param string $pluginId the unique name of the plugin
5149
* @param string $appSecret application public key
52-
* @param $sessionHandler optional custom session handler
53-
* @param $leeway in seconds to compensate clock skew
54-
* @param $remoteCallHandler a class handling remote calls
50+
* @param SessionHandlerInterface $sessionHandler optional custom session handler
51+
* @param int $leeway in seconds to compensate clock skew
52+
* @param RemoteCallInterface $remoteCallHandler a class handling remote calls
5553
*
5654
* @throws SSOAuthenticationException | SSOException
5755
*/

src/SSOToken.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414

1515
namespace Staffbase\plugins\sdk;
1616

17+
use Lcobucci\JWT\Token;
1718
use Lcobucci\JWT\Parser;
18-
use Lcobucci\JWT\Builder;
19+
use Lcobucci\JWT\Signer\Key;
1920
use Lcobucci\JWT\ValidationData;
2021
use Lcobucci\JWT\Claim\Validatable;
21-
use Lcobucci\JWT\Signer\Keychain;
2222
use Lcobucci\JWT\Signer\Rsa\Sha256;
2323
use Staffbase\plugins\sdk\Exceptions\SSOException;
2424
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
@@ -30,7 +30,7 @@
3030
class SSOToken extends SSOData
3131
{
3232
/**
33-
* @var $token Lcobucci\JWT\Token
33+
* @var Token $token
3434
*/
3535
private $token = null;
3636

@@ -68,8 +68,6 @@ public function __construct($appSecret, $tokenData, $leeway = 0) {
6868
* @param string $tokenData The token text.
6969
* @param int $leeway count of seconds added to current timestamp
7070
*
71-
* @return Lcobucci\JWT\Token;
72-
*
7371
* @throws SSOAuthenticationException if the parsing/verification/validation of the token fails.
7472
*/
7573
protected function parseToken($appSecret, $tokenData, $leeway) {
@@ -79,9 +77,9 @@ protected function parseToken($appSecret, $tokenData, $leeway) {
7977

8078
// verify signature
8179
$signer = new Sha256();
82-
$keychain = new Keychain();
80+
$key = new Key($appSecret);
8381

84-
if (!$this->token->verify($signer, $keychain->getPublicKey($appSecret)))
82+
if (!$this->token->verify($signer, $key))
8583
throw new SSOAuthenticationException('Token verification failed.');
8684

8785
// validate claims
@@ -127,7 +125,7 @@ public static function base64ToPEMPublicKey($data) {
127125
* by using then supported verbosity or reimplementing validation
128126
* as done in the new flow.
129127
*
130-
* @param Lcobucci\JWT\ValidationData $data to validate against
128+
* @param ValidationData $data to validate against
131129
*
132130
* @throws SSOAuthenticationException always.
133131
*/

test/PluginSessionTest.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
namespace Staffbase\plugins\test;
1515

16-
use Exception;
1716
use ReflectionClass;
1817
use phpseclib\Crypt\RSA;
1918
use PHPUnit\Framework\TestCase;
@@ -83,7 +82,7 @@ public function testConstructorWorksAsExpected() {
8382

8483
$mock = $this->getMockBuilder($this->classname)
8584
->disableOriginalConstructor()
86-
->setMethods(array('openSession', 'closeSession'))
85+
->onlyMethods(array('openSession', 'closeSession'))
8786
->getMock();
8887

8988
$mock->expects($this->exactly(2))
@@ -112,7 +111,7 @@ public function testConstructorRejectsSpoofedPID() {
112111

113112
$mock = $this->getMockBuilder($this->classname)
114113
->disableOriginalConstructor()
115-
->setMethods(array('openSession', 'closeSession'))
114+
->onlyMethods(array('openSession', 'closeSession'))
116115
->getMock();
117116

118117
$reflectedClass = new ReflectionClass($this->classname);
@@ -138,7 +137,7 @@ public function testConstructorRefuseEmptyPluginId() {
138137

139138
$mock = $this->getMockBuilder($this->classname)
140139
->disableOriginalConstructor()
141-
->setMethods(array('openSession', 'closeSession'))
140+
->onlyMethods(array('openSession', 'closeSession'))
142141
->getMock();
143142

144143
$this->expectException(SSOException::class);
@@ -162,7 +161,7 @@ public function testConstructorRefuseEmptySecret() {
162161

163162
$mock = $this->getMockBuilder($this->classname)
164163
->disableOriginalConstructor()
165-
->setMethods(array('openSession', 'closeSession'))
164+
->onlyMethods(array('openSession', 'closeSession'))
166165
->getMock();
167166

168167
$this->expectException(SSOException::class);
@@ -186,7 +185,7 @@ public function testConstructorRefuseEmptyEnv() {
186185

187186
$mock = $this->getMockBuilder($this->classname)
188187
->disableOriginalConstructor()
189-
->setMethods(array('openSession', 'closeSession'))
188+
->onlyMethods(array('openSession', 'closeSession'))
190189
->getMock();
191190

192191
$this->expectException(SSOAuthenticationException::class);
@@ -210,7 +209,7 @@ public function testConstructorRefuseHavingBothJwtAndPid() {
210209

211210
$mock = $this->getMockBuilder($this->classname)
212211
->disableOriginalConstructor()
213-
->setMethods(array('openSession', 'closeSession'))
212+
->onlyMethods(array('openSession', 'closeSession'))
214213
->getMock();
215214

216215
$this->expectException(SSOAuthenticationException::class);
@@ -234,10 +233,11 @@ public function testConstructorUpdatesInfoOnJwt() {
234233

235234
$mock = $this->getMockBuilder($this->classname)
236235
->disableOriginalConstructor()
237-
->setMethods(array('openSession', 'closeSession'))
236+
->onlyMethods(array('openSession', 'closeSession'))
238237
->getMock();
239238

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

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

@@ -248,6 +248,7 @@ public function testConstructorUpdatesInfoOnJwt() {
248248
$this->setupEnvironment(null, $newToken, false);
249249
$newSession = new $mock($this->pluginId, $this->publicKey);
250250

251+
/** @var PluginSession $newSession */
251252
$this->assertEquals($newSession->getRole(), $tokenData[PluginSession::CLAIM_USER_ROLE]);
252253
$this->assertEquals($session->getRole(), $newSession->getRole());
253254
}
@@ -267,9 +268,10 @@ public function testConstructorSupportMultipleInstances() {
267268

268269
$mock = $this->getMockBuilder($this->classname)
269270
->disableOriginalConstructor()
270-
->setMethods(array('openSession', 'closeSession'))
271+
->onlyMethods(array('openSession', 'closeSession'))
271272
->getMock();
272273

274+
/** @var PluginSession $session */
273275
$session = new $mock($this->pluginId, $this->publicKey);
274276

275277

@@ -280,7 +282,8 @@ public function testConstructorSupportMultipleInstances() {
280282

281283
$this->setupEnvironment(null, $newToken, false);
282284

283-
$newSession = new $mock($this->pluginId, $this->publicKey);
285+
/** @var PluginSession $newSession */
286+
$newSession = new $mock($this->pluginId, $this->publicKey);
284287

285288
$this->assertEquals($newSession->getRole(), $tokenData[PluginSession::CLAIM_USER_ROLE]);
286289
$this->assertNotEquals($session->getRole(), $newSession->getRole());
@@ -311,10 +314,11 @@ public function testGetSessionData() {
311314

312315
$mock = $this->getMockBuilder($this->classname)
313316
->disableOriginalConstructor()
314-
->setMethods(array('openSession', 'closeSession'))
317+
->onlyMethods(array('openSession', 'closeSession'))
315318
->getMock();
316319

317-
$session = new $mock($this->pluginId, $this->publicKey);
320+
/** @var PluginSession $session */
321+
$session = new $mock($this->pluginId, $this->publicKey);
318322

319323
$sessionData = [
320324
'test1' => 'val1',
@@ -346,7 +350,7 @@ public function testDeleteSuccessfulCallInterface() {
346350

347351
// successfull remote call handler mock
348352
$handler = $this->getMockBuilder(DeleteInstanceCallHandlerInterface::class)
349-
->setMethods(array('deleteInstance', 'exitSuccess', 'exitFailure'))
353+
->onlyMethods(array('deleteInstance', 'exitSuccess', 'exitFailure'))
350354
->getMock();
351355

352356
$handler->method('deleteInstance')
@@ -364,7 +368,7 @@ public function testDeleteSuccessfulCallInterface() {
364368
// session mock
365369
$Session = $this->getMockBuilder($this->classname)
366370
->disableOriginalConstructor()
367-
->setMethods(array('openSession', 'closeSession', 'exitRemoteCall'))
371+
->onlyMethods(array('openSession', 'closeSession', 'exitRemoteCall'))
368372
->getMock();
369373

370374
new $Session($this->pluginId, $this->publicKey, null, 0, $handler);
@@ -387,7 +391,7 @@ public function testDeleteFailedCallInterface() {
387391

388392
// successfull remote call handler mock
389393
$handler = $this->getMockBuilder(DeleteInstanceCallHandlerInterface::class)
390-
->setMethods(array('deleteInstance', 'exitSuccess', 'exitFailure'))
394+
->onlyMethods(array('deleteInstance', 'exitSuccess', 'exitFailure'))
391395
->getMock();
392396

393397
$handler->method('deleteInstance')
@@ -405,7 +409,7 @@ public function testDeleteFailedCallInterface() {
405409
// session mock
406410
$Session = $this->getMockBuilder($this->classname)
407411
->disableOriginalConstructor()
408-
->setMethods(array('openSession', 'closeSession', 'exitRemoteCall'))
412+
->onlyMethods(array('openSession', 'closeSession', 'exitRemoteCall'))
409413
->getMock();
410414

411415
new $Session($this->pluginId, $this->publicKey, null, 0, $handler);

0 commit comments

Comments
 (0)