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

TTO-153 Logged-in user doesn't see collections despite matching username #30

Merged
merged 3 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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} ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, line 110 gets the lowercased REMOTE_USER, and this line gets a case-preserved version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

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();
Loading