~ubuntu-branches/ubuntu/quantal/libmail-dkim-perl/quantal

« back to all changes in this revision

Viewing changes to t/signer_dk.t

  • Committer: Bazaar Package Importer
  • Author(s): Magnus Holmgren
  • Date: 2011-02-06 18:59:40 UTC
  • mfrom: (2.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20110206185940-8qumurv3358gozoz
Tags: 0.39-1
* New upstream release.
* debian/copyright: Updated.
* Add Breaks: dkimproxy (<< 1.2-1) along with the Replaces: from 0.37-1.
* Add ${misc:Depends} to Depends: just in case and to silence Lintian.
* Up Standards-Version to 3.9.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -I../lib
 
2
 
 
3
use strict;
 
4
use warnings;
 
5
use Test::Simple tests => 8;
 
6
 
 
7
use Mail::DKIM::Signer;
 
8
use Mail::DKIM::DkSignature;
 
9
 
 
10
# The main purpose of this set of tests is to ensure that I am aware
 
11
# whenever a change in my code causes the generated signature to change
 
12
# for DomainKeys signatures. Generally this should never occur for a
 
13
# change in DomainKeys code. (In contrast to DKIM, where the generated
 
14
# signature gets included in the signature, so any changes to the format
 
15
# of the signature will cause the hash to change.)
 
16
 
17
 
 
18
{
 
19
my %sig_args;
 
20
my $policyfn = sub {
 
21
                my $signer = shift;
 
22
                if ($sig_args{Headers} && $sig_args{Headers} eq "*")
 
23
                {
 
24
                        $sig_args{Headers} = $signer->headers;
 
25
                }
 
26
                $signer->add_signature(Mail::DKIM::DkSignature->new(%sig_args));
 
27
                return;
 
28
        };
 
29
my $tdir = -f "t/test.key" ? "t" : ".";
 
30
my $keyfile = "$tdir/test.key";
 
31
my $sample_email = <<END_OF_SAMPLE;
 
32
From: jason <jlong\@messiah.edu>
 
33
Subject: hi there
 
34
Comment: what is a comment
 
35
 
 
36
this is a sample message
 
37
END_OF_SAMPLE
 
38
$sample_email =~ s/\n/\015\012/gs;
 
39
 
 
40
sub sign_sample_using_args
 
41
{
 
42
        %sig_args = (
 
43
                Algorithm => "rsa-sha1",
 
44
                Selector => "test8",
 
45
                Domain => "messiah.edu",
 
46
                @_,
 
47
                );
 
48
        my $dkim = Mail::DKIM::Signer->new(
 
49
                Policy => $policyfn,
 
50
                KeyFile => $keyfile,
 
51
                );
 
52
$dkim->PRINT($sample_email);
 
53
$dkim->CLOSE;
 
54
 
 
55
my $signature = $dkim->signature;
 
56
return $signature;
 
57
}
 
58
}
 
59
 
 
60
my $signature;
 
61
$signature = sign_sample_using_args(
 
62
                Method => "simple",
 
63
                );
 
64
ok($signature, "signature() works");
 
65
print "# " . $signature->as_string . "\n";
 
66
ok($signature->data =~ /^TL93PzPvedAijHChCAt/, "got expected signature");
 
67
 
 
68
 
 
69
$signature = sign_sample_using_args(
 
70
                Method => "simple",
 
71
                Headers => "*",
 
72
                );
 
73
ok($signature, "signature() works");
 
74
print "# " . $signature->as_string . "\n";
 
75
ok($signature->data =~ /^n\+qfVkhQPch80atOC7/, "got expected signature");
 
76
 
 
77
$signature = sign_sample_using_args(
 
78
                Method => "nofws",
 
79
                );
 
80
ok($signature, "signature() works");
 
81
print "# " . $signature->as_string . "\n";
 
82
ok($signature->data =~ /^JWzIzvCZBIYnoMebzKU/, "got expected signature");
 
83
 
 
84
 
 
85
$signature = sign_sample_using_args(
 
86
                Method => "nofws",
 
87
                Headers => "*",
 
88
                );
 
89
ok($signature, "signature() works");
 
90
print "# " . $signature->as_string . "\n";
 
91
ok($signature->data =~ /^fkDC8iF/, "got expected signature");
 
92