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/VisibilityContext.php (6 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\Mink\Element\NodeElement;
6
use Behat\Mink\Exception\ExpectationException;
7
use Behat\Mink\Exception\UnsupportedDriverActionException;
8
9
/**
10
 * Class VisibilityContext.
11
 *
12
 * @package NuvoleWeb\Drupal\DrupalExtension\Context
13
 */
14
class VisibilityContext extends RawMinkContext {
15
16
  /**
17
   * Assert presence of given element on the page.
18
   *
19
   * @Then the element :tag with text :text should be visible
20
   */
21 View Code Duplication
  public function assertElementVisibility($tag, $text) {
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
    $element = $this->getSession()->getPage();
23
    /** @var \Behat\Mink\Element\NodeElement[] $nodes */
24
    $nodes = $element->findAll('css', $tag);
25
    foreach ($nodes as $node) {
26
      if ($node->getText() === $text) {
27
        $this->assertElementVisible($text, $node);
28
      }
29
    }
30
  }
31
32
  /**
33
   * Assert absence of given element on the page.
34
   *
35
   * @Then the element :tag with text :text should not be visible
36
   */
37 View Code Duplication
  public function assertElementNonVisibility($tag, $text) {
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...
38
    $element = $this->getSession()->getPage();
39
    /** @var \Behat\Mink\Element\NodeElement[] $nodes */
40
    $nodes = $element->findAll('css', $tag);
41
    foreach ($nodes as $node) {
42
      if ($node->getText() === $text) {
43
        $this->assertElementNotVisible($text, $node);
44
      }
45
    }
46
  }
47
48
  /**
49
   * Assert presence of given field on the page.
50
   *
51
   * @Then I should see the field :field
52
   */
53
  public function iShouldSeeTheField($field) {
54
    $element = $this->getSession()->getPage();
55
    $result = $element->findField($field);
56
    $this->assertElementVisible($field, $result);
0 ignored issues
show
It seems like $result defined by $element->findField($field) on line 55 can be null; however, NuvoleWeb\Drupal\DrupalE...:assertElementVisible() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
57
  }
58
59
  /**
60
   * Assert absence of given field.
61
   *
62
   * @Then I should not see the field :field
63
   */
64
  public function iShouldNotSeeTheField($field) {
65
    $element = $this->getSession()->getPage();
66
    $this->assertElementNotVisible($field, $element->findField($field));
0 ignored issues
show
It seems like $element->findField($field) can be null; however, assertElementNotVisible() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
67
  }
68
69
  /**
70
   * Assert visibility of an element.
71
   *
72
   * @param string $element
73
   *    Element selector or a string that describes it.
74
   * @param \Behat\Mink\Element\NodeElement $node
75
   *    Node representing the element above, if any.
76
   *
77
   * @throws \Behat\Mink\Exception\ExpectationException
78
   *    Throws exception if element not found.
79
   */
80 View Code Duplication
  protected function assertElementVisible($element, NodeElement $node) {
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...
81
    try {
82
      if ($node && !$node->isVisible()) {
83
        throw new ExpectationException(sprintf("The element '%s' is not present on the page %s", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
84
      }
85
    }
86
    catch (UnsupportedDriverActionException $e) {
87
      // We catch the UnsupportedDriverActionException exception in case
88
      // this step is not being performed by a driver that supports javascript.
89
      // All other exceptions are valid.
90
      if (empty($node)) {
91
        throw new ExpectationException(sprintf("The element '%s' is not present on the page %s", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
92
      }
93
    }
94
  }
95
96
  /**
97
   * Assert non visibility of an element.
98
   *
99
   * @param string $element
100
   *    Element selector or a string that describes it.
101
   * @param \Behat\Mink\Element\NodeElement $node
102
   *    Node representing the element above, if any.
103
   *
104
   * @throws \Behat\Mink\Exception\ExpectationException
105
   *    Throws exception if element is found.
106
   */
107 View Code Duplication
  protected function assertElementNotVisible($element, NodeElement $node) {
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...
108
    try {
109
      if ($node && $node->isVisible()) {
110
        throw new ExpectationException(sprintf("The field '%s' was present on the page %s and was not supposed to be", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
111
      }
112
    }
113
    catch (UnsupportedDriverActionException $e) {
114
      // We catch the UnsupportedDriverActionException exception in case
115
      // this step is not being performed by a driver that supports javascript.
116
      // All other exceptions are valid.
117
      if ($node) {
118
        throw new ExpectationException(sprintf("The field '%s' was present on the page %s and was not supposed to be", $element, $this->getSession()->getCurrentUrl()), $this->getSession());
119
      }
120
    }
121
  }
122
123
}
124