Skip to content

Commit 42bcc2c

Browse files
Merge pull request #62 from paragonie/test-improvements
Test improvements (+PHP 8.5)
2 parents db38ff9 + fe952a9 commit 42bcc2c

29 files changed

Lines changed: 636 additions & 95 deletions

.gitattributes

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html
33

44
# This way, the files would be available in the repository but it would not be downloaded when the package is required by another project.
5-
/.github export-ignore
6-
/.gitignore export-ignore
7-
/.gitattributes export-ignore
8-
/tests export-ignore
9-
/phpunit.xml.dist export-ignore
10-
/psalm.xml export-ignore
5+
/.github export-ignore
6+
/.gitignore export-ignore
7+
/.gitattributes export-ignore
8+
/fuzzing export-ignore
9+
/tests export-ignore
10+
/infection.json.dist export-ignore
11+
/phpunit.xml.dist export-ignore
12+
/psalm.xml export-ignore

.github/workflows/ci.yml

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ name: CI
33
on: [push, pull_request]
44

55
jobs:
6-
moderate-modern:
7-
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }}
6+
with-sodium:
7+
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} with ext-sodium
88
runs-on: ${{ matrix.operating-system }}
99
strategy:
1010
matrix:
1111
operating-system: ['ubuntu-latest']
12-
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4']
12+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
1313

1414
steps:
1515
- name: Checkout
@@ -28,3 +28,29 @@ jobs:
2828

2929
- name: PHPUnit tests
3030
run: vendor/bin/phpunit
31+
32+
without-sodium:
33+
name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} without ext-sodium
34+
runs-on: ${{ matrix.operating-system }}
35+
strategy:
36+
matrix:
37+
operating-system: ['ubuntu-latest']
38+
php-versions: ['8.0', '8.1', '8.2', '8.3', '8.4', '8.5']
39+
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php-versions }}
48+
extensions: mbstring, intl
49+
ini-values: error_reporting=-1, display_errors=On
50+
coverage: none
51+
52+
- name: Install Composer dependencies
53+
uses: "ramsey/composer-install@v3"
54+
55+
- name: PHPUnit tests
56+
run: vendor/bin/phpunit

.github/workflows/fuzz.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Fuzz Testing
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
psalm:
7+
name: PHP-Fuzzer on PHP ${{ matrix.php-versions }}
8+
runs-on: ${{ matrix.operating-system }}
9+
strategy:
10+
matrix:
11+
operating-system: ['ubuntu-latest']
12+
php-versions: ['8.4']
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Setup PHP
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: ${{ matrix.php-versions }}
21+
coverage: none
22+
23+
- name: Install Composer dependencies
24+
uses: "ramsey/composer-install@v3"
25+
26+
- name: Fuzz Tests
27+
run: vendor/bin/php-fuzzer --max-runs 100000 fuzz fuzzing/FuzzConstTime.php

.github/workflows/mutation.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Mutation Testing
2+
3+
on:
4+
create:
5+
tags:
6+
- v*
7+
8+
jobs:
9+
psalm:
10+
name: Infection on PHP ${{ matrix.php-versions }}
11+
runs-on: ${{ matrix.operating-system }}
12+
strategy:
13+
matrix:
14+
operating-system: ['ubuntu-latest']
15+
php-versions: ['8.3']
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
20+
- name: Setup PHP
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-versions }}
24+
coverage: pcov
25+
26+
- name: Install Composer dependencies
27+
uses: "ramsey/composer-install@v3"
28+
29+
- name: Mutation Tests
30+
run: composer mutation-test

.github/workflows/psalm.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
strategy:
1010
matrix:
1111
operating-system: ['ubuntu-latest']
12-
php-versions: ['8.3']
12+
php-versions: ['8.4']
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
@@ -18,13 +18,16 @@ jobs:
1818
uses: shivammathur/setup-php@v2
1919
with:
2020
php-version: ${{ matrix.php-versions }}
21-
tools: psalm:4
21+
tools: psalm:6
2222
coverage: none
2323

