This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /* |
||
3 | * Copyright (c) STMicroelectronics, 2011. All Rights Reserved. |
||
4 | * |
||
5 | * This file is a part of Codendi. |
||
6 | * |
||
7 | * Codendi is free software; you can redistribute it and/or modify |
||
8 | * it under the terms of the GNU General Public License as published by |
||
9 | * the Free Software Foundation; either version 2 of the License, or |
||
10 | * (at your option) any later version. |
||
11 | * |
||
12 | * Codendi is distributed in the hope that it will be useful, |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
15 | * GNU General Public License for more details. |
||
16 | * |
||
17 | * You should have received a copy of the GNU General Public License |
||
18 | * along with Codendi; if not, write to the Free Software |
||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
20 | */ |
||
21 | |||
22 | require_once 'bootstrap.php'; |
||
23 | |||
24 | |||
25 | class GitDriverTest extends TuleapTestCase { |
||
26 | |||
27 | private $destinationPath; |
||
28 | private $sourcePath; |
||
29 | |||
30 | public function setUp() { |
||
31 | $this->curDir = getcwd(); |
||
32 | $this->fixturesPath = dirname(__FILE__).'/_fixtures'; |
||
33 | |||
34 | $this->sourcePath = "/var/tmp/".uniqid(); |
||
35 | mkdir($this->sourcePath, 0770, true); |
||
36 | $this->destinationPath = "/var/tmp/".uniqid(); |
||
37 | mkdir($this->destinationPath, 0770, true); |
||
38 | @exec('GIT_DIR='.$this->sourcePath.' git --bare init --shared=group'); |
||
0 ignored issues
–
show
|
|||
39 | } |
||
40 | |||
41 | public function tearDown() { |
||
42 | chdir($this->curDir); |
||
43 | @unlink($this->fixturesPath.'/tmp/hooks/blah'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
44 | @unlink($this->fixturesPath.'/tmp/config'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
45 | @exec('/bin/rm -rdf '.$this->fixturesPath.'/tmp/repo.git'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
46 | @exec('/bin/rm -rdf '.$this->fixturesPath.'/tmp/fork.git'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
47 | @exec('/bin/rm -rdf '.$this->destinationPath); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
48 | @exec('/bin/rm -rdf '.$this->sourcePath); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
49 | } |
||
50 | |||
51 | public function itExtractsTheGitVersion() { |
||
52 | $git_driver = partial_mock('GitDriver', array('execGitAction')); |
||
53 | stub($git_driver)->execGitAction('git --version', 'version')->returns('git version 1.8.1.2'); |
||
54 | $this->assertEqual($git_driver->getGitVersion(), "1.8.1.2"); |
||
55 | } |
||
56 | |||
57 | public function testInitBareRepo() { |
||
58 | $path = $this->fixturesPath.'/tmp/repo.git'; |
||
59 | $driver = new GitDriver(); |
||
60 | mkdir($path, 0770, true); |
||
61 | chdir($path); |
||
62 | $driver->init(true); |
||
63 | $this->assertTrue(file_exists($path.'/HEAD')); |
||
64 | $this->assertEqual(file_get_contents($path.'/description'), 'Default description for this project'.PHP_EOL); |
||
65 | } |
||
66 | |||
67 | public function testInitStdRepo() { |
||
68 | $path = $this->fixturesPath.'/tmp/repo.git'; |
||
69 | $driver = new GitDriver(); |
||
70 | mkdir($path, 0770, true); |
||
71 | chdir($path); |
||
72 | $driver->init(false); |
||
73 | $this->assertTrue(file_exists($path.'/.git/HEAD')); |
||
74 | } |
||
75 | |||
76 | public function testForkRepo() { |
||
77 | $srcPath = $this->fixturesPath.'/tmp/repo.git'; |
||
78 | $dstPath = $this->fixturesPath.'/tmp/fork.git'; |
||
79 | |||
80 | mkdir($srcPath, 0770, true); |
||
81 | @exec('GIT_DIR='.$srcPath.' git --bare init --shared=group'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
82 | |||
83 | $driver = new GitDriver(); |
||
84 | $driver->fork($srcPath, $dstPath); |
||
85 | |||
86 | $this->assertTrue(file_exists($dstPath.'/HEAD')); |
||
87 | $this->assertEqual(file_get_contents($dstPath.'/description'), 'Default description for this project'.PHP_EOL); |
||
88 | } |
||
89 | |||
90 | public function testCloneAtSpecifiqBranch() { |
||
91 | $driver = new GitDriver(); |
||
92 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
93 | |||
94 | $this->assertTrue(file_exists($this->destinationPath)); |
||
95 | } |
||
96 | |||
97 | public function testAdd() { |
||
98 | $driver = new GitDriver(); |
||
99 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
100 | |||
101 | @exec('cd '.$this->destinationPath.' && touch toto'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
102 | $driver->add($this->destinationPath, 'toto'); |
||
103 | exec('cd '.$this->destinationPath.' && git status --porcelain',$out,$ret); |
||
104 | $this->assertEqual(implode($out), 'A toto'); |
||
105 | } |
||
106 | |||
107 | public function testGetInformationsFile() { |
||
108 | $driver = new GitDriver(); |
||
109 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
110 | |||
111 | @exec('cd '.$this->destinationPath.' && touch toto'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
112 | $driver->add($this->destinationPath, 'toto'); |
||
113 | exec('cd '.$this->destinationPath.' && git ls-files -s toto',$out,$ret); |
||
114 | $sha1 = split(" ", implode($out)); |
||
115 | $this->assertEqual(strlen($sha1[1]), 40); |
||
116 | } |
||
117 | |||
118 | public function testchangeGitUserInfo() { |
||
119 | $driver = new GitDriver(); |
||
120 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
121 | |||
122 | $driver->changeGitUserInfo($this->destinationPath, "[email protected]", "testman"); |
||
123 | exec('cd '.$this->destinationPath.' && git config --get user.name',$out,$ret); |
||
124 | $this->assertEqual(implode($out), "testman"); |
||
125 | |||
126 | exec('cd '.$this->destinationPath.' && git config --get user.email',$out2,$ret2); |
||
127 | $this->assertEqual(implode($out2), "[email protected]"); |
||
128 | } |
||
129 | |||
130 | public function testCommit() { |
||
131 | $driver = new GitDriver(); |
||
132 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
133 | |||
134 | @exec('cd '.$this->destinationPath.' && touch toto'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
135 | |||
136 | $driver->add($this->destinationPath, 'toto'); |
||
137 | $driver->changeGitUserInfo($this->destinationPath, "[email protected]", "testman"); |
||
138 | $driver->commit($this->destinationPath, "test commit"); |
||
139 | |||
140 | exec('cd '.$this->destinationPath.' && git status --porcelain',$out,$ret); |
||
141 | $this->assertEqual(implode($out), ''); |
||
142 | } |
||
143 | |||
144 | public function testRmREpo() { |
||
145 | $driver = new GitDriver(); |
||
146 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
147 | $driver->removeRepository($this->destinationPath); |
||
148 | $this->assertTrue(!file_exists($this->destinationPath)); |
||
149 | } |
||
150 | |||
151 | public function testMergeAndPush() { |
||
152 | $destinationPath2 = "/var/tmp/".uniqid(); |
||
153 | mkdir($destinationPath2, 0770, true); |
||
154 | $destinationPath3 = "/var/tmp/".uniqid(); |
||
155 | mkdir($destinationPath3, 0770, true); |
||
156 | |||
157 | $driver = new GitDriver(); |
||
158 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $this->destinationPath, "master"); |
||
159 | $driver->changeGitUserInfo($this->destinationPath, "[email protected]", "testman"); |
||
160 | @exec('cd '.$this->destinationPath.'&& touch test.txt && git add . && git commit -m "add master" && git push --quiet -u '. $this->sourcePath .' master'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
161 | |||
162 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $destinationPath2, "master"); |
||
163 | |||
164 | @exec('cd '.$this->destinationPath.'&& touch toto.txt'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
165 | $driver->add($this->destinationPath, 'toto.txt'); |
||
166 | $driver->commit($this->destinationPath, "test commit"); |
||
167 | $driver->mergeAndPush($this->destinationPath, $this->sourcePath); |
||
168 | |||
169 | @exec('cd '.$destinationPath2.'&& touch titi.txt'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
170 | $driver->add($destinationPath2, 'titi.txt'); |
||
171 | $driver->changeGitUserInfo($destinationPath2, "[email protected]", "testman2"); |
||
172 | $driver->commit($destinationPath2, "test commit"); |
||
173 | $driver->mergeAndPush($destinationPath2, $this->sourcePath); |
||
174 | |||
175 | $driver->cloneAtSpecifiqBranch($this->sourcePath, $destinationPath3, "master"); |
||
176 | |||
177 | $this->assertTrue(file_exists($destinationPath3.'/toto.txt') && file_exists($destinationPath3.'/titi.txt')); |
||
178 | |||
179 | @exec('/bin/rm -rdf '.$destinationPath2); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
180 | @exec('/bin/rm -rdf '.$destinationPath3); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
181 | } |
||
182 | |||
183 | public function testSetRepositoryAccessPublic() { |
||
184 | $srcPath = $this->fixturesPath.'/tmp/repo.git'; |
||
185 | |||
186 | mkdir($srcPath, 0770, true); |
||
187 | @exec('GIT_DIR='.$srcPath.' git --bare init --shared=group'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
188 | |||
189 | $driver = new GitDriver(); |
||
190 | $driver->setRepositoryAccess($srcPath, GitRepository::PUBLIC_ACCESS); |
||
191 | |||
192 | clearstatcache(); |
||
193 | $stat = stat($srcPath); |
||
194 | //system('/bin/ls -ld '.$srcPath); |
||
195 | $this->assertEqual(base_convert($stat['mode'], 10, 8), 42775); |
||
196 | } |
||
197 | |||
198 | public function testSetRepositoryAccessPrivate() { |
||
199 | $srcPath = $this->fixturesPath.'/tmp/repo.git'; |
||
200 | |||
201 | mkdir($srcPath, 0770, true); |
||
202 | @exec('GIT_DIR='.$srcPath.' git --bare init --shared=group'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
203 | |||
204 | $driver = new GitDriver(); |
||
205 | $driver->setRepositoryAccess($srcPath, GitRepository::PRIVATE_ACCESS); |
||
206 | |||
207 | clearstatcache(); |
||
208 | $stat = stat($srcPath); |
||
209 | //system('/bin/ls -ld '.$srcPath); |
||
210 | $this->assertEqual(base_convert($stat['mode'], 10, 8), 42770); |
||
211 | } |
||
212 | |||
213 | public function testForkRepoUnixPermissions() { |
||
214 | $srcPath = $this->fixturesPath.'/tmp/repo.git'; |
||
215 | $dstPath = $this->fixturesPath.'/tmp/fork.git'; |
||
216 | |||
217 | mkdir($srcPath, 0770, true); |
||
218 | @exec('GIT_DIR='.$srcPath.' git --bare init --shared=group'); |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
219 | |||
220 | $driver = new GitDriver(); |
||
221 | $driver->fork($srcPath, $dstPath); |
||
222 | |||
223 | clearstatcache(); |
||
224 | $stat = stat($dstPath.'/HEAD'); |
||
225 | //system('/bin/ls -ld '.$dstPath.'/HEAD'); |
||
226 | $this->assertEqual(base_convert($stat['mode'], 10, 8), 100664, '/HEAD must be writable by group'); |
||
227 | |||
228 | $stat = stat($dstPath.'/refs'); |
||
229 | //system('/bin/ls -ld '.$dstPath.'/refs'); |
||
230 | $this->assertEqual(base_convert($stat['mode'], 10, 8), 42775, '/refs must have setgid bit'); |
||
231 | |||
232 | $stat = stat($dstPath.'/refs/heads'); |
||
233 | $this->assertEqual(base_convert($stat['mode'], 10, 8), 42775, '/refs/heads must have setgid bit'); |
||
234 | } |
||
235 | |||
236 | public function testActivateHook() { |
||
237 | copy($this->fixturesPath.'/hooks/post-receive', $this->fixturesPath.'/tmp/hooks/blah'); |
||
238 | |||
239 | $driver = new GitDriver(); |
||
240 | $driver->activateHook('blah', $this->fixturesPath.'/tmp'); |
||
241 | |||
242 | $this->assertTrue(is_executable($this->fixturesPath.'/tmp/hooks/blah')); |
||
243 | } |
||
244 | |||
245 | public function testSetConfigSimple() { |
||
246 | copy($this->fixturesPath.'/config', $this->fixturesPath.'/tmp/config'); |
||
247 | |||
248 | $driver = new GitDriver(); |
||
249 | $driver->setConfig($this->fixturesPath.'/tmp', 'hooks.showrev', 'abcd'); |
||
250 | |||
251 | $config = parse_ini_file($this->fixturesPath.'/tmp/config', true); |
||
252 | $this->assertEqual($config['hooks']['showrev'], 'abcd'); |
||
253 | } |
||
254 | |||
255 | public function testSetConfigComplex() { |
||
256 | copy($this->fixturesPath.'/config', $this->fixturesPath.'/tmp/config'); |
||
257 | |||
258 | $val = "t=%s; git log --name-status --pretty='format:URL: https://codendi.org/plugins/git/index.php/1750/view/290/?p=git.git&a=commitdiff&h=%%H%%nAuthor: %%an <%%ae>%%nDate: %%aD%%n%%n%%s%%n%%b' \$t~1..\$t"; |
||
259 | |||
260 | $driver = new GitDriver(); |
||
261 | $driver->setConfig($this->fixturesPath.'/tmp', 'hooks.showrev', $val); |
||
262 | |||
263 | $config = parse_ini_file($this->fixturesPath.'/tmp/config', true); |
||
264 | $this->assertEqual($config['hooks']['showrev'], 't=%s; git log --name-status --pretty=\'format:URL: https://codendi.org/plugins/git/index.php/1750/view/290/?p=git.git&a=commitdiff&h=%%H%%nAuthor: %%an <%%ae>%%nDate: %%aD%%n%%n%%s%%n%%b\' $t~1..$t'); |
||
265 | } |
||
266 | |||
267 | public function testSetConfigWithSpace() { |
||
268 | copy($this->fixturesPath.'/config', $this->fixturesPath.'/tmp/config'); |
||
269 | |||
270 | $driver = new GitDriver(); |
||
271 | $driver->setConfig($this->fixturesPath.'/tmp', 'hooks.showrev', '[MyVal] '); |
||
272 | |||
273 | $config = parse_ini_file($this->fixturesPath.'/tmp/config', true); |
||
274 | $this->assertEqual($config['hooks']['showrev'], '[MyVal] '); |
||
275 | } |
||
276 | |||
277 | public function testSetEmptyConfig() { |
||
278 | copy($this->fixturesPath.'/config', $this->fixturesPath.'/tmp/config'); |
||
279 | |||
280 | $driver = new GitDriver(); |
||
281 | $driver->setConfig($this->fixturesPath.'/tmp', 'hooks.showrev', ''); |
||
282 | |||
283 | $config = parse_ini_file($this->fixturesPath.'/tmp/config', true); |
||
284 | $this->assertEqual($config['hooks']['showrev'], ''); |
||
285 | } |
||
286 | } |
||
287 | ?> |
If you suppress an error, we recommend checking for the error condition explicitly: