FederationContext.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. /**
  3. *
  4. *
  5. * @author Joas Schilling <coding@schilljs.com>
  6. * @author Sergio Bertolin <sbertolin@solidgear.es>
  7. * @author Sergio Bertolín <sbertolin@solidgear.es>
  8. *
  9. * @license GNU AGPL version 3 or any later version
  10. *
  11. * This program is free software: you can redistribute it and/or modify
  12. * it under the terms of the GNU Affero General Public License as
  13. * published by the Free Software Foundation, either version 3 of the
  14. * License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU Affero General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU Affero General Public License
  22. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  23. *
  24. */
  25. use Behat\Behat\Context\Context;
  26. use Behat\Behat\Context\SnippetAcceptingContext;
  27. use GuzzleHttp\Client;
  28. use GuzzleHttp\Message\ResponseInterface;
  29. require __DIR__ . '/../../vendor/autoload.php';
  30. /**
  31. * Federation context.
  32. */
  33. class FederationContext implements Context, SnippetAcceptingContext {
  34. use WebDav;
  35. use AppConfiguration;
  36. /**
  37. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with user "([^"]*)" from server "(LOCAL|REMOTE)"$/
  38. *
  39. * @param string $sharerUser
  40. * @param string $sharerServer "LOCAL" or "REMOTE"
  41. * @param string $sharerPath
  42. * @param string $shareeUser
  43. * @param string $shareeServer "LOCAL" or "REMOTE"
  44. */
  45. public function federateSharing($sharerUser, $sharerServer, $sharerPath, $shareeUser, $shareeServer){
  46. if ($shareeServer == "REMOTE"){
  47. $shareWith = "$shareeUser@" . substr($this->remoteBaseUrl, 0, -4);
  48. } else {
  49. $shareWith = "$shareeUser@" . substr($this->localBaseUrl, 0, -4);
  50. }
  51. $previous = $this->usingServer($sharerServer);
  52. $this->createShare($sharerUser, $sharerPath, 6, $shareWith, null, null, null);
  53. $this->usingServer($previous);
  54. }
  55. /**
  56. * @Given /^User "([^"]*)" from server "(LOCAL|REMOTE)" shares "([^"]*)" with group "([^"]*)" from server "(LOCAL|REMOTE)"$/
  57. *
  58. * @param string $sharerUser
  59. * @param string $sharerServer "LOCAL" or "REMOTE"
  60. * @param string $sharerPath
  61. * @param string $shareeUser
  62. * @param string $shareeServer "LOCAL" or "REMOTE"
  63. */
  64. public function federateGroupSharing($sharerUser, $sharerServer, $sharerPath, $shareeGroup, $shareeServer){
  65. if ($shareeServer == "REMOTE"){
  66. $shareWith = "$shareeGroup@" . substr($this->remoteBaseUrl, 0, -4);
  67. } else {
  68. $shareWith = "$shareeGroup@" . substr($this->localBaseUrl, 0, -4);
  69. }
  70. $previous = $this->usingServer($sharerServer);
  71. $this->createShare($sharerUser, $sharerPath, 9, $shareWith, null, null, null);
  72. $this->usingServer($previous);
  73. }
  74. /**
  75. * @When /^User "([^"]*)" from server "(LOCAL|REMOTE)" accepts last pending share$/
  76. * @param string $user
  77. * @param string $server
  78. */
  79. public function acceptLastPendingShare($user, $server){
  80. $previous = $this->usingServer($server);
  81. $this->asAn($user);
  82. $this->sendingToWith('GET', "/apps/files_sharing/api/v1/remote_shares/pending", null);
  83. $this->theHTTPStatusCodeShouldBe('200');
  84. $this->theOCSStatusCodeShouldBe('100');
  85. $share_id = simplexml_load_string($this->response->getBody())->data[0]->element[0]->id;
  86. $this->sendingToWith('POST', "/apps/files_sharing/api/v1/remote_shares/pending/{$share_id}", null);
  87. $this->theHTTPStatusCodeShouldBe('200');
  88. $this->theOCSStatusCodeShouldBe('100');
  89. $this->usingServer($previous);
  90. }
  91. protected function resetAppConfigs() {
  92. $this->modifyServerConfig('files_sharing', 'incoming_server2server_group_share_enabled', 'no');
  93. $this->modifyServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled', 'no');
  94. }
  95. }