Commit 122d9157 authored by Xavier Guimard's avatar Xavier Guimard

Fix session duplication (#354)

TODO: bad session count with IP
parent 1c76c713
......@@ -11,12 +11,15 @@ has id => ( is => 'rw' );
package main;
use Test::More;
use strict;
use POSIX qw(mktime strftime);
use lib 'lemonldap-ng-common/blib/lib';
use lib 'lemonldap-ng-handler/blib/lib';
use lib 'lemonldap-ng-portal/blib/lib';
use lib 'lemonldap-ng-manager/blib/lib';
require './lemonldap-ng-portal/t/test-lib.pm';
use constant COUNT => 1000;
my $portal = LLNG::Manager::Test->new(
{
ini => {
......@@ -30,17 +33,29 @@ my $portal = LLNG::Manager::Test->new(
)->p;
my @chars = ( "A" .. "Z", "a" .. "z" );
foreach my $i ( 1 .. 100000 ) {
foreach my $i ( 1 .. COUNT() ) {
my $string;
$string .= $chars[ rand @chars ] for 1 .. 8;
#$string = 'dwho';
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
localtime(time);
$hour = int( rand($hour) );
$min = int( rand(60) );
$sec = int( rand(60) );
my $req = Test::Request->new(
{
sessionInfo => {
_user => $string,
uid => $string,
cn => uc($string),
sn => $string,
mail => "$string\@badwolf.org",
_user => $string,
uid => $string,
cn => uc($string),
sn => $string,
mail => "$string\@badwolf.org",
_utime => mktime( $sec, $min, $hour, $mday, $mon, $year ),
startTime => strftime(
"%Y%m%d%H%M%S",
$sec, $min, $hour, $mday, $mon,
$year, $wday, $yday, $isdst
),
}
}
);
......
......@@ -99,6 +99,11 @@ sub sessions {
: ( $s => $params->{$_} );
} keys %$params;
$filters{_session_kind} = $type;
push @fields, keys(%filters);
{
my %seen;
@fields = grep { !$seen{$_}++ } @fields;
}
# Check if a '*' is required
my $function = 'searchOn';
......@@ -112,6 +117,8 @@ sub sessions {
: $b eq '_session_kind' ? -1
: $a cmp $b
} keys %filters;
$self->logger->debug(
"First filter: $firstFilter = $filters{$firstFilter} ($function)");
$res =
Lemonldap::NG::Common::Apache::Session->$function( $moduleOptions,
$firstFilter, $filters{$firstFilter}, @fields );
......@@ -128,6 +135,7 @@ sub sessions {
delete $filters{$firstFilter};
foreach my $k ( keys %filters ) {
$self->logger->debug("Removing unless $k =~ /^$filters{$k}\$/");
$filters{$k} =~ s/\*/\.\*/g;
foreach my $session ( keys %$res ) {
if ( $res->{$session}->{$k} ) {
......
......@@ -18,7 +18,7 @@ schemes =
]
ipAddr: [
(t,v) ->
"#{t}=#{v}*&groupBy=net4(#{t},1)"
"groupBy=net4(#{t},1)"
(t,v) ->
"#{t}=#{v}*&groupBy=net4(#{t},2)"
(t,v) ->
......@@ -34,14 +34,17 @@ schemes =
(t,v) ->
"groupBy=substr(#{t},8)"
(t,v) ->
"groupBy=substr(#{t},10)"
"#{t}=#{v}*&groupBy=substr(#{t},10)"
(t,v) ->
"groupBy=substr(#{t},11)"
"#{t}=#{v}*&groupBy=substr(#{t},11)"
(t,v) ->
"groupBy=substr(#{t},12)"
"#{t}=#{v}*&groupBy=substr(#{t},12)"
(t,v) ->
"#{t}=#{v}*&groupBy=_whatToTrace"
(t,v,q) ->
console.log t
console.log v
console.log q
q.replace(/\&groupBy.*$/, '') + "&_whatToTrace=#{v}"
]
doubleIp: [
......
......@@ -21,7 +21,7 @@
],
ipAddr: [
function(t, v) {
return t + "=" + v + "*&groupBy=net4(" + t + ",1)";
return "groupBy=net4(" + t + ",1)";
}, function(t, v) {
return t + "=" + v + "*&groupBy=net4(" + t + ",2)";
}, function(t, v) {
......@@ -38,14 +38,17 @@
function(t, v) {
return "groupBy=substr(" + t + ",8)";
}, function(t, v) {
return "groupBy=substr(" + t + ",10)";
return t + "=" + v + "*&groupBy=substr(" + t + ",10)";
}, function(t, v) {
return "groupBy=substr(" + t + ",11)";
return t + "=" + v + "*&groupBy=substr(" + t + ",11)";
}, function(t, v) {
return "groupBy=substr(" + t + ",12)";
return t + "=" + v + "*&groupBy=substr(" + t + ",12)";
}, function(t, v) {
return t + "=" + v + "*&groupBy=_whatToTrace";
}, function(t, v, q) {
console.log(t);
console.log(v);
console.log(q);
return q.replace(/\&groupBy.*$/, '') + ("&_whatToTrace=" + v);
}
],
......
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