SFTP_KeyTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin McCorkell <robin@mccorkell.me.uk>
  7. * @author Ross Nicoll <jrn@jrn.me.uk>
  8. * @author Thomas Müller <thomas.mueller@tmit.eu>
  9. * @author Viktor Szépe <viktor@szepe.net>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\Files_External\Tests\Storage;
  27. use \OCA\Files_External\Lib\Storage\SFTP_Key;
  28. /**
  29. * Class SFTP_KeyTest
  30. *
  31. * @group DB
  32. *
  33. * @package OCA\Files_External\Tests\Storage
  34. */
  35. class SFTP_KeyTest extends \Test\Files\Storage\Storage {
  36. private $config;
  37. protected function setUp() {
  38. parent::setUp();
  39. $id = $this->getUniqueID();
  40. $this->config = include('files_external/tests/config.php');
  41. if ( ! is_array($this->config) or ! isset($this->config['sftp_key']) or ! $this->config['sftp_key']['run']) {
  42. $this->markTestSkipped('SFTP with key backend not configured');
  43. }
  44. // Make sure we have an new empty folder to work in
  45. $this->config['sftp_key']['root'] .= '/' . $id;
  46. $this->instance = new SFTP_Key($this->config['sftp_key']);
  47. $this->instance->mkdir('/');
  48. }
  49. protected function tearDown() {
  50. if ($this->instance) {
  51. $this->instance->rmdir('/');
  52. }
  53. parent::tearDown();
  54. }
  55. /**
  56. * @expectedException InvalidArgumentException
  57. */
  58. public function testInvalidAddressShouldThrowException() {
  59. // I'd use example.com for this, but someone decided to break the spec and make it resolve
  60. $this->instance->assertHostAddressValid('notarealaddress...');
  61. }
  62. public function testValidAddressShouldPass() {
  63. $this->assertTrue($this->instance->assertHostAddressValid('localhost'));
  64. }
  65. /**
  66. * @expectedException InvalidArgumentException
  67. */
  68. public function testNegativePortNumberShouldThrowException() {
  69. $this->instance->assertPortNumberValid('-1');
  70. }
  71. /**
  72. * @expectedException InvalidArgumentException
  73. */
  74. public function testNonNumericalPortNumberShouldThrowException() {
  75. $this->instance->assertPortNumberValid('a');
  76. }
  77. /**
  78. * @expectedException InvalidArgumentException
  79. */
  80. public function testHighPortNumberShouldThrowException() {
  81. $this->instance->assertPortNumberValid('65536');
  82. }
  83. public function testValidPortNumberShouldPass() {
  84. $this->assertTrue($this->instance->assertPortNumberValid('22222'));
  85. }
  86. }