Skip to content

Commit 2fe7b02

Browse files
Merge pull request #814 from nextcloud/bugfix/780/secure-view-compatibility
test: Add an integration test with richdocuments
2 parents e1ff63e + 7ad5de7 commit 2fe7b02

File tree

11 files changed

+166
-8
lines changed

11 files changed

+166
-8
lines changed

.github/workflows/integration.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
php-versions: ['8.4']
2727
databases: ['sqlite', 'mysql', 'pgsql']
2828
server-versions: ['master']
29+
richdocuments-versions: ['main']
2930
primary-storage: ['local', 'minio']
3031

3132
name: php${{ matrix.php-versions }}-${{ matrix.databases }}-${{ matrix.server-versions }}-${{ matrix.primary-storage}}
@@ -70,6 +71,14 @@ jobs:
7071
persist-credentials: false
7172
path: apps/${{ env.APP_NAME }}
7273

74+
- name: Checkout app (richdocuments)
75+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
76+
with:
77+
persist-credentials: false
78+
path: apps/richdocuments
79+
repository: nextcloud/richdocuments
80+
ref: ${{ matrix.richdocuments-versions }}
81+
7382
- name: Set up php ${{ matrix.php-versions }}
7483
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
7584
with:
@@ -91,6 +100,10 @@ jobs:
91100
working-directory: apps/${{ env.APP_NAME }}/tests/Integration
92101
run: composer i
93102

103+
- name: Set up dependencies (richdocuments)
104+
working-directory: apps/richdocuments
105+
run: composer i --no-dev
106+
94107
- name: Set up Nextcloud for S3 primary storage
95108
if: matrix.primary-storage == 'minio'
96109
run: |

.github/workflows/phpunit-mariadb.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ jobs:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
7373
mariadb-versions: ['10.6', '11.4']
74+
richdocuments-versions: ['main']
7475

7576
name: MariaDB ${{ matrix.mariadb-versions }} PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7677

@@ -104,6 +105,14 @@ jobs:
104105
persist-credentials: false
105106
path: apps/${{ env.APP_NAME }}
106107

108+
- name: Checkout app (richdocuments)
109+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
110+
with:
111+
persist-credentials: false
112+
path: apps/richdocuments
113+
repository: nextcloud/richdocuments
114+
ref: ${{ matrix.richdocuments-versions }}
115+
107116
- name: Set up php ${{ matrix.php-versions }}
108117
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
109118
with:
@@ -136,6 +145,10 @@ jobs:
136145
composer remove nextcloud/ocp --dev --no-scripts
137146
composer i
138147
148+
- name: Set up dependencies (richdocuments)
149+
working-directory: apps/richdocuments
150+
run: composer i --no-dev
151+
139152
- name: Set up Nextcloud
140153
env:
141154
DB_PORT: 4444

.github/workflows/phpunit-mysql.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
id: versions
3333
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1
3434
with:
35-
matrix: '{"mysql-versions": ["8.4"]}'
35+
matrix: '{"mysql-versions": ["8.4"], "richdocuments-versions": ["main"]}'
3636

3737
changes:
3838
runs-on: ubuntu-latest-low
@@ -102,6 +102,14 @@ jobs:
102102
persist-credentials: false
103103
path: apps/${{ env.APP_NAME }}
104104

105+
- name: Checkout app (richdocuments)
106+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
107+
with:
108+
persist-credentials: false
109+
path: apps/richdocuments
110+
repository: nextcloud/richdocuments
111+
ref: ${{ matrix.richdocuments-versions }}
112+
105113
- name: Set up php ${{ matrix.php-versions }}
106114
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
107115
with:
@@ -134,6 +142,10 @@ jobs:
134142
composer remove nextcloud/ocp --dev --no-scripts
135143
composer i
136144
145+
- name: Set up dependencies (richdocuments)
146+
working-directory: apps/richdocuments
147+
run: composer i --no-dev
148+
137149
- name: Set up Nextcloud
138150
env:
139151
DB_PORT: 4444

.github/workflows/phpunit-oci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
matrix:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
73+
richdocuments-versions: ['main']
7374

7475
name: OCI PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7576

@@ -115,6 +116,14 @@ jobs:
115116
persist-credentials: false
116117
path: apps/${{ env.APP_NAME }}
117118

119+
- name: Checkout app (richdocuments)
120+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
121+
with:
122+
persist-credentials: false
123+
path: apps/richdocuments
124+
repository: nextcloud/richdocuments
125+
ref: ${{ matrix.richdocuments-versions }}
126+
118127
- name: Set up php ${{ matrix.php-versions }}
119128
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
120129
with:
@@ -142,6 +151,10 @@ jobs:
142151
composer remove nextcloud/ocp --dev --no-scripts
143152
composer i
144153
154+
- name: Set up dependencies (richdocuments)
155+
working-directory: apps/richdocuments
156+
run: composer i --no-dev
157+
145158
- name: Set up Nextcloud
146159
env:
147160
DB_PORT: 1521

.github/workflows/phpunit-pgsql.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
matrix:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
73+
richdocuments-versions: ['main']
7374

