Add missing docs to ->set, for which params are allowed in the object/db.
Add missing allowMacroAccess to default dbLink. Add several tests for create, get, delete, etc.
This commit is contained in:
parent
86d9fc6860
commit
8261c896a6
2 changed files with 110 additions and 7 deletions
|
|
@ -330,9 +330,10 @@ sub new {
|
||||||
identifier=>$session->config->get("dbpass"),
|
identifier=>$session->config->get("dbpass"),
|
||||||
title=>"WebGUI Database",
|
title=>"WebGUI Database",
|
||||||
allowedKeywords=>"select\ndescribe\ndesc\nshow\ncall",
|
allowedKeywords=>"select\ndescribe\ndesc\nshow\ncall",
|
||||||
|
allowMacroAccess=>0,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
%databaseLink = $session->db->quickHash("select * from databaseLink where databaseLinkId=".$session->db->quote($databaseLinkId));
|
%databaseLink = $session->db->quickHash("select * from databaseLink where databaseLinkId=?",[$databaseLinkId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -407,6 +408,15 @@ The password to connect to the database with.
|
||||||
|
|
||||||
A text label to identify this database to humans in the UI.
|
A text label to identify this database to humans in the UI.
|
||||||
|
|
||||||
|
=head4 allowedKeywords
|
||||||
|
|
||||||
|
A whitespace delimited of keywords that a query may start with. Checked in
|
||||||
|
queryIsAllowed.
|
||||||
|
|
||||||
|
=head4 allowMacroAccess
|
||||||
|
|
||||||
|
A boolean that indicates whether macros are allowed to access this DatabaseLink.
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub set {
|
sub set {
|
||||||
|
|
|
||||||
105
t/DatabaseLink.t
105
t/DatabaseLink.t
|
|
@ -17,7 +17,8 @@ use WebGUI::Session;
|
||||||
|
|
||||||
use WebGUI::DatabaseLink;
|
use WebGUI::DatabaseLink;
|
||||||
|
|
||||||
use Test::More; # increment this value for each test you create
|
use Test::More;
|
||||||
|
use Test::Deep;
|
||||||
|
|
||||||
my $session = WebGUI::Test->session;
|
my $session = WebGUI::Test->session;
|
||||||
|
|
||||||
|
|
@ -123,12 +124,94 @@ my $grants = [
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
plan tests => 2 + scalar @{ $DSNs } + scalar @{ $grants };
|
plan tests => 14 + scalar @{ $DSNs } + scalar @{ $grants };
|
||||||
|
|
||||||
my $dbLink = WebGUI::DatabaseLink->new($session, 0);
|
####################################################
|
||||||
is($dbLink->get->{DSN}, $session->config->get('dsn'), 'DSN set correctly for default database link');
|
#
|
||||||
|
# create
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
my $startingDbLinks = scalar keys %{WebGUI::DatabaseLink->getList($session)};
|
||||||
|
|
||||||
|
my $dbLink = WebGUI::DatabaseLink->create($session);
|
||||||
|
isa_ok($dbLink, 'WebGUI::DatabaseLink', 'create made an object');
|
||||||
|
ok($session->id->valid($dbLink->getId), 'create makes an object with a valid GUID');
|
||||||
|
cmp_deeply(
|
||||||
|
$dbLink->get(),
|
||||||
|
{
|
||||||
|
databaseLinkId => re(".{22}"),
|
||||||
|
DSN => undef,
|
||||||
|
username => undef,
|
||||||
|
identifier => undef,
|
||||||
|
title => undef,
|
||||||
|
allowedKeywords => undef,
|
||||||
|
allowMacroAccess => 0,
|
||||||
|
},
|
||||||
|
'create: passing no params autovivifies the databaseLinkId, but that is all',
|
||||||
|
);
|
||||||
|
|
||||||
|
is(scalar keys %{WebGUI::DatabaseLink->getList($session)}, $startingDbLinks+1, 'new DatabaseLink created');
|
||||||
|
$dbLink->delete();
|
||||||
|
is(scalar keys %{WebGUI::DatabaseLink->getList($session)}, $startingDbLinks, 'new DatabaseLink deleted');
|
||||||
|
|
||||||
|
my $dbLinkParams = {
|
||||||
|
DSN => 'DBI:mysql:myDb:myHost',
|
||||||
|
username => 'dbUser',
|
||||||
|
identifier => 'dbPass',
|
||||||
|
title => 'Access to my Awesome DB',
|
||||||
|
allowedKeywords => 'SELECT UPDATE',
|
||||||
|
databaseLinkId => 'fooBarBaz',
|
||||||
|
allowMacroAccess => 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
$dbLink = WebGUI::DatabaseLink->create($session, $dbLinkParams);
|
||||||
|
$dbLinkParams->{databaseLinkId} = ignore();
|
||||||
|
|
||||||
|
cmp_deeply(
|
||||||
|
$dbLink->get(),
|
||||||
|
$dbLinkParams,
|
||||||
|
'create: params sent to create are embedded in the object correctly',
|
||||||
|
);
|
||||||
|
isnt($dbLink->getId, 'fooBarBaz', 'requested databaseLinkId was not used as the linkId');
|
||||||
|
ok($session->id->valid($dbLink->getId), 'create made a valid GUID instead of that thing I asked for');
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# queryIsValid
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# new
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
my $wgDbLink = WebGUI::DatabaseLink->new($session, 0);
|
||||||
|
is($wgDbLink->get->{DSN}, $session->config->get('dsn'), 'DSN set correctly for default database link');
|
||||||
my ($databaseName) = $session->db->quickArray('SELECT DATABASE()');
|
my ($databaseName) = $session->db->quickArray('SELECT DATABASE()');
|
||||||
is ($dbLink->databaseName, $databaseName, 'databaseName parsed default DSN from config file');
|
is ($wgDbLink->databaseName, $databaseName, 'databaseName parsed default DSN from config file');
|
||||||
|
is ($wgDbLink->getId, 0, 'databaseLinkId set correctly');
|
||||||
|
|
||||||
|
is(WebGUI::DatabaseLink->new($session), undef, 'new returns undef unless you specify a databaseLinkId');
|
||||||
|
is(WebGUI::DatabaseLink->new($session,'foobar'), undef, 'new returns undef with a non-existant databaseLinkId');
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# delete
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# databaseName
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
|
my $dbs = WebGUI::DatabaseLink->getList($session);
|
||||||
|
|
||||||
foreach my $dsn (@{ $DSNs }) {
|
foreach my $dsn (@{ $DSNs }) {
|
||||||
my $dbl = WebGUI::DatabaseLink->create($session, { DSN => $dsn->{dsn} });
|
my $dbl = WebGUI::DatabaseLink->create($session, { DSN => $dsn->{dsn} });
|
||||||
|
|
@ -136,6 +219,12 @@ foreach my $dsn (@{ $DSNs }) {
|
||||||
$dbl->delete;
|
$dbl->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
####################################################
|
||||||
|
#
|
||||||
|
# checkPrivileges
|
||||||
|
#
|
||||||
|
####################################################
|
||||||
|
|
||||||
foreach my $grant (@{ $grants }) {
|
foreach my $grant (@{ $grants }) {
|
||||||
my $dbl = WebGUI::DatabaseLink->create($session, { DSN => $grant->{dsn} });
|
my $dbl = WebGUI::DatabaseLink->create($session, { DSN => $grant->{dsn} });
|
||||||
is(
|
is(
|
||||||
|
|
@ -146,8 +235,12 @@ foreach my $grant (@{ $grants }) {
|
||||||
$dbl->delete;
|
$dbl->delete;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $dbsAfter = WebGUI::DatabaseLink->getList($session);
|
||||||
|
|
||||||
|
cmp_deeply($dbs, $dbsAfter, 'delete cleaned up all temporarily created DatabaseLinks');
|
||||||
|
|
||||||
END {
|
END {
|
||||||
foreach my $link ($dbLink, ) {
|
foreach my $link ($dbLink, $wgDbLink) {
|
||||||
$link->delete if (defined $link and ref $link eq 'WebGUI::DatabaseLink');
|
$link->delete if (defined $link and ref $link eq 'WebGUI::DatabaseLink');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue