File: 03certificate.t

package info (click to toggle)
libweb-id-perl 1.927-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 288 kB
  • sloc: perl: 1,381; makefile: 2; sh: 1
file content (138 lines) | stat: -rw-r--r-- 3,755 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
=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;

my $cert = new_ok 'Web::ID::Certificate' => [pem => <<PEM];
-----BEGIN CERTIFICATE-----
MIIDwjCCAyugAwIBAgIBADANBgkqhkiG9w0BAQUFADCBiDELMAkGA1UEBhMCR0Ix
FDASBgNVBAgTC0Vhc3QgU3Vzc2V4MQ4wDAYDVQQHEwVMZXdlczEVMBMGA1UEChMM
VG9ieSBJbmtzdGVyMRUwEwYDVQQDEwxUb2J5IElua3N0ZXIxJTAjBgkqhkiG9w0B
CQEWFm1haWxAdG9ieWlua3N0ZXIuY28udWswHhcNM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
xQX4IrD3
-----END CERTIFICATE-----
PEM

is(
	$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
310909140079095101890533230320492369801087117742406223614892501
787774620864861679114505059424999743262559670390116085085948715
342933807186300265081435647527932300421122776861006014367973239
989185928655230008072818263686128144228920459652460693839
MOD

ok(
	$cert->modulus eq $modulus,
	'correct modulus'
);

isa_ok(
	$cert->subject_alt_names->[$_],
	'Web::ID::SAN',
	"SAN $_",
) 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;

is(
	$cert->subject_alt_names->[0]->value,
	'http://tobyinkster.co.uk/#i',
	'SAN 0 correct value',
);