The clean & modern RSS server that doesn't give you any crap. https://thearsse.com/
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.

TestCreation.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /** @license MIT
  3. * Copyright 2017 J. King, Dustin Wilson et al.
  4. * See LICENSE and AUTHORS files for details */
  5. declare(strict_types=1);
  6. namespace JKingWeb\Arsse\TestCase\Db\PostgreSQL;
  7. use JKingWeb\Arsse\Arsse;
  8. use JKingWeb\Arsse\Db\PostgreSQL\Driver;
  9. /**
  10. * @covers \JKingWeb\Arsse\Db\PostgreSQL\Driver<extended> */
  11. class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
  12. /** @dataProvider provideConnectionStrings */
  13. public function testGenerateConnectionString(bool $pdo, string $user, string $pass, string $db, string $host, int $port, string $service, string $exp) {
  14. self::setConf();
  15. $timeout = (string) ceil(Arsse::$conf->dbTimeoutConnect ?? 0);
  16. $postfix = "application_name='arsse' client_encoding='UTF8' connect_timeout='$timeout'";
  17. $act = Driver::makeConnectionString($pdo, $user, $pass, $db, $host, $port, $service);
  18. if ($act==$postfix) {
  19. $this->assertSame($exp, "");
  20. } else {
  21. $test = substr($act, 0, strlen($act) - (strlen($postfix) + 1));
  22. $check = substr($act, strlen($test) + 1);
  23. $this->assertSame($postfix, $check);
  24. $this->assertSame($exp, $test);
  25. }
  26. }
  27. public function provideConnectionStrings() {
  28. return [
  29. [false, "arsse", "secret", "arsse", "", 5432, "", "dbname='arsse' password='secret' user='arsse'"],
  30. [false, "arsse", "p word", "arsse", "", 5432, "", "dbname='arsse' password='p word' user='arsse'"],
  31. [false, "arsse", "p'word", "arsse", "", 5432, "", "dbname='arsse' password='p\\'word' user='arsse'"],
  32. [false, "arsse user", "secret", "arsse db", "", 5432, "", "dbname='arsse db' password='secret' user='arsse user'"],
  33. [false, "arsse", "secret", "", "", 5432, "", "password='secret' user='arsse'"],
  34. [false, "arsse", "secret", "arsse", "localhost", 5432, "", "dbname='arsse' host='localhost' password='secret' user='arsse'"],
  35. [false, "arsse", "secret", "arsse", "", 9999, "", "dbname='arsse' password='secret' port='9999' user='arsse'"],
  36. [false, "arsse", "secret", "arsse", "localhost", 9999, "", "dbname='arsse' host='localhost' password='secret' port='9999' user='arsse'"],
  37. [false, "arsse", "secret", "arsse", "/socket", 9999, "", "dbname='arsse' host='/socket' password='secret' user='arsse'"],
  38. [false, "T'Pau of Vulcan", "", "", "", 5432, "", "user='T\\'Pau of Vulcan'"],
  39. [false, "T'Pau of Vulcan", "superman", "datumbase", "somehost", 2112, "arsse", "service='arsse'"],
  40. [true, "arsse", "secret", "arsse", "", 5432, "", "dbname='arsse'"],
  41. [true, "arsse", "p word", "arsse", "", 5432, "", "dbname='arsse'"],
  42. [true, "arsse", "p'word", "arsse", "", 5432, "", "dbname='arsse'"],
  43. [true, "arsse user", "secret", "arsse db", "", 5432, "", "dbname='arsse db'"],
  44. [true, "arsse", "secret", "", "", 5432, "", ""],
  45. [true, "arsse", "secret", "arsse", "localhost", 5432, "", "dbname='arsse' host='localhost'"],
  46. [true, "arsse", "secret", "arsse", "", 9999, "", "dbname='arsse' port='9999'"],
  47. [true, "arsse", "secret", "arsse", "localhost", 9999, "", "dbname='arsse' host='localhost' port='9999'"],
  48. [true, "arsse", "secret", "arsse", "/socket", 9999, "", "dbname='arsse' host='/socket'"],
  49. [true, "T'Pau of Vulcan", "", "", "", 5432, "", ""],
  50. [true, "T'Pau of Vulcan", "superman", "datumbase", "somehost", 2112, "arsse", "service='arsse'"],
  51. ];
  52. }
  53. }