From cdc51df9e68f65ce71ae8c7ca4c39d29a690875f Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Fri, 10 Aug 2012 11:00:26 -0600 Subject: [PATCH] Fix HTTPMicro POST: attach content to request. Validate type. --- bin/pt-table-checksum | 23 +++++++++++++++++++++-- lib/HTTPMicro.pm | 1 + lib/VersionCheck.pm | 19 ++++++++++++++++++- t/lib/VersionCheck.t | 21 +++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index cb9e6bf8..69eb8991 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -38,7 +38,17 @@ sub Dumper { sub new { 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 { @@ -100,6 +110,13 @@ sub get_versions { sub valid_item { my ($self, $item) = @_; + return unless $item; + + if ( ($item->{type} || '') !~ m/$self->{valid_types}/ ) { + PTDEBUG && _d('Invalid type:', $item->{type}); + return; + } + return 1; } @@ -386,6 +403,7 @@ sub _prepare_headers_and_cb { utf8::downgrade($args->{content}, 1) or Carp::croak(q/Wide character in request message body/); $request->{headers}{'content-length'} = length $args->{content}; + $request->{content} = $args->{content}; } return; } @@ -7883,13 +7901,14 @@ sub main { # TODO: how to format this? print "--version-check advice:\n"; print join("\n", map { " * $_" } @$advice); + print "\n"; } }; if ( $EVAL_ERROR ) { PTDEBUG && _d('Error doing --version-check:', $EVAL_ERROR); } } - + # ######################################################################## # 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 diff --git a/lib/HTTPMicro.pm b/lib/HTTPMicro.pm index bdff27bd..a47700a1 100644 --- a/lib/HTTPMicro.pm +++ b/lib/HTTPMicro.pm @@ -138,6 +138,7 @@ sub _prepare_headers_and_cb { utf8::downgrade($args->{content}, 1) or Carp::croak(q/Wide character in request message body/); $request->{headers}{'content-length'} = length $args->{content}; + $request->{content} = $args->{content}; } return; } diff --git a/lib/VersionCheck.pm b/lib/VersionCheck.pm index 13617a45..870d4391 100644 --- a/lib/VersionCheck.pm +++ b/lib/VersionCheck.pm @@ -41,7 +41,17 @@ sub Dumper { sub new { 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 { @@ -103,6 +113,13 @@ sub get_versions { sub valid_item { my ($self, $item) = @_; + return unless $item; + + if ( ($item->{type} || '') !~ m/$self->{valid_types}/ ) { + PTDEBUG && _d('Invalid type:', $item->{type}); + return; + } + return 1; } diff --git a/t/lib/VersionCheck.t b/t/lib/VersionCheck.t index 4939f08a..8a256886 100644 --- a/t/lib/VersionCheck.t +++ b/t/lib/VersionCheck.t @@ -174,6 +174,27 @@ ok( "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. # #############################################################################