mirror of
https://github.com/inspec/inspec
synced 2024-11-27 07:00:39 +00:00
b5cd64d16a
Most passwd/shadow implementations treat lines that start with '#' as comments. For example, the implementation in OS X: if (buf[0] == '#') { /* skip comments for Rhapsody. */ continue; } https://opensource.apple.com/source/remote_cmds/remote_cmds-41/rpc_yppasswdd.tproj/passwd.c Fixes #725 Signed-off-by: Steven Danna <steve@chef.io>
48 lines
1.1 KiB
Ruby
48 lines
1.1 KiB
Ruby
# encoding: utf-8
|
|
# author: Dominik Richter
|
|
# author: Christoph Hartmann
|
|
|
|
require 'helper'
|
|
|
|
describe PasswdParser do
|
|
let (:parser) { Class.new() { include PasswdParser }.new }
|
|
|
|
describe '#parse_passwd' do
|
|
it 'parses nil content' do
|
|
parser.parse_passwd(nil).must_equal([])
|
|
end
|
|
|
|
it 'parses an empty passwd line' do
|
|
parser.parse_passwd('').must_equal([])
|
|
end
|
|
|
|
it 'parses a comment line' do
|
|
content = <<EOF
|
|
# This is a comment
|
|
# this is another comment
|
|
root:x:0:0:root:/root:/bin/sh
|
|
EOF
|
|
info = [{ "user"=>"root",
|
|
"password"=>"x",
|
|
"uid"=>"0",
|
|
"gid"=>"0",
|
|
"desc"=>"root",
|
|
"home"=>"/root",
|
|
"shell"=>"/bin/sh" }]
|
|
parser.parse_passwd(content).must_equal(info)
|
|
end
|
|
|
|
it 'parses a valid passwd line' do
|
|
info = [{
|
|
"user"=>"root",
|
|
"password"=>"x",
|
|
"uid"=>"0",
|
|
"gid"=>"0",
|
|
"desc"=>"root",
|
|
"home"=>"/root",
|
|
"shell"=>"/bin/sh"
|
|
}]
|
|
parser.parse_passwd('root:x:0:0:root:/root:/bin/sh').must_equal(info)
|
|
end
|
|
end
|
|
end
|