Issues (5)

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/PlaylistSchedulerTest.php (2 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
/*
4
 * This file is part of the Mala package.
5
 *
6
 * (c) Chrisyue <http://chrisyue.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Tests;
13
14
use Chrisyue\Mala\PlaylistScheduler;
15
use Prophecy\Prophecy\ObjectProphecy;
16
17
class PlaylistSchedulerTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * @expectedException UnexpectedValueException
21
     */
22 View Code Duplication
    public function testScheduleFirstTimeButNoEpg() // no last media segment
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...
23
    {
24
        $startsAt = new \DateTime();
25
        $endsAt = new \DateTime('+30 seconds');
26
        $channel = $this->prophesizeChannel();
27
28
        $parser = $this->prophesizeParser();
29
        $msManager = $this->prophesizeMediaSegmentManager();
30
        $epgManager = $this->prophesizeEpgManager();
31
32
        $scheduler = new PlaylistScheduler($parser->reveal(), $epgManager->reveal(), $msManager->reveal());
33
        $scheduler->schedule($channel->reveal(), $startsAt, $endsAt);
34
    }
35
36
    public function testSchedule()
37
    {
38
        $startsAt = new \DateTime();
39
        $endsAt = new \DateTime('+30 seconds');
40
        $channel = $this->prophesizeChannel();
41
42
        $videoUri = 'http://www.example.com/foo.m3u8';
43
        $video = $this->prophesizeVideo($videoUri);
44
45
        $programStartsAt = new \DateTime('+10 seconds');
46
        $programEndsAt = new \DateTime('+40 seconds');
47
        $program = $this->prophesizeProgram($programStartsAt, $programEndsAt, $video);
48
49
        $epgManager = $this->prophesizeEpgManager($channel, $startsAt, $endsAt, $program);
50
51
        $lastScheduledMsSequence = 10;
52
        $lastScheduledMsEndsAt = new \DateTime('+10 seconds');
53
        $lastScheduledMs = $this->prophesizeLastScheduledMediaSegment($lastScheduledMsEndsAt, $lastScheduledMsSequence);
54
55
        $msDuration = 30;
56
        $msUri = 'http://example.com/foo1.ts';
57
        $mediaSegment = $this->prophesizeMediaSegment($msUri, $msDuration);
58
59
        $m3u8 = $this->prophesizeM3u8($mediaSegment);
60
61
        $parser = $this->prophesizeParser($videoUri, $m3u8);
62
63
        $newScheduledMs = $this->prophesizeNewScheduledMediaSegment();
64
65
        $msManager = $this->prophesizeMediaSegmentManager($channel, $programStartsAt, $lastScheduledMs);
66
        $msManager->create($program->reveal(), $programStartsAt, $programEndsAt, $msUri, $msDuration, $lastScheduledMsSequence + 1, true)
67
            ->shouldBeCalledTimes(1)->willReturn($newScheduledMs->reveal());
68
69
        $msManager->saveDeferred($newScheduledMs->reveal())->shouldBeCalledTimes(1);
70
        $msManager->commit()->shouldBeCalledTimes(1);
71
72
        $scheduler = new PlaylistScheduler($parser->reveal(), $epgManager->reveal(), $msManager->reveal());
73
        $scheduler->schedule($channel->reveal(), $startsAt, $endsAt);
74
    }
75
76
    private function prophesizeMediaSegmentManager(ObjectProphecy $channel = null, $programStartsAt = null, ObjectProphecy $last = null)
77
    {
78
        $msManager = $this->prophesize('Chrisyue\Mala\Manager\MediaSegmentManagerInterface');
79
80
        if (null === $channel) {
81
            return $msManager;
82
        }
83
84
        $msManager->clear($channel->reveal(), $programStartsAt)->shouldBeCalledTimes(1);
85
        $msManager->findLast($channel->reveal())->shouldBeCalledTimes(1)->willReturn(null === $last ? null : $last->reveal());
86
87
        return $msManager;
88
    }
89
90
    private function prophesizeChannel()
91
    {
92
        $channel = $this->prophesize('Chrisyue\Mala\Model\ChannelInterface');
93
94
        return $channel;
95
    }
96
97
    private function prophesizeEpgManager(
98
        ObjectProphecy $channel = null,
99
        \DateTime $startsAt = null,
100
        \DateTime $endsAt = null,
101
        ObjectProphecy $program = null
102
    ) {
103
        $epgManager = $this->prophesize('Chrisyue\Mala\Manager\EpgManagerInterface');
104
        if (null === $channel) {
105
            return $epgManager;
106
        }
107
108
        $findResult = null;
109
        if (null !== $program) {
110
            $findResult = array($program->reveal());
111
        }
112
113
        $epgManager->find($channel->reveal(), $startsAt, $endsAt)->willReturn($findResult);
114
115
        return $epgManager;
116
    }
117
118
    private function prophesizeLastScheduledMediaSegment(\DateTime $endsAt, $sequence)
119
    {
120
        $mediaSegment = $this->prophesize('Chrisyue\Mala\Model\ScheduledMediaSegment');
121
        $mediaSegment->getEndsAt()->shouldBeCalledTimes(1)->willReturn($endsAt);
122
        $mediaSegment->getSequence()->shouldBeCalledTimes(1)->willReturn($sequence);
123
124
        return $mediaSegment;
125
    }
126
127
    private function prophesizeNewScheduledMediaSegment()
128
    {
129
        $mediaSegment = $this->prophesize('Chrisyue\Mala\Model\ScheduledMediaSegment');
130
131
        return $mediaSegment;
132
    }
133
134
    private function prophesizeMediaSegment($uri, $duration)
135
    {
136
        $mediaSegment = $this->prophesize('Chrisyue\Mala\Model\ScheduledMediaSegment');
137
        $mediaSegment->getUri()->shouldBeCalledTimes(1)->willReturn($uri);
138
        $mediaSegment->getDuration()->shouldBeCalledTimes(2)->willReturn($duration);
139
140
        return $mediaSegment;
141
    }
142
143
    private function prophesizeParser($m3u8Uri = null, ObjectProphecy $m3u8 = null)
144
    {
145
        $parser = $this->prophesize('Chrisyue\PhpM3u8\Parser');
146
        if (null === $m3u8Uri) {
147
            return $parser;
148
        }
149
150
        $parser->parseFromUri($m3u8Uri)->shouldBeCalledTimes(1)->willReturn($m3u8->reveal());
151
152
        return $parser;
153
    }
154
155
    private function prophesizeProgram(\DateTime $startsAt, \DateTime $endsAt, ObjectProphecy $video)
156
    {
157
        $program = $this->prophesize('Chrisyue\Mala\Model\ProgramInterface');
158
        $program->getVideo()->shouldBeCalledTimes(1)->willReturn($video->reveal());
159
        $program->getStartsAt()->shouldBeCalled()->willReturn($startsAt);
160
161
        return $program;
162
    }
163
164
    private function prophesizeVideo($uri)
165
    {
166
        $video = $this->prophesize('Chrisyue\Mala\Model\VideoInterface');
167
        $video->getUri()->shouldBeCalledTimes(1)->willReturn($uri);
168
169
        return $video;
170
    }
171
172 View Code Duplication
    private function prophesizeM3u8(ObjectProphecy $mediaSegment)
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...
173
    {
174
        $m3u8 = $this->prophesize('Chrisyue\PhpM3u8\M3u8\M3u8');
175
        $m3u8->getPlaylist()->shouldBeCalledTimes(1)->willReturn(array($mediaSegment->reveal()));
176
177
        return $m3u8;
178
    }
179
}
180