Debian Codegraph @

lemonldap-ng-common/t/60-Hashed-Session.t

raw
1 use warnings;
2
3 use Test::More;
4 use Test::Output;
5 use File::Path;
6 use Data::Dumper;
7 use JSON;
8
9 BEGIN {
10 use_ok('Lemonldap::NG::Common::Session');
11 use_ok('Lemonldap::NG::Common::CliSessions');
12 }
13
14 use File::Temp;
15 my $dir = File::Temp::tempdir();
16 my $sessionsdir = "$dir/sessions";
17 my $psessionsdir = "$dir/psessions";
18 mkdir $sessionsdir;
19 mkdir $psessionsdir;
20
21 my $session;
22
23 ok(
24 $session = Lemonldap::NG::Common::Session->new( {
25 force => 1,
26 hashStore => 1,
27 id => "123",
28 storageModule => 'Apache::Session::File',
29 storageModuleOptions => { Directory => $sessionsdir },
30 kind => "SSO",
31 info => { aa => 1 },
32 }
33 ),
34 'Create fixed session'
35 );
36 ok( -f "$sessionsdir/" . id2storage('123'), 'Session name is hashed' );
37
38 ok(
39 $session = Lemonldap::NG::Common::Session->new( {
40 hashStore => 1,
41 id => "123",
42 storageModule => 'Apache::Session::File',
43 storageModuleOptions => { Directory => $sessionsdir },
44 kind => "SSO",
45 }
46 ),
47 'Recover fixed session'
48 );
49 ok( $session->data->{aa} == 1, 'Data restored' );
50
51 ok(
52 $session = Lemonldap::NG::Common::Session->new( {
53 hashStore => 1,
54 id => undef,
55 storageModule => 'Apache::Session::File',
56 storageModuleOptions => { Directory => $sessionsdir },
57 kind => "SSO",
58 info => { bb => 1 },
59 }
60 ),
61 'Create session'
62 );
63
64 ok( -f "$sessionsdir/" . id2storage( $session->id ), 'Session name is hashed' );
65
66 ok(
67 $session = Lemonldap::NG::Common::Session->new( {
68 hashStore => 1,
69 id => $session->id,
70 storageModule => 'Apache::Session::File',
71 storageModuleOptions => { Directory => $sessionsdir },
72 kind => "SSO",
73 }
74 ),
75 'Recover session'
76 );
77 ok( $session->data->{bb} == 1, 'Data restored' );
78
79 ok(
80 $session = Lemonldap::NG::Common::Session->new( {
81 hashStore => 1,
82 id => $session->id,
83 storageModule => 'Apache::Session::File',
84 storageModuleOptions => { Directory => $sessionsdir },
85 kind => "SSO",
86 info => { bb => 1, cc => 2 },
87 }
88 ),
89 'Recover session'
90 );
91 ok( $session->data->{bb} == 1 && $session->data->{cc} == 2, 'Data updated' )
92 or print STDERR Dumper( $session->data );
93
94 ok(
95 $session = Lemonldap::NG::Common::Session->new( {
96 hashStore => 1,
97 id => $session->id,
98 storageModule => 'Apache::Session::File',
99 storageModuleOptions => { Directory => $sessionsdir },
100 kind => "SSO",
101 }
102 ),
103 'Recover session'
104 );
105 ok( $session->data->{bb} == 1 && $session->data->{cc} == 2, 'Data updated' )
106 or print STDERR Dumper( $session->data );
107
108 rmtree $dir;
109 done_testing();