Skip to content

Commit cff51b9

Browse files
authored
Merge pull request #5417 from nextcloud/backport/5416/stable33
[stable33] fix: Properly annotate settings controller
2 parents 0a64c03 + cf0db7d commit cff51b9

5 files changed

Lines changed: 101 additions & 8 deletions

File tree

.github/workflows/integration.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ jobs:
5757
code-image: [ 'release' ]
5858
php-versions: ['8.2']
5959
databases: ['sqlite']
60-
server-versions: ['master']
61-
scenarios: ['wopi', 'direct', 'federation', 'api']
60+
server-versions: ['stable33']
61+
scenarios: ['wopi', 'direct', 'federation', 'api', 'secure-view', 'admin-settings']
6262

6363
name: integration-${{ matrix.code-image }}-${{ matrix.scenarios }}-${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}
6464

@@ -125,8 +125,8 @@ jobs:
125125
matrix:
126126
php-versions: ['8.2']
127127
databases: ['mysql']
128-
server-versions: ['master']
129-
scenarios: ['wopi', 'direct', 'federation', 'api']
128+
server-versions: ['stable33']
129+
scenarios: ['wopi', 'direct', 'federation', 'api', 'secure-view', 'admin-settings']
130130

131131
name: integration-${{ matrix.scenarios }}-${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}
132132

@@ -201,7 +201,7 @@ jobs:
201201
php-versions: ['8.2']
202202
databases: ['pgsql']
203203
server-versions: ['stable33']
204-
scenarios: ['wopi', 'direct', 'federation', 'api']
204+
scenarios: ['wopi', 'direct', 'federation', 'api', 'secure-view', 'admin-settings']
205205

206206
name: integration-${{ matrix.scenarios }}-${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}
207207

@@ -277,8 +277,8 @@ jobs:
277277
matrix:
278278
php-versions: ['8.2']
279279
databases: ['oci']
280-
server-versions: ['master']
281-
scenarios: ['wopi', 'direct', 'federation', 'api']
280+
server-versions: ['stable33']
281+
scenarios: ['wopi', 'direct', 'federation', 'api', 'secure-view', 'admin-settings']
282282

283283
name: integration-${{ matrix.scenarios }}-${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}
284284

lib/Controller/SettingsController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ public function demoServers(): DataResponse {
9999
return new DataResponse([], Http::STATUS_NOT_FOUND);
100100
}
101101

102-
#[NoAdminRequired]
103102
public function getSettings(): JSONResponse {
104103
return new JSONResponse($this->getSettingsData());
105104
}

tests/config/behat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ default:
2222
- DirectContext
2323
- FederationContext
2424
- ApiContext
25+
- SettingsContext
2526

2627

2728
extensions:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Admin Settings
2+
3+
Background:
4+
Given user "user1" exists
5+
6+
Scenario: Normal user cannot retrieve admin settings
7+
When the admin settings are requested by a user
8+
Then the admin settings are forbidden
9+
10+
Scenario: Admin can retrieve admin settings
11+
When the admin settings are requested by an admin
12+
Then the admin settings are returned
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
3+
declare(strict_types = 1);
4+
/**
5+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
6+
* SPDX-License-Identifier: AGPL-3.0-or-later
7+
*/
8+
9+
use Behat\Behat\Context\Context;
10+
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
11+
use Behat\Hook\AfterScenario;
12+
use Behat\Hook\BeforeScenario;
13+
use Behat\Step\Then;
14+
use Behat\Step\When;
15+
use JuliusHaertl\NextcloudBehat\Context\ServerContext;
16+
use PHPUnit\Framework\Assert;
17+
18+
class SettingsContext implements Context {
19+
/** @var ServerContext */
20+
private $serverContext;
21+
22+
/** @var GuzzleHttp\Client */
23+
private $http;
24+
25+
/** @var Psr\Http\Message\ResponseInterface */
26+
private $httpResponse;
27+
28+
public function __construct() {
29+
30+
}
31+
32+
#[BeforeScenario]
33+
public function gatherContexts(BeforeScenarioScope $scope) {
34+
$this->serverContext = $scope->getEnvironment()->getContext(ServerContext::class);
35+
36+
$this->http = new GuzzleHttp\Client([
37+
'base_uri' => $this->serverContext->getBaseUrl() . 'index.php/apps/richdocuments/',
38+
'http_errors' => false,
39+
]);
40+
}
41+
42+
#[AfterScenario]
43+
public function cleanup() {
44+
$this->httpResponse = null;
45+
}
46+
47+
#[When('the admin settings are requested by a user')]
48+
public function userRequestAdminSettings() {
49+
$this->serverContext->actingAsUser('user1');
50+
51+
$options = $this->serverContext->getWebOptions();
52+
$this->httpResponse = $this->http->get('ajax/settings.php', $options);
53+
}
54+
55+
#[When('the admin settings are requested by an admin')]
56+
public function adminRequestAdminSettings() {
57+
$this->serverContext->actAsAdmin(function () {
58+
$options = $this->serverContext->getWebOptions();
59+
$this->httpResponse = $this->http->get('ajax/settings.php', $options);
60+
});
61+
}
62+
63+
#[Then('the admin settings are forbidden')]
64+
public function adminSettingsRequestForbidden() {
65+
Assert::assertEquals(403, $this->httpResponse->getStatusCode());
66+
67+
Assert::assertJsonStringEqualsJsonString(
68+
'{"message":"Logged in account must be an admin"}',
69+
$this->httpResponse->getBody()->getContents(),
70+
);
71+
}
72+
73+
#[Then('the admin settings are returned')]
74+
public function adminSettingsRequestReturned() {
75+
Assert::assertEquals(200, $this->httpResponse->getStatusCode());
76+
Assert::assertJsonStringNotEqualsJsonString(
77+
'{}',
78+
$this->httpResponse->getBody()->getContents(),
79+
);
80+
}
81+
}

0 commit comments

Comments
 (0)