1
0
mirror of https://github.com/pgbackrest/pgbackrest.git synced 2025-03-03 14:52:21 +02:00

Config test code writes secure options to a file instead of passing on the command-line.

This commit is contained in:
David Steele 2018-03-15 11:09:46 -04:00
parent 4fb75c9cc1
commit dd3ce70810
3 changed files with 86 additions and 13 deletions

View File

@ -145,6 +145,10 @@
<p>Buld performance improvements. Improve bin and libc build performance. Improve code generation performance.</p>
</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>
<p>Disable console display of coverage for C files since <code>Devel::Cover</code> does not handle it well.</p>
</release-item>

View File

@ -20,8 +20,21 @@ use pgBackRest::Config::Config;
use pgBackRest::LibC qw(:test);
use pgBackRest::Version;
use pgBackRestTest::Common::RunTest;
use constant CONFIGENVTEST => 'ConfigEnvTest';
####################################################################################################################################
# Is the option secure?
####################################################################################################################################
sub optionTestSecure
{
my $self = shift;
my $strOption = shift;
return (cfgDefOptionSecure(cfgOptionId($strOption)) ? true : false);
}
sub optionTestSet
{
my $self = shift;
@ -68,25 +81,24 @@ sub configTestSet
$self->{&CONFIGENVTEST} = $rhConfig;
}
sub commandTestWrite
####################################################################################################################################
# Write all secure options to a config file
####################################################################################################################################
sub configFileWrite
{
my $self = shift;
my $strCommand = shift;
my $strConfigFile = shift;
my $rhConfig = shift;
my @szyParam = ();
my $strConfig = "[global]\n";
if (defined($rhConfig->{boolean}))
{
foreach my $strOption (sort(keys(%{$rhConfig->{boolean}})))
{
if ($rhConfig->{boolean}{$strOption})
if ($self->optionTestSecure($strOption))
{
push(@szyParam, "--${strOption}");
}
else
{
push(@szyParam, "--no-${strOption}");
$strConfig .= "${strOption}=" . ($rhConfig->{boolean}{$strOption} ? 'y' : 'n') . "\n";
}
}
}
@ -95,10 +107,63 @@ sub commandTestWrite
{
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);
return @szyParam;
@ -112,7 +177,11 @@ sub configTestLoad
my $self = 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));
$self->testResult(
sub {configLoad(false, backrestBin(), cfgCommandName($iCommandId), \$strConfigJson)},

View File

@ -133,11 +133,11 @@ testRun()
strLstAdd(argList, strNew("--pg1-path=/path/to/db"));
strLstAdd(argList, strNew("--no-config"));
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));
TEST_ERROR(
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();