Issues (13)

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.

src/Tests/ImageBundleTest.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
namespace Drupal\media\Tests;
4
5
use Drupal\simpletest\WebTestBase;
6
7
/**
8
 * Ensures that media bundle for images can be created.
9
 *
10
 * @group media
11
 */
12
class ImageBundleTest extends WebTestBase {
13
  /**
14
   * Exempt from strict schema checking.
15
   *
16
   * @see \Drupal\Core\Config\Testing\ConfigSchemaChecker
17
   *
18
   * @var bool
19
   */
20
  protected $strictConfigSchema = FALSE;
21
22
  /**
23
   * Modules to enable.
24
   *
25
   * @var array
26
   */
27
  public static $modules = [
28
    'media',
29
    'media_entity',
30
    'media_entity_image',
31
    'image',
32
    'node',
33
    'editor',
34
  ];
35
36
  /**
37
   * The test media bundle.
38
   *
39
   * @var \Drupal\media_entity\MediaBundleInterface
40
   */
41
  protected $testBundle;
42
43
  /**
44
   * {@inheritdoc}
45
   */
46 View Code Duplication
  protected function setUp() {
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...
47
    parent::setUp();
48
    $this->testBundle = $this->container->get('entity.manager')->getStorage('media_bundle')->load('image');
49
50
    $adminUser = $this->drupalCreateUser([
51
      'view media',
52
      'create media',
53
      'update media',
54
      'update any media',
55
      'delete media',
56
      'delete any media',
57
      'access media overview',
58
    ]);
59
    $this->drupalLogin($adminUser);
60
  }
61
62
  /**
63
   * Tests image media bundle creation from config files.
64
   */
65 View Code Duplication
  public function testMediaBundleCreationFromModule() {
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...
66
    $type_configuration = [
67
      'source_field' => 'field_image',
68
      'gather_exif' => FALSE,
69
    ];
70
71
    $this->assertTrue((bool) $this->testBundle, 'The media bundle from default configuration has been created in the database.');
72
    $this->assertEqual($this->testBundle->get('label'), 'Image', 'Correct label detected.');
73
    $this->assertEqual($this->testBundle->get('description'), 'Use Image for uploading locally hosted images.', 'Correct description detected.');
74
    $this->assertEqual($this->testBundle->get('type'), 'image', 'Correct plugin ID detected.');
75
    $this->assertEqual($this->testBundle->get('type_configuration'), $type_configuration, 'Type configuration correct.');
76
    $this->assertEqual($this->testBundle->get('field_map'), [], 'Correct field map detected.');
77
  }
78
79
  /**
80
   * Tests item creation and thumbnail.
81
   */
82
  public function testMediaBundleItemCreation() {
83
    // Define the media item name.
84
    $name = $this->randomMachineName();
85
    $image_files = $this->drupalGetTestFiles('image');
86
    $testImage = current($image_files);
87
    $file_path = $this->container->get('file_system')->realpath($testImage->uri);
88
    $edit = [
89
      'name[0][value]' => $name,
90
      'files[field_image_0]' => $file_path,
91
    ];
92
93
    // Save the image.
94
    $this->drupalPostForm('media/add/' . $this->testBundle->id(), $edit, t('Save and publish'));
95
    $this->drupalPostForm(NULL, ['field_image[0][alt]' => $name], t('Save and publish'));
96
97
    // Let's retrieve the media id and corresponding media entity object.
98
    $media_id = $this->container->get('entity.query')->get('media')->execute();
99
    $media_id = reset($media_id);
100
    /** @var \Drupal\media_entity\MediaInterface $media */
101
    $media = $this->container->get('entity_type.manager')
102
        ->getStorage('media')
103
        ->loadUnchanged($media_id);
104
    $this->assertEqual($media->get('name')[0]->getValue()['value'], $name, "Correct name stored.");
105
    $image = $media->getType();
106
    $thumbnail = $image->thumbnail($media);
107
    $default_thumbnail = $image->getDefaultThumbnail();
108
    $this->assertNotEqual($thumbnail, $default_thumbnail, "The thumbnail generated is different from the default thumbnail.");
109
  }
110
111
}
112