Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/diffusion/request/__tests__/DiffusionURITestCase.php
13401 views
1
<?php
2
3
final class DiffusionURITestCase extends PhutilTestCase {
4
5
public function testBlobDecode() {
6
$map = array(
7
// This is a basic blob.
8
'branch/path.ext;abc$3' => array(
9
'branch' => 'branch',
10
'path' => 'path.ext',
11
'commit' => 'abc',
12
'line' => '3',
13
),
14
'branch/path.ext$3' => array(
15
'branch' => 'branch',
16
'path' => 'path.ext',
17
'line' => '3',
18
),
19
'branch/money;;/$$100' => array(
20
'branch' => 'branch',
21
'path' => 'money;/$100',
22
),
23
'a%252Fb/' => array(
24
'branch' => 'a/b',
25
),
26
'branch/path/;Version-1_0_0' => array(
27
'branch' => 'branch',
28
'path' => 'path/',
29
'commit' => 'Version-1_0_0',
30
),
31
'branch/path/;$$moneytag$$' => array(
32
'branch' => 'branch',
33
'path' => 'path/',
34
'commit' => '$moneytag$',
35
),
36
'branch/path/semicolon;;;;;$$;;semicolon;;$$$$$100' => array(
37
'branch' => 'branch',
38
'path' => 'path/semicolon;;',
39
'commit' => '$;;semicolon;;$$',
40
'line' => '100',
41
),
42
'branch/path.ext;abc$3-5,7-12,14' => array(
43
'branch' => 'branch',
44
'path' => 'path.ext',
45
'commit' => 'abc',
46
'line' => '3-5,7-12,14',
47
),
48
);
49
50
foreach ($map as $input => $expect) {
51
52
// Simulate decode effect of the webserver.
53
$input = rawurldecode($input);
54
55
$expect = $expect + array(
56
'branch' => null,
57
'path' => null,
58
'commit' => null,
59
'line' => null,
60
);
61
$expect = array_select_keys(
62
$expect,
63
array('branch', 'path', 'commit', 'line'));
64
65
$actual = $this->parseBlob($input);
66
67
$this->assertEqual(
68
$expect,
69
$actual,
70
pht("Parsing '%s'", $input));
71
}
72
}
73
74
public function testBlobDecodeFail() {
75
$this->tryTestCaseMap(
76
array(
77
'branch/path/../../../secrets/secrets.key' => false,
78
),
79
array($this, 'parseBlob'));
80
}
81
82
public function parseBlob($blob) {
83
return DiffusionRequest::parseRequestBlob(
84
$blob,
85
$supports_branches = true);
86
}
87
88
public function testURIGeneration() {
89
$actor = PhabricatorUser::getOmnipotentUser();
90
91
$repository = PhabricatorRepository::initializeNewRepository($actor)
92
->setCallsign('A')
93
->makeEphemeral();
94
95
$map = array(
96
'/diffusion/A/browse/branch/path.ext;abc$1' => array(
97
'action' => 'browse',
98
'branch' => 'branch',
99
'path' => 'path.ext',
100
'commit' => 'abc',
101
'line' => '1',
102
),
103
'/diffusion/A/browse/a%252Fb/path.ext' => array(
104
'action' => 'browse',
105
'branch' => 'a/b',
106
'path' => 'path.ext',
107
),
108
'/diffusion/A/browse/%2B/%20%21' => array(
109
'action' => 'browse',
110
'path' => '+/ !',
111
),
112
'/diffusion/A/browse/money/%24%24100$2' => array(
113
'action' => 'browse',
114
'path' => 'money/$100',
115
'line' => '2',
116
),
117
'/diffusion/A/browse/path/to/file.ext?view=things' => array(
118
'action' => 'browse',
119
'path' => 'path/to/file.ext',
120
'params' => array(
121
'view' => 'things',
122
),
123
),
124
'/diffusion/A/repository/master/' => array(
125
'action' => 'branch',
126
'branch' => 'master',
127
),
128
'path/to/file.ext;abc' => array(
129
'action' => 'rendering-ref',
130
'path' => 'path/to/file.ext',
131
'commit' => 'abc',
132
),
133
'/diffusion/A/browse/branch/path.ext$3-5%2C7-12%2C14' => array(
134
'action' => 'browse',
135
'branch' => 'branch',
136
'path' => 'path.ext',
137
'line' => '3-5,7-12,14',
138
),
139
);
140
141
foreach ($map as $expect => $input) {
142
$actual = $repository->generateURI($input);
143
$this->assertEqual($expect, (string)$actual);
144
}
145
}
146
147
}
148
149