2424
- name: Install Composer dependencies
2525
uses: "ramsey/composer-install@v3"
2626
with:
2727
composer-options: --no-dev
2828

29+
- name: Use New psalm.xml
30+
run: mv psalm.xml psalm-old.xml && mv psalm-new.xml psalm.xml
31+
2932
- name: Static Analysis
3033
run: psalm

composer.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,10 @@
4040
"php": "^8"
4141
},
4242
"require-dev": {
43-
"phpunit/phpunit": "^9",
44-
"vimeo/psalm": "^4|^5"
43+
"infection/infection": "^0",
44+
"nikic/php-fuzzer": "^0",
45+
"phpunit/phpunit": "^9|^10|^11",
46+
"vimeo/psalm": "^4|^5|^6"
4547
},
4648
"autoload": {
4749
"psr-4": {
@@ -52,5 +54,11 @@
5254
"psr-4": {
5355
"ParagonIE\\ConstantTime\\Tests\\": "tests/"
5456
}
57+
},
58+
"config": {
59+
"process-timeout": 0,
60+
"allow-plugins": {
61+
"infection/extension-installer": true
62+
}
5563
}
5664
}

fuzzing/FuzzConstTime.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
use ParagonIE\ConstantTime\{Base32,
4+
Base32Hex,
5+
Base64,
6+
Base64UrlSafe,
7+
Base64DotSlash,
8+
Base64DotSlashOrdered,
9+
EncoderInterface,
10+
Hex};
11+
12+
require __DIR__ . '/../vendor/autoload.php';
13+
14+
/** @var PhpFuzzer\Config $config */
15+
$config->setTarget(function(string $input) {
16+
static $targets = [
17+
Base32::class,
18+
Base32Hex::class,
19+
Base64::class,
20+
Base64UrlSafe::class,
21+
Base64DotSlash::class,
22+
Base64DotSlashOrdered::class,
23+
Hex::class,
24+
];
25+
26+
/** @var class-string<EncoderInterface> $target */
27+
$target = $targets[array_rand($targets)];
28+
$out = $target::decode($input, true);
29+
$re = $target::encode($out);
30+
if ($re !== $input) {
31+
throw new Exception('invalid');
32+
}
33+
});

infection.json.dist

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"source": {
3+
"directories": [
4+
"src"
5+
]
6+
},
7+
"threads": "max",
8+
"minCoveredMsi": 80,
9+
"phpUnit": {
10+
"configDir": "."
11+
},
12+
"mutators": {
13+
"@default": true
14+
},
15+
"logs": {
16+
"text": "infection.log"
17+
}
18+
}

phpunit.xml.dist

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnError="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
3-
<coverage processUncoveredFiles="true">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
colors="true"
5+
>
6+
<source restrictNotices="true" restrictWarnings="true">
47
<include>
5-
<directory suffix=".php">./src</directory>
8+
<directory>src</directory>
69
</include>
7-
</coverage>
10+
</source>
811
<testsuites>
912
<testsuite name="Constant Time Encoding Test Suite">
1013
<directory suffix="Test.php">./tests</directory>

psalm-new.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
useDocblockTypes="true"
4+
>
5+
<projectFiles>
6+
<directory name="src" />
7+
<ignoreFiles>
8+
<directory name="tests" />
9+
<directory name="vendor" />
10+
</ignoreFiles>
11+
</projectFiles>
12+
<issueHandlers>
13+
<InvalidAttribute errorLevel="info" />
14+
<PossiblyUnusedMethod errorLevel="info" />
15+
<PossiblyUnusedReturnValue errorLevel="info" />
16+
<UnusedClass errorLevel="info" />
17+
<UnnecessaryVarAnnotation errorLevel="info" />
18+
</issueHandlers>
19+
</psalm>

0 commit comments

Comments
 (0)