Skip to content
This repository was 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
Changes from 1 commit
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
Next Next commit
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 committed Nov 27, 2023
commit 8128409506b18dd5e7424be03d680fe029f6a26a
10 changes: 9 additions & 1 deletion Utils.pm
Original file line number Diff line number Diff line change
@@ -103,10 +103,18 @@ 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)
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.

$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} ) ) {
push @usernames, $value unless ( grep(/^$value$/, @usernames) );
$value = lc $value;
push @usernames, $value unless ( grep(/^$value$/, @usernames) );
}
}
32 changes: 32 additions & 0 deletions t/Utils.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/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};
$ENV{eppn} = 'EPPN@default.invalid';
$ENV{REMOTE_USER} = 'REMOTE_USER@default.invalid';
subtest "contains lowercase REMOTE_USER" => sub {
ok(1 <= scalar grep(/remote_user/, Utils::Get_Remote_User_Names()));
};
subtest "contains case-preserved REMOTE_USER" => sub {
ok(1 <= scalar grep(/REMOTE_USER/, Utils::Get_Remote_User_Names()));
};
subtest "contains lowercase EPPN" => sub {
ok(1 <= scalar grep(/eppn/, Utils::Get_Remote_User_Names()));
};
subtest "contains case-preserved EPPN" => sub {
ok(1 <= scalar grep(/EPPN/, Utils::Get_Remote_User_Names()));
};
$ENV{REMOTE_USER} = $save_remote_user;
$ENV{eppn} = $save_eppn;
};

done_testing();