Skip to content

Commit 5581f0c

Browse files
committed
chore: remove legacy action to test remote endpoint
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent a4c3e0c commit 5581f0c

4 files changed

Lines changed: 1 addition & 167 deletions

File tree

apps/files_sharing/appinfo/routes.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,6 @@
4040
'verb' => 'GET',
4141
'root' => '',
4242
],
43-
44-
[
45-
'name' => 'externalShares#testRemote',
46-
'url' => '/testremote',
47-
'verb' => 'GET'
48-
],
4943
[
5044
'name' => 'PublicPreview#getPreview',
5145
'url' => '/publicpreview/{token}',

apps/files_sharing/lib/Controller/ExternalSharesController.php

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,7 @@
88

99
use OCP\AppFramework\Controller;
1010
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
11-
use OCP\AppFramework\Http\Attribute\PublicPage;
12-
use OCP\AppFramework\Http\DataResponse;
1311
use OCP\AppFramework\Http\JSONResponse;
14-
use OCP\Http\Client\IClientService;
15-
use OCP\IConfig;
1612
use OCP\IRequest;
1713

1814
/**
@@ -25,8 +21,6 @@ public function __construct(
2521
string $appName,
2622
IRequest $request,
2723
private \OCA\Files_Sharing\External\Manager $externalManager,
28-
private IClientService $clientService,
29-
private IConfig $config,
3024
) {
3125
parent::__construct($appName, $request);
3226
}
@@ -64,64 +58,4 @@ public function destroy($id) {
6458
$this->externalManager->declineShare($id);
6559
return new JSONResponse();
6660
}
67-
68-
/**
69-
* Test whether the specified remote is accessible
70-
*
71-
* @param string $remote
72-
* @param bool $checkVersion
73-
* @return bool
74-
*/
75-
protected function testUrl($remote, $checkVersion = false) {
76-
try {
77-
$client = $this->clientService->newClient();
78-
$response = json_decode($client->get(
79-
$remote,
80-
[
81-
'timeout' => 3,
82-
'connect_timeout' => 3,
83-
'verify' => !$this->config->getSystemValueBool('sharing.federation.allowSelfSignedCertificates', false),
84-
]
85-
)->getBody());
86-
87-
if ($checkVersion) {
88-
return !empty($response->version) && version_compare($response->version, '7.0.0', '>=');
89-
} else {
90-
return is_object($response);
91-
}
92-
} catch (\Exception $e) {
93-
return false;
94-
}
95-
}
96-
97-
/**
98-
* @NoOutgoingFederatedSharingRequired
99-
* @NoIncomingFederatedSharingRequired
100-
*
101-
* @param string $remote
102-
* @return DataResponse
103-
* @AnonRateThrottle(limit=5, period=120)
104-
*/
105-
#[PublicPage]
106-
public function testRemote($remote) {
107-
if (preg_match('%[!#$&\'()*+,;=?@[\]]%', $remote)) {
108-
return new DataResponse(false);
109-
}
110-
111-
if (
112-
$this->testUrl('https://' . $remote . '/ocm-provider/') ||
113-
$this->testUrl('https://' . $remote . '/ocm-provider/index.php') ||
114-
$this->testUrl('https://' . $remote . '/status.php', true)
115-
) {
116-
return new DataResponse('https');
117-
} elseif (
118-
$this->testUrl('http://' . $remote . '/ocm-provider/') ||
119-
$this->testUrl('http://' . $remote . '/ocm-provider/index.php') ||
120-
$this->testUrl('http://' . $remote . '/status.php', true)
121-
) {
122-
return new DataResponse('http');
123-
} else {
124-
return new DataResponse(false);
125-
}
126-
}
12761
}

apps/files_sharing/openapi.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3805,10 +3805,5 @@
38053805
}
38063806
}
38073807
},
3808-
"tags": [
3809-
{
3810-
"name": "external_shares",
3811-
"description": "Class ExternalSharesController"
3812-
}
3813-
]
3808+
"tags": []
38143809
}

