Commit 61eb91b7 authored by Xavier Guimard's avatar Xavier Guimard

Store pdata in mailToken (#1508)

parent 95d792d6
......@@ -117,6 +117,9 @@ sub _reset {
$req->data->{mailAddress} =
$mailSession->data->{ $self->conf->{mailSessionKey} };
$self->logger->debug( 'User associated to: ' . $req->{user} );
# Restore pdata if any
$req->pdata( $mailSession->data->{_pdata} || {} );
$mailSession->remove;
$searchByMail = 0 unless ( $req->{user} =~ /\@/ );
}
......@@ -239,6 +242,9 @@ sub _reset {
# Store type
$infos->{_type} = "mail";
# Store pdata
$infos->{_pdata} = $req->pdata;
# create session
$mailSession = $self->p->getApacheSession( undef, info => $infos );
......
......@@ -11,7 +11,7 @@ BEGIN {
}
my ( $res, $user, $pwd );
my $maintests = 7;
my $maintests = 14;
my $mailSend = 0;
my $mail2 = 0;
......@@ -61,59 +61,63 @@ SKIP: {
}
);
# Test form
# ------------------------
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ),
'Reset form', );
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail' );
$query = 'mail=yadd%40badwolf.org';
# Post email
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
query => 'test=sql',
length => length($query),
accept => 'text/html'
),
'Post mail'
);
my $pdata = 'lemonldappdata=' . expectCookie( $res, 'lemonldappdata' );
ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
'Found link in mail' );
$query = $1;
ok(
$res = $client->_get(
'/resetpwd',
query => $query,
accept => 'text/html',
cookie => $pdata,
),
'Post mail token received by mail'
);
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password' );
$query .= '&newpassword=zz&confirmpassword=zz';
$pdata = 'lemonldappdata=' . expectCookie( $res, 'lemonldappdata' );
# Post new password
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html',
cookie => $pdata,
),
'Post new password'
);
foreach my $sameBrowser ( 0 .. 1 ) {
# Test form
# ------------------------
ok( $res = $client->_get( '/resetpwd', accept => 'text/html' ),
'Reset form', );
my ( $host, $url, $query ) = expectForm( $res, '#', undef, 'mail' );
$query = 'mail=yadd%40badwolf.org';
# Post email
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
query => 'test=sql',
length => length($query),
accept => 'text/html'
),
'Post mail'
);
my $pdata = 'lemonldappdata=' . expectCookie( $res, 'lemonldappdata' );
ok( mail() =~ /Your password was changed/, 'Password was changed' );
ok( mail() =~ m#a href="http://auth.example.com/resetpwd\?(.*?)"#,
'Found link in mail' );
$query = $1;
#print STDERR Dumper($query);
ok(
$res = $client->_get(
'/resetpwd',
query => $query,
accept => 'text/html',
( $sameBrowser ? ( cookie => $pdata ) : () ),
),
'Post mail token received by mail with '
. ( $sameBrowser ? 'the same browser' : 'another browser' )
);
( $host, $url, $query ) = expectForm( $res, '#', undef, 'token' );
ok( $res->[2]->[0] =~ /newpassword/s, ' Ask for a new password' );
$query .= '&newpassword=zz&confirmpassword=zz';
$pdata = 'lemonldappdata=' . expectCookie( $res, 'lemonldappdata' );
# Post new password
ok(
$res = $client->_post(
'/resetpwd', IO::String->new($query),
length => length($query),
accept => 'text/html',
cookie => $pdata,
),
'Post new password'
);
ok( mail() =~ /Your password was changed/, 'Password was changed' );
#print STDERR Dumper($query);
}
}
eval { unlink 't/userdb.db' };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment