Add SMTPAuthUser and SMTPAuthPass in Manager, with SMTP connection and authentication tests on configuration save (#293)

This commit is contained in:
Clément Oudot 2011-04-15 09:44:15 +00:00
parent 2b45ee0a5e
commit 8e023b267d
2 changed files with 38 additions and 1 deletions

View File

@ -759,10 +759,12 @@ sub struct {
passwordManagement => {
_nodes => [
qw(SMTPServer mailUrl mailFrom mailSubject mailBody mailConfirmSubject mailConfirmBody randomPasswordRegexp)
qw(SMTPServer SMTPAuthUser SMTPAuthPass mailUrl mailFrom mailSubject mailBody mailConfirmSubject mailConfirmBody randomPasswordRegexp)
],
_help => 'password',
SMTPServer => 'text:/SMTPServer',
SMTPAuthUser => 'text:/SMTPAuthUser',
SMTPAuthPass => 'text:/SMTPAuthPass',
mailUrl => 'text:/mailUrl',
mailFrom => 'text:/mailFrom',
mailSubject => 'text:/mailSubject',
@ -1186,6 +1188,8 @@ sub testStruct {
passwordDB => $testNotDefined,
mailBody => $testNotDefined,
SMTPServer => $testNotDefined,
SMTPAuthUser => $testNotDefined,
SMTPAuthPass => $testNotDefined,
cookieExpiration => $testNotDefined,
notificationStorage => $testNotDefined,
mailUrl => $testNotDefined,
@ -2084,6 +2088,35 @@ sub globalTests {
);
},
# Test SMTP connection and authentication
smtpConnectionAuthentication => sub {
# Skip test if no SMTP configuration
return 1 unless ( $conf->{SMTPServer} );
# Use SMTP
eval "use Net::SMTP";
return ( 0, "Net::SMTP module is required to use SMTP server" )
if ($@);
# Create SMTP object
my $smtp = Net::SMTP->new( $conf->{SMTPServer} );
return ( 0,
"SMTP connection to " . $conf->{SMTPServer} . " failed" )
unless ($smtp);
# Skip other tests if no authentication
return 1 unless ( $conf->{SMTPAuthUser} and $conf->{SMTPAuthPass} );
# Try authentication
return ( 0, "SMTP authentication failed" )
unless $smtp->auth( $conf->{SMTPAuthUser},
$conf->{SMTPAuthPass} );
# Return
return 1;
},
# 2. MODIFICATIONS
# Remove unused and non-customized parameters

View File

@ -259,6 +259,8 @@ sub en {
singleUserByIP => 'One user by IP address',
slaveAuthnLevel => 'Authentication level',
slaveParams => 'Slave parameters',
SMTPAuthPass => 'SMTP password',
SMTPAuthUser => 'SMTP user',
SMTPServer => 'SMTP server',
soap => 'SOAP',
Soap => 'Activation',
@ -646,6 +648,8 @@ sub fr {
singleUserByIP => 'Une seule adresse IP par utilisateur',
slaveAuthnLevel => 'Niveau d\'authentification',
slaveParams => 'Paramètres Slave',
SMTPAuthPass => 'Mot de passe SMTP',
SMTPAuthUser => 'Utilisateur SMTP',
SMTPServer => 'Serveur SMTP',
soap => 'SOAP',
Soap => 'Activation',