From eb5348c2803f98e60f910652564fad622cf6f0cb Mon Sep 17 00:00:00 2001
From: Fabien COMBERNOUS <fabien.combernous@adullact.org>
Date: Thu, 3 Nov 2022 11:04:31 +0100
Subject: [PATCH] add minimalistic acceptance tests

---
 .devcontainer/Dockerfile        |  6 ---
 .devcontainer/README.md         | 38 -------------
 .devcontainer/devcontainer.json | 17 ------
 .gitignore                      |  3 ++
 .gitlab-ci.yml                  | 65 ++++++++++++++--------
 .sync.yml                       | 95 ++++++++++++++++++++++++++++++++-
 .travis.yml                     | 45 ----------------
 .vscode/extensions.json         |  6 ---
 .yardopts                       |  1 -
 Gemfile                         |  7 +++
 appveyor.yml                    | 49 -----------------
 manifests/goose.pp              |  3 +-
 manifests/init.pp               | 33 ++++++------
 metadata.json                   | 25 ++++++---
 spec/acceptance/cfssl_spec.rb   | 24 +++++++++
 spec/spec_helper_acceptance.rb  | 20 +++++++
 16 files changed, 228 insertions(+), 209 deletions(-)
 delete mode 100644 .devcontainer/Dockerfile
 delete mode 100644 .devcontainer/README.md
 delete mode 100644 .devcontainer/devcontainer.json
 delete mode 100644 .travis.yml
 delete mode 100644 .vscode/extensions.json
 delete mode 100644 .yardopts
 delete mode 100644 appveyor.yml
 create mode 100644 spec/acceptance/cfssl_spec.rb
 create mode 100644 spec/spec_helper_acceptance.rb

diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
deleted file mode 100644
index 12ed4ff..0000000
--- a/.devcontainer/Dockerfile
+++ /dev/null
@@ -1,6 +0,0 @@
-FROM puppet/pdk:latest
-
-# [Optional] Uncomment this section to install additional packages.
-# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
-#     && apt-get -y install --no-install-recommends <your-package-list-here>
-
diff --git a/.devcontainer/README.md b/.devcontainer/README.md
deleted file mode 100644
index a719361..0000000
--- a/.devcontainer/README.md
+++ /dev/null
@@ -1,38 +0,0 @@
-# devcontainer
-
-
-For format details, see https://aka.ms/devcontainer.json. 
-
-For config options, see the README at:
-https://github.com/microsoft/vscode-dev-containers/tree/v0.140.1/containers/puppet
- 
-``` json
-{
-	"name": "Puppet Development Kit (Community)",
-	"dockerFile": "Dockerfile",
-
-	// Set *default* container specific settings.json values on container create.
-	"settings": {
-		"terminal.integrated.profiles.linux": {
-			"bash": {
-				"path": "bash",
-			}
-		}
-	},
-
-	// Add the IDs of extensions you want installed when the container is created.
-	"extensions": [
-		"puppet.puppet-vscode",
-		"rebornix.Ruby"
-	],
-
-	// Use 'forwardPorts' to make a list of ports inside the container available locally.
-	"forwardPorts": [],
-
-	// Use 'postCreateCommand' to run commands after the container is created.
-	"postCreateCommand": "pdk --version",
-}
-```
-
-
-
diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json
deleted file mode 100644
index fe7a8b1..0000000
--- a/.devcontainer/devcontainer.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
-	"name": "Puppet Development Kit (Community)",
-	"dockerFile": "Dockerfile",
-
-	"settings": {
-		"terminal.integrated.profiles.linux": {
-			"bash": {
-				"path": "bash",
-			}
-		}
-	},
-
-	"extensions": [
-		"puppet.puppet-vscode",
-		"rebornix.Ruby"
-	]
-}
diff --git a/.gitignore b/.gitignore
index 988dcbb..88b73b3 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,6 @@
 .envrc
 /inventory.yaml
 /spec/fixtures/litmus_inventory.yaml
+.devcontainer/
+.vscode/
+.yardopts
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 6d5e786..72818c1 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -2,6 +2,7 @@
 stages:
   - syntax
   - unit
+  - acceptance
 
 default:
   cache:
@@ -19,35 +20,57 @@ default:
     - bundle -v
     - bundle install --without system_tests --path vendor/bundle --jobs $(nproc)
 
-validate lint check rubocop-Ruby 2.5.7-Puppet ~> 6:
+validate lint check rubocop-Ruby 2.7.5-Puppet ~> 7:
   stage: syntax
-  image: ruby:2.5.7
+  image: ruby:2.7.5
   script:
-    - bundle exec rake validate lint check rubocop
+  - bundle exec rake validate lint check rubocop
   variables:
-    PUPPET_GEM_VERSION: '~> 6'
-
-parallel_spec-Ruby 2.5.7-Puppet ~> 6:
+    PUPPET_GEM_VERSION: "~> 7"
+parallel_spec-Ruby 2.7.5-Puppet ~> 6:
   stage: unit
-  image: ruby:2.5.7
+  image: ruby:2.7.5
   script:
-    - bundle exec rake parallel_spec
+  - bundle exec rake parallel_spec
   variables:
-    PUPPET_GEM_VERSION: '~> 6'
-
-validate lint check rubocop-Ruby 2.7.2-Puppet ~> 7:
-  stage: syntax
-  image: ruby:2.7.2
+    PUPPET_GEM_VERSION: "~> 6"
+parallel_spec-Ruby 2.7.5-Puppet ~> 7:
+  stage: unit
+  image: ruby:2.7.5
   script:
-    - bundle exec rake validate lint check rubocop
+  - bundle exec rake parallel_spec
   variables:
-    PUPPET_GEM_VERSION: '~> 7'
-
-parallel_spec-Ruby 2.7.2-Puppet ~> 7:
-  stage: unit
-  image: ruby:2.7.2
+    PUPPET_GEM_VERSION: "~> 7"
+acceptance with puppet6 ubuntu2004:
+  needs:
+  - parallel_spec-Ruby 2.7.5-Puppet ~> 6
+  stage: acceptance
+  variables:
+    RBENV_VERSION: 2.7.5
+    PUPPET_INSTALL_TYPE: agent
+    BEAKER_IS_PE: 'no'
+    BEAKER_PUPPET_COLLECTION: puppet6
+    BEAKER_debug: 'true'
+    BEAKER_setfile: ubuntu2004-64
+    BEAKER_HYPERVISOR: docker
   script:
-    - bundle exec rake parallel_spec
+  - bundle exec rake beaker
+  tags:
+  - puppet-tests
+acceptance with puppet7 ubuntu2004:
+  needs:
+  - parallel_spec-Ruby 2.7.5-Puppet ~> 7
+  stage: acceptance
   variables:
-    PUPPET_GEM_VERSION: '~> 7'
+    RBENV_VERSION: 2.7.5
+    PUPPET_INSTALL_TYPE: agent
+    BEAKER_IS_PE: 'no'
+    BEAKER_PUPPET_COLLECTION: puppet7
+    BEAKER_debug: 'true'
+    BEAKER_setfile: ubuntu2004-64
+    BEAKER_HYPERVISOR: docker
+  script:
+  - bundle exec rake beaker
+  tags:
+  - puppet-tests
 
