[openssl-commits] [tools] master update

Richard Levitte levitte at openssl.org
Wed Jun 14 12:13:43 UTC 2017


The branch master has been updated
       via  3313e513342afb0cc2e01a90efba029f271079d4 (commit)
       via  548a1260ed6e0e74347e077fff0c0013a3f7e1da (commit)
       via  ebbb09a34b8ed9ae9fd02e26e76bc55c0b35413a (commit)
       via  ddb83245fbcfdb94f6ea4201322d7e7368b127d2 (commit)
       via  96e6e0beeb15eab47b436ef92d394c13dc8dc5f0 (commit)
      from  200f98e598aa4563114d2b98b93e7c6ffdc969de (commit)


- Log -----------------------------------------------------------------
commit 3313e513342afb0cc2e01a90efba029f271079d4
Author: Richard Levitte <richard at levitte.org>
Date:   Wed Jun 14 14:13:23 2017 +0200

    QueryApp: Add a test recipe that queries the OpenSSL::Query::DB impl directly

commit 548a1260ed6e0e74347e077fff0c0013a3f7e1da
Author: Richard Levitte <richard at levitte.org>
Date:   Wed Jun 14 14:12:37 2017 +0200

    OpenSSL-Query, QueryApp: Test the API that fetches the list of ids

commit ebbb09a34b8ed9ae9fd02e26e76bc55c0b35413a
Author: Richard Levitte <richard at levitte.org>
Date:   Wed Jun 14 14:11:52 2017 +0200

    QueryApp: Add the REST API to get the list of ids

commit ddb83245fbcfdb94f6ea4201322d7e7368b127d2
Author: Richard Levitte <richard at levitte.org>
Date:   Wed Jun 14 14:10:59 2017 +0200

    OpenSSL-Query, QueryApp: Add methods to get the list of identities

commit 96e6e0beeb15eab47b436ef92d394c13dc8dc5f0
Author: Richard Levitte <richard at levitte.org>
Date:   Wed Jun 14 14:09:28 2017 +0200

    QueryApp: Correct reference to OpenSSL-Query in test

-----------------------------------------------------------------------

Summary of changes:
 OpenSSL-Query/lib/OpenSSL/Query.pm            |   9 +++
 OpenSSL-Query/lib/OpenSSL/Query/PersonREST.pm |  13 +++
 OpenSSL-Query/t/query.t                       |  10 ++-
 QueryApp/RESTAPI.txt                          |   5 ++
 QueryApp/bin/query.psgi                       |   8 ++
 QueryApp/lib/OpenSSL/Query/PersonDB.pm        |  12 +++
 QueryApp/t/query.t                            |  16 +++-
 QueryApp/t/query_direct.t                     | 111 ++++++++++++++++++++++++++
 8 files changed, 179 insertions(+), 5 deletions(-)
 create mode 100644 QueryApp/t/query_direct.t

diff --git a/OpenSSL-Query/lib/OpenSSL/Query.pm b/OpenSSL-Query/lib/OpenSSL/Query.pm
index f8bd82c..727c77b 100644
--- a/OpenSSL-Query/lib/OpenSSL/Query.pm
+++ b/OpenSSL-Query/lib/OpenSSL/Query.pm
@@ -90,6 +90,15 @@ sub _perform {
 }
 
 # Person methods
