Skip to content

Commit 1652349

Browse files
committed
chore: add file conversion integration tests
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
1 parent 7cbcbdc commit 1652349

File tree

7 files changed

+189
-14
lines changed

7 files changed

+189
-14
lines changed

.github/workflows/integration-sqlite.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
- 'federation_features'
6262
- '--tags ~@large files_features'
6363
- 'filesdrop_features'
64+
- 'file_conversions'
6465
- 'openldap_features'
6566
- 'openldap_numerical_features'
6667
- 'ldap_features'

build/integration/config/behat.yml

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ default:
1616
- "%paths.base%/../features"
1717
contexts:
1818
- FeatureContext:
19-
baseUrl: http://localhost:8080/ocs/
19+
baseUrl: http://localhost:8080/ocs/
2020
admin:
2121
- admin
2222
- admin
@@ -39,7 +39,7 @@ default:
3939
- "%paths.base%/../comments_features"
4040
contexts:
4141
- FeatureContext:
42-
baseUrl: http://localhost:8080/ocs/
42+
baseUrl: http://localhost:8080/ocs/
4343
admin:
4444
- admin
4545
- admin
@@ -62,7 +62,7 @@ default:
6262
- "%paths.base%/../dav_features"
6363
contexts:
6464
- DavFeatureContext:
65-
baseUrl: http://localhost:8080/ocs/
65+
baseUrl: http://localhost:8080/ocs/
6666
admin:
6767
- admin
6868
- admin
@@ -85,7 +85,7 @@ default:
8585
- "%paths.base%/../federation_features"
8686
contexts:
8787
- FederationContext:
88-
baseUrl: http://localhost:8080/ocs/
88+
baseUrl: http://localhost:8080/ocs/
8989
admin:
9090
- admin
9191
- admin
@@ -95,7 +95,7 @@ default:
9595
- "%paths.base%/../files_features"
9696
contexts:
9797
- FeatureContext:
98-
baseUrl: http://localhost:8080/ocs/
98+
baseUrl: http://localhost:8080/ocs/
9999
admin:
100100
- admin
101101
- admin
@@ -112,13 +112,22 @@ default:
112112
baseUrl: http://localhost:8080
113113
- CommandLineContext:
114114
baseUrl: http://localhost:8080
115-
ocPath: ../../
115+
files_conversion:
116+
paths:
117+
- "%paths.base%/../file_conversions"
118+
contexts:
119+
- ConversionsContext:
120+
baseUrl: http://localhost:8080
121+
admin:
122+
- admin
123+
- admin
124+
regular_user_password: 123456
116125
capabilities:
117126
paths:
118127
- "%paths.base%/../capabilities_features"
119128
contexts:
120129
- CapabilitiesContext:
121-
baseUrl: http://localhost:8080/ocs/
130+
baseUrl: http://localhost:8080/ocs/
122131
admin:
123132
- admin
124133
- admin
@@ -128,7 +137,7 @@ default:
128137
- "%paths.base%/../collaboration_features"
129138
contexts:
130139
- CollaborationContext:
131-
baseUrl: http://localhost:8080/ocs/
140+
baseUrl: http://localhost:8080/ocs/
132141
admin:
133142
- admin
134143
- admin
@@ -138,7 +147,7 @@ default:
138147
- "%paths.base%/../sharees_features"
139148
contexts:
140149
- ShareesContext:
141-
baseUrl: http://localhost:8080/ocs/
150+
baseUrl: http://localhost:8080/ocs/
142151
admin:
143152
- admin
144153
- admin
@@ -148,7 +157,7 @@ default:
148157
- "%paths.base%/../sharing_features"
149158
contexts:
150159
- SharingContext:
151-
baseUrl: http://localhost:8080/ocs/
160+
baseUrl: http://localhost:8080/ocs/
152161
admin:
153162
- admin
154163
- admin
@@ -159,7 +168,7 @@ default:
159168
- "%paths.base%/../videoverification_features"
160169
contexts:
161170
- SharingContext:
162-
baseUrl: http://localhost:8080/ocs/
171+
baseUrl: http://localhost:8080/ocs/
163172
admin:
164173
- admin
165174
- admin
@@ -170,7 +179,7 @@ default:
170179
- "%paths.base%/../setup_features"
171180
contexts:
172181
- SetupContext:
173-
baseUrl: http://localhost:8080/ocs/
182+
baseUrl: http://localhost:8080/ocs/
174183
admin:
175184
- admin
176185
- admin
@@ -220,10 +229,10 @@ default:
220229
- "%paths.base%/../remoteapi_features"
221230
contexts:
222231
- FeatureContext:
223-
baseUrl: http://localhost:8080/ocs/
232+
baseUrl: http://localhost:8080/ocs/
224233
admin:
225234
- admin
226235
- admin
227236
regular_user_password: 123456
228237
- RemoteContext:
229-
remote: http://localhost:8080
238+
remote: http://localhost:8080

