<commit_before>#
# Author:: <NAME> <<EMAIL>>
# Cookbook:: acme
#
# Copyright 2015-2018 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'serverspec'

set :backend, :exec

describe x509_certificate('/etc/ssl/test.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 2048 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=test.example.com/' }
  its(:issuer) { should eq '/CN=happy hacker fake CA' }
end

describe x509_private_key('/etc/ssl/test.example.com.key') do
  it { should be_valid }
  it { should_not be_encrypted }
  it { should have_matching_certificate('/etc/ssl/test.example.com.crt') }
end

describe x509_certificate('/etc/ssl/test.example.com-chain.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should have_purpose 'SSL server CA' }
  its(:subject) { should eq '/CN=happy hacker fake CA' }
  its(:issuer) { should eq '/CN=cackling cryptographer fake ROOT' }
end

describe command('echo | openssl s_client -connect 0:443 2>&1 | openssl x509 -noout -serial') do
  its(:stdout) { should eq `openssl x509 -in /etc/ssl/test.example.com.crt -noout -serial` }
end

describe command('openssl x509 -in /etc/ssl/test.example.com.crt -noout -text') do
  its(:stdout) { should match(/DNS:test.example.com/) }
  its(:stdout) { should match(/DNS:web.example.com/) }
  its(:stdout) { should match(/DNS:mail.example.com/) }
end

describe x509_certificate('/etc/ssl/new.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 2048 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=new.example.com/' }
  its(:issuer) { should eq '/CN=happy hacker fake CA' }
end

describe x509_private_key('/etc/ssl/new.example.com.key') do
  it { should be_valid }
  it { should_not be_encrypted }
  it { should have_matching_certificate('/etc/ssl/new.example.com.crt') }
end

describe x509_certificate('/etc/ssl/4096.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 4096 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=4096.example.com/' }
  its(:issuer) { should eq '/CN=happy hacker fake CA' }
end

describe command('openssl x509 -in /etc/ssl/web.example.com.crt -noout -text') do
  its(:stdout) { should match(/DNS:web.example.com/) }
  its(:stdout) { should match(/DNS:mail.example.com/) }
end
<commit_msg>certificate_spec.rb: update for pebble-based acme_server<commit_after>#
# Author:: <NAME> <<EMAIL>>
# Cookbook:: acme
#
# Copyright 2015-2018 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'serverspec'

set :backend, :exec

describe x509_certificate('/etc/ssl/test.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 2048 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=test.example.com' }
  its(:issuer) { should match '/CN=Pebble Intermediate CA' }
end

describe x509_private_key('/etc/ssl/test.example.com.key') do
  it { should be_valid }
  it { should_not be_encrypted }
  it { should have_matching_certificate('/etc/ssl/test.example.com.crt') }
end

describe command('echo | openssl s_client -connect 0:443 2>&1 | openssl x509 -noout -serial') do
  its(:stdout) { should eq `openssl x509 -in /etc/ssl/test.example.com.crt -noout -serial` }
end

describe command('openssl x509 -in /etc/ssl/test.example.com.crt -noout -text') do
  its(:stdout) { should match(/DNS:test.example.com/) }
  its(:stdout) { should match(/DNS:web.example.com/) }
  its(:stdout) { should match(/DNS:mail.example.com/) }
end

describe x509_certificate('/etc/ssl/new.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 2048 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=new.example.com' }
  its(:issuer) { should match '/CN=Pebble Intermediate CA' }
end

describe x509_private_key('/etc/ssl/new.example.com.key') do
  it { should be_valid }
  it { should_not be_encrypted }
  it { should have_matching_certificate('/etc/ssl/new.example.com.crt') }
end

describe x509_certificate('/etc/ssl/4096.example.com.crt') do
  it { should be_certificate }
  it { should have_purpose 'SSL server' }
  it { should_not have_purpose 'SSL server CA' }
  its(:keylength) { should be 4096 }
  its(:validity_in_days) { should be > 30 }
  its(:subject) { should match '/CN=4096.example.com' }
  its(:issuer) { should match '/CN=Pebble Intermediate CA' }
end

describe command('openssl x509 -in /etc/ssl/web.example.com.crt -noout -text') do
  its(:stdout) { should match(/DNS:web.example.com/) }
  its(:stdout) { should match(/DNS:mail.example.com/) }
end

{'fraction_non_alphanumeric': 0.13152332953991222, 'fraction_numerical': 0.02357340269874817, 'mean_word_length': 4.096934548467274, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6738615', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2060, 'n_words': 601}