mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-04-23 11:58:50 +02:00
This was not enforced at parse time because repo1-cipher-type could be passed on the command-line even in cases where encryption was not needed by the subprocess. Filter repo-cipher-type so it is never passed on the command line. If the subprocess does not have access to the passphrase then knowing the encryption type is useless anyway.
154 lines
7.9 KiB
Perl
154 lines
7.9 KiB
Perl
####################################################################################################################################
|
|
# StorageHelperTest.pm - Tests for Storage::Helper module.
|
|
####################################################################################################################################
|
|
package pgBackRestTest::Module::Storage::StorageHelperPerlTest;
|
|
use parent 'pgBackRestTest::Env::ConfigEnvTest';
|
|
|
|
####################################################################################################################################
|
|
# Perl includes
|
|
####################################################################################################################################
|
|
use strict;
|
|
use warnings FATAL => qw(all);
|
|
use Carp qw(confess);
|
|
use English '-no_match_vars';
|
|
|
|
use Storable qw(dclone);
|
|
|
|
use pgBackRest::Config::Config;
|
|
use pgBackRest::Common::Exception;
|
|
use pgBackRest::Common::Log;
|
|
use pgBackRest::Protocol::Storage::Helper;
|
|
use pgBackRest::Storage::Helper;
|
|
|
|
use pgBackRestTest::Common::ExecuteTest;
|
|
use pgBackRestTest::Env::Host::HostBackupTest;
|
|
use pgBackRestTest::Common::RunTest;
|
|
|
|
####################################################################################################################################
|
|
# initTest - initialization before each test
|
|
####################################################################################################################################
|
|
sub initTest
|
|
{
|
|
my $self = shift;
|
|
|
|
storageTest()->pathCreate('db');
|
|
storageTest()->pathCreate('repo');
|
|
storageTest()->pathCreate('spool');
|
|
}
|
|
|
|
####################################################################################################################################
|
|
# run
|
|
####################################################################################################################################
|
|
sub run
|
|
{
|
|
my $self = shift;
|
|
|
|
# Define test file
|
|
my $strFile = 'file.txt';
|
|
my $strFileCopy = 'file.txt.copy';
|
|
my $strFileContent = 'TESTDATA';
|
|
my $iFileSize = length($strFileContent);
|
|
|
|
# Setup parameters
|
|
$self->optionTestSet(CFGOPT_PG_PATH, $self->testPath() . '/db');
|
|
$self->optionTestSet(CFGOPT_REPO_PATH, $self->testPath() . '/repo');
|
|
$self->optionTestSet(CFGOPT_SPOOL_PATH, $self->testPath() . '/spool');
|
|
$self->optionTestSet(CFGOPT_STANZA, $self->stanza());
|
|
$self->optionTestSetBool(CFGOPT_ARCHIVE_ASYNC, true);
|
|
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
if ($self->begin("storageLocal()"))
|
|
{
|
|
$self->testResult(sub {storageLocal($self->testPath())->put($strFile, $strFileContent)}, $iFileSize, 'put');
|
|
$self->testResult(sub {${storageTest()->get($strFile)}}, $strFileContent, ' check put');
|
|
|
|
$self->testResult(sub {storageLocal($self->testPath())->put($strFile, $strFileContent)}, $iFileSize, 'put cache storage');
|
|
$self->testResult(sub {${storageTest()->get($strFile)}}, $strFileContent, ' check put');
|
|
}
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
if ($self->begin("storageDb()"))
|
|
{
|
|
$self->testResult(sub {storageDb()->put($strFile, $strFileContent)}, $iFileSize, 'put');
|
|
$self->testResult(sub {${storageTest()->get("db/${strFile}")}}, $strFileContent, ' check put');
|
|
|
|
$self->testResult(sub {storageDb()->put($strFileCopy, $strFileContent)}, $iFileSize, 'put cached storage');
|
|
$self->testResult(sub {${storageTest()->get("db/${strFileCopy}")}}, $strFileContent, ' check put');
|
|
}
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
if ($self->begin("storageRepo()"))
|
|
{
|
|
$self->testResult(sub {storageRepo()->put($strFile, $strFileContent)}, $iFileSize, 'put');
|
|
$self->testResult(sub {${storageTest()->get("repo/${strFile}")}}, $strFileContent, ' check put');
|
|
|
|
$self->testResult(sub {storageRepo()->put($strFileCopy, $strFileContent)}, $iFileSize, 'put cached storage');
|
|
$self->testResult(sub {${storageTest()->get("repo/${strFileCopy}")}}, $strFileContent, ' check put');
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_ARCHIVE)}, $self->testPath() . '/repo/archive/db', 'check archive path');
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_ARCHIVE . '/9.3-1/000000010000000100000001')},
|
|
$self->testPath() . '/repo/archive/db/9.3-1/0000000100000001/000000010000000100000001', 'check repo WAL file');
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_ARCHIVE . '/9.3-1/0000000100000001')},
|
|
$self->testPath() . '/repo/archive/db/9.3-1/0000000100000001', 'check repo WAL path');
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_ARCHIVE . '/9.3-1/0000000100000001')},
|
|
$self->testPath() . '/repo/archive/db/9.3-1/0000000100000001', 'check repo WAL major path');
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_ARCHIVE . '/9.3-1')},
|
|
$self->testPath() . '/repo/archive/db/9.3-1', 'check repo archive id path');
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_BACKUP)}, $self->testPath() . '/repo/backup/db', 'check backup path');
|
|
$self->testResult(
|
|
sub {storageRepo()->pathGet(STORAGE_REPO_BACKUP . '/file')}, $self->testPath() . '/repo/backup/db/file',
|
|
'check backup file');
|
|
|
|
#---------------------------------------------------------------------------------------------------------------------------
|
|
# Insert a bogus rule to generate an error
|
|
storageRepo()->{hRule}{'<BOGUS>'} =
|
|
{
|
|
fnRule => storageRepo()->{hRule}{&STORAGE_REPO_ARCHIVE}{fnRule},
|
|
};
|
|
|
|
$self->testException(sub {storageRepo()->pathGet('<BOGUS>')}, ERROR_ASSERT, 'invalid <REPO> storage rule <BOGUS>');
|
|
}
|
|
|
|
#-------------------------------------------------------------------------------------------------------------------------------
|
|
if ($self->begin("storageRepo() encryption"))
|
|
{
|
|
my $strStanzaEncrypt = 'test-encrypt';
|
|
$self->optionTestSet(CFGOPT_REPO_CIPHER_TYPE, CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC);
|
|
$self->testException(
|
|
sub {$self->configTestLoad(CFGCMD_ARCHIVE_PUSH)}, ERROR_OPTION_REQUIRED,
|
|
'archive-push command requires option: repo1-cipher-pass');
|
|
|
|
# Set the encryption passphrase and confirm passphrase and type have been set in the storage object
|
|
$self->optionTestSet(CFGOPT_REPO_CIPHER_PASS, 'x');
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
|
|
|
$self->testResult(sub {storageRepo({strStanza => $strStanzaEncrypt})->cipherType() eq
|
|
CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC}, true, 'encryption type set');
|
|
$self->testResult(sub {storageRepo({strStanza => $strStanzaEncrypt})->cipherPassUser() eq 'x'}, true,
|
|
'encryption passphrase set');
|
|
|
|
# Cannot change encryption after it has been set (cached values not reset)
|
|
$self->optionTestClear(CFGOPT_REPO_CIPHER_TYPE);
|
|
$self->optionTestClear(CFGOPT_REPO_CIPHER_PASS);
|
|
$self->configTestLoad(CFGCMD_ARCHIVE_PUSH);
|
|
|
|
$self->testResult(sub {storageRepo({strStanza => $strStanzaEncrypt})->cipherType() eq
|
|
CFGOPTVAL_REPO_CIPHER_TYPE_AES_256_CBC}, true, 'encryption type not reset');
|
|
$self->testResult(sub {storageRepo({strStanza => $strStanzaEncrypt})->cipherPassUser() eq 'x'}, true,
|
|
'encryption passphrase not reset');
|
|
}
|
|
}
|
|
|
|
1;
|