Issues (37)

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.

test/StoragelessTest/Session/LazySessionTest.php (1 issue)

Labels
Severity

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 SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types=1);
20
21
namespace PSR7SessionsTest\Storageless\Session;
22
23
use PHPUnit\Framework\MockObject\MockObject;
24
use PHPUnit\Framework\TestCase;
25
use PSR7Sessions\Storageless\Session\LazySession;
26
use PSR7Sessions\Storageless\Session\SessionInterface;
27
use stdClass;
28
use function assert;
29
use function is_callable;
30
use function uniqid;
31
32
/**
33
 * @covers \PSR7Sessions\Storageless\Session\LazySession
34
 */
35
final class LazySessionTest extends TestCase
36
{
37
    /** @var SessionInterface&MockObject */
38
    private SessionInterface $wrappedSession;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
39
40
    /** @var callable&MockObject */
41
    private MockObject $sessionLoader;
42
43
    private LazySession $lazySession;
44
45
    protected function setUp() : void
46
    {
47
        $this->wrappedSession = $this->createMock(SessionInterface::class);
48
        $sessionLoader        = $this->getMockBuilder(stdClass::class)->setMethods(['__invoke'])->getMock();
49
        assert(is_callable($sessionLoader));
50
        $this->sessionLoader = $sessionLoader;
51
        $this->lazySession   = LazySession::fromContainerBuildingCallback($this->sessionLoader);
52
    }
53
54
    public function testLazyNonInitializedSessionIsAlwaysNotChanged() : void
55
    {
56
        $this->sessionLoader->expects(self::never())->method('__invoke');
57
58
        self::assertFalse($this->lazySession->hasChanged());
59
    }
60
61
    public function testHasChanged() : void
62
    {
63
        $this->wrappedSessionWillBeLoaded();
64
65
        $this->wrappedSession->expects(self::at(1))->method('hasChanged')->willReturn(true);
66
        $this->wrappedSession->expects(self::at(2))->method('hasChanged')->willReturn(false);
67
68
        $this->forceWrappedSessionInitialization();
69
70
        self::assertTrue($this->lazySession->hasChanged());
71
        self::assertFalse($this->lazySession->hasChanged());
72
    }
73
74
    public function testHas() : void
75
    {
76
        $this->wrappedSessionWillBeLoaded();
77
78
        $this->wrappedSession->expects(self::exactly(2))->method('has')->willReturnMap([
79
            ['foo', false],
80
            ['bar', true],
81
        ]);
82
83
        self::assertFalse($this->lazySession->has('foo'));
84
        self::assertTrue($this->lazySession->has('bar'));
85
    }
86
87
    public function testGet() : void
88
    {
89
        $this->wrappedSessionWillBeLoaded();
90
91
        $this->wrappedSession->expects(self::exactly(3))->method('get')->willReturnMap([
92
            ['foo', null, 'bar'],
93
            ['baz', null, 'tab'],
94
            ['baz', 'default', 'taz'],
95
        ]);
96
97
        self::assertSame('bar', $this->lazySession->get('foo'));
98
        self::assertSame('tab', $this->lazySession->get('baz'));
99
        self::assertSame('taz', $this->lazySession->get('baz', 'default'));
100
    }
101
102
    public function testRemove() : void
103
    {
104
        $this->wrappedSessionWillBeLoaded();
105
106
        $this->wrappedSession->expects(self::exactly(2))->method('remove')->with(self::logicalOr('foo', 'bar'));
107
108
        $this->lazySession->remove('foo');
109
        $this->lazySession->remove('bar');
110
    }
111
112
    public function testClear() : void
113
    {
114
        $this->wrappedSessionWillBeLoaded();
115
116
        $this->wrappedSession->expects(self::exactly(2))->method('clear');
117
118
        $this->lazySession->clear();
119
        $this->lazySession->clear();
120
    }
121
122
    public function testSet() : void
123
    {
124
        $this->wrappedSessionWillBeLoaded();
125
126
        $this
127
            ->wrappedSession
128
            ->expects(self::exactly(2))
129
            ->method('set')
130
            ->with(self::logicalOr('foo', 'baz'), self::logicalOr('bar', 'tab'));
131
132
        $this->lazySession->set('foo', 'bar');
133
        $this->lazySession->set('baz', 'tab');
134
    }
135
136
    public function testIsEmpty() : void
137
    {
138
        $this->wrappedSessionWillBeLoaded();
139
140
        $this->wrappedSession->expects(self::at(0))->method('isEmpty')->willReturn(true);
141
        $this->wrappedSession->expects(self::at(1))->method('isEmpty')->willReturn(false);
142
143
        self::assertTrue($this->lazySession->isEmpty());
144
        self::assertFalse($this->lazySession->isEmpty());
145
    }
146
147
    public function testJsonSerialize() : void
148
    {
149
        $this->wrappedSessionWillBeLoaded();
150
151
        $this->wrappedSession->expects(self::at(0))->method('jsonSerialize')->willReturn((object) ['foo' => 'bar']);
152
        $this->wrappedSession->expects(self::at(1))->method('jsonSerialize')->willReturn((object) ['baz' => 'tab']);
153
154
        self::assertEquals((object) ['foo' => 'bar'], $this->lazySession->jsonSerialize());
155
        self::assertEquals((object) ['baz' => 'tab'], $this->lazySession->jsonSerialize());
156
    }
157
158
    private function wrappedSessionWillBeLoaded() : void
159
    {
160
        $this->sessionLoader->expects(self::once())->method('__invoke')->willReturn($this->wrappedSession);
161
    }
162
163
    private function forceWrappedSessionInitialization() : void
164
    {
165
        // no-op operation that is known to trigger session lazy-loading
166
        $this->lazySession->remove(uniqid('nonExisting', true));
167
    }
168
}
169