1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use ABAC; |
---|
5 | use Data::Dumper; |
---|
6 | $Data::Dumper::Indent = 1; |
---|
7 | |
---|
8 | use constant { |
---|
9 | ROLE => '3f1aca4c5911b345d81c5f1a77675dce13249d0c.fed_create', |
---|
10 | PRINCIPAL => '5839d714b16bbe108642c5eb586c2173420bed19', |
---|
11 | }; |
---|
12 | |
---|
13 | my $keystore = shift || die "Usage: prover.pl <keystore> [-v]\n"; |
---|
14 | my $verbose = shift; |
---|
15 | |
---|
16 | my $ctx = ABAC::Context->new; |
---|
17 | $ctx->load_directory("$keystore/1"); |
---|
18 | |
---|
19 | my $ctx_add = ABAC::Context->new($ctx); |
---|
20 | |
---|
21 | my ($success, $credentials) = $ctx_add->query(ROLE, PRINCIPAL); |
---|
22 | my $result = $success ? 'FAIL' : 'PASS'; |
---|
23 | printf "%-60s %s\n", 'Unsuccessful query:', $result; |
---|
24 | dump_creds($credentials) if $verbose; |
---|
25 | |
---|
26 | $ctx_add->load_directory("$keystore/2"); |
---|
27 | my ($success, $credentials) = $ctx_add->query(ROLE, PRINCIPAL); |
---|
28 | my $result = $success ? 'PASS' : 'FAIL'; |
---|
29 | printf "%-60s %s\n", 'Added credentials, successful query:', $result; |
---|
30 | dump_creds($credentials) if $verbose; |
---|
31 | |
---|
32 | my ($success, $credentials) = $ctx->query(ROLE, PRINCIPAL); |
---|
33 | my $result = $success ? 'FAIL' : 'PASS'; |
---|
34 | printf "%-60s %s\n", 'Original context, failed query:', $result; |
---|
35 | dump_creds($credentials) if $verbose; |
---|
36 | |
---|
37 | sub dump_creds { |
---|
38 | my $credentials = shift; |
---|
39 | foreach my $credential (@$credentials) { |
---|
40 | printf "%s <- %s\n", |
---|
41 | $credential->head->string, |
---|
42 | $credential->tail->string; |
---|
43 | } |
---|
44 | } |
---|