sftp_key.php 2.7 KB

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