Added the checkPrivileges method, borrowed from SQLForm.

Wrote tests based on SQLForm bugs to validate it, and it passes.
This commit is contained in:
Colin Kuskie 2007-07-14 23:11:03 +00:00
parent 3d016a366b
commit cff3ac1816
2 changed files with 149 additions and 1 deletions

View file

@ -55,7 +55,75 @@ my $DSNs = [
},
];
plan tests => 2 + scalar @{ $DSNs };
#Grants for parsing tests, particularly the database name
my $grants = [
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALTER, CREATE, INSERT, DELETE ON *.* to user@localhost',
],
privileged => 1,
comment => 'ACID on *.*, privileged',
},
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALL PRIVILEGES ON *.* to user@localhost',
],
privileged => 1,
comment => 'ALL PRIVILEGES on *.*, privileged',
},
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALTER, CREATE, INSERT ON *.* to user@localhost',
],
privileged => 0,
comment => 'Missing DELETE on *.*, unprivileged',
},
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALL PRIVILEGES ON myDb.* to user@localhost',
],
privileged => 1,
comment => 'ALL PRIVILEGES on explicit db name, privileged',
},
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALL PRIVILEGES ON `myDb`.* to user@localhost',
],
privileged => 1,
comment => 'ALL PRIVILEGES on quoted, explicit db name, privileged',
},
{
dsn => 'DBI:mysql:myDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALL PRIVILEGES ON `my%`.* to user@localhost',
],
privileged => 1,
comment => 'ALL PRIVILEGES on quoted, wildcard name, privileged',
},
{
dsn => 'DBI:mysql:yourDb:myHost:8008',
privileges => [qw/ALTER CREATE INSERT DELETE/],
grants => [
'GRANT ALL PRIVILEGES ON `my%`.* to user@localhost',
],
privileged => 0,
comment => 'ALL PRIVILEGES on wrong db, unprivileged',
},
];
plan tests => 2 + 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');
@ -68,6 +136,15 @@ foreach my $dsn (@{ $DSNs }) {
$dbl->delete;
}
foreach my $grant (@{ $grants }) {
my $dbl = WebGUI::DatabaseLink->create($session, { DSN => $grant->{dsn} });
is(
$dbl->checkPrivileges($grant->{privileges}, $grant->{grants}),
$grant->{privileged},
$grant->{comment}
);
$dbl->delete;
}
END {
foreach my $link ($dbLink, ) {