From 943fd852ef136e3020e886f22cd3024dd98a4d20 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Sun, 23 Feb 2020 22:42:49 +0000 Subject: [PATCH] Add tests for git cookbook --- .github/workflows/test-kitchen.yml | 3 +++ .kitchen.yml | 9 ++++++++ cookbooks/git/attributes/default.rb | 2 ++ cookbooks/git/metadata.rb | 1 + cookbooks/git/recipes/server.rb | 3 +++ cookbooks/git/templates/default/apache.erb | 2 ++ roles/sarel.rb | 3 +-- test/data_bags/accounts/git.json | 6 ++++++ .../git-web/serverspec/apache_spec.rb | 21 +++++++++++++++++++ .../git-web/serverspec/gitweb_spec.rb | 8 +++++++ test/integration/git/serverspec/git_spec.rb | 8 +++++++ 11 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 test/data_bags/accounts/git.json create mode 100644 test/integration/git-web/serverspec/apache_spec.rb create mode 100644 test/integration/git-web/serverspec/gitweb_spec.rb create mode 100644 test/integration/git/serverspec/git_spec.rb diff --git a/.github/workflows/test-kitchen.yml b/.github/workflows/test-kitchen.yml index 086850543..1c83e25f4 100644 --- a/.github/workflows/test-kitchen.yml +++ b/.github/workflows/test-kitchen.yml @@ -32,6 +32,9 @@ jobs: - ftp - geodns - geoipupdate + - git + - git-server + - git-web - gps-tile - hardware - incron diff --git a/.kitchen.yml b/.kitchen.yml index c136565f1..8414198bb 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -117,6 +117,15 @@ suites: - name: geoipupdate run_list: - recipe[geoipupdate::default] + - name: git + run_list: + - recipe[git::default] + - name: git-server + run_list: + - recipe[git::server] + - name: git-web + run_list: + - recipe[git::web] - name: gps-tile run_list: - recipe[gps-tile::default] diff --git a/cookbooks/git/attributes/default.rb b/cookbooks/git/attributes/default.rb index 2d89a83de..fd641f37a 100644 --- a/cookbooks/git/attributes/default.rb +++ b/cookbooks/git/attributes/default.rb @@ -1,5 +1,7 @@ +default[:git][:host] = "git.openstreetmap.org" default[:git][:directory] = "/var/lib/git" default[:git][:public_user] = "git" default[:git][:public_group] = "git" default[:git][:private_user] = "git" default[:git][:private_group] = "git" +default[:git][:private_nodes] = "fqdn:*" diff --git a/cookbooks/git/metadata.rb b/cookbooks/git/metadata.rb index 003590d11..19f53944f 100644 --- a/cookbooks/git/metadata.rb +++ b/cookbooks/git/metadata.rb @@ -6,5 +6,6 @@ description "Installs and configures git" version "1.0.0" supports "ubuntu" +depends "accounts" depends "apache" depends "networking" diff --git a/cookbooks/git/recipes/server.rb b/cookbooks/git/recipes/server.rb index 4a98818e3..78c1b828a 100644 --- a/cookbooks/git/recipes/server.rb +++ b/cookbooks/git/recipes/server.rb @@ -17,6 +17,9 @@ # limitations under the License. # +node.default[:accounts][:users][:git][:status] = :role + +include_recipe "accounts" include_recipe "networking" git_directory = node[:git][:directory] diff --git a/cookbooks/git/templates/default/apache.erb b/cookbooks/git/templates/default/apache.erb index 39a680120..67dc1913b 100644 --- a/cookbooks/git/templates/default/apache.erb +++ b/cookbooks/git/templates/default/apache.erb @@ -59,10 +59,12 @@ Require all granted +<% unless @private_allowed.empty? -%> Require ip <%= @private_allowed.sort.join(" ") %> +<% end -%> Require all denied diff --git a/roles/sarel.rb b/roles/sarel.rb index 647aa57c5..e3f550d9c 100644 --- a/roles/sarel.rb +++ b/roles/sarel.rb @@ -4,8 +4,7 @@ description "Master role applied to sarel" default_attributes( :git => { :private_user => "chefrepo", - :private_group => "chefrepo", - :private_nodes => "fqdn:*" + :private_group => "chefrepo" }, :networking => { :interfaces => { diff --git a/test/data_bags/accounts/git.json b/test/data_bags/accounts/git.json new file mode 100644 index 000000000..1938a3fc8 --- /dev/null +++ b/test/data_bags/accounts/git.json @@ -0,0 +1,6 @@ +{ + "id": "git", + "uid": "508", + "comment": "git.openstreetmap.org", + "home": "/var/lib/git" +} diff --git a/test/integration/git-web/serverspec/apache_spec.rb b/test/integration/git-web/serverspec/apache_spec.rb new file mode 100644 index 000000000..446d3b915 --- /dev/null +++ b/test/integration/git-web/serverspec/apache_spec.rb @@ -0,0 +1,21 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("apache2") do + it { should be_installed } +end + +describe service("apache2") do + it { should be_enabled } + it { should be_running } +end + +describe port(80) do + it { should be_listening.with("tcp") } +end + +describe port(443) do + it { should be_listening.with("tcp") } +end diff --git a/test/integration/git-web/serverspec/gitweb_spec.rb b/test/integration/git-web/serverspec/gitweb_spec.rb new file mode 100644 index 000000000..3818bea8d --- /dev/null +++ b/test/integration/git-web/serverspec/gitweb_spec.rb @@ -0,0 +1,8 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("gitweb") do + it { should be_installed } +end diff --git a/test/integration/git/serverspec/git_spec.rb b/test/integration/git/serverspec/git_spec.rb new file mode 100644 index 000000000..b34c37dec --- /dev/null +++ b/test/integration/git/serverspec/git_spec.rb @@ -0,0 +1,8 @@ +require "serverspec" + +# Required by serverspec +set :backend, :exec + +describe package("git") do + it { should be_installed } +end -- 2.43.2