Issues (234)

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.

tests/Provider/VimeoProviderTest.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\MediaBundle\Tests\Provider;
15
16
use Buzz\Browser;
17
use Buzz\Message\AbstractMessage;
18
use Buzz\Message\Response;
19
use Gaufrette\Adapter;
20
use Gaufrette\File;
21
use Gaufrette\Filesystem;
22
use Imagine\Image\Box;
23
use Sonata\AdminBundle\Admin\AdminInterface;
24
use Sonata\AdminBundle\Form\FormMapper;
25
use Sonata\MediaBundle\CDN\Server;
26
use Sonata\MediaBundle\Generator\IdGenerator;
27
use Sonata\MediaBundle\Metadata\MetadataBuilderInterface;
28
use Sonata\MediaBundle\Provider\MediaProviderInterface;
29
use Sonata\MediaBundle\Provider\VimeoProvider;
30
use Sonata\MediaBundle\Resizer\ResizerInterface;
31
use Sonata\MediaBundle\Tests\Entity\Media;
32
use Sonata\MediaBundle\Thumbnail\FormatThumbnail;
33
34
class VimeoProviderTest extends AbstractProviderTest
35
{
36
    public function getProvider(?Browser $browser = null): MediaProviderInterface
37
    {
38
        if (!$browser) {
39
            $browser = $this->createMock(Browser::class);
40
        }
41
42
        $resizer = $this->createMock(ResizerInterface::class);
43
        $resizer->method('resize')->willReturn(true);
44
        $resizer->method('getBox')->willReturn(new Box(100, 100));
45
46
        $adapter = $this->createMock(Adapter::class);
47
48
        $filesystem = $this->getMockBuilder(Filesystem::class)
49
            ->onlyMethods(['get'])
50
            ->setConstructorArgs([$adapter])
51
            ->getMock();
52
        $file = $this->getMockBuilder(File::class)
53
            ->setConstructorArgs(['foo', $filesystem])
54
            ->getMock();
55
        $filesystem->method('get')->willReturn($file);
56
57
        $cdn = new Server('/uploads/media');
58
59
        $generator = new IdGenerator();
60
61
        $thumbnail = new FormatThumbnail('jpg');
62
63
        $metadata = $this->createMock(MetadataBuilderInterface::class);
64
65
        $provider = new VimeoProvider('vimeo', $filesystem, $cdn, $generator, $thumbnail, $browser, $metadata);
66
        $provider->setResizer($resizer);
67
68
        return $provider;
69
    }
70
71
    public function testProvider(): void
72
    {
73
        $provider = $this->getProvider();
74
75
        $media = new Media();
76
        $media->setName('Blinkyâ„¢');
77
        $media->setProviderName('vimeo');
78
        $media->setProviderReference('21216091');
79
        $media->setContext('default');
80
        $media->setProviderMetadata(json_decode('{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"http:\/\/vimeo.com\/","title":"Blinky\u2122","author_name":"Ruairi Robinson","author_url":"http:\/\/vimeo.com\/ruairirobinson","is_plus":"1","html":"<iframe src=\"http:\/\/player.vimeo.com\/video\/21216091\" width=\"1920\" height=\"1080\" frameborder=\"0\"><\/iframe>","width":"1920","height":"1080","duration":"771","description":"","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/136\/375\/136375440_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":"21216091"}', true));
81
82
        $media->setId(1023457);
83
        $this->assertSame('http://b.vimeocdn.com/ts/136/375/136375440_1280.jpg', $provider->getReferenceImage($media));
84
85
        $this->assertSame('default/0011/24', $provider->generatePath($media));
86
        $this->assertSame('/uploads/media/default/0011/24/thumb_1023457_big.jpg', $provider->generatePublicUrl($media, 'big'));
87
    }
88
89
    public function testThumbnail(): void
90
    {
91
        $response = $this->createMock(AbstractMessage::class);
92
        $response->expects($this->once())->method('getContent')->willReturn('content');
93
94
        $browser = $this->createMock(Browser::class);
95
96
        $browser->expects($this->once())->method('get')->willReturn($response);
97
98
        $provider = $this->getProvider($browser);
99
100
        $media = new Media();
101
        $media->setName('Blinkyâ„¢');
102
        $media->setProviderName('vimeo');
103
        $media->setProviderReference('21216091');
104
        $media->setContext('default');
105
        $media->setProviderMetadata(json_decode('{"type":"video","version":"1.0","provider_name":"Vimeo","provider_url":"http:\/\/vimeo.com\/","title":"Blinky\u2122","author_name":"Ruairi Robinson","author_url":"http:\/\/vimeo.com\/ruairirobinson","is_plus":"1","html":"<iframe src=\"http:\/\/player.vimeo.com\/video\/21216091\" width=\"1920\" height=\"1080\" frameborder=\"0\"><\/iframe>","width":"1920","height":"1080","duration":"771","description":"","thumbnail_url":"http:\/\/b.vimeocdn.com\/ts\/136\/375\/136375440_1280.jpg","thumbnail_width":1280,"thumbnail_height":720,"video_id":"21216091"}', true));
106
107
        $media->setId(1023457);
108
109
        $this->assertTrue($provider->requireThumbnails());
110
111
        $provider->addFormat('big', ['width' => 200, 'height' => 100, 'constraint' => true]);
112
113
        $this->assertNotEmpty($provider->getFormats(), '::getFormats() return an array');
114
115
        $provider->generateThumbnails($media);
116
117
        $this->assertSame('default/0011/24/thumb_1023457_big.jpg', $provider->generatePrivateUrl($media, 'big'));
118
    }
119
120
    public function testTransformWithSig(): void
121
    {
122
        $response = new Response();
123
        $response->setContent(file_get_contents(__DIR__.'/../fixtures/valid_vimeo.txt'));
124
125
        $browser = $this->createMock(Browser::class);
126
        $browser->expects($this->once())->method('get')->willReturn($response);
127
128
        $provider = $this->getProvider($browser);
129
130
        $provider->addFormat('big', ['width' => 200, 'height' => 100, 'constraint' => true]);
131
132
        $media = new Media();
133
        $media->setContext('default');
134
        $media->setBinaryContent('BDYAbAtaDzA');
135
        $media->setId(1023456);
136
137
        // pre persist the media
138
        $provider->transform($media);
139
        $provider->prePersist($media);
140
141
        $this->assertSame('Blinkyâ„¢', $media->getName(), '::getName() return the file name');
142
        $this->assertSame('BDYAbAtaDzA', $media->getProviderReference(), '::getProviderReference() is set');
143
    }
144
145
    /**
146
     * @dataProvider getTransformWithUrlMedia
147
     */
148
    public function testTransformWithUrl(Media $media): void
149
    {
150
        $response = new Response();
151
        $response->setContent(file_get_contents(__DIR__.'/../fixtures/valid_vimeo.txt'));
152
153
        $browser = $this->createMock(Browser::class);
154
        $browser->expects($this->once())->method('get')->willReturn($response);
155
156
        $provider = $this->getProvider($browser);
157
158
        $provider->addFormat('big', ['width' => 200, 'height' => 100, 'constraint' => true]);
159
160
        // pre persist the media
161
        $provider->transform($media);
162
        $provider->prePersist($media);
163
164
        $this->assertSame('Blinkyâ„¢', $media->getName(), '::getName() return the file name');
165
        $this->assertSame('012341231', $media->getProviderReference(), '::getProviderReference() is set');
166
    }
167
168
    public function getTransformWithUrlMedia(): array
169
    {
170
        $mediaWebsite = new Media();
171
        $mediaWebsite->setContext('default');
172
        $mediaWebsite->setBinaryContent('https://vimeo.com/012341231');
173
        $mediaWebsite->setId(1023456);
174
175
        $mediaPlayer = new Media();
176
        $mediaPlayer->setContext('default');
177
        $mediaPlayer->setBinaryContent('https://player.vimeo.com/video/012341231');
178
        $mediaPlayer->setId(1023456);
179
180
        return [
181
            'transform with website url' => [$mediaWebsite],
182
            'transform with player url' => [$mediaPlayer],
183
        ];
184
    }
185
186
    public function testGetMetadataException(): void
187
    {
188
        $this->expectException(\RuntimeException::class);
189
        $this->expectExceptionMessage('Unable to retrieve the video information for :012341231');
190
        $this->expectExceptionCode(12);
191
192
        $response = new Response();
193
        $response->setContent(file_get_contents(__DIR__.'/../fixtures/valid_vimeo.txt'));
194
195
        $browser = $this->createMock(Browser::class);
196
        $browser->expects($this->once())->method('get')->will($this->throwException(new \RuntimeException('First error on get', 12)));
197
198
        $provider = $this->getProvider($browser);
199
200
        $provider->addFormat('big', ['width' => 200, 'height' => 100, 'constraint' => true]);
201
202
        $media = new Media();
203
        $media->setBinaryContent('https://vimeo.com/012341231');
204
        $media->setId(1023456);
205
206
        $method = new \ReflectionMethod($provider, 'getMetadata');
207
        $method->setAccessible(true);
208
209
        $method->invokeArgs($provider, [$media, '012341231']);
210
    }
211
212
    public function testForm(): void
213
    {
214
        $provider = $this->getProvider();
215
216
        $admin = $this->createMock(AdminInterface::class);
217
        $admin
218
            ->method('trans')
219
            ->willReturn('message');
220
221
        $formMapper = $this->createMock(FormMapper::class);
222
        $formMapper->expects($this->exactly(8))
223
            ->method('add')
224
            ->willReturn(null);
225
226
        $provider->buildCreateForm($formMapper);
227
228
        $provider->buildEditForm($formMapper);
229
    }
230
231
    public function testHelperProperies(): void
232
    {
233
        $provider = $this->getProvider();
234
235
        $provider->addFormat('admin', ['width' => 100]);
236
        $media = new Media();
237
        $media->setName('Les tests');
238
        $media->setProviderReference('ASDASDAS.png');
239
        $media->setId(10);
240
        $media->setHeight(100);
241
        $media->setWidth(100);
242
243
        $properties = $provider->getHelperProperties($media, 'admin');
244
245
        $this->assertIsArray($properties);
246
        $this->assertSame(100, $properties['height']);
247
        $this->assertSame(100, $properties['width']);
248
    }
249
250
    public function testGetReferenceUrl(): void
251
    {
252
        $media = new Media();
253
        $media->setProviderReference('123456');
254
        $this->assertSame('https://vimeo.com/123456', $this->getProvider()->getReferenceUrl($media));
0 ignored issues
show
It seems like you code against a concrete implementation and not the interface Sonata\MediaBundle\Provider\MediaProviderInterface as the method getReferenceUrl() does only exist in the following implementations of said interface: Sonata\MediaBundle\Provider\DailyMotionProvider, Sonata\MediaBundle\Provider\VimeoProvider, Sonata\MediaBundle\Provider\YouTubeProvider.

Let’s take a look at an example:

interface User
{
    /** @return string */
    public function getPassword();
}

class MyUser implements User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the interface:

    interface User
    {
        /** @return string */
        public function getPassword();
    
        /** @return string */
        public function getDisplayName();
    }
    
Loading history...
255
    }
256
257
    public function testMetadata(): void
258
    {
259
        $provider = $this->getProvider();
260
261
        $this->assertSame('vimeo', $provider->getProviderMetadata()->getTitle());
262
        $this->assertSame('vimeo.description', $provider->getProviderMetadata()->getDescription());
263
        $this->assertNotNull($provider->getProviderMetadata()->getImage());
264
        $this->assertSame('fa fa-vimeo-square', $provider->getProviderMetadata()->getOption('class'));
265
        $this->assertSame('SonataMediaBundle', $provider->getProviderMetadata()->getDomain());
266
    }
267
}
268