View | Details | Raw Unified | Return to bug 40596
Collapse All | Expand All

(-)a/Koha/Auth/Identity/Provider/CAS.pm (+70 lines)
Line 0 Link Here
1
package Koha::Auth::Identity::Provider::CAS;
2
3
# Copyright 2025 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Auth::Identity::Provider);
23
24
=head1 NAME
25
26
Koha::Auth::Identity::Provider::CAS - CAS identity provider
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 new
33
34
Constructor. Inherits from L<Koha::Auth::Identity::Provider>.
35
36
=cut
37
38
=head2 Instance methods
39
40
=head3 mandatory_config_attributes
41
42
    my @attributes = $provider->mandatory_config_attributes
43
44
Returns the list of mandatory configuration attributes for CAS providers.
45
46
=cut
47
48
sub mandatory_config_attributes {
49
    return qw(
50
        cas_url
51
    );
52
}
53
54
=head2 Internal methods
55
56
=head3 _type
57
58
=cut
59
60
sub _type {
61
    return 'IdentityProvider';
62
}
63
64
=head1 AUTHOR
65
66
Koha Development Team
67
68
=cut
69
70
1;
(-)a/Koha/Auth/Identity/Provider/Shibboleth.pm (+72 lines)
Line 0 Link Here
1
package Koha::Auth::Identity::Provider::Shibboleth;
2
3
# Copyright 2025 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use base qw(Koha::Auth::Identity::Provider);
23
24
=head1 NAME
25
26
Koha::Auth::Identity::Provider::Shibboleth - Shibboleth identity provider
27
28
=head1 API
29
30
=head2 Class methods
31
32
=head3 new
33
34
Constructor. Inherits from L<Koha::Auth::Identity::Provider>.
35
36
=cut
37
38
=head2 Instance methods
39
40
=head3 mandatory_config_attributes
41
42
    my @attributes = $provider->mandatory_config_attributes
