Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce nssdb and nssdb_certificate types #360

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions spec/acceptance/qpid_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,24 @@
it { should be_grouped_into 'qpidd' }
end

describe command("certutil -L -d #{nssdb_dir}") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/^ca CT,C,c$/i) }
its(:stdout) { should match(/^broker u,u,u$/i) }
describe nssdb(nssdb_dir) do
its(:certificates) { should match(/^ca CT,C,c$/i) }
its(:certificates) { should match(/^broker u,u,u$/i) }
end

describe command("certutil -L -d #{nssdb_dir} -n ca") do
describe nssdb_certificate(nssdb_dir, name: 'ca') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match_without_whitespace(/Subject: "CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US"/) }
its(:stdout) { should match_without_whitespace(/Issuer: "CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US"/) }
its(:subject) { should match(/CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US/) }
its(:issuer) { should match(/CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US/) }
end

describe command("certutil -L -d #{nssdb_dir} -n broker") do
describe nssdb_certificate(nssdb_dir, name: 'broker') do
its(:exit_status) { should eq 0 }
its(:stdout) { should match_without_whitespace(/Subject: "CN=#{fqdn},OU=SomeOrgUnit,O=pulp,ST=North Carolina,C=US"/) }
its(:stdout) { should match_without_whitespace(/Issuer: "CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US"/) }
its(:subject) { should match(/CN=#{fqdn},OU=SomeOrgUnit,O=pulp,ST=North Carolina,C=US/) }
its(:issuer) { should match(/CN=#{fqdn},OU=SomeOrgUnit,O=Katello,L=Raleigh,ST=North Carolina,C=US/) }
end

# TODO: nssdb_private_key
describe command("certutil -K -d #{nssdb_dir} -f #{nssdb_password_file} -n broker") do
its(:exit_status) { should eq 0 }
its(:stdout) { should match(/rsa/) }
Expand Down
57 changes: 57 additions & 0 deletions spec/support/acceptance/nssdb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
begin
require 'serverspec'
rescue LoadError
# Not using acceptance tests
else
module Serverspec
module Type
class Nssdb < Command
def certificates
# TODO: parse the output
stdout
end

private

def command
"certutil -L -d #{@name}"
end
end

class NssdbCertificate < Command
def subject
# TODO: multi line support
if command_result =~ /^Subject: (.+)$/
$1
end
end

def issuer
# TODO: multi line support
if command_result =~ /^Issuer: (.+)$/
$1
end
end

private

def command
# TODO: ensure name is set
"certutil -L -d #{@name} -n #{options[:name]}"
end
end
end

module Helper
module Type
def nssdb(*args)
Serverspec::Type::Nssdb.new(*args)
end

def nssdb_certificate(*args)
Serverspec::Type::NssdbCertificate.new(*args)
end
end
end
end
end