File: public_key.t

package info (click to toggle)
libmail-dkim-perl 0.38-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 752 kB
  • ctags: 298
  • sloc: perl: 4,630; makefile: 45
file content (57 lines) | stat: -rwxr-xr-x 1,235 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/perl -I../lib

use strict;
use warnings;
use Test::More tests => 5;

use Mail::DKIM::Verifier;
$Mail::DKIM::DNS::TIMEOUT = 3;

#
# this public key exists
#
my $pubkey = Mail::DKIM::PublicKey->fetch(
		Protocol => "dns",
		Selector => "test1",
		Domain => "messiah.edu",
		);
ok($pubkey, "public key exists");

#
# this public key is "NXDOMAIN"
#
$pubkey = Mail::DKIM::PublicKey->fetch(
		Protocol => "dns",
		Selector => "nonexistent",
		Domain => "messiah.edu",
		);
ok(!$pubkey, "public key should not exist");
ok($@ =~ /^NXDOMAIN$/, "reason given is NXDOMAIN");

SKIP:
{
	skip "these tests fail when run on the other side of my firewall", 2
		unless ($ENV{DNS_TESTS} && $ENV{DNS_TESTS} > 1);

$pubkey = eval { Mail::DKIM::PublicKey->fetch(
		Protocol => "dns",
		Selector => "foo",
		Domain => "blackhole.messiah.edu",
		) };
my $E = $@;
print "# got error: $E" if $E;
ok(!$pubkey
	&& $E && $E =~ /(timeout|timed? out)/,
	"timeout error fetching public key");

$pubkey = eval { Mail::DKIM::PublicKey->fetch(
		Protocol => "dns",
		Selector => "foo",
		Domain => "blackhole2.messiah.edu",
		) };
$E = $@;
print "# got error: $E" if $E;
ok(!$pubkey
	&& $E && $E =~ /SERVFAIL/,
	"SERVFAIL dns error fetching public key");
}