+sub list_people {
+  my $self = shift;
+
+  $self->_perform('person',
+		  sub { my $obj = shift;
+			return $obj->list_people(@_) },
+		  @_);
+}
+
 sub find_person {
   my $self = shift;
 
diff --git a/OpenSSL-Query/lib/OpenSSL/Query/PersonREST.pm b/OpenSSL-Query/lib/OpenSSL/Query/PersonREST.pm
index 082c877..ce3abb9 100644
--- a/OpenSSL-Query/lib/OpenSSL/Query/PersonREST.pm
+++ b/OpenSSL-Query/lib/OpenSSL/Query/PersonREST.pm
@@ -35,6 +35,19 @@ sub _build__personhandler {
 #  croak "Server error: ", $resp->message if $resp->is_server_error;
 #}
 
+sub list_people {
+  my $self = shift;
+
+  my $ua = $self->_personhandler;
+  my $json = $ua->get($self->base_url . '/0/People/');
+  croak "Server error: ", $json->message if $json->is_server_error;
+  return () unless $json->code == 200;
+
+  my $decoded = decode_json $json->decoded_content;
+
+  return @$decoded;
+}
+
 sub find_person {
   my $self = shift;
   my $id = shift;
diff --git a/OpenSSL-Query/t/query.t b/OpenSSL-Query/t/query.t
index 2900b62..f167a66 100644
--- a/OpenSSL-Query/t/query.t
+++ b/OpenSSL-Query/t/query.t
@@ -11,7 +11,7 @@ use Test::More;
 use OpenSSL::Query::REST;
 use Data::Dumper;
 
-plan tests => 11;
+plan tests => 12;
 
 SKIP: {
   my $query;
@@ -22,6 +22,14 @@ SKIP: {
 	       'Creating a OpenSSL::Query object' );
 
   # print STDERR Dumper($query);
+  subtest 'Request of identity list' => sub {
+    plan tests => 1;
+
+    my @res = $query->list_people();
+    ok( scalar @res > 0, 'We got a list' );
+    note( Dumper( [ @res ] ) );
+  };
+
   subtest 'Request of person data for Ray Bradbury' => sub {
     plan tests => 2;
 
diff --git a/QueryApp/RESTAPI.txt b/QueryApp/RESTAPI.txt
index abe2686..1cecba0 100644
--- a/QueryApp/RESTAPI.txt
+++ b/QueryApp/RESTAPI.txt
@@ -9,6 +9,11 @@ Supported versions:
 Version 0 API:
 --------------
 
+/0/People
+
+    Fetches the list of known people.  Each item of this list is a
+    list of identities for each person.
+
 /0/Person/:name
 
     Fetches the complete set of database information on :name.
diff --git a/QueryApp/bin/query.psgi b/QueryApp/bin/query.psgi
index 6724ecf..80d8a53 100644
--- a/QueryApp/bin/query.psgi
+++ b/QueryApp/bin/query.psgi
@@ -64,6 +64,14 @@ set bureau => '/var/cache/openssl/checkouts/bureau';
 
 prefix '/0';
 
+get '/People' => sub {
+  my $query = OpenSSL::Query->new(bureau => config->{bureau});
+  my @response = $query->list_people();
+
+  return [ @response ] if @response;
+  send_error('Not found', HTTP_NO_CONTENT);
+};
+
 get '/Person/:name' => sub {
   my $query = OpenSSL::Query->new(bureau => config->{bureau});
   my $name = uri_decode(route_parameters->get('name'));
diff --git a/QueryApp/lib/OpenSSL/Query/PersonDB.pm b/QueryApp/lib/OpenSSL/Query/PersonDB.pm
index 4d9ede3..ab5507b 100644
--- a/QueryApp/lib/OpenSSL/Query/PersonDB.pm
+++ b/QueryApp/lib/OpenSSL/Query/PersonDB.pm
@@ -12,6 +12,7 @@ use strict;
 package OpenSSL::Query::PersonDB;
 
 use Carp;
+use Clone qw(clone);
 use Moo;
 use OpenSSL::Query qw(-register-person OpenSSL::Query::PersonDB -priority 0);
 
@@ -38,6 +39,17 @@ sub _build__persondb {
   return $yaml;
 }
 
+sub list_people {
+  my $self = shift;
+
+  my @list = ();
+  foreach my $record (@{$self->_persondb}) {
+    push @list, clone($record->{ids});
+  }
+
+  return @list;
+}
+
 sub find_person {
   my $self = shift;
   my $id = shift;
diff --git a/QueryApp/t/query.t b/QueryApp/t/query.t
index 3fce11b..1f0d3d3 100644
--- a/QueryApp/t/query.t
+++ b/QueryApp/t/query.t
@@ -7,15 +7,15 @@ BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';}
 
 use strict;
 use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
 use Plack::Test;
 use Plack::Util;
 use HTTP::Request::Common;
 use FindBin;
 
-# This picks up if this is part of a checkout with OpenSSLQuery
-use if -r $FindBin::Bin.'/../../OpenSSLQuery/lib/OpenSSL/Query.pm',
-  lib => $FindBin::Bin.'/../../OpenSSLQuery/lib';
+# This picks up if this is part of a checkout with OpenSSL-Query
+use if -r $FindBin::Bin.'/../../OpenSSL-Query/lib/OpenSSL/Query.pm',
+  lib => $FindBin::Bin.'/../../OpenSSL-Query/lib';
 
 $ENV{PERSONDB} = $FindBin::Bin.'/query_data/pdb.yaml';
 $ENV{CLADB} = $FindBin::Bin.'/query_data/cdb.txt';
@@ -23,6 +23,14 @@ $ENV{CLADB} = $FindBin::Bin.'/query_data/cdb.txt';
 my $app = Plack::Util::load_psgi( $FindBin::Bin.'/../bin/query.psgi' );
 my $test = Plack::Test->create( $app );
 
+subtest 'Request of identity list' => sub {
+  my $res = $test->request( GET '/0/People' );
+  plan tests => 2;
+  ok( $res->is_success, 'Successful request' );
+  note( $res->content );
+  is( $res->code, 200, 'We have content' );
+};
+
 subtest 'A empty request' => sub {
   my $res = $test->request( GET '/' );
   plan tests => 1;
diff --git a/QueryApp/t/query_direct.t b/QueryApp/t/query_direct.t
new file mode 100644
index 0000000..bbd9240
--- /dev/null
+++ b/QueryApp/t/query_direct.t
@@ -0,0 +1,111 @@
+#! /usr/bin/env perl
+
+# This means that 'dance' at the end of query.psgi will not start a built in
+# service, but will simply return a coderef.  This is useful to run this with
+# diverse dispatchers as well as tests.
+BEGIN { $ENV{DANCER_APPHANDLER} = 'PSGI';}
+
+use strict;
+use warnings;
+use Test::More tests => 11;
+use Data::Dumper;
+use FindBin;
+
+# This picks up if this is part of a checkout with OpenSSLQuery
+use if -r $FindBin::Bin.'/../../OpenSSL-Query/lib/OpenSSL/Query.pm',
+  lib => $FindBin::Bin.'/../../OpenSSL-Query/lib';
+require OpenSSL::Query::DB; OpenSSL::Query::DB->import();
+
+$ENV{PERSONDB} = $FindBin::Bin.'/query_data/pdb.yaml';
+$ENV{CLADB} = $FindBin::Bin.'/query_data/cdb.txt';
+
+my $query = OpenSSL::Query->new();
+
+subtest 'Request of identity list' => sub {
+  plan tests => 1;
+
+  my @res = $query->list_people();
+  ok( scalar @res > 0, 'We got a list' );
+  note( Dumper( [ @res ] ) );
+};
+
+subtest 'Request of person data for Ray Bradbury' => sub {
+  plan tests => 2;
+
+  my $res1 = $query->find_person( 'Ray Bradbury' );
+  ok( $res1, 'Ray Bradbury is present' );
+  note( $res1 );
+
+  my %res2 = $query->find_person( 'Ray Bradbury' );
+  ok(scalar keys %res2 > 1, "Got Ray Bradbury's data" );
+  note( Dumper( { %res2 } ) );
+};
+
+subtest 'Request of membership in specific group for Ray Bradbury' => sub {
+  plan tests => 1;
+  my $res = $query->is_member_of( 'Ray Bradbury', 'scifi' );
+  ok( $res, "Ray Bradbury is member of scifi since ".( $res ? $res : "(unknown)" ) );
+  note( $res );
+};
+
+subtest 'Request of "author" tag value for Ray Bradbury' => sub {
+  plan tests => 1;
+  my $res = $query->find_person_tag( 'Ray Bradbury', 'author' );
+  ok( $res, "The 'author' tag for Ray Bradbury is ".( $res ? $res : "(unknown)" ) );
+  note( Dumper $res );
+};
+
+subtest 'Request of CLA status for Ray Bradbury' => sub {
+  plan tests => 1;
+  my $res = $query->has_cla( 'ray at ourplace.com' );
+  ok( $res, 'Ray Bradbury has CLA as ray at ourplace.com' );
+  note( $res );
+};
+
+subtest 'Request of membership in the group "writers"' => sub {
+  plan tests => 1;
+  my @res = $query->members_of( 'writers' );
+  ok( @res, 'Finding members of "writers"' );
+  note( Dumper @res );
+};
+
+subtest 'Request of person data for Jay Luser' => sub {
+  plan tests => 2;
+
+  my $res1 = $query->find_person( 'Jay Luser' );
+  ok( !$res1, 'Jay Luser is not present' );
+  note( $res1 );
+
+  my %res2 = $query->find_person( 'Jay Luser' );
+  ok( !%res2, "Failed getting Jay Luser's data" );
+};
+
+subtest 'Request of membership in specific group for Jay Luser' => sub {
+  plan tests => 1;
+  my $res = $query->is_member_of( 'Jay Luser', 'scifi' );
+  ok( !$res, 'Jay Luser is not member of scifi' );
+  note( $res );
+};
+
+subtest 'Request of "author" tag value for Jay Luser' => sub {
+  plan tests => 1;
+  my $res = $query->find_person_tag( 'Jay Luser', 'author' );
+  ok( !$res, "No 'author' tag for Jay Luser" );
+  note( $res );
+};
+
+subtest 'Request of CLA status for Jay Luser' => sub {
+  plan tests => 1;
+  my $res = $query->has_cla( 'jluser at ourplace.com' );
+  ok( !$res, 'Jay Luser has no CLA' );
+  note( $res );
+};
+
+subtest 'Request of membership in the group "couchpotatoes"' => sub {
+  plan tests => 1;
+  my @res = $query->members_of( 'couchpotatoes' );
+  ok( !@res, 'No members in "couchpotatoes"' );
+  note( @res );
+};
+
+1;


More information about the openssl-commits mailing list