diff --git a/.sync.yml b/.sync.yml
index 2fbf0ff..b9deeee 100644
--- a/.sync.yml
+++ b/.sync.yml
@@ -1 +1,94 @@
---- {}
+---
+.travis.yml:
+  delete: true
+appveyor.yml:
+  delete: true
+.gitignore:
+  paths:
+    - .devcontainer/
+    - .vscode/
+    - .yardopts
+
+.gitlab-ci.yml:
+  override: true
+  custom:
+    cache:
+      paths:
+        - vendor/bundle
+    bundler_args: '--without system_tests --path vendor/bundle --jobs $(nproc)'
+    custom_stages:
+      - syntax
+      - unit
+      - acceptance
+    custom_jobs:
+      validate lint check rubocop-Ruby 2.7.5-Puppet ~> 7:
+        stage: syntax
+        image: ruby:2.7.5
+        script:
+          - bundle exec rake validate lint check rubocop
+        variables:
+          PUPPET_GEM_VERSION: '~> 7'
+      parallel_spec-Ruby 2.7.5-Puppet ~> 6:
+        stage: unit
+        image: ruby:2.7.5
+        script:
+          - bundle exec rake parallel_spec
+        variables:
+          PUPPET_GEM_VERSION: '~> 6'
+      parallel_spec-Ruby 2.7.5-Puppet ~> 7:
+        stage: unit
+        image: ruby:2.7.5
+        script:
+          - bundle exec rake parallel_spec
+        variables:
+          PUPPET_GEM_VERSION: '~> 7'
+
+      acceptance with puppet6 ubuntu2004:
+        needs:
+          - parallel_spec-Ruby 2.7.5-Puppet ~> 6
+        stage: acceptance
+        variables:
+          RBENV_VERSION: '2.7.5'
+          PUPPET_INSTALL_TYPE: 'agent'
+          BEAKER_IS_PE: 'no'
+          BEAKER_PUPPET_COLLECTION: 'puppet6'
+          BEAKER_debug: 'true'
+          BEAKER_setfile: 'ubuntu2004-64'
+          BEAKER_HYPERVISOR: 'docker'
+        script:
+          - bundle exec rake beaker
+        tags:
+          - puppet-tests
+      acceptance with puppet7 ubuntu2004:
+        needs:
+          - parallel_spec-Ruby 2.7.5-Puppet ~> 7
+        stage: acceptance
+        variables:
+          RBENV_VERSION: '2.7.5'
+          PUPPET_INSTALL_TYPE: 'agent'
+          BEAKER_IS_PE: 'no'
+          BEAKER_PUPPET_COLLECTION: 'puppet7'
+          BEAKER_debug: 'true'
+          BEAKER_setfile: 'ubuntu2004-64'
+          BEAKER_HYPERVISOR: 'docker'
+        script:
+          - bundle exec rake beaker
+        tags:
+          - puppet-tests
+
+Gemfile:
+  required:
+    ':development':
+      - gem: 'beaker-rspec'
+      - gem: 'beaker-puppet'
+      - gem: 'beaker-docker'
+      - gem: 'beaker-puppet_install_helper'
+      - gem: 'beaker-module_install_helper'
+      - gem: 'pdk'
+        version: '<= 2.5.0'
+      - gem: 'puppet-strings'
+        version: '<= 2.8.0'
+
+
+spec/spec_helper.rb:
+  mock_with: ':rspec'
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 444e17a..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,45 +0,0 @@
----
-os: linux
-dist: xenial
-language: ruby
-cache: bundler
-before_install:
-  - bundle -v
-  - rm -f Gemfile.lock
-  - "# Update system gems if requested. This is useful to temporarily workaround troubles in the test runner"
-  - "# See https://github.com/puppetlabs/pdk-templates/commit/705154d5c437796b821691b707156e1b056d244f for an example of how this was used"
-  - "# Ignore exit code of SIGPIPE'd yes to not fail with shell's pipefail set"
-  - '[ -z "$RUBYGEMS_VERSION" ] || (yes || true) | gem update --system $RUBYGEMS_VERSION'
-  - gem --version
-  - bundle -v
-script:
-  - 'bundle exec rake $CHECK'
-bundler_args: --without system_tests
-rvm:
-  - 2.5.7
-stages:
-  - static
-  - spec
-  - acceptance
-  -
-    if: tag =~ ^v\d
-    name: deploy
-jobs:
-  fast_finish: true
-  include:
-    -
-      env: CHECK="validate lint check rubocop"
-      stage: static
-    -
-      env: PUPPET_GEM_VERSION="~> 6.0" CHECK=parallel_spec
-      rvm: 2.5.7
-      stage: spec
-    -
-      env: DEPLOY_TO_FORGE=yes
-      stage: deploy
-branches:
-  only:
-    - main
-    - /^v\d/
-notifications:
-  email: false
diff --git a/.vscode/extensions.json b/.vscode/extensions.json
deleted file mode 100644
index 2f1e4f7..0000000
--- a/.vscode/extensions.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
-  "recommendations": [
-    "puppet.puppet-vscode",
-    "rebornix.Ruby"
-  ]
-}
diff --git a/.yardopts b/.yardopts
deleted file mode 100644
index 29c933b..0000000
--- a/.yardopts
+++ /dev/null
@@ -1 +0,0 @@
---markup markdown
diff --git a/Gemfile b/Gemfile
index fc28658..f16e6e4 100644
--- a/Gemfile
+++ b/Gemfile
@@ -25,6 +25,13 @@ group :development do
   gem "puppet-module-win-default-r#{minor_version}", '~> 1.0',   require: false, platforms: [:mswin, :mingw, :x64_mingw]
   gem "puppet-module-win-dev-r#{minor_version}", '~> 1.0',       require: false, platforms: [:mswin, :mingw, :x64_mingw]
   gem "voxpupuli-puppet-lint-plugins", '>= 3.0',                 require: false
+  gem "beaker-rspec",                                            require: false
+  gem "beaker-puppet",                                           require: false
+  gem "beaker-docker",                                           require: false
+  gem "beaker-puppet_install_helper",                            require: false
+  gem "beaker-module_install_helper",                            require: false
+  gem "pdk", '<= 2.5.0',                                         require: false
+  gem "puppet-strings", '<= 2.8.0',                              require: false
 end
 group :system_tests do
   gem "puppet-module-posix-system-r#{minor_version}", '~> 1.0', require: false, platforms: [:ruby]
