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 |
||
|
0 ignored issues
–
show
|
|||
| 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'); |
||
| 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' |
||
| 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( |
||
| 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 | /* |
||
| 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 |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 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 |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 158 | { |
||
| 159 | public static $api_access = false; |
||
| 160 | |||
| 161 | public static $db = array( |
||
| 162 | 'Title' => 'Text', |
||
| 163 | 'Content' => 'HTMLText', |
||
| 164 | ); |
||
| 165 | } |
||
| 166 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.