Skip to content

Commit c574c1b

Browse files
authored
Merge pull request #59588 from nextcloud/tests/59511/integration-test-guests-app
test(integration): Add an integration test with the guests app
2 parents 7bca362 + 14a748b commit c574c1b

4 files changed

Lines changed: 134 additions & 0 deletions

File tree

.github/workflows/integration-sqlite.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,10 @@ jobs:
7373
- 'sharing_features'
7474
- 'theming_features'
7575
- 'videoverification_features'
76+
- 'guests_features'
7677

7778
php-versions: ['8.4']
79+
guests-versions: ['main']
7880
spreed-versions: ['main']
7981
activity-versions: ['master']
8082

@@ -111,6 +113,15 @@ jobs:
111113
path: apps/spreed
112114
ref: ${{ matrix.spreed-versions }}
113115

116+
- name: Checkout Guests app
117+
if: ${{ matrix.test-suite == 'guests_features' }}
118+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
119+
with:
120+
persist-credentials: false
121+
repository: nextcloud/guests
122+
path: apps/guests
123+
ref: ${{ matrix.guests-versions }}
124+
114125
- name: Checkout Activity app
115126
if: ${{ matrix.test-suite == 'sharing_features' }}
116127
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

build/integration/config/behat.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,17 @@ default:
193193
- admin
194194
regular_user_password: 123456
195195
- TalkContext
196+
guests:
197+
paths:
198+
- "%paths.base%/../guests_features"
199+
contexts:
200+
- GuestsContext
201+
- SharingContext:
202+
baseUrl: http://localhost:8080/ocs/
203+
admin:
204+
- admin
205+
- admin
206+
regular_user_password: 123456
196207
setup:
197208
paths:
198209
- "%paths.base%/../setup_features"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
use Behat\Behat\Context\Context;
10+
11+
class GuestsContext implements Context {
12+
public const TEST_PASSWORD = '123456';
13+
protected static $lastStdOut = null;
14+
protected static $lastCode = null;
15+
16+
#[\Behat\Hook\BeforeScenario('@Guests')]
17+
#[\Behat\Hook\BeforeFeature('@Guests')]
18+
public static function skipTestsIfGuestsIsNotInstalled() {
19+
if (!self::isGuestsInstalled()) {
20+
throw new Exception('Guests needs to be installed to run features or scenarios tagged with @Guests');
21+
}
22+
}
23+
24+
#[\Behat\Hook\AfterScenario('@Guests')]
25+
public static function disableGuests() {
26+
self::runOcc(['app:disable', 'guests']);
27+
}
28+
29+
private static function isGuestsInstalled(): bool {
30+
self::runOcc(['app:list']);
31+
return strpos(self::$lastStdOut, 'guests') !== false;
32+
}
33+
34+
private static function runOcc(array $args, array $env = []): int {
35+
// Based on "runOcc" from CommandLine trait (which can not be used due
36+
// to not being static and being already used in other sibling
37+
// contexts).
38+
$args = array_map(function ($arg) {
39+
return escapeshellarg($arg);
40+
}, $args);
41+
$args[] = '--no-ansi --no-warnings';
42+
$args = implode(' ', $args);
43+
44+
$descriptor = [
45+
0 => ['pipe', 'r'],
46+
1 => ['pipe', 'w'],
47+
2 => ['pipe', 'w'],
48+
];
49+
$process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..', $env);
50+
self::$lastStdOut = stream_get_contents($pipes[1]);
51+
self::$lastCode = proc_close($process);
52+
53+
return self::$lastCode;
54+
}
55+
56+
#[\Behat\Step\Given('/^user "([^"]*)" is a guest account user$/')]
57+
public function createGuestUser(string $email): void {
58+
self::runOcc([
59+
'user:delete',
60+
$email,
61+
]);
62+
63+
$lastCode = self::runOcc([
64+
'config:app:set',
65+
'guests',
66+
'hash_user_ids',
67+
'--value=false',
68+
'--type=boolean',
69+
]);
70+
\PHPUnit\Framework\Assert::assertEquals(0, $lastCode);
71+
72+
$lastCode = self::runOcc([
73+
'guests:add',
74+
// creator user
75+
'admin',
76+
// email
77+
$email,
78+
'--display-name',
79+
$email . '-displayname',
80+
'--password-from-env',
81+
], [
82+
'OC_PASS' => self::TEST_PASSWORD,
83+
]);
84+
\PHPUnit\Framework\Assert::assertEquals(0, $lastCode, 'Guest creation succeeded for ' . $email);
85+
}
86+
87+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@Guests
2+
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
3+
# SPDX-License-Identifier: AGPL-3.0-or-later
4+
Feature: guests app
5+
Background:
6+
Given using api version "1"
7+
Given using old dav path
8+
Given invoking occ with "app:enable --force guests"
9+
Given the command was successful
10+
And user "user-guest@example.com" is a guest account user
11+
12+
Scenario: Receive a share as a guests app user
13+
And user "user-guest@example.com" should see following elements
14+
| / |
15+
Given user "user0" exists
16+
And As an "user0"
17+
When creating a share with
18+
| path | welcome.txt |
19+
| shareType | 0 |
20+
| shareWith | user-guest@example.com |
21+
Then the OCS status code should be "100"
22+
And the HTTP status code should be "200"
23+
And user "user-guest@example.com" should see following elements
24+
| / |
25+
| /welcome.txt |

0 commit comments

Comments
 (0)