-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUriTest.php
More file actions
140 lines (119 loc) · 3.84 KB
/
UriTest.php
File metadata and controls
140 lines (119 loc) · 3.84 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
declare(strict_types=1);
namespace Tests\Unit\Support;
use PHPUnit\Framework\TestCase;
use Hyperf\OpenTelemetry\Support\Uri;
/**
* @internal
*/
class UriTest extends TestCase
{
public function testSanitizeE2EId()
{
$uri = '/E60701190202409271154DY52JQB76B5/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{e2e_id}', $result);
}
public function testSanitizeSha1()
{
$uri = '/da39a3ee5e6b4b0d3255bfef95601890afd80709/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{sha1}', $result);
}
public function testSanitizeUuid()
{
$uri = '/123e4567-e89b-12d3-a456-426614174000/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
public function testSanitizeLicensePlate()
{
$uri = '/ABC1A23/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{license_plate}', $result);
}
public function testSanitizeOid()
{
$uri = '/abcdef1234567890abcdef12/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{oid}', $result);
}
public function testSanitizeDate()
{
$uri = '/2024-06-01/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{date}', $result);
}
public function testSanitizeNumber()
{
$uri = '/123456789/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{number}', $result);
}
public function testSanitizeMultiplePatterns()
{
$uri = '/E60701190202409271154DY52JQB76B5/2024-06-01/123e4567-e89b-12d3-a456-426614174000/123456789/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{e2e_id}/', $result);
$this->assertStringContainsString('/{date}/', $result);
$this->assertStringContainsString('/{uuid}/', $result);
$this->assertStringContainsString('/{number}', $result);
}
public function testSanitizeWithCustomMask()
{
$uri = '/custom123/';
$mask = [
'/custom\d+/' => '/{custom}',
];
$result = Uri::sanitize($uri, $mask);
$this->assertStringContainsString('/{custom}', $result);
}
public function testSanitizeNoMatch()
{
$uri = '/no-match/';
$result = Uri::sanitize($uri);
$this->assertSame('/no-match/', $result);
}
public function testSanitizeUriWithoutLeadingSlash()
{
$uri = '123456789';
$result = Uri::sanitize($uri);
$this->assertSame('/{number}', $result);
}
public function testSanitizeEmptyUri()
{
$uri = '';
$result = Uri::sanitize($uri);
$this->assertSame('/', $result);
}
public function testSanitizeUuidV1ToV4()
{
$uri = '/5c4f7ab3-7849-4422-a262-cd1bfc5ae7ae/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
public function testSanitizeUuidV1ToV5()
{
$uri = '/123e4567-e89b-12d3-a456-426614174000/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
public function testSanitizeUuidV6()
{
$uri = '/01000000-9f9e-6094-2a9d-08ddf52351e2/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
public function testSanitizeUuidV7()
{
$uri = '/01890f28-54c2-7d11-bc99-9bb9d1a9e9af/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
public function testSanitizeUuidV8()
{
$uri = '/ffffffff-ffff-8fff-9fff-ffffffffffff/';
$result = Uri::sanitize($uri);
$this->assertStringContainsString('/{uuid}', $result);
}
}