Issues (67)

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.

src/DrupalExtension/Context/SelectFieldContext.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 NuvoleWeb\Drupal\DrupalExtension\Context;
4
5
use Behat\Gherkin\Node\TableNode;
6
use Behat\Mink\Element\NodeElement;
7
use Behat\Mink\Exception\ExpectationException;
8
9
/**
10
 * Class SelectFieldContext.
11
 *
12
 * @package NuvoleWeb\Drupal\DrupalExtension\Context
13
 */
14
class SelectFieldContext extends RawMinkContext {
15
16
  /**
17
   * Checks that the given select field has the options listed in the table.
18
   *
19
   * @Then I should have the following options for :select:
20
   */
21 View Code Duplication
  public function assertSelectOptions($select, TableNode $options) {
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...
22
    // Retrieve the specified field.
23
    if (!$field = $this->getSession()->getPage()->findField($select)) {
24
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
25
    }
26
27
    /* @var \Behat\Mink\Element\NodeElement $field */
28
29
    // Check that the specified field is a <select> field.
30
    $this->assertElementType($field, 'select');
31
32
    // Retrieve the options table from the test scenario and flatten it.
33
    $expected_options = $options->getColumnsHash();
34
    array_walk($expected_options, function (&$value) {
35
      $value = reset($value);
36
    });
37
38
    // Retrieve the actual options that are shown in the page.
39
    $actual_options = $field->findAll('css', 'option');
40
41
    // Convert into a flat list of option text strings.
42
    array_walk($actual_options, function (NodeElement &$value) {
43
      $value = $value->getText();
44
    });
45
46
    // Check that all expected options are present.
47
    foreach ($expected_options as $expected_option) {
48
      if (!in_array($expected_option, $actual_options)) {
49
        throw new ExpectationException("Option '$expected_option' is missing from select list '$select'.", $this->getSession());
50
      }
51
    }
52
  }
53
54
  /**
55
   * Checks that the given select field doesn't have the listed options.
56
   *
57
   * @Then I should not have the following options for :select:
58
   */
59 View Code Duplication
  public function assertNoSelectOptions($select, TableNode $options) {
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...
60
    // Retrieve the specified field.
61
    if (!$field = $this->getSession()->getPage()->findField($select)) {
62
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
63
    }
64
65
    /* @var \Behat\Mink\Element\NodeElement $field */
66
67
    // Check that the specified field is a <select> field.
68
    $this->assertElementType($field, 'select');
69
70
    // Retrieve the options table from the test scenario and flatten it.
71
    $expected_options = $options->getColumnsHash();
72
    array_walk($expected_options, function (&$value) {
73
      $value = reset($value);
74
    });
75
76
    // Retrieve the actual options that are shown in the page.
77
    $actual_options = $field->findAll('css', 'option');
78
79
    // Convert into a flat list of option text strings.
80
    array_walk($actual_options, function (NodeElement &$value) {
81
      $value = $value->getText();
82
    });
83
84
    // Check that none of the expected options are present.
85
    foreach ($expected_options as $expected_option) {
86
      if (in_array($expected_option, $actual_options)) {
87
        throw new ExpectationException("Option '$expected_option' is unexpectedly found in select list '$select'.", $this->getSession());
88
      }
89
    }
90
  }
91
92
  /**
93
   * Assert that given option field is selected.
94
   *
95
   * @Then the option :option_label from select :select is selected
96
   */
97
  public function theOptionFromIsSelected($select, $option_label) {
98
    $this->getSelectedOptionByLabel($select, $option_label);
99
  }
100
101
  /**
102
   * Assert that given option field is not selected.
103
   *
104
   * @Then the option :option_label from select :select is not selected
105
   */
106
  public function theOptionFromIsNotSelected($select, $option_label) {
107
    $this->getSelectedOptionByLabel($select, $option_label, FALSE);
108
  }
109
110
  /**
111
   * Returns an option from a specific select.
112
   *
113
   * @param string $select
114
   *   The select name.
115
   * @param string $option_label
116
   *   The option text.
117
   * @param bool $check_selected
118
   *   (optional) If TRUE, will check for selected option, if FALSE for
119
   *   unselected. Defaults to TRUE.
120
   *
121
   * @return \Behat\Mink\Element\NodeElement|null
122
   *   The node element or NULL.
123
   *
124
   * @throws \Behat\Mink\Exception\ExpectationException
125
   */
126
  protected function getSelectedOptionByLabel($select, $option_label, $check_selected = TRUE) {
127
    if (!$field = $this->getSession()->getPage()->findField($select)) {
128
      throw new ExpectationException("Field '$select' not found.", $this->getSession());
129
    }
130
131
    /* @var \Behat\Mink\Element\NodeElement $field */
132
133
    // Check that the specified field is a <select> field.
134
    $this->assertElementType($field, 'select');
135
136
    $options = $field->findAll('css', 'option');
137
    $options = array_filter($options, function (NodeElement $option) use ($option_label) {
138
      return $option->getText() == $option_label ? $option : FALSE;
139
    });
140
141
    if (!($option = $options ? reset($options) : NULL)) {
142
      throw new ExpectationException("Option '$option_label' doesn't exist in '$select' select.", $this->getSession());
143
    }
144
145
    return $check_selected ? $option->isSelected() : !$option->isSelected();
146
  }
147
148
}
149