File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
spec/lib/msf/core/post/linux Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'spec_helper'
2
+
3
+ RSpec . describe Msf ::Post ::Linux ::User do
4
+ subject do
5
+ mod = ::Msf ::Module . new
6
+ mod . extend described_class
7
+ mod
8
+ end
9
+
10
+ describe '#get_home_dir' do
11
+ let ( :user ) { 'testuser' }
12
+ let ( :expected_command ) { "grep '^#{ user } :' /etc/passwd | cut -d ':' -f 6" }
13
+
14
+ context 'when the user exists' do
15
+ it 'returns the home directory path from /etc/passwd' do
16
+ expect ( tester ) . to receive ( :cmd_exec )
17
+ . with ( expected_command )
18
+ . and_return ( "/home/testuser\n " )
19
+
20
+ result = tester . get_home_dir ( user )
21
+ expect ( result ) . to eq ( '/home/testuser' )
22
+ end
23
+ end
24
+
25
+ context 'when the user does not exist in /etc/passwd' do
26
+ it 'returns an empty string' do
27
+ expect ( tester ) . to receive ( :cmd_exec )
28
+ . with ( expected_command )
29
+ . and_return ( "\n " )
30
+
31
+ result = tester . get_home_dir ( user )
32
+ expect ( result ) . to eq ( '' )
33
+ end
34
+ end
35
+
36
+ end
37
+ end
You can’t perform that action at this time.
0 commit comments