DRI/Protocol/EPP/Extensions/Keygroup.pm

filter: Statementstmt 11.4% 13 / 114 Branchbran 0.0% 0 / 40 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 25.0% 4 / 16 Podpod 0.0% 0 / 12 totaltotal 8.5% 17 / 200 CC 31 SCAR 36.2
CC
31
Cov
8%
build_command
72.0
format_key
56.0
check_parse
42.0
CRAP 37.3
« DRI/Protocol/ResultStatus.pm ↑ Summary DRI/Protocol/EPP/Core/Status.pm »
1 ## Domain Registry Interface, EURid/DNSBE Keygroup EPP Extension
2 ##
3 ## Copyright (c) 2010,2013-2014,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::Keygroup;
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  
20 1 ▶use Net::DRI::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use Net::DRI::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 ####################################################################################################
24  
25 sub register_commands
26 0 ▶{
Subroutine register_commands: not called CC=1 SCAR=6.9
Pod undocumented
27 0 my ($class,$version)=@_;
28 0 my %tmp=( create => [ \&create, undef ],
29 check => [ \&check, \&check_parse ],
30 info => [ \&info, \&info_parse ],
31 delete => [ \&delete, undef ],
32 update => [ \&update, undef ],
33 );
34  
35 0 $tmp{check_multi}=$tmp{check};
36 0 return { 'keygroup' => \%tmp };
37 }
38  
39 0 ▶sub capabilities_add { return ('keygroup_update','keys',['set']); }
Subroutine capabilities_add: not called CC=1 SCAR=6.9
Pod undocumented
40  
41 sub setup
42 0 ▶{
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ($class,$po,$version)=@_;
44 0 $po->ns({ 'keygroup' => 'http://www.eurid.eu/xml/epp/keygroup-1.0' });
45 0 return;
46 }
47  
48 sub build_command
49 0 ▶{
Subroutine build_command: not called CC=8 SCAR=42.8
Pod undocumented
50 0 my ($epp,$msg,$command,$names)=@_;
51  
52 0 my @gn;
53 0 ▶ foreach my $h ( grep { defined } (ref $names eq 'ARRAY')? @$names : ($names))
Branch: 1 branch
BranchTrueFalseTotal
ref $names eq 'ARRAY' ? : 0 0 0
54 {
55 0 ▶ Net::DRI::Exception->die(1,'protocol/EPP',10,'Invalid Keygroup name: '.$h) unless (defined $h && length $h && ! ref $h && Net::DRI::Util::xml_is_token($h,1,100));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h and length $h and not ref $h and Net::DRI::Util::xml_is_token($h, 1, 100) 0 0 0
Condition0%0/9
defined $h and length $h and not ref $h and Net::DRI::Util::xml_is_token($h, 1, 100)
!ll&&!rl&&r
000
defined $h and length $h and not ref $h
!ll&&!rl&&r
000
defined $h and length $h
!ll&&!rl&&r
000
MC/DC0%0/4
defined $h and length $h and not ref $h and Net::DRI::Util::xml_is_token($h, 1, 100)
defined $h length $h not ref $h Net::DRI::Util::xml_is_token($h, 1, 100)
Truth table0%0/5
A and B and not(C) and D
A= defined $hB= length $hC= not ref $hD= Net::DRI::Util::xml_is_token($h, 1, 100)
ABCDresult
0XXX0
10XX0
110X0
11100
11111
56 0 push @gn,$h;
57 }
58  
59 0 ▶ Net::DRI::Exception->die(1,'protocol/EPP',2,'Keygroup name needed') unless @gn;
Branch: 1 branch
BranchTrueFalseTotal
unless @gn 0 0 0
60  
61 0 $msg->command([$command,'keygroup:'.$command, $msg->nsattrs('keygroup')]);
62 0 return map { ['keygroup:name',$_] } @gn;
63 }
64  
65 ## The hash keys names are modeled on those used for the secDNS extension.
66 sub format_key
67 0 ▶{
Subroutine format_key: not called CC=7 SCAR=40.3
Pod undocumented
68 0 my $e=shift;
69  
70 0 my @mk=grep { ! Net::DRI::Util::has_key($e,$_) } qw/keyTag flags protocol alg pubKey/;
71 0 ▶ Net::DRI::Exception::usererr_insufficient_parameters('Attributes missing: '.join(@mk)) if @mk;
Branch: 1 branch
BranchTrueFalseTotal
if @mk 0 0 0
72 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('keyTag must be 16-bit unsigned integer: '.$e->{keyTag}) unless Net::DRI::Util::verify_ushort($e->{keyTag});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_ushort($e->{"keyTag"}) 0 0 0
73 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('flags mut be a 16-bit unsigned integer: '.$e->{flags}) unless Net::DRI::Util::verify_ushort($e->{flags});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_ushort($e->{"flags"}) 0 0 0
74 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('protocol must be an unsigned byte: '.$e->{protocol}) unless Net::DRI::Util::verify_ubyte($e->{protocol});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_ubyte($e->{"protocol"}) 0 0 0
75 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('alg must be an unsigned byte: '.$e->{alg}) unless Net::DRI::Util::verify_ubyte($e->{alg});
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_ubyte($e->{"alg"}) 0 0 0
76 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('pubKey must be a non empty base64 string: '.$e->{pubKey}) unless Net::DRI::Util::verify_base64($e->{pubKey},1);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::verify_base64($e->{"pubKey"}, 1) 0 0 0
77  
78 0 my @c;
79 0 push @c,['keygroup:keyTag',$e->{keyTag}];
80 0 push @c,['keygroup:flags',$e->{flags}];
81 0 push @c,['keygroup:protocol',$e->{protocol}];
82 0 push @c,['keygroup:algorithm',$e->{alg}];
83 0 push @c,['keygroup:pubKey',$e->{pubKey}];
84  
85 0 return @c;
86 }
87  
88 ####################################################################################################
89 ########### Query commands
90  
91 sub check
92 0 ▶{
Subroutine check: not called CC=1 SCAR=6.9
Pod undocumented
93 0 my ($epp,$names)=@_;
94 0 my $mes=$epp->message();
95 0 my @d=build_command($epp,$mes,'check',$names);
96 0 $mes->command_body(\@d);
97 0 return;
98 }
99  
100 sub check_parse
101 0 ▶{
Subroutine check_parse: not called CC=6 SCAR=37.4
Pod undocumented
102 0 my ($po,$otype,$oaction,$oname,$rinfo)=@_;
103 0 my $mes=$po->message();
104 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
105  
106 0 my $chkdata=$mes->get_response('keygroup', 'chkData');
107 0 ▶ return unless defined $chkdata;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chkdata 0 0 0
108  
109 0 foreach my $cd ($chkdata->getChildrenByTagNameNS($mes->ns('keygroup'), 'cd'))
110 {
111 0 foreach my $el (Net::DRI::Util::xml_list_children($cd))
112 {
113 0 my ($n,$c)=@$el;
114 0 ▶ if ($n eq 'name')
Branch: 1 branch
BranchTrueFalseTotal
if ($n eq "name") 0 0 0
115 {
116 0 my $kg=$c->textContent();
117 0 $rinfo->{keygroup}->{$kg}->{exist}=1-Net::DRI::Util::xml_parse_boolean($c->getAttribute('avail'));
118 0 $rinfo->{keygroup}->{$kg}->{action}='check';
119 }
120 }
121 }
122 0 return;
123 }
124  
125 sub info
126 0 ▶{
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
127 0 my ($epp,$name)=@_;
128 0 my $mes=$epp->message();
129 0 my @d=build_command($epp,$mes,'info',$name);
130 0 $mes->command_body(\@d);
131 0 return;
132 }
133  
134 sub info_parse
135 0 ▶{
Subroutine info_parse: not called CC=6 SCAR=37.4
Pod undocumented
136 0 my ($po,$otype,$oaction,$oname,$rinfo)=@_;
137 0 my $mes=$po->message();
138 0 ▶ return unless $mes->is_success();
Branch: 1 branch
BranchTrueFalseTotal
unless $mes->is_success 0 0 0
139  
140 0 my $ns=$mes->ns('keygroup');
141 0 my $infdata=$mes->get_response('keygroup', 'infData');
142 0 ▶ return unless defined $infdata;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $infdata 0 0 0
143  
144 0 my @k;
145 0 foreach my $el (Net::DRI::Util::xml_list_children($infdata))
146 {
147 0 my ($name,$c)=@$el;
148 0 ▶ if ($name eq 'name')
Branch: 2 branches
BranchTrueFalseTotal
if ($name eq 'name') { } 0 0 0
elsif ($name eq 'key') { } 0 0 0
149 {
150 0 $oname=$c->textContent();
151 0 $rinfo->{keygroup}->{$oname}->{exist}=1;
152 0 $rinfo->{keygroup}->{$oname}->{action}='info';
153 } elsif ($name eq 'key')
154 {
155 0 push @k,{ keyTag => Net::DRI::Util::xml_child_content($c,$ns,'keyTag'),
156 flags => Net::DRI::Util::xml_child_content($c,$ns,'flags'),
157 protocol =>Net::DRI::Util::xml_child_content($c,$ns,'protocol') ,
158 alg => Net::DRI::Util::xml_child_content($c,$ns,'algorithm'),
159 pubKey => Net::DRI::Util::xml_child_content($c,$ns,'pubKey'),
160 };
161 }
162 }
163  
164 0 $rinfo->{keygroup}->{$oname}->{'keys'}=\@k;
165 0 return;
166 }
167  
168 ############ Transform commands
169  
170 sub create
171 0 ▶{
Subroutine create: not called CC=4 SCAR=30.0
Pod undocumented
172 0 my ($epp,$name,$rd)=@_;
173 0 my $mes=$epp->message();
174 0 my @d=build_command($epp,$mes,'create',$name);
175 0 ▶ if (Net::DRI::Util::has_key($rd,'keys'))
Branch: 1 branch
BranchTrueFalseTotal
if (Net::DRI::Util::has_key($rd, "keys")) 0 0 0
176 {
177 0 ▶ Net::DRI::Exception::usererr_invalid_parameters('secdns key must be a ref array') unless ref $rd->{'keys'} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $rd->{"keys"} eq "ARRAY" 0 0 0
178 0 foreach my $k (@{$rd->{'keys'}})
179 {
180 0 push @d,['keygroup:key',format_key($k)];
181 }
182 }
183 0 $mes->command_body(\@d);
184 0 return;
185 }
186  
187 sub delete ## no critic (Subroutines::ProhibitBuiltinHomonyms)
188 0 ▶{
Subroutine delete: not called CC=1 SCAR=6.9
Pod undocumented
189 0 my ($epp,$name)=@_;
190 0 my $mes=$epp->message();
191 0 my @d=build_command($epp,$mes,'delete',$name);
192 0 $mes->command_body(\@d);
193 0 return;
194 }
195  
196 sub update
197 0 ▶{
Subroutine update: not called CC=5 SCAR=34.0
Pod undocumented
198 0 my ($epp,$name,$todo,$rd)=@_;
199 0 ▶ Net::DRI::Exception::usererr_invalid_parameters($todo.' must be a Net::DRI::Data::Changes object') unless Net::DRI::Util::isa_changes($todo);
Branch: 1 branch
BranchTrueFalseTotal
unless Net::DRI::Util::isa_changes($todo) 0 0 0
200  
201 0 ▶ if ((grep { ! /^(?:keys)$/ } $todo->types()) || (grep { ! /^(?:set)$/ } $todo->types('keys') ))
Branch: 1 branch
BranchTrueFalseTotal
if (grep {not /^(?:keys)$/;} $todo->types or grep {not /^(?:set)$/;} $todo->types("keys")) 0 0 0
Condition0%0/3
grep {not /^(?:keys)$/;} $todo->types or grep {not /^(?:set)$/;} $todo->types("keys")
l!l&&r!l&&!r
000
MC/DC0%0/2
grep {not /^(?:keys)$/;} $todo->types or grep {not /^(?:set)$/;} $todo->types("keys")
grep {not /^(?:keys)$/;} $todo->types grep {not /^(?:set)$/;} $todo->types("keys")
Truth table0%0/3
A or B
A= grep {not /^(?:keys)$/;} $todo->typesB= grep {not /^(?:set)$/;} $todo->types("keys")
ABresult
1X1
011
000
202 {
203 0 Net::DRI::Exception->die(0,'protocol/EPP',11,'Only keys set available for keygroup');
204 }
205  
206 0 my $mes=$epp->message();
207 0 my @d=build_command($epp,$mes,'update',$name);
208 0 foreach my $k (@{$todo->set('keys')})
209 {
210 0 push @d,['keygroup:key',format_key($k)];
211 }
212 0 $mes->command_body(\@d);
213 0 return;
214 }
215  
216 ####################################################################################################
217 1 1;
218  
219 __END__
« DRI/Protocol/ResultStatus.pm ↑ Summary DRI/Protocol/EPP/Core/Status.pm »