Skip to content

Commit 71d0d03

Browse files
committed
add spec for linux user lib
1 parent 83a6e82 commit 71d0d03

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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

0 commit comments

Comments
 (0)