Skip to content

Commit 37af5c9

Browse files
committed
Let Net::LDAP::Server::Test make the socket for us
This restores the behaviour before 8a52894 to let Net::LDAP::Server::Test make the socket. The differnt behaviour I was seeing was due to have a non-standard sysctl setting. I have left this commit in the history incase it is useful in the future.
1 parent ba441bb commit 37af5c9

File tree

1 file changed

+10
-20
lines changed

1 file changed

+10
-20
lines changed

lib/RT/Test/LDAP.pm

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# COPYRIGHT:
44
#
5-
# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
5+
# This software is Copyright (c) 1996-2025 Best Practical Solutions, LLC
66
# <sales@bestpractical.com>
77
#
88
# (Except where explicitly superseded by other copyright notices)
@@ -46,13 +46,12 @@
4646
#
4747
# END BPS TAGGED BLOCK }}}
4848

49-
# Portions Copyright 2023 Andrew Ruthven <andrew@etc.gen.nz>
49+
# Portions Copyright 2023-2025 Andrew Ruthven <andrew@etc.gen.nz>
5050

5151
package RT::Test::LDAP;
5252

5353
use strict;
5454
use warnings;
55-
use IO::Socket::INET;
5655

5756
use base 'RT::Test';
5857

@@ -61,7 +60,6 @@ sub new {
6160
my %options = @_;
6261
my $class = ref($proto) ? ref($proto) : $proto;
6362
my $self = bless {
64-
ldap_ip => '127.0.0.1',
6563
base_dn => $options{base_dn} || 'dc=bestpractical,dc=com',
6664
}, $class;
6765

@@ -114,22 +112,14 @@ sub import {
114112
sub new_server {
115113
my $self = shift;
116114

117-
$self->{'ldap_port'} = RT::Test->find_idle_port;
118-
my $ldap_socket = IO::Socket::INET->new(
119-
Listen => 5,
120-
Proto => 'tcp',
121-
Reuse => 1,
122-
LocalAddr => $self->{'ldap_ip'},
123-
LocalPort => $self->{'ldap_port'},
124-
)
125-
|| die "Failed to create socket: $IO::Socket::errstr";
115+
$self->{'ldap_port'} = RT::Test->find_idle_port;
126116

127-
$self->{'ldap_server'}
128-
= Net::LDAP::Server::Test->new( $ldap_socket, auto_schema => 1 )
129-
|| die "Failed to spawn test LDAP server on port " . $self->{'ldap_port'};
117+
$self->{'ldap_server'} = Net::LDAP::Server::Test->new(
118+
$self->{'ldap_port'}, auto_schema => 1
119+
) || die "Failed to spawn test LDAP server on port " . $self->{'ldap_port'};
130120

131121
my $ldap_client
132-
= Net::LDAP->new(join(':', $self->{'ldap_ip'}, $self->{'ldap_port'}))
122+
= Net::LDAP->new('localhost:' . $self->{'ldap_port'})
133123
|| die "Failed to connect to LDAP server: $@";
134124

135125
$ldap_client->bind();
@@ -139,7 +129,7 @@ sub new_server {
139129
}
140130

141131
sub config_set_externalauth {
142-
my $self = shift;
132+
my $self = shift;
143133
my $settings = shift;
144134

145135
$settings->{'ExternalAuthPriority'} //= ['My_LDAP'];
@@ -152,7 +142,7 @@ sub config_set_externalauth {
152142
}
153143

154144
$self->{'externalauth'}{'My_LDAP'}{'server'} //=
155-
join(':', $self->{'ldap_ip'}, $self->{'ldap_port'});
145+
'localhost:' . $self->{'ldap_port'};
156146

157147
RT->Config->Set(ExternalSettings => $self->{'externalauth'});
158148
RT->Config->PostLoadCheck;
@@ -163,7 +153,7 @@ sub config_set_ldapimport {
163153
my $settings = shift;
164154

165155
$settings->{'LDAPHost'}
166-
//= 'ldap://' . $self->{'ldap_ip'} . ':' . $self->{'ldap_port'};
156+
//= 'ldap://localhost:' . $self->{'ldap_port'};
167157
$settings->{'LDAPMapping'} //= {
168158
Name => 'uid',
169159
EmailAddress => 'mail',

0 commit comments

Comments
 (0)