Working on notifications (#595)

environments/ppa-mbqj77/deployments/1
Xavier Guimard 9 years ago
parent 437fef99b6
commit 00a0fe7241
  1. 11
      lemonldap-ng-portal/lib/Lemonldap/NG/Portal/Plugins/Notifications.pm
  2. 1
      lemonldap-ng-portal/site/templates/common/notification.xsl
  3. 37
      lemonldap-ng-portal/t/10-Notifications.t
  4. 1
      lemonldap-ng-portal/t/test-lib.pm

@ -228,17 +228,17 @@ sub getNotifBack {
# Search for Lemonldap::NG cookie (ciphered)
my $id;
if ( $id = $req->cookies
unless ( $id = $req->cookies
and $id =~ s/$self->{conf}->{cookieName}=([^,; ]+)/$1/o )
{
return $self->p->sendError( 'No cookie found', 401 );
return $self->p->sendError( $req, 'No cookie found', 401 );
}
$id = $self->p->HANDLER->tsv->{cipher}->decrypt($id)
or return $self->sendError( 'Unable to decrypt', 500 );
or return $self->sendError( $req, 'Unable to decrypt', 500 );
# Verify that session exists
$self->p->HANDLER->retrieveSession($id)
or return $self->sendError( 'Unknown session', 401 );
or return $self->sendError( $req, 'Unknown session', 401 );
# Restore datas
$self->p->importHandlerDatas($req);
@ -309,8 +309,9 @@ sub rebuildCookies {
my @tmp;
for ( my $i = 0 ; $i < @{ $req->{respHeaders} } ; $i += 2 ) {
push @tmp, $req->respHeaders->[0], $req->respHeaders->[1]
unless ( $req->respHeaders eq 'Set-Cookie' );
unless ( $req->respHeaders->[0] eq 'Set-Cookie' );
}
$req->{respHeaders} = \@tmp;
$self->p->buildCookie($req);
}

@ -21,6 +21,7 @@
<xsl:attribute name="type">checkbox</xsl:attribute>
<xsl:attribute name="name">check<xsl:value-of select="$start"/>x<xsl:value-of select="$level"/>x<xsl:value-of select="$sublevel"/></xsl:attribute>
<xsl:attribute name="id">check<xsl:value-of select="$start"/>x<xsl:value-of select="$level"/>x<xsl:value-of select="$sublevel"/></xsl:attribute>
<xsl:attribute name="value">accepted</xsl:attribute>
</xsl:element>
<xsl:value-of select="."/>
</xsl:element>

@ -9,17 +9,17 @@ my $file = 't/20160530_dwho_dGVzdHJlZg==.xml';
open F, "> $file" or die($!);
print F '<?xml version="1.0" encoding="UTF-8"?>
<root><notification uid="dwho" date="2016-05-30" reference="testref"><root>
<root><notification uid="dwho" date="2016-05-30" reference="testref">
<title>Test title</title>
<subtitle>Test subtitle</subtitle>
<text>This is a test text</text>
<check>Accept test</check>
</root></notification></root>';
</notification></root>';
close F;
init(
{
logLevel => 'error',
logLevel => 'debug',
useSafeJail => 1,
notifications => 1,
templatesDir => 'site/templates/',
@ -49,7 +49,36 @@ ok( $id = $cookies->{lemonldap}, 'Get cookie' )
or explain( $res, 'Set-Cookie: something' );
count(3);
#print STDERR Dumper($res);
# Verify that cookie is ciphered (session unvalid)
ok(
$res = &client->_get(
'/',
query => 'url=aHR0cDovL3Rlc3QxLmV4YW1wbGUuY29tLw==',
cookie => "lemonldap=$id",
),
'Test cookie received'
);
ok( $res->[0] == 401, "Session isn't valid" )
or explain( [ $res->[0], $res->[1] ], 401 );
count(2);
# Try to validate notification without accepting it
my $str = 'reference1x1=testref';
ok(
$res = &client->_post(
'/notifback',
IO::String->new($str),
cookie => "lemonldap=$id",
accept => 'text/html',
length => length($str),
),
"Don't accept notification"
);
ok( $res->[0] == 200, "Don't receive redirection" )
or explain( [ $res->[0], $res->[1] ], 200 );
count(2);
print STDERR Dumper($res);
clean_sessions();

@ -18,6 +18,7 @@ sub init {
$ini->{localSessionStorage} ||= '';
$ini->{logLevel} ||= 'error';
$ini->{cookieName} ||= 'lemonldap';
$ini->{domain} ||= 'example.com';
$ini->{templateDir} ||= 'site/templates';
$ini->{staticPrefix} ||= '/index.fcgi';
$ini->{securedCookie} //= 0;

Loading…
Cancel
Save