Hatena::ブログ(Diary)

(ひ)メモ このページをアンテナに追加 RSSフィード

2006-11-21 (Tue)

Net::SSL::ExpireDate + Test::Base で証明書の期限切れをチェック

拙作のNet::SSL::ExpireDateとTest::Baseとで証明書の期限切れをチェック。

こんな感じの出力。

$ prove -v sample/cert-expire.t
sample/cert-expire....1..2
ok 1 - rt.cpan.org
ok 2 - www.google.com
ok
All tests successful.
Files=1, Tests=2,  5 wallclock secs ( 0.33 cusr +  0.03 csys =  0.36 CPU)

で、期限切れのがいるとこんな感じに。

$ prove -v sample/cert-expire.t
sample/cert-expire....1..2

#   Failed test 'rt.cpan.org'
#   in sample/cert-expire.t at line 27.
#          got: '2015-04-14T05:12:17'
#     expected: undef
not ok 1 - rt.cpan.org
(snip)

追記


#!/usr/bin/env perl
# -*- mode: cperl; -*-
use Test::Base;
use Net::SSL::ExpireDate;
use Regexp::Common qw(net);

my $Check_Duration;
# $Check_Duration = '15 years';

plan tests => 1 * blocks;

run {
    my $block = shift;
    my $ed = Net::SSL::ExpireDate->new( build_arg($block->name) );
    is($ed->is_expired($Check_Duration) && $ed->expire_date->iso8601,
       undef,
       $block->name);
};

sub build_arg {
    my ($v) = @_;
    if ($v =~ m{^(file)://(.+)}) {
        return $1 => $2;
    } elsif ($v =~ m{^(https)://([^/]+)}) {
        return $1 => $2;
    } elsif ($v =~ m{^$RE{net}{domain}{-nospace}{-keep}$}) {
        return 'https' => $1;
    } elsif (-r $v) {
        return 'file' => $v;
    } else {
        croak "$v: assume file. but cannot read.";
    }
}

__END__
=== rt.cpan.org
=== www.google.com

はてなユーザーのみコメントできます。はてなへログインもしくは新規登録をおこなってください。

2003 | 11 | 12 |
2004 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 10 | 11 | 12 |
2005 | 01 | 02 | 03 | 05 | 08 | 09 | 10 | 11 | 12 |
2006 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2007 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2008 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2009 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2010 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2011 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 12 |
2012 | 01 | 02 | 03 | 06 | 08 | 10 | 11 | 12 |
2013 | 01 | 02 | 03 | 05 | 06 | 07 | 08 | 09 | 10 | 11 | 12 |
2014 | 01 | 02 | 03 | 04 | 05 | 06 | 07 | 08 | 10 |
2015 | 01 | 02 | 07 | 10 |
2016 | 01 | 05 | 10 | 12 |
2017 | 07 |