File: LDAPNestedGroups.t

package info (click to toggle)
znuny 6.5.18-1
  • links: PTS
  • area: non-free
  • in suites: forky, sid
  • size: 205,344 kB
  • sloc: perl: 1,038,694; xml: 74,551; javascript: 65,276; sql: 23,574; sh: 417; makefile: 63
file content (202 lines) | stat: -rw-r--r-- 6,407 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
# --
# Copyright (C) 2021 Znuny GmbH, https://znuny.org/
# --
# This software comes with ABSOLUTELY NO WARRANTY. For details, see
# the enclosed file COPYING for license information (AGPL). If you
# did not receive this file, see http://www.gnu.org/licenses/agpl.txt.
# --

use strict;
use warnings;
use utf8;

use vars (qw($Self));

$Kernel::OM->ObjectParamAdd(
    'Kernel::System::UnitTest::Helper' => {
        RestoreDatabase => 1,
    },
);

my $HelperObject = $Kernel::OM->Get('Kernel::System::UnitTest::Helper');
my $ConfigObject = $Kernel::OM->Get('Kernel::Config');
my $UserObject   = $Kernel::OM->Get('Kernel::System::User');
my $GroupObject  = $Kernel::OM->Get('Kernel::System::Group');

#
# TODO
# Tests are deactivated for now  because of problems in CI environment.
#

# #
# # Prepare groups
# #
# GROUP:
# for my $Group (qw( 1st 2nd )) {
#     my $GroupID = $GroupObject->GroupLookup( Group => $Group );
#     next GROUP if $GroupID;

#     $GroupObject->GroupAdd(
#         Name    => $Group,
#         ValidID => 1,
#         UserID  => 1,
#     );
# }

# #
# # LDAP for nested groups testing
# #

# # Note that host and credentials have to be configured in environment variables.
# $ConfigObject->{'AuthModule2'}                      = 'Kernel::System::Auth::LDAP';
# $ConfigObject->{'AuthModule::LDAP::Host2'}          = $ENV{OPENLDAP_HOST};
# $ConfigObject->{'AuthModule::LDAP::BaseDN2'}        = 'dc=planetexpress,dc=com';
# $ConfigObject->{'AuthModule::LDAP::UID2'}           = 'uid';
# $ConfigObject->{'AuthModule::LDAP::SearchUserDN2'}  = $ENV{OPENLDAP_USERDN};
# $ConfigObject->{'AuthModule::LDAP::SearchUserPw2'}  = $ENV{OPENLDAP_USERPASSWORD};
# $ConfigObject->{'AuthModule::LDAP::UserLowerCase2'} = 1;
# $ConfigObject->{'AuthModule::LDAP::Params2'}        = {
#     timeout => 4,
# };

# $ConfigObject->{'AuthSyncModule2'}                     = 'Kernel::System::Auth::Sync::LDAP';
# $ConfigObject->{'AuthSyncModule::LDAP::Host2'}         = $ENV{OPENLDAP_HOST};
# $ConfigObject->{'AuthSyncModule::LDAP::BaseDN2'}       = 'dc=planetexpress,dc=com';
# $ConfigObject->{'AuthSyncModule::LDAP::SearchUserDN2'} = $ENV{OPENLDAP_USERDN};
# $ConfigObject->{'AuthSyncModule::LDAP::SearchUserPw2'} = $ENV{OPENLDAP_USERPASSWORD};
# $ConfigObject->{'AuthSyncModule::LDAP::UID2'}          = 'uid';
# $ConfigObject->{'AuthSyncModule::LDAP::AccessAttr2'}   = 'member';
# $ConfigObject->{'AuthSyncModule::LDAP::UserAttr2'}     = 'DN';
# $ConfigObject->{'AuthSyncModule::LDAP::Params2'}       = {
#     timeout => 4,
# };

# $ConfigObject->{'AuthSyncModule::LDAP::UserSyncMap2'} = {

#     # DB -> LDAP
#     UserFirstname => 'givenName',
#     UserLastname  => 'sn',
#     UserEmail     => 'mail',
# };

