Skip to content

Commit 7df3328

Browse files
committed
test(integration): Add an integration test with the guests app
It has quite nasty overwrites in place for appconfig and storages which break too often and can otherwise only be noticed by low privileged users Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent f8dbe23 commit 7df3328

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed

.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: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
use Behat\Behat\Context\Context;
9+
10+
class GuestsContext implements Context {
11+
public const TEST_PASSWORD = '123456';
12+
protected static $lastStdOut = null;
13+
protected static $lastCode = null;
14+
15+
#[\Behat\Hook\BeforeScenario('@Guests')]
16+
#[\Behat\Hook\BeforeFeature('@Guests')]
17+
public static function skipTestsIfTalkIsNotInstalled() {
18+
if (!self::isGuestsInstalled()) {
19+
throw new Exception('Guests needs to be installed to run features or scenarios tagged with @Guests');
20+
}
21+
}
22+
23+
#[\Behat\Hook\AfterScenario('@Guests')]
24+
public static function disableGuests() {
25+
self::runOcc(['app:disable', 'guests']);
26+
}
27+
28+
private static function isGuestsInstalled(): bool {
29+
self::runOcc(['app:list']);
30+
return strpos(self::$lastStdOut, 'guests') !== false;
31+
}
32+
33+
private static function runOcc(array $args, array $env = []): int {
34+
// Based on "runOcc" from CommandLine trait (which can not be used due
35+
// to not being static and being already used in other sibling
36+
// contexts).
37+
$args = array_map(function ($arg) {
38+
return escapeshellarg($arg);
39+
}, $args);
40+
$args[] = '--no-ansi --no-warnings';
41+
$args = implode(' ', $args);
42+
43+
$descriptor = [
44+
0 => ['pipe', 'r'],
45+
1 => ['pipe', 'w'],
46+
2 => ['pipe', 'w'],
47+
];
48+
$process = proc_open('php console.php ' . $args, $descriptor, $pipes, $ocPath = '../..', $env);
49+
self::$lastStdOut = stream_get_contents($pipes[1]);
50+
self::$lastCode = proc_close($process);
51+
52+
return self::$lastCode;
53+
}
54+
55+
#[\Behat\Step\Given('/^user "([^"]*)" is a guest account user$/')]
56+
public function createGuestUser(string $email): void {
57+
self::runOcc([
58+
'user:delete',
59+
$email,
60+
]);
61+
62+
$lastCode = self::runOcc([
63+
'config:app:set',
64+
'guests',
65+
'hash_user_ids',
66+
'--value=false',
67+
'--type=boolean',
68+
]);
69+
\PHPUnit\Framework\Assert::assertEquals(0, $lastCode);
70+
71+
$lastCode = self::runOcc([
72+
'guests:add',
73+
// creator user
74+
'admin',
75+
// email
76+
$email,
77+
'--display-name',
78+
$email . '-displayname',
79+
'--password-from-env',
80+
], [
81+
'OC_PASS' => self::TEST_PASSWORD,
82+
]);
83+
\PHPUnit\Framework\Assert::assertEquals(0, $lastCode, 'Guest creation succeeded for ' . $email);
84+
}
85+
86+
}
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: Creating a link share with send password by Talk
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)