Skip to content

Commit

Permalink
Merge pull request #23 from MyParcelCOM/feature/php82
Browse files Browse the repository at this point in the history
🔧 PHP 8.2
  • Loading branch information
zwaans authored Apr 18, 2024
2 parents ed2992d + e4e0600 commit 0043b3a
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 51 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,12 @@ jobs:
- name: Composer
uses: php-actions/composer@v6
with:
php_version: 8.0
php_version: 8.2

- name: PHPUnit
uses: php-actions/phpunit@v3
with:
bootstrap: vendor/autoload.php
test_suffix: Test.php
php_extensions: xdebug
args: --no-coverage
php_version: 8.2
configuration: phpunit.xml
coverage_text: true
env:
XDEBUG_MODE: coverage
test_suffix: Test.php
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"name": "myparcelcom/auth-module",
"description": "Package for validating a JWT token and checking the contained scopes",
"homepage": "https://www.myparcel.com",
"type": "library",
"require": {
"php": ">=8.0",
"lcobucci/jwt": ">=4.0",
"php": ">=8.2",
"lcobucci/jwt": ">=5.0",
"myclabs/php-enum": ">=1.7",
"myparcelcom/json-api": "^3.0"
},
"require-dev": {
"ext-openssl": "*",
"mockery/mockery": "^1.4",
"phpunit/phpunit": ">=9.5",
"mockery/mockery": "^1.5",
"phpunit/phpunit": "^11.0",
"roave/security-advisories": "dev-latest",
"squizlabs/php_codesniffer": "^3.3"
"squizlabs/php_codesniffer": "^3.7"
},
"autoload": {
"psr-4": {
Expand All @@ -27,8 +28,8 @@
},
"scripts": {
"test": "vendor/bin/phpunit --no-coverage",
"check-style": "vendor/bin/phpcs -p --standard=PSR12 --exclude=PSR2.ControlStructures.ControlStructureSpacing --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --warning-severity=6 app tests database/factories",
"fix-style": "vendor/bin/phpcbf -p --standard=PSR12 --exclude=PSR2.ControlStructures.ControlStructureSpacing --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --warning-severity=6 app tests database/factories"
"check-style": "vendor/bin/phpcs -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --warning-severity=6 src tests",
"fix-style": "vendor/bin/phpcbf -p --standard=PSR12 --runtime-set ignore_errors_on_exit 1 --runtime-set ignore_warnings_on_exit 1 --warning-severity=6 src tests"
},
"extra": {
"laravel": {
Expand Down
19 changes: 10 additions & 9 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions tests/CheckForAnyScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,20 @@ protected function setUp(): void
$this->scopeChecker = new CheckForAnyScope();
}

/** @test */
public function testHandle(): void
{
$this->scopeChecker->setAuthenticator($this->createAuthenticatorReturningScopes(['test-scope']));

$this->assertTrue($this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope'));
}

/** @test */
public function testHandleWithOnlyOneScopeExisting(): void
{
$this->scopeChecker->setAuthenticator($this->createAuthenticatorReturningScopes(['test-scope']));

$this->assertTrue($this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope', 'test-scope2'));
}

/** @test */
public function testHandleWithMissingScopeGivesMissingScopeExceptionWhenMissingOne(): void
{
$this->expectException(MissingScopeException::class);
Expand All @@ -63,7 +60,6 @@ public function testHandleWithMissingScopeGivesMissingScopeExceptionWhenMissingO
$this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope');
}

/** @test */
public function testHandleWithMultipleScopes(): void
{
$this->scopeChecker->setAuthenticator($this->createAuthenticatorReturningScopes([
Expand Down
8 changes: 1 addition & 7 deletions tests/CheckForScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,18 @@ protected function setUp(): void
parent::setUp();

$this->generateKeys();
$this->trueClosure = function () {
return true;
};
$this->trueClosure = fn () => true;
$this->request = $this->createAuthorizationRequest();
$this->scopeChecker = new CheckForScopes();
}

/** @test */
public function testHandle(): void
{
$this->scopeChecker->setAuthenticator($this->createAuthenticatorReturningScopes(['test-scope']));

$this->assertTrue($this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope'));
}

/** @test */
public function testHandleWithMissingScopesGivesMissingScopeExceptionWhenMissingOnlyOne(): void
{
$this->expectException(MissingScopeException::class);
Expand All @@ -52,7 +48,6 @@ public function testHandleWithMissingScopesGivesMissingScopeExceptionWhenMissing
$this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope', 'test-scope2');
}

/** @test */
public function testHandleWithMissingScopeGivesMissingScopeExceptionWhenMissingOne(): void
{
$this->expectException(MissingScopeException::class);
Expand All @@ -64,7 +59,6 @@ public function testHandleWithMissingScopeGivesMissingScopeExceptionWhenMissingO
$this->scopeChecker->handle($this->request, $this->trueClosure, 'test-scope');
}

/** @test */
public function testHandleWithMultipleScopes(): void
{
$this->scopeChecker->setAuthenticator($this->createAuthenticatorReturningScopes([
Expand Down
9 changes: 0 additions & 9 deletions tests/JwtRequestAuthenticatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ protected function setUp(): void
->setPublicKey($this->publicKey);
}

/** @test */
public function testAuthenticate(): void
{
$authorizationHeader = 'Bearer ' . $this->createTokenString([], null, 'some-user-id', []);
Expand All @@ -41,7 +40,6 @@ public function testAuthenticate(): void
$this->assertEquals('some-user-id', $token->claims()->get('user_id'));
}

/** @test */
public function testAuthenticateWithQueryParameter(): void
{
$request = Mockery::mock(Request::class, [
Expand All @@ -54,7 +52,6 @@ public function testAuthenticateWithQueryParameter(): void
$this->assertEquals('some-user-id', $token->claims()->get('user_id'));
}

/** @test */
public function testAuthenticateWithInvalidKey(): void
{
$this->authenticator->setPublicKey('');
Expand All @@ -65,7 +62,6 @@ public function testAuthenticateWithInvalidKey(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testAuthenticateWithInvalidToken(): void
{
$authorizationHeader = 'Bearer ' . $this->createTokenString([], null, 'some-user-id', []);
Expand All @@ -76,7 +72,6 @@ public function testAuthenticateWithInvalidToken(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testAuthenticateWithInvalidSignature(): void
{
$privateKeyResource = openssl_pkey_new(['private_key_bits' => 2048]);
Expand All @@ -90,7 +85,6 @@ public function testAuthenticateWithInvalidSignature(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testAuthenticateWithExpiredToken(): void
{
$authorizationHeader = 'Bearer ' . $this->createTokenString([], time() - 100, 'some-user-id', []);
Expand All @@ -100,7 +94,6 @@ public function testAuthenticateWithExpiredToken(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testAccessTokenWithRequestWithoutAuthorizationHeader(): void
{
$request = Mockery::mock(Request::class, ['header' => null, 'has' => false]);
Expand All @@ -109,7 +102,6 @@ public function testAccessTokenWithRequestWithoutAuthorizationHeader(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testAccessTokenParsing(): void
{
$request = Mockery::mock(Request::class, ['header' => 'r.i.p', 'has' => false]);
Expand All @@ -118,7 +110,6 @@ public function testAccessTokenParsing(): void
$this->authenticator->authenticate($request);
}

/** @test */
public function testGetPublicKeyExceptionWithoutKey(): void
{
$this->authenticator = new JwtRequestAuthenticator();
Expand Down
6 changes: 0 additions & 6 deletions tests/PublicKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ protected function setUp(): void
$this->key->setPath($tempFile);
}

/** @test */
public function testGetKeyString(): void
{
$keyString = $this->key->getKeyString();
Expand All @@ -35,7 +34,6 @@ public function testGetKeyString(): void
$this->assertEquals('this-is-an-oauth-key', $keyString);
}

/** @test */
public function testGetKeyStringWithoutSsl(): void
{
$keyString = $this->key->setVerifySsl(false)->getKeyString();
Expand All @@ -44,13 +42,11 @@ public function testGetKeyStringWithoutSsl(): void
$this->assertEquals('this-is-an-oauth-key', $keyString);
}

/** @test */
public function testToString(): void
{
$this->assertEquals($this->key->getKeyString(), (string) $this->key);
}

/** @test */
public function testCache(): void
{
$publicKey = $this->key->setCache(new CacheMock());
Expand All @@ -76,7 +72,6 @@ public function testCache(): void
);
}

/** @test */
public function testSetPath(): void
{
$publicKey = new PublicKey();
Expand All @@ -98,7 +93,6 @@ public function testSetPath(): void
);
}

/** @test */
public function testUnSetPath(): void
{
$publicKey = new PublicKey();
Expand Down
2 changes: 0 additions & 2 deletions tests/ScopeCheckerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ protected function setUp(): void
$this->scopeChecker = new ScopeChecker();
}

/** @test */
public function testTokenCan(): void
{
$request = $this->createAuthorizationRequest();
Expand All @@ -37,7 +36,6 @@ public function testTokenCan(): void
$this->assertTrue($result);
}

/** @test */
public function testTokenCanNot(): void
{
$request = $this->createAuthorizationRequest();
Expand Down

0 comments on commit 0043b3a

Please sign in to comment.