Commits

Toby Inkster committed 02c424c

document and tidy test suite

  • Participants
  • Parent commits 033d369

Comments (0)

Files changed (4)

-use Test::More tests => 1;
-BEGIN {
-	use_ok('Web::ID');
-}
+=head1 PURPOSE
 
+This test has been retired. Web::ID no longer uses Any::Moose/Mouse.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
+use Test::More skip_all => "eek! eek!";
+
+=head1 PURPOSE
+
+Check that Web::ID compiles.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
 use Test::More;
-eval { require Moose; require MooseX::Types::Moose; 1 }
-	or plan skip_all => "need Moose";
+
+#eval { require Moose; require MooseX::Types::Moose; 1 }
+#	or plan skip_all => "need Moose";
 
 plan tests => 1;
 use_ok('Web::ID');

t/03certificate.t

+=head1 PURPOSE
+
+Tests that L<Web::ID::Certificate> is able to extract information from a
+PEM-encoded certificate.
+
+The majority of the tests are conducted on a certificate that I<< will
+expire on 2013-06-21T11:49:45 >> however, it is believed that the nature
+of these tests is such that they will continue to pass after the certificate
+has expired. (No tests should be relying on it being a timely certificate.)
+The situation may need reviewing in July 2013.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
 use Test::More tests => 18;
 use Web::ID::Certificate;
 
 	$cert->not_before,
 	'2009-06-22T11:49:45',
 	'certificate not_before correct',
-	);
+);
 
 is(
 	$cert->not_after,
 	'2013-06-21T11:49:45',
 	'certificate not_after correct',
-	);
+);
 
 ok(
 	! $cert->timely( $cert->not_before->clone->subtract(days => 1) ),
 	'not timely before not_before',
-	);
+);
 
 ok(
 	$cert->timely( $cert->not_before ),
 	'timely on not_before',
-	);
+);
 
 ok(
 	$cert->timely( $cert->not_before->clone->add(days => 1) ),
 	'timely after not_before',
-	);
+);
 
 ok(
 	$cert->timely( $cert->not_after ),
 	'timely on not_after',
-	);
+);
 
 ok(
 	! $cert->timely( $cert->not_after->clone->add(days => 1) ),
 	'not timely after not_after',
-	);
+);
 
 is(
 	$cert->fingerprint,
 	'f4651a0cd4efc7301103a7dfec983244dd47b190',
 	'correct fingerprint',
-	);
+);
 
 ok(
 	$cert->exponent eq '65537',
 	'correct exponent'
-	);
+);
 
 (my $modulus = <<MOD)  =~ s/\D//g;
 146454716751099837259538589121569684032917070750180889825346452
 ok(
 	$cert->modulus eq $modulus,
 	'correct modulus'
-	);
+);
 
 isa_ok(
 	$cert->subject_alt_names->[$_],
 	'Web::ID::SAN',
 	"SAN $_",
-	) for 0..2;
+) for 0..2;
 
 isa_ok(
 	$cert->subject_alt_names->[0],
 	'Web::ID::SAN::URI',
 	"SAN 0",
-	);
+);
 
 isa_ok(
 	$cert->subject_alt_names->[$_],
 	'Web::ID::SAN::Email',
 	"SAN $_",
-	) for 1..2;
+) for 1..2;
 
 is(
 	$cert->subject_alt_names->[0]->value,
 	'http://tobyinkster.co.uk/#i',
 	'SAN 0 correct value',
-	);
+);
 
+=head1 PURPOSE
+
+Performs as close to an end-to-end test as possible without an actual
+HTTPS server.
+
+Generates certificates for five dummy identities using
+L<Web::ID::Certificate::Generator>; creates FOAF profiles for them
+(using a mixture of Turtle and RDF/XML) and checks that their
+certificates can be validated against their profiles.
+
+Destroys one of the FOAF profiles and checks that the corresponding
+certificate no longer validates.
+
+Alters one of the FOAF profiles and checks that the corresponding
+certificate no longer validates.
+
+Tries its very best to clean up after itself.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT AND LICENCE
+
+This software is copyright (c) 2012 by Toby Inkster.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
+
 use 5.010;
 use strict;
 
 use Web::ID;
 use Web::ID::Certificate::Generator;
 
+# Attempt to silence openssl during test cases
+sub capture_merged (&;@);
+BEGIN {
+	*capture_merged = eval { require Capture::Tiny }
+		? \&Capture::Tiny::capture_merged
+		: sub (&;@) { my $code = shift; $code->() }
+}
+
 -x '/usr/bin/openssl'
 	or plan skip_all => "/usr/bin/openssl not executable";
 
+# They're unlikely to have /usr/bin/openssl anyway, but...
+$^O eq 'MSWin32'
+	and plan skip_all => "This test will not run on MSWin32";
+
 our @PEOPLE = qw(alice bob carol david eve);
 our %Certificates;
 
 {
 	my $discard;
 	my $rdf;
-	$Certificates{$p} = 'Web::ID::Certificate'->generate(
-		passphrase        => 'secret',
-		subject_alt_names => [
-			Web::ID::SAN::URI->new(value => $baseuri.$p),
-		],
-		subject_cn        => ucfirst($p),
-		rdf_output        => \$rdf,
-		cert_output       => \$discard,
-	)->pem;
+	my @captured = capture_merged {
+		$Certificates{$p} = 'Web::ID::Certificate'->generate(
+			passphrase        => 'secret',
+			subject_alt_names => [
+				Web::ID::SAN::URI->new(value => $baseuri.$p),
+			],
+			subject_cn        => ucfirst($p),
+			rdf_output        => \$rdf,
+			cert_output       => \$discard,
+		)->pem
+	};
 	
 	isa_ok($rdf, 'RDF::Trine::Model', tmpfile($p).' $rdf');