Commit 8ac1bb70 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

Test #933 ldap (#934)

* wip(install): clean old table and added n_order to access

issue #993

* wip(tests): cleaned old bases table

issue #993

* test(LDAP): moved LDAP tests initialization to test lib

issue #993

* wip(test): fixed missing test skip count

issue #993

* refactor(test): moved method to common test module

issue #993
parent c0756fbf
CREATE TABLE `bases` (
`id` integer NOT NULL PRIMARY KEY AUTOINCREMENT
, `name` varchar(80) NOT NULL
, `image` varchar(255) DEFAULT NULL
, UNIQUE (`name`)
);
...@@ -898,7 +898,7 @@ for my $vm_name ( 'KVM', 'Void' ) { ...@@ -898,7 +898,7 @@ for my $vm_name ( 'KVM', 'Void' ) {
if (!$ENV{TEST_STRESS} && !$ENV{"TEST_STRESS_$vm_name"}) { if (!$ENV{TEST_STRESS} && !$ENV{"TEST_STRESS_$vm_name"}) {
diag("Skipped $vm_name stress test. Set environment variable TEST_STRESS or" diag("Skipped $vm_name stress test. Set environment variable TEST_STRESS or"
." TEST_STRESS_$vm_name to run"); ." TEST_STRESS_$vm_name to run");
skip("Skipping stress $vm_name"); skip("Skipping stress $vm_name",1000);
} }
eval { eval {
$RVD_BACK= Ravada->new(); $RVD_BACK= Ravada->new();
......
sql: sql:
- ../../sql/sqlite/bases.sql
- ../../sql/sqlite/bases_vm.sql
- ../../sql/sqlite/iso_images.sql - ../../sql/sqlite/iso_images.sql
- ../../sql/sqlite/domains.sql - ../../sql/sqlite/domains.sql
- ../../sql/sqlite/requests.sql - ../../sql/sqlite/requests.sql
......
...@@ -12,10 +12,6 @@ use lib 't/lib'; ...@@ -12,10 +12,6 @@ use lib 't/lib';
use Test::Ravada; use Test::Ravada;
use Ravada::Auth::LDAP; use Ravada::Auth::LDAP;
my $CONFIG_FILE = 't/etc/ravada_ldap.conf';
init( $CONFIG_FILE );
delete $Ravada::CONFIG->{ldap}->{ravada_posix_group};
sub test_external_auth { sub test_external_auth {
my ($name, $password) = ('jimmy','jameson'); my ($name, $password) = ('jimmy','jameson');
...@@ -449,9 +445,9 @@ sub test_access_by_attribute_2bases($vm, $do_clones=0) { ...@@ -449,9 +445,9 @@ sub test_access_by_attribute_2bases($vm, $do_clones=0) {
################################################################################ ################################################################################
init();
clean(); clean();
for my $vm_name ('KVM', 'Void') { for my $vm_name ('KVM', 'Void') {
my $vm = rvd_back->search_vm($vm_name); my $vm = rvd_back->search_vm($vm_name);
...@@ -461,9 +457,22 @@ for my $vm_name ('KVM', 'Void') { ...@@ -461,9 +457,22 @@ for my $vm_name ('KVM', 'Void') {
if ($vm && $vm_name =~ /kvm/i && $>) { if ($vm && $vm_name =~ /kvm/i && $>) {
$msg = "SKIPPED: Test must run as root"; $msg = "SKIPPED: Test must run as root";
$vm = undef; $vm = undef;
} else {
my $fly_config = init_ldap_config();
init($fly_config);
}
my $ldap;
eval { $ldap = Ravada::Auth::LDAP::_init_ldap_admin() };
if ($@ =~ /Bad credentials/) {
diag("$@\nFix admin credentials in t/etc/ravada_ldap.conf");
} else {
diag("Skipped LDAP tests ".($@ or '')) if !$ldap;
} }
skip($msg,10) if !$vm; $msg = "SKIPPEd: No LDAP server found" if !$ldap && $@ !~ /Bad credentials/;
skip($msg,10) if !$vm || !$ldap;
diag("Testing LDAP access for $vm_name"); diag("Testing LDAP access for $vm_name");
test_external_auth(); test_external_auth();
......
...@@ -63,7 +63,7 @@ for my $vm_name ( 'KVM' ) { ...@@ -63,7 +63,7 @@ for my $vm_name ( 'KVM' ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg if !$vm; skip $msg,10 if !$vm;
diag("Testing shutdown on $vm_name"); diag("Testing shutdown on $vm_name");
......
...@@ -9,7 +9,7 @@ use YAML qw(DumpFile); ...@@ -9,7 +9,7 @@ use YAML qw(DumpFile);
use Hash::Util qw(lock_hash); use Hash::Util qw(lock_hash);
use IPC::Run3 qw(run3); use IPC::Run3 qw(run3);
use Test::More; use Test::More;
use YAML qw(LoadFile); use YAML qw(LoadFile DumpFile);
use feature qw(signatures); use feature qw(signatures);
no warnings "experimental::signatures"; no warnings "experimental::signatures";
...@@ -51,6 +51,7 @@ create_domain ...@@ -51,6 +51,7 @@ create_domain
create_ldap_user create_ldap_user
connector connector
create_ldap_user create_ldap_user
init_ldap_config
); );
our $DEFAULT_CONFIG = "t/etc/ravada.conf"; our $DEFAULT_CONFIG = "t/etc/ravada.conf";
...@@ -70,6 +71,11 @@ our $CHAIN = 'RAVADA'; ...@@ -70,6 +71,11 @@ our $CHAIN = 'RAVADA';
our $RVD_BACK; our $RVD_BACK;
our $RVD_FRONT; our $RVD_FRONT;
#LDAP default values
my $ADMIN_GROUP = "test.admin.group";
my $RAVADA_POSIX_GROUP = "rvd_posix_group";
my ($LDAP_USER , $LDAP_PASS) = ("cn=Directory Manager","saysomething");
our %ARG_CREATE_DOM = ( our %ARG_CREATE_DOM = (
KVM => [] KVM => []
,Void => [] ,Void => []
...@@ -1213,4 +1219,45 @@ sub DESTROY { ...@@ -1213,4 +1219,45 @@ sub DESTROY {
remove_old_user_ldap() if $CONNECTOR; remove_old_user_ldap() if $CONNECTOR;
} }
sub init_ldap_config($file_config='t/etc/ravada_ldap.conf'
, $with_admin=0
, $with_posix_group=0) {
if ( ! -e $file_config) {
my $config = {
ldap => {
admin_user => { dn => $LDAP_USER , password => $LDAP_PASS }
,base => "dc=example,dc=com"
,admin_group => $ADMIN_GROUP
,auth => 'match'
,ravada_posix_group => $RAVADA_POSIX_GROUP
}
};
DumpFile($file_config,$config);
}
my $config = LoadFile($file_config);
delete $config->{ldap}->{admin_group} if !$with_admin;
if ($with_posix_group) {
if ( !exists $config->{ldap}->{ravada_posix_group}
|| !$config->{ldap}->{ravada_posix_group}) {
$config->{ldap}->{ravada_posix_group} = $RAVADA_POSIX_GROUP;
diag("Adding ravada_posix_group = $RAVADA_POSIX_GROUP in $file_config");
}
} else {
delete $config->{ldap}->{ravada_posix_group};
}
$config->{vm}=['KVM','Void'];
delete $config->{ldap}->{ravada_posix_group} if !$with_posix_group;
my $fly_config = "/var/tmp/ravada_".base_domain_name().".conf";
DumpFile($fly_config, $config);
$RVD_BACK = undef;
$RVD_FRONT = undef;
init($fly_config);
return $fly_config;
}
1; 1;
...@@ -102,7 +102,7 @@ for my $vm_name ( vm_names() ) { ...@@ -102,7 +102,7 @@ for my $vm_name ( vm_names() ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg if !$vm; skip $msg,10 if !$vm;
test_request_start($vm_name); test_request_start($vm_name);
test_request_iptables($vm_name); test_request_iptables($vm_name);
......
...@@ -380,7 +380,7 @@ for my $vm_name ( vm_names() ) { ...@@ -380,7 +380,7 @@ for my $vm_name ( vm_names() ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg,10 if !$vm; skip $msg,10 if !$vm;
diag("Testing remove on $vm_name"); diag("Testing remove on $vm_name");
......
...@@ -354,7 +354,7 @@ for my $vm_name ( vm_names() ) { ...@@ -354,7 +354,7 @@ for my $vm_name ( vm_names() ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg,10 if !$vm; skip $msg,10 if !$vm;
diag("Testing shutdown on $vm_name"); diag("Testing shutdown on $vm_name");
......
...@@ -54,7 +54,7 @@ for my $vm_name ( q'KVM' ) { ...@@ -54,7 +54,7 @@ for my $vm_name ( q'KVM' ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg,10 if !$vm; skip $msg,10 if !$vm;
diag("Testing remove on $vm_name"); diag("Testing remove on $vm_name");
......
...@@ -70,7 +70,7 @@ for my $vm_name ( vm_names() ) { ...@@ -70,7 +70,7 @@ for my $vm_name ( vm_names() ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg if !$vm; skip $msg,10 if !$vm;
diag("Testing free mem on $vm_name"); diag("Testing free mem on $vm_name");
......
...@@ -82,7 +82,7 @@ for my $vm_name ( q(KVM) ) { ...@@ -82,7 +82,7 @@ for my $vm_name ( q(KVM) ) {
} }
diag($msg) if !$vm; diag($msg) if !$vm;
skip $msg if !$vm; skip $msg,10 if !$vm;
diag("Testing free mem on $vm_name"); diag("Testing free mem on $vm_name");
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment