|
Lines 7-13
use CGI qw ( -utf8 );
Link Here
|
| 7 |
use Test::MockObject; |
7 |
use Test::MockObject; |
| 8 |
use Test::MockModule; |
8 |
use Test::MockModule; |
| 9 |
use List::MoreUtils qw/all any none/; |
9 |
use List::MoreUtils qw/all any none/; |
| 10 |
use Test::More tests => 24; |
10 |
use Test::More tests => 25; |
| 11 |
use Test::NoWarnings; |
11 |
use Test::NoWarnings; |
| 12 |
use Test::Warn; |
12 |
use Test::Warn; |
| 13 |
use t::lib::Mocks; |
13 |
use t::lib::Mocks; |
|
Lines 1664-1669
subtest 'checkpw for users with shared cardnumber / userid ' => sub {
Link Here
|
| 1664 |
|
1664 |
|
| 1665 |
}; |
1665 |
}; |
| 1666 |
|
1666 |
|
|
|
1667 |
subtest 'DISABLE_SYSPREF permission tests' => sub { |
| 1668 |
plan tests => 6; |
| 1669 |
|
| 1670 |
$schema->storage->txn_begin; |
| 1671 |
|
| 1672 |
# Test the permission checking logic directly using haspermission |
| 1673 |
my $patron_no_debug = |
| 1674 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 4 } } ); # catalogue only |
| 1675 |
my $patron_with_debug = |
| 1676 |
$builder->build_object( { class => 'Koha::Patrons', value => { flags => 4 } } ); # catalogue only initially |
| 1677 |
my $superlibrarian = $builder->build_object( { class => 'Koha::Patrons', value => { flags => 1 } } ); |
| 1678 |
|
| 1679 |
# Add debug permission to second patron by setting the flag directly |
| 1680 |
# Debug permission is bit 32, so we set that bit |
| 1681 |
my $debug_flag = 1 << 32; |
| 1682 |
$patron_with_debug->flags( $patron_with_debug->flags | $debug_flag )->store; |
| 1683 |
|
| 1684 |
# Test that our permission check logic works correctly |
| 1685 |
ok( |
| 1686 |
!haspermission( $patron_no_debug->userid, { debug => 1 } ), |
| 1687 |
'Patron without debug permission correctly denied' |
| 1688 |
); |
| 1689 |
|
| 1690 |
ok( |
| 1691 |
haspermission( $patron_with_debug->userid, { debug => 1 } ), |
| 1692 |
'Patron with debug permission correctly allowed' |
| 1693 |
); |
| 1694 |
|
| 1695 |
ok( |
| 1696 |
haspermission( $superlibrarian->userid, { debug => 1 } ), |
| 1697 |
'Superlibrarian correctly allowed debug permission' |
| 1698 |
); |
| 1699 |
|
| 1700 |
# Test the actual logic more directly by mocking CGI and checking environment variables |
| 1701 |
my $cgi = Test::MockObject->new(); |
| 1702 |
$cgi->mock( |
| 1703 |
'param', |
| 1704 |
sub { |
| 1705 |
my ( $self, $param ) = @_; |
| 1706 |
return 'yes' if $param eq 'DISABLE_SYSPREF_IntranetUserCSS'; |
| 1707 |
return; |
| 1708 |
} |
| 1709 |
); |
| 1710 |
|
| 1711 |
# Mock userenv for patron without debug permission |
| 1712 |
C4::Context->set_userenv( |
| 1713 |
$patron_no_debug->borrowernumber, |
| 1714 |
$patron_no_debug->userid, |
| 1715 |
$patron_no_debug->cardnumber, |
| 1716 |
$patron_no_debug->firstname, |
| 1717 |
$patron_no_debug->surname, |
| 1718 |
$patron_no_debug->branchcode, |
| 1719 |
$patron_no_debug->library->branchname, |
| 1720 |
$patron_no_debug->flags, |
| 1721 |
$patron_no_debug->email // '', |
| 1722 |
'' |
| 1723 |
); |
| 1724 |
|
| 1725 |
# Create mock input for get_template_and_user to trigger our syspref logic |
| 1726 |
my $input_mock = { query => $cgi }; |
| 1727 |
|
| 1728 |
# Simulate the permission check in get_template_and_user |
| 1729 |
delete $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"}; |
| 1730 |
|
| 1731 |
# Test the logic: Should not override for patron without permission |
| 1732 |
if ( C4::Context->userenv && haspermission( C4::Context->userenv->{'id'}, { debug => 1 } ) ) { |
| 1733 |
$ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} = q{} if $cgi->param("DISABLE_SYSPREF_IntranetUserCSS"); |
| 1734 |
} |
| 1735 |
|
| 1736 |
ok( |
| 1737 |
!exists $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"}, |
| 1738 |
'IntranetUserCSS not overridden for patron without debug permission' |
| 1739 |
); |
| 1740 |
|
| 1741 |
# Now test with patron who has debug permission |
| 1742 |
C4::Context->set_userenv( |
| 1743 |
$patron_with_debug->borrowernumber, |
| 1744 |
$patron_with_debug->userid, |
| 1745 |
$patron_with_debug->cardnumber, |
| 1746 |
$patron_with_debug->firstname, |
| 1747 |
$patron_with_debug->surname, |
| 1748 |
$patron_with_debug->branchcode, |
| 1749 |
$patron_with_debug->library->branchname, |
| 1750 |
$patron_with_debug->flags, |
| 1751 |
$patron_with_debug->email // '', |
| 1752 |
'' |
| 1753 |
); |
| 1754 |
|
| 1755 |
delete $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"}; |
| 1756 |
|
| 1757 |
# Test the logic: Should override for patron with permission |
| 1758 |
if ( C4::Context->userenv && haspermission( C4::Context->userenv->{'id'}, { debug => 1 } ) ) { |
| 1759 |
$ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} = q{} if $cgi->param("DISABLE_SYSPREF_IntranetUserCSS"); |
| 1760 |
} |
| 1761 |
|
| 1762 |
ok( |
| 1763 |
exists $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} && $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} eq '', |
| 1764 |
'IntranetUserCSS correctly overridden for patron with debug permission' |
| 1765 |
); |
| 1766 |
|
| 1767 |
# Test superlibrarian |
| 1768 |
C4::Context->set_userenv( |
| 1769 |
$superlibrarian->borrowernumber, |
| 1770 |
$superlibrarian->userid, |
| 1771 |
$superlibrarian->cardnumber, |
| 1772 |
$superlibrarian->firstname, |
| 1773 |
$superlibrarian->surname, |
| 1774 |
$superlibrarian->branchcode, |
| 1775 |
$superlibrarian->library->branchname, |
| 1776 |
$superlibrarian->flags, |
| 1777 |
$superlibrarian->email // '', |
| 1778 |
'' |
| 1779 |
); |
| 1780 |
|
| 1781 |
delete $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"}; |
| 1782 |
|
| 1783 |
# Test the logic: Should override for superlibrarian |
| 1784 |
if ( C4::Context->userenv && haspermission( C4::Context->userenv->{'id'}, { debug => 1 } ) ) { |
| 1785 |
$ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} = q{} if $cgi->param("DISABLE_SYSPREF_IntranetUserCSS"); |
| 1786 |
} |
| 1787 |
|
| 1788 |
ok( |
| 1789 |
exists $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} && $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"} eq '', |
| 1790 |
'IntranetUserCSS correctly overridden for superlibrarian' |
| 1791 |
); |
| 1792 |
|
| 1793 |
# Clean up |
| 1794 |
delete $ENV{"OVERRIDE_SYSPREF_IntranetUserCSS"}; |
| 1795 |
C4::Context->unset_userenv(); |
| 1796 |
|
| 1797 |
$schema->storage->txn_rollback; |
| 1798 |
}; |
| 1799 |
|
| 1667 |
sub set_weak_password { |
1800 |
sub set_weak_password { |
| 1668 |
my ($patron) = @_; |
1801 |
my ($patron) = @_; |
| 1669 |
my $password = 'password'; |
1802 |
my $password = 'password'; |
| 1670 |
- |
|
|