diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml
index c4473dc..81a3084 100644
--- a/.github/workflows/phpunit.yml
+++ b/.github/workflows/phpunit.yml
@@ -16,9 +16,10 @@ jobs:
strategy:
matrix:
php-version:
+ - "8.4"
+ - "8.3"
- "8.2"
- "8.1"
- - "8.0"
steps:
- uses: actions/checkout@v4
@@ -32,5 +33,6 @@ jobs:
with:
folder: php
project: ${{ github.event.repository.name }}
- secrets: inherit
+ secrets:
+ DOC_TOKEN: ${{ secrets.DOC_TOKEN }}
diff --git a/.gitignore b/.gitignore
index 13c8a0e..071730b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,6 @@
composer.lock
vendor
/.phpunit.result.cache
+phpunit.coverage.xml
+phpunit.report.xml
+*.bak
diff --git a/composer.json b/composer.json
index ad5b53b..6344eb8 100644
--- a/composer.json
+++ b/composer.json
@@ -9,11 +9,16 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
- "php": ">=8.0",
- "byjg/jwt-wrapper": "4.9.*"
+ "php": ">=8.1 <8.5",
+ "byjg/jwt-wrapper": "^6.0"
},
"require-dev": {
- "phpunit/phpunit": "5.7.*|7.4.*|^9.6"
+ "phpunit/phpunit": "^10|^11",
+ "vimeo/psalm": "^5.9|^6.12"
+ },
+ "scripts": {
+ "test": "vendor/bin/phpunit",
+ "psalm": "vendor/bin/psalm"
},
"license": "MIT"
}
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index d5df793..0de38db 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -6,14 +6,21 @@ and open the template in the editor.
-->
-
* Sessions that have not updated for * the last maxlifetime seconds will be removed. *
- * @return int|false- * The return value (usually TRUE on success, FALSE on failure). - * Note this value is returned internally to PHP for processing. - *
+ * + * @return int|falseThe return value (usually TRUE on success, FALSE on failure). Note this value is returned internally to PHP for processing.
+ * * @since 5.4.0 */ + #[\Override] public function gc(int $max_lifetime): int|false { - return true; + return 1; } /** @@ -126,6 +129,7 @@ public function gc(int $max_lifetime): int|false * * @since 5.4.0 */ + #[\Override] public function open(string $path, string $name): bool { return true; @@ -143,6 +147,7 @@ public function open(string $path, string $name): bool * * @since 5.4.0 */ + #[\Override] public function read(string $id): string { try { @@ -184,13 +189,14 @@ public function read(string $id): string * @throws JwtWrapperException * @since 5.4.0 */ + #[\Override] public function write(string $id, string $data): bool { $jwt = new JwtWrapper( $this->sessionConfig->getServerName(), $this->sessionConfig->getKey() ); - $session_data = $jwt->createJwtData($data, $this->sessionConfig->getTimeoutMinutes() * 60); + $session_data = $jwt->createJwtData(['data' => $data], $this->sessionConfig->getTimeoutMinutes() * 60, 0, null); $token = $jwt->generateToken($session_data); if (!headers_sent()) { @@ -198,7 +204,7 @@ public function write(string $id, string $data): bool self::COOKIE_PREFIX . $this->sessionConfig->getSessionContext(), $token, (time()+$this->sessionConfig->getTimeoutMinutes()*60) , - $this->sessionConfig->getCookiePath() ?? "", + $this->sessionConfig->getCookiePath(), $this->sessionConfig->getCookieDomain() ?? "", false, true @@ -236,7 +242,7 @@ public function unSerializeSessionData($session_data): array $num = $pos - $offset; $varname = substr($session_data, $offset, $num); $offset += $num + 1; - $data = unserialize(substr($session_data, $offset)); + $data = @unserialize(substr($session_data, $offset), ['allowed_classes' => true]); $return_data[$varname] = $data; $offset += strlen(serialize($data)); } diff --git a/src/SessionConfig.php b/src/SessionConfig.php index cdcfdc9..54d0d13 100644 --- a/src/SessionConfig.php +++ b/src/SessionConfig.php @@ -2,9 +2,9 @@ namespace ByJG\Session; -use ByJG\Util\JwtKeyInterface; -use ByJG\Util\JwtKeySecret; -use ByJG\Util\JwtRsaKey; +use ByJG\JwtWrapper\JwtKeyInterface; +use ByJG\JwtWrapper\JwtHashHmacSecret; +use ByJG\JwtWrapper\JwtOpenSSLKey; class SessionConfig { @@ -53,13 +53,13 @@ public function withCookie($domain, $path = "/"): static public function withSecret($secret): static { - $this->jwtKey = new JwtKeySecret($secret); + $this->jwtKey = new JwtHashHmacSecret($secret); return $this; } - + public function withRsaSecret($private, $public): static { - $this->jwtKey = new JwtRsaKey($private, $public); + $this->jwtKey = new JwtOpenSSLKey($private, $public); return $this; } diff --git a/tests/JwtSessionTest.php b/tests/JwtSessionTest.php index 0cf1a09..5387a17 100644 --- a/tests/JwtSessionTest.php +++ b/tests/JwtSessionTest.php @@ -1,10 +1,11 @@ assertTrue($this->object->close()); } - public function dataProvider(): array + public static function dataProvider(): array { $obj = new stdClass(); $obj->prop1 = "value1"; @@ -119,35 +120,21 @@ public function dataProvider(): array ]; } - /** - * @dataProvider dataProvider - * @param $input - * @param $expected - */ + #[DataProvider('dataProvider')] public function testSerializeSessionData($input, $expected) { $result = $this->object->serializeSessionData($input); $this->assertEquals($expected, $result); } - /** - * @dataProvider dataProvider - * @param $expected - * @param $input - * @throws Exception - */ + #[DataProvider('dataProvider')] public function testUnserializeData($expected, $input) { $result = $this->object->unSerializeSessionData($input); $this->assertEquals($expected, $result); } - /** - * @dataProvider dataProvider - * @param $object - * @param $serialize - * @throws JwtWrapperException - */ + #[DataProvider('dataProvider')] public function testReadWrite($object, $serialize) { $this->object->write("SESSID", $serialize);