From 810d2c7f944822eba10bbd884ae499271f16fb67 Mon Sep 17 00:00:00 2001 From: Maxime Besson Date: Tue, 27 Aug 2019 11:01:32 +0200 Subject: [PATCH] Disable template cache to avoid translation issues in mail (#1897) --- .../lib/Lemonldap/NG/Portal/Lib/SMTP.pm | 2 ++ .../lib/Lemonldap/NG/Portal/Main/Run.pm | 2 +- lemonldap-ng-portal/t/43-MailPasswordReset.t | 24 +++++++++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm index deddab1a4..2a6f67f7d 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Lib/SMTP.pm @@ -84,6 +84,8 @@ has transport => ( sub loadMailTemplate { my ( $self, $req, $name, %prm ) = @_; + # HTML::Template cache interferes with email translation (#1897) + $prm{cache} = 0 unless defined $prm{cache}; $prm{params}->{STATIC_PREFIX} = $self->p->staticPrefix; my %extra = $self->p->can('tplParams') diff --git a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm index dfa76bf7f..c3378488e 100644 --- a/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm +++ b/lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Main/Run.pm @@ -1058,7 +1058,7 @@ sub loadTemplate { search_path_on_include => 1, die_on_bad_params => 0, die_on_missing_include => 1, - cache => 1, + cache => ( defined $prm{cache} ? $prm{cache} : 1 ), global_vars => 0, ( $prm{filter} ? ( filter => $prm{filter} ) : () ), ); diff --git a/lemonldap-ng-portal/t/43-MailPasswordReset.t b/lemonldap-ng-portal/t/43-MailPasswordReset.t index df6d4263e..bc456ca8a 100644 --- a/lemonldap-ng-portal/t/43-MailPasswordReset.t +++ b/lemonldap-ng-portal/t/43-MailPasswordReset.t @@ -10,10 +10,7 @@ BEGIN { } my ( $res, $user, $pwd ); -my $maintests = 9; -my $mailSend = 0; - -my $mail2 = 0; +my $maintests = 12; SKIP: { eval @@ -50,7 +47,20 @@ SKIP: { $res = $client->_post( '/resetpwd', IO::String->new($query), length => length($query), - accept => 'text/html' + accept => 'text/html', + cookie => 'llnglanguage=fr', + ), + 'Post mail' + ); + like( mail(), qr#Bonjour#, "Found french greeting" ); + + # Test another language (#1897) + ok( + $res = $client->_post( + '/resetpwd', IO::String->new($query), + length => length($query), + accept => 'text/html', + cookie => 'llnglanguage=en', ), 'Post mail' ); @@ -62,6 +72,8 @@ SKIP: { ok( mail() =~ m%Content-Type: image/png; name="logo_llng_old.png"%, 'Found custom Main logo in mail' ) or print STDERR Dumper( mail() ); + like( mail(), qr#Hello#, "Found english greeting" ); + ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#, 'Found link in mail' ); $query = $1; @@ -89,8 +101,6 @@ SKIP: { ); ok( mail() =~ /Your password was changed/, 'Password was changed' ); - - #print STDERR Dumper($query); } count($maintests);