This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * @todo Test Relation getters |
||
4 | * @todo Test filter and limit through GET params |
||
5 | * @todo Test DELETE verb |
||
6 | */ |
||
7 | class SoapModelAccessTest extends SapphireTest |
||
8 | { |
||
9 | public static $fixture_file = 'SoapModelAccessTest.yml'; |
||
10 | |||
11 | protected $extraDataObjects = array( |
||
12 | 'SoapModelAccessTest_Comment', |
||
13 | 'SoapModelAccessTest_Page', |
||
14 | ); |
||
15 | |||
16 | public function getTestSoapConnection() |
||
17 | { |
||
18 | // We can't actually test the SOAP server itself because there's not currently a way of putting it into "test mode" |
||
19 | return new SOAPModelAccess(); |
||
20 | |||
21 | // One day, we should build this facility and then return something more like the item below: |
||
22 | // return new SoapClient(Director::absoluteBaseURL() . 'soap/v1/wsdl'); |
||
0 ignored issues
–
show
|
|||
23 | } |
||
24 | |||
25 | public function testApiAccess() |
||
26 | { |
||
27 | $c = $this->getTestSoapConnection(); |
||
28 | $soapResponse = $c->getXML( |
||
29 | 'SoapModelAccessTest_Comment', |
||
30 | 1, |
||
31 | null, |
||
32 | null, |
||
33 | '[email protected]', |
||
34 | 'editor' |
||
0 ignored issues
–
show
The call to
SOAPModelAccess::getXML() has too many arguments starting with 'editor' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
|||
35 | ); |
||
36 | |||
37 | $responseArr = Convert::xml2array($soapResponse); |
||
38 | $this->assertEquals($responseArr['ID'], 1); |
||
39 | $this->assertEquals($responseArr['Name'], 'Joe'); |
||
40 | } |
||
41 | |||
42 | public function testAuthenticatedPUT() |
||
43 | { |
||
44 | $comment1 = $this->objFromFixture('SoapModelAccessTest_Comment', 'comment1'); |
||
45 | $comment1ID = $comment1->ID; |
||
46 | |||
47 | // test wrong details |
||
48 | $c = $this->getTestSoapConnection(); |
||
49 | |||
50 | $updateXML = <<<XML |
||
51 | <?xml version="1.0" encoding="UTF-8"?> |
||
52 | <SoapModelAccessTest_Comment> |
||
53 | <ID>$comment1ID</ID> |
||
54 | <Name>Jimmy</Name> |
||
55 | </SoapModelAccessTest_Comment> |
||
56 | XML; |
||
57 | |||
58 | $soapResponse = $c->putXML( |
||
59 | 'SoapModelAccessTest_Comment', |
||
60 | $comment1->ID, |
||
61 | null, |
||
62 | $updateXML, |
||
63 | '[email protected]', |
||
64 | 'wrongpassword' |
||
65 | ); |
||
66 | $this->assertEquals('<error type="authentication" code="401">Unauthorized</error>', $soapResponse); |
||
67 | |||
68 | // Check that the details weren't saved |
||
69 | $c = $this->getTestSoapConnection(); |
||
70 | $soapResponse = $c->getXML('SoapModelAccessTest_Comment', $comment1->ID, null, '[email protected]', 'editor'); |
||
71 | $responseArr = Convert::xml2array($soapResponse); |
||
72 | $this->assertEquals($comment1->ID, $responseArr['ID']); |
||
73 | $this->assertEquals('Joe', $responseArr['Name']); |
||
74 | |||
75 | // Now do an update with the right password |
||
76 | $soapResponse = $c->putXML( |
||
0 ignored issues
–
show
$soapResponse 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 ![]() |
|||
77 | 'SoapModelAccessTest_Comment', |
||
78 | $comment1->ID, |
||
79 | null, |
||
80 | $updateXML, |
||
81 | '[email protected]', |
||
82 | 'editor' |
||
83 | ); |
||
84 | |||
85 | // Check that the details were saved |
||
86 | $c = $this->getTestSoapConnection(); |
||
87 | $soapResponse = $c->getXML('SoapModelAccessTest_Comment', $comment1->ID, null, '[email protected]', 'editor'); |
||
88 | $responseArr = Convert::xml2array($soapResponse); |
||
89 | $this->assertEquals($comment1->ID, $responseArr['ID']); |
||
90 | $this->assertEquals('Jimmy', $responseArr['Name']); |
||
91 | } |
||
92 | |||
93 | public function testAuthenticatedPOST() |
||
94 | { |
||
95 | /* |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
61% 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. ![]() |
|||
96 | $c = $this->getTestSoapConnection(); |
||
97 | $soapResponse = $c->getXML( |
||
98 | "SoapModelAccessTest_Comment", |
||
99 | null, |
||
100 | null, |
||
101 | '[email protected]', |
||
102 | 'editor' |
||
103 | ); |
||
104 | Debug::message($soapResponse); |
||
105 | $responseArr = Convert::xml2array($soapResponse); |
||
106 | Debug::show($responseArr); |
||
107 | $this->assertEquals($responseArr['Name'], 'Created Name'); |
||
108 | */ |
||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Everybody can view comments, logged in members in the "users" group can create comments, |
||
114 | * but only "editors" can edit or delete them. |
||
115 | */ |
||
116 | class SoapModelAccessTest_Comment extends DataObject implements PermissionProvider,TestOnly |
||
117 | { |
||
118 | public static $api_access = true; |
||
119 | |||
120 | public static $db = array( |
||
121 | 'Name' => 'Varchar(255)', |
||
122 | 'Comment' => 'Text', |
||
123 | ); |
||
124 | |||
125 | public static $has_many = array(); |
||
126 | |||
127 | public function providePermissions() |
||
128 | { |
||
129 | return array( |
||
130 | 'EDIT_Comment' => 'Edit Comment Objects', |
||
131 | 'CREATE_Comment' => 'Create Comment Objects', |
||
132 | 'DELETE_Comment' => 'Delete Comment Objects', |
||
133 | ); |
||
134 | } |
||
135 | |||
136 | public function canView($member = null) |
||
137 | { |
||
138 | return true; |
||
139 | } |
||
140 | |||
141 | public function canEdit($member = null) |
||
142 | { |
||
143 | return Permission::checkMember($member, 'EDIT_Comment'); |
||
144 | } |
||
145 | |||
146 | public function canDelete($member = null) |
||
147 | { |
||
148 | return Permission::checkMember($member, 'DELETE_Comment'); |
||
149 | } |
||
150 | |||
151 | public function canCreate($member = null) |
||
152 | { |
||
153 | return Permission::checkMember($member, 'CREATE_Comment'); |
||
154 | } |
||
155 | } |
||
156 | |||
157 | class SoapModelAccessTest_Page extends DataObject implements TestOnly |
||
158 | { |
||
159 | public static $api_access = false; |
||
160 | |||
161 | public static $db = array( |
||
162 | 'Title' => 'Text', |
||
163 | 'Content' => 'HTMLText', |
||
164 | ); |
||
165 | } |
||
166 |
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.