address: added tests for canonify
This commit is contained in:
parent
3273abb25e
commit
2aaedbb445
@ -190,7 +190,9 @@ sub canonify {
|
|||||||
my ($dummy, $path) = @_;
|
my ($dummy, $path) = @_;
|
||||||
|
|
||||||
# strip delimiters
|
# strip delimiters
|
||||||
return if $path !~ /^<(.*)>$/;
|
if ($path !~ /^<(.*)>$/) {
|
||||||
|
return undef, undef, 'missing delimiters'; ## no critic (undef)
|
||||||
|
};
|
||||||
$path = $1;
|
$path = $1;
|
||||||
|
|
||||||
my $domain = $domain_expr || "$subdomain_expr(?:\.$subdomain_expr)*";
|
my $domain = $domain_expr || "$subdomain_expr(?:\.$subdomain_expr)*";
|
||||||
@ -204,18 +206,22 @@ sub canonify {
|
|||||||
$path =~ s/^\@$domain(?:,\@$domain)*://;
|
$path =~ s/^\@$domain(?:,\@$domain)*://;
|
||||||
|
|
||||||
# empty path is ok
|
# empty path is ok
|
||||||
return '' if $path eq '';
|
if ($path eq '') {
|
||||||
|
return '', undef, 'empty path';
|
||||||
|
};
|
||||||
|
|
||||||
# bare postmaster is permissible, perl RFC-2821 (4.5.1)
|
# bare postmaster is permissible, perl RFC-2821 (4.5.1)
|
||||||
if ( $path =~ m/^postmaster$/i ) {
|
if ( $path =~ m/^postmaster$/i ) {
|
||||||
return 'postmaster';
|
return 'postmaster', undef, 'bare postmaster';
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($localpart, $domainpart) = ($path =~ /^(.*)\@($domain)$/);
|
my ($localpart, $domainpart) = ($path =~ /^(.*)\@($domain)$/);
|
||||||
return if !defined $localpart;
|
if (!defined $localpart) {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
if ($localpart =~ /^$atom_expr(\.$atom_expr)*/) {
|
if ($localpart =~ /^$atom_expr(\.$atom_expr)*/) {
|
||||||
return $localpart, $domainpart; # simple case, we are done
|
return $localpart, $domainpart, 'local matches atom'; # simple case, we are done
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($localpart =~ /^"(($qtext_expr|\\$text_expr)*)"$/) {
|
if ($localpart =~ /^"(($qtext_expr|\\$text_expr)*)"$/) {
|
||||||
@ -223,7 +229,7 @@ sub canonify {
|
|||||||
$localpart =~ s/\\($text_expr)/$1/g;
|
$localpart =~ s/\\($text_expr)/$1/g;
|
||||||
return $localpart, $domainpart;
|
return $localpart, $domainpart;
|
||||||
}
|
}
|
||||||
return;
|
return undef, undef, 'fall through'; ## no critic (undef)
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse {
|
sub parse {
|
||||||
|
@ -17,6 +17,7 @@ BEGIN {
|
|||||||
__new();
|
__new();
|
||||||
__config();
|
__config();
|
||||||
__parse();
|
__parse();
|
||||||
|
__canonify();
|
||||||
|
|
||||||
done_testing();
|
done_testing();
|
||||||
|
|
||||||
@ -186,3 +187,26 @@ sub __config {
|
|||||||
is($sender->config($_->{pref}), $_->{expected}, $_->{descr});
|
is($sender->config($_->{pref}), $_->{expected}, $_->{descr});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub __canonify {
|
||||||
|
|
||||||
|
my $as = 'foo@x.example.com';
|
||||||
|
my $ao = Qpsmtpd::Address->new($as);
|
||||||
|
ok( ! defined $Qpsmtpd::Address::domain_expr, "domain_expr is undef");
|
||||||
|
ok( $Qpsmtpd::Address::subdomain_expr, "subdomain_expr is defined, $Qpsmtpd::Address::subdomain_expr");
|
||||||
|
|
||||||
|
my @r = Qpsmtpd::Address->canonify('sample@path');
|
||||||
|
is_deeply(\@r, [ undef, undef, "missing delimiters" ], 'canonify, missing delimiters');
|
||||||
|
|
||||||
|
@r = Qpsmtpd::Address->canonify('');
|
||||||
|
is_deeply(\@r, [ undef, undef, "missing delimiters" ], 'canonify, empty path');
|
||||||
|
|
||||||
|
@r = Qpsmtpd::Address->canonify('<postmaster>');
|
||||||
|
is_deeply(\@r, [ 'postmaster', undef, "bare postmaster" ], 'canonify, bare postmaster');
|
||||||
|
|
||||||
|
@r = Qpsmtpd::Address->canonify('<postmaster@test>');
|
||||||
|
is_deeply(\@r, [ 'postmaster', 'test', 'local matches atom' ], 'canonify, postmaster@test');
|
||||||
|
|
||||||
|
@r = Qpsmtpd::Address->canonify('<postmáster@test>');
|
||||||
|
is_deeply(\@r, [ 'postmáster', 'test', 'local matches atom' ], 'canonify, postmáster@test, local matches atom');
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user