Repository navigation
Expand file tree
/
Copy pathUriSanitizerTest.php
More file actions
74 lines (66 loc) · 2.94 KB
/
Copy pathUriSanitizerTest.php
File metadata and controls
74 lines (66 loc) · 2.94 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
namespace OpenTelemetry\Tests\Instrumentation\HttpConfig\Unit;
use League\Uri\Http;
use OpenTelemetry\Contrib\Instrumentation\HttpConfig\UriSanitizer\RedactSensitiveQueryStringValuesSanitizer;
use OpenTelemetry\Contrib\Instrumentation\HttpConfig\UriSanitizer\RedactUsernamePasswordSanitizer;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\UriInterface;
final class UriSanitizerTest extends TestCase
{
#[DataProvider('redactUsernamePasswordProvider')]
public function testRedactUsernamePassword(UriInterface $uri, UriInterface $expected): void
{
$sanitizer = new RedactUsernamePasswordSanitizer();
$this->assertEquals($expected, $sanitizer->sanitize($uri));
}
public static function redactUsernamePasswordProvider(): iterable
{
yield 'no userinfo' => [
Http::new('https://example.com'),
Http::new('https://example.com'),
];
yield 'username only' => [
Http::new('https://user@example.com'),
Http::new('https://REDACTED@example.com'),
];
yield 'username+password' => [
Http::new('https://user:pass@example.com'),
Http::new('https://REDACTED:REDACTED@example.com'),
];
}
#[DataProvider('redactSensitiveQueryStringValuesProvider')]
public function testRedactSensitiveQueryStringValues(UriInterface $uri, UriInterface $expected): void
{
$sanitizer = new RedactSensitiveQueryStringValuesSanitizer(['secret', 'pass', 'passwd']);
$this->assertEquals($expected, $sanitizer->sanitize($uri));
}
public static function redactSensitiveQueryStringValuesProvider(): iterable
{
yield 'no query string' => [
Http::new('https://example.com'),
Http::new('https://example.com'),
];
yield 'non-sensitive query string' => [
Http::new('https://example.com?key=value'),
Http::new('https://example.com?key=value'),
];
yield 'sensitive query string' => [
Http::new('https://example.com?secret=value'),
Http::new('https://example.com?secret=REDACTED'),
];
yield 'multiple sensitive query strings' => [
Http::new('https://example.com?secret=value&pass=test'),
Http::new('https://example.com?secret=REDACTED&pass=REDACTED'),
];
yield 'multiple sensitive query strings with values longer than "REDACTED"' => [
Http::new('https://example.com?secret=value0123456789&pass=test0123456789'),
Http::new('https://example.com?secret=REDACTED&pass=REDACTED'),
];
yield 'mixed sensitive and non-sensitive query string' => [
Http::new('https://example.com?secret=value&key=value&pass=1234×tamp=123456789'),
Http::new('https://example.com?secret=REDACTED&key=value&pass=REDACTED×tamp=123456789'),
];
}
}