apps/files_sharing/tests/Controller/ExternalShareControllerTest.php

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,8 @@
88

99
use OCA\Files_Sharing\Controller\ExternalSharesController;
1010
use OCA\Files_Sharing\External\Manager;
11-
use OCP\AppFramework\Http\DataResponse;
1211
use OCP\AppFramework\Http\JSONResponse;
13-
use OCP\Http\Client\IClient;
1412
use OCP\Http\Client\IClientService;
15-
use OCP\Http\Client\IResponse;
1613
use OCP\IConfig;
1714
use OCP\IRequest;
1815
use PHPUnit\Framework\MockObject\MockObject;
@@ -79,90 +76,4 @@ public function testDestroy(): void {
7976

8077
$this->assertEquals(new JSONResponse(), $this->getExternalShareController()->destroy(4));
8178
}
82-
83-
public function testRemoteWithValidHttps(): void {
84-
$client = $this->createMock(IClient::class);
85-
$response = $this->createMock(IResponse::class);
86-
$response
87-
->expects($this->exactly(2))
88-
->method('getBody')
89-
->willReturnOnConsecutiveCalls(
90-
'Certainly not a JSON string',
91-
'{"installed":true,"maintenance":false,"version":"8.1.0.8","versionstring":"8.1.0","edition":""}'
92-
);
93-
$client
94-
->expects($this->any())
95-
->method('get')
96-
->willReturn($response);
97-
98-
$this->clientService
99-
->expects($this->exactly(2))
100-
->method('newClient')
101-
->willReturn($client);
102-
103-
$this->assertEquals(new DataResponse('https'), $this->getExternalShareController()->testRemote('nextcloud.com'));
104-
}
105-
106-
public function testRemoteWithWorkingHttp(): void {
107-
$client = $this->createMock(IClient::class);
108-
$response = $this->createMock(IResponse::class);
109-
$client
110-
->method('get')
111-
->willReturn($response);
112-
$response
113-
->expects($this->exactly(5))
114-
->method('getBody')
115-
->willReturnOnConsecutiveCalls(
116-
'Certainly not a JSON string',
117-
'Certainly not a JSON string',
118-
'Certainly not a JSON string',
119-
'Certainly not a JSON string',
120-
'{"installed":true,"maintenance":false,"version":"8.1.0.8","versionstring":"8.1.0","edition":""}'
121-
);
122-
$this->clientService
123-
->expects($this->exactly(5))
124-
->method('newClient')
125-
->willReturn($client);
126-
127-
$this->assertEquals(new DataResponse('http'), $this->getExternalShareController()->testRemote('nextcloud.com'));
128-
}
129-
130-
public function testRemoteWithInvalidRemote(): void {
131-
$client = $this->createMock(IClient::class);
132-
$response = $this->createMock(IResponse::class);
133-
$client
134-
->expects($this->exactly(6))
135-
->method('get')
136-
->willReturn($response);
137-
$response
138-
->expects($this->exactly(6))
139-
->method('getBody')
140-
->willReturn('Certainly not a JSON string');
141-
$this->clientService
142-
->expects($this->exactly(6))
143-
->method('newClient')
144-
->willReturn($client);
145-
146-
$this->assertEquals(new DataResponse(false), $this->getExternalShareController()->testRemote('nextcloud.com'));
147-
}
148-
149-
public function dataRemoteWithInvalidRemoteURLs(): array {
150-
return [
151-
['nextcloud.com?query'],
152-
['nextcloud.com/#anchor'],
153-
['nextcloud.com/;tomcat'],
154-
];
155-
}
156-
157-
/**
158-
* @dataProvider dataRemoteWithInvalidRemoteURLs
159-
* @param string $remote
160-
*/
161-
public function testRemoteWithInvalidRemoteURLs(string $remote): void {
162-
$this->clientService
163-
->expects($this->never())
164-
->method('newClient');
165-
166-
$this->assertEquals(new DataResponse(false), $this->getExternalShareController()->testRemote($remote));
167-
}
16879
}

0 commit comments

Comments
 (0)