2019-06-11 22:24:35 +00:00
|
|
|
require "helper"
|
|
|
|
require "inspec/utils/parser"
|
2016-01-28 13:47:46 +00:00
|
|
|
|
2020-01-07 23:02:42 +00:00
|
|
|
describe Inspec::Utils::PasswdParser do
|
|
|
|
let(:parser) { Class.new { include Inspec::Utils::PasswdParser }.new }
|
2015-10-26 14:50:57 +00:00
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
describe "#parse_passwd" do
|
|
|
|
it "parses nil content" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(parser.parse_passwd(nil)).must_equal([])
|
2015-10-26 14:50:57 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses an empty passwd line" do
|
2019-09-30 22:31:55 +00:00
|
|
|
_(parser.parse_passwd("")).must_equal([])
|
2015-10-26 14:50:57 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
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" }]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(parser.parse_passwd(content)).must_equal(info)
|
2016-08-16 08:38:55 +00:00
|
|
|
end
|
|
|
|
|
2019-06-11 22:24:35 +00:00
|
|
|
it "parses a valid passwd line" do
|
2015-10-26 14:50:57 +00:00
|
|
|
info = [{
|
2019-06-11 22:24:35 +00:00
|
|
|
"user" => "root",
|
|
|
|
"password" => "x",
|
|
|
|
"uid" => "0",
|
|
|
|
"gid" => "0",
|
|
|
|
"desc" => "root",
|
|
|
|
"home" => "/root",
|
|
|
|
"shell" => "/bin/sh",
|
2015-10-26 14:50:57 +00:00
|
|
|
}]
|
2019-09-30 22:31:55 +00:00
|
|
|
_(parser.parse_passwd("root:x:0:0:root:/root:/bin/sh")).must_equal(info)
|
2015-10-26 14:50:57 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|