Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
TTO-153 Logged-in user doesn't see collections despite matching usern…
Browse files Browse the repository at this point in the history
…ame (#30)

* TTO-153 Logged-in user doesn't see collections despite matching username
- `Utils::Get_Remote_User_Names` modified to include case-preserved `REMOTE_USER` and `eppn` components.
  • Loading branch information
moseshll authored Nov 29, 2023
1 parent 973d534 commit 67faf66
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,20 @@ sub Get_Legacy_Remote_User {
return $remote_user;
}

# Returns an array of unique (Get_Remote_User, case-preserving REMOTE_USER if it exists,
# EPPN components in case-preserving and lowercase-only forms).
# Note: returns the empty string when user is not logged in, i.e., returns ('')
sub Get_Remote_User_Names {
my @usernames = ( Get_Remote_User() );
if ( exists $ENV{REMOTE_USER} && defined $ENV{REMOTE_USER} && $ENV{REMOTE_USER} ) {
my $value = $ENV{REMOTE_USER};
push @usernames, $value unless grep(/^$value$/, @usernames);
}
if ( defined $ENV{eppn} && $ENV{eppn} ) {
foreach my $value ( split(/;/, lc $ENV{eppn} ) ) {
foreach my $value ( split(/;/, $ENV{eppn} ) ) {
next unless $value;
push @usernames, $value unless ( grep(/^$value$/, @usernames) );
$value = lc $value;
push @usernames, $value unless ( grep(/^$value$/, @usernames) );
}
}
Expand Down
37 changes: 37 additions & 0 deletions t/Utils.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/perl

use strict;
use warnings;
use Test::More;

use Utils;

local %ENV = %ENV;

subtest "Get_Remote_User_Names" => sub {
my $save_remote_user = $ENV{REMOTE_USER};
my $save_eppn = $ENV{eppn};

subtest "with logged-in user" => sub {
$ENV{eppn} = 'EPPN@default.invalid';
$ENV{REMOTE_USER} = 'REMOTE_USER@default.invalid';
my @names = Utils::Get_Remote_User_Names();
ok(1 <= scalar grep(/remote_user/, @names), "contains lowercase REMOTE_USER");
ok(1 <= scalar grep(/REMOTE_USER/, @names), "contains case-preserved REMOTE_USER");
ok(1 <= scalar grep(/eppn/, @names), "contains lowercase EPPN");
ok(1 <= scalar grep(/EPPN/, @names), "contains case-preserved EPPN");
};

subtest "with logged-out user" => sub {
delete $ENV{REMOTE_USER};
delete $ENV{eppn};
my @names = Utils::Get_Remote_User_Names();
ok(1 == scalar @names, "there is one name");
ok('' eq $names[0], "name is empty string");
};

$ENV{REMOTE_USER} = $save_remote_user;
$ENV{eppn} = $save_eppn;
};

done_testing();

0 comments on commit 67faf66

Please sign in to comment.