1## 2## ADD NODE VALIDATION 3## 4## Here we can test the add-node function 5## 6## We need running LDAP server for that 7## 8 9use strict; 10use warnings; 11use utf8; 12use Test::More; 13use File::Spec; 14 15#--- check permission to run test 16my $test_directory = File::Spec->catfile( 't', '18_ldap'); 17my $semaphore_file = File::Spec->catfile( 18 $test_directory, 19 'enable_talk_to_server', 20 ); 21if( !( -f $semaphore_file) ) { 22 plan skip_all => "No ldap server for testing"; 23}; 24 25use_ok( 'OpenXPKI::LdapUtils' ); 26 27#---------------------- C O N F I G U R A T I O N ------------------------- 28my $realm={}; 29my $ldap=undef; 30$realm->{ldap_enable} = "yes"; 31$realm->{ldap_excluded_roles} = 'RA Operator'; 32$realm->{ldap_suffix}=['dc=openxpki,dc=org','dc=openxpki,c=RU']; 33$realm->{ldap_server} = 'localhost'; 34$realm->{ldap_port} = '60389'; 35$realm->{ldap_version} = '3'; 36$realm->{ldap_tls} = 'no'; 37#$realm->{ldap_client_cert} = '/usr/local/etc/openldap/certs/saslcert.pem'; 38#$realm->{ldap_client_key} = '/usr/local/etc/openldap/keys/saslkey.pem'; 39#$realm->{ldap_ca_cert} = '/usr/local/etc/openldap/certs/cacert.pem'; 40$realm->{ldap_sasl} = 'no'; 41#$realm->{ldap_sasl_mech} ='EXTERNAL'; 42$realm->{ldap_login} = 'cn=Manager,dc=openxpki,dc=org'; 43$realm->{ldap_password} = 'secret'; 44 45 46 my $new_nodes = { 47 'ou=x1,dc=openxpki,dc=org' => [ 48 'ou' => 'x1', 49 'objectclass' => [ 50 'organizationalUnit', 51 ], 52 ], 53 'o=x3,dc=openxpki,dc=org' => [ 54 'o' => 'x3', 55 'objectclass' => [ 56 'organization', 57 ], 58 ], 59 'ou=x2,dc=openxpki,dc=org' => [ 60 'ou' => 'x2', 61 'objectclass' => [ 62 'organizationalUnit', 63 ], 64 ], 65 'cn=John+sn=Smith,dc=openxpki,dc=org' => [ 66 'cn' => 'John', 67 'sn' => 'Smith', 68 'objectclass' => [ 69 'person', 70 ], 71 ], 72 }; 73 74# bad entries description 75# 76# 1) already exists in new nodes 77# 2) already exists in new nodes 78# 3) dn does not match attributes 79# 4) schema violation 80 81 my $bad_nodes = { 82 'ou=x1,dc=openxpki,dc=org' => [ 83 'ou' => 'x1', 84 'objectclass' => [ 85 'organizationalUnit', 86 ], 87 ], 88 'o=x3,dc=openxpki,dc=org' => [ 89 'o' => 'x3', 90 'objectclass' => [ 91 'organization', 92 ], 93 ], 94 'ou=x2,dc=openxpki,dc=org' => [ 95 'ou' => 'x1', 96 'objectclass' => [ 97 'organizationalUnit', 98 ], 99 ], 100 'cn=x3,dc=openxpki,dc=org' => [ 101 'cn' => 'x3', 102 'objectclass' => [ 103 'organization', 104 ], 105 ], 106 }; 107 108 109my $test_number = (scalar (keys %{$new_nodes} )) + 110 (scalar (keys %{$bad_nodes} )) 111; 112 113if($ENV{DEBUG}){ 114diag( "NUMBER OF TESTS >" . $test_number . "<\n"); 115}; 116 117plan tests => $test_number; 118 119diag "ADD LDAP NODE VALIDATION\n" if $ENV{VERBOSE}; 120 121#------------------- Call utils ----------------------------------------- 122 123 my $utils = OpenXPKI::LdapUtils->new(); 124 $ldap = $utils->ldap_connect($realm); 125 126#-------------------- must add ------------------------------------------ Go 127 128 129 foreach my $node ( keys %{$new_nodes} ){ 130 if($ENV{DEBUG}){ 131 diag( "ADDING A GOOD NODE -> $node \n"); 132 }; 133 ok( $utils->add_node( $ldap, $node, $new_nodes->{$node} ), 134 "adding a node ". $node, 135 ); 136 }; 137 138 139 140#-------------------- must fail ----------------------------------------- Go 141 142 foreach my $node ( keys %{$bad_nodes} ){ 143 if($ENV{DEBUG}){ 144 diag( "ADDING A BAD NODE -> $node \n"); 145 }; 146 ok( 1 - $utils->add_node( $ldap, $node, $bad_nodes->{$node} ), 147 "trying to add a bad node ". $node, 148 ); 149 }; 150 151######################################################################### 152# clean up ldap tree 153# FIXME - the order of erasing must be reversed 154# 155 foreach my $node ( keys %{$new_nodes} ){ $ldap->delete($node)}; 156 foreach my $node ( keys %{$bad_nodes} ){ $ldap->delete($node)}; 157 158 $utils->ldap_disconnect($ldap); 159 1601; 161