Keycloak/Admin.pm

filter: Statementstmt 96.7% 205 / 212 Branchbran 84.4% 49 / 58 Conditioncond 66.6% 26 / 39 MC/DCmcdc 45.0% 9 / 20 Subroutinesub 94.7% 90 / 95 Podpod 96.3% 53 / 55 totaltotal 90.1% 432 / 479 CC 48 SCAR 11.2
CC
48
Cov
91%
export_realm
12.0
call
9.1
ensure_protocol_mapper
7.2
CRAP 3.1
« Keycloak/OIDC.pm ↑ Summary Keycloak/Error/API.pm »
1 package WWW::Keycloak::Admin;
2  
3 # ABSTRACT: Keycloak Admin REST API for one realm, with idempotent ensure methods
4  
5 6 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 with 'WWW::Keycloak::Role::HTTP';
7 6 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶use Types::Standard qw( InstanceOf Str );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶use URI::Escape qw( uri_escape_utf8 );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use WWW::Keycloak::Diff;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use WWW::Keycloak::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use WWW::Keycloak::Error::Validation;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 6 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 our $VERSION = '0.001';
16  
17  
18 6 has base_url => (
19 is => 'ro',
20 isa => Str,
21 required => 1
22 );
23  
24  
25 6 has realm => (
26 is => 'ro',
27 isa => Str,
28 required => 1
29 );
30  
31  
32 6 has ua => (
33 is => 'ro',
34 isa => InstanceOf['LWP::UserAgent'],
35 required => 1
36 );
37  
38  
39 6 has auth => (
40 is => 'ro',
41 isa => InstanceOf['WWW::Keycloak::Auth'],
42 predicate => 'has_auth'
43 );
44  
45  
46 18 ▶sub diff_class { 'WWW::Keycloak::Diff' }
Subroutine diff_class: called CC=1 SCAR=0.0
Pod undocumented
47  
48 #### transport
49  
50 114 ▶sub realm_url { $_[0]->base_url.'/admin/realms/'.uri_escape_utf8( $_[0]->realm ) }
Subroutine realm_url: called CC=1 SCAR=0.0
Pod undocumented
51  
52 119 ▶sub call {
Subroutine call: called CC=9 SCAR=22.1
Pod documented
53 119 my ( $self, $method, $path, $body ) = @_;
54 119 ▶ my $url = $path =~ m{\A/admin/} ? $self->base_url.$path : $self->realm_url.$path;
Branch: 1 branch
BranchTrueFalseTotal
$path =~ m[\A/admin/] ? : 5 114 119
55 119 ▶ WWW::Keycloak::Error::Validation->throw( message => 'the Admin API needs credentials: give username and password, client_id and client_secret, or token' )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_auth 1 118 119
56 unless $self->has_auth;
57 118 ▶ my %arg = defined $body ? ( json => $body ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $body ? : 38 80 118
58 118 my $bearer = $self->auth->token; # outside the eval: a failed login is not a refused token
59 117 my $result = eval { $self->send_request( $method, $url, %arg, bearer => $bearer ) };
60 117 ▶ if ( my $error = $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $error = $@) 8 109 117
61 8 ▶ die $error unless blessed $error && $error->isa('WWW::Keycloak::Error::API') && $error->is_unauthorized && $self->auth->renewable;
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable 6 2 8
Condition66%6/9
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable
!ll&&!rl&&r
512
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized
!ll&&!rl&&r
053
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API")
!ll&&!rl&&r
008
MC/DC50%2/4
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_unauthorized and $self->auth->renewable
builtin::blessed($error) $error->isa("WWW::Keycloak::Error::API") $error->is_unauthorized $self->auth->renewable
Truth table60%3/5
A and B and C and D
A= builtin::blessed($error)B= $error->isa("WWW::Keycloak::Error::API")C= $error->is_unauthorizedD= $self->auth->renewable
ABCDresult
0XXX0
10XX0
110X0
11100
11111
62 2 $self->auth->invalidate;
63 2 $result = $self->send_request( $method, $url, %arg, bearer => $self->auth->token );
64 }
65 110 return $result;
66 }
67  
68  
69 74 ▶sub _data { $_[0]->call( @_[ 1 .. $#_ ] )->{data} }
Subroutine _data: called CC=1 SCAR=0.0
70 21 ▶sub _done { $_[0]->call( @_[ 1 .. $#_ ] ); 1 }
Subroutine _done: called CC=1 SCAR=0.0
71 19 ▶sub _create {
Subroutine _create: called CC=3 SCAR=11.0
72 19 my ( $self, $path, $body ) = @_;
73 19 ▶ my $location = $self->call( POST => $path, $body )->{location} // '';
Condition100%2/2
$self->call("POST", $path, $body)->{"location"} // ""
l!l
171
MC/DC100%1/1
$self->call("POST", $path, $body)->{"location"} // ""
$self->call("POST", $path, $body)->{"location"}
Truth table100%2/2
A
A= $self->call("POST", $path, $body)->{"location"}
Aresult
11
00
74 18 my ( $id ) = $location =~ m{/([^/]+)\z};
75 18 ▶ WWW::Keycloak::Error->throw( message => 'POST '.$path.' created something but sent no Location header' ) unless defined $id;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $id 1 17 18
76 17 return $id;
77 }
78 124 ▶sub _esc { uri_escape_utf8( $_[1] ) }
Subroutine _esc: called CC=1 SCAR=0.0
79  
80 23 ▶sub _query {
Subroutine _query: called CC=2 SCAR=6.9
81 23 my ( $self, %query ) = @_;
82 23 ▶ return '' unless %query;
Branch: 1 branch
BranchTrueFalseTotal
unless %query 1 22 23
83 22 return '?'.join '&', map { $self->_esc($_).'='.$self->_esc( $query{$_} ) } sort keys %query;
84 }
85  
86 1 ▶sub _missing {
Subroutine _missing: called CC=4 SCAR=18.9
87 1 my ( $self, $error ) = @_;
88 1 ▶ return 1 if blessed $error && $error->isa('WWW::Keycloak::Error::API') && $error->is_not_found;
Branch: 1 branch
BranchTrueFalseTotal
if builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found 1 0 1
Condition33%2/6
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found
!ll&&!rl&&r
001
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API")
!ll&&!rl&&r
001
MC/DC0%0/3
builtin::blessed($error) and $error->isa("WWW::Keycloak::Error::API") and $error->is_not_found
builtin::blessed($error) $error->isa("WWW::Keycloak::Error::API") $error->is_not_found
Truth table25%1/4
A and B and C
A= builtin::blessed($error)B= $error->isa("WWW::Keycloak::Error::API")C= $error->is_not_found
ABCresult
0XX0
10X0
1100
1111
89 0 die $error;
90 }
91  
92 #### server and realm
93  
94 1 ▶sub server_info { $_[0]->_data( GET => '/admin/serverinfo' ) }
Subroutine server_info: called CC=1 SCAR=0.0
Pod documented
95  
96 14 ▶sub get_realm { $_[0]->_data( GET => '' ) }
Subroutine get_realm: called CC=1 SCAR=0.0
Pod documented
97 2 ▶sub update_realm { $_[0]->_done( PUT => '', $_[1] ) }
Subroutine update_realm: called CC=1 SCAR=0.0
Pod documented
98 0 ▶sub delete_realm { $_[0]->_done( DELETE => '' ) }
Subroutine delete_realm: not called CC=1 SCAR=6.9
Pod documented
99  
100 4 ▶sub create_realm {
Subroutine create_realm: called CC=2 SCAR=6.9
Pod documented
101 4 my ( $self, $rep ) = @_;
102 4 ▶ $self->call( POST => '/admin/realms', { realm => $self->realm, %{ $rep || {} } } );
Condition100%2/2
$rep || {}
l!l
31
MC/DC100%1/1
$rep || {}
$rep
Truth table100%2/2
A
A= $rep
Aresult
11
00
103 3 return $self->realm;
104 }
105  
106 0 ▶sub export_realm {
Subroutine export_realm: not called CC=3 SCAR=24.8
Pod documented
107 0 my ( $self, %opt ) = @_;
108 return $self->_data( POST => '/partial-export'.$self->_query(
109 exportClients => $opt{clients} ? 'true' : 'false',
110 0 ▶ exportGroupsAndRoles => $opt{groups_and_roles} ? 'true' : 'false'
Branch: 2 branches
BranchTrueFalseTotal
$opt{'clients'} ? : 0 0 0
$opt{'groups_and_roles'} ? : 0 0 0
111 ) );
112 }
113  
114 1 ▶sub partial_import {
Subroutine partial_import: called CC=2 SCAR=7.2
Pod documented
115 1 my ( $self, $rep, %opt ) = @_;
116 1 ▶ return $self->_data( POST => '/partialImport', { ifResourceExists => $opt{if_exists} // 'FAIL', %$rep } );
Condition50%1/2
$opt{"if_exists"} // "FAIL"
l!l
10
MC/DC0%0/1
$opt{"if_exists"} // "FAIL"
$opt{"if_exists"}
Truth table50%1/2
A
A= $opt{"if_exists"}
Aresult
11
00
117 }
118  
119  
120 #### clients
121  
122 13 ▶sub list_clients { my ( $self, %q ) = @_; $self->_data( GET => '/clients'.$self->_query(%q) ) }
Subroutine list_clients: called CC=1 SCAR=0.0
Pod documented
123 5 ▶sub get_client { $_[0]->_data( GET => '/clients/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_client: called CC=1 SCAR=0.0
Pod documented
124 6 ▶sub create_client { $_[0]->_create( '/clients', $_[1] ) }
Subroutine create_client: called CC=1 SCAR=0.0
Pod documented
125 2 ▶sub update_client { $_[0]->_done( PUT => '/clients/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_client: called CC=1 SCAR=0.0
Pod documented
126 1 ▶sub delete_client { $_[0]->_done( DELETE => '/clients/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_client: called CC=1 SCAR=0.0
Pod documented
127  
128 12 ▶sub find_client {
Subroutine find_client: called CC=1 SCAR=0.0
Pod documented
129 12 my ( $self, $client_id ) = @_;
130 12 my ( $client ) = grep { $_->{clientId} eq $client_id } @{ $self->list_clients( clientId => $client_id ) };
131 12 return $client;
132 }
133  
134 1 ▶sub get_client_secret { $_[0]->_data( GET => '/clients/'.$_[0]->_esc( $_[1] ).'/client-secret' ) }
Subroutine get_client_secret: called CC=1 SCAR=0.0
Pod documented
135 0 ▶sub regenerate_client_secret { $_[0]->_data( POST => '/clients/'.$_[0]->_esc( $_[1] ).'/client-secret' ) }
Subroutine regenerate_client_secret: not called CC=1 SCAR=6.9
Pod documented
136 1 ▶sub get_service_account_user { $_[0]->_data( GET => '/clients/'.$_[0]->_esc( $_[1] ).'/service-account-user' ) }
Subroutine get_service_account_user: called CC=1 SCAR=0.0
Pod documented
137  
138  
139 #### client scopes
140  
141 6 ▶sub list_client_scopes { $_[0]->_data( GET => '/client-scopes' ) }
Subroutine list_client_scopes: called CC=1 SCAR=0.0
Pod documented
142 0 ▶sub get_client_scope { $_[0]->_data( GET => '/client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_client_scope: not called CC=1 SCAR=6.9
Pod documented
143 2 ▶sub create_client_scope { $_[0]->_create( '/client-scopes', $_[1] ) }
Subroutine create_client_scope: called CC=1 SCAR=0.0
Pod documented
144 1 ▶sub update_client_scope { $_[0]->_done( PUT => '/client-scopes/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_client_scope: called CC=1 SCAR=0.0
Pod documented
145 0 ▶sub delete_client_scope { $_[0]->_done( DELETE => '/client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_client_scope: not called CC=1 SCAR=6.9
Pod documented
146  
147 6 ▶sub find_client_scope {
Subroutine find_client_scope: called CC=1 SCAR=0.0
Pod documented
148 6 my ( $self, $name ) = @_;
149 6 my ( $scope ) = grep { $_->{name} eq $name } @{ $self->list_client_scopes };
150 6 return $scope;
151 }
152  
153 1 ▶sub add_default_client_scope {
Subroutine add_default_client_scope: called CC=1 SCAR=0.0
Pod documented
154 1 my ( $self, $client, $scope ) = @_;
155 1 return $self->_done( PUT => '/clients/'.$self->_esc($client).'/default-client-scopes/'.$self->_esc($scope) );
156 }
157  
158 1 ▶sub add_realm_default_client_scope { $_[0]->_done( PUT => '/default-default-client-scopes/'.$_[0]->_esc( $_[1] ) ) }
Subroutine add_realm_default_client_scope: called CC=1 SCAR=0.0
Pod documented
159  
160  
161 #### protocol mappers
162  
163 14 ▶sub _mapper_path {
Subroutine _mapper_path: called CC=6 SCAR=18.1
164 14 my ( $self, $kind, $owner ) = @_;
165 14 ▶ WWW::Keycloak::Error::Validation->throw( message => 'protocol mappers belong to a client or a client_scope, not to '.( $kind // 'nothing' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kind and $kind eq "client" || $kind eq "client_scope" 1 13 14
Condition75%6/8
defined $kind and $kind eq "client" || $kind eq "client_scope"
!ll&&!rl&&r
0113
$kind eq "client" or $kind eq "client_scope"
l!l&&r!l&&!r
1031
$kind // "nothing"
l!l
10
MC/DC66%2/3
defined $kind and $kind eq "client" || $kind eq "client_scope"
defined $kind $kind eq "client" $kind eq "client_scope"
MC/DC0%0/1
$kind // "nothing"
$kind
Truth table75%3/4
A and B or C
A= defined $kindB= $kind eq "client"C= $kind eq "client_scope"
ABCresult
0XX0
1000
11X1
1011
Truth table50%1/2
A
A= $kind
Aresult
11
00
166 unless defined $kind && ( $kind eq 'client' || $kind eq 'client_scope' );
167 13 ▶ return ( $kind eq 'client' ? '/clients/' : '/client-scopes/' ).$self->_esc($owner).'/protocol-mappers/models';
Branch: 1 branch
BranchTrueFalseTotal
$kind eq 'client' ? : 10 3 13
168 }
169  
170 7 ▶sub list_protocol_mappers { my ( $self, $kind, $owner ) = @_; $self->_data( GET => $self->_mapper_path( $kind, $owner ) ) }
Subroutine list_protocol_mappers: called CC=1 SCAR=0.0
Pod documented
171 4 ▶sub create_protocol_mapper { my ( $self, $kind, $owner, $rep ) = @_; $self->_create( $self->_mapper_path( $kind, $owner ), $rep ) }
Subroutine create_protocol_mapper: called CC=1 SCAR=0.0
Pod documented
172  
173 2 ▶sub update_protocol_mapper {
Subroutine update_protocol_mapper: called CC=1 SCAR=0.0
Pod documented
174 2 my ( $self, $kind, $owner, $id, $rep ) = @_;
175 2 return $self->_done( PUT => $self->_mapper_path( $kind, $owner ).'/'.$self->_esc($id), $rep );
176 }
177  
178 1 ▶sub delete_protocol_mapper {
Subroutine delete_protocol_mapper: called CC=1 SCAR=0.0
Pod documented
179 1 my ( $self, $kind, $owner, $id ) = @_;
180 1 return $self->_done( DELETE => $self->_mapper_path( $kind, $owner ).'/'.$self->_esc($id) );
181 }
182  
183  
184 #### users
185  
186 10 ▶sub list_users { my ( $self, %q ) = @_; $self->_data( GET => '/users'.$self->_query(%q) ) }
Subroutine list_users: called CC=1 SCAR=0.0
Pod documented
187 1 ▶sub get_user { $_[0]->_data( GET => '/users/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_user: called CC=1 SCAR=0.0
Pod documented
188 3 ▶sub create_user { $_[0]->_create( '/users', $_[1] ) }
Subroutine create_user: called CC=1 SCAR=0.0
Pod documented
189 3 ▶sub update_user { $_[0]->_done( PUT => '/users/'.$_[0]->_esc( $_[1] ), $_[2] ) }
Subroutine update_user: called CC=1 SCAR=0.0
Pod documented
190 1 ▶sub delete_user { $_[0]->_done( DELETE => '/users/'.$_[0]->_esc( $_[1] ) ) }
Subroutine delete_user: called CC=1 SCAR=0.0
Pod documented
191  
192 10 ▶sub find_user {
Subroutine find_user: called CC=1 SCAR=0.0
Pod documented
193 10 my ( $self, $username ) = @_;
194 10 my ( $user ) = grep { lc $_->{username} eq lc $username } @{ $self->list_users( username => $username, exact => 'true' ) };
195 10 return $user;
196 }
197  
198 1 ▶sub set_password {
Subroutine set_password: called CC=2 SCAR=7.2
Pod documented
199 1 my ( $self, $id, $password, %opt ) = @_;
200 return $self->_done( PUT => '/users/'.$self->_esc($id).'/reset-password',
201 1 ▶ { type => 'password', value => $password, temporary => $opt{temporary} ? \1 : \0 } );
Branch: 1 branch
BranchTrueFalseTotal
$opt{'temporary'} ? : 1 0 1
202 }
203  
204 2 ▶sub list_credentials { $_[0]->_data( GET => '/users/'.$_[0]->_esc( $_[1] ).'/credentials' ) }
Subroutine list_credentials: called CC=1 SCAR=0.0
Pod documented
205 1 ▶sub delete_credential { $_[0]->_done( DELETE => '/users/'.$_[0]->_esc( $_[1] ).'/credentials/'.$_[0]->_esc( $_[2] ) ) }
Subroutine delete_credential: called CC=1 SCAR=0.0
Pod documented
206 1 ▶sub list_sessions { $_[0]->_data( GET => '/users/'.$_[0]->_esc( $_[1] ).'/sessions' ) }
Subroutine list_sessions: called CC=1 SCAR=0.0
Pod documented
207 1 ▶sub logout_user { $_[0]->_done( POST => '/users/'.$_[0]->_esc( $_[1] ).'/logout' ) }
Subroutine logout_user: called CC=1 SCAR=0.0
Pod documented
208  
209  
210 #### authentication
211  
212 1 ▶sub list_flows { $_[0]->_data( GET => '/authentication/flows' ) }
Subroutine list_flows: called CC=1 SCAR=0.0
Pod documented
213 7 ▶sub list_executions { $_[0]->_data( GET => '/authentication/flows/'.$_[0]->_esc( $_[1] ).'/executions' ) }
Subroutine list_executions: called CC=1 SCAR=0.0
Pod documented
214 1 ▶sub copy_flow { $_[0]->_create( '/authentication/flows/'.$_[0]->_esc( $_[1] ).'/copy', { newName => $_[2] } ) }
Subroutine copy_flow: called CC=1 SCAR=0.0
Pod documented
215 3 ▶sub get_execution_config { $_[0]->_data( GET => '/authentication/config/'.$_[0]->_esc( $_[1] ) ) }
Subroutine get_execution_config: called CC=1 SCAR=0.0
Pod documented
216 3 ▶sub create_execution_config { $_[0]->_create( '/authentication/executions/'.$_[0]->_esc( $_[1] ).'/config', $_[2] ) }
Subroutine create_execution_config: called CC=1 SCAR=0.0
Pod documented
217 3 ▶sub update_execution_config { $_[0]->_done( PUT => '/authentication/config/'.$_[0]->_esc( $_[1] ), { %{ $_[2] }, id => $_[1] } ) }
Subroutine update_execution_config: called CC=1 SCAR=0.0
Pod documented
218 1 ▶sub describe_authenticator { $_[0]->_data( GET => '/authentication/config-description/'.$_[0]->_esc( $_[1] ) ) }
Subroutine describe_authenticator: called CC=1 SCAR=0.0
Pod documented
219  
220  
221 #### ensure
222  
223 26 ▶sub _ensure {
Subroutine _ensure: called CC=3 SCAR=11.0
224 26 my ( $self, %arg ) = @_;
225 26 my $current = $arg{find}->();
226 26 ▶ return { id => $arg{create}->(), changed => 'created' } unless $current;
Branch: 1 branch
BranchTrueFalseTotal
unless $current 10 16 26
227 16 my $changes = $self->diff_class->changes( $current, $arg{wanted} );
228 16 ▶ return { id => $arg{id}->($current), changed => '' } unless %$changes;
Branch: 1 branch
BranchTrueFalseTotal
unless %$changes 8 8 16
229 8 $arg{update}->( $current, $changes );
230 8 return { id => $arg{id}->($current), changed => 'updated' };
231 }
232  
233 3 ▶sub ensure_realm {
Subroutine ensure_realm: called CC=1 SCAR=0.0
Pod documented
234 3 my ( $self, %rep ) = @_;
235 return $self->_ensure(
236 wanted => \%rep,
237 3 ▶ find => sub { my $realm = eval { $self->get_realm }; $self->_missing($@) unless $realm; $realm },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
unless $realm 1 2 3
238 1 ▶ create => sub { $self->create_realm( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
239 1 ▶ update => sub { $self->update_realm( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
240 2 ▶ id => sub { $_[0]->{realm} }
Subroutine __ANON__: called CC=1 SCAR=0.0
241 3 );
242 }
243  
244  
245 9 ▶sub ensure_client {
Subroutine ensure_client: called CC=4 SCAR=13.9
Pod documented
246 9 my ( $self, %rep ) = @_;
247 9 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_client needs a clientId' ) unless defined $rep{clientId};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"clientId"} 1 8 9
248 8 for my $ignored (qw( defaultClientScopes optionalClientScopes protocolMappers )) {
249 WWW::Keycloak::Error::Validation->throw( message => 'ensure_client cannot set '.$ignored
250 .': Keycloak ignores it when a client is updated; use add_default_client_scope or ensure_protocol_mapper' )
251 21 ▶ if exists $rep{$ignored};
Branch: 1 branch
BranchTrueFalseTotal
if exists $rep{$ignored} 3 18 21
252 }
253 return $self->_ensure(
254 wanted => \%rep,
255 5 ▶ find => sub { $self->find_client( $rep{clientId} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
256 2 ▶ create => sub { $self->create_client( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
257 1 ▶ update => sub { $self->update_client( $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
258 3 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
259 5 );
260 }
261  
262  
263 3 ▶sub ensure_client_scope {
Subroutine ensure_client_scope: called CC=2 SCAR=6.9
Pod documented
264 3 my ( $self, %rep ) = @_;
265 3 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_client_scope needs a name' ) unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 0 3 3
266 return $self->_ensure(
267 wanted => \%rep,
268 3 ▶ find => sub { $self->find_client_scope( $rep{name} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
269 1 ▶ create => sub { $self->create_client_scope( { protocol => 'openid-connect', %rep } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
270 1 ▶ update => sub { $self->update_client_scope( $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
271 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
272 3 );
273 }
274  
275  
276 6 ▶sub ensure_protocol_mapper {
Subroutine ensure_protocol_mapper: called CC=7 SCAR=19.7
Pod documented
277 6 my ( $self, $kind, $owner_key, %rep ) = @_;
278 6 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_protocol_mapper needs a name' ) unless defined $rep{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"name"} 1 5 6
279 5 ▶ my $owner = $kind && $kind eq 'client' ? $self->find_client($owner_key)
Branch: 2 branches
BranchTrueFalseTotal
$kind && $kind eq 'client' ? : 4 1 5
$kind && $kind eq 'client_scope' ? : 1 0 1
Condition50%3/6
$kind and $kind eq "client"
!ll&&!rl&&r
014
$kind and $kind eq "client_scope"
!ll&&!rl&&r
001
MC/DC50%1/2
$kind and $kind eq "client"
$kind $kind eq "client"
MC/DC0%0/2
$kind and $kind eq "client_scope"
$kind $kind eq "client_scope"
Truth table66%2/3
A and B
A= $kindB= $kind eq "client"
ABresult
0X0
100
111
Truth table33%1/3
A and B
A= $kindB= $kind eq "client_scope"
ABresult
0X0
100
111
280 : $kind && $kind eq 'client_scope' ? $self->find_client_scope($owner_key)
281 : $self->_mapper_path($kind);
282 5 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_protocol_mapper: no '.$kind.' '.$owner_key ) unless $owner;
Branch: 1 branch
BranchTrueFalseTotal
unless $owner 1 4 5
283 return $self->_ensure(
284 wanted => \%rep,
285 4 ▶ find => sub { ( grep { $_->{name} eq $rep{name} } @{ $self->list_protocol_mappers( $kind, $owner->{id} ) } )[0] },
Subroutine __ANON__: called CC=1 SCAR=0.0
286 2 ▶ create => sub { $self->create_protocol_mapper( $kind, $owner->{id}, { protocol => 'openid-connect', %rep } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
287 1 ▶ update => sub { $self->update_protocol_mapper( $kind, $owner->{id}, $_[0]{id}, { %{ $_[0] }, %{ $_[1] } } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
288 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
289 4 );
290 }
291  
292  
293 7 ▶sub ensure_user {
Subroutine ensure_user: called CC=5 SCAR=16.1
Pod documented
294 7 my ( $self, %rep ) = @_;
295 7 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_user needs a username' ) unless defined $rep{username};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rep{"username"} 0 7 7
296 # Keycloak keeps user names and e-mail addresses in lower case
297 7 my %compare = %rep;
298 7 delete $compare{credentials};
299 7 $compare{$_} = lc $compare{$_} for grep { defined $compare{$_} } qw( username email );
300 # Keycloak keeps every user attribute as a list of strings
301 3 ▶ $compare{attributes} = { map { $_ => ref $rep{attributes}{$_} eq 'ARRAY' ? $rep{attributes}{$_} : [ $rep{attributes}{$_} ] } keys %{ $rep{attributes} } }
Branch: 1 branch
BranchTrueFalseTotal
ref $rep{'attributes'}{$_} eq 'ARRAY' ? : 1 2 3
302 7 ▶ if ref $rep{attributes} eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $rep{"attributes"} eq "HASH" 3 4 7
303 return $self->_ensure(
304 wanted => \%compare,
305 7 ▶ find => sub { $self->find_user( $rep{username} ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
306 2 ▶ create => sub { $self->create_user( \%rep ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
307 # the whole user: Keycloak's user profile drops fields a PUT with attributes does not name
308 2 ▶ update => sub { $self->update_user( $_[0]{id}, $self->diff_class->merge( $_[0], $_[1] ) ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
309 5 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
310 7 );
311 }
312  
313  
314 6 ▶sub ensure_execution_config {
Subroutine ensure_execution_config: called CC=6 SCAR=17.9
Pod documented
315 6 my ( $self, %arg ) = @_;
316 6 for (qw( flow authenticator config )) {
317 18 ▶ WWW::Keycloak::Error::Validation->throw( message => 'ensure_execution_config needs '.$_ ) unless defined $arg{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{$_} 1 17 18
318 }
319 5 ▶ my ( $execution ) = grep { ( $_->{providerId} // '' ) eq $arg{authenticator} } @{ $self->list_executions( $arg{flow} ) };
Condition100%2/2
$_->{"providerId"} // ""
l!l
144
MC/DC100%1/1
$_->{"providerId"} // ""
$_->{"providerId"}
Truth table100%2/2
A
A= $_->{"providerId"}
Aresult
11
00
320 5 ▶ WWW::Keycloak::Error::Validation->throw( message => 'flow "'.$arg{flow}.'" has no step '.$arg{authenticator} ) unless $execution;
Branch: 1 branch
BranchTrueFalseTotal
unless $execution 1 4 5
321 4 ▶ my $alias = $arg{alias} // $arg{flow}.' '.$arg{authenticator};
Condition100%2/2
$arg{"alias"} // $arg{"flow"} . ' ' . $arg{"authenticator"}
l!l
13
MC/DC100%1/1
$arg{"alias"} // $arg{"flow"} . ' ' . $arg{"authenticator"}
$arg{"alias"}
Truth table100%2/2
A
A= $arg{"alias"}
Aresult
11
00
322 return $self->_ensure(
323 wanted => { config => $arg{config} },
324 4 ▶ find => sub { $execution->{authenticationConfig} ? $self->get_execution_config( $execution->{authenticationConfig} ) : undef },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$execution->{'authenticationConfig'} ? : 2 2 4
325 2 ▶ create => sub { $self->create_execution_config( $execution->{id}, { alias => $alias, config => $arg{config} } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
326 2 ▶ update => sub { $self->update_execution_config( $_[0]{id}, { alias => $_[0]{alias}, config => $arg{config} } ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
327 2 ▶ id => sub { $_[0]->{id} }
Subroutine __ANON__: called CC=1 SCAR=0.0
328 4 );
329 }
330  
331  
332 6 1;
333  
334 __END__
« Keycloak/OIDC.pm ↑ Summary Keycloak/Error/API.pm »