Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
matrix:
operating-system: ['ubuntu-latest']
php-versions: ['8.3', '8.4']
php-versions: ['8.3', '8.4', '8.5']
phpunit-versions: ['latest']
steps:
- name: Checkout
Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "staffbase/plugins-sdk-php",
"version": "3.0.1",
"version": "3.0.2",
"type": "library",
"description": "Staffbase PHP SDK library for plugins.",
"keywords": ["staffbase", "plugins", "library", "php", "sdk"],
Expand All @@ -13,13 +13,12 @@
}
],
"require": {
"php": "^8.3 || ^8.4",
"php": "^8.3",
"lcobucci/jwt": "^5.5",
"lcobucci/clock": "^3.3"

},
"require-dev": {
"phpseclib/phpseclib": "^2.0",
"phpunit/phpunit": "^9.0"
},
"autoload": {
Expand Down
2 changes: 1 addition & 1 deletion src/SSOTokenGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class SSOTokenGenerator
*
* @return string Encoded token.
*/
public static function createSignedTokenFromData(string $privateKey, array $tokenData, Signer $signer = null): string
public static function createSignedTokenFromData(string $privateKey, array $tokenData, ?Signer $signer = null): string
{

$config = Configuration::forSymmetricSigner($signer ?: new Sha256(), InMemory::plainText($privateKey));
Expand Down
2 changes: 1 addition & 1 deletion src/SessionHandling/SessionHandlerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function setSessionVar($key, $val, ?string $parentKey = null): void
* @param String|null $sessionId
* @return bool true on success or false on failure.
*/
public function destroySession(String $sessionId = null): bool
public function destroySession(?string $sessionId = null): bool
{
$sessionId = $sessionId ?: $this->sessionId;

Expand Down
9 changes: 2 additions & 7 deletions test/PluginSessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Staffbase\plugins\test;

use ReflectionClass;
use phpseclib\Crypt\RSA;
use PHPUnit\Framework\TestCase;
use SessionHandlerInterface;
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
Expand Down Expand Up @@ -42,11 +41,7 @@ public function __construct()
{

parent::__construct();
$rsa = new RSA();
$keypair = $rsa->createKey(2048);

$this->publicKey = $keypair['publickey'];
$this->privateKey = $keypair['privatekey'];
[$this->publicKey, $this->privateKey] = SSOTestData::createKeyPair();

$this->tokenData = SSOTestData::getTokenData();
$this->token = SSOTokenGenerator::createSignedTokenFromData($this->privateKey, $this->tokenData);
Expand All @@ -61,7 +56,7 @@ public function __construct()
* @param string|null $queryParamJwt JWT query param emulation
* @param boolean $clearSession optionally clear out the $_SESSION array
*/
private function setupEnvironment(string $queryParamPid = null, string $queryParamJwt = null, bool $clearSession = true)
private function setupEnvironment(?string $queryParamPid = null, ?string $queryParamJwt = null, bool $clearSession = true)
{

$_REQUEST[PluginSession::QUERY_PARAM_PID] = $queryParamPid;
Expand Down
14 changes: 7 additions & 7 deletions test/SSOData/SSODataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ public function testIsEditorReturnsCorrectValues(): void
{

$map = [
null => false,
'' => false,
'use' => false,
'edito' => false,
'user' => false,
'editor' => true,
[null, false],
['', false],
['use', false],
['edito', false],
['user', false],
['editor', true],
];

foreach ($map as $arg => $expect) {
foreach ($map as [$arg, $expect]) {
$tokenData = SSOTestData::getTokenData();
$tokenData[SSOTestData::CLAIM_USER_ROLE] = $arg;

Expand Down
16 changes: 16 additions & 0 deletions test/SSOTestData.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ class SSOTestData
private const CLAIM_USER_LOCALE = 'locale';
private const CLAIM_USER_TAGS = 'tags';

/**
* Create an RSA-256 key pair in PEM format.
*
* @return array{0: string, 1: string} public key and private key
*/
public static function createKeyPair(): array
{
$key = openssl_pkey_new([
'private_key_bits' => 2048,
'private_key_type' => OPENSSL_KEYTYPE_RSA,
]);
openssl_pkey_export($key, $privateKey);

return [openssl_pkey_get_details($key)['key'], $privateKey];
}

/**
* Create test data for a token.
*
Expand Down
7 changes: 1 addition & 6 deletions test/SSOTokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
namespace Staffbase\plugins\test;

use DateTimeImmutable;
use phpseclib\Crypt\RSA;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
use Staffbase\plugins\sdk\Exceptions\SSOAuthenticationException;
Expand All @@ -37,11 +36,7 @@ class SSOTokenTest extends TestCase
public function setUp(): void
{

$rsa = new RSA();
$keypair = $rsa->createKey(2048);

$this->publicKey = $keypair['publickey'];
$this->privateKey = $keypair['privatekey'];
[$this->publicKey, $this->privateKey] = SSOTestData::createKeyPair();
}

/**
Expand Down
Loading