mirror of
https://github.com/percona/percona-toolkit.git
synced 2025-10-22 02:39:04 +00:00
Fix HTTPMicro POST: attach content to request. Validate type.
This commit is contained in:
@@ -38,7 +38,17 @@ sub Dumper {
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %args) = @_;
|
my ($class, %args) = @_;
|
||||||
return bless {}, $class;
|
my $self = {
|
||||||
|
valid_types => qr/
|
||||||
|
^(?:
|
||||||
|
os_version
|
||||||
|
|perl_version
|
||||||
|
|perl_module_version
|
||||||
|
|mysql_variable
|
||||||
|
|bin_version
|
||||||
|
)$/x,
|
||||||
|
};
|
||||||
|
return bless $self, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_server_response {
|
sub parse_server_response {
|
||||||
@@ -100,6 +110,13 @@ sub get_versions {
|
|||||||
|
|
||||||
sub valid_item {
|
sub valid_item {
|
||||||
my ($self, $item) = @_;
|
my ($self, $item) = @_;
|
||||||
|
return unless $item;
|
||||||
|
|
||||||
|
if ( ($item->{type} || '') !~ m/$self->{valid_types}/ ) {
|
||||||
|
PTDEBUG && _d('Invalid type:', $item->{type});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -386,6 +403,7 @@ sub _prepare_headers_and_cb {
|
|||||||
utf8::downgrade($args->{content}, 1)
|
utf8::downgrade($args->{content}, 1)
|
||||||
or Carp::croak(q/Wide character in request message body/);
|
or Carp::croak(q/Wide character in request message body/);
|
||||||
$request->{headers}{'content-length'} = length $args->{content};
|
$request->{headers}{'content-length'} = length $args->{content};
|
||||||
|
$request->{content} = $args->{content};
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -7883,13 +7901,14 @@ sub main {
|
|||||||
# TODO: how to format this?
|
# TODO: how to format this?
|
||||||
print "--version-check advice:\n";
|
print "--version-check advice:\n";
|
||||||
print join("\n", map { " * $_" } @$advice);
|
print join("\n", map { " * $_" } @$advice);
|
||||||
|
print "\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if ( $EVAL_ERROR ) {
|
if ( $EVAL_ERROR ) {
|
||||||
PTDEBUG && _d('Error doing --version-check:', $EVAL_ERROR);
|
PTDEBUG && _d('Error doing --version-check:', $EVAL_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# ########################################################################
|
# ########################################################################
|
||||||
# If this is not a dry run (--explain was not specified), then we're
|
# If this is not a dry run (--explain was not specified), then we're
|
||||||
# going to checksum the tables, so do the necessary preparations and
|
# going to checksum the tables, so do the necessary preparations and
|
||||||
|
@@ -138,6 +138,7 @@ sub _prepare_headers_and_cb {
|
|||||||
utf8::downgrade($args->{content}, 1)
|
utf8::downgrade($args->{content}, 1)
|
||||||
or Carp::croak(q/Wide character in request message body/);
|
or Carp::croak(q/Wide character in request message body/);
|
||||||
$request->{headers}{'content-length'} = length $args->{content};
|
$request->{headers}{'content-length'} = length $args->{content};
|
||||||
|
$request->{content} = $args->{content};
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -41,7 +41,17 @@ sub Dumper {
|
|||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my ($class, %args) = @_;
|
my ($class, %args) = @_;
|
||||||
return bless {}, $class;
|
my $self = {
|
||||||
|
valid_types => qr/
|
||||||
|
^(?:
|
||||||
|
os_version
|
||||||
|
|perl_version
|
||||||
|
|perl_module_version
|
||||||
|
|mysql_variable
|
||||||
|
|bin_version
|
||||||
|
)$/x,
|
||||||
|
};
|
||||||
|
return bless $self, $class;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_server_response {
|
sub parse_server_response {
|
||||||
@@ -103,6 +113,13 @@ sub get_versions {
|
|||||||
|
|
||||||
sub valid_item {
|
sub valid_item {
|
||||||
my ($self, $item) = @_;
|
my ($self, $item) = @_;
|
||||||
|
return unless $item;
|
||||||
|
|
||||||
|
if ( ($item->{type} || '') !~ m/$self->{valid_types}/ ) {
|
||||||
|
PTDEBUG && _d('Invalid type:', $item->{type});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -174,6 +174,27 @@ ok(
|
|||||||
"Newline stripped from OS"
|
"Newline stripped from OS"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
# #############################################################################
|
||||||
|
# Validate items
|
||||||
|
# #############################################################################
|
||||||
|
|
||||||
|
my $versions = $vc->get_versions(
|
||||||
|
items => {
|
||||||
|
'Foo' => {
|
||||||
|
item => 'Foo',
|
||||||
|
type => 'perl_variable',
|
||||||
|
vars => [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
is_deeply(
|
||||||
|
$versions,
|
||||||
|
{},
|
||||||
|
"perl_variable is not a valid type"
|
||||||
|
);
|
||||||
|
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
# Done.
|
# Done.
|
||||||
# #############################################################################
|
# #############################################################################
|
||||||
|
Reference in New Issue
Block a user