2014-12-19 12:23:24 -05:00
|
|
|
<?php
|
2025-05-17 05:46:26 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
2014-12-19 12:23:24 -05:00
|
|
|
/**
|
2024-06-06 03:55:47 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019-2024 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
2014-12-19 12:23:24 -05:00
|
|
|
*/
|
2016-04-13 18:18:07 -04:00
|
|
|
namespace OCA\Files_External\Tests\Storage;
|
|
|
|
|
|
2019-11-22 14:52:10 -05:00
|
|
|
use OCA\Files_External\Lib\Storage\SFTP_Key;
|
2014-12-19 12:23:24 -05:00
|
|
|
|
2015-11-19 10:42:29 -05:00
|
|
|
/**
|
2016-04-13 18:18:07 -04:00
|
|
|
* Class SFTP_KeyTest
|
2015-11-19 10:42:29 -05:00
|
|
|
*
|
|
|
|
|
*
|
2016-04-13 18:18:07 -04:00
|
|
|
* @package OCA\Files_External\Tests\Storage
|
2015-11-19 10:42:29 -05:00
|
|
|
*/
|
2026-01-07 08:21:48 -05:00
|
|
|
#[\PHPUnit\Framework\Attributes\Group(name: 'DB')]
|
2016-04-13 18:18:07 -04:00
|
|
|
class SFTP_KeyTest extends \Test\Files\Storage\Storage {
|
2025-09-26 03:39:33 -04:00
|
|
|
use ConfigurableStorageTrait;
|
2014-12-19 12:23:24 -05:00
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function setUp(): void {
|
2014-12-19 12:23:24 -05:00
|
|
|
parent::setUp();
|
|
|
|
|
|
|
|
|
|
$id = $this->getUniqueID();
|
2025-12-18 10:10:06 -05:00
|
|
|
$this->loadConfig(__DIR__ . '/../config.php');
|
2015-07-21 16:19:53 -04:00
|
|
|
// Make sure we have an new empty folder to work in
|
|
|
|
|
$this->config['sftp_key']['root'] .= '/' . $id;
|
2016-04-13 18:18:07 -04:00
|
|
|
$this->instance = new SFTP_Key($this->config['sftp_key']);
|
2014-12-19 12:23:24 -05:00
|
|
|
$this->instance->mkdir('/');
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-26 03:39:33 -04:00
|
|
|
protected function shouldRunConfig(mixed $config): bool {
|
|
|
|
|
return is_array($config) && ($config['sftp_key']['run'] ?? false);
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-21 10:40:38 -05:00
|
|
|
protected function tearDown(): void {
|
2014-12-19 12:23:24 -05:00
|
|
|
if ($this->instance) {
|
|
|
|
|
$this->instance->rmdir('/');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
parent::tearDown();
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
public function testInvalidAddressShouldThrowException(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
// I'd use example.com for this, but someone decided to break the spec and make it resolve
|
|
|
|
|
$this->instance->assertHostAddressValid('notarealaddress...');
|
|
|
|
|
}
|
2014-12-19 12:23:24 -05:00
|
|
|
|
|
|
|
|
public function testValidAddressShouldPass(): void {
|
2015-07-21 16:19:53 -04:00
|
|
|
$this->assertTrue($this->instance->assertHostAddressValid('localhost'));
|
|
|
|
|
}
|
2014-12-19 12:23:24 -05:00
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
|
2014-12-19 12:23:24 -05:00
|
|
|
public function testNegativePortNumberShouldThrowException(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
|
2014-12-19 12:23:24 -05:00
|
|
|
$this->instance->assertPortNumberValid('-1');
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
public function testNonNumericalPortNumberShouldThrowException(): void {
|
2019-11-27 09:27:18 -05:00
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
$this->instance->assertPortNumberValid('a');
|
|
|
|
|
}
|
2014-12-19 12:23:24 -05:00
|
|
|
|
2025-05-17 05:46:26 -04:00
|
|
|
|
2019-11-27 09:27:18 -05:00
|
|
|
public function testHighPortNumberShouldThrowException(): void {
|
|
|
|
|
$this->expectException(\InvalidArgumentException::class);
|
2025-05-17 05:46:26 -04:00
|
|
|
|
2015-07-21 16:19:53 -04:00
|
|
|
$this->instance->assertPortNumberValid('65536');
|
|
|
|
|
}
|
2014-12-19 12:23:24 -05:00
|
|
|
|
|
|
|
|
public function testValidPortNumberShouldPass(): void {
|
2015-07-21 16:19:53 -04:00
|
|
|
$this->assertTrue($this->instance->assertPortNumberValid('22222'));
|
|
|
|
|
}
|
2014-12-19 12:23:24 -05:00
|
|
|
}
|