7475
name: PostgreSQL PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7576

@@ -105,6 +106,14 @@ jobs:
105106
persist-credentials: false
106107
path: apps/${{ env.APP_NAME }}
107108

109+
- name: Checkout app (richdocuments)
110+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
111+
with:
112+
persist-credentials: false
113+
path: apps/richdocuments
114+
repository: nextcloud/richdocuments
115+
ref: ${{ matrix.richdocuments-versions }}
116+
108117
- name: Set up php ${{ matrix.php-versions }}
109118
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
110119
with:
@@ -132,6 +141,10 @@ jobs:
132141
composer remove nextcloud/ocp --dev --no-scripts
133142
composer i
134143
144+
- name: Set up dependencies (richdocuments)
145+
working-directory: apps/richdocuments
146+
run: composer i --no-dev
147+
135148
- name: Set up Nextcloud
136149
env:
137150
DB_PORT: 4444

.github/workflows/phpunit-sqlite.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
matrix:
7171
php-versions: ${{ fromJson(needs.matrix.outputs.php-version) }}
7272
server-versions: ${{ fromJson(needs.matrix.outputs.server-max) }}
73+
richdocuments-versions: ['main']
7374

7475
name: SQLite PHP ${{ matrix.php-versions }} Nextcloud ${{ matrix.server-versions }}
7576

@@ -94,6 +95,14 @@ jobs:
9495
persist-credentials: false
9596
path: apps/${{ env.APP_NAME }}
9697

98+
- name: Checkout app (richdocuments)
99+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
100+
with:
101+
persist-credentials: false
102+
path: apps/richdocuments
103+
repository: nextcloud/richdocuments
104+
ref: ${{ matrix.richdocuments-versions }}
105+
97106
- name: Set up php ${{ matrix.php-versions }}
98107
uses: shivammathur/setup-php@0f7f1d08e3e32076e51cae65eb0b0c871405b16e # v2.34.1
99108
with:
@@ -121,6 +130,10 @@ jobs:
121130
composer remove nextcloud/ocp --dev --no-scripts
122131
composer i
123132
133+
- name: Set up dependencies (richdocuments)
134+
working-directory: apps/richdocuments
135+
run: composer i --no-dev
136+
124137
- name: Set up Nextcloud
125138
env:
126139
DB_PORT: 4444

