lib/Rex/User/OpenWrt.pm

filter: Statementstmt 57.3% 35 / 61 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 73.3% 11 / 15 Podpod 0.0% 0 / 4 totaltotal 47.9% 46 / 96 CC 6 SCAR 17.7
CC
6
Cov
48%
user_groups
20.0
new
6.0
user_list
6.0
CRAP 5.8
« lib/Rex/Interface/Fs/Sudo.pm ↑ Summary lib/Rex/Virtualization/Docker/status.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::User::OpenWrt;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Logger;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 require Rex::Commands;
14 1 ▶use Rex::Helper::Run;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Rex::Commands::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Rex::Interface::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Rex::Interface::Fs;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Rex::Interface::Exec;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶use Rex::Helper::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 1 ▶use Rex::User::Linux;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use base qw(Rex::User::Linux);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
25 0 my $that = shift;
26 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
27 0 my $self = $proto->SUPER::new(@_);
28  
29 0 bless( $self, $proto );
30  
31 0 return $self;
32 }
33  
34 0 ▶sub get_user {
Subroutine get_user: not called CC=1 SCAR=6.9
Pod undocumented
35 0 my ( $self, $user ) = @_;
36  
37 0 Rex::Logger::debug("Getting information for $user");
38 0 my $o_data = i_run "perl -e 'print join(\";\", getpwnam(\"$user\"))'";
39 0 chomp $o_data;
40 0 my @data = split( /;/, $o_data );
41  
42 return (
43 0 name => $data[0],
44 password => $data[1],
45 uid => $data[2],
46 gid => $data[3],
47 comment => $data[6],
48 home => $data[7],
49 shell => $data[8],
50 );
51 }
52  
53 0 ▶sub user_groups {
Subroutine user_groups: not called CC=4 SCAR=30.0
Pod undocumented
54 0 my ( $self, $user ) = @_;
55  
56 0 Rex::Logger::debug("Getting group membership of $user");
57  
58 0 my $data_str = i_run "/usr/bin/id -Gn $user", fail_ok => 1;
59 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
60 0 die("Error getting group list");
61 }
62  
63 0 my $wantarray = wantarray();
64  
65 0 ▶ if ( defined $wantarray && !$wantarray ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $wantarray and not $wantarray) 0 0 0
Condition0%0/3
defined $wantarray and not $wantarray
!ll&&!rl&&r
000
MC/DC0%0/2
defined $wantarray and not $wantarray
defined $wantarray not $wantarray
Truth table0%0/3
A and not(B)
A= defined $wantarrayB= not $wantarray
ABresult
0X0
100
111
66  
67 # arrayref
68 0 return [ split( / /, $data_str ) ];
69 }
70  
71 0 return split( / /, $data_str );
72 }
73  
74 0 ▶sub user_list {
Subroutine user_list: not called CC=2 SCAR=17.9
Pod undocumented
75 0 my $self = shift;
76  
77 0 Rex::Logger::debug("Getting user list");
78  
79 0 my $data_str = i_run "cut -d':' -f1 /etc/passwd", fail_ok => 1;
80 0 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 0 0
81 0 die("Error getting user list");
82 }
83  
84 0 return split( /\n/, $data_str );
85 }
86  
87 1 1;
« lib/Rex/Interface/Fs/Sudo.pm ↑ Summary lib/Rex/Virtualization/Docker/status.pm »