FederationContext.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. *
  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. /**
  39. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with user "([^"]*)" from server "(LOCAL|REMOTE)"$/
  40. *
  41. * @param string $sharerUser
  42. * @param string $sharerServer "LOCAL" or "REMOTE"
  43. * @param string $sharerPath
  44. * @param string $shareeUser
  45. * @param string $shareeServer "LOCAL" or "REMOTE"
  46. */
  47. public function federateSharing($sharerUser, $sharerServer, $sharerPath, $shareeUser, $shareeServer) {
  48. if ($shareeServer == "REMOTE") {
  49. $shareWith = "$shareeUser@" . substr($this->remoteBaseUrl, 0, -4);
  50. } else {
  51. $shareWith = "$shareeUser@" . substr($this->localBaseUrl, 0, -4);
  52. }
  53. $previous = $this->usingServer($sharerServer);
  54. $this->createShare($sharerUser, $sharerPath, 6, $shareWith, null, null, null);
  55. $this->usingServer($previous);
  56. }
  57. /**
  58. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with group "([^"]*)" from server "(LOCAL|REMOTE)"$/
  59. *
  60. * @param string $sharerUser
  61. * @param string $sharerServer "LOCAL" or "REMOTE"
  62. * @param string $sharerPath
  63. * @param string $shareeUser
  64. * @param string $shareeServer "LOCAL" or "REMOTE"
  65. */
  66. public function federateGroupSharing($sharerUser, $sharerServer, $sharerPath, $shareeGroup, $shareeServer) {
  67. if ($shareeServer == "REMOTE") {
  68. $shareWith = "$shareeGroup@" . substr($this->remoteBaseUrl, 0, -4);
  69. } else {
  70. $shareWith = "$shareeGroup@" . substr($this->localBaseUrl, 0, -4);
  71. }
  72. $previous = $this->usingServer($sharerServer);
  73. $this->createShare($sharerUser, $sharerPath, 9, $shareWith, null, null, null);
  74. $this->usingServer($previous);
  75. }
  76. /**
  77. * @When /^User "([^"]*)" from server "(LOCAL|REMOTE)" accepts last pending share$/
  78. * @param string $user
  79. * @param string $server
  80. */
  81. public function acceptLastPendingShare($user, $server) {
  82. $previous = $this->usingServer($server);
  83. $this->asAn($user);
  84. $this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null);
  85. $this->theHTTPStatusCodeShouldBe('200');
  86. $this->theOCSStatusCodeShouldBe('100');
  87. $share_id = simplexml_load_string($this->response->getBody())->data[0]->element[0]->id;
  88. $this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null);
  89. $this->theHTTPStatusCodeShouldBe('200');
  90. $this->theOCSStatusCodeShouldBe('100');
  91. $this->usingServer($previous);
  92. }
  93. protected function resetAppConfigs() {
  94. $this->deleteServerConfig('files_sharing', 'incoming_server2server_group_share_enabled');
  95. $this->deleteServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled');
  96. }
  97. }