You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2025-07-15 01:04:37 +02:00
Config test code writes secure options to a file instead of passing on the command-line.
This commit is contained in:
@ -145,6 +145,10 @@
|
|||||||
<p>Buld performance improvements. Improve bin and libc build performance. Improve code generation performance.</p>
|
<p>Buld performance improvements. Improve bin and libc build performance. Improve code generation performance.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
|
||||||
|
<release-item>
|
||||||
|
<p>Config test code writes secure options to a file instead of passing on the command-line.</p>
|
||||||
|
</release-item>
|
||||||
|
|
||||||
<release-item>
|
<release-item>
|
||||||
<p>Disable console display of coverage for C files since <code>Devel::Cover</code> does not handle it well.</p>
|
<p>Disable console display of coverage for C files since <code>Devel::Cover</code> does not handle it well.</p>
|
||||||
</release-item>
|
</release-item>
|
||||||
|
@ -20,8 +20,21 @@ use pgBackRest::Config::Config;
|
|||||||
use pgBackRest::LibC qw(:test);
|
use pgBackRest::LibC qw(:test);
|
||||||
use pgBackRest::Version;
|
use pgBackRest::Version;
|
||||||
|
|
||||||
|
use pgBackRestTest::Common::RunTest;
|
||||||
|
|
||||||
use constant CONFIGENVTEST => 'ConfigEnvTest';
|
use constant CONFIGENVTEST => 'ConfigEnvTest';
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
# Is the option secure?
|
||||||
|
####################################################################################################################################
|
||||||
|
sub optionTestSecure
|
||||||
|
{
|
||||||
|
my $self = shift;
|
||||||
|
my $strOption = shift;
|
||||||
|
|
||||||
|
return (cfgDefOptionSecure(cfgOptionId($strOption)) ? true : false);
|
||||||
|
}
|
||||||
|
|
||||||
sub optionTestSet
|
sub optionTestSet
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
@ -68,25 +81,24 @@ sub configTestSet
|
|||||||
$self->{&CONFIGENVTEST} = $rhConfig;
|
$self->{&CONFIGENVTEST} = $rhConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub commandTestWrite
|
####################################################################################################################################
|
||||||
|
# Write all secure options to a config file
|
||||||
|
####################################################################################################################################
|
||||||
|
sub configFileWrite
|
||||||
{
|
{
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $strCommand = shift;
|
my $strConfigFile = shift;
|
||||||
my $rhConfig = shift;
|
my $rhConfig = shift;
|
||||||
|
|
||||||
my @szyParam = ();
|
my $strConfig = "[global]\n";
|
||||||
|
|
||||||
if (defined($rhConfig->{boolean}))
|
if (defined($rhConfig->{boolean}))
|
||||||
{
|
{
|
||||||
foreach my $strOption (sort(keys(%{$rhConfig->{boolean}})))
|
foreach my $strOption (sort(keys(%{$rhConfig->{boolean}})))
|
||||||
{
|
{
|
||||||
if ($rhConfig->{boolean}{$strOption})
|
if ($self->optionTestSecure($strOption))
|
||||||
{
|
{
|
||||||
push(@szyParam, "--${strOption}");
|
$strConfig .= "${strOption}=" . ($rhConfig->{boolean}{$strOption} ? 'y' : 'n') . "\n";
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
push(@szyParam, "--no-${strOption}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,10 +107,63 @@ sub commandTestWrite
|
|||||||
{
|
{
|
||||||
foreach my $strOption (sort(keys(%{$rhConfig->{option}})))
|
foreach my $strOption (sort(keys(%{$rhConfig->{option}})))
|
||||||
{
|
{
|
||||||
push(@szyParam, "--${strOption}=$rhConfig->{option}{$strOption}");
|
if ($self->optionTestSecure($strOption))
|
||||||
|
{
|
||||||
|
$strConfig .= "${strOption}=$rhConfig->{option}{$strOption}\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
storageTest()->put($strConfigFile, $strConfig);
|
||||||
|
}
|
||||||
|
|
||||||
|
####################################################################################################################################
|
||||||
|
# Write all non-secure options to the command line
|
||||||
|
####################################################################################################################################
|
||||||
|
sub commandTestWrite
|
||||||
|
{
|
||||||
|
my $self = shift;
|
||||||
|
my $strCommand = shift;
|
||||||
|
my $strConfigFile = shift;
|
||||||
|
my $rhConfig = shift;
|
||||||
|
|
||||||
|
my @szyParam = ();
|
||||||
|
|
||||||
|
# Add boolean options
|
||||||
|
if (defined($rhConfig->{boolean}))
|
||||||
|
{
|
||||||
|
foreach my $strOption (sort(keys(%{$rhConfig->{boolean}})))
|
||||||
|
{
|
||||||
|
if (!$self->optionTestSecure($strOption))
|
||||||
|
{
|
||||||
|
if ($rhConfig->{boolean}{$strOption})
|
||||||
|
{
|
||||||
|
push(@szyParam, "--${strOption}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
push(@szyParam, "--no-${strOption}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add non-boolean options
|
||||||
|
if (defined($rhConfig->{option}))
|
||||||
|
{
|
||||||
|
foreach my $strOption (sort(keys(%{$rhConfig->{option}})))
|
||||||
|
{
|
||||||
|
if (!$self->optionTestSecure($strOption))
|
||||||
|
{
|
||||||
|
push(@szyParam, "--${strOption}=$rhConfig->{option}{$strOption}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Add config file
|
||||||
|
push(@szyParam, '--' . cfgOptionName(CFGOPT_CONFIG) . "=${strConfigFile}");
|
||||||
|
|
||||||
|
# Add command
|
||||||
push(@szyParam, $strCommand);
|
push(@szyParam, $strCommand);
|
||||||
|
|
||||||
return @szyParam;
|
return @szyParam;
|
||||||
@ -112,7 +177,11 @@ sub configTestLoad
|
|||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $iCommandId = shift;
|
my $iCommandId = shift;
|
||||||
|
|
||||||
my @stryArg = $self->commandTestWrite(cfgCommandName($iCommandId), $self->{&CONFIGENVTEST});
|
# A config file is required to store secure options before they can be parsed
|
||||||
|
my $strConfigFile = $self->testPath() . '/pgbackrest.test.conf';
|
||||||
|
$self->configFileWrite($strConfigFile, $self->{&CONFIGENVTEST});
|
||||||
|
|
||||||
|
my @stryArg = $self->commandTestWrite(cfgCommandName($iCommandId), $strConfigFile, $self->{&CONFIGENVTEST});
|
||||||
my $strConfigJson = cfgParseTest(backrestBin(), join('|', @stryArg));
|
my $strConfigJson = cfgParseTest(backrestBin(), join('|', @stryArg));
|
||||||
$self->testResult(
|
$self->testResult(
|
||||||
sub {configLoad(false, backrestBin(), cfgCommandName($iCommandId), \$strConfigJson)},
|
sub {configLoad(false, backrestBin(), cfgCommandName($iCommandId), \$strConfigJson)},
|
||||||
|
@ -133,11 +133,11 @@ testRun()
|
|||||||
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
|
||||||
strLstAdd(argList, strNew("--no-config"));
|
strLstAdd(argList, strNew("--no-config"));
|
||||||
strLstAdd(argList, strNew("--stanza=db"));
|
strLstAdd(argList, strNew("--stanza=db"));
|
||||||
strLstAdd(argList, strNew("--repo1-s3-key=xxx"));
|
strLstAdd(argList, strNew("--repo1-s3-host=xxx"));
|
||||||
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
strLstAdd(argList, strNew(TEST_COMMAND_BACKUP));
|
||||||
TEST_ERROR(
|
TEST_ERROR(
|
||||||
configParse(strLstSize(argList), strLstPtr(argList)), OptionInvalidError,
|
configParse(strLstSize(argList), strLstPtr(argList)), OptionInvalidError,
|
||||||
"option 'repo1-s3-key' not valid without option 'repo1-type' = 's3'");
|
"option 'repo1-s3-host' not valid without option 'repo1-type' = 's3'");
|
||||||
|
|
||||||
// -------------------------------------------------------------------------------------------------------------------------
|
// -------------------------------------------------------------------------------------------------------------------------
|
||||||
argList = strLstNew();
|
argList = strLstNew();
|
||||||
|
Reference in New Issue
Block a user