Skip to content

Commit

Permalink
fix: KeyDumpSigner for PHP < 8
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickbussmann committed May 17, 2024
1 parent d5048c7 commit 6b38a21
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 41 deletions.
82 changes: 42 additions & 40 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
name: 'CI'
name: CI

on:
pull_request:
push:
branches:
- 'main'
- main

env:
COMPOSER_ROOT_VERSION: '1.99.99'

jobs:
lint:
name: 'Lint'
runs-on: 'ubuntu-latest'
name: Lint
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: 'none'
ini-values: 'memory_limit=-1'
tools: 'composer:v2'
- uses: 'ramsey/composer-install@v1'
coverage: none
ini-values: memory_limit=-1
tools: composer:v2
- uses: ramsey/composer-install@v3
- name: 'Lint the PHP source code'
run: './vendor/bin/parallel-lint src test'
run: ./vendor/bin/parallel-lint src test

coding-standards:
name: 'Coding Standards'
runs-on: 'ubuntu-latest'
name: Coding Standards
runs-on: ubuntu-latest
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
coverage: 'none'
ini-values: 'memory_limit=-1'
tools: 'composer:v2'
- uses: 'ramsey/composer-install@v1'
- name: 'Check coding standards'
run: './vendor/bin/phpcs src --standard=psr2 -sp --colors'
coverage: none
ini-values: memory_limit=-1
tools: composer:v2
- uses: ramsey/composer-install@v3
- name: Check coding standards
run: ./vendor/bin/phpcs src --standard=psr2 -sp --colors

unit-tests:
name: 'Unit Tests'
runs-on: 'ubuntu-latest'
name: Unit Tests
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
strategy:
fail-fast: false
Expand All @@ -55,30 +55,32 @@ jobs:
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.4'
dependencies:
- 'lowest'
- 'highest'
- lowest
- highest
experimental:
- false
include:
- php-version: '8.1'
experimental: true
composer-options: '--ignore-platform-reqs'
- php-version: '8.3'
experimental: false
steps:
- uses: 'actions/checkout@v2'
- uses: 'shivammathur/setup-php@v2'
- uses: actions/checkout@v4
- uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-version }}'
coverage: 'pcov'
ini-values: 'memory_limit=-1'
tools: 'composer:v2'
- name: 'Prepare for tests'
run: 'mkdir -p build/logs'
- uses: 'ramsey/composer-install@v1'
coverage: pcov
ini-values: memory_limit=-1
tools: composer:v2
- name: Prepare for tests
run: mkdir -p build/logs
- uses: ramsey/composer-install@v3
with:
dependency-versions: '${{ matrix.dependencies }}'
composer-options: '${{ matrix.composer-options }}'
- name: 'Run unit tests'
run: './vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml'
- name: 'Publish coverage report to Codecov'
uses: 'codecov/codecov-action@v1'
- name: Run unit tests
run: ./vendor/bin/phpunit --colors=always --coverage-clover build/logs/clover.xml
- name: Publish coverage report to Codecov
uses: codecov/codecov-action@v4
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"phpunit/phpunit": "^5.7 || ^6.0 || ^9.3",
"mockery/mockery": "^1.3",
"php-parallel-lint/php-parallel-lint": "^1.3",
"squizlabs/php_codesniffer": "^2.3 || ^3.0"
"squizlabs/php_codesniffer": "^2.3 || ^3.0",
"composer/semver": "^3.0"
},
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./test/</directory>
<exclude>./test/ext/</exclude>
</testsuite>
</testsuites>
</phpunit>
29 changes: 29 additions & 0 deletions test/ext/KeyDumpSigner5.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace League\OAuth2\Client\Test;

use Lcobucci\JWT\Signature;
use Lcobucci\JWT\Signer;

final class KeyDumpSigner implements Signer
{
public function getAlgorithmId()
{
return 'keydump';
}

public function modifyHeader(array &$headers)
{
$headers['alg'] = $this->getAlgorithmId();
}

public function verify($expected, $payload, $key)
{
return $expected === $key->contents();
}

public function sign($payload, $key)
{
return new Signature($key->contents());
}
}
File renamed without changes.
12 changes: 12 additions & 0 deletions test/src/KeyDumpSignerLoader.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace League\OAuth2\Client\Test;

use Composer\InstalledVersions;
use Composer\Semver\VersionParser;

if (!InstalledVersions::satisfies(new VersionParser(), 'lcobucci/jwt', '^1 || ^2 || ^3')) {
require_once __DIR__ . '/../ext/KeyDumpSigner8.php';
} else {
require_once __DIR__ . '/../ext/KeyDumpSigner5.php';
}

0 comments on commit 6b38a21

Please sign in to comment.