diff --git a/appveyor.yml b/appveyor.yml
deleted file mode 100644
index a70c01e..0000000
--- a/appveyor.yml
+++ /dev/null
@@ -1,49 +0,0 @@
----
-version: 1.1.x.{build}
-skip_branch_with_pr: true
-branches:
-  only:
-    - main
-    - release
-skip_commits:
-  message: /^\(?doc\)?.*/
-clone_depth: 10
-init:
-  - SET
-  - 'mkdir C:\ProgramData\PuppetLabs\code && exit 0'
-  - 'mkdir C:\ProgramData\PuppetLabs\facter && exit 0'
-  - 'mkdir C:\ProgramData\PuppetLabs\hiera && exit 0'
-  - 'mkdir C:\ProgramData\PuppetLabs\puppet\var && exit 0'
-environment:
-  matrix:
-    -
-      RUBY_VERSION: 25-x64
-      CHECK: validate lint check rubocop
-    -
-      PUPPET_GEM_VERSION: ~> 6.0
-      RUBY_VERSION: 25
-      CHECK: parallel_spec
-    -
-      PUPPET_GEM_VERSION: ~> 6.0
-      RUBY_VERSION: 25-x64
-      CHECK: parallel_spec
-matrix:
-  fast_finish: true
-install:
-  - set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
-  - bundle install --jobs 4 --retry 2 --without system_tests
-  - type Gemfile.lock
-build: off
-test_script:
-  - bundle exec puppet -V
-  - ruby -v
-  - gem -v
-  - bundle -v
-  - bundle exec rake %CHECK%
-notifications:
-  - provider: Email
-    to:
-      - nobody@nowhere.com
-    on_build_success: false
-    on_build_failure: false
-    on_build_status_changed: false
diff --git a/manifests/goose.pp b/manifests/goose.pp
index 683f94f..80162a6 100644
--- a/manifests/goose.pp
+++ b/manifests/goose.pp
@@ -17,7 +17,8 @@ class cfssl::goose {
     command     => '/usr/local/bin/go get bitbucket.org/liamstask/goose/cmd/goose',
     creates     => "/home/${cfssl::sysuser}/go/bin/goose",
     user        => $cfssl::sysuser,
-    environment => ["HOME=/home/${cfssl::sysuser}/"],
+    environment => ["HOME=/home/${cfssl::sysuser}"],
+    cwd         => '/tmp',
     require     => User[$cfssl::sysuser],
   }
 }
