You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

httphelper.php 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <?php
  2. /**
  3. * Copyright (c) 2014 Lukas Reschke <lukas@owncloud.com>
  4. * This file is licensed under the Affero General Public License version 3 or
  5. * later.
  6. * See the COPYING-README file.
  7. */
  8. class TestHTTPHelper extends \Test\TestCase {
  9. /** @var \OCP\IConfig*/
  10. private $config;
  11. /** @var \OC\HTTPHelper */
  12. private $httpHelperMock;
  13. protected function setUp() {
  14. parent::setUp();
  15. $this->config = $this->getMockBuilder('\OCP\IConfig')
  16. ->disableOriginalConstructor()->getMock();
  17. $this->httpHelperMock = $this->getMockBuilder('\OC\HTTPHelper')
  18. ->setConstructorArgs(array($this->config))
  19. ->setMethods(array('getHeaders'))
  20. ->getMock();
  21. }
  22. public function isHttpTestData() {
  23. return array(
  24. array('http://wwww.owncloud.org/enterprise/', true),
  25. array('https://wwww.owncloud.org/enterprise/', true),
  26. array('HTTPS://WWW.OWNCLOUD.ORG', true),
  27. array('HTTP://WWW.OWNCLOUD.ORG', true),
  28. array('FILE://WWW.OWNCLOUD.ORG', false),
  29. array('file://www.owncloud.org', false),
  30. array('FTP://WWW.OWNCLOUD.ORG', false),
  31. array('ftp://www.owncloud.org', false),
  32. );
  33. }
  34. /**
  35. * Note: Not using a dataprovider because onConsecutiveCalls expects not
  36. * an array but the function arguments directly
  37. */
  38. public function testGetFinalLocationOfURLValid() {
  39. $url = 'https://www.owncloud.org/enterprise/';
  40. $expected = 'https://www.owncloud.com/enterprise/';
  41. $this->httpHelperMock->expects($this->any())
  42. ->method('getHeaders')
  43. ->will($this->onConsecutiveCalls(
  44. array('Location' => 'http://www.owncloud.com/enterprise/'),
  45. array('Location' => 'https://www.owncloud.com/enterprise/')
  46. ));
  47. $result = $this->httpHelperMock->getFinalLocationOfURL($url);
  48. $this->assertSame($expected, $result);
  49. }
  50. /**
  51. * Note: Not using a dataprovider because onConsecutiveCalls expects not
  52. * an array but the function arguments directly
  53. */
  54. public function testGetFinalLocationOfURLInvalid() {
  55. $url = 'https://www.owncloud.org/enterprise/';
  56. $expected = 'http://www.owncloud.com/enterprise/';
  57. $this->httpHelperMock->expects($this->any())
  58. ->method('getHeaders')
  59. ->will($this->onConsecutiveCalls(
  60. array('Location' => 'http://www.owncloud.com/enterprise/'),
  61. array('Location' => 'file://etc/passwd'),
  62. array('Location' => 'http://www.example.com/')
  63. ));
  64. $result = $this->httpHelperMock->getFinalLocationOfURL($url);
  65. $this->assertSame($expected, $result);
  66. }
  67. /**
  68. * @expectedException \Exception
  69. * @expectedExceptionMessage URL must begin with HTTPS or HTTP.
  70. */
  71. public function testGetFinalLocationOfURLException() {
  72. $this->httpHelperMock->getFinalLocationOfURL('file://etc/passwd');
  73. }
  74. /**
  75. * @dataProvider isHttpTestData
  76. */
  77. public function testIsHTTP($url, $expected) {
  78. $this->assertSame($expected, $this->httpHelperMock->isHTTPURL($url));
  79. }
  80. }