Issues (248)

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/SearchableFieldTest.php (12 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
 * Test the functionality of the Searchable extension
5
 * @package elastica
6
 */
7
class SearchableFieldTest extends ElasticsearchBaseTest {
8
	public static $fixture_file = 'elastica/tests/ElasticaTest.yml';
9
10
	public function testCMSFields() {
11
		$sf = new SearchableField();
12
		$sf->Name = 'TestField';
0 ignored issues
show
The property Name does not exist on object<SearchableField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
13
		$sf->ClazzName = 'TestClazz';
0 ignored issues
show
The property ClazzName does not exist on object<SearchableField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
14
		$sf->write();
15
16
		$fields = $sf->getCMSFields();
17
18
		$tab = $this->checkTabExists($fields,'Main');
19
20
		//Check fields
21
		$nf = $this->checkFieldExists($tab, 'Name');
22
		$this->assertTrue($nf->isDisabled());
23
	}
24
25
26
27
28
	/* Zero weight is pointless as it means not part of the search */
29 View Code Duplication
	public function testZeroWeight() {
30
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
31
		$lastEdited = $searchPage->LastEdited;
32
33
		$extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1,
34
			'Weight' => 0);
35
		$esfs = $searchPage->ElasticaSearchableFields();
0 ignored issues
show
The method ElasticaSearchableFields() does not exist on DataObject. Did you maybe mean searchableFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
36
		foreach ($esfs as $sf) {
37
			if ($sf->Name == 'Title' || $sf->Name == 'Description') {
38
				$esfs->remove($sf);
39
				$esfs->add($sf, $extraFields);
40
			}
41
		}
42
43
		try {
44
			$searchPage->write();
45
			$this->fail('Searchable fail should have failed to write');
46
		} catch (ValidationException $e) {
47
			$this->assertInstanceOf('ValidationException', $e);
0 ignored issues
show
The method assertInstanceOf() does not seem to exist on object<SearchableFieldTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
48
			$expected = 'The field SearchableTestPage.Title has a zero weight. ; The field '.
49
			'SiteTree.Title has a zero weight. ; The field Page.Title has a zero weight. ';
50
			$this->assertEquals($expected, $e->getMessage());
51
		}
52
53
		//Effectively assert that the search page has not been written by checking LastEdited
54
		$pageFromDB = DataObject::get_by_id('ElasticSearchPage', $searchPage->ID);
55
		$this->assertEquals($lastEdited, $pageFromDB->LastEdited);
56
	}
57
58
59
	/* Weights must be positive */
60 View Code Duplication
	public function testNegativeWeight() {
61
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
62
		$lastEdited = $searchPage->LastEdited;
63
64
		$extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1,
65
			'Weight' => -1);
66
		$esfs = $searchPage->ElasticaSearchableFields();
0 ignored issues
show
The method ElasticaSearchableFields() does not exist on DataObject. Did you maybe mean searchableFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
67
		foreach ($esfs as $sf) {
68
			if ($sf->Name == 'Title' || $sf->Name == 'Description') {
69
				$esfs->remove($sf);
70
				$esfs->add($sf, $extraFields);
71
			}
72
		}
73
74
		try {
75
			$searchPage->write();
76
			$this->fail('Searchable fail should have failed to write');
77
		} catch (ValidationException $e) {
78
			$this->assertInstanceOf('ValidationException', $e);
79
			$expected = 'The field SearchableTestPage.Title has a negative weight. ; The field '.
80
			'SiteTree.Title has a negative weight. ; The field Page.Title has a negative weight. ';
81
			$this->assertEquals($expected, $e->getMessage());
82
		}
83
		//Effectively assert that the search page has not been written by checking LastEdited
84
		$pageFromDB = DataObject::get_by_id('ElasticSearchPage', $searchPage->ID);
85
		$this->assertEquals($lastEdited, $pageFromDB->LastEdited);
86
	}
87
88
89
	public function testDefaultWeight() {
90
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
91
		//$searchPage->write();
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
92
		$sf = $searchPage->ElasticaSearchableFields()->first();
0 ignored issues
show
The method ElasticaSearchableFields() does not exist on DataObject. Did you maybe mean searchableFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
93
		$this->assertEquals(1, $sf->Weight);
94
		$this->assertTrue($sf->ID > 0);
95
	}
96
97
98
	public function testPositiveWeight() {
99
		$sf = new SearchableField();
100
		$sf->Name = 'TestField';
0 ignored issues
show
The property Name does not exist on object<SearchableField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
101
		$sf->Weight = 10;
0 ignored issues
show
The property Weight does not exist on object<SearchableField>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
102
		$sf->write();
103
		$this->assertEquals(10, $sf->Weight);
0 ignored issues
show
The property Weight does not exist on object<SearchableField>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
104
		$this->assertTrue($sf->ID > 0);
105
	}
106
107
108
	public function testHumanReadableSearchable() {
109
110
		$searchPage = $this->objFromFixture('ElasticSearchPage', 'search');
111
112
		//ensure valid
113
		$extraFields = array('Searchable' => 1, 'SimilarSearchable' => 1, 'Active' => 1,
0 ignored issues
show
$extraFields is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
114
			'Weight' => 1);
115
		$sf = $searchPage->ElasticaSearchableFields()->first();
0 ignored issues
show
The method ElasticaSearchableFields() does not exist on DataObject. Did you maybe mean searchableFields()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
116
117
118
		$sf->Name = 'TestField';
119
		$sf->Searchable = false;
120
		$this->assertEquals('No', $sf->HumanReadableSearchable());
121
		$sf->Searchable = true;
122
		$this->assertEquals('Yes', $sf->HumanReadableSearchable());
123
	}
124
125
126
	// ---- searchable fields are created via a script, so test do not allow creation/deletion ----
127
128
	/*
129
	Ensure CMS users cannot delete searchable fields
130
	 */
131
	public function testCanDelete() {
132
		$sf = new SearchableField();
133
		$this->assertFalse($sf->canDelete());
134
	}
135
136
	/*
137
	Ensure CMS users cannot create searchable fields
138
	 */
139
	public function testCanCreate() {
140
		$sf = new SearchableField();
141
		$this->assertFalse($sf->canCreate());
142
	}
143
144
145
}
146