FederationContext.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016 Sergio Bertolin <sbertolin@solidgear.es>
  4. *
  5. * @author Bjoern Schiessle <bjoern@schiessle.org>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Daniel Calviño Sánchez <danxuliu@gmail.com>
  8. * @author Joas Schilling <coding@schilljs.com>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Sergio Bertolin <sbertolin@solidgear.es>
  11. * @author Sergio Bertolín <sbertolin@solidgear.es>
  12. *
  13. * @license GNU AGPL version 3 or any later version
  14. *
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License as
  17. * published by the Free Software Foundation, either version 3 of the
  18. * License, or (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. *
  28. */
  29. use Behat\Behat\Context\Context;
  30. use Behat\Behat\Context\SnippetAcceptingContext;
  31. require __DIR__ . '/../../vendor/autoload.php';
  32. /**
  33. * Federation context.
  34. */
  35. class FederationContext implements Context, SnippetAcceptingContext {
  36. use WebDav;
  37. use AppConfiguration;
  38. use CommandLine;
  39. /**
  40. * @BeforeScenario
  41. */
  42. public function cleanupRemoteStorages() {
  43. // Ensure that dangling remote storages from previous tests will not
  44. // interfere with the current scenario.
  45. // The storages must be cleaned before each scenario; they can not be
  46. // cleaned after each scenario, as this hook is executed before the hook
  47. // that removes the users, so the shares would be still valid and thus
  48. // the storages would not be dangling yet.
  49. $this->runOcc(['sharing:cleanup-remote-storages']);
  50. }
  51. /**
  52. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with user "([^"]*)" from server "(LOCAL|REMOTE)"$/
  53. *
  54. * @param string $sharerUser
  55. * @param string $sharerServer "LOCAL" or "REMOTE"
  56. * @param string $sharerPath
  57. * @param string $shareeUser
  58. * @param string $shareeServer "LOCAL" or "REMOTE"
  59. */
  60. public function federateSharing($sharerUser, $sharerServer, $sharerPath, $shareeUser, $shareeServer) {
  61. if ($shareeServer == "REMOTE") {
  62. $shareWith = "$shareeUser@" . substr($this->remoteBaseUrl, 0, -4);
  63. } else {
  64. $shareWith = "$shareeUser@" . substr($this->localBaseUrl, 0, -4);
  65. }
  66. $previous = $this->usingServer($sharerServer);
  67. $this->createShare($sharerUser, $sharerPath, 6, $shareWith, null, null, null);
  68. $this->usingServer($previous);
  69. }
  70. /**
  71. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with group "([^"]*)" from server "(LOCAL|REMOTE)"$/
  72. *
  73. * @param string $sharerUser
  74. * @param string $sharerServer "LOCAL" or "REMOTE"
  75. * @param string $sharerPath
  76. * @param string $shareeUser
  77. * @param string $shareeServer "LOCAL" or "REMOTE"
  78. */
  79. public function federateGroupSharing($sharerUser, $sharerServer, $sharerPath, $shareeGroup, $shareeServer) {
  80. if ($shareeServer == "REMOTE") {
  81. $shareWith = "$shareeGroup@" . substr($this->remoteBaseUrl, 0, -4);
  82. } else {
  83. $shareWith = "$shareeGroup@" . substr($this->localBaseUrl, 0, -4);
  84. }
  85. $previous = $this->usingServer($sharerServer);
  86. $this->createShare($sharerUser, $sharerPath, 9, $shareWith, null, null, null);
  87. $this->usingServer($previous);
  88. }
  89. /**
  90. * @When /^User "([^"]*)" from server "(LOCAL|REMOTE)" accepts last pending share$/
  91. * @param string $user
  92. * @param string $server
  93. */
  94. public function acceptLastPendingShare($user, $server) {
  95. $previous = $this->usingServer($server);
  96. $this->asAn($user);
  97. $this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null);
  98. $this->theHTTPStatusCodeShouldBe('200');
  99. $this->theOCSStatusCodeShouldBe('100');
  100. $share_id = simplexml_load_string($this->response->getBody())->data[0]->element[0]->id;
  101. $this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null);
  102. $this->theHTTPStatusCodeShouldBe('200');
  103. $this->theOCSStatusCodeShouldBe('100');
  104. $this->usingServer($previous);
  105. }
  106. protected function resetAppConfigs() {
  107. $this->deleteServerConfig('files_sharing', 'incoming_server2server_group_share_enabled');
  108. $this->deleteServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled');
  109. }
  110. }