Commit b86d78c9 authored by Francesc Guasch's avatar Francesc Guasch
Browse files

search domain by id

parent e0c45443
...@@ -151,6 +151,23 @@ sub search_domain { ...@@ -151,6 +151,23 @@ sub search_domain {
} }
} }
=head2 search_domain_by_id
my $domain = $ravada->search_domain_by_id($id);
=cut
sub search_domain_by_id {
my $self = shift;
my $id = shift;
for my $vm (@{$self->vm}) {
my $domain = $vm->search_domain_by_id($id);
return $domain if $domain;
}
}
=head2 list_domains =head2 list_domains
List all created domains List all created domains
......
...@@ -15,6 +15,7 @@ requires 'connect'; ...@@ -15,6 +15,7 @@ requires 'connect';
# domain # domain
requires 'create_domain'; requires 'create_domain';
requires 'search_domain'; requires 'search_domain';
requires 'search_domain_by_id';
requires 'list_domains'; requires 'list_domains';
......
...@@ -151,6 +151,27 @@ sub search_domain { ...@@ -151,6 +151,27 @@ sub search_domain {
} }
} }
=head2 search_domain_by_id
Returns a domain searching by its id
$domain = $vm->search_domain_by_id($id);
=cut
sub search_domain_by_id {
my $self = shift;
my $id = shift;
my $sth = $self->connector->dbh->prepare("SELECT name FROM domains "
." WHERE id=?");
$sth->execute($id);
my ($name) = $sth->fetchrow;
return if !$name;
return $self->search_domain($name);
}
=head2 list_domains =head2 list_domains
Returns a list of the created domains Returns a list of the created domains
......
...@@ -83,6 +83,11 @@ sub test_new_domain { ...@@ -83,6 +83,11 @@ sub test_new_domain {
my $row = search_domain_db($domain->name); my $row = search_domain_db($domain->name);
ok($row->{name} && $row->{name} eq $domain->name,"I can't find the domain at the db"); ok($row->{name} && $row->{name} eq $domain->name,"I can't find the domain at the db");
my $domain2 = $ravada->search_domain_by_id($domain->id);
ok($domain2->id eq $domain->id,"Expecting id = ".$domain->id." , got ".$domain2->id);
ok($domain2->name eq $domain->name,"Expecting name = ".$domain->name." , got "
.$domain2->name);
return $domain; return $domain;
} }
......
use warnings;
use strict;
use Test::More;
use Test::SQL::Data;
my $test = Test::SQL::Data->new(config => 't/etc/ravada.conf');
use_ok('Ravada');
use_ok('Ravada::Auth::SQL');
ok($Ravada::Auth::SQL::CON,"Undefined DB connection");
my $RAVADA = Ravada->new(connector => $test->connector);
Ravada::Auth::SQL::add_user('test',$$);
my $sth = $$Ravada::Auth::SQL::CON->dbh->prepare("SELECT * FROM users WHERE name=?");
$sth->execute('test');
ok($sth->fetchrow,"I can't find test user in the database") or exit;
ok(Ravada::Auth::SQL::login('test',$$,"I can't login test/$$"));
done_testing();
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