-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidatorTest.php
More file actions
54 lines (45 loc) · 2.02 KB
/
ValidatorTest.php
File metadata and controls
54 lines (45 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
declare(strict_types=1);
namespace WonderNetwork\SshPubkeyPayloadVerification;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
final class ValidatorTest extends TestCase {
#[DataProvider('signatures')]
public function testValidate(string $signature): void {
$sut = ValidatorBuilder::start()
->withKnownHostsFile(__DIR__.'/Resources/127.0.0.1.keyscan')
->build();
$sut->validate('ssh://127.0.0.1:2022', 'file', "Hello World!\n", $signature);
$this->expectNotToPerformAssertions();
}
public function testFailsWithoutProperPublicKey(): void {
$signature = \file_get_contents(__DIR__.'/Resources/hello-world.rsa.sig')
?: throw new \RuntimeException("Problem reading signature file");
$sut = ValidatorBuilder::start()
->withKnownHostsFile(__DIR__.'/Resources/127.0.0.1-ed25519.keyscan')
->build();
$this->expectException(KeyMismatchException::class);
$sut->validate('ssh://127.0.0.1:2022', 'file', "Hello World!\n", $signature);
}
public function testFailsWhenNamespaceMismatched(): void {
$signature = \file_get_contents(__DIR__.'/Resources/hello-world.ecdsa.sig')
?: throw new \RuntimeException("Problem reading signature file");
$sut = ValidatorBuilder::start()
->withKnownHostsFile(__DIR__.'/Resources/127.0.0.1-ecdsa.keyscan')
->build();
$this->expectException(NamespaceMismatchException::class);
$sut->validate('ssh://127.0.0.1:2022', 'email', "Hello World!\n", $signature);
}
/** @return iterable<mixed> */
public static function signatures(): iterable {
yield 'rsa' => [
\file_get_contents(__DIR__.'/Resources/hello-world.rsa.sig'),
];
yield 'ed25519' => [
\file_get_contents(__DIR__.'/Resources/hello-world.ed.sig'),
];
yield 'ecdsa' => [
\file_get_contents(__DIR__.'/Resources/hello-world.ecdsa.sig'),
];
}
}