Browse Source

Fix more bugs

rpm
J. King 3 years ago
parent
commit
19ab9df063
  1. 2
      CHANGELOG
  2. 2
      lib/Conf.php
  3. 6
      lib/Db/SQLite3/Driver.php
  4. 8
      tests/cases/Conf/TestConf.php
  5. 13
      tests/cases/Db/SQLite3/TestCreation.php

2
CHANGELOG

@ -3,6 +3,8 @@ Version 0.9.2 (2021-??-??)
Bug fixes:
- Do not fail adding users to an empty database (regression since 0.9.0)
- Cleanly ignore unknown configuration properties
- Set access mode to rw-r---- when creating SQLite databases
Changes:
- Packages for Arch Linux are now available (see manual for details)

2
lib/Conf.php

@ -265,7 +265,7 @@ class Conf {
protected function propertyImport(string $key, $value, string $file = "") {
$typeName = $this->types[$key]['name'] ?? "mixed";
$typeConst = $this->types[$key]['const'] ?? Value::T_MIXED;
$nullable = (int) (bool) ($this->types[$key]['const'] & Value::M_NULL);
$nullable = (int) (bool) ($typeConst & Value::M_NULL);
try {
if ($typeName === "\\DateInterval") {
// date intervals have special handling: if the existing value (ultimately, the default value)

6
lib/Db/SQLite3/Driver.php

@ -31,6 +31,12 @@ class Driver extends \JKingWeb\Arsse\Db\AbstractDriver {
$dbKey = Arsse::$conf->dbSQLite3Key;
$timeout = Arsse::$conf->dbSQLite3Timeout * 1000;
try {
// check whether the file exists; if it doesn't create the file and set its mode to rw-r-----
if ($dbFile !== ":memory:" && !file_exists($dbFile)) {
if (@touch($dbFile)) {
chmod($dbFile, 0640);
}
}
$this->makeConnection($dbFile, $dbKey);
} catch (\Throwable $e) {
// if opening the database doesn't work, check various pre-conditions to find out what the problem might be

8
tests/cases/Conf/TestConf.php

@ -108,6 +108,14 @@ class TestConf extends \JKingWeb\Arsse\Test\AbstractTest {
$conf->import($arr);
}
public function testImportCustomProperty(): void {
$arr = [
'customProperty' => "I'm special!",
];
$conf = new Conf;
$this->assertSame($conf, $conf->import($arr));
}
public function testImportBogusDriver(): void {
$arr = [
'dbDriver' => "this driver does not exist",

13
tests/cases/Db/SQLite3/TestCreation.php

@ -185,4 +185,17 @@ class TestCreation extends \JKingWeb\Arsse\Test\AbstractTest {
$this->assertException("fileCorrupt", "Db");
new Driver;
}
public function testSetFileMode(): void {
$f = tempnam(sys_get_temp_dir(), "arsse");
Arsse::$conf->dbSQLite3File = $f;
// delete the file PHP just created
unlink($f);
// recreate the file
new Driver;
// check the mode
clearstatcache();
$mode = base_convert((string) stat($f)['mode'], 10, 8);
$this->assertMatchesRegularExpression("/640$/", $mode);
}
}

Loading…
Cancel
Save