43
44
Returns the list of mandatory configuration attributes for Shibboleth providers.
45
46
=cut
47
48
sub mandatory_config_attributes {
49
    return qw(
50
        sso_url
51
        slo_url
52
        entity_id
53
    );
54
}
55
56
=head2 Internal methods
57
58
=head3 _type
59
60
=cut
61
62
sub _type {
63
    return 'IdentityProvider';
64
}
65
66
=head1 AUTHOR
67
68
Koha Development Team
69
70
=cut
71
72
1;
(-)a/t/db_dependent/Koha/Auth/Identity/Provider/CAS.t (+112 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
3
# Copyright 2025 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 5;
23
use Test::Exception;
24
use Test::NoWarnings;
25
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
29
use Koha::Database;
30
use Koha::Auth::Identity::Providers;
31
32
BEGIN {
33
    use_ok('Koha::Auth::Identity::Provider::CAS');
34
}
35
36
my $schema  = Koha::Database->schema;
37
my $builder = t::lib::TestBuilder->new;
38
39
subtest 'CAS provider instantiation' => sub {
40
    plan tests => 3;
41
42
    $schema->storage->txn_begin;
43
44
    # Test direct instantiation
45
    my $provider_data = {
46
        code        => 'cas_test',
47
        description => 'Test CAS Provider',
48
        protocol    => 'CAS',
49
        config      => '{"cas_url": "https://cas.example.com/cas"}',
50
        mapping     => '{"userid": "user", "email": "mail"}',
51
        matchpoint  => 'userid'
52
    };
53
54
    my $provider = Koha::Auth::Identity::Provider::CAS->new($provider_data);
55
    isa_ok( $provider, 'Koha::Auth::Identity::Provider::CAS' );
56
    isa_ok( $provider, 'Koha::Auth::Identity::Provider' );
57
    is( $provider->protocol, 'CAS', 'Protocol is set correctly' );
58
59
    $schema->storage->txn_rollback;
60
};
61
62
subtest 'mandatory_config_attributes() tests' => sub {
63
    plan tests => 2;
64
65
    $schema->storage->txn_begin;
66
67
    my $provider  = Koha::Auth::Identity::Provider::CAS->new();
68
    my @mandatory = $provider->mandatory_config_attributes();
69
70
    is( scalar @mandatory, 1,         'Returns correct number of mandatory attributes' );
71
    is( $mandatory[0],     'cas_url', 'Returns cas_url as mandatory attribute' );
72
73
    $schema->storage->txn_rollback;
74
};
75
76
subtest 'Configuration validation' => sub {
77
    plan tests => 4;
78
79
    $schema->storage->txn_begin;
80
81
    my $provider = $builder->build_object(
82
        {
83
            class => 'Koha::Auth::Identity::Providers',
84
            value => {
85
                protocol => 'CAS',
86
                config   => '{}',
87
                mapping  => '{}',
88
            }
89
        }
90
    );
91
92
    # Upgrade to CAS provider
93
    my $cas_provider = $provider->upgrade_class();
94
    isa_ok( $cas_provider, 'Koha::Auth::Identity::Provider::CAS' );
95
96
    # Test valid configuration
97
    my $valid_config = { cas_url => 'https://cas.example.com/cas' };
98
99
    lives_ok { $cas_provider->set_config($valid_config) } 'Valid config is accepted';
100
101
    # Test invalid configuration (missing cas_url)
102
    my $invalid_config = { some_other_param => 'value' };
103
104
    throws_ok {
105
        $cas_provider->set_config($invalid_config)
106
    }
107
    'Koha::Exceptions::MissingParameter', 'Missing cas_url throws exception';
108
109
    is( $@->parameter, 'cas_url', 'Exception indicates missing cas_url parameter' );
110
111
    $schema->storage->txn_rollback;
112
};
(-)a/t/db_dependent/Koha/Auth/Identity/Provider/Shibboleth.t (-1 / +153 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2025 Koha Development team
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 5;
23
use Test::Exception;
24
use Test::NoWarnings;
25
26
use t::lib::TestBuilder;
27
use t::lib::Mocks;
28
29
use Koha::Database;
30
use Koha::Auth::Identity::Providers;
31
32
BEGIN {
33
    use_ok('Koha::Auth::Identity::Provider::Shibboleth');
34
}
35
36
my $schema  = Koha::Database->schema;
37
my $builder = t::lib::TestBuilder->new;
38
39
subtest 'Shibboleth provider instantiation' => sub {
40
    plan tests => 3;
41
42
    $schema->storage->txn_begin;
43
44
    # Test direct instantiation
45
    my $provider_data = {
46
        code        => 'shibboleth_test',
47
        description => 'Test Shibboleth Provider',
48
        protocol    => 'Shibboleth',
49
        config      =>
50
            '{"sso_url": "https://idp.example.com/sso", "slo_url": "https://idp.example.com/slo", "entity_id": "https://idp.example.com"}',
51
        mapping    => '{"userid": "REMOTE_USER", "email": "mail"}',
52
        matchpoint => 'userid'
53
    };
54
55
    my $provider = Koha::Auth::Identity::Provider::Shibboleth->new($provider_data);
56
    isa_ok( $provider, 'Koha::Auth::Identity::Provider::Shibboleth' );
57
    isa_ok( $provider, 'Koha::Auth::Identity::Provider' );
58
    is( $provider->protocol, 'Shibboleth', 'Protocol is set correctly' );
59
60
    $schema->storage->txn_rollback;
61
};
62
63
subtest 'mandatory_config_attributes() tests' => sub {
64
    plan tests => 5;
65
66
    $schema->storage->txn_begin;
67
68
    my $provider  = Koha::Auth::Identity::Provider::Shibboleth->new();
69
    my @mandatory = $provider->mandatory_config_attributes();
70
71
    is( scalar @mandatory, 3, 'Returns correct number of mandatory attributes' );
72
73
    my %mandatory_hash = map { $_ => 1 } @mandatory;
74
    ok( exists $mandatory_hash{'sso_url'},   'sso_url is mandatory' );
75
    ok( exists $mandatory_hash{'slo_url'},   'slo_url is mandatory' );
76
    ok( exists $mandatory_hash{'entity_id'}, 'entity_id is mandatory' );
77
78
    # Verify order (should be consistent)
79
    is_deeply( \@mandatory, [qw(sso_url slo_url entity_id)], 'Mandatory attributes in expected order' );
80
81
    $schema->storage->txn_rollback;
82
};
83
84
subtest 'Configuration validation' => sub {
85
    plan tests => 8;
86
87
    $schema->storage->txn_begin;
88
89
    my $provider = $builder->build_object(
90
        {
91
            class => 'Koha::Auth::Identity::Providers',
92
            value => {
93
                protocol => 'Shibboleth',
94
                config   => '{}',
95
                mapping  => '{}',
96
            }
97
        }
98
    );
99
100
    # Upgrade to Shibboleth provider
101
    my $shibboleth_provider = $provider->upgrade_class();
102
    isa_ok( $shibboleth_provider, 'Koha::Auth::Identity::Provider::Shibboleth' );
103
104
    # Test valid configuration
105
    my $valid_config = {
106
        sso_url   => 'https://idp.example.com/sso',
107
        slo_url   => 'https://idp.example.com/slo',
108
        entity_id => 'https://idp.example.com'
109
    };
110
111
    lives_ok { $shibboleth_provider->set_config($valid_config) } 'Valid config is accepted';
112
113
    # Test invalid configuration (missing sso_url)
114
    my $invalid_config1 = {
115
        slo_url   => 'https://idp.example.com/slo',
116
        entity_id => 'https://idp.example.com'
117
    };
118
119
    throws_ok {
120
        $shibboleth_provider->set_config($invalid_config1)
121
    }
122
    'Koha::Exceptions::MissingParameter', 'Missing sso_url throws exception';
123
124
    is( $@->parameter, 'sso_url', 'Exception indicates missing sso_url parameter' );
125
126
    # Test invalid configuration (missing slo_url)
127
    my $invalid_config2 = {
128
        sso_url   => 'https://idp.example.com/sso',
129
        entity_id => 'https://idp.example.com'
130
    };
131
132
    throws_ok {
133
        $shibboleth_provider->set_config($invalid_config2)
134
    }
135
    'Koha::Exceptions::MissingParameter', 'Missing slo_url throws exception';
136
137
    is( $@->parameter, 'slo_url', 'Exception indicates missing slo_url parameter' );
138
139
    # Test invalid configuration (missing entity_id)
140
    my $invalid_config3 = {
141
        sso_url => 'https://idp.example.com/sso',
142
        slo_url => 'https://idp.example.com/slo'
143
    };
144
145
    throws_ok {
146
        $shibboleth_provider->set_config($invalid_config3)
147
    }
148
    'Koha::Exceptions::MissingParameter', 'Missing entity_id throws exception';
149
150
    is( $@->parameter, 'entity_id', 'Exception indicates missing entity_id parameter' );
151
152
    $schema->storage->txn_rollback;
153
};

Return to bug 40596