# $ConfigObject->{'AuthSyncModule::LDAP::UserSyncGroupsDefinition2'} = {
#     'cn=1st Level,ou=people,dc=planetexpress,dc=com' => {
#         '1st' => { 'rw' => 1 },
#     },
#     'cn=2nd Level,ou=people,dc=planetexpress,dc=com' => {
#         '2nd' => { 'rw' => 1 },
#     },
#     'cn=fallback,ou=people,dc=planetexpress,dc=com' => {
#         'users' => { 'rw' => 1 },
#     },
# };

# # Login uid = password
# # amy, zoidberg, hermes, fry

# # Auth object must be initialized after changes to config above.
# my $AuthObject = $Kernel::OM->Get('Kernel::System::Auth');

# my @Tests = (
#     {
#         NestedGroupSearchActive => 0,
#         User                    => 'amy',
#         ExpectedUser            => 'Amy',
#         ExpectedUserData        => {
#             UserLastname  => 'Kroker',
#             UserEmail     => 'amy@planetexpress.com',
#             UserFirstname => 'Amy',
#         },
#         ExpectedGroups => [ 'users', ],
#     },
#     {
#         NestedGroupSearchActive => 1,
#         User                    => 'amy',
#         ExpectedUser            => 'Amy',
#         ExpectedUserData        => {
#             UserLastname  => 'Kroker',
#             UserEmail     => 'amy@planetexpress.com',
#             UserFirstname => 'Amy',
#         },
#         ExpectedGroups => [ '1st', 'users', ],
#     },
#     {
#         NestedGroupSearchActive => 0,
#         User                    => 'fry',
#         ExpectedUser            => 'fry',
#         ExpectedUserData        => {
#             UserLastname  => 'Fry',
#             UserEmail     => 'fry@planetexpress.com',
#             UserFirstname => 'Philip',
#         },
#         ExpectedGroups => [ 'users', ],
#     },
#     {
#         NestedGroupSearchActive => 1,
#         User                    => 'fry',
#         ExpectedUser            => 'fry',
#         ExpectedUserData        => {
#             UserLastname  => 'Fry',
#             UserEmail     => 'fry@planetexpress.com',
#             UserFirstname => 'Philip',
#         },
#         ExpectedGroups => [ '1st', '2nd', 'users', ],
#     },
# );

# for my $Test (@Tests) {
#     $ConfigObject->{'AuthSyncModule::LDAP::NestedGroupSearch2'} = $Test->{NestedGroupSearchActive};

#     # Re-initialize auth object because it stored the config in itself.
#     $Kernel::OM->ObjectsDiscard(
#         Objects => [ 'Kernel::System::Auth::Sync::LDAP', 'Kernel::System::Auth', ],
#     );
#     $AuthObject = $Kernel::OM->Get('Kernel::System::Auth');

#     my $TestUser = $Test->{User};

#     my $User = $AuthObject->Auth(
#         User => $TestUser,
#         Pw   => $TestUser,
#     );

#     $Self->Is(
#         scalar $User,
#         $Test->{ExpectedUser},
#         "User '$TestUser' must have successfully been authenticated via LDAP.",
#     );

#     my %User = $UserObject->GetUserData(
#         User => $User,
#     );

#     $Self->True(
#         scalar %User,
#         "User '$TestUser' must have been created/updated locally."
#     );

#     for my $UserDataField ( sort keys %{ $Test->{ExpectedUserData} } ) {
#         my $ExpectedValue = $Test->{ExpectedUserData}->{$UserDataField};

#         $Self->Is(
#             scalar $User{$UserDataField},
#             scalar $ExpectedValue,
#             "Field '$UserDataField' must contain expected value.",
#         );
#     }

#     my %Groups = $GroupObject->PermissionUserGroupGet(
#         UserID => $User{UserID},
#         Type   => 'rw',
#     );
#     my @Groups = sort values %Groups;

#     $Self->IsDeeply(
#         \@Groups,
#         $Test->{ExpectedGroups},
#         "User '$User' must be assigned to the expected groups.",
#     );

# }

1;