GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

Issues (4873)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

plugins/git/tests/GitDriverTest.php (19 issues)

Upgrade to new PHP Analysis Engine

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
Security Best Practice introduced by
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.');
}
Loading history...
39
    }
40
41
    public function tearDown() {
42
        chdir($this->curDir);
43
        @unlink($this->fixturesPath.'/tmp/hooks/blah');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
44
        @unlink($this->fixturesPath.'/tmp/config');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
45
        @exec('/bin/rm -rdf '.$this->fixturesPath.'/tmp/repo.git');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
46
        @exec('/bin/rm -rdf '.$this->fixturesPath.'/tmp/fork.git');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
47
        @exec('/bin/rm -rdf '.$this->destinationPath);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
48
        @exec('/bin/rm -rdf '.$this->sourcePath);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
161
162
            $driver->cloneAtSpecifiqBranch($this->sourcePath, $destinationPath2, "master");
163
164
            @exec('cd '.$this->destinationPath.'&& touch toto.txt');
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
180
            @exec('/bin/rm -rdf '.$destinationPath3);
0 ignored issues
show
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
Security Best Practice introduced by
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.');
}
Loading history...
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
?>