summaryrefslogtreecommitdiffstats
path: root/Bugzilla/Quantum
diff options
context:
space:
mode:
authorDylan William Hardison <dylan@hardison.net>2018-10-04 15:34:13 +0200
committerGitHub <noreply@github.com>2018-10-04 15:34:13 +0200
commitd32521c8b2ca82469540caff9a6ce5a9ca3c4f7b (patch)
treed276aec8f4e36449c49f50904543dffe1b4726d9 /Bugzilla/Quantum
parente3fb2fbabb83a12117ca8db405dacd1781c028cd (diff)
downloadbugzilla-d32521c8b2ca82469540caff9a6ce5a9ca3c4f7b.tar.gz
bugzilla-d32521c8b2ca82469540caff9a6ce5a9ca3c4f7b.tar.xz
Bug 1495901 - SES type checking error
Diffstat (limited to 'Bugzilla/Quantum')
-rw-r--r--Bugzilla/Quantum/SES.pm101
1 files changed, 59 insertions, 42 deletions
diff --git a/Bugzilla/Quantum/SES.pm b/Bugzilla/Quantum/SES.pm
index 750da4e77..2d19de240 100644
--- a/Bugzilla/Quantum/SES.pm
+++ b/Bugzilla/Quantum/SES.pm
@@ -19,11 +19,60 @@ 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__};
+use Type::Library -base, -declare => qw(
+ Self
+ Notification NotificationType TypeField
+ BounceNotification BouncedRecipients
+ ComplaintNotification ComplainedRecipients
+);
+use Type::Utils -all;
+use Types::Standard -all;
+use Type::Params qw(compile);
+
+class_type Self, {class => __PACKAGE__};
+
+declare ComplainedRecipients,
+ as ArrayRef [Dict [emailAddress => Str, slurpy Any]];
+declare ComplaintNotification,
+ as Dict [
+ complaint => Dict [
+ complainedRecipients => ComplainedRecipients,
+ complaintFeedbackType => Str,
+ slurpy Any,
+ ],
+ slurpy Any,
+ ];
+
+declare BouncedRecipients,
+ as ArrayRef [
+ Dict [
+ emailAddress => Str,
+ action => Optional [Str],
+ diagnosticCode => Optional [Str],
+ status => Optional [Str],
+ slurpy Any,
+ ],
+ ];
+declare BounceNotification,
+ as Dict [
+ bounce => Dict [
+ bouncedRecipients => BouncedRecipients,
+ reportingMTA => Str,
+ bounceSubType => Str,
+ bounceType => Str,
+ slurpy Any,
+ ],
+ slurpy Any,
+ ];
+
+declare NotificationType, as Enum [qw( Bounce Complaint )];
+declare TypeField, as Enum [qw(eventType notificationType)];
+declare Notification,
+ as Dict [
+ eventType => Optional [NotificationType],
+ notificationType => Optional [NotificationType],
+ slurpy Any,
+ ];
sub main {
my ($self) = @_;
@@ -70,7 +119,7 @@ sub _main {
}
sub _confirm_subscription {
- state $check = compile($Invocant, Dict [SubscribeURL => Str, slurpy Any]);
+ state $check = compile(Self, Dict [SubscribeURL => Str, slurpy Any]);
my ($self, $message) = $check->(@_);
my $subscribe_url = $message->{SubscribeURL};
@@ -91,16 +140,8 @@ 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 {
- state $check = compile($Invocant, $Notification, $TypeField);
+ state $check = compile(Self, Notification, TypeField);
my ($self, $notification, $type_field) = $check->(@_);
if (!exists $notification->{$type_field}) {
@@ -121,22 +162,8 @@ sub _handle_notification {
return 1;
}
-my $BouncedRecipients = ArrayRef [
- Dict [emailAddress => Str, action => Str, diagnosticCode => Str, slurpy Any,],
-];
-my $BounceNotification = Dict [
- bounce => Dict [
- bouncedRecipients => $BouncedRecipients,
- reportingMTA => Str,
- bounceSubType => Str,
- bounceType => Str,
- slurpy Any,
- ],
- slurpy Any,
-];
-
sub _process_bounce {
- state $check = compile($Invocant, $BounceNotification);
+ state $check = compile(Self, BounceNotification);
my ($self, $notification) = $check->(@_);
# disable each account that is bouncing
@@ -180,18 +207,8 @@ 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 {
- state $check = compile($Invocant, $ComplaintNotification);
+ state $check = compile(Self, ComplaintNotification);
my ($self, $notification) = $check->(@_);
my $template = Bugzilla->template_inner();
my $json = JSON::MaybeXS->new(pretty => 1, utf8 => 1, canonical => 1,);
@@ -223,7 +240,7 @@ sub _respond {
}
sub _decode_json_wrapper {
- state $check = compile($Invocant, Str);
+ state $check = compile(Self, Str);
my ($self, $json) = $check->(@_);
my $result;
my $ok = try {