summaryrefslogtreecommitdiff
path: root/perl
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2008-01-23 22:58:01 +0000
committerRuss Allbery <rra@stanford.edu>2008-01-23 22:58:01 +0000
commita396efdbc792c6b1e0ff3763dd8f09c9b638976f (patch)
treeb3ebeaaae92670e8ebd5b7515bba3093df446e70 /perl
parentd1e2c5add56f1597821d401aabf2630b33d12020 (diff)
Return IDs and names from list_acls.
Diffstat (limited to 'perl')
-rw-r--r--perl/Wallet/Admin.pm31
-rwxr-xr-xperl/t/admin.t17
2 files changed, 30 insertions, 18 deletions
diff --git a/perl/Wallet/Admin.pm b/perl/Wallet/Admin.pm
index 481f1b8..9e89e5e 100644
--- a/perl/Wallet/Admin.pm
+++ b/perl/Wallet/Admin.pm
@@ -143,22 +143,23 @@ sub list_objects {
}
}
-# Returns a list of all ACLs stored in the wallet database as a list of ACL
-# IDs. On error and for an empty database, the empty list will be returned;
-# however, this is unlikely since any valid database will have at least an
-# ADMIN ACL. Still, to distinguish between an empty list and an error, call
-# error(), which will return undef if there was no error.
+# Returns a list of all ACLs stored in the wallet database as a list of pairs
+# of ACL IDs and ACL names. On error and for an empty database, the empty
+# list will be returned; however, this is unlikely since any valid database
+# will have at least an ADMIN ACL. Still, to distinguish between an empty
+# list and an error, call error(), which will return undef if there was no
+# error.
sub list_acls {
my ($self) = @_;
undef $self->{error};
my @acls;
eval {
- my $sql = 'select ac_id from acls order by ac_id';
+ my $sql = 'select ac_id, ac_name from acls order by ac_id';
my $sth = $self->{dbh}->prepare ($sql);
$sth->execute;
my $object;
while (defined ($object = $sth->fetchrow_arrayref)) {
- push (@acls, $object->[0]);
+ push (@acls, [ @$object ]);
}
$self->{dbh}->commit;
};
@@ -246,11 +247,17 @@ actions on the object it returns.
=item list_acls()
-Returns a list of the ACL IDs of all ACLs found in the database or an
-empty list on failure. Any valid wallet database should have at least one
-ACL, but an error can be distinguished from the odd case of a database
-with no ACLs by calling error(). error() is guaranteed to return the
-error message if there was an error and undef if there was no error.
+Returns a list of all ACLs in the database. The return value is a list of
+references to pairs of ACL ID and name. For example, if there are two
+ACLs in the database, one with name "ADMIN" and ID 1 and one with name
+"group/admins" and ID 3, list_acls() would return:
+
+ ([ 1, 'ADMIN' ], [ 3, 'group/admins' ])
+
+Returns the empty list on failure. Any valid wallet database should have
+at least one ACL, but an error can be distinguished from the odd case of a
+database with no ACLs by calling error(). error() is guaranteed to return
+the error message if there was an error and undef if there was no error.
=item list_objects()
diff --git a/perl/t/admin.t b/perl/t/admin.t
index 4c387bd..9795f19 100755
--- a/perl/t/admin.t
+++ b/perl/t/admin.t
@@ -8,7 +8,7 @@
#
# See LICENSE for licensing terms.
-use Test::More tests => 22;
+use Test::More tests => 27;
use Wallet::Admin;
use Wallet::Schema;
@@ -31,7 +31,8 @@ is (scalar (@objects), 0, 'No objects in the database');
is ($admin->error, undef, ' and no error');
my @acls = $admin->list_acls;
is (scalar (@acls), 1, 'One ACL in the database');
-is ($acls[0], 1, ' and that is ACL ID 1');
+is ($acls[0][0], 1, ' and that is ACL ID 1');
+is ($acls[0][1], 'ADMIN', ' with the right name');
# Register a base object so that we can create a simple object.
my $schema = Wallet::Schema->new;
@@ -53,16 +54,20 @@ is ($objects[0][1], 'service/admin', ' and the right name');
is ($server->acl_create ('first'), 1, 'ACL creation succeeds');
@acls = $admin->list_acls;
is (scalar (@acls), 2, ' and now there are two ACLs');
-is ($acls[0], 1, ' and the first ID is correct');
-is ($acls[1], 2, ' and the second ID is correct');
+is ($acls[0][0], 1, ' and the first ID is correct');
+is ($acls[0][1], 'ADMIN', ' and the first name is correct');
+is ($acls[1][0], 2, ' and the second ID is correct');
+is ($acls[1][1], 'first', ' and the second name is correct');
# Delete that ACL and create another.
is ($server->acl_create ('second'), 1, 'Second ACL creation succeeds');
is ($server->acl_destroy ('first'), 1, ' and deletion of the first succeeds');
@acls = $admin->list_acls;
is (scalar (@acls), 2, ' and there are still two ACLs');
-is ($acls[0], 1, ' and the first ID is still the same');
-is ($acls[1], 3, ' but the second ID has changed');
+is ($acls[0][0], 1, ' and the first ID is still the same');
+is ($acls[0][1], 'ADMIN', ' and the first name is still the same');
+is ($acls[1][0], 3, ' but the second ID has changed');
+is ($acls[1][1], 'second', ' and the second name is correct');
# Clean up.
is ($admin->destroy, 1, 'Destruction succeeds');