Skip to content

Commit 19ce362

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

File tree

7 files changed

+189
-13
lines changed

7 files changed

+189
-13
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 & 13 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
@@ -113,12 +113,22 @@ default:
113113
- CommandLineContext:
114114
baseUrl: http://localhost:8080
115115
ocPath: ../../
116+
files_conversion:
117+
paths:
118+
- "%paths.base%/../file_conversions"
119+
contexts:
120+
- ConversionsContext:
121+
baseUrl: http://localhost:8080
122+
admin:
123+
- admin
124+
- admin
125+
regular_user_password: 123456
116126
capabilities:
117127
paths:
118128
- "%paths.base%/../capabilities_features"
119129
contexts:
120130
- CapabilitiesContext:
121-
baseUrl: http://localhost:8080/ocs/
131+
baseUrl: http://localhost:8080/ocs/
122132
admin:
123133
- admin
124134
- admin
@@ -128,7 +138,7 @@ default:
128138
- "%paths.base%/../collaboration_features"
129139
contexts:
130140
- CollaborationContext:
131-
baseUrl: http://localhost:8080/ocs/
141+
baseUrl: http://localhost:8080/ocs/
132142
admin:
133143
- admin
134144
- admin
@@ -138,7 +148,7 @@ default:
138148
- "%paths.base%/../sharees_features"
139149
contexts:
140150
- ShareesContext:
141-
baseUrl: http://localhost:8080/ocs/
151+
baseUrl: http://localhost:8080/ocs/
142152
admin:
143153
- admin
144154
- admin
@@ -148,7 +158,7 @@ default:
148158
- "%paths.base%/../sharing_features"
149159
contexts:
150160
- SharingContext:
151-
baseUrl: http://localhost:8080/ocs/
161+
baseUrl: http://localhost:8080/ocs/
152162
admin:
153163
- admin
154164
- admin
@@ -159,7 +169,7 @@ default:
159169
- "%paths.base%/../videoverification_features"
160170
contexts:
161171
- SharingContext:
162-
baseUrl: http://localhost:8080/ocs/
172+
baseUrl: http://localhost:8080/ocs/
163173
admin:
164174
- admin
165175
- admin
@@ -170,7 +180,7 @@ default:
170180
- "%paths.base%/../setup_features"
171181
contexts:
172182
- SetupContext:
173-
baseUrl: http://localhost:8080/ocs/
183+
baseUrl: http://localhost:8080/ocs/
174184
admin:
175185
- admin
176186
- admin
@@ -220,10 +230,10 @@ default:
220230
- "%paths.base%/../remoteapi_features"
221231
contexts:
222232
- FeatureContext:
223-
baseUrl: http://localhost:8080/ocs/
233+
baseUrl: http://localhost:8080/ocs/
224234
admin:
225235
- admin
226236
- admin
227237
regular_user_password: 123456
228238
- RemoteContext:
229-
remote: http://localhost:8080
239+
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)