ErrorHandlerTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * ownCloud
  5. *
  6. * @author Bjoern Schiessle
  7. * @copyright 2014 Bjoern Schiessle <schiessle@owncloud.com>
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
  11. * License as published by the Free Software Foundation; either
  12. * version 3 of the License, or any later version.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public
  20. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  21. *
  22. */
  23. namespace Test;
  24. use OC\Log\ErrorHandler;
  25. use OCP\ILogger;
  26. use PHPUnit\Framework\MockObject\MockObject;
  27. use Psr\Log\LoggerInterface;
  28. class ErrorHandlerTest extends TestCase {
  29. /** @var MockObject */
  30. private LoggerInterface $logger;
  31. private ErrorHandler $errorHandler;
  32. protected function setUp(): void {
  33. parent::setUp();
  34. $this->logger = $this->createMock(LoggerInterface::class);
  35. $this->errorHandler = new ErrorHandler(
  36. $this->logger
  37. );
  38. }
  39. /**
  40. * provide username, password combinations for testRemovePassword
  41. * @return array
  42. */
  43. public function passwordProvider() {
  44. return [
  45. ['us:er', 'pass@word'],
  46. ['us:er', 'password'],
  47. ['user', '-C:R,w)@6*}'],
  48. ['user', 'pass:word'],
  49. ['user', 'pass@word'],
  50. ['user', 'password'],
  51. ['user:test@cloud', 'password'],
  52. ['user@owncloud.org', 'password'],
  53. ['user@test@owncloud.org', 'password'],
  54. ];
  55. }
  56. /**
  57. * @dataProvider passwordProvider
  58. * @param string $username
  59. * @param string $password
  60. */
  61. public function testRemovePasswordFromError($username, $password) {
  62. $url = 'http://'.$username.':'.$password.'@owncloud.org';
  63. $expectedResult = 'http://xxx:xxx@owncloud.org';
  64. $this->logger->expects(self::once())
  65. ->method('log')
  66. ->with(
  67. ILogger::ERROR,
  68. 'Could not reach ' . $expectedResult . ' at file#4',
  69. ['app' => 'PHP'],
  70. );
  71. $result = $this->errorHandler->onError(E_USER_ERROR, 'Could not reach ' . $url, 'file', 4);
  72. self::assertTrue($result);
  73. }
  74. }