diff --git a/manifests/init.pp b/manifests/init.pp
index 537babf..daa922f 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -8,7 +8,7 @@ class cfssl (
   Hash $rootca_manifest = {},
   Stdlib::HTTPSUrl $downloadurl = 'https://github.com/cloudflare/cfssl/releases/download',
   String[1] $version = '1.6.3',
-  String[1] $downloadchecksum = '824ff707e54611e8911210a5e8e1afbf745bba1dab55babdeb1a39d85b2f8c10',
+  String[1] $downloadchecksum = '16b42bfc592dc4d0ba1e51304f466cae7257edec13743384caf4106195ab6047',
   Enum['md5', 'sha1', 'sha2','sha256', 'sha384', 'sha512'] $checksum_type = 'sha256',
   String[1] $sysuser = 'cfssl',
   String[1] $sysgroup = 'cfssl',
@@ -43,12 +43,12 @@ class cfssl (
     gid        => $sysgroup,
   }
 
-  archive::download { "${binpath}/cfssl" :
-    ensure        => present,
-    url           => "${downloadurl}/v${version}/cfssl_${version}_linux_amd64",
-    checksum      => true,
-    digest_type   => $checksum_type,
-    digest_string => $downloadchecksum,
+  archive { "${binpath}/cfssl" :
+    ensure          => present,
+    source          => "${downloadurl}/v${version}/cfssl_${version}_linux_amd64",
+    checksum_verify => true,
+    checksum_type   => $checksum_type,
+    checksum        => $downloadchecksum,
   }
   -> file { "${binpath}/cfssl" :
     ensure  => file,
@@ -61,12 +61,13 @@ class cfssl (
   $_binaries.each | String $_bin | {
     $_archiveurn = "v${version}/${_bin}_${version}_linux_amd64"
 
-    archive::download { "${binpath}/${_bin}" :
-      ensure    => present,
-      url       => "${downloadurl}/${_archiveurn}",
-      subscribe => Archive::Download["${binpath}/cfssl"],
+    archive { "${binpath}/${_bin}" :
+      ensure          => present,
+      source          => "${downloadurl}/${_archiveurn}",
+      checksum_verify => false,
+      subscribe       => Archive["${binpath}/cfssl"],
     }
-    ~> file { "${binpath}/${_bin}" :
+    -> file { "${binpath}/${_bin}" :
       ensure  => file,
       mode    => '0700',
       owner   => $sysuser,
@@ -136,8 +137,8 @@ class cfssl (
     require => [
       File[$cfssl::confdir],
       File["${cfssl::confdir}/ca"],
-      Archive::Download["${binpath}/cfssl"],
-      Archive::Download["${binpath}/cfssljson"],
+      Archive["${binpath}/cfssl"],
+      Archive["${binpath}/cfssljson"],
     ],
   }
 
@@ -152,14 +153,14 @@ class cfssl (
     ensure    => 'running',
     enable    => true,
     require   => [
-      Archive::Download["${binpath}/cfssl"],
+      Archive["${binpath}/cfssl"],
       Postgresql::Server::Db[$dbname],
       Exec['goose pg up'],
       File["${confdir}/${_serve_config_json}"],
       File["${confdir}/${_db_config_json}"],
       Class['cfssl::ca::root'],
     ],
-    subscribe => Archive::Download["${binpath}/cfssl"],
+    subscribe => Archive["${binpath}/cfssl"],
     provider  => 'systemd',
   }
 }
diff --git a/metadata.json b/metadata.json
index 00fd7dc..ce4a3a9 100644
--- a/metadata.json
+++ b/metadata.json
@@ -6,19 +6,28 @@
   "license": "AGPL-3.0",
   "source": "",
   "dependencies": [
-
-  ],
-  "operatingsystem_support": [
     {
-      "operatingsystem": "Debian",
-      "operatingsystemrelease": [
-        "10"
-      ]
+      "name": "puppetlabs/stdlib",
+      "version_requirement": ">= 4.17.0 < 9.0.0"
+    },
+    {
+      "name": "puppetlabs/vcsrepo",
+      "version_requirement": ">= 5.0.0 < 6.0.0"
     },
+    {
+      "name": "puppet/archive",
+      "version_requirement": ">= 4.0.0 < 7.0.0"
+    },
+    {
+      "name": "puppetlabs/postgresql",
+      "version_requirement": ">= 6.1.0 < 9.0.0"
+    }
+  ],
+  "operatingsystem_support": [
     {
       "operatingsystem": "Ubuntu",
       "operatingsystemrelease": [
-        "18.04"
+        "20.04"
       ]
     }
   ],
diff --git a/spec/acceptance/cfssl_spec.rb b/spec/acceptance/cfssl_spec.rb
new file mode 100644
index 0000000..86ad2d9
--- /dev/null
+++ b/spec/acceptance/cfssl_spec.rb
@@ -0,0 +1,24 @@
+require 'spec_helper_acceptance'
+
+describe 'cfssl' do
+  context 'with defaults' do
+    pp = %(
+      include cfssl
+    )
+
+    it 'applies without error' do
+      apply_manifest(pp, catch_failures: true)
+    end
+    it 'applies idempotently' do
+      apply_manifest(pp, catch_changes: true)
+    end
+
+    describe port(8080) do
+      it { is_expected.to be_listening.on('127.0.0.1').with('tcp') }
+    end
+
+    describe command('curl -s -d "{}" -H "Content-Type: application/json" -X POST 127.0.0.1:8080/api/v1/cfssl/info') do
+      its(:stdout) { is_expected.to match %r{BEGIN CERTIFICATE} }
+    end
+  end
+end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
new file mode 100644
index 0000000..1064aeb
--- /dev/null
+++ b/spec/spec_helper_acceptance.rb
@@ -0,0 +1,20 @@
+require 'beaker-rspec'
+require 'beaker-puppet'
+require 'beaker/puppet_install_helper'
+require 'beaker/module_install_helper'
+
+run_puppet_install_helper
+install_module_on(hosts)
+install_module_dependencies_on(hosts)
+
+RSpec.configure do |c|
+  # Configure all nodes in nodeset
+  c.before :suite do
+    # vcsrepo expect git already installed
+    # curl is used during tests to interact with CA
+    pp_prepare_sut = %(
+      package { ['git','curl']: ensure => present }
+    )
+    apply_manifest(pp_prepare_sut, catch_failures: true)
+  end
+end
-- 
GitLab