Skip to content

Commit

Permalink
Merge pull request #1447 from hafezdivandari/fix-windows
Browse files Browse the repository at this point in the history
Fix key files permission on Windows
  • Loading branch information
Sephster authored Dec 20, 2024
2 parents 1bc1185 + e0c44b0 commit 70dc310
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
fail-fast: false
matrix:
php: [8.1, 8.2, 8.3, 8.4]
os: [ubuntu-22.04]
os: [ubuntu-latest, windows-latest]
stability: [prefer-lowest, prefer-stable]

runs-on: ${{ matrix.os }}

name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
name: PHP ${{ matrix.php }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
Expand All @@ -29,7 +29,7 @@ jobs:
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip
extensions: dom, curl, libxml, mbstring, sodium, zip
coverage: pcov

- name: Install dependencies
Expand Down
2 changes: 1 addition & 1 deletion src/CryptKey.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(string $keyPath, protected ?string $passPhrase = nul
throw new LogicException('Invalid key supplied');
}

if ($keyPermissionsCheck === true) {
if ($keyPermissionsCheck === true && PHP_OS_FAMILY !== 'Windows') {
// Verify the permissions of the key
$keyPathPerms = decoct(fileperms($this->keyPath) & 0777);
if (in_array($keyPathPerms, ['400', '440', '600', '640', '660'], true) === false) {
Expand Down
9 changes: 9 additions & 0 deletions tests/AuthorizationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public function setUp(): void
chmod(__DIR__ . '/Stubs/private.key.crlf', 0600);
}

public function testKeyPermissions(): void
{
$permission = PHP_OS_FAMILY === 'Windows' ? '666' : '600';

self::assertSame($permission, decoct(fileperms(__DIR__ . '/Stubs/private.key') & 0777));
self::assertSame($permission, decoct(fileperms(__DIR__ . '/Stubs/public.key') & 0777));
self::assertSame($permission, decoct(fileperms(__DIR__ . '/Stubs/private.key.crlf') & 0777));
}

public function testGrantTypeGetsEnabled(): void
{
$server = new AuthorizationServer(
Expand Down

0 comments on commit 70dc310

Please sign in to comment.