DRI/Protocol/EPP/Extensions/Validate.pm

filter: Statementstmt 22.6% 19 / 84 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 19 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 5 totaltotal 14.5% 25 / 172 CC 33 SCAR 58.9
CC
33
Cov
13%
check
600.0
check_parse
110.0
register_commands
2.0
CRAP 360.7
« DRI/Protocol/Whois/Domain/common.pm ↑ Summary DRI/Protocol/EPP/Extensions/PRO/AV.pm »
1 ## Validate Mapping for the Extensible Provisioning Protocol (draft-ietf-regext-validate-04)
2 ##
3 ## Copyright (c) 2018 Patrick Mevzek <netdri@dotandco.com>. All rights reserved.
4 ##
5 ## This file is part of Net::DRI
6 ##
7 ## Net::DRI is free software; you can redistribute it and/or modify
8 ## it under the terms of the GNU General Public License as published by
9 ## the Free Software Foundation; either version 2 of the License, or
10 ## (at your option) any later version.
11 ##
12 ## See the LICENSE file that comes with this distribution for more details.
13 ####################################################################################################
14  
15 package Net::DRI::Protocol::EPP::Extensions::Validate;
16  
17 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Net::DRI::Protocol::EPP::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 ####################################################################################################
26  
27 sub register_commands
28 {
29 0 ▶ my ($class,$version)=@_;
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
30  
31 0 state $cmds = { 'contact' => { 'validate' => [ \&check, \&check_parse ] } };
32 0 return $cmds;
33 }
34  
35 sub setup
36 {
37 0 ▶ my ($class,$po,$version)=@_;
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
38  
39 0 state $ns = { 'validate' => 'urn:ietf:params:xml:ns:validate-0.2' };
40 0 $po->ns($ns);
41 0 return;
42 }
43  
44 0 ▶sub implements { return 'https://tools.ietf.org/html/draft-ietf-regext-validate-04'; }
Subroutine implements: not called CC=1 SCAR=6.9
Pod undocumented
45  
46 ####################################################################################################
47  
48 sub check
49 {
50 0 ▶ my ($epp, $contact) = @_;
Subroutine check: not called CC=24 SCAR=64.0
Pod undocumented
51 0 my $mes = $epp->message();
52  
53 0 my @contacts;
54 0 ▶ foreach my $cd (ref $contact eq 'ARRAY' ? @$contact : ($contact))
Branch: 1 branch
BranchTrueFalseTotal
ref $contact eq 'ARRAY' ? : 0 0 0
55 {
56 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('"type" key must exist and its content be an XML token from 1 to 255 characters') unless Net::DRI::Util::has_key($cd, 'type') && Net::DRI::Util::xml_is_token($cd->{type}, 1, 255);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($cd, "type") and Net::DRI::Util::xml_is_token($cd->{"type"}, 1, 255) 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($cd, "type") and Net::DRI::Util::xml_is_token($cd->{"type"}, 1, 255)
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($cd, "type") and Net::DRI::Util::xml_is_token($cd->{"type"}, 1, 255)
Net::DRI::Util::has_key($cd, "type") Net::DRI::Util::xml_is_token($cd->{"type"}, 1, 255)
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($cd, "type")B= Net::DRI::Util::xml_is_token($cd->{"type"}, 1, 255)
ABresult
0X0
100
111
57 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('"zone" key must exist and its content be an XML token from 1 to 255 characters') unless Net::DRI::Util::has_key($cd, 'zone') && Net::DRI::Util::xml_is_token($cd->{zone}, 1, 255);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($cd, "zone") and Net::DRI::Util::xml_is_token($cd->{"zone"}, 1, 255) 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($cd, "zone") and Net::DRI::Util::xml_is_token($cd->{"zone"}, 1, 255)
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($cd, "zone") and Net::DRI::Util::xml_is_token($cd->{"zone"}, 1, 255)
Net::DRI::Util::has_key($cd, "zone") Net::DRI::Util::xml_is_token($cd->{"zone"}, 1, 255)
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($cd, "zone")B= Net::DRI::Util::xml_is_token($cd->{"zone"}, 1, 255)
ABresult
0X0
100
111
58 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('"contact" key must exist and its content be a Net::DRI contact object') unless Net::DRI::Util::has_key($cd, 'contact') && Net::DRI::Util::isa_contact($cd->{contact});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::has_key($cd, "contact") and Net::DRI::Util::isa_contact($cd->{"contact"}) 0 0 0
Condition0%0/3
Net::DRI::Util::has_key($cd, "contact") and Net::DRI::Util::isa_contact($cd->{"contact"})
!ll&&!rl&&r
000
MC/DC0%0/2
Net::DRI::Util::has_key($cd, "contact") and Net::DRI::Util::isa_contact($cd->{"contact"})
Net::DRI::Util::has_key($cd, "contact") Net::DRI::Util::isa_contact($cd->{"contact"})
Truth table0%0/3
A and B
A= Net::DRI::Util::has_key($cd, "contact")B= Net::DRI::Util::isa_contact($cd->{"contact"})
ABresult
0X0
100
111
59  
60 0 my $co = $cd->{'contact'};
61 0 my @c;
62 0 ▶ my $id = $co->srid() // '';
Condition0%0/2
$co->srid // ""
l!l
00
MC/DC0%0/1
$co->srid // ""
$co->srid
Truth table0%0/2
A
A= $co->srid
Aresult
11
00
63 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('Contact ID must be defined and be a token from 3 to 16 characters') unless Net::DRI::Util::xml_is_token($id, 3, 16);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($id, 3, 16) 0 0 0
64 0 push @c, ['validate:id', $id];
65  
66 0 ▶ if (grep { defined } map { $co->$_() } qw/name org street city sp pc cc/)
Branch: 1 branch
BranchTrueFalseTotal
if (grep {defined $_;} map({$co->$_;} "name", "org", "street", "city", "sp", "pc", "cc")) 0 0 0
67 {
68 # We allow only one postalInfo
69 0 my ($pi, @pi) = Net::DRI::Protocol::EPP::Util::build_postalinfo($co, $epp->{contacti18n});
70 0 $pi->[0] = 'validate:postalInfo';
71 0 push @c, $pi;
72 }
73 0 ▶ push @c, Net::DRI::Protocol::EPP::Util::build_tel('validate:voice', $co->voice()) if defined $co->voice();
Branch: 1 branch
BranchTrueFalseTotal
if defined $co->voice 0 0 0
74 0 ▶ push @c, Net::DRI::Protocol::EPP::Util::build_tel('validate:fax', $co->fax()) if defined $co->fax();
Branch: 1 branch
BranchTrueFalseTotal
if defined $co->fax 0 0 0
75 0 ▶ push @c, ['validate:email', $co->email()] if defined $co->email();
Branch: 1 branch
BranchTrueFalseTotal
if defined $co->email 0 0 0
76 0 my $az = $co->auth();
77 0 ▶ push @c, ['validate:authInfo', ['contact:pw', $az->{pw}]] if defined $az && ref $az eq 'HASH' && exists $az->{pw};
Branch: 1 branch
BranchTrueFalseTotal
if defined $az and ref $az eq "HASH" and exists $az->{"pw"} 0 0 0
Condition0%0/6
defined $az and ref $az eq "HASH" and exists $az->{"pw"}
!ll&&!rl&&r
000
defined $az and ref $az eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/3
defined $az and ref $az eq "HASH" and exists $az->{"pw"}
defined $az ref $az eq "HASH" exists $az->{"pw"}
Truth table0%0/4
A and B and C
A= defined $azB= ref $az eq "HASH"C= exists $az->{"pw"}
ABCresult
0XX0
10X0
1100
1111
78  
79 0 ▶ if (Net::DRI::Util::has_key($cd, 'kv'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($cd, "kv")) 0 0 0
80 {
81 # contactType probably not needed here?
82 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('"kv" data element must be a ref hash') unless ref $cd->{kv} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $cd->{"kv"} eq "HASH" 0 0 0
83 0 my @kvs;
84 0 foreach my $key (sort { $a cmp $b } keys %{$cd->{kv}})
85 {
86 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('KV key content must be an XML token of at least 1 character') unless Net::DRI::Util::xml_is_token($key, 1);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($key, 1) 0 0 0
87 0 my $value = $cd->{kv}->{$key};
88 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('KV value content must be an XML token') unless Net::DRI::Util::xml_is_token($value);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::xml_is_token($value) 0 0 0
89 0 push @kvs, ['validate:kv', { key => $key, value => $value }];
90 }
91 0 ▶ push @c, @kvs if @kvs;
Branch: 1 branch
BranchTrueFalseTotal
if @kvs 0 0 0
92 }
93 0 push @contacts, ['validate:contact', { contactType => $cd->{type}, tld => $cd->{zone}}, @c];
94 }
95  
96 0 $mes->command(['check', 'validate:check', $mes->nsattrs('validate')]);
97 0 $mes->command_body(\@contacts);
98 0 return;
99 }
100  
101 sub check_parse
102 {
103 0 ▶ my ($po, $otype, $oaction, $oname, $rinfo)=@_;
Subroutine check_parse: not called CC=10 SCAR=47.0
Pod undocumented
104 0 my $mes = $po->message();
105 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
106  
107 0 my $chkdata = $mes->get_response('validate', 'chkData');
108 0 ▶ return unless defined $chkdata;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chkdata 0 0 0
109  
110 0 foreach my $cd ($chkdata->getChildrenByTagNameNS($mes->ns('validate'), 'cd'))
111 {
112 0 my $contact;
113 my %kvs;
114 0 foreach my $el (Net::DRI::Util::xml_list_children($cd))
115 {
116 0 my ($name, $node) = @$el;
117 0 ▶ if ($name eq 'id')
Branch: 3 branches
BranchTrueFalseTotal
if ($name eq 'id') { } 0 0 0
elsif ($name eq 'response') { } 0 0 0
elsif ($name eq 'kv') { } 0 0 0
118 {
119 0 $contact = $node->textContent();
120 0 $rinfo->{contact}->{$contact}->{action} = 'validate';
121 } elsif ($name eq 'response')
122 {
123 0 $rinfo->{contact}->{$contact}->{validate} = { response => $node->textContent() };
124 } elsif ($name eq 'kv')
125 {
126 0 my $key = $node->getAttribute('key');
127 0 my $value = $node->getAttribute('value');
128 0 my $type = $node->getAttribute('contactType'); # optional
129 0 ▶ $rinfo->{contact}->{$contact}->{validate}->{$key} //= {};
Condition0%0/2
$rinfo->{"contact"}{$contact}{"validate"}{$key} //= {}
l!l
00
MC/DC0%0/1
$rinfo->{"contact"}{$contact}{"validate"}{$key} //= {}
$rinfo->{"contact"}{$contact}{"validate"}{$key}
Truth table0%0/2
A
A= $rinfo->{"contact"}{$contact}{"validate"}{$key}
Aresult
11
00
130 0 ▶ $rinfo->{contact}->{$contact}->{validate}->{$key}->{defined $type ? lc $type : '*'} = $value;
Branch: 1 branch
BranchTrueFalseTotal
defined $type ? : 0 0 0
131 }
132 }
133 }
134  
135 0 return;
136 }
137  
138 ####################################################################################################
139 1 1;
140  
141 __END__
142  
143 =pod
144  
145 =head1 NAME
146  
147 Net::DRI::Protocol::EPP::Extensions::DNAME - EPP Mapping for validation of contact data (draft-ietf-regext-validate-04) for Net::DRI
148  
149 =head1 DESCRIPTION
150  
151 Please see the README file for details.
152  
153 =head1 SUPPORT
154  
155 For now, support questions should be sent to:
156  
157 E<lt>netdri@dotandco.comE<gt>
158  
159 Please also see the SUPPORT file in the distribution.
160  
161 =head1 SEE ALSO
162  
163 E<lt>http://www.dotandco.com/services/software/Net-DRI/E<gt>
164  
165 =head1 AUTHOR
166  
167 Patrick Mevzek, E<lt>netdri@dotandco.comE<gt>
168  
169 =head1 COPYRIGHT
170  
171 Copyright (c) 2018 Patrick Mevzek <netdri@dotandco.com>.
172 All rights reserved.
173  
174 This program is free software; you can redistribute it and/or modify
175 it under the terms of the GNU General Public License as published by
176 the Free Software Foundation; either version 2 of the License, or
177 (at your option) any later version.
178  
179 See the LICENSE file that comes with this distribution for more details.
180  
181 =cut
« DRI/Protocol/Whois/Domain/common.pm ↑ Summary DRI/Protocol/EPP/Extensions/PRO/AV.pm »