fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2012-01-10 11:50 am

[dw-free] suppress reset notifications from running console-reset.t

[commit: http://hg.dwscoalition.org/dw-free/rev/bd7b2d844877]

http://bugs.dwscoalition.org/show_bug.cgi?id=4204

Allow tests to disable notifications from email resets.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Console/Command/ResetPassword.pm
  • cgi-bin/LJ/User.pm
  • t/console-reset.t
--------------------------------------------------------------------------------
diff -r 0df25880fd10 -r bd7b2d844877 cgi-bin/LJ/Console/Command/ResetPassword.pm
--- a/cgi-bin/LJ/Console/Command/ResetPassword.pm	Tue Jan 10 19:48:23 2012 +0800
+++ b/cgi-bin/LJ/Console/Command/ResetPassword.pm	Tue Jan 10 19:51:34 2012 +0800
@@ -54,18 +54,20 @@
 
     $u->kill_all_sessions;
 
-    my $body = "The password for your $LJ::SITENAME account '$username' has been reset to:\n\n";
-    $body .= "     $newpass\n\n";
-    $body .= "Please change it immediately by going to:\n\n";
-    $body .= "     $LJ::SITEROOT/changepassword\n\n";
-    $body .= "Regards,\n$LJ::SITENAME Team\n\n$LJ::SITEROOT/\n";
+    unless ( $LJ::T_SUPPRESS_EMAIL ) {
+        my $body = "The password for your $LJ::SITENAME account '$username' has been reset to:\n\n";
+        $body .= "     $newpass\n\n";
+        $body .= "Please change it immediately by going to:\n\n";
+        $body .= "     $LJ::SITEROOT/changepassword\n\n";
+        $body .= "Regards,\n$LJ::SITENAME Team\n\n$LJ::SITEROOT/\n";
 
-    LJ::send_mail({
-        'to' => $u->email_raw,
-        'from' => $LJ::ADMIN_EMAIL,
-        'subject' => "Password Reset",
-        'body' => $body,
-    }) or $self->info("New password notification email could not be sent.");
+        LJ::send_mail( {
+            'to' => $u->email_raw,
+            'from' => $LJ::ADMIN_EMAIL,
+            'subject' => "Password Reset",
+            'body' => $body,
+        } ) or $self->info("New password notification email could not be sent.");
+    }
 
     my $remote = LJ::get_remote();
     LJ::statushistory_add($u, $remote, "reset_password", $reason);
diff -r 0df25880fd10 -r bd7b2d844877 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Tue Jan 10 19:48:23 2012 +0800
+++ b/cgi-bin/LJ/User.pm	Tue Jan 10 19:51:34 2012 +0800
@@ -4684,7 +4684,9 @@
         return $errsub->( LJ::Lang::ml( "email.emailreset.error",
                                         { user => $u->user } ) );
 
-    if ( defined $emailsucc ) {
+    if ( $LJ::T_SUPPRESS_EMAIL ) {
+        $$emailsucc = 1 if ref $emailsucc;  # pretend we sent it
+    } elsif ( defined $emailsucc ) {
         my $aa = LJ::register_authaction( $u->id, "validateemail", $newemail );
         my $auth = "$aa->{aaid}.$aa->{authcode}";
         my $sent = LJ::send_mail( {
diff -r 0df25880fd10 -r bd7b2d844877 t/console-reset.t
--- a/t/console-reset.t	Tue Jan 10 19:48:23 2012 +0800
+++ b/t/console-reset.t	Tue Jan 10 19:51:34 2012 +0800
@@ -6,6 +6,7 @@
 use LJ::Console;
 use LJ::Test qw (temp_user);
 local $LJ::T_NO_COMMAND_PRINT = 1;
+local $LJ::T_SUPPRESS_EMAIL = 1;
 
 plan tests => 14;
 
--------------------------------------------------------------------------------