build/integration/data/clouds.jpg

526 KB
Loading
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
SPDX-FileCopyrightText: 2019 CHUTTERSNAP <https://unsplash.com/@chuttersnap> <https://unsplash.com/photos/blue-clouds-under-white-sky-9AqIdzEc9pY>"
2+
SPDX-License-Identifier: LicenseRef-Unsplash

build/integration/features/bootstrap/BasicStructure.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GuzzleHttp\Client;
99
use GuzzleHttp\Cookie\CookieJar;
1010
use GuzzleHttp\Exception\ClientException;
11+
use GuzzleHttp\Exception\ServerException;
1112
use PHPUnit\Framework\Assert;
1213
use Psr\Http\Message\ResponseInterface;
1314

@@ -170,6 +171,8 @@ public function sendingToWith($verb, $url, $body) {
170171
$this->response = $client->request($verb, $fullUrl, $options);
171172
} catch (ClientException $ex) {
172173
$this->response = $ex->getResponse();
174+
} catch (ServerException $ex) {
175+
$this->response = $ex->getResponse();
173176
}
174177
}
175178

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
5+
* SPDX-License-Identifier: AGPL-3.0-or-later
6+
*/
7+
require __DIR__ . '/../../vendor/autoload.php';
8+
9+
use Behat\Behat\Context\Context;
10+
use Behat\Behat\Context\SnippetAcceptingContext;
11+
use Behat\Gherkin\Node\TableNode;
12+
13+
class ConversionsContext implements Context, SnippetAcceptingContext {
14+
use AppConfiguration;
15+
use BasicStructure;
16+
use WebDav;
17+
18+
/** @BeforeScenario */
19+
public function setUpScenario() {
20+
$this->asAn('admin');
21+
$this->setStatusTestingApp(true);
22+
}
23+
24+
/** @AfterScenario */
25+
public function tearDownScenario() {
26+
$this->asAn('admin');
27+
$this->setStatusTestingApp(false);
28+
}
29+
30+
protected function resetAppConfigs() {
31+
}
32+
33+
/**
34+
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)"$/
35+
*/
36+
public function userConvertsTheSavedFileId(string $user, string $path, string $mime) {
37+
$this->userConvertsTheSavedFileIdTo($user, $path, $mime, null);
38+
}
39+
40+
/**
41+
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)" and saves it to "([^"]*)"$/
42+
*/
43+
public function userConvertsTheSavedFileIdTo(string $user, string $path, string $mime, ?string $destination) {
44+
try {
45+
$fileId = $this->getFileIdForPath($user, $path);
46+
} catch (Exception $e) {
47+
// return a fake value to keep going and be able to test the error
48+
$fileId = 0;
49+
}
50+
51+
$data = [['fileId', $fileId], ['targetMimeType', $mime]];
52+
if ($destination !== null) {
53+
$data[] = ['destination', $destination];
54+
}
55+
56+
$this->asAn($user);
57+
$this->sendingToWith('post', '/apps/files/api/v1/convert', new TableNode($data));
58+
}
59+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
2+
# SPDX-License-Identifier: AGPL-3.0-only
3+
4+
Feature: conversions
5+
Background:
6+
Given using api version "2"
7+
Given using new dav path
8+
Given user "user0" exists
9+
10+
Scenario: Converting a file works
11+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
12+
Then as "user0" the file "/image.jpg" exists
13+
When user "user0" converts file "/image.jpg" to "image/png"
14+
Then the HTTP status code should be "201"
15+
Then the OCS status code should be "201"
16+
Then as "user0" the file "/image.png" exists
17+
18+
Scenario: Converting a file to a given path works
19+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
20+
And User "user0" created a folder "/folder"
21+
Then as "user0" the file "/image.jpg" exists
22+
Then as "user0" the folder "/folder" exists
23+
When user "user0" converts file "/image.jpg" to "image/png" and saves it to "/folder/image.png"
24+
Then the HTTP status code should be "201"
25+
Then the OCS status code should be "201"
26+
Then as "user0" the file "/folder/image.png" exists
27+
Then as "user0" the file "/image.png" does not exist
28+
29+
Scenario: Converting a file path with overwrite
30+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
31+
And user "user0" uploads file "data/green-square-256.png" to "/image.png"
32+
Then as "user0" the file "/image.jpg" exists
33+
Then as "user0" the file "/image.png" exists
34+
When user "user0" converts file "/image.jpg" to "image/png"
35+
Then the HTTP status code should be "201"
36+
Then the OCS status code should be "201"
37+
Then as "user0" the file "/image.jpg" exists
38+
Then as "user0" the file "/image.png" exists
39+
Then as "user0" the file "/image (2).png" exists
40+
41+
Scenario: Converting a file path with overwrite to a given path
42+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
43+
And User "user0" created a folder "/folder"
44+
And user "user0" uploads file "data/green-square-256.png" to "/folder/image.png"
45+
Then as "user0" the file "/image.jpg" exists
46+
Then as "user0" the folder "/folder" exists
47+
Then as "user0" the file "/folder/image.png" exists
48+
When user "user0" converts file "/image.jpg" to "image/png" and saves it to "/folder/image.png"
49+
Then the HTTP status code should be "201"
50+
Then the OCS status code should be "201"
51+
Then as "user0" the file "/folder/image.png" exists
52+
Then as "user0" the file "/folder/image (2).png" exists
53+
Then as "user0" the file "/image.png" does not exist
54+
Then as "user0" the file "/image.jpg" exists
55+
56+
Scenario: Converting a file which does not exist fails
57+
When user "user0" converts file "/image.jpg" to "image/png"
58+
Then the HTTP status code should be "404"
59+
Then the OCS status code should be "404"
60+
Then as "user0" the file "/image.jpg" does not exist
61+
Then as "user0" the file "/image.png" does not exist
62+
63+
Scenario: Converting a file to an invalid destination path fails
64+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
65+
When user "user0" converts file "/image.jpg" to "image/png" and saves it to "/folder/image.png"
66+
Then the HTTP status code should be "404"
67+
Then the OCS status code should be "404"
68+
Then as "user0" the file "/image.jpg" exists
69+
Then as "user0" the file "/folder/image.png" does not exist
70+
71+
Scenario: Converting a file to an invalid format fails
72+
Given user "user0" uploads file "data/clouds.jpg" to "/image.jpg"
73+
When user "user0" converts file "/image.jpg" to "image/invalid"
74+
Then the HTTP status code should be "500"
75+
Then the OCS status code should be "999"
76+
Then as "user0" the file "/image.jpg" exists
77+
Then as "user0" the file "/image.png" does not exist
78+
79+
Scenario: Forbid conversion to a destination without create permission
80+
Given user "user1" exists
81+
# Share the folder with user1
82+
Given User "user0" created a folder "/folder"
83+
Then As an "user0"
84+
When creating a share with
85+
| path | folder |
86+
| shareWith | user1 |
87+
| shareType | 0 |
88+
| permissions | 1 |
89+
Then the OCS status code should be "200"
90+
And the HTTP status code should be "200"
91+
# Create the folder, upload the image
92+
Then As an "user1"
93+
Given user "user1" accepts last share
94+
Given as "user1" the folder "/folder" exists
95+
Given user "user1" uploads file "data/clouds.jpg" to "/image.jpg"
96+
Then as "user1" the file "/image.jpg" exists
97+
# Try to convert the image to a folder where user1 has no create permission
98+
When user "user1" converts file "/image.jpg" to "image/png" and saves it to "/folder/folder.png"
99+
Then the OCS status code should be "403"
100+
And the HTTP status code should be "403"
101+
Then as "user1" the file "/folder/folder.png" does not exist

0 commit comments

Comments
 (0)