Skip to content

Commit 877f75f

Browse files
committed
Add integration tests for federated shares from unavailable servers
The federated server needs to be stopped during the tests, so it is now stopped in the FederationContext for each scenario instead of just once in the run.sh script. Signed-off-by: Daniel Calviño Sánchez <[email protected]>
1 parent 43f96c3 commit 877f75f

File tree

3 files changed

+130
-4
lines changed

3 files changed

+130
-4
lines changed

build/integration/features/bootstrap/FederationContext.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,29 @@ class FederationContext implements Context, SnippetAcceptingContext {
4040
use AppConfiguration;
4141
use CommandLine;
4242

43+
/** @var string */
44+
private static $phpFederatedServerPid = '';
45+
4346
/** @var string */
4447
private $lastAcceptedRemoteShareId;
4548

49+
/**
50+
* @BeforeScenario
51+
* @AfterScenario
52+
*
53+
* The server is started also after the scenarios to ensure that it is
54+
* properly cleaned up if stopped.
55+
*/
56+
public function startFederatedServer() {
57+
if (self::$phpFederatedServerPid !== '') {
58+
return;
59+
}
60+
61+
$port = getenv('PORT_FED');
62+
63+
self::$phpFederatedServerPid = exec('php -S localhost:' . $port . ' -t ../../ >/dev/null & echo $!');
64+
}
65+
4666
/**
4767
* @BeforeScenario
4868
*/
@@ -157,6 +177,19 @@ public function deleteLastAcceptedRemoteShare($user) {
157177
$this->sendingToWith('DELETE', "/apps/files_sharing/api/v1/remote_shares/" . $this->lastAcceptedRemoteShareId, null);
158178
}
159179

180+
/**
181+
* @When /^remote server is stopped$/
182+
*/
183+
public function remoteServerIsStopped() {
184+
if (self::$phpFederatedServerPid === '') {
185+
return;
186+
}
187+
188+
exec('kill ' . self::$phpFederatedServerPid);
189+
190+
self::$phpFederatedServerPid = '';
191+
}
192+
160193
protected function resetAppConfigs() {
161194
$this->deleteServerConfig('files_sharing', 'incoming_server2server_group_share_enabled');
162195
$this->deleteServerConfig('files_sharing', 'outgoing_server2server_group_share_enabled');

build/integration/federation_features/federated.feature

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,54 @@ Feature: federated
318318
| type | file |
319319
| file_id | A_NUMBER |
320320

321+
Scenario: List federated share from another server no longer reachable
322+
Given Using server "LOCAL"
323+
And user "user0" exists
324+
Given Using server "REMOTE"
325+
And user "user1" exists
326+
# Rename file so it has a unique name in the target server (as the target
327+
# server may have its own /textfile0.txt" file)
328+
And User "user1" copies file "/textfile0.txt" to "/remote-share.txt"
329+
And User "user1" from server "REMOTE" shares "/remote-share.txt" with user "user0" from server "LOCAL"
330+
And Using server "LOCAL"
331+
And User "user0" from server "LOCAL" accepts last pending share
332+
And remote server is stopped
333+
When As an "user0"
334+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
335+
Then the list of returned shares has 1 shares
336+
And remote share 0 is returned with
337+
| remote | http://localhost:8180/ |
338+
| name | /remote-share.txt |
339+
| owner | user1 |
340+
| user | user0 |
341+
| mountpoint | /remote-share.txt |
342+
343+
Scenario: List federated share from another server no longer reachable after caching the file entry
344+
Given Using server "LOCAL"
345+
And user "user0" exists
346+
Given Using server "REMOTE"
347+
And user "user1" exists
348+
# Rename file so it has a unique name in the target server (as the target
349+
# server may have its own /textfile0.txt" file)
350+
And User "user1" copies file "/textfile0.txt" to "/remote-share.txt"
351+
And User "user1" from server "REMOTE" shares "/remote-share.txt" with user "user0" from server "LOCAL"
352+
And Using server "LOCAL"
353+
And User "user0" from server "LOCAL" accepts last pending share
354+
# Checking that the file exists caches the file entry, which causes an
355+
# exception to be thrown when getting the file info if the remote server is
356+
# unreachable.
357+
And as "user0" the file "/remote-share.txt" exists
358+
And remote server is stopped
359+
When As an "user0"
360+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
361+
Then the list of returned shares has 1 shares
362+
And remote share 0 is returned with
363+
| remote | http://localhost:8180/ |
364+
| name | /remote-share.txt |
365+
| owner | user1 |
366+
| user | user0 |
367+
| mountpoint | /remote-share.txt |
368+
321369

322370

323371
Scenario: Delete federated share with another server
@@ -382,6 +430,30 @@ Feature: federated
382430
And sending "GET" to "/apps/files_sharing/api/v1/shares"
383431
And the list of returned shares has 0 shares
384432

433+
Scenario: Delete federated share from another server no longer reachable
434+
Given Using server "LOCAL"
435+
And user "user0" exists
436+
Given Using server "REMOTE"
437+
And user "user1" exists
438+
# Rename file so it has a unique name in the target server (as the target
439+
# server may have its own /textfile0.txt" file)
440+
And User "user1" copies file "/textfile0.txt" to "/remote-share.txt"
441+
And User "user1" from server "REMOTE" shares "/remote-share.txt" with user "user0" from server "LOCAL"
442+
And Using server "LOCAL"
443+
And User "user0" from server "LOCAL" accepts last pending share
444+
And as "user0" the file "/remote-share.txt" exists
445+
And As an "user0"
446+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
447+
And the list of returned shares has 1 shares
448+
And remote server is stopped
449+
When user "user0" deletes last accepted remote share
450+
Then the OCS status code should be "100"
451+
And the HTTP status code should be "200"
452+
And as "user0" the file "/remote-share.txt" does not exist
453+
And As an "user0"
454+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
455+
And the list of returned shares has 0 shares
456+
385457
Scenario: Delete federated share file from another server
386458
Given Using server "LOCAL"
387459
And user "user0" exists
@@ -410,3 +482,26 @@ Feature: federated
410482
And As an "user1"
411483
And sending "GET" to "/apps/files_sharing/api/v1/shares"
412484
And the list of returned shares has 0 shares
485+
486+
Scenario: Delete federated share file from another server no longer reachable
487+
Given Using server "LOCAL"
488+
And user "user0" exists
489+
Given Using server "REMOTE"
490+
And user "user1" exists
491+
# Rename file so it has a unique name in the target server (as the target
492+
# server may have its own /textfile0.txt" file)
493+
And User "user1" copies file "/textfile0.txt" to "/remote-share.txt"
494+
And User "user1" from server "REMOTE" shares "/remote-share.txt" with user "user0" from server "LOCAL"
495+
And Using server "LOCAL"
496+
And User "user0" from server "LOCAL" accepts last pending share
497+
And as "user0" the file "/remote-share.txt" exists
498+
And As an "user0"
499+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
500+
And the list of returned shares has 1 shares
501+
And remote server is stopped
502+
When User "user0" deletes file "/remote-share.txt"
503+
Then the HTTP status code should be "204"
504+
And as "user0" the file "/remote-share.txt" does not exist
505+
And As an "user0"
506+
And sending "GET" to "/apps/files_sharing/api/v1/remote_shares"
507+
And the list of returned shares has 0 shares

build/integration/run.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@ php -S localhost:$PORT -t ../.. &
3838
PHPPID=$!
3939
echo $PHPPID
4040

41+
# The federated server is started and stopped by the tests themselves
4142
PORT_FED=$((8180 + $EXECUTOR_NUMBER))
4243
echo $PORT_FED
43-
php -S localhost:$PORT_FED -t ../.. &
44-
PHPPID_FED=$!
45-
echo $PHPPID_FED
44+
export PORT_FED
4645

4746
export TEST_SERVER_URL="http://localhost:$PORT/ocs/"
4847
export TEST_SERVER_FED_URL="http://localhost:$PORT_FED/ocs/"
@@ -65,7 +64,6 @@ vendor/bin/behat --strict -f junit -f pretty $TAGS $SCENARIO_TO_RUN
6564
RESULT=$?
6665

6766
kill $PHPPID
68-
kill $PHPPID_FED
6967

7068
if [ "$INSTALLED" == "true" ]; then
7169

0 commit comments

Comments
 (0)