Provisioning.php 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. /**
  3. *
  4. * @author Joas Schilling <coding@schilljs.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Roeland Jago Douma <roeland@famdouma.nl>
  7. * @author Sergio Bertolin <sbertolin@solidgear.es>
  8. * @author Sergio Bertolín <sbertolin@solidgear.es>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. * @author Vincent Petry <pvince81@owncloud.com>
  11. *
  12. * @license GNU AGPL version 3 or any later version
  13. *
  14. * This program is free software: you can redistribute it and/or modify
  15. * it under the terms of the GNU Affero General Public License as
  16. * published by the Free Software Foundation, either version 3 of the
  17. * License, or (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26. *
  27. */
  28. use GuzzleHttp\Client;
  29. use GuzzleHttp\Message\ResponseInterface;
  30. require __DIR__ . '/../../vendor/autoload.php';
  31. trait Provisioning {
  32. use BasicStructure;
  33. /** @var array */
  34. private $createdUsers = [];
  35. /** @var array */
  36. private $createdRemoteUsers = [];
  37. /** @var array */
  38. private $createdRemoteGroups = [];
  39. /** @var array */
  40. private $createdGroups = [];
  41. /**
  42. * @Given /^user "([^"]*)" exists$/
  43. * @param string $user
  44. */
  45. public function assureUserExists($user) {
  46. try {
  47. $this->userExists($user);
  48. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  49. $previous_user = $this->currentUser;
  50. $this->currentUser = "admin";
  51. $this->creatingTheUser($user);
  52. $this->currentUser = $previous_user;
  53. }
  54. $this->userExists($user);
  55. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  56. }
  57. /**
  58. * @Given /^user "([^"]*)" does not exist$/
  59. * @param string $user
  60. */
  61. public function userDoesNotExist($user) {
  62. try {
  63. $this->userExists($user);
  64. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  65. $this->response = $ex->getResponse();
  66. PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
  67. return;
  68. }
  69. $previous_user = $this->currentUser;
  70. $this->currentUser = "admin";
  71. $this->deletingTheUser($user);
  72. $this->currentUser = $previous_user;
  73. try {
  74. $this->userExists($user);
  75. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  76. $this->response = $ex->getResponse();
  77. PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
  78. }
  79. }
  80. public function creatingTheUser($user) {
  81. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users";
  82. $client = new Client();
  83. $options = [];
  84. if ($this->currentUser === 'admin') {
  85. $options['auth'] = $this->adminUser;
  86. }
  87. $options['body'] = [
  88. 'userid' => $user,
  89. 'password' => '123456'
  90. ];
  91. $options['headers'] = [
  92. 'OCS-APIREQUEST' => 'true',
  93. ];
  94. $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
  95. if ($this->currentServer === 'LOCAL'){
  96. $this->createdUsers[$user] = $user;
  97. } elseif ($this->currentServer === 'REMOTE') {
  98. $this->createdRemoteUsers[$user] = $user;
  99. }
  100. //Quick hack to login once with the current user
  101. $options2 = [
  102. 'auth' => [$user, '123456'],
  103. ];
  104. $options2['headers'] = [
  105. 'OCS-APIREQUEST' => 'true',
  106. ];
  107. $url = $fullUrl.'/'.$user;
  108. $client->send($client->createRequest('GET', $url, $options2));
  109. }
  110. public function createUser($user) {
  111. $previous_user = $this->currentUser;
  112. $this->currentUser = "admin";
  113. $this->creatingTheUser($user);
  114. $this->userExists($user);
  115. $this->currentUser = $previous_user;
  116. }
  117. public function deleteUser($user) {
  118. $previous_user = $this->currentUser;
  119. $this->currentUser = "admin";
  120. $this->deletingTheUser($user);
  121. $this->userDoesNotExist($user);
  122. $this->currentUser = $previous_user;
  123. }
  124. public function createGroup($group) {
  125. $previous_user = $this->currentUser;
  126. $this->currentUser = "admin";
  127. $this->creatingTheGroup($group);
  128. $this->groupExists($group);
  129. $this->currentUser = $previous_user;
  130. }
  131. public function deleteGroup($group) {
  132. $previous_user = $this->currentUser;
  133. $this->currentUser = "admin";
  134. $this->deletingTheGroup($group);
  135. $this->groupDoesNotExist($group);
  136. $this->currentUser = $previous_user;
  137. }
  138. public function userExists($user){
  139. $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user";
  140. $client = new Client();
  141. $options = [];
  142. $options['auth'] = $this->adminUser;
  143. $options['headers'] = [
  144. 'OCS-APIREQUEST' => 'true'
  145. ];
  146. $this->response = $client->get($fullUrl, $options);
  147. }
  148. /**
  149. * @Then /^check that user "([^"]*)" belongs to group "([^"]*)"$/
  150. * @param string $user
  151. * @param string $group
  152. */
  153. public function checkThatUserBelongsToGroup($user, $group) {
  154. $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
  155. $client = new Client();
  156. $options = [];
  157. if ($this->currentUser === 'admin') {
  158. $options['auth'] = $this->adminUser;
  159. }
  160. $options['headers'] = [
  161. 'OCS-APIREQUEST' => 'true',
  162. ];
  163. $this->response = $client->get($fullUrl, $options);
  164. $respondedArray = $this->getArrayOfGroupsResponded($this->response);
  165. sort($respondedArray);
  166. PHPUnit_Framework_Assert::assertContains($group, $respondedArray);
  167. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  168. }
  169. public function userBelongsToGroup($user, $group) {
  170. $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
  171. $client = new Client();
  172. $options = [];
  173. if ($this->currentUser === 'admin') {
  174. $options['auth'] = $this->adminUser;
  175. }
  176. $options['headers'] = [
  177. 'OCS-APIREQUEST' => 'true',
  178. ];
  179. $this->response = $client->get($fullUrl, $options);
  180. $respondedArray = $this->getArrayOfGroupsResponded($this->response);
  181. if (array_key_exists($group, $respondedArray)) {
  182. return True;
  183. } else{
  184. return False;
  185. }
  186. }
  187. /**
  188. * @Given /^user "([^"]*)" belongs to group "([^"]*)"$/
  189. * @param string $user
  190. * @param string $group
  191. */
  192. public function assureUserBelongsToGroup($user, $group){
  193. $previous_user = $this->currentUser;
  194. $this->currentUser = "admin";
  195. if (!$this->userBelongsToGroup($user, $group)){
  196. $this->addingUserToGroup($user, $group);
  197. }
  198. $this->checkThatUserBelongsToGroup($user, $group);
  199. $this->currentUser = $previous_user;
  200. }
  201. /**
  202. * @Given /^user "([^"]*)" does not belong to group "([^"]*)"$/
  203. * @param string $user
  204. * @param string $group
  205. */
  206. public function userDoesNotBelongToGroup($user, $group) {
  207. $fullUrl = $this->baseUrl . "v2.php/cloud/users/$user/groups";
  208. $client = new Client();
  209. $options = [];
  210. if ($this->currentUser === 'admin') {
  211. $options['auth'] = $this->adminUser;
  212. }
  213. $options['headers'] = [
  214. 'OCS-APIREQUEST' => 'true',
  215. ];
  216. $this->response = $client->get($fullUrl, $options);
  217. $groups = array($group);
  218. $respondedArray = $this->getArrayOfGroupsResponded($this->response);
  219. PHPUnit_Framework_Assert::assertNotEquals($groups, $respondedArray, "", 0.0, 10, true);
  220. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  221. }
  222. /**
  223. * @When /^creating the group "([^"]*)"$/
  224. * @param string $group
  225. */
  226. public function creatingTheGroup($group) {
  227. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups";
  228. $client = new Client();
  229. $options = [];
  230. if ($this->currentUser === 'admin') {
  231. $options['auth'] = $this->adminUser;
  232. }
  233. $options['body'] = [
  234. 'groupid' => $group,
  235. ];
  236. $options['headers'] = [
  237. 'OCS-APIREQUEST' => 'true',
  238. ];
  239. $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
  240. if ($this->currentServer === 'LOCAL'){
  241. $this->createdGroups[$group] = $group;
  242. } elseif ($this->currentServer === 'REMOTE') {
  243. $this->createdRemoteGroups[$group] = $group;
  244. }
  245. }
  246. /**
  247. * @When /^assure user "([^"]*)" is disabled$/
  248. */
  249. public function assureUserIsDisabled($user) {
  250. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/disable";
  251. $client = new Client();
  252. $options = [];
  253. if ($this->currentUser === 'admin') {
  254. $options['auth'] = $this->adminUser;
  255. }
  256. $options['headers'] = [
  257. 'OCS-APIREQUEST' => 'true',
  258. ];
  259. // TODO: fix hack
  260. $options['body'] = [
  261. 'foo' => 'bar'
  262. ];
  263. $this->response = $client->send($client->createRequest("PUT", $fullUrl, $options));
  264. }
  265. /**
  266. * @When /^Deleting the user "([^"]*)"$/
  267. * @param string $user
  268. */
  269. public function deletingTheUser($user) {
  270. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
  271. $client = new Client();
  272. $options = [];
  273. if ($this->currentUser === 'admin') {
  274. $options['auth'] = $this->adminUser;
  275. }
  276. $options['headers'] = [
  277. 'OCS-APIREQUEST' => 'true',
  278. ];
  279. $this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
  280. }
  281. /**
  282. * @When /^Deleting the group "([^"]*)"$/
  283. * @param string $group
  284. */
  285. public function deletingTheGroup($group) {
  286. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/groups/$group";
  287. $client = new Client();
  288. $options = [];
  289. if ($this->currentUser === 'admin') {
  290. $options['auth'] = $this->adminUser;
  291. }
  292. $options['headers'] = [
  293. 'OCS-APIREQUEST' => 'true',
  294. ];
  295. $this->response = $client->send($client->createRequest("DELETE", $fullUrl, $options));
  296. }
  297. /**
  298. * @Given /^Add user "([^"]*)" to the group "([^"]*)"$/
  299. * @param string $user
  300. * @param string $group
  301. */
  302. public function addUserToGroup($user, $group) {
  303. $this->userExists($user);
  304. $this->groupExists($group);
  305. $this->addingUserToGroup($user, $group);
  306. }
  307. /**
  308. * @When /^User "([^"]*)" is added to the group "([^"]*)"$/
  309. * @param string $user
  310. * @param string $group
  311. */
  312. public function addingUserToGroup($user, $group) {
  313. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/groups";
  314. $client = new Client();
  315. $options = [];
  316. if ($this->currentUser === 'admin') {
  317. $options['auth'] = $this->adminUser;
  318. }
  319. $options['headers'] = [
  320. 'OCS-APIREQUEST' => 'true',
  321. ];
  322. $options['body'] = [
  323. 'groupid' => $group,
  324. ];
  325. $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
  326. }
  327. public function groupExists($group) {
  328. $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group";
  329. $client = new Client();
  330. $options = [];
  331. $options['auth'] = $this->adminUser;
  332. $options['headers'] = [
  333. 'OCS-APIREQUEST' => 'true',
  334. ];
  335. $this->response = $client->get($fullUrl, $options);
  336. }
  337. /**
  338. * @Given /^group "([^"]*)" exists$/
  339. * @param string $group
  340. */
  341. public function assureGroupExists($group) {
  342. try {
  343. $this->groupExists($group);
  344. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  345. $previous_user = $this->currentUser;
  346. $this->currentUser = "admin";
  347. $this->creatingTheGroup($group);
  348. $this->currentUser = $previous_user;
  349. }
  350. $this->groupExists($group);
  351. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  352. }
  353. /**
  354. * @Given /^group "([^"]*)" does not exist$/
  355. * @param string $group
  356. */
  357. public function groupDoesNotExist($group) {
  358. try {
  359. $this->groupExists($group);
  360. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  361. $this->response = $ex->getResponse();
  362. PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
  363. return;
  364. }
  365. $previous_user = $this->currentUser;
  366. $this->currentUser = "admin";
  367. $this->deletingTheGroup($group);
  368. $this->currentUser = $previous_user;
  369. try {
  370. $this->groupExists($group);
  371. } catch (\GuzzleHttp\Exception\ClientException $ex) {
  372. $this->response = $ex->getResponse();
  373. PHPUnit_Framework_Assert::assertEquals(404, $ex->getResponse()->getStatusCode());
  374. }
  375. }
  376. /**
  377. * @Given /^user "([^"]*)" is subadmin of group "([^"]*)"$/
  378. * @param string $user
  379. * @param string $group
  380. */
  381. public function userIsSubadminOfGroup($user, $group) {
  382. $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
  383. $client = new Client();
  384. $options = [];
  385. if ($this->currentUser === 'admin') {
  386. $options['auth'] = $this->adminUser;
  387. }
  388. $options['headers'] = [
  389. 'OCS-APIREQUEST' => 'true',
  390. ];
  391. $this->response = $client->get($fullUrl, $options);
  392. $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
  393. sort($respondedArray);
  394. PHPUnit_Framework_Assert::assertContains($user, $respondedArray);
  395. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  396. }
  397. /**
  398. * @Given /^Assure user "([^"]*)" is subadmin of group "([^"]*)"$/
  399. * @param string $user
  400. * @param string $group
  401. */
  402. public function assureUserIsSubadminOfGroup($user, $group) {
  403. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user/subadmins";
  404. $client = new Client();
  405. $options = [];
  406. if ($this->currentUser === 'admin') {
  407. $options['auth'] = $this->adminUser;
  408. }
  409. $options['body'] = [
  410. 'groupid' => $group
  411. ];
  412. $options['headers'] = [
  413. 'OCS-APIREQUEST' => 'true',
  414. ];
  415. $this->response = $client->send($client->createRequest("POST", $fullUrl, $options));
  416. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  417. }
  418. /**
  419. * @Given /^user "([^"]*)" is not a subadmin of group "([^"]*)"$/
  420. * @param string $user
  421. * @param string $group
  422. */
  423. public function userIsNotSubadminOfGroup($user, $group) {
  424. $fullUrl = $this->baseUrl . "v2.php/cloud/groups/$group/subadmins";
  425. $client = new Client();
  426. $options = [];
  427. if ($this->currentUser === 'admin') {
  428. $options['auth'] = $this->adminUser;
  429. }
  430. $options['headers'] = [
  431. 'OCS-APIREQUEST' => 'true',
  432. ];
  433. $this->response = $client->get($fullUrl, $options);
  434. $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
  435. sort($respondedArray);
  436. PHPUnit_Framework_Assert::assertNotContains($user, $respondedArray);
  437. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  438. }
  439. /**
  440. * @Then /^users returned are$/
  441. * @param \Behat\Gherkin\Node\TableNode|null $usersList
  442. */
  443. public function theUsersShouldBe($usersList) {
  444. if ($usersList instanceof \Behat\Gherkin\Node\TableNode) {
  445. $users = $usersList->getRows();
  446. $usersSimplified = $this->simplifyArray($users);
  447. $respondedArray = $this->getArrayOfUsersResponded($this->response);
  448. PHPUnit_Framework_Assert::assertEquals($usersSimplified, $respondedArray, "", 0.0, 10, true);
  449. }
  450. }
  451. /**
  452. * @Then /^groups returned are$/
  453. * @param \Behat\Gherkin\Node\TableNode|null $groupsList
  454. */
  455. public function theGroupsShouldBe($groupsList) {
  456. if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
  457. $groups = $groupsList->getRows();
  458. $groupsSimplified = $this->simplifyArray($groups);
  459. $respondedArray = $this->getArrayOfGroupsResponded($this->response);
  460. PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
  461. }
  462. }
  463. /**
  464. * @Then /^subadmin groups returned are$/
  465. * @param \Behat\Gherkin\Node\TableNode|null $groupsList
  466. */
  467. public function theSubadminGroupsShouldBe($groupsList) {
  468. if ($groupsList instanceof \Behat\Gherkin\Node\TableNode) {
  469. $groups = $groupsList->getRows();
  470. $groupsSimplified = $this->simplifyArray($groups);
  471. $respondedArray = $this->getArrayOfSubadminsResponded($this->response);
  472. PHPUnit_Framework_Assert::assertEquals($groupsSimplified, $respondedArray, "", 0.0, 10, true);
  473. }
  474. }
  475. /**
  476. * @Then /^apps returned are$/
  477. * @param \Behat\Gherkin\Node\TableNode|null $appList
  478. */
  479. public function theAppsShouldBe($appList) {
  480. if ($appList instanceof \Behat\Gherkin\Node\TableNode) {
  481. $apps = $appList->getRows();
  482. $appsSimplified = $this->simplifyArray($apps);
  483. $respondedArray = $this->getArrayOfAppsResponded($this->response);
  484. PHPUnit_Framework_Assert::assertEquals($appsSimplified, $respondedArray, "", 0.0, 10, true);
  485. }
  486. }
  487. /**
  488. * @Then /^subadmin users returned are$/
  489. * @param \Behat\Gherkin\Node\TableNode|null $groupsList
  490. */
  491. public function theSubadminUsersShouldBe($groupsList) {
  492. $this->theSubadminGroupsShouldBe($groupsList);
  493. }
  494. /**
  495. * Parses the xml answer to get the array of users returned.
  496. * @param ResponseInterface $resp
  497. * @return array
  498. */
  499. public function getArrayOfUsersResponded($resp) {
  500. $listCheckedElements = $resp->xml()->data[0]->users[0]->element;
  501. $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
  502. return $extractedElementsArray;
  503. }
  504. /**
  505. * Parses the xml answer to get the array of groups returned.
  506. * @param ResponseInterface $resp
  507. * @return array
  508. */
  509. public function getArrayOfGroupsResponded($resp) {
  510. $listCheckedElements = $resp->xml()->data[0]->groups[0]->element;
  511. $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
  512. return $extractedElementsArray;
  513. }
  514. /**
  515. * Parses the xml answer to get the array of apps returned.
  516. * @param ResponseInterface $resp
  517. * @return array
  518. */
  519. public function getArrayOfAppsResponded($resp) {
  520. $listCheckedElements = $resp->xml()->data[0]->apps[0]->element;
  521. $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
  522. return $extractedElementsArray;
  523. }
  524. /**
  525. * Parses the xml answer to get the array of subadmins returned.
  526. * @param ResponseInterface $resp
  527. * @return array
  528. */
  529. public function getArrayOfSubadminsResponded($resp) {
  530. $listCheckedElements = $resp->xml()->data[0]->element;
  531. $extractedElementsArray = json_decode(json_encode($listCheckedElements), 1);
  532. return $extractedElementsArray;
  533. }
  534. /**
  535. * @Given /^app "([^"]*)" is disabled$/
  536. * @param string $app
  537. */
  538. public function appIsDisabled($app) {
  539. $fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=disabled";
  540. $client = new Client();
  541. $options = [];
  542. if ($this->currentUser === 'admin') {
  543. $options['auth'] = $this->adminUser;
  544. }
  545. $options['headers'] = [
  546. 'OCS-APIREQUEST' => 'true',
  547. ];
  548. $this->response = $client->get($fullUrl, $options);
  549. $respondedArray = $this->getArrayOfAppsResponded($this->response);
  550. PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
  551. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  552. }
  553. /**
  554. * @Given /^app "([^"]*)" is enabled$/
  555. * @param string $app
  556. */
  557. public function appIsEnabled($app) {
  558. $fullUrl = $this->baseUrl . "v2.php/cloud/apps?filter=enabled";
  559. $client = new Client();
  560. $options = [];
  561. if ($this->currentUser === 'admin') {
  562. $options['auth'] = $this->adminUser;
  563. }
  564. $options['headers'] = [
  565. 'OCS-APIREQUEST' => 'true',
  566. ];
  567. $this->response = $client->get($fullUrl, $options);
  568. $respondedArray = $this->getArrayOfAppsResponded($this->response);
  569. PHPUnit_Framework_Assert::assertContains($app, $respondedArray);
  570. PHPUnit_Framework_Assert::assertEquals(200, $this->response->getStatusCode());
  571. }
  572. /**
  573. * @Then /^user "([^"]*)" is disabled$/
  574. * @param string $user
  575. */
  576. public function userIsDisabled($user) {
  577. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
  578. $client = new Client();
  579. $options = [];
  580. if ($this->currentUser === 'admin') {
  581. $options['auth'] = $this->adminUser;
  582. }
  583. $options['headers'] = [
  584. 'OCS-APIREQUEST' => 'true',
  585. ];
  586. $this->response = $client->get($fullUrl, $options);
  587. PHPUnit_Framework_Assert::assertEquals("false", $this->response->xml()->data[0]->enabled);
  588. }
  589. /**
  590. * @Then /^user "([^"]*)" is enabled$/
  591. * @param string $user
  592. */
  593. public function userIsEnabled($user) {
  594. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
  595. $client = new Client();
  596. $options = [];
  597. if ($this->currentUser === 'admin') {
  598. $options['auth'] = $this->adminUser;
  599. }
  600. $options['headers'] = [
  601. 'OCS-APIREQUEST' => 'true',
  602. ];
  603. $this->response = $client->get($fullUrl, $options);
  604. PHPUnit_Framework_Assert::assertEquals("true", $this->response->xml()->data[0]->enabled);
  605. }
  606. /**
  607. * @Given user :user has a quota of :quota
  608. * @param string $user
  609. * @param string $quota
  610. */
  611. public function userHasAQuotaOf($user, $quota)
  612. {
  613. $body = new \Behat\Gherkin\Node\TableNode([
  614. 0 => ['key', 'quota'],
  615. 1 => ['value', $quota],
  616. ]);
  617. // method used from BasicStructure trait
  618. $this->sendingToWith("PUT", "/cloud/users/" . $user, $body);
  619. }
  620. /**
  621. * @Given user :user has unlimited quota
  622. * @param string $user
  623. */
  624. public function userHasUnlimitedQuota($user)
  625. {
  626. $this->userHasAQuotaOf($user, 'none');
  627. }
  628. /**
  629. * Returns home path of the given user
  630. * @param string $user
  631. */
  632. public function getUserHome($user) {
  633. $fullUrl = $this->baseUrl . "v{$this->apiVersion}.php/cloud/users/$user";
  634. $client = new Client();
  635. $options = [];
  636. $options['auth'] = $this->adminUser;
  637. $this->response = $client->get($fullUrl, $options);
  638. return $this->response->xml()->data[0]->home;
  639. }
  640. /**
  641. * @BeforeScenario
  642. * @AfterScenario
  643. */
  644. public function cleanupUsers()
  645. {
  646. $previousServer = $this->currentServer;
  647. $this->usingServer('LOCAL');
  648. foreach($this->createdUsers as $user) {
  649. $this->deleteUser($user);
  650. }
  651. $this->usingServer('REMOTE');
  652. foreach($this->createdRemoteUsers as $remoteUser) {
  653. $this->deleteUser($remoteUser);
  654. }
  655. $this->usingServer($previousServer);
  656. }
  657. /**
  658. * @BeforeScenario
  659. * @AfterScenario
  660. */
  661. public function cleanupGroups()
  662. {
  663. $previousServer = $this->currentServer;
  664. $this->usingServer('LOCAL');
  665. foreach($this->createdGroups as $group) {
  666. $this->deleteGroup($group);
  667. }
  668. $this->usingServer('REMOTE');
  669. foreach($this->createdRemoteGroups as $remoteGroup) {
  670. $this->deleteUser($remoteGroup);
  671. }
  672. $this->usingServer($previousServer);
  673. }
  674. }