Updated docker environment to support this.
Updated compose volume mapping to support SELinux.
build: .
working_dir: /cli
volumes:
- - ./:/cli
+ - ./:/cli:z
depends_on:
db:
condition: service_healthy
MYSQL_USER: bookstack
MYSQL_PASSWORD: bookstack
volumes:
- - ./docker-mysql-init.sql:/docker-entrypoint-initdb.d/init.sql
+ - ./docker-mysql-init.sql:/docker-entrypoint-initdb.d/init.sql:z
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
-GRANT RELOAD ON *.* TO 'bookstack'@'%';
\ No newline at end of file
+GRANT RELOAD ON *.* TO 'bookstack'@'%';
+CREATE USER testuser@'%' IDENTIFIED BY 'a#pass${}with\\tspe\'cial\\nch"ars';
+GRANT ALL PRIVILEGES ON bookstack.* to testuser@'%';
\ No newline at end of file
exec('rm -rf /var/www/bookstack-symlink-backup');
}
+ public function test_backup_using_database_credentials_with_special_chars()
+ {
+ // The user details used here is created as part of the database docker-mysql-init.sql script.
+ chdir('/var/www/bookstack');
+ $this->assertCount(0, glob('storage/backups/bookstack-backup-*.zip'));
+
+ $result = $this->runCommand('backup', [], [], [
+ 'DB_USERNAME' => 'testuser',
+ 'DB_PASSWORD' => 'a#pass${}with\tspe\'cial\nch"ars',
+ ]);
+ $result->assertSuccessfulExit();
+ $result->assertStdoutContains("Backup finished.");
+
+ $this->assertCount(1, glob('storage/backups/bookstack-backup-*.zip'));
+
+ $zipFile = glob('storage/backups/bookstack-backup-*.zip')[0];
+ unlink($zipFile);
+ }
+
}
\ No newline at end of file
return require dirname(__DIR__) . '/src/app.php';
}
- protected function runCommand(string $command, array $args = [], array $inputs = []): CommandResult
+ protected function runCommand(string $command, array $args = [], array $inputs = [], array $env = []): CommandResult
{
$app = $this->getApp();
$command = $app->find($command);
$commandTester->setInputs($inputs);
}
+ foreach ($env as $name => $value) {
+ $_SERVER[$name] = $value;
+ }
+
try {
$commandTester->execute($args);
} catch (\Exception $exception) {
$err = $exception;
}
+ foreach ($env as $name => $value) {
+ unset($_SERVER[$name]);
+ }
+
return new CommandResult($commandTester, $err);
}