Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process: add sensitive option to prevent verbose reporting of the command #256

Merged
merged 1 commit into from
Nov 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/main/perl/Process.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ regardless of any value for C<NoAction>.
By default, commands modify the state and thus C<keeps_state> is
false.

=item C<sensitive>

A boolean specifying whether the arguments contain sensitive information
(like passwords). If C<sensitive> is true, the commandline will not be reported
(by default when C<log> option is used, the commandline is reported
with verbose level).

This does not cover command output. If the output (stdout and/or stderr) contains
sensitve information, make sure to handle it yourself via C<stdout> and/or C<stderr>
options (or by using the C<output> method).

=back

These options will only be used by the execute method.
Expand All @@ -122,6 +133,8 @@ sub _initialize
$self->{NoAction} = 0
};

$self->{sensitive} = $opts{sensitive};

$self->{COMMAND} = $command;

$self->setopts (%opts);
Expand All @@ -145,7 +158,9 @@ sub _LC_Process
my ($self, $function, $args, $noaction_value, $msg, $postmsg) = @_;

$msg =~ s/^(\w)/Not \L$1/ if $self->noAction();
$self->verbose("$msg command: ", $self->stringify_command(), (defined($postmsg) ? " $postmsg" : ''));
$self->verbose("$msg command: ",
($self->{sensitive} ? "$self->{COMMAND}->[0] <sensitive>" : $self->stringify_command()),
(defined($postmsg) ? " $postmsg" : ''));

if ($self->noAction()) {
$self->debug(1, "LC_Process in noaction mode for $function");
Expand Down
18 changes: 15 additions & 3 deletions src/test/perl/process.t
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ like ($str, qr/Executing.*ls a random command.*stdin.*Something/,
"execute_if_exists does the same as execute");
is ($opts{stdin}, "Something", "execute_if_exists does the same thing as execute");


$str = "";
open ($fh, ">", \$str);
$this_app->config_reporter(logfile => $fh);
Expand All @@ -109,6 +110,17 @@ $p->toutput (10);
is ($toutput, 2, "Logged toutput correctly run");
like ($str, qr/Getting output of command: ls a random command.* with 10 seconds/,
"toutput logged");

$str = "";
open ($fh, ">", \$str);
$this_app->config_reporter(logfile => $fh);
my $ps = CAF::Process->new ($command, log => $this_app,
stdin => "Something", sensitive => 1);
$ps->run ();
like ($str, qr/Running the command: ls <sensitive>/,
"run logged with sensitive mode (command not in log)");


init_test();
# Let's test the rest of the commands
$p->pushargs (qw (this does not matter at all));
Expand Down Expand Up @@ -156,15 +168,15 @@ is($p->get_executable, "ls", "get_executable returns executable");
my $ls = $p->is_executable;
like($ls, qr{^/.*ls$}, "Test ls basename resolved to absolute path");

$p = CAF::Process->new([$ls]);
$p = CAF::Process->new([$ls]);
is($p->is_executable, $ls, "Test absolute path");

$p = CAF::Process->new([qw(doesnotexists)]);
$p = CAF::Process->new([qw(doesnotexists)]);
ok(! defined($p->is_executable), "Test can't resolve basename");
is($p->execute_if_exists, 1, "Fails to execute non-existing executable, returns 1");

# empty command process
$p = CAF::Process->new([]);
$p = CAF::Process->new([]);
is("$p", "", "Empty command process is empty string");
ok(! $p, "Empty process is logical false (autogeneration of overloaded bool via new stringify)");

Expand Down