Issues (144)

Security Analysis    no request data  

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.

tests/integration/Node/LocalFileTest.php (4 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
 * This file is part of graze/data-file
4
 *
5
 * Copyright (c) 2016 Nature Delivered Ltd. <https://www.graze.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license https://github.com/graze/data-file/blob/master/LICENSE.md
11
 * @link    https://github.com/graze/data-file
12
 */
13
14
namespace Graze\DataFile\Test\Integration\Node;
15
16
use Graze\DataFile\Modify\Compress\Gzip;
17
use Graze\DataFile\Node\FileNodeInterface;
18
use Graze\DataFile\Node\LocalFile;
19
use Graze\DataFile\Test\AbstractFileTestCase;
20
21
class LocalFileTest extends AbstractFileTestCase
22
{
23
    public function testInstanceOf()
24
    {
25
        $file = new LocalFile('/broken/path/to/nowhere');
26
        static::assertInstanceOf(FileNodeInterface::class, $file);
27
    }
28
29 View Code Duplication
    public function testGetFilePathReturnsFullyQualifiedPath()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
30
    {
31
        $file = new LocalFile(static::$dir . 'file_path.test');
32
        $file->put('random');
33
34
        $expected = static::$dir . 'file_path.test';
35
36
        static::assertEquals($expected, $file->getPath());
37
    }
38
39
    public function testGetFilenameJustReturnsTheFilename()
40
    {
41
        $file = new LocalFile(static::$dir . 'file_name.test');
42
43
        static::assertEquals('file_name.test', $file->getFilename());
44
    }
45
46
    public function testFileExists()
47
    {
48
        $file = new LocalFile(static::$dir . 'file_exists.test');
49
50
        static::assertFalse($file->exists());
51
52
        $file->put('random');
53
54
        static::assertTrue($file->exists());
55
    }
56
57
    public function testFileGetContents()
58
    {
59
        $file = new LocalFile(static::$dir . 'file_get_contents.test');
60
61
        $file->put('content stuff');
62
63
        static::assertEquals(['content stuff'], $file->getContents());
64
    }
65
66
    public function testFileGetContentsReturnsEmptyArrayIfFileDoesNotExist()
67
    {
68
        $file = new LocalFile(static::$dir . 'file_get_contents_empty.test');
69
        static::assertEquals([], $file->getContents());
70
    }
71
72
    public function testCompression()
73
    {
74
        $file = (new LocalFile(static::$dir . 'file_compression.test'))
75
            ->setCompression(Gzip::NAME);
76
        static::assertEquals('gzip', $file->getCompression());
77
    }
78
79
    public function testEncoding()
80
    {
81
        $file = (new LocalFile(static::$dir . 'file_encoding.test'))
82
            ->setEncoding('UTF-8');
83
        static::assertEquals('UTF-8', $file->getEncoding());
84
    }
85
86
    public function testToString()
87
    {
88
        $file = new LocalFile(static::$dir . 'to_string.test');
89
        static::assertEquals($file->getPath(), $file);
90
    }
91
92
    public function testGetContentsForCompressedFile()
93
    {
94
        $file = new LocalFile(static::$dir . 'file_uncompressed.test');
95
        $file->put('uncompressed contents');
96
97
        $gzip = new Gzip();
98
        $compressed = $gzip->compress($file, ['keepOldFile' => true]);
99
100
        static::assertEquals(['uncompressed contents'], $compressed->getContents());
101
    }
102
103
    public function testGetContentsForCompressedFileDeletesTheUncompressedFileAfterwards()
104
    {
105
        $file = new LocalFile(static::$dir . 'file_uncompressed_todelete.test');
106
        $file->put('uncompressed contents');
107
108
        $gzip = new Gzip();
109
        $compressed = $gzip->compress($file, ['keepOldFile' => true]);
110
111
        $compressed->getContents();
112
113
        static::assertFalse(
114
            file_exists(static::$dir . 'file_uncompressed_todelete'),
115
            "The uncompressed file should be deleted"
116
        );
117
    }
118
119
    public function testSetEncodingModifiesTheEncoding()
120
    {
121
        $file = new LocalFile(static::$dir . 'file_set_encoding.test');
122
        $file->put('uncompressed contents');
123
124
        $file->setEncoding('us-ascii');
125
126
        static::assertEquals('us-ascii', $file->getEncoding());
127
    }
128
129 View Code Duplication
    public function testSetEncodingReturnsIsFluent()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
130
    {
131
        $file = new LocalFile(static::$dir . 'file_set_encoding2.test');
132
        $file->put('uncompressed contents');
133
134
        $newFile = $file->setEncoding('us-ascii');
135
136
        static::assertNotNull($newFile);
137
        static::assertSame($file, $newFile);
138
    }
139
140 View Code Duplication
    public function testSetCompressionModifiesTheEncoding()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
141
    {
142
        $file = new LocalFile(static::$dir . 'file_set_compression.test');
143
        $file->put('uncompressed contents');
144
145
        $file->setCompression(Gzip::NAME);
146
147
        static::assertEquals(Gzip::NAME, $file->getCompression());
148
    }
149
150 View Code Duplication
    public function testSetCompressionReturnsIsFluent()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
151
    {
152
        $file = new LocalFile(static::$dir . 'file_set_compression2.test');
153
        $file->put('uncompressed contents');
154
155
        $newFile = $file->setCompression(Gzip::NAME);
156
157
        static::assertNotNull($newFile);
158
        static::assertSame($file, $newFile);
159
    }
160
161
    public function testGetDirectoryReturnsJustTheDirectory()
162
    {
163
        $file = new LocalFile(static::$dir . 'file_dont_care.test');
164
165
        static::assertEquals(static::$dir, $file->getDirectory());
166
    }
167
168
    public function testGetStream()
169
    {
170
        $file = new LocalFile(static::$dir . 'file_get_stream.test');
171
172
        $stream = $file->getStream();
173
174
        static::assertInternalType('resource', $stream);
175
176
        fwrite($stream, 'some text');
177
        fclose($stream);
178
179
        static::assertEquals('some text', $file->read());
180
    }
181
}
182