Skip to content

Commit

Permalink
fix windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria committed Aug 7, 2024
1 parent 3b6f1e4 commit 82f85ad
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 10 deletions.
6 changes: 3 additions & 3 deletions config/verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

return [
'validation' => [
ValidateHash::class => '685b1e0749627c537af1bcdbb0ffa3683c2fbb5a',
ValidateSignature::class => '9518e1d258259cc0c95704a924b5ecdce8161bb2',
Verify::class => '2e5ddaf589b6f9ea30ffd4b3a30e0a48a3c7fb2d',
ValidateHash::class => 'c34da4a4523e54f303c23cd22eaf252f74ed7965',
ValidateSignature::class => 'a3d4081247b4f56c8aeb7c6b192415700e27acc0',
Verify::class => 'cda79b50522e9189aa928a5f471ebc20a049db76',
VerifySupporterStatus::class => '6358c45ed0414c1e2697e0881238659fa6221bed',
VerifyServiceProvider::class => '927a8f3c811fc82cb8a0ac2667c06e7d292c3633',
],
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/ValidateHash.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use LycheeVerify\Contract\Validator;

/**
* This is the valitaor for supporters.
* This is the validator for supporters.
*/
class ValidateHash implements Validator
{
Expand Down
2 changes: 1 addition & 1 deletion src/Validators/ValidateSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use function Safe\openssl_verify;

/**
* This is the check for the premium users.
* This is the validator for the premium users.
*/
class ValidateSignature implements Validator
{
Expand Down
11 changes: 9 additions & 2 deletions src/Verify.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use LycheeVerify\Validators\ValidateHash;
use LycheeVerify\Validators\ValidateSignature;
use function Safe\json_encode;
use function Safe\sha1_file;
use function Safe\preg_replace;

class Verify
{
Expand Down Expand Up @@ -123,7 +123,14 @@ public function validate(): bool

foreach ($checks as $class => $value) {
$file = (new \ReflectionClass($class))->getFileName();
if ($file === false || !file_exists($file) || sha1_file($file) !== $value) {
if ($file === false || !file_exists($file)) {
return false;
}
// this necessary because stupid line endings in Windows.
/** @var string $content */
$content = file_get_contents($file); // @phpstan-ignore-line
$content = preg_replace('~\R~u', "\n", $content);
if (sha1($content) !== $value) {
return false;
}
}
Expand Down
10 changes: 7 additions & 3 deletions tests/Verify/VerifyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use LycheeVerify\Tests\Constants;
use LycheeVerify\Tests\TestCase;
use LycheeVerify\Verify;
use function Safe\sha1_file;
use function Safe\preg_replace;

class VerifyTest extends TestCase
{
Expand Down Expand Up @@ -65,8 +65,12 @@ public function testVerifyValidate(): void
if ($file === false || !file_exists($file)) {
self::fail(sprintf('Validation failed for %s: file not found', $class));
}
if (sha1_file($file) !== $value) {
self::fail(sprintf("Validation failed for %s: expected '%s'", $class, sha1_file($file)));
// this necessary because stupid line endings in Windows.
/** @var string $content */
$content = file_get_contents($file); // @phpstan-ignore-line
$content = preg_replace('~\R~u', "\n", $content);
if (sha1($content) !== $value) {
self::fail(sprintf("Validation failed for %s: expected '%s'", $class, sha1($content)));
}
}

Expand Down

0 comments on commit 82f85ad

Please sign in to comment.