diff options
author | Dylan William Hardison <dylan@hardison.net> | 2018-08-09 04:29:23 +0200 |
---|---|---|
committer | Dylan William Hardison <dylan@hardison.net> | 2018-08-20 23:52:52 +0200 |
commit | 59fe9f7c0e56abd084c711455d5639d163312e52 (patch) | |
tree | dc43309ee2c1f466c8aa544977626d77293749c8 /Bugzilla/Quantum | |
parent | 96e529c4357f7f7832465b71f42994854a174cdd (diff) | |
download | bugzilla-59fe9f7c0e56abd084c711455d5639d163312e52.tar.gz bugzilla-59fe9f7c0e56abd084c711455d5639d163312e52.tar.xz |
add more testing
Diffstat (limited to 'Bugzilla/Quantum')
-rw-r--r-- | Bugzilla/Quantum/SES.pm | 58 | ||||
-rw-r--r-- | 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,8 +18,25 @@ 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; my $message_type = $self->req->headers->header('X-Amz-SNS-Message-Type') // '(missing)'; @@ -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 { |