From 59fe9f7c0e56abd084c711455d5639d163312e52 Mon Sep 17 00:00:00 2001 From: Dylan William Hardison Date: Wed, 8 Aug 2018 22:29:23 -0400 Subject: add more testing --- Bugzilla/Quantum/SES.pm | 58 +++++++++++++++++++++++++++++++++++++++++++--- Bugzilla/Quantum/Stdout.pm | 3 ++- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/Bugzilla/Quantum/SES.pm b/Bugzilla/Quantum/SES.pm index 26df7a3eb..119769b32 100644 --- a/Bugzilla/Quantum/SES.pm +++ b/Bugzilla/Quantum/SES.pm @@ -18,7 +18,24 @@ use JSON::MaybeXS qw(decode_json); use LWP::UserAgent (); use Try::Tiny qw(catch try); +use Types::Standard qw( :all ); +use Type::Utils; +use Type::Params qw( compile ); + +my $Invocant = class_type { class => __PACKAGE__ }; + sub main { + my ($self) = @_; + try { + $self->_main; + } + catch { + FATAL($_); + die $_; + }; +} + +sub _main { my ($self) = @_; Bugzilla->error_mode(ERROR_MODE_DIE); my $message = $self->_decode_json_wrapper( $self->req->body ) // return; @@ -70,8 +87,17 @@ sub _confirm_subscription { $self->_respond( 200 => 'OK' ); } +my $NotificationType = Enum [qw( Bounce Complaint )]; +my $TypeField = Enum [qw(eventType notificationType)]; +my $Notification = Dict [ + eventType => Optional [$NotificationType], + notificationType => Optional [$NotificationType], + slurpy Any, +]; + sub _handle_notification { - my ( $self, $notification, $type_field ) = @_; + state $check = compile($Invocant, $Notification, $TypeField ); + my ( $self, $notification, $type_field ) = $check->(@_); if ( !exists $notification->{$type_field} ) { return 0; @@ -91,8 +117,23 @@ sub _handle_notification { return 1; } +my $BouncedRecipients = ArrayRef[ + Dict[ + emailAddress => Str, + action => Str, + diagnosticCode => Int, + slurpy Any, + ], +]; +my $BounceNotification = Dict[ + bounce => Dict[ + bouncedRecipients => $BouncedRecipients, + reportingMTA => Str, + ], +]; sub _process_bounce { - my ($self, $notification) = @_; + state $check = compile($Invocant, $BounceNotification); + my ($self, $notification) = $check->(@_); # disable each account that is bouncing foreach my $recipient ( @{ $notification->{bounce}->{bouncedRecipients} } ) { @@ -132,8 +173,19 @@ sub _process_bounce { $self->_respond( 200 => 'OK' ); } +my $ComplainedRecipients = ArrayRef[Dict[ emailAddress => Str, slurpy Any ]]; +my $ComplaintNotification = Dict[ + complaint => Dict [ + complainedRecipients => $ComplainedRecipients, + complaintFeedbackType => Str, + slurpy Any, + ], + slurpy Any, +]; + sub _process_complaint { - my ($self, $notification) = @_; + state $check = compile($Invocant, $ComplaintNotification); + my ($self, $notification) = $check->(@_); my $template = Bugzilla->template_inner(); my $json = JSON::MaybeXS->new( pretty => 1, diff --git a/Bugzilla/Quantum/Stdout.pm b/Bugzilla/Quantum/Stdout.pm index be7b546ea..9cf19992c 100644 --- a/Bugzilla/Quantum/Stdout.pm +++ b/Bugzilla/Quantum/Stdout.pm @@ -11,6 +11,7 @@ use Moo; use Bugzilla::Logging; use Encode; +use English qw(-no_match_vars); has 'controller' => ( is => 'ro', @@ -41,7 +42,7 @@ sub PRINT { ## no critic (unpack) if ( $self->_encoding ) { $bytes = encode( $self->_encoding, $bytes ); } - $c->write($bytes.$\); + $c->write($bytes . ( $OUTPUT_RECORD_SEPARATOR // '' ) ); } sub BINMODE { -- cgit v1.2.3-24-g4f1b