tests/Integration/features/bootstrap/FeatureContext.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ class FeatureContext implements Context {
4545
protected string $tagId = '';
4646
protected array $createdUsers = [];
4747

48+
protected array $changedConfigs = [];
49+
4850
/**
4951
* FeatureContext constructor.
5052
*/
@@ -61,6 +63,12 @@ public function cleanUpBetweenTests() {
6163
$this->setCurrentUser('admin');
6264
$this->sendingTo('DELETE', '/apps/files_accesscontrol_testing');
6365
$this->assertStatusCode($this->response, 200);
66+
67+
foreach ($this->changedConfigs as $appId => $configs) {
68+
foreach ($configs as $config) {
69+
$this->sendingTo('DELETE', '/apps/provisioning_api/api/v1/config/apps/' . $appId . '/' . $config);
70+
}
71+
}
6472
}
6573

6674
/**
@@ -133,6 +141,20 @@ public function userSharesFile(string $sharer, string $file, string $sharee): vo
133141
]);
134142
}
135143

144+
/**
145+
* @Given /^user "([^"]*)" shares file "([^"]*)" publicly$/
146+
*/
147+
public function userSharesFilePublicly(string $sharer, string $file): void {
148+
$this->setCurrentUser($sharer);
149+
$this->sendingToWith('POST', '/apps/files_sharing/api/v1/shares', [
150+
'path' => $file,
151+
'permissions' => 19,
152+
'shareType' => 3,
153+
]);
154+
$responseBody = json_decode($this->response->getBody()->getContents(), true, flags: JSON_THROW_ON_ERROR);
155+
$this->lastShareData = $responseBody['ocs']['data'];
156+
}
157+
136158
// ChecksumsContext
137159
/**
138160
* @Then The webdav response should have a status code :statusCode
@@ -150,6 +172,18 @@ public function theWebdavResponseShouldHaveAStatusCode($statusCode) {
150172
}
151173
}
152174

175+
176+
#[\Behat\Step\Given('the following :appId app config is set')]
177+
public function setAppConfig(string $appId, TableNode $formData): void {
178+
$this->setCurrentUser('admin');
179+
foreach ($formData->getRows() as $row) {
180+
$this->sendingToWith('POST', '/apps/provisioning_api/api/v1/config/apps/' . $appId . '/' . $row[0], [
181+
'value' => $row[1],
182+
]);
183+
$this->changedConfigs[$appId][] = $row[0];
184+
}
185+
}
186+
153187
/**
154188
* User management
155189
*/

tests/Integration/features/bootstrap/WebDav.php

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ trait WebDav {
2020
/** @var int */
2121
private $storedFileID = null;
2222
private array $trashedFiles = [];
23+
protected array $lastShareData = [];
2324

2425
/**
2526
* @Given /^using dav path "([^"]*)"$/
@@ -141,7 +142,7 @@ public function downloadFileWithRange($fileSource, $range) {
141142
* @param string $range
142143
*/
143144
public function downloadPublicFileWithRange($range) {
144-
$token = $this->lastShareData->data->token;
145+
$token = $this->lastShareData['token'];
145146
$fullUrl = $this->baseUrl . 'public.php/webdav';
146147

147148
$client = new GClient();
@@ -151,15 +152,19 @@ public function downloadPublicFileWithRange($range) {
151152
'Range' => $range
152153
];
153154

154-
$this->response = $client->request('GET', $fullUrl, $options);
155+
try {
156+
$this->response = $client->request('GET', $fullUrl, $options);
157+
} catch (\GuzzleHttp\Exception\ClientException $e) {
158+
$this->response = $e->getResponse();
159+
}
155160
}
156161

157162
/**
158163
* @When /^Downloading last public shared file inside a folder "([^"]*)" with range "([^"]*)"$/
159164
* @param string $range
160165
*/
161166
public function downloadPublicFileInsideAFolderWithRange($path, $range) {
162-
$token = $this->lastShareData->data->token;
167+
$token = $this->lastShareData['token'];
163168
$fullUrl = $this->baseUrl . 'public.php/webdav' . "$path";
164169

165170
$client = new GClient();
@@ -170,7 +175,11 @@ public function downloadPublicFileInsideAFolderWithRange($path, $range) {
170175
];
171176
$options['auth'] = [$token, ''];
172177

173-
$this->response = $client->request('GET', $fullUrl, $options);
178+
try {
179+
$this->response = $client->request('GET', $fullUrl, $options);
180+
} catch (\GuzzleHttp\Exception\ClientException $e) {
181+
$this->response = $e->getResponse();
182+
}
174183
}
175184

176185
/**
@@ -190,8 +199,13 @@ public function downloadedContentShouldBe($content) {
190199
*/
191200
public function checkPropForFile($file, $prefix, $prop, $value) {
192201
$elementList = $this->propfindFile($this->currentUser, $file, "<$prefix:$prop/>");
193-
$property = $elementList['/' . $this->getDavFilesPath($this->currentUser) . $file][200]["{DAV:}$prop"];
194-
Assert::assertEquals($property, $value);
202+
if ($prefix === 'oc') {
203+
$prefix = '{http://owncloud.org/ns}';
204+
} else {
205+
$prefix = '{DAV:}';
206+
}
207+
$property = $elementList['/' . $this->getDavFilesPath($this->currentUser) . $file][200]["$prefix$prop"];
208+
Assert::assertEquals($value, $property);
195209
}
196210

197211
/**

tests/Integration/features/mimetypes.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
Given as user "test1"
66
And using new dav path
77

8-
Scenario: Can properly block path detected mimetypes for application/javscript
8+
Scenario: Can properly block path detected mimetypes for application/javascript
99
And user "admin" creates global flow with 200
1010
| name | Admin flow |
1111
| class | OCA\FilesAccessControl\Operation |

tests/Integration/features/sharing-user.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,35 @@ Feature: Sharing user
172172
And The webdav response should have a status code "404"
173173
And user "test2" should see following elements
174174
| /nextcloud2.txt |
175+
176+
Scenario: Downloading is still blocked when Secure View is enabled
177+
Given the following files app config is set
178+
| watermark_enabled | yes |
179+
Given User "test1" uploads file "data/textfile.txt" to "/foobar.txt"
180+
And The webdav response should have a status code "201"
181+
And user "test1" shares file "/foobar.txt" with user "test2"
182+
And as user "test2"
183+
When File "/foobar.txt" should have prop "oc:permissions" equal to "SRGDNVW"
184+
When Downloading file "/foobar.txt"
185+
Then The webdav response should have a status code "200"
186+
When Downloading file "/foobar.txt" with range "1-4"
187+
Then The webdav response should have a status code "200"
188+
And user "test1" shares file "/foobar.txt" publicly
189+
And as user "test2"
190+
When Downloading last public shared file with range "1-4"
191+
Then The webdav response should have a status code "200"
192+
And user "admin" creates global flow with 200
193+
| name | Admin flow |
194+
| class | OCA\FilesAccessControl\Operation |
195+
| entity | OCA\WorkflowEngine\Entity\File |
196+
| events | [] |
197+
| operation | deny |
198+
| checks-0 | {"class":"OCA\\\\WorkflowEngine\\\\Check\\\\FileMimeType", "operator": "is", "value": "text/plain"} |
199+
And as user "test2"
200+
When File "/foobar.txt" should have prop "oc:permissions" equal to "SRD"
201+
When Downloading file "/foobar.txt"
202+
Then The webdav response should have a status code "404"
203+
When Downloading file "/foobar.txt" with range "1-4"
204+
Then The webdav response should have a status code "404"
205+
When Downloading last public shared file with range "1-4"
206+
Then The webdav response should have a status code "404"

0 commit comments

Comments
 (0)