Permalink
Browse files

Fixed root_id => root_dn in POD docs

added t/04.bind.t

Bumped version to 0.0.11

Added configuration for port 20389, to allow non-root tests

added common::sense and IO::Pipe

t/03.param.t revamped

now it is a forking test, with an alarm signal

minor cosmetic change

some debug support + one more test

DIST VERSION 0.0.11

Bumped version to 0.0.12

changed paramter from "data" to "ldap_data"

fixed a test, added another one

refrained from passing custom opts in new(), passing on run()

multiple changes

- refrained from passing custom options to new(), passing them to run() instead
- fixed parameter for Net::LDAP
- added more verbose messages when LDAP fails
- added another test, to unbind from a server

cosmetic changes in t/03.params.t

added authenticated and authenticated-wrong-pw tests

added test for different case in bind dn

implemented bind functionality

- ProtocolHandler - implementing bind function
  - replaced strict/warnings with common::sense
  - added new fields root_dn and root_pw
  - implemented _get_ldap_constant() and _make_result() to, respectively,
    lookup a LDAP code (into Net::LDAP::Constant) and to make a proper
    LDAP response based on the code provided
  - changed new() to receive a hashref as 1st-param. It must contain keys
    store and root_dn.
  - tests whether root_dn is canonical_dn
  - bind() function
- changed SimpleServer to pass root_dn and root_pw down into
  ProtocolHandler
- changed t/02.handler.t to pass hashref rather than a single param
  into ProtocolHandler
- added more tests to t/02.handler.t for the new parameter combinations
- fixed t/04.bind.t to spawn the server using the designated password as
  the root_pw

removed the temporary files that were added by mistake

Updated documentation for ProtocolHandler
  • Loading branch information...
1 parent fee4d22 commit 2207c5ab77d924812f32e620374c395ccf11e8e6 @russoz committed Nov 8, 2010
Showing with 367 additions and 88 deletions.
  1. +2 −0 Build.PL
  2. +11 −0 Changes
  3. +1 −0 MANIFEST
  4. +5 −5 README
  5. +1 −1 dev/mkdist
  6. +3 −1 examples/single-entry.conf
  7. +54 −39 lib/Net/LDAP/SimpleServer.pm
  8. +1 −1 lib/Net/LDAP/SimpleServer/LDIFStore.pm
  9. +116 −20 lib/Net/LDAP/SimpleServer/ProtocolHandler.pm
  10. +18 −5 t/02.handler.t
  11. +57 −16 t/03.param.t
  12. +98 −0 t/04.bind.t
View
@@ -18,6 +18,8 @@ my $builder = Module::Build->new(
'File::HomeDir' => 0,
'File::Basename' => 0,
'Test::More' => 0,
+ 'IO::Pipe' => 0,
+ 'common::sense' => 0,
'version' => 0,
'Carp' => 0,
},
View
11 Changes
@@ -1,5 +1,16 @@
Revision history for Net-LDAP-SimpleServer
+0.0.11 [2010.11.14 11:43:03] Net::LDAP::SimpleServer DIST VERSION 0.0.11
+======= ======================================================================
+ab18ca8 some debug support + one more test
+801b930 minor cosmetic change
+9c5b6d3 t/03.param.t revamped
+dbded61 added common::sense and IO::Pipe
+de7f2c7 Added configuration for port 20389, to allow non-root tests
+b67da4d Bumped version to 0.0.11
+2ea4161 added t/04.bind.t
+17db48c Fixed root_id => root_dn in POD docs
+
0.0.10 [2010.11.08 19:33:29] Net::LDAP::SimpleServer DIST VERSION 0.0.10
======= ==============================================================================
ef0f769 if needed creates directory for log_file and pid_file
View
@@ -15,6 +15,7 @@ t/01.load.store.t
t/02.handler.t
t/02.store.t
t/03.param.t
+t/04.bind.t
t/perlcritic.t
t/pod-coverage.t
t/pod.t
View
10 README
@@ -22,7 +22,7 @@ SYNOPSIS
# passing configurations in a hash
my $server = Net::LDAP::SimpleServer->new({
port => 5000,
- data => '/path/to/data.ldif',
+ ldap_data => '/path/to/data.ldif',
});
# make it spin
@@ -61,7 +61,7 @@ METHODS
As specified in Net::Server, this method creates new options for
the, server, namely:
- data - the LDIF data file used by LDIFStore
+ ldap_data - the LDIF data file used by LDIFStore
root_dn - the administrator DN of the repository
@@ -77,7 +77,7 @@ METHODS
host => '*',
port => 389,
proto => 'tcp',
- root_id => 'cn=root',
+ root_dn => 'cn=root',
root_pw => 'ldappw',
syslog_ident => 'Net::LDAP::SimpleServer-'
. $Net::LDAP::SimpleServer::VERSION,
@@ -112,9 +112,9 @@ CONFIGURATION AND ENVIRONMENT
hash, this module will look for a default configuration file named
"${HOME}/.ldapsimpleserver/config".
- data /path/to/a/ldif/file.ldif
+ ldap_data /path/to/a/ldif/file.ldif
#port 389
- #root_id cn=root
+ #root_dn cn=root
#root_pw somepassword
#objectclass_req (true|false)
#user_tree dc=some,dc=subtree,dc=com
View
@@ -76,7 +76,7 @@ msg "== Generating <Changes> automagically"
echo ""
printf '%-7s [%s] %s\n' "${version}" "$(date '+%Y.%m.%d %H:%M:%S')" \
"${modulename} DIST VERSION ${version}"
- perl -e 'print "="x7 . " " . "="x78 . "\n"'
+ perl -e 'print "="x7 . " " . "="x70 . "\n"'
git log --oneline | perl -nle 'exit if /DIST VERSION/; print "$_";' &&
echo "" &&
cat Changes | perl -e '$a=<>; $a=<>; while(<>) { print }'
@@ -1,4 +1,5 @@
-data examples/single-entry.ldif
+
+ldap_data examples/single-entry.ldif
### user and group to become
#user somebody
@@ -33,6 +34,7 @@ data examples/single-entry.ldif
#host 127.0.0.1
#port localhost:20204
#port 20205
+port 20389
### reverse lookups ?
# reverse_lookups on
@@ -1,19 +1,24 @@
package Net::LDAP::SimpleServer;
-use strict;
-use warnings;
use Carp;
+use common::sense;
-use version; our $VERSION = qv('0.0.10');
+use version; our $VERSION = qv('0.0.12');
our $personality = undef;
sub import {
my $pkg = shift;
$personality = shift || 'Fork';
use Net::Server;
- eval 'use base qw/Net::Server::' . $personality . '/';
- die $@ if $@;
+ eval "use base qw{Net::Server::$personality}";
+ croak $@ if $@;
+
+ @Net::LDAP::SimpleServer::ISA = qw(Net::Server);
+
+ #use Data::Dumper;
+ #print STDERR Data::Dumper->Dump( [ \@Net::LDAP::SimpleServer::ISA ],
+ # ['ISA'] );
}
use File::Basename;
@@ -30,39 +35,42 @@ use constant DEFAULT_CONFIG_FILE => File::Spec->catfile( BASEDIR, 'config' );
use constant DEFAULT_DATA_FILE => File::Spec->catfile( BASEDIR, 'server.ldif' );
my $_add_option = sub {
- my ( $prop, $template, $opt, $initial ) = @_;
+ my ( $template, $prop, $opt, $initial ) = @_;
$prop->{$opt} = $initial;
$template->{$opt} = \$prop->{$opt};
};
sub options {
my ( $self, $template ) = @_;
- my $prop = $self->{'ldap'};
-
### setup options in the parent classes
$self->SUPER::options($template);
### add a single value option
- $_add_option->( $prop, $template, 'data', undef );
- $_add_option->( $prop, $template, 'root_dn', undef );
- $_add_option->( $prop, $template, 'root_pw', undef );
+ my $prop = $self->{server};
+ $_add_option->( $template, $prop, 'ldap_data', undef );
+ $_add_option->( $template, $prop, 'root_dn', undef );
+ $_add_option->( $template, $prop, 'root_pw', undef );
+
+ #use Data::Dumper;
+ #print STDERR Data::Dumper->Dump( [$self], ['options_END'] );
}
sub default_values {
- return {
- host => '*',
- port => 389,
- proto => 'tcp',
- root_dn => 'cn=root',
- root_pw => 'ldappw',
- log_file => File::Spec->catfile( LOGDIR, 'server.log' ),
- pid_file => File::Spec->catfile( LOGDIR, 'server.pid' ),
- conf_file => -r DEFAULT_CONFIG_FILE ? DEFAULT_CONFIG_FILE : undef,
- data => -r DEFAULT_DATA_FILE ? DEFAULT_DATA_FILE : undef,
- syslog_ident => 'Net::LDAP::SimpleServer-'
- . $Net::LDAP::SimpleServer::VERSION,
- };
+ my $self = @_;
+
+ my $v = {};
+ $v->{port} = 389;
+ $v->{root_dn} = 'cn=root';
+ $v->{root_pw} = 'ldappw';
+ $v->{log_file} = File::Spec->catfile( LOGDIR, 'server.log' );
+
+ #$v->{pid_file} = File::Spec->catfile( LOGDIR, 'server.pid' );
+ $v->{conf_file} = DEFAULT_CONFIG_FILE if -r DEFAULT_CONFIG_FILE;
+ $v->{ldap_data} = DEFAULT_DATA_FILE if -r DEFAULT_DATA_FILE;
+ $v->{syslog_ident} =
+ 'Net::LDAP::SimpleServer-' . $Net::LDAP::SimpleServer::VERSION;
+ return $v;
}
sub _make_dir {
@@ -78,26 +86,33 @@ sub _make_dir {
sub post_configure_hook {
my $self = shift;
- my $prop = $self->{'ldap'};
+ my $prop = $self->{server};
+ #use Data::Dumper;
+ #print STDERR '# ' . Data::Dumper->Dump( [$self], ['post_configure_hook'] );
croak q{Cannot find conf file "} . $self->{server}->{conf_file} . q{"}
if $self->{server}->{conf_file} and not -r $self->{server}->{conf_file};
_make_dir( $self->{server}->{log_file} );
_make_dir( $self->{server}->{pid_file} );
- croak q{Configuration has no "data" file!}
- unless exists $prop->{data};
- croak qq{Cannot read data file "} . $prop->{data} . q{"}
- unless -r $prop->{data};
-
- $prop->{store} = LDIFStore->new( $prop->{data} );
+ croak q{Configuration has no "ldap_data" file!}
+ unless exists $prop->{ldap_data};
+ croak qq{Cannot read ldap_data file "} . $prop->{ldap_data} . q{"}
+ unless -r $prop->{ldap_data};
+
+ $prop->{store} =
+ Net::LDAP::SimpleServer::LDIFStore->new( $prop->{ldap_data} )
+ || croak q{Cannot create data store!};
}
sub process_request {
my $self = shift;
- my $in = *STDIN{IO};
- my $out = *STDOUT{IO};
- my $handler = ProtocolHandler->new( $self->{ldap}->{store}, $in, $out );
+ my $in = *STDIN{IO};
+ my $out = *STDOUT{IO};
+ my $params =
+ { map { ( $_ => $self->{server}->{$_} ) } qw/store root_dn root_pw/ };
+ my $handler =
+ Net::LDAP::SimpleServer::ProtocolHandler->new( $params, $in, $out );
until ( $handler->handle ) {
@@ -135,7 +150,7 @@ B<< WORK IN PROGRESS!! NOT READY TO USE YET!! >>
# passing configurations in a hash
my $server = Net::LDAP::SimpleServer->new({
port => 5000,
- data => '/path/to/data.ldif',
+ ldap_data => '/path/to/data.ldif',
});
# make it spin
@@ -193,7 +208,7 @@ server, namely:
=over
-data - the LDIF data file used by LDIFStore
+ldap_data - the LDIF data file used by LDIFStore
root_dn - the administrator DN of the repository
@@ -211,7 +226,7 @@ number of options. In Net::LDAP::SimpleServer, this method is defined as:
host => '*',
port => 389,
proto => 'tcp',
- root_id => 'cn=root',
+ root_dn => 'cn=root',
root_pw => 'ldappw',
syslog_ident => 'Net::LDAP::SimpleServer-'
. $Net::LDAP::SimpleServer::VERSION,
@@ -272,9 +287,9 @@ server settings. If no file is specified and options are not passed
in a hash, this module will look for a default configuration file named
C<< ${HOME}/.ldapsimpleserver/config >>.
- data /path/to/a/ldif/file.ldif
+ ldap_data /path/to/a/ldif/file.ldif
#port 389
- #root_id cn=root
+ #root_dn cn=root
#root_pw somepassword
#objectclass_req (true|false)
#user_tree dc=some,dc=subtree,dc=com
@@ -9,7 +9,7 @@ use UNIVERSAL::isa;
use Scalar::Util qw(blessed reftype);
use Net::LDAP::LDIF;
-use version; our $VERSION = qv('0.0.10');
+use version; our $VERSION = qv('0.0.12');
sub new {
my ( $class, $param ) = @_;
Oops, something went wrong.

0 comments on commit 2207c5a

Please sign in to comment.