diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index fe7a8b12b9..cdd65d220a 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -5,7 +5,7 @@ "settings": { "terminal.integrated.profiles.linux": { "bash": { - "path": "bash", + "path": "bash" } } }, diff --git a/.fixtures.yml b/.fixtures.yml index 1fd983cde0..37bc6910f9 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -6,7 +6,7 @@ fixtures: provision: 'https://github.com/puppetlabs/provision.git' puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 stdlib: "https://github.com/puppetlabs/puppetlabs-stdlib.git" yumrepo_core: repo: "https://github.com/puppetlabs/puppetlabs-yumrepo_core.git" diff --git a/.rubocop.yml b/.rubocop.yml index a886d8dbfe..0d076d68c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,10 @@ require: - rubocop-rspec AllCops: DisplayCopNames: true - TargetRubyVersion: '2.5' + NewCops: enable + TargetRubyVersion: '2.7' + ExtraDetails: true + DisplayStyleGuide: true Include: - "**/*.rb" Exclude: @@ -80,441 +83,5 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -Performance/AncestorsInclude: - Enabled: true -Performance/BigDecimalWithNumericArgument: - Enabled: true -Performance/BlockGivenWithExplicitBlock: - Enabled: true -Performance/CaseWhenSplat: - Enabled: true -Performance/ConstantRegexp: - Enabled: true -Performance/MethodObjectAsBlock: - Enabled: true -Performance/RedundantSortBlock: - Enabled: true -Performance/RedundantStringChars: - Enabled: true -Performance/ReverseFirst: - Enabled: true -Performance/SortReverse: - Enabled: true -Performance/Squeeze: - Enabled: true -Performance/StringInclude: - Enabled: true -Performance/Sum: - Enabled: true -Style/CollectionMethods: - Enabled: true -Style/MethodCalledOnDoEndBlock: - Enabled: true -Style/StringMethods: - Enabled: true -Bundler/InsecureProtocolSource: - Enabled: false -Gemspec/DuplicatedAssignment: - Enabled: false -Gemspec/OrderedDependencies: - Enabled: false -Gemspec/RequiredRubyVersion: - Enabled: false -Gemspec/RubyVersionGlobalsUsage: - Enabled: false -Layout/ArgumentAlignment: - Enabled: false -Layout/BeginEndAlignment: - Enabled: false -Layout/ClosingHeredocIndentation: - Enabled: false -Layout/EmptyComment: - Enabled: false -Layout/EmptyLineAfterGuardClause: - Enabled: false -Layout/EmptyLinesAroundArguments: - Enabled: false -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: false -Layout/EndOfLine: - Enabled: false -Layout/FirstArgumentIndentation: - Enabled: false -Layout/HashAlignment: - Enabled: false -Layout/HeredocIndentation: - Enabled: false -Layout/LeadingEmptyLines: - Enabled: false -Layout/SpaceAroundMethodCallOperator: - Enabled: false -Layout/SpaceInsideArrayLiteralBrackets: - Enabled: false -Layout/SpaceInsideReferenceBrackets: - Enabled: false -Lint/BigDecimalNew: - Enabled: false -Lint/BooleanSymbol: - Enabled: false -Lint/ConstantDefinitionInBlock: - Enabled: false -Lint/DeprecatedOpenSSLConstant: - Enabled: false -Lint/DisjunctiveAssignmentInConstructor: - Enabled: false -Lint/DuplicateElsifCondition: - Enabled: false -Lint/DuplicateRequire: - Enabled: false -Lint/DuplicateRescueException: - Enabled: false -Lint/EmptyConditionalBody: - Enabled: false -Lint/EmptyFile: - Enabled: false -Lint/ErbNewArguments: - Enabled: false -Lint/FloatComparison: - Enabled: false -Lint/HashCompareByIdentity: - Enabled: false -Lint/IdentityComparison: - Enabled: false -Lint/InterpolationCheck: - Enabled: false -Lint/MissingCopEnableDirective: - Enabled: false -Lint/MixedRegexpCaptureTypes: - Enabled: false -Lint/NestedPercentLiteral: - Enabled: false -Lint/NonDeterministicRequireOrder: - Enabled: false -Lint/OrderedMagicComments: - Enabled: false -Lint/OutOfRangeRegexpRef: - Enabled: false -Lint/RaiseException: - Enabled: false -Lint/RedundantCopEnableDirective: - Enabled: false -Lint/RedundantRequireStatement: - Enabled: false -Lint/RedundantSafeNavigation: - Enabled: false -Lint/RedundantWithIndex: - Enabled: false -Lint/RedundantWithObject: - Enabled: false -Lint/RegexpAsCondition: - Enabled: false -Lint/ReturnInVoidContext: - Enabled: false -Lint/SafeNavigationConsistency: - Enabled: false -Lint/SafeNavigationWithEmpty: - Enabled: false -Lint/SelfAssignment: - Enabled: false -Lint/SendWithMixinArgument: - Enabled: false -Lint/ShadowedArgument: - Enabled: false -Lint/StructNewOverride: - Enabled: false -Lint/ToJSON: - Enabled: false -Lint/TopLevelReturnWithArgument: - Enabled: false -Lint/TrailingCommaInAttributeDeclaration: - Enabled: false -Lint/UnreachableLoop: - Enabled: false -Lint/UriEscapeUnescape: - Enabled: false -Lint/UriRegexp: - Enabled: false -Lint/UselessMethodDefinition: - Enabled: false -Lint/UselessTimes: - Enabled: false -Metrics/AbcSize: - Enabled: false -Metrics/BlockLength: - Enabled: false -Metrics/BlockNesting: - Enabled: false -Metrics/ClassLength: - Enabled: false -Metrics/CyclomaticComplexity: - Enabled: false -Metrics/MethodLength: - Enabled: false -Metrics/ModuleLength: - Enabled: false -Metrics/ParameterLists: - Enabled: false -Metrics/PerceivedComplexity: - Enabled: false -Migration/DepartmentName: - Enabled: false -Naming/AccessorMethodName: - Enabled: false -Naming/BlockParameterName: - Enabled: false -Naming/HeredocDelimiterCase: - Enabled: false -Naming/HeredocDelimiterNaming: - Enabled: false -Naming/MemoizedInstanceVariableName: - Enabled: false Naming/MethodParameterName: - Enabled: false -Naming/RescuedExceptionsVariableName: - Enabled: false -Naming/VariableNumber: - Enabled: false -Performance/BindCall: - Enabled: false -Performance/DeletePrefix: - Enabled: false -Performance/DeleteSuffix: - Enabled: false -Performance/InefficientHashSearch: - Enabled: false -Performance/UnfreezeString: - Enabled: false -Performance/UriDefaultParser: - Enabled: false -RSpec/Be: - Enabled: false -RSpec/Capybara/CurrentPathExpectation: - Enabled: false -RSpec/Capybara/FeatureMethods: - Enabled: false -RSpec/Capybara/VisibilityMatcher: - Enabled: false -RSpec/ContextMethod: - Enabled: false -RSpec/ContextWording: - Enabled: false -RSpec/DescribeClass: - Enabled: false -RSpec/EmptyHook: - Enabled: false -RSpec/EmptyLineAfterExample: - Enabled: false -RSpec/EmptyLineAfterExampleGroup: - Enabled: false -RSpec/EmptyLineAfterHook: - Enabled: false -RSpec/ExampleLength: - Enabled: false -RSpec/ExampleWithoutDescription: - Enabled: false -RSpec/ExpectChange: - Enabled: false -RSpec/ExpectInHook: - Enabled: false -RSpec/FactoryBot/AttributeDefinedStatically: - Enabled: false -RSpec/FactoryBot/CreateList: - Enabled: false -RSpec/FactoryBot/FactoryClassName: - Enabled: false -RSpec/HooksBeforeExamples: - Enabled: false -RSpec/ImplicitBlockExpectation: - Enabled: false -RSpec/ImplicitSubject: - Enabled: false -RSpec/LeakyConstantDeclaration: - Enabled: false -RSpec/LetBeforeExamples: - Enabled: false -RSpec/MissingExampleGroupArgument: - Enabled: false -RSpec/MultipleExpectations: - Enabled: false -RSpec/MultipleMemoizedHelpers: - Enabled: false -RSpec/MultipleSubjects: - Enabled: false -RSpec/NestedGroups: - Enabled: false -RSpec/PredicateMatcher: - Enabled: false -RSpec/ReceiveCounts: - Enabled: false -RSpec/ReceiveNever: - Enabled: false -RSpec/RepeatedExampleGroupBody: - Enabled: false -RSpec/RepeatedExampleGroupDescription: - Enabled: false -RSpec/RepeatedIncludeExample: - Enabled: false -RSpec/ReturnFromStub: - Enabled: false -RSpec/SharedExamples: - Enabled: false -RSpec/StubbedMock: - Enabled: false -RSpec/UnspecifiedException: - Enabled: false -RSpec/VariableDefinition: - Enabled: false -RSpec/VoidExpect: - Enabled: false -RSpec/Yield: - Enabled: false -Security/Open: - Enabled: false -Style/AccessModifierDeclarations: - Enabled: false -Style/AccessorGrouping: - Enabled: false -Style/AsciiComments: - Enabled: false -Style/BisectedAttrAccessor: - Enabled: false -Style/CaseLikeIf: - Enabled: false -Style/ClassEqualityComparison: - Enabled: false -Style/ColonMethodDefinition: - Enabled: false -Style/CombinableLoops: - Enabled: false -Style/CommentedKeyword: - Enabled: false -Style/Dir: - Enabled: false -Style/DoubleCopDisableDirective: - Enabled: false -Style/EmptyBlockParameter: - Enabled: false -Style/EmptyLambdaParameter: - Enabled: false -Style/Encoding: - Enabled: false -Style/EvalWithLocation: - Enabled: false -Style/ExpandPathArguments: - Enabled: false -Style/ExplicitBlockArgument: - Enabled: false -Style/ExponentialNotation: - Enabled: false -Style/FloatDivision: - Enabled: false -Style/FrozenStringLiteralComment: - Enabled: false -Style/GlobalStdStream: - Enabled: false -Style/HashAsLastArrayItem: - Enabled: false -Style/HashLikeCase: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: false -Style/IfUnlessModifier: - Enabled: false -Style/KeywordParametersOrder: - Enabled: false -Style/MinMax: - Enabled: false -Style/MixinUsage: - Enabled: false -Style/MultilineWhenThen: - Enabled: false -Style/NegatedUnless: - Enabled: false -Style/NumericPredicate: - Enabled: false -Style/OptionalBooleanParameter: - Enabled: false -Style/OrAssignment: - Enabled: false -Style/RandomWithOffset: - Enabled: false -Style/RedundantAssignment: - Enabled: false -Style/RedundantCondition: - Enabled: false -Style/RedundantConditional: - Enabled: false -Style/RedundantFetchBlock: - Enabled: false -Style/RedundantFileExtensionInRequire: - Enabled: false -Style/RedundantRegexpCharacterClass: - Enabled: false -Style/RedundantRegexpEscape: - Enabled: false -Style/RedundantSelfAssignment: - Enabled: false -Style/RedundantSort: - Enabled: false -Style/RescueStandardError: - Enabled: false -Style/SingleArgumentDig: - Enabled: false -Style/SlicingWithRange: - Enabled: false -Style/SoleNestedConditional: - Enabled: false -Style/StderrPuts: - Enabled: false -Style/StringConcatenation: - Enabled: false -Style/Strip: - Enabled: false -Style/SymbolProc: - Enabled: false -Style/TrailingBodyOnClass: - Enabled: false -Style/TrailingBodyOnMethodDefinition: - Enabled: false -Style/TrailingBodyOnModule: - Enabled: false -Style/TrailingCommaInHashLiteral: - Enabled: false -Style/TrailingMethodEndStatement: - Enabled: false -Style/UnpackFirst: - Enabled: false -Lint/DuplicateBranch: - Enabled: false -Lint/DuplicateRegexpCharacterClassElement: - Enabled: false -Lint/EmptyBlock: - Enabled: false -Lint/EmptyClass: - Enabled: false -Lint/NoReturnInBeginEndBlocks: - Enabled: false -Lint/ToEnumArguments: - Enabled: false -Lint/UnexpectedBlockArity: - Enabled: false -Lint/UnmodifiedReduceAccumulator: - Enabled: false -Performance/CollectionLiteralInLoop: - Enabled: false -Style/ArgumentsForwarding: - Enabled: false -Style/CollectionCompact: - Enabled: false -Style/DocumentDynamicEvalDefinition: - Enabled: false -Style/NegatedIfElseCondition: - Enabled: false -Style/NilLambda: - Enabled: false -Style/RedundantArgument: - Enabled: false -Style/SwapValues: - Enabled: false + AllowedNames: 'is' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9e99e20040..7295fd9d68 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,18 +1,158 @@ -Style/GlobalVars: +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-20 10:23:43 UTC using RuboCop version 1.48.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'spec/acceptance/mod_php_spec.rb' + - 'spec/spec_helper_acceptance_local.rb' + +# Offense count: 5 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 126 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 13 + +# Offense count: 7 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 101 + +# Offense count: 3 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 13 + +# Offense count: 2 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'spec/classes/mod/http2_spec.rb' + +# Offense count: 3 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to +Naming/MethodParameterName: + Exclude: + - 'spec/spec_helper_acceptance_local.rb' + - 'util/apache_mod_platform_support.rb' + +# Offense count: 2 +# Configuration parameters: MinSize. +Performance/CollectionLiteralInLoop: + Exclude: + - 'spec/classes/mod/passenger_spec.rb' + - 'spec/defines/vhost_spec.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +RSpec/BeEq: + Exclude: + - 'spec/functions/bool2httpd_spec.rb' + - 'spec/functions/pw_hash_spec.rb' + +# Offense count: 393 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: Enabled: false -RSpec/InstanceVariable: - Enabled: false -RSpec/RepeatedExample: - Enabled: false -RSpec/ExpectInHook: + +# Offense count: 95 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: Enabled: false + +# Offense count: 25 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 107 + +# Offense count: 6 +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: + Exclude: + - 'spec/classes/mod/lbmethod_bybusyness.rb' + - 'spec/classes/mod/lbmethod_byrequests.rb' + - 'spec/classes/mod/lbmethod_bytraffic.rb' + - 'spec/classes/mod/lbmethod_heartbeat.rb' + - 'spec/classes/mod/lookup_identity.rb' + - 'spec/classes/mod/proxy_wstunnel.rb' + +# Offense count: 16 +# This cop supports safe autocorrection. +RSpec/LetBeforeExamples: + Exclude: + - 'spec/classes/mod/auth_kerb_spec.rb' + - 'spec/classes/mod/auth_openidc_spec.rb' + - 'spec/classes/mod/cluster_spec.rb' + - 'spec/classes/mod/disk_cache_spec.rb' + - 'spec/classes/mod/jk_spec.rb' + - 'spec/classes/mod/proxy_balancer_spec.rb' + - 'spec/classes/mod/ssl_spec.rb' + - 'spec/classes/mod/wsgi_spec.rb' + - 'spec/classes/service_spec.rb' + +# Offense count: 17 +RSpec/MultipleExpectations: + Max: 8 + +# Offense count: 69 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 6 + +# Offense count: 291 +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only RSpec/NamedSubject: Enabled: false -RSpec/VoidExpect: + +# Offense count: 123 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 6 + +# Offense count: 101 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: Enabled: false -RSpec/AnyInstance: - Enabled: false -RSpec/FilePath: - Enabled: false -RSpec/EmptyExampleGroup: - Enabled: false + +# Offense count: 8 +RSpec/RepeatedExample: + Exclude: + - 'spec/classes/apache_spec.rb' + +# Offense count: 19 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'spec/acceptance/apache_parameters_spec.rb' + - 'spec/acceptance/apache_ssl_spec.rb' + - 'spec/acceptance/vhost_spec.rb' + - 'spec/classes/mod/remoteip_spec.rb' + - 'spec/functions/pw_hash_spec.rb' + +# Offense count: 18 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'spec/acceptance/apache_parameters_spec.rb' + - 'spec/acceptance/vhost_spec.rb' + - 'spec/classes/apache_spec.rb' + - 'spec/classes/mod/security_spec.rb' + +# Offense count: 4 +RSpec/StubbedMock: + Exclude: + - 'spec/util/apache_mod_platform_compatibility_spec.rb' diff --git a/Gemfile b/Gemfile index 1881afe150..7fad5040d0 100644 --- a/Gemfile +++ b/Gemfile @@ -14,31 +14,31 @@ def location_for(place_or_version, fake_version = nil) end group :development do - gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) - gem "voxpupuli-puppet-lint-plugins", '~> 3.1', require: false - gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false - gem "puppetlabs_spec_helper", '>= 3.0.0', '< 5.0.0', require: false - gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false - gem "dependency_checker", '~> 0.2', require: false - gem "parallel_tests", '~> 3.4', require: false - gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false - gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.6.1', require: false - gem "rubocop-performance", '= 1.9.1', require: false - gem "rubocop-rspec", '= 2.0.1', require: false - gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] - gem "github_changelog_generator", '= 1.15.2', require: false + gem "json", '= 2.1.0', require: false if Gem::Requirement.create(['>= 2.5.0', '< 2.7.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.3.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.5.1', require: false if Gem::Requirement.create(['>= 3.0.0', '< 3.0.5']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.1', require: false if Gem::Requirement.create(['>= 3.1.0', '< 3.1.3']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "json", '= 2.6.3', require: false if Gem::Requirement.create(['>= 3.2.0', '< 4.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) + gem "voxpupuli-puppet-lint-plugins", '~> 4.0', require: false + gem "facterdb", '~> 1.18', require: false + gem "metadata-json-lint", '>= 2.0.2', '< 4.0.0', require: false + gem "puppetlabs_spec_helper", '~> 5.0', require: false + gem "rspec-puppet-facts", '~> 2.0', require: false + gem "codecov", '~> 0.2', require: false + gem "dependency_checker", '~> 0.2', require: false + gem "parallel_tests", '= 3.12.1', require: false + gem "pry", '~> 0.10', require: false + gem "simplecov-console", '~> 0.5', require: false + gem "puppet-debugger", '~> 1.0', require: false + gem "rubocop", '~> 1.48.1', require: false + gem "rubocop-performance", '~> 1.16', require: false + gem "rubocop-rspec", '~> 2.19', require: false + gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] + gem "github_changelog_generator", '= 1.15.2', require: false end group :system_tests do - gem "puppet_litmus", '<= 0.34.6', require: false, platforms: [:ruby] - gem "serverspec", '~> 2.41', require: false + gem "puppet_litmus", '< 1.0.0', require: false, platforms: [:ruby, :x64_mingw] + gem "serverspec", '~> 2.41', require: false end puppet_version = ENV['PUPPET_GEM_VERSION'] diff --git a/Rakefile b/Rakefile index 47ff253418..3cf60463bd 100644 --- a/Rakefile +++ b/Rakefile @@ -4,7 +4,6 @@ require 'bundler' require 'puppet_litmus/rake_tasks' if Bundler.rubygems.find_name('puppet_litmus').any? require 'puppetlabs_spec_helper/rake_tasks' require 'puppet-syntax/tasks/puppet-syntax' -require 'puppet_blacksmith/rake_tasks' if Bundler.rubygems.find_name('puppet-blacksmith').any? require 'github_changelog_generator/task' if Bundler.rubygems.find_name('github_changelog_generator').any? require 'puppet-strings/tasks' if Bundler.rubygems.find_name('puppet-strings').any? diff --git a/lib/puppet/functions/apache/bool2httpd.rb b/lib/puppet/functions/apache/bool2httpd.rb index 1fb71c590c..b864c8675f 100644 --- a/lib/puppet/functions/apache/bool2httpd.rb +++ b/lib/puppet/functions/apache/bool2httpd.rb @@ -21,6 +21,7 @@ def bool2httpd(arg) return 'Off' if arg.nil? || arg == false || matches_string?(arg, %r{false}i) || arg == :undef return 'On' if arg == true || matches_string?(arg, %r{true}i) + arg.to_s end diff --git a/lib/puppet/functions/apache/pw_hash.rb b/lib/puppet/functions/apache/pw_hash.rb index c56e916b9e..6a1630b546 100644 --- a/lib/puppet/functions/apache/pw_hash.rb +++ b/lib/puppet/functions/apache/pw_hash.rb @@ -18,6 +18,6 @@ def apache_pw_hash(password) require 'base64' - '{SHA}' + Base64.strict_encode64(Digest::SHA1.digest(password)) + "{SHA}#{Base64.strict_encode64(Digest::SHA1.digest(password))}" end end diff --git a/lib/puppet/provider/a2mod.rb b/lib/puppet/provider/a2mod.rb index 7406e01da3..bc0899e2d5 100644 --- a/lib/puppet/provider/a2mod.rb +++ b/lib/puppet/provider/a2mod.rb @@ -6,9 +6,7 @@ class Puppet::Provider::A2mod < Puppet::Provider def self.prefetch(mods) instances.each do |prov| mod = mods[prov.name] - if mod - mod.provider = prov - end + mod.provider = prov if mod end end @@ -29,9 +27,7 @@ def properties # Returns the properties of the given mod if it exists. def query self.class.instances.each do |mod| - if mod.name == name || mod.name.downcase == name - return mod.properties - end + return mod.properties if mod.name == name || mod.name.downcase == name end nil end diff --git a/manifests/vhost.pp b/manifests/vhost.pp index ae99f4545e..f598fb3ffd 100644 --- a/manifests/vhost.pp +++ b/manifests/vhost.pp @@ -2145,7 +2145,7 @@ allow_override => $override, directoryindex => $directoryindex, require => 'all granted', - } + }, ] } else { $_directories = undef diff --git a/metadata.json b/metadata.json index 9bc7957c24..94af5b9602 100644 --- a/metadata.json +++ b/metadata.json @@ -14,7 +14,7 @@ }, { "name": "puppetlabs/concat", - "version_requirement": ">= 2.2.1 < 8.0.0" + "version_requirement": ">= 2.2.1 < 9.0.0" } ], "operatingsystem_support": [ @@ -83,11 +83,11 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">= 6.24.0 < 8.0.0" + "version_requirement": ">= 7.0.0 < 9.0.0" } ], "description": "Module for Apache configuration", - "pdk-version": "2.5.0", + "pdk-version": "2.7.1", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "2.7.1-0-g9a16c87" + "template-ref": "heads/main-0-ge5b0114" } diff --git a/spec/acceptance/apache_parameters_spec.rb b/spec/acceptance/apache_parameters_spec.rb index 501a4a9baf..28ba8f547f 100644 --- a/spec/acceptance/apache_parameters_spec.rb +++ b/spec/acceptance/apache_parameters_spec.rb @@ -16,6 +16,7 @@ end end end + describe 'default_confd_files => true' do it 'copies conf.d files' do pp = "class { 'apache': default_confd_files => true }" @@ -137,6 +138,7 @@ class { 'apache': describe file("#{apache_hash['confd_dir']}/test.conf") do it { is_expected.to be_file } end + describe file("#{apache_hash['confd_dir']}.vhosts/test.conf") do it { is_expected.to be_file } end @@ -161,6 +163,7 @@ class { 'apache': describe file("#{apache_hash['confd_dir']}/test.conf") do it { is_expected.not_to be_file } end + describe file("#{apache_hash['confd_dir']}.vhosts/test.conf") do it { is_expected.not_to be_file } end @@ -364,8 +367,8 @@ class { 'apache': pp = <<-MANIFEST class { 'apache': log_formats => { - 'vhost_common' => '%v %h %l %u %t \\\"%r\\\" %>s %b', - 'vhost_combined' => '%v %h %l %u %t \\\"%r\\\" %>s %b \\\"%{Referer}i\\\" \\\"%{User-agent}i\\\"', + 'vhost_common' => '%v %h %l %u %t \\"%r\\" %>s %b', + 'vhost_combined' => '%v %h %l %u %t \\"%r\\" %>s %b \\"%{Referer}i\\" \\"%{User-agent}i\\"', } } MANIFEST diff --git a/spec/acceptance/apache_ssl_spec.rb b/spec/acceptance/apache_ssl_spec.rb index 5e1c5909b6..08b249c9e4 100644 --- a/spec/acceptance/apache_ssl_spec.rb +++ b/spec/acceptance/apache_ssl_spec.rb @@ -23,6 +23,7 @@ class { 'apache': describe file("#{apache_hash['mod_ssl_dir']}/ssl.conf") do it { is_expected.to be_file } + if os[:family].include?('redhat') && os[:release].to_i >= 8 it { is_expected.not_to contain 'SSLProtocol' } elsif ['debian', 'ubuntu'].include?(os[:family]) @@ -40,6 +41,7 @@ class { 'apache': it { is_expected.to contain 'SSLCACertificateFile "/tmp/ssl_ca"' } it { is_expected.to contain 'SSLCARevocationPath "/tmp/ssl_crl_path"' } it { is_expected.to contain 'SSLCARevocationFile "/tmp/ssl_crl"' } + if apache_hash['version'] == '2.4' it { is_expected.to contain 'SSLCARevocationCheck chain' } else @@ -107,6 +109,7 @@ class { 'apache': it { is_expected.to contain 'SSLVerifyClient require' } it { is_expected.to contain 'SSLVerifyDepth 1' } it { is_expected.to contain 'SSLOptions test test1' } + if apache_hash['version'] == '2.4' it { is_expected.to contain 'SSLCARevocationCheck chain flag' } else diff --git a/spec/acceptance/itk_spec.rb b/spec/acceptance/itk_spec.rb index c5ef34b9c4..914cc7aeb5 100644 --- a/spec/acceptance/itk_spec.rb +++ b/spec/acceptance/itk_spec.rb @@ -28,13 +28,13 @@ class { 'apache': mpm_module => 'prefork', } class { 'apache::mod::itk': } - MANIFEST + MANIFEST when :itk_only <<-MANIFEST class { 'apache': mpm_module => 'itk', } - MANIFEST + MANIFEST end end diff --git a/spec/acceptance/mod_authnz_ldap_spec.rb b/spec/acceptance/mod_authnz_ldap_spec.rb index 82615ab624..aa92bcf51b 100644 --- a/spec/acceptance/mod_authnz_ldap_spec.rb +++ b/spec/acceptance/mod_authnz_ldap_spec.rb @@ -18,12 +18,12 @@ } class { 'apache': } class { 'apache::mod::authnz_ldap': } - MANIFEST + MANIFEST else <<-MANIFEST class { 'apache': } class { 'apache::mod::authnz_ldap': } - MANIFEST + MANIFEST end it 'succeeds in installing the mod_authnz_ldap module' do diff --git a/spec/acceptance/vhost_spec.rb b/spec/acceptance/vhost_spec.rb index fd412d9fff..da2867d162 100644 --- a/spec/acceptance/vhost_spec.rb +++ b/spec/acceptance/vhost_spec.rb @@ -10,11 +10,11 @@ class { 'apache': default_ssl_vhost => false, service_ensure => stopped, } - if ($::osfamily == 'Suse' and $::operatingsystemrelease < '15') { + if ($facts['os']['family'] == 'Suse' and $facts['os']['release']['major'] < '15') { exec { '/usr/bin/gensslcert': require => Class['apache'], } - } elsif ($::osfamily == 'Suse' and $::operatingsystemrelease >= '15') { + } elsif ($facts['os']['family'] == 'Suse' and $facts['os']['release']['major'] >= '15') { # In SLES 15, if not given a name, gensslcert defaults the name to be the hostname exec { '/usr/bin/gensslcert -n default': require => Class['apache'], @@ -125,7 +125,7 @@ class { 'apache': } it { is_expected.to contain 'ProxyPreserveHost On' } it { is_expected.to contain 'ProxyErrorOverride On' } it { is_expected.not_to contain 'ProxyAddHeaders' } - it { is_expected.not_to contain "" } + it { is_expected.not_to contain '' } end end @@ -153,7 +153,7 @@ class { 'apache': } it { is_expected.to contain 'ProxyPreserveHost On' } it { is_expected.to contain 'ProxyErrorOverride On' } it { is_expected.not_to contain 'ProxyAddHeaders' } - it { is_expected.not_to contain "" } + it { is_expected.not_to contain '' } end end @@ -276,9 +276,9 @@ class { 'apache': class { 'apache': } if versioncmp('#{apache_hash['version']}', '2.4') >= 0 { - $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', } + $_files_match_directory = { 'path' => '(.swp|.bak|~)$', 'provider' => 'filesmatch', 'require' => 'all denied', } } else { - $_files_match_directory = { 'path' => '(\.swp|\.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', } + $_files_match_directory = { 'path' => '(.swp|.bak|~)$', 'provider' => 'filesmatch', 'deny' => 'from all', } } $_directories = [ @@ -299,7 +299,7 @@ class { 'apache': } content => "Hello World\\n", } host { 'files.example.net': ip => '127.0.0.1', } - MANIFEST + MANIFEST end describe 'readme example, adapted' do @@ -315,6 +315,7 @@ class { 'apache': } it 'answers to files.example.net #stdout' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") end + it 'answers to files.example.net #stderr' do result = run_shell('/usr/bin/curl -sSf files.example.net:80/index.html.bak', expect_failures: true) expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) @@ -369,14 +370,17 @@ class { 'apache': } it 'answers to files.example.net #stdout' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/').stdout).to eq("Hello World\n") end + it 'answers to files.example.net #stdout foo' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/foo/').stdout).to eq("Hello Foo\n") end + it 'answers to files.example.net #stderr' do result = run_shell('/usr/bin/curl -sSf files.example.net:80/private.html', expect_failures: true) expect(result.stderr).to match(%r{curl: \(22\) The requested URL returned error: 403}) expect(result.exit_code).to eq 22 end + it 'answers to files.example.net #stdout bar' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/bar/bar.html').stdout).to eq("Hello Bar\n") end @@ -411,6 +415,7 @@ class { 'apache': } it 'answers to files.example.net #stdout' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/index.html').stdout).to eq("Hello World\n") end + it 'answers to files.example.net #stdout regex' do expect(run_shell('/usr/bin/curl -sSf files.example.net:80/server-status?auto').stdout).to match(%r{Scoreboard: }) end @@ -576,6 +581,7 @@ class { 'apache': default_vhost => false, } expect(r.stdout).to eq("Hello from localhost\n") end end + it 'gets a response from the back end #exit_code' do run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.exit_code).to eq(0) @@ -621,6 +627,7 @@ class { 'apache': default_vhost => false, } expect(r.stdout).to eq("Hello from localhost\n") end end + it 'gets a response from the back end #exit_code' do run_shell('/usr/bin/curl --max-redirs 0 proxy.example.com:80') do |r| expect(r.exit_code).to eq(0) @@ -646,6 +653,7 @@ class { 'apache': } it { is_expected.to be_file } it { is_expected.not_to contain 'NameVirtualHost test.server' } end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ServerName test.server' } @@ -670,6 +678,7 @@ class { 'apache': } it { is_expected.to be_file } it { is_expected.not_to contain 'NameVirtualHost test.server' } end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.not_to contain 'ServerName' } @@ -776,14 +785,14 @@ class { 'apache': } apache::vhost { 'test.setenv_setenvif': docroot => '/tmp', setenv => ['TEST /test'], - setenvif => ['Request_URI "\.gif$" object_is_image=gif'] + setenvif => ['Request_URI ".gif$" object_is_image=gif'] } apache::vhost { 'test.rewrite': docroot => '/tmp', rewrites => [ { comment => 'test', rewrite_cond => '%{HTTP_USER_AGENT} ^Lynx/ [OR]', - rewrite_rule => ['^index\.html$ welcome.html'], + rewrite_rule => ['^index.html$ welcome.html'], rewrite_map => ['lc int:tolower'], } ], @@ -865,27 +874,33 @@ class { 'apache': } it { is_expected.to be_file } it { is_expected.to contain 'AssignUserId nobody nobody' } end + describe file("#{apache_hash['vhost_dir']}/25-test.custom_fragment.conf") do it { is_expected.to be_file } it { is_expected.to contain '#weird test string' } end + describe file("#{apache_hash['vhost_dir']}/test.without_priority_prefix.conf") do it { is_expected.to be_file } end + describe file("#{apache_hash['vhost_dir']}/25-test.ssl_protocol.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SSLProtocol *All -SSLv2' } it { is_expected.to contain 'SSLUserName *SSL_CLIENT_S_DN_CN' } end + describe file("#{apache_hash['vhost_dir']}/25-test.block.conf") do it { is_expected.to be_file } it { is_expected.to contain '' } end + describe file("#{apache_hash['vhost_dir']}/25-test.setenv_setenvif.conf") do it { is_expected.to be_file } it { is_expected.to contain 'SetEnv TEST /test' } it { is_expected.to contain 'SetEnvIf Request_URI "\.gif$" object_is_image=gif' } end + describe file("#{apache_hash['vhost_dir']}/25-test.rewrite.conf") do it { is_expected.to be_file } it { is_expected.to contain '#test' } @@ -893,32 +908,39 @@ class { 'apache': } it { is_expected.to contain 'RewriteRule ^index.html$ welcome.html' } it { is_expected.to contain 'RewriteMap lc int:tolower' } end + describe file("#{apache_hash['vhost_dir']}/25-test.request_headers.conf") do it { is_expected.to be_file } it { is_expected.to contain 'append MirrorID "mirror 12"' } end + describe file("#{apache_hash['vhost_dir']}/25-test.redirect.conf") do it { is_expected.to be_file } it { is_expected.to contain 'Redirect permanent /images http://test.server/' } end + describe file("#{apache_hash['vhost_dir']}/25-test.no_proxy_uris.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ProxyPass http://test2/test !' } it { is_expected.to contain 'ProxyPass / http://test2/' } end + describe file("#{apache_hash['vhost_dir']}/25-test.proxy.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ProxyPass / http://testproxy/' } end + describe file("#{apache_hash['vhost_dir']}/25-test.scriptaliases.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } end + describe file("#{apache_hash['vhost_dir']}/25-test.aliases.conf") do it { is_expected.to be_file } it { is_expected.to contain 'Alias /image "/ftp/pub/image"' } it { is_expected.to contain 'ScriptAlias /myscript "/usr/share/myscript"' } end + describe file("#{apache_hash['vhost_dir']}/25-test.access_logs.conf") do it { is_expected.to be_file } it { is_expected.to contain 'CustomLog "/tmp/log1" combined' } @@ -926,26 +948,32 @@ class { 'apache': } it { is_expected.to contain 'CustomLog "/var/tmp/log3" "%h %l"' } it { is_expected.to contain 'CustomLog "syslog" combined' } end + describe file("#{apache_hash['vhost_dir']}/25-test.access_log_env_var.conf") do it { is_expected.to be_file } it { is_expected.to contain 'CustomLog "syslog" combined env=admin' } end + describe file("#{apache_hash['vhost_dir']}/25-test.access_log_format.conf") do it { is_expected.to be_file } it { is_expected.to contain 'CustomLog "syslog" "%h %l"' } end + describe file("#{apache_hash['vhost_dir']}/25-test.logroot.conf") do it { is_expected.to be_file } it { is_expected.to contain ' CustomLog "/tmp' } end + describe file("#{apache_hash['vhost_dir']}/25-test.override.conf") do it { is_expected.to be_file } it { is_expected.to contain 'AllowOverride All' } end + describe file("#{apache_hash['vhost_dir']}/25-test.options.conf") do it { is_expected.to be_file } it { is_expected.to contain 'Options Indexes FollowSymLinks ExecCGI' } end + describe file("#{apache_hash['vhost_dir']}/25-test.empty_options.conf") do it { is_expected.to be_file } it { is_expected.not_to contain 'Options' } @@ -967,12 +995,14 @@ class { 'apache': } it 'applies cleanly' do _result = apply_manifest(pp, catch_failures: true) end + describe file("#{apache_hash['vhost_dir']}/25-test.servername.conf") do it { is_expected.to be_file } it { is_expected.to contain ' ErrorLog "/tmp/test.servername_error.log' } it { is_expected.to contain ' CustomLog "/tmp/test.servername_access.log' } end end + describe 'when the $use_servername_for_filenames parameter is NOT defined' do pp = <<-MANIFEST class { 'apache': } @@ -986,6 +1016,7 @@ class { 'apache': } it 'applies cleanly' do _result = apply_manifest(pp, catch_failures: true) end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain ' ErrorLog "/tmp/test.server_error.log' } @@ -1135,7 +1166,6 @@ class { 'apache::mod::wsgi': } docroot => '/tmp', wsgi_application_group => '%{GLOBAL}', wsgi_daemon_process => { 'wsgi' => { 'python-home' => '/usr' }, 'foo' => {} }, - wsgi_daemon_process_options => {processes => 2}, wsgi_import_script => '/test1', wsgi_import_script_options => { application-group => '%{GLOBAL}', process-group => 'wsgi' }, wsgi_process_group => 'nobody', @@ -1148,6 +1178,7 @@ class { 'apache::mod::wsgi': } it 'import_script applies cleanly' do apply_manifest(pp, catch_failures: true) end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'WSGIApplicationGroup %{GLOBAL}' } @@ -1213,6 +1244,7 @@ class { 'apache::mod::shib': } it 'applies cleanly' do apply_manifest(pp, catch_failures: true) end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'ShibCompatValidUser On' } @@ -1242,6 +1274,7 @@ class { 'apache': } it 'applys cleanly' do apply_manifest(pp, catch_failures: true) end + describe file("#{apache_hash['vhost_dir']}/25-test.server.conf") do it { is_expected.to be_file } it { is_expected.to contain 'OIDCProviderMetadataURL https://login.example.com/.well-known/openid-configuration' } diff --git a/spec/classes/apache_spec.rb b/spec/classes/apache_spec.rb index 0d5cda12ae..c1b8262459 100644 --- a/spec/classes/apache_spec.rb +++ b/spec/classes/apache_spec.rb @@ -7,60 +7,71 @@ include_examples 'Debian 11' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_package('httpd').with( + expect(subject).to contain_package('httpd').with( 'notify' => 'Class[Apache::Service]', 'ensure' => 'installed', ) } + it { is_expected.to contain_user('www-data') } it { is_expected.to contain_group('www-data') } it { is_expected.to contain_class('apache::service') } + it { - is_expected.to contain_file('/var/www/html').with( + expect(subject).to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } + it { - is_expected.to contain_file('/etc/apache2/sites-enabled').with( + expect(subject).to contain_file('/etc/apache2/sites-enabled').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_file('/etc/apache2/mods-enabled').with( + expect(subject).to contain_file('/etc/apache2/mods-enabled').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_file('/etc/apache2/mods-available').with( + expect(subject).to contain_file('/etc/apache2/mods-available').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'false' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { is_expected.to contain_file('/etc/apache2/apache2.conf').without_content(%r{ServerAdmin}) } + it { - is_expected.to contain_concat('/etc/apache2/ports.conf').with( + expect(subject).to contain_concat('/etc/apache2/ports.conf').with( 'owner' => 'root', 'group' => 'root', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } + # Assert that load files are placed and symlinked for these mods, but no conf file. ['auth_basic', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with( - 'path' => "/etc/apache2/mods-available/#{modname}.load", + expect(subject).to contain_file("#{modname}.load").with( + 'path' => "/etc/apache2/mods-available/#{modname}.load", 'ensure' => 'file', ) } + it { - is_expected.to contain_file("#{modname}.load symlink").with( - 'path' => "/etc/apache2/mods-enabled/#{modname}.load", + expect(subject).to contain_file("#{modname}.load symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.load", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.load", ) } + it { is_expected.not_to contain_file("#{modname}.conf") } it { is_expected.not_to contain_file("#{modname}.conf symlink") } end @@ -68,7 +79,7 @@ context 'with use_optional_includes' do let :params do { - use_optional_includes: true, + use_optional_includes: true } end @@ -78,7 +89,7 @@ context 'with serveradmin' do let(:params) do { - serveradmin: 'admin@example.com', + serveradmin: 'admin@example.com' } end @@ -120,27 +131,30 @@ # Assert that both load files and conf files are placed and symlinked for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with( - 'path' => "/etc/apache2/mods-available/#{modname}.load", + expect(subject).to contain_file("#{modname}.load").with( + 'path' => "/etc/apache2/mods-available/#{modname}.load", 'ensure' => 'file', ) } + it { - is_expected.to contain_file("#{modname}.load symlink").with( - 'path' => "/etc/apache2/mods-enabled/#{modname}.load", + expect(subject).to contain_file("#{modname}.load symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.load", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.load", ) } + it { - is_expected.to contain_file("#{modname}.conf").with( - 'path' => "/etc/apache2/mods-available/#{modname}.conf", + expect(subject).to contain_file("#{modname}.conf").with( + 'path' => "/etc/apache2/mods-available/#{modname}.conf", 'ensure' => 'file', ) } + it { - is_expected.to contain_file("#{modname}.conf symlink").with( - 'path' => "/etc/apache2/mods-enabled/#{modname}.conf", + expect(subject).to contain_file("#{modname}.conf symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.conf", 'ensure' => 'link', 'target' => "/etc/apache2/mods-available/#{modname}.conf", ) @@ -155,6 +169,7 @@ it { is_expected.not_to contain_user('www-data') } it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^User www-data\n} } end + describe "Don't create group resource when parameter manage_group is false" do let :params do { manage_group: false } @@ -167,40 +182,41 @@ describe 'Add extra LogFormats When parameter log_formats is a hash' do let :params do { log_formats: { - 'vhost_common' => '%v %h %l %u %t "%r" %>s %b', - 'vhost_combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"', + 'vhost_common' => '%v %h %l %u %t "%r" %>s %b', + 'vhost_combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"' } } end - it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" vhost_common\n} } - it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" vhost_combined\n} } + it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^LogFormat "%v %h %l %u %t "%r" %>s %b" vhost_common\n} } + it { is_expected.to contain_file('/etc/apache2/apache2.conf').with_content %r{^LogFormat "%v %h %l %u %t "%r" %>s %b "%\{Referer\}i" "%\{User-agent\}i"" vhost_combined\n} } end describe 'Override existing LogFormats When parameter log_formats is a hash' do let :params do { log_formats: { - 'common' => '%v %h %l %u %t "%r" %>s %b', - 'combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"', + 'common' => '%v %h %l %u %t "%r" %>s %b', + 'combined' => '%v %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-agent}i"' } } end expected = [ - %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n}, - %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b" common\n}, - %r{^LogFormat "%v %h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, + %r{^LogFormat "%v %h %l %u %t "%r" %>s %b" common\n}, + %r{^LogFormat "%v %h %l %u %t "%r" %>s %b" common\n}, + %r{^LogFormat "%v %h %l %u %t "%r" %>s %b "%\{Referer\}i" "%\{User-agent\}i"" combined\n}, ] unexpected = [ - %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, - %r{^LogFormat "%h %l %u %t \"%r\" %>s %b \"%\{Referer\}i\" \"%\{User-agent\}i\"" combined\n}, + %r{^LogFormat "%h %l %u %t "%r" %>s %b "%\{Referer\}i" "%\{User-agent\}i"" combined\n}, + %r{^LogFormat "%h %l %u %t "%r" %>s %b "%\{Referer\}i" "%\{User-agent\}i"" combined\n}, ] it 'Expected to contain' do expected.each do |reg| - is_expected.to contain_file('/etc/apache2/apache2.conf').with_content reg + expect(subject).to contain_file('/etc/apache2/apache2.conf').with_content reg end end + it 'Not expected to contain' do unexpected.each do |reg| - is_expected.to contain_file('/etc/apache2/apache2.conf').without_content reg + expect(subject).to contain_file('/etc/apache2/apache2.conf').without_content reg end end end @@ -218,7 +234,7 @@ include_examples 'Ubuntu 18.04' it { - is_expected.to contain_file('/var/www/html').with( + expect(subject).to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } @@ -229,44 +245,50 @@ include_examples 'RedHat 8' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_package('httpd').with( + expect(subject).to contain_package('httpd').with( 'notify' => 'Class[Apache::Service]', 'ensure' => 'installed', ) } + it { is_expected.to contain_user('apache') } it { is_expected.to contain_group('apache') } it { is_expected.to contain_class('apache::service') } + it { - is_expected.to contain_file('/var/www/html').with( + expect(subject).to contain_file('/var/www/html').with( 'ensure' => 'directory', ) } + it { - is_expected.to contain_file('/etc/httpd/conf.d').with( + expect(subject).to contain_file('/etc/httpd/conf.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_concat('/etc/httpd/conf/ports.conf').with( + expect(subject).to contain_concat('/etc/httpd/conf/ports.conf').with( 'owner' => 'root', 'group' => 'root', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } + describe 'Alternate confd/mod/vhosts directory' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', - mod_dir: '/etc/httpd/mod.d', + mod_dir: '/etc/httpd/mod.d' } end ['mod.d', 'site.d', 'conf.d'].each do |dir| it { - is_expected.to contain_file("/etc/httpd/#{dir}").with( + expect(subject).to contain_file("/etc/httpd/#{dir}").with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') @@ -276,12 +298,13 @@ # Assert that load files are placed for these mods, but no conf file. ['auth_basic', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with_path( + expect(subject).to contain_file("#{modname}.load").with_path( "/etc/httpd/mod.d/#{modname}.load", ) } + it { - is_expected.not_to contain_file("#{modname}.conf").with_path( + expect(subject).not_to contain_file("#{modname}.conf").with_path( "/etc/httpd/mod.d/#{modname}.conf", ) } @@ -290,12 +313,13 @@ # Assert that both load files and conf files are placed for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with_path( + expect(subject).to contain_file("#{modname}.load").with_path( "/etc/httpd/mod.d/#{modname}.load", ) } + it { - is_expected.to contain_file("#{modname}.conf").with_path( + expect(subject).to contain_file("#{modname}.conf").with_path( "/etc/httpd/mod.d/#{modname}.conf", ) } @@ -305,25 +329,27 @@ it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.conf"$} } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^Include "/etc/httpd/mod\.d/\*\.load"$} } end + describe 'Alternate confd/mod/vhosts directory' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', - use_optional_includes: true, + use_optional_includes: true } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^IncludeOptional "/etc/httpd/conf\.d/\*\.conf"$} } end + describe 'Alternate confd/mod/vhosts directory when specifying slash encoding behaviour' do let :params do { vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', - allow_encoded_slashes: 'nodecode', + allow_encoded_slashes: 'nodecode' } end @@ -336,7 +362,7 @@ vhost_dir: '/etc/httpd/site.d', confd_dir: '/etc/httpd/conf.d', mod_dir: '/etc/httpd/mod.d', - default_charset: 'none', + default_charset: 'none' } end @@ -349,7 +375,7 @@ end it { - is_expected.to contain_file('/opt/rh/root/etc/httpd/conf/httpd.conf').with( + expect(subject).to contain_file('/opt/rh/root/etc/httpd/conf/httpd.conf').with( 'ensure' => 'file', ).that_notifies('Class[Apache::Service]').that_requires(['Package[httpd]', 'Concat[/etc/httpd/conf/ports.conf]']) } @@ -361,7 +387,7 @@ end it { - is_expected.to contain_file('/etc/httpd/special_conf.d').with( + expect(subject).to contain_file('/etc/httpd/special_conf.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') @@ -376,10 +402,11 @@ unexpected = ['apache::mod::event', 'apache::mod::itk', 'apache::mod::peruser', 'apache::mod::prefork', 'apache::mod::worker'] it 'does not declare mpm modules' do unexpected.each do |not_expect| - is_expected.not_to contain_class(not_expect) + expect(subject).not_to contain_class(not_expect) end end end + describe 'Alternate mpm_modules when declaring mpm_module => prefork' do let :params do { mpm_module: 'prefork' } @@ -391,6 +418,7 @@ it { is_expected.not_to contain_class('apache::mod::peruser') } it { is_expected.not_to contain_class('apache::mod::worker') } end + describe 'Alternate mpm_modules when declaring mpm_module => worker' do let :params do { mpm_module: 'worker' } @@ -410,6 +438,7 @@ it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^# Security\n} } end + describe 'different templates for httpd.conf with non-default' do let :params do { conf_template: 'site_apache/fake.conf.erb' } @@ -426,6 +455,7 @@ it { is_expected.to contain_apache__mod('authz_host') } it { is_expected.not_to contain_apache__mod('env') } end + describe 'default mods custom' do let :params do { default_mods: ['info', 'alias', 'mime', 'env', 'setenv', 'expires'] } @@ -436,6 +466,7 @@ it { is_expected.to contain_class('apache::mod::info') } it { is_expected.to contain_class('apache::mod::mime') } end + describe "Don't create user resource when parameter manage_user is false" do let :params do { manage_user: false } @@ -444,6 +475,7 @@ it { is_expected.not_to contain_user('apache') } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^User apache\n} } end + describe "Don't create group resource when parameter manage_group is false" do let :params do { manage_group: false } @@ -464,6 +496,7 @@ }.to raise_error(Puppet::PreformattedError, %r{Evaluation Error: Error while evaluating a Resource Statement, Class\[Apache\]: parameter 'sendfile' expects a match for Enum\['Off', 'On', 'off', 'on'\]}) # rubocop:disable Layout/LineLength end end + describe 'sendfile On' do let :params do { sendfile: 'On' } @@ -471,6 +504,7 @@ it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^EnableSendfile On\n} } end + describe 'sendfile Off' do let :params do { sendfile: 'Off' } @@ -490,6 +524,7 @@ }.to raise_error(Puppet::Error, %r{Evaluation Error}) end end + describe 'hostname_lookups On' do let :params do { hostname_lookups: 'On' } @@ -497,6 +532,7 @@ it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^HostnameLookups On\n} } end + describe 'hostname_lookups Off' do let :params do { hostname_lookups: 'Off' } @@ -513,6 +549,7 @@ it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{^HostnameLookups Double\n} } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 10' @@ -521,56 +558,64 @@ it { is_expected.to contain_user('www') } it { is_expected.to contain_group('www') } it { is_expected.to contain_class('apache::service') } + it { - is_expected.to contain_file('/usr/local/www/apache24/data').with( + expect(subject).to contain_file('/usr/local/www/apache24/data').with( 'ensure' => 'directory', ) } + it { - is_expected.to contain_file('/usr/local/etc/apache24/Vhosts').with( + expect(subject).to contain_file('/usr/local/etc/apache24/Vhosts').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_file('/usr/local/etc/apache24/Modules').with( + expect(subject).to contain_file('/usr/local/etc/apache24/Modules').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_concat('/usr/local/etc/apache24/ports.conf').with( + expect(subject).to contain_concat('/usr/local/etc/apache24/ports.conf').with( 'owner' => 'root', 'group' => 'wheel', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } + # Assert that load files are placed for these mods, but no conf file. ['auth_basic', 'authn_core', 'authn_file', 'authz_groupfile', 'authz_host', 'authz_user', 'dav', 'env'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with( - 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", + expect(subject).to contain_file("#{modname}.load").with( + 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", 'ensure' => 'file', ) } + it { is_expected.not_to contain_file("#{modname}.conf") } end # Assert that both load files and conf files are placed for these mods ['alias', 'autoindex', 'dav_fs', 'deflate', 'dir', 'mime', 'negotiation', 'setenvif'].each do |modname| it { - is_expected.to contain_file("#{modname}.load").with( - 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", + expect(subject).to contain_file("#{modname}.load").with( + 'path' => "/usr/local/etc/apache24/Modules/#{modname}.load", 'ensure' => 'file', ) } + it { - is_expected.to contain_file("#{modname}.conf").with( - 'path' => "/usr/local/etc/apache24/Modules/#{modname}.conf", + expect(subject).to contain_file("#{modname}.conf").with( + 'path' => "/usr/local/etc/apache24/Modules/#{modname}.conf", 'ensure' => 'file', ) } end end + context 'on a Gentoo OS' do include_examples 'Gentoo' @@ -578,97 +623,108 @@ it { is_expected.to contain_user('apache') } it { is_expected.to contain_group('apache') } it { is_expected.to contain_class('apache::service') } + it { - is_expected.to contain_file('/var/www/localhost/htdocs').with( + expect(subject).to contain_file('/var/www/localhost/htdocs').with( 'ensure' => 'directory', ) } + it { - is_expected.to contain_file('/etc/apache2/vhosts.d').with( + expect(subject).to contain_file('/etc/apache2/vhosts.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_file('/etc/apache2/modules.d').with( + expect(subject).to contain_file('/etc/apache2/modules.d').with( 'ensure' => 'directory', 'recurse' => 'true', 'purge' => 'true' ).that_notifies('Class[Apache::Service]').that_requires('Package[httpd]') } + it { - is_expected.to contain_concat('/etc/apache2/ports.conf').with( + expect(subject).to contain_concat('/etc/apache2/ports.conf').with( 'owner' => 'root', 'group' => 'wheel', 'mode' => '0644' ).that_notifies('Class[Apache::Service]') } end + context 'on all OSes' do include_examples 'RedHat 8' context 'with a custom apache_name parameter' do let :params do { - apache_name: 'httpd24-httpd', + apache_name: 'httpd24-httpd' } end it { - is_expected.to contain_package('httpd').with( + expect(subject).to contain_package('httpd').with( 'ensure' => 'installed', - 'name' => 'httpd24-httpd', + 'name' => 'httpd24-httpd', ).that_notifies('Class[Apache::Service]') } end + context 'with a custom file_mode parameter' do let :params do { - file_mode: '0640', + file_mode: '0640' } end it { - is_expected.to contain_concat('/etc/httpd/conf/ports.conf').with( + expect(subject).to contain_concat('/etc/httpd/conf/ports.conf').with( 'mode' => '0640', ) } end + context 'with a custom root_directory_options parameter' do let :params do { - root_directory_options: ['-Indexes', '-FollowSymLinks'], + root_directory_options: ['-Indexes', '-FollowSymLinks'] } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options -Indexes -FollowSymLinks} } end + context 'with a custom root_directory_secured parameter' do let :params do { - root_directory_secured: true, + root_directory_secured: true } end it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options FollowSymLinks\n\s+AllowOverride None\n\s+Require all denied} } end + context 'default vhost defaults' do it { is_expected.to contain_apache__vhost('default').with_ensure('present') } it { is_expected.to contain_apache__vhost('default-ssl').with_ensure('absent') } it { is_expected.to contain_file('/etc/httpd/conf/httpd.conf').with_content %r{Options FollowSymLinks} } end + context 'without default non-ssl vhost' do let :params do { - default_vhost: false, + default_vhost: false } end it { is_expected.to contain_apache__vhost('default').with_ensure('absent') } it { is_expected.not_to contain_file('/var/www/html') } end + context 'with default ssl vhost' do let :params do { - default_ssl_vhost: true, + default_ssl_vhost: true } end @@ -676,6 +732,7 @@ it { is_expected.to contain_file('/var/www/html') } end end + context 'with unsupported osfamily' do include_examples 'Darwin' diff --git a/spec/classes/dev_spec.rb b/spec/classes/dev_spec.rb index 96ec70aabc..1dcafdaeed 100644 --- a/spec/classes/dev_spec.rb +++ b/spec/classes/dev_spec.rb @@ -4,7 +4,7 @@ describe 'apache::dev' do on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -18,13 +18,13 @@ it { is_expected.to compile.with_all_deps } it { is_expected.to contain_class('apache::params') } + case facts[:os]['name'] when 'Debian' it { is_expected.to contain_package('libaprutil1-dev') } it { is_expected.to contain_package('libapr1-dev') } - if facts[:os]['release']['major'].to_i < 8 - it { is_expected.to contain_package('apache2-prefork-dev') } - end + + it { is_expected.to contain_package('apache2-prefork-dev') } if facts[:os]['release']['major'].to_i < 8 when 'Ubuntu' it { is_expected.to contain_package('apache2-dev') } when 'RedHat' diff --git a/spec/classes/mod/alias_spec.rb b/spec/classes/mod/alias_spec.rb index 38d4207739..cdaeba7ba2 100644 --- a/spec/classes/mod/alias_spec.rb +++ b/spec/classes/mod/alias_spec.rb @@ -10,27 +10,30 @@ include_examples 'Debian 11' it { is_expected.to contain_apache__mod('alias') } - it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/apache2\/icons\/"}) } + it { is_expected.to contain_file('alias.conf').with(content: %r{Alias /icons/ "/usr/share/apache2/icons/"}) } end + context 'on a RedHat 7-based OS', :compile do include_examples 'RedHat 7' it { is_expected.to contain_apache__mod('alias') } - it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/httpd\/icons\/"}) } + it { is_expected.to contain_file('alias.conf').with(content: %r{Alias /icons/ "/usr/share/httpd/icons/"}) } end + context 'on a RedHat 8-based OS', :compile do include_examples 'RedHat 8' it { is_expected.to contain_apache__mod('alias') } - it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/share\/httpd\/icons\/"}) } + it { is_expected.to contain_file('alias.conf').with(content: %r{Alias /icons/ "/usr/share/httpd/icons/"}) } end + context 'with icons options', :compile do let :pre_condition do 'class { apache: default_mods => false }' end let :params do { - 'icons_options' => 'foo', + 'icons_options' => 'foo' } end @@ -39,28 +42,30 @@ it { is_expected.to contain_apache__mod('alias') } it { is_expected.to contain_file('alias.conf').with(content: %r{Options foo}) } end + context 'with icons path change', :compile do let :pre_condition do 'class { apache: default_mods => false }' end let :params do { - 'icons_prefix' => 'apache-icons', + 'icons_prefix' => 'apache-icons' } end include_examples 'RedHat 7' it { is_expected.to contain_apache__mod('alias') } - it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/apache-icons\/ "\/usr\/share\/httpd\/icons\/"}) } + it { is_expected.to contain_file('alias.conf').with(content: %r{Alias /apache-icons/ "/usr/share/httpd/icons/"}) } end + context 'with icons path as false', :compile do let :pre_condition do 'class { apache: default_mods => false }' end let :params do { - 'icons_path' => false, + 'icons_path' => false } end @@ -69,11 +74,12 @@ it { is_expected.to contain_apache__mod('alias') } it { is_expected.not_to contain_file('alias.conf') } end + context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 10' it { is_expected.to contain_apache__mod('alias') } - it { is_expected.to contain_file('alias.conf').with(content: %r{Alias \/icons\/ "\/usr\/local\/www\/apache24\/icons\/"}) } + it { is_expected.to contain_file('alias.conf').with(content: %r{Alias /icons/ "/usr/local/www/apache24/icons/"}) } end end end diff --git a/spec/classes/mod/auth_cas_spec.rb b/spec/classes/mod/auth_cas_spec.rb index 9d615e5a10..9b053f3de2 100644 --- a/spec/classes/mod/auth_cas_spec.rb +++ b/spec/classes/mod/auth_cas_spec.rb @@ -8,7 +8,7 @@ { cas_login_url: 'https://cas.example.com/login', cas_validate_url: 'https://cas.example.com/validate', - cas_cookie_path: '/var/cache/apache2/mod_auth_cas/', + cas_cookie_path: '/var/cache/apache2/mod_auth_cas/' } end @@ -21,7 +21,7 @@ cas_login_url: 'https://cas.example.com/login', cas_validate_url: 'https://cas.example.com/validate', cas_timeout: 1234, - cas_idle_timeout: 4321, + cas_idle_timeout: 4321 } end @@ -37,6 +37,7 @@ it { is_expected.to contain_file('auth_cas.conf').with_content(%r{CASTimeout 1234}) } it { is_expected.to contain_file('auth_cas.conf').with_content(%r{CASIdleTimeout 4321}) } end + context 'on a RedHat OS', :compile do include_examples 'RedHat 8' @@ -63,9 +64,10 @@ it { is_expected.to contain_package('mod_auth_cas') } it { is_expected.to contain_file('auth_cas.conf').with_path('/etc/httpd/conf.modules.d/auth_cas.conf') } it { is_expected.to contain_file('/var/cache/mod_auth_cas/').with_owner('apache') } + it { - is_expected.to contain_concat__fragment('test.server-auth_cas').with(content: %r{^\s+CASRootProxiedAs http://test.server$}) - is_expected.to contain_concat__fragment('test.server-auth_cas').with(content: %r{^\s+CASCookiePath /my/cas/path$}) + expect(subject).to contain_concat__fragment('test.server-auth_cas').with(content: %r{^\s+CASRootProxiedAs http://test.server$}) + expect(subject).to contain_concat__fragment('test.server-auth_cas').with(content: %r{^\s+CASCookiePath /my/cas/path$}) } end end diff --git a/spec/classes/mod/auth_gssapi_spec.rb b/spec/classes/mod/auth_gssapi_spec.rb index 3f67969747..f50d6dd2e4 100644 --- a/spec/classes/mod/auth_gssapi_spec.rb +++ b/spec/classes/mod/auth_gssapi_spec.rb @@ -14,6 +14,7 @@ it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('libapache2-mod-auth-gssapi') } end + context 'on a RedHat OS', :compile do include_examples 'RedHat 8' @@ -22,6 +23,7 @@ it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('mod_auth_gssapi') } end + context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' @@ -30,6 +32,7 @@ it { is_expected.to contain_apache__mod('auth_gssapi') } it { is_expected.to contain_package('www/mod_auth_gssapi') } end + context 'on a Gentoo OS', :compile do include_examples 'Gentoo' diff --git a/spec/classes/mod/auth_kerb_spec.rb b/spec/classes/mod/auth_kerb_spec.rb index 867a5b36d5..84410311bf 100644 --- a/spec/classes/mod/auth_kerb_spec.rb +++ b/spec/classes/mod/auth_kerb_spec.rb @@ -14,6 +14,7 @@ it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('libapache2-mod-auth-kerb') } end + context 'on a RedHat OS', :compile do include_examples 'RedHat 8' @@ -22,6 +23,7 @@ it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('mod_auth_kerb') } end + context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' @@ -30,6 +32,7 @@ it { is_expected.to contain_apache__mod('auth_kerb') } it { is_expected.to contain_package('www/mod_auth_kerb2') } end + context 'on a Gentoo OS', :compile do include_examples 'Gentoo' @@ -39,6 +42,7 @@ it { is_expected.to contain_package('www-apache/mod_auth_kerb') } end end + context 'overriding mod_packages' do context 'on a RedHat OS', :compile do include_examples 'RedHat 8' diff --git a/spec/classes/mod/auth_mellon_spec.rb b/spec/classes/mod/auth_mellon_spec.rb index ffeb0e6b58..22f496fe95 100644 --- a/spec/classes/mod/auth_mellon_spec.rb +++ b/spec/classes/mod/auth_mellon_spec.rb @@ -13,8 +13,9 @@ it { is_expected.to contain_apache__mod('auth_mellon') } it { is_expected.to contain_package('libapache2-mod-auth-mellon') } it { is_expected.to contain_file('auth_mellon.conf').with_path('/etc/apache2/mods-available/auth_mellon.conf') } - it { is_expected.to contain_file('auth_mellon.conf').with_content("MellonPostDirectory \"\/var\/cache\/apache2\/mod_auth_mellon\/\"\n") } + it { is_expected.to contain_file('auth_mellon.conf').with_content("MellonPostDirectory \"/var/cache/apache2/mod_auth_mellon/\"\n") } end + describe 'with parameters' do let :params do { mellon_cache_size: 200, @@ -28,13 +29,14 @@ it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonCacheSize\s+200$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonCacheEntrySize\s+2010$}) } - it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonLockFile\s+"\/tmp\/junk"$}) } - it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostDirectory\s+"\/tmp\/post"$}) } + it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonLockFile\s+"/tmp/junk"$}) } + it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostDirectory\s+"/tmp/post"$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostTTL\s+5$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostSize\s+8$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostCount\s+10$}) } end end + context 'default configuration with parameters on a RedHat OS' do include_examples 'RedHat 8' @@ -45,6 +47,7 @@ it { is_expected.to contain_file('auth_mellon.conf').with_path('/etc/httpd/conf.modules.d/auth_mellon.conf') } it { is_expected.to contain_file('auth_mellon.conf').with_content("MellonCacheSize 100\nMellonLockFile \"/run/mod_auth_mellon/lock\"\n") } end + describe 'with parameters' do let :params do { mellon_cache_size: 200, @@ -58,8 +61,8 @@ it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonCacheSize\s+200$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonCacheEntrySize\s+2010$}) } - it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonLockFile\s+"\/tmp\/junk"$}) } - it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostDirectory\s+"\/tmp\/post"$}) } + it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonLockFile\s+"/tmp/junk"$}) } + it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostDirectory\s+"/tmp/post"$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostTTL\s+5$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostSize\s+8$}) } it { is_expected.to contain_file('auth_mellon.conf').with_content(%r{^MellonPostCount\s+10$}) } diff --git a/spec/classes/mod/auth_openidc_spec.rb b/spec/classes/mod/auth_openidc_spec.rb index 24f6228731..ed0ad42cfd 100644 --- a/spec/classes/mod/auth_openidc_spec.rb +++ b/spec/classes/mod/auth_openidc_spec.rb @@ -15,6 +15,7 @@ it { is_expected.to contain_package('libapache2-mod-auth-openidc') } it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') } end + context 'on RedHat 7', :compile do include_examples 'RedHat 7' @@ -24,6 +25,7 @@ it { is_expected.to contain_package('mod_auth_openidc') } it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') } end + context 'on RedHat 8', :compile do include_examples 'RedHat 8' @@ -31,13 +33,15 @@ it { is_expected.to contain_class('apache::mod::authz_user') } it { is_expected.to contain_apache__mod('auth_openidc') } it { is_expected.to contain_package('mod_auth_openidc') } + it do - is_expected.to contain_package('dnf-module-mod_auth_openidc') + expect(subject).to contain_package('dnf-module-mod_auth_openidc') .with_ensure('present') .with_name('mod_auth_openidc') .that_comes_before('Package[mod_auth_openidc]') end end + context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' @@ -48,6 +52,7 @@ it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') } end end + context 'overriding mod_packages' do context 'on a RedHat OS', :compile do include_examples 'RedHat 8' diff --git a/spec/classes/mod/authn_dbd_spec.rb b/spec/classes/mod/authn_dbd_spec.rb index 4dca262247..e59e96f235 100644 --- a/spec/classes/mod/authn_dbd_spec.rb +++ b/spec/classes/mod/authn_dbd_spec.rb @@ -6,7 +6,7 @@ context 'default params' do let :params do { - authn_dbd_params: 'host=db_host port=3306 user=apache password=###### dbname=apache_auth', + authn_dbd_params: 'host=db_host port=3306 user=apache password=###### dbname=apache_auth' } end @@ -18,7 +18,7 @@ { authn_dbd_params: 'host=db_host port=3306 user=apache password=###### dbname=apache_auth', authn_dbd_alias: 'db_authn', - authn_dbd_query: 'SELECT password FROM authn WHERE username = %s', + authn_dbd_query: 'SELECT password FROM authn WHERE username = %s' } end diff --git a/spec/classes/mod/authnz_ldap_spec.rb b/spec/classes/mod/authnz_ldap_spec.rb index 27f75d66bd..f672c4a573 100644 --- a/spec/classes/mod/authnz_ldap_spec.rb +++ b/spec/classes/mod/authnz_ldap_spec.rb @@ -26,14 +26,15 @@ let(:params) { { verify_server_cert: 'wrong' } } it 'raises an error' do - is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) + expect(subject).to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) end end - end # Debian + end context 'default configuration with parameters on a RedHat OS' do on_supported_os.each do |os, os_facts| next unless os.start_with?('redhat') + context "On #{os}" do let :facts do os_facts @@ -63,7 +64,7 @@ let(:params) { { verify_server_cert: 'wrong' } } it 'raises an error' do - is_expected.to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) + expect(subject).to compile.and_raise_error(%r{parameter 'verify_server_cert' expects a Boolean value, got String}) end end @@ -80,5 +81,5 @@ end end end - end # Redhat + end end diff --git a/spec/classes/mod/authnz_pam_spec.rb b/spec/classes/mod/authnz_pam_spec.rb index 6fb9a6a697..c97574878e 100644 --- a/spec/classes/mod/authnz_pam_spec.rb +++ b/spec/classes/mod/authnz_pam_spec.rb @@ -12,7 +12,7 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('libapache2-mod-authnz-pam') } it { is_expected.to contain_apache__mod('authnz_pam') } - end # Debian + end context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -20,6 +20,6 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('mod_authnz_pam') } it { is_expected.to contain_apache__mod('authnz_pam') } - end # Redhat + end end end diff --git a/spec/classes/mod/cluster_spec.rb b/spec/classes/mod/cluster_spec.rb index 88783d5fb4..0a93fad648 100644 --- a/spec/classes/mod/cluster_spec.rb +++ b/spec/classes/mod/cluster_spec.rb @@ -11,7 +11,7 @@ allowed_network: '172.17.0', balancer_name: 'mycluster', ip: '172.17.0.1', - version: '1.3.0', + version: '1.3.0' } end @@ -34,7 +34,7 @@ allowed_network: '172.17.0', balancer_name: 'mycluster', ip: '172.17.0.1', - version: '1.3.1', + version: '1.3.1' } end diff --git a/spec/classes/mod/dav_svn_spec.rb b/spec/classes/mod/dav_svn_spec.rb index 273c603d05..fadcc69df6 100644 --- a/spec/classes/mod/dav_svn_spec.rb +++ b/spec/classes/mod/dav_svn_spec.rb @@ -13,10 +13,11 @@ it { is_expected.to contain_apache__mod('dav_svn') } it { is_expected.to contain_package('libapache2-mod-svn') } it { is_expected.to contain_file('dav_svn.load').with_content(%r{LoadModule dav_svn_module}) } + describe 'with parameters' do let :params do { - 'authz_svn_enabled' => true, + 'authz_svn_enabled' => true } end @@ -27,6 +28,7 @@ it { is_expected.to contain_file('dav_svn_authz_svn.load').with_content(%r{LoadModule authz_svn_module}) } end end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -34,10 +36,11 @@ it { is_expected.to contain_apache__mod('dav_svn') } it { is_expected.to contain_package('mod_dav_svn') } it { is_expected.to contain_file('dav_svn.load').with_content(%r{LoadModule dav_svn_module}) } + describe 'with parameters' do let :params do { - 'authz_svn_enabled' => true, + 'authz_svn_enabled' => true } end @@ -48,6 +51,7 @@ it { is_expected.to contain_file('dav_svn_authz_svn.load').with_content(%r{LoadModule authz_svn_module}) } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -59,7 +63,7 @@ describe 'with parameters' do let :params do { - 'authz_svn_enabled' => true, + 'authz_svn_enabled' => true } end @@ -70,6 +74,7 @@ it { is_expected.to contain_file('dav_svn_authz_svn.load').with_content(%r{LoadModule authz_svn_module}) } end end + context 'on a Gentoo OS', :compile do include_examples 'Gentoo' @@ -81,7 +86,7 @@ describe 'with parameters' do let :params do { - 'authz_svn_enabled' => true, + 'authz_svn_enabled' => true } end diff --git a/spec/classes/mod/deflate_spec.rb b/spec/classes/mod/deflate_spec.rb index 96ecaa0f82..045a3cd04b 100644 --- a/spec/classes/mod/deflate_spec.rb +++ b/spec/classes/mod/deflate_spec.rb @@ -6,17 +6,17 @@ def general_deflate_specs it { is_expected.to contain_apache__mod('deflate') } - expected = "AddOutputFilterByType DEFLATE application/rss+xml\n"\ - "AddOutputFilterByType DEFLATE application/x-javascript\n"\ - "AddOutputFilterByType DEFLATE text/css\n"\ - "AddOutputFilterByType DEFLATE text/html\n"\ - "\n"\ - "DeflateFilterNote Input instream\n"\ - "DeflateFilterNote Output outstream\n"\ + expected = "AddOutputFilterByType DEFLATE application/rss+xml\n" \ + "AddOutputFilterByType DEFLATE application/x-javascript\n" \ + "AddOutputFilterByType DEFLATE text/css\n" \ + "AddOutputFilterByType DEFLATE text/html\n" \ + "\n" \ + "DeflateFilterNote Input instream\n" \ + "DeflateFilterNote Output outstream\n" \ "DeflateFilterNote Ratio ratio\n" it do - is_expected.to contain_file('deflate.conf').with_content(expected) + expect(subject).to contain_file('deflate.conf').with_content(expected) end end @@ -43,12 +43,13 @@ def general_deflate_specs general_deflate_specs it { - is_expected.to contain_file('deflate.conf').with(ensure: 'file', - path: '/etc/apache2/mods-available/deflate.conf') + expect(subject).to contain_file('deflate.conf').with(ensure: 'file', + path: '/etc/apache2/mods-available/deflate.conf') } + it { - is_expected.to contain_file('deflate.conf symlink').with(ensure: 'link', - path: '/etc/apache2/mods-enabled/deflate.conf') + expect(subject).to contain_file('deflate.conf symlink').with(ensure: 'link', + path: '/etc/apache2/mods-enabled/deflate.conf') } end @@ -68,8 +69,8 @@ def general_deflate_specs general_deflate_specs it { - is_expected.to contain_file('deflate.conf').with(ensure: 'file', - path: '/usr/local/etc/apache24/Modules/deflate.conf') + expect(subject).to contain_file('deflate.conf').with(ensure: 'file', + path: '/usr/local/etc/apache24/Modules/deflate.conf') } end @@ -80,8 +81,8 @@ def general_deflate_specs general_deflate_specs it { - is_expected.to contain_file('deflate.conf').with(ensure: 'file', - path: '/etc/apache2/modules.d/deflate.conf') + expect(subject).to contain_file('deflate.conf').with(ensure: 'file', + path: '/etc/apache2/modules.d/deflate.conf') } end end diff --git a/spec/classes/mod/dir_spec.rb b/spec/classes/mod/dir_spec.rb index 21df7e29cb..f76404eda5 100644 --- a/spec/classes/mod/dir_spec.rb +++ b/spec/classes/mod/dir_spec.rb @@ -10,8 +10,9 @@ context 'passing no parameters' do it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('dir') } + it do - is_expected.to contain_file('dir.conf') + expect(subject).to contain_file('dir.conf') .with_content(%r{^DirectoryIndex }) .with_content(%r{ index\.html }) .with_content(%r{ index\.html\.var }) @@ -21,6 +22,7 @@ .with_content(%r{ index\.xhtml$}) end end + context "passing indexes => ['example.txt','fearsome.aspx']" do let :params do { indexes: ['example.txt', 'fearsome.aspx'] } diff --git a/spec/classes/mod/disk_cache_spec.rb b/spec/classes/mod/disk_cache_spec.rb index d7dd466829..ce840bdcf6 100644 --- a/spec/classes/mod/disk_cache_spec.rb +++ b/spec/classes/mod/disk_cache_spec.rb @@ -8,7 +8,7 @@ let(:params) do { - cache_ignore_headers: 'Set-Cookie', + cache_ignore_headers: 'Set-Cookie' } end @@ -23,10 +23,12 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/apache2/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } + context 'with $default_cache_enable = false' do let(:params) { { 'default_cache_enable' => false } } @@ -34,11 +36,13 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheRoot "/var/cache/apache2/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = true' do let(:params) { { 'default_cache_enable' => true } } @@ -46,11 +50,13 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/apache2\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/apache2/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = foo' do let(:params) { { 'default_cache_enable' => 'foo' } } @@ -63,7 +69,7 @@ let(:params) do { - cache_ignore_headers: 'Set-Cookie', + cache_ignore_headers: 'Set-Cookie' } end @@ -75,9 +81,10 @@ end it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/httpd/proxy"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } context 'with $default_cache_enable = false' do @@ -87,11 +94,13 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheRoot "/var/cache/httpd/proxy"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = true' do let(:params) { { 'default_cache_enable' => true } } @@ -99,23 +108,26 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/httpd\/proxy\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/httpd/proxy"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = foo' do let(:params) { { 'default_cache_enable' => 'foo' } } it { is_expected.not_to compile } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 10' let(:params) do { - cache_ignore_headers: 'Set-Cookie', + cache_ignore_headers: 'Set-Cookie' } end @@ -130,9 +142,10 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\nCacheIgnoreHeaders Set-Cookie}) } context 'with $default_cache_enable = false' do @@ -142,11 +155,13 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheRoot "/var/cache/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = true' do let(:params) { { 'default_cache_enable' => true } } @@ -154,11 +169,13 @@ it { is_expected.to contain_class('apache::mod::disk_cache') } it { is_expected.to contain_class('apache::mod::cache').that_comes_before('Class[Apache::Mod::Disk_cache]') } it { is_expected.to contain_apache__mod('cache_disk') } + it { - is_expected.to contain_file('disk_cache.conf') - .with(content: %r{CacheEnable disk \/\nCacheRoot \"\/var\/cache\/mod_cache_disk\"\nCacheDirLevels 2\nCacheDirLength 1\n}) + expect(subject).to contain_file('disk_cache.conf') + .with(content: %r{CacheEnable disk /\nCacheRoot "/var/cache/mod_cache_disk"\nCacheDirLevels 2\nCacheDirLength 1\n}) } end + context 'with $default_cache_enable = foo' do let(:params) { { 'default_cache_enable' => 'foo' } } diff --git a/spec/classes/mod/dumpio_spec.rb b/spec/classes/mod/dumpio_spec.rb index 884200836c..218351d5e0 100644 --- a/spec/classes/mod/dumpio_spec.rb +++ b/spec/classes/mod/dumpio_spec.rb @@ -20,20 +20,22 @@ it { is_expected.to contain_file('dumpio.conf').with_content(%r{^\s*DumpIOInput\s+"Off"$}) } it { is_expected.to contain_file('dumpio.conf').with_content(%r{^\s*DumpIOOutput\s+"Off"$}) } end + context 'with dumpio_input set to On' do let :params do { - dump_io_input: 'On', + dump_io_input: 'On' } end it { is_expected.to contain_file('dumpio.conf').with_content(%r{^\s*DumpIOInput\s+"On"$}) } it { is_expected.to contain_file('dumpio.conf').with_content(%r{^\s*DumpIOOutput\s+"Off"$}) } end + context 'with dumpio_ouput set to On' do let :params do { - dump_io_output: 'On', + dump_io_output: 'On' } end diff --git a/spec/classes/mod/event_spec.rb b/spec/classes/mod/event_spec.rb index 2099bd5530..39d83ae992 100644 --- a/spec/classes/mod/event_spec.rb +++ b/spec/classes/mod/event_spec.rb @@ -14,6 +14,7 @@ it { is_expected.not_to contain_apache__mod('event') } it { is_expected.to contain_file('/usr/local/etc/apache24/Modules/event.conf').with_ensure('file') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' @@ -21,6 +22,7 @@ it { is_expected.not_to contain_apache__mod('event') } it { is_expected.to contain_file('/etc/apache2/modules.d/event.conf').with_ensure('file') } end + context 'on a Debian OS' do include_examples 'Debian 11' @@ -40,7 +42,7 @@ threadlimit: 7, listenbacklog: 8, maxrequestworkers: 9, - maxconnectionsperchild: 10, + maxconnectionsperchild: 10 } end @@ -66,7 +68,7 @@ threadlimit: 7, listenbacklog: 8, maxrequestworkers: :undef, - maxconnectionsperchild: :undef, + maxconnectionsperchild: :undef } end @@ -92,7 +94,7 @@ threadlimit: false, listenbacklog: false, maxrequestworkers: false, - maxconnectionsperchild: false, + maxconnectionsperchild: false } end @@ -108,11 +110,13 @@ end it { - is_expected.to contain_file('/etc/apache2/mods-available/event.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/event.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_event_module /usr/lib/apache2/modules/mod_mpm_event.so\n") } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/event.load').with_ensure('link') } end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -123,8 +127,8 @@ it { is_expected.to contain_file('/etc/httpd/conf.modules.d/event.conf').with_ensure('file') } it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/event.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_event_module modules/mod_mpm_event.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/event.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_event_module modules/mod_mpm_event.so\n") } end end diff --git a/spec/classes/mod/expires_spec.rb b/spec/classes/mod/expires_spec.rb index 759c46ad25..e9b201a79d 100644 --- a/spec/classes/mod/expires_spec.rb +++ b/spec/classes/mod/expires_spec.rb @@ -11,26 +11,29 @@ it { is_expected.to contain_apache__mod('expires') } it { is_expected.to contain_file('expires.conf').with(content: %r{ExpiresActive On\n}) } end + context 'with expires default', :compile do let :pre_condition do 'class { apache: default_mods => false }' end let :params do { - 'expires_default' => 'access plus 1 month', + 'expires_default' => 'access plus 1 month' } end include_examples 'RedHat 7' it { is_expected.to contain_apache__mod('expires') } + it { - is_expected.to contain_file('expires.conf').with_content( + expect(subject).to contain_file('expires.conf').with_content( "ExpiresActive On\n" \ "ExpiresDefault \"access plus 1 month\"\n", ) } end + context 'with expires by type', :compile do let :pre_condition do 'class { apache: default_mods => false }' @@ -40,15 +43,16 @@ 'expires_by_type' => [ { 'text/json' => 'mod plus 1 day' }, { 'text/html' => 'access plus 1 year' }, - ], + ] } end include_examples 'RedHat 7' it { is_expected.to contain_apache__mod('expires') } + it { - is_expected.to contain_file('expires.conf').with_content( + expect(subject).to contain_file('expires.conf').with_content( "ExpiresActive On\n" \ "ExpiresByType text/json \"mod plus 1 day\"\n" \ "ExpiresByType text/html \"access plus 1 year\"\n", diff --git a/spec/classes/mod/ext_filter_spec.rb b/spec/classes/mod/ext_filter_spec.rb index f75b87686c..010639103b 100644 --- a/spec/classes/mod/ext_filter_spec.rb +++ b/spec/classes/mod/ext_filter_spec.rb @@ -11,6 +11,7 @@ it { is_expected.to contain_apache__mod('ext_filter') } it { is_expected.not_to contain_file('ext_filter.conf') } end + describe 'with parameters' do let :params do { ext_filter_define: { 'filtA' => 'input=A output=B', @@ -21,6 +22,7 @@ it { is_expected.to contain_file('ext_filter.conf').with_content(%r{^ExtFilterDefine\s+filtB\s+input=C cmd="C"$}) } end end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -28,6 +30,7 @@ it { is_expected.to contain_apache__mod('ext_filter') } it { is_expected.not_to contain_file('ext_filter.conf') } end + describe 'with parameters' do let :params do { ext_filter_define: { 'filtA' => 'input=A output=B', diff --git a/spec/classes/mod/fcgid_spec.rb b/spec/classes/mod/fcgid_spec.rb index 341a2d986e..7121d4984d 100644 --- a/spec/classes/mod/fcgid_spec.rb +++ b/spec/classes/mod/fcgid_spec.rb @@ -9,9 +9,11 @@ include_examples 'Debian 11' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_apache__mod('fcgid').with('loadfile_name' => nil) + expect(subject).to contain_apache__mod('fcgid').with('loadfile_name' => nil) } + it { is_expected.to contain_package('libapache2-mod-fcgid') } end @@ -20,9 +22,11 @@ describe 'without parameters' do it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_apache__mod('fcgid').with('loadfile_name' => 'unixd_fcgid.load') + expect(subject).to contain_apache__mod('fcgid').with('loadfile_name' => 'unixd_fcgid.load') } + it { is_expected.to contain_package('mod_fcgid') } end end @@ -31,9 +35,11 @@ include_examples 'FreeBSD 10' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_apache__mod('fcgid').with('loadfile_name' => 'unixd_fcgid.load') + expect(subject).to contain_apache__mod('fcgid').with('loadfile_name' => 'unixd_fcgid.load') } + it { is_expected.to contain_package('www/mod_fcgid') } end @@ -41,9 +47,11 @@ include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_apache__mod('fcgid').with('loadfile_name' => nil) + expect(subject).to contain_apache__mod('fcgid').with('loadfile_name' => nil) } + it { is_expected.to contain_package('www-apache/mod_fcgid') } end end diff --git a/spec/classes/mod/http2_spec.rb b/spec/classes/mod/http2_spec.rb index 530ef32c35..3046914d06 100644 --- a/spec/classes/mod/http2_spec.rb +++ b/spec/classes/mod/http2_spec.rb @@ -9,13 +9,14 @@ include_examples 'Debian 11' it { is_expected.to contain_class('apache::mod::http2') } + context 'with default values' do let(:expected_content) do - <\n" it { is_expected.to contain_file('info.conf').with_content(expected) } end + context 'passing restrict_access => false' do let :params do { - restrict_access: false, + restrict_access: false } end it { - is_expected.to contain_file('info.conf').with_content( - "\n"\ - " SetHandler server-info\n"\ + expect(subject).to contain_file('info.conf').with_content( + "\n " \ + "SetHandler server-info\n" \ "\n", ) } end + context "passing allow_from => ['10.10.1.2', '192.168.1.2', '127.0.0.1']" do let :params do { allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'] } end - expected = "\n"\ - " SetHandler server-info\n"\ - " Require ip 10.10.1.2 192.168.1.2 127.0.0.1\n"\ - "\n" + expected = "\n " \ + "SetHandler server-info\n " \ + "Require ip 10.10.1.2 192.168.1.2 127.0.0.1\n" \ + "\n" it { - is_expected.to contain_file('info.conf').with_content(expected) + expect(subject).to contain_file('info.conf').with_content(expected) } end + context 'passing both restrict_access and allow_from' do let :params do { restrict_access: false, - allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'], + allow_from: ['10.10.1.2', '192.168.1.2', '127.0.0.1'] } end it { - is_expected.to contain_file('info.conf').with_content( - "\n"\ - " SetHandler server-info\n"\ + expect(subject).to contain_file('info.conf').with_content( + "\n " \ + "SetHandler server-info\n" \ "\n", ) } @@ -68,12 +71,13 @@ def general_info_specs_apache24 general_info_specs_apache24 it { - is_expected.to contain_file('info.conf').with(ensure: 'file', - path: '/etc/apache2/mods-available/info.conf') + expect(subject).to contain_file('info.conf').with(ensure: 'file', + path: '/etc/apache2/mods-available/info.conf') } + it { - is_expected.to contain_file('info.conf symlink').with(ensure: 'link', - path: '/etc/apache2/mods-enabled/info.conf') + expect(subject).to contain_file('info.conf symlink').with(ensure: 'link', + path: '/etc/apache2/mods-enabled/info.conf') } end @@ -84,8 +88,8 @@ def general_info_specs_apache24 general_info_specs_apache24 it { - is_expected.to contain_file('info.conf').with(ensure: 'file', - path: '/etc/httpd/conf.modules.d/info.conf') + expect(subject).to contain_file('info.conf').with(ensure: 'file', + path: '/etc/httpd/conf.modules.d/info.conf') } end @@ -96,8 +100,8 @@ def general_info_specs_apache24 general_info_specs_apache24 it { - is_expected.to contain_file('info.conf').with(ensure: 'file', - path: '/usr/local/etc/apache24/Modules/info.conf') + expect(subject).to contain_file('info.conf').with(ensure: 'file', + path: '/usr/local/etc/apache24/Modules/info.conf') } end @@ -108,8 +112,8 @@ def general_info_specs_apache24 general_info_specs_apache24 it { - is_expected.to contain_file('info.conf').with(ensure: 'file', - path: '/etc/apache2/modules.d/info.conf') + expect(subject).to contain_file('info.conf').with(ensure: 'file', + path: '/etc/apache2/modules.d/info.conf') } end end diff --git a/spec/classes/mod/intercept_form_submit_spec.rb b/spec/classes/mod/intercept_form_submit_spec.rb index 1618b138e5..2e12c182b3 100644 --- a/spec/classes/mod/intercept_form_submit_spec.rb +++ b/spec/classes/mod/intercept_form_submit_spec.rb @@ -12,7 +12,7 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('libapache2-mod-intercept-form-submit') } it { is_expected.to contain_apache__mod('intercept_form_submit') } - end # Debian + end context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -20,6 +20,6 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('mod_intercept_form_submit') } it { is_expected.to contain_apache__mod('intercept_form_submit') } - end # Redhat + end end end diff --git a/spec/classes/mod/itk_spec.rb b/spec/classes/mod/itk_spec.rb index 3348a4e094..2ecf14f76f 100644 --- a/spec/classes/mod/itk_spec.rb +++ b/spec/classes/mod/itk_spec.rb @@ -21,11 +21,13 @@ end it { - is_expected.to contain_file('/etc/apache2/mods-available/itk.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/itk.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_itk_module /usr/lib/apache2/modules/mod_mpm_itk.so\n") } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/itk.load').with_ensure('link') } end + context 'with enablecapabilities not set' do let :pre_condition do 'class { "apache": mpm_module => prefork, }' @@ -49,10 +51,11 @@ end it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/itk.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_itk_module modules/mod_mpm_itk.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/itk.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_itk_module modules/mod_mpm_itk.so\n") } end + context 'with enablecapabilities set' do let :pre_condition do 'class { "apache": mpm_module => prefork, }' @@ -60,13 +63,14 @@ let :params do { - enablecapabilities: false, + enablecapabilities: false } end it { is_expected.to contain_file('/etc/httpd/conf.modules.d/itk.conf').with_content(%r{EnableCapabilities Off}) } end end + context 'on a FreeBSD OS' do let :pre_condition do 'class { "apache": mpm_module => false, }' @@ -83,7 +87,7 @@ context 'with enablecapabilities set' do let :params do { - enablecapabilities: true, + enablecapabilities: true } end diff --git a/spec/classes/mod/jk_spec.rb b/spec/classes/mod/jk_spec.rb index 05e92e02a9..bfad48533e 100644 --- a/spec/classes/mod/jk_spec.rb +++ b/spec/classes/mod/jk_spec.rb @@ -26,34 +26,35 @@ 'worker_a' => { 'type' => 'ajp13', 'socket_keepalive' => 'true', - 'comment' => 'This is worker A', + 'comment' => 'This is worker A' }, 'worker_b' => { 'type' => 'ajp13', 'socket_keepalive' => 'true', - 'comment' => 'This is worker B', + 'comment' => 'This is worker B' }, 'worker_maintain' => 40, - 'worker_lists' => ['worker_a,worker_b'], - }, + 'worker_lists' => ['worker_a,worker_b'] + } } end it { is_expected.to compile } it { is_expected.to compile.with_all_deps } - expected_content = "# This file is generated automatically by Puppet - DO NOT EDIT\n"\ - "# Any manual changes will be overwritten\n"\ - "\n"\ - "worker.list = worker_a,worker_b\n"\ - "\n"\ - "worker.maintain = 40\n"\ - "\n"\ - "# This is worker A\n"\ - "worker.worker_a.socket_keepalive=true\n"\ - "worker.worker_a.type=ajp13\n"\ - "\n"\ - "# This is worker B\n"\ - "worker.worker_b.socket_keepalive=true\n"\ + + expected_content = "# This file is generated automatically by Puppet - DO NOT EDIT\n" \ + "# Any manual changes will be overwritten\n" \ + "\n" \ + "worker.list = worker_a,worker_b\n" \ + "\n" \ + "worker.maintain = 40\n" \ + "\n" \ + "# This is worker A\n" \ + "worker.worker_a.socket_keepalive=true\n" \ + "worker.worker_a.type=ajp13\n" \ + "\n" \ + "# This is worker B\n" \ + "worker.worker_b.socket_keepalive=true\n" \ "worker.worker_b.type=ajp13\n" it { is_expected.to contain_file("#{mod_dir}/workers.properties").with_content(expected_content) } end @@ -73,7 +74,7 @@ end let(:params) do { - logroot: '/var/log/apache2', + logroot: '/var/log/apache2' } end let(:mod_dir) { mod_dir } @@ -84,6 +85,7 @@ it_behaves_like 'specific workers_file', mod_dir it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") } it { is_expected.to contain_package('libapache2-mod-jk') } + it { verify_contents(catalogue, 'jk.conf', ['', '']) } @@ -97,7 +99,7 @@ end let(:params) do { - logroot: '/var/log/httpd', + logroot: '/var/log/httpd' } end @@ -112,6 +114,7 @@ it_behaves_like 'minimal resources', mod_dir it_behaves_like 'specific workers_file', mod_dir it { is_expected.to contain_apache__listen("#{default_ip}:#{default_port}") } + it { verify_contents(catalogue, 'jk.conf', ['', '']) } @@ -140,26 +143,26 @@ shm_file: :undef, log_file: :undef, shm_path: '/var/log/httpd/jk-runtime-status', - log_path: '/var/log/httpd/mod_jk.log', + log_path: '/var/log/httpd/mod_jk.log' }, relative: { shm_file: 'shm_file', log_file: 'log_file', shm_path: '/var/log/httpd/shm_file', - log_path: '/var/log/httpd/log_file', + log_path: '/var/log/httpd/log_file' }, absolute: { shm_file: '/run/shm_file', log_file: '/tmp/log_file', shm_path: '/run/shm_file', - log_path: '/tmp/log_file', + log_path: '/tmp/log_file' }, pipe: { shm_file: :undef, log_file: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"', shm_path: '/var/log/httpd/jk-runtime-status', - log_path: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"', - }, + log_path: '"|rotatelogs /var/log/httpd/mod_jk.log.%Y%m%d 86400 -180"' + } }.each do |option, paths| context "#{option} shm_file and log_file paths" do let(:params) do @@ -169,12 +172,12 @@ ) end - expected = "# This file is generated automatically by Puppet - DO NOT EDIT\n"\ - "# Any manual changes will be overwritten\n"\ - "\n"\ - "\n"\ - " JkShmFile #{paths[:shm_path]}\n"\ - " JkLogFile #{paths[:log_path]}\n"\ + expected = "# This file is generated automatically by Puppet - DO NOT EDIT\n" \ + "# Any manual changes will be overwritten\n" \ + "\n" \ + "\n " \ + "JkShmFile #{paths[:shm_path]}\n " \ + "JkLogFile #{paths[:log_path]}\n" \ "\n" it { is_expected.to contain_file('jk.conf').with_content(expected) } end diff --git a/spec/classes/mod/lbmethod_bybusyness.rb b/spec/classes/mod/lbmethod_bybusyness.rb index 94c24ad495..8e26df19a7 100644 --- a/spec/classes/mod/lbmethod_bybusyness.rb +++ b/spec/classes/mod/lbmethod_bybusyness.rb @@ -9,29 +9,32 @@ context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") + # rubocop:disable Layout/LineLength + expect(subject).to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") } end end + context 'on a RedHat OS' do include_examples 'RedHat 6' context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + # rubocop:enable Layout/LineLength } end end diff --git a/spec/classes/mod/lbmethod_byrequests.rb b/spec/classes/mod/lbmethod_byrequests.rb index 94c24ad495..8e26df19a7 100644 --- a/spec/classes/mod/lbmethod_byrequests.rb +++ b/spec/classes/mod/lbmethod_byrequests.rb @@ -9,29 +9,32 @@ context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") + # rubocop:disable Layout/LineLength + expect(subject).to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") } end end + context 'on a RedHat OS' do include_examples 'RedHat 6' context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + # rubocop:enable Layout/LineLength } end end diff --git a/spec/classes/mod/lbmethod_bytraffic.rb b/spec/classes/mod/lbmethod_bytraffic.rb index 94c24ad495..8e26df19a7 100644 --- a/spec/classes/mod/lbmethod_bytraffic.rb +++ b/spec/classes/mod/lbmethod_bytraffic.rb @@ -9,29 +9,32 @@ context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") + # rubocop:disable Layout/LineLength + expect(subject).to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") } end end + context 'on a RedHat OS' do include_examples 'RedHat 6' context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + # rubocop:enable Layout/LineLength } end end diff --git a/spec/classes/mod/lbmethod_heartbeat.rb b/spec/classes/mod/lbmethod_heartbeat.rb index 94c24ad495..8e26df19a7 100644 --- a/spec/classes/mod/lbmethod_heartbeat.rb +++ b/spec/classes/mod/lbmethod_heartbeat.rb @@ -9,29 +9,32 @@ context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") + # rubocop:disable Layout/LineLength + expect(subject).to contain_file('/etc/apache2/mods-enabled/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module /usr/lib/apache2/modules/mod_lbmethod_byrequests.so\n") } end end + context 'on a RedHat OS' do include_examples 'RedHat 6' context 'with Apache version >= 2.4' do let :params do { - apache_version: '2.4', + apache_version: '2.4' } end it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', - 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/lbmethod_byrequests.load').with('ensure' => 'file', + 'content' => "LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so\n") + # rubocop:enable Layout/LineLength } end end diff --git a/spec/classes/mod/ldap_spec.rb b/spec/classes/mod/ldap_spec.rb index 9fb165fdd4..15c160d44a 100644 --- a/spec/classes/mod/ldap_spec.rb +++ b/spec/classes/mod/ldap_spec.rb @@ -33,7 +33,7 @@ ldap_cache_ttl: 600, ldap_opcache_entries: 1024, ldap_opcache_ttl: 600, - ldap_path: '/custom-ldap-status', + ldap_path: '/custom-ldap-status' } end @@ -46,13 +46,13 @@ it { is_expected.to contain_file('ldap.conf').with_content(%r{^LDAPOpCacheTTL 600$}) } expected_ldap_path_re = - "\n"\ - "\s*SetHandler ldap-status\n"\ - ".*\n"\ + "\n" \ + "\s*SetHandler ldap-status\n" \ + ".*\n" \ "\n" it { is_expected.to contain_file('ldap.conf').with_content(%r{#{expected_ldap_path_re}}m) } end - end # Debian + end context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -75,7 +75,7 @@ let(:params) do { ldap_trusted_global_cert_file: 'ca.pem', - ldap_trusted_global_cert_type: 'CA_DER', + ldap_trusted_global_cert_type: 'CA_DER' } end @@ -93,5 +93,5 @@ it { is_expected.to contain_package('httpd24-mod_ldap') } end - end # Redhat + end end diff --git a/spec/classes/mod/lookup_identity.rb b/spec/classes/mod/lookup_identity.rb index 320d1843cc..9cfeaf469d 100644 --- a/spec/classes/mod/lookup_identity.rb +++ b/spec/classes/mod/lookup_identity.rb @@ -12,7 +12,7 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('libapache2-mod-lookup-identity') } it { is_expected.to contain_apache__mod('lookup_identity') } - end # Debian + end context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -20,6 +20,6 @@ it { is_expected.to contain_class('apache') } it { is_expected.to contain_package('mod_lookup_identity') } it { is_expected.to contain_apache__mod('lookup_identity') } - end # Redhat + end end end diff --git a/spec/classes/mod/md_spec.rb b/spec/classes/mod/md_spec.rb index 738671d04e..495cbfd8f3 100644 --- a/spec/classes/mod/md_spec.rb +++ b/spec/classes/mod/md_spec.rb @@ -39,7 +39,7 @@ 'md_stapling_keep_response' => { type: 'Duration', pass_opt: 'MDStaplingKeepResponse' }, 'md_stapling_renew_window' => { type: 'Duration', pass_opt: 'MDStaplingRenewWindow' }, 'md_store_dir' => { type: 'Path', pass_opt: 'MDStoreDir' }, - 'md_warn_window' => { type: 'Duration', pass_opt: 'MDWarnWindow' }, + 'md_warn_window' => { type: 'Duration', pass_opt: 'MDWarnWindow' } } md_options.each do |config_option, config_hash| diff --git a/spec/classes/mod/mime_magic_spec.rb b/spec/classes/mod/mime_magic_spec.rb index 8bc07b89f3..12da4510f9 100644 --- a/spec/classes/mod/mime_magic_spec.rb +++ b/spec/classes/mod/mime_magic_spec.rb @@ -16,18 +16,19 @@ def general_mime_magic_specs general_mime_magic_specs it do - is_expected.to contain_file('mime_magic.conf').with_content( + expect(subject).to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/etc/apache2/magic\"\n", ) end it { - is_expected.to contain_file('mime_magic.conf').with(ensure: 'file', - path: '/etc/apache2/mods-available/mime_magic.conf') + expect(subject).to contain_file('mime_magic.conf').with(ensure: 'file', + path: '/etc/apache2/mods-available/mime_magic.conf') } + it { - is_expected.to contain_file('mime_magic.conf symlink').with(ensure: 'link', - path: '/etc/apache2/mods-enabled/mime_magic.conf') + expect(subject).to contain_file('mime_magic.conf symlink').with(ensure: 'link', + path: '/etc/apache2/mods-enabled/mime_magic.conf') } context 'with magic_file => /tmp/Debian_magic' do @@ -36,7 +37,7 @@ def general_mime_magic_specs end it do - is_expected.to contain_file('mime_magic.conf').with_content( + expect(subject).to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/tmp/Debian_magic\"\n", ) end @@ -49,7 +50,7 @@ def general_mime_magic_specs general_mime_magic_specs it do - is_expected.to contain_file('mime_magic.conf').with_content( + expect(subject).to contain_file('mime_magic.conf').with_content( "MIMEMagicFile \"/etc/httpd/conf/magic\"\n", ) end diff --git a/spec/classes/mod/mime_spec.rb b/spec/classes/mod/mime_spec.rb index 0891059f02..483e9b5989 100644 --- a/spec/classes/mod/mime_spec.rb +++ b/spec/classes/mod/mime_spec.rb @@ -7,10 +7,10 @@ def general_mime_specs it { is_expected.to contain_apache__mod('mime') } it do - is_expected.to contain_file('mime.conf').with_content(%r{AddHandler type-map var}) - is_expected.to contain_file('mime.conf').with_content(%r{ddOutputFilter INCLUDES .shtml}) - is_expected.to contain_file('mime.conf').with_content(%r{AddType text/html .shtml}) - is_expected.to contain_file('mime.conf').with_content(%r{AddType application/x-compress .Z}) + expect(subject).to contain_file('mime.conf').with_content(%r{AddHandler type-map var}) + expect(subject).to contain_file('mime.conf').with_content(%r{ddOutputFilter INCLUDES .shtml}) + expect(subject).to contain_file('mime.conf').with_content(%r{AddType text/html .shtml}) + expect(subject).to contain_file('mime.conf').with_content(%r{AddType application/x-compress .Z}) end end diff --git a/spec/classes/mod/negotiation_spec.rb b/spec/classes/mod/negotiation_spec.rb index 0f4bd69273..dc0074fe2a 100644 --- a/spec/classes/mod/negotiation_spec.rb +++ b/spec/classes/mod/negotiation_spec.rb @@ -9,9 +9,10 @@ context 'default params' do it { is_expected.to contain_class('apache') } + it do - is_expected.to contain_file('negotiation.conf').with(ensure: 'file', - content: 'LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW + expect(subject).to contain_file('negotiation.conf').with(ensure: 'file', + content: 'LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW ForceLanguagePriority Prefer Fallback ') end @@ -23,8 +24,8 @@ end it do - is_expected.to contain_file('negotiation.conf').with(ensure: 'file', - content: %r{^ForceLanguagePriority Prefer$}) + expect(subject).to contain_file('negotiation.conf').with(ensure: 'file', + content: %r{^ForceLanguagePriority Prefer$}) end end @@ -34,8 +35,8 @@ end it do - is_expected.to contain_file('negotiation.conf').with(ensure: 'file', - content: %r{^LanguagePriority en es$}) + expect(subject).to contain_file('negotiation.conf').with(ensure: 'file', + content: %r{^LanguagePriority en es$}) end end end diff --git a/spec/classes/mod/passenger_spec.rb b/spec/classes/mod/passenger_spec.rb index 80e56ca08c..2805e8c53c 100644 --- a/spec/classes/mod/passenger_spec.rb +++ b/spec/classes/mod/passenger_spec.rb @@ -4,7 +4,7 @@ describe 'apache::mod::passenger', type: :class do on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -15,11 +15,13 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('passenger') } it { is_expected.to contain_package('libapache2-mod-passenger') } + it { - is_expected.to contain_file('zpassenger.load').with('path' => '/etc/apache2/mods-available/zpassenger.load') + expect(subject).to contain_file('zpassenger.load').with('path' => '/etc/apache2/mods-available/zpassenger.load') } + it { - is_expected.to contain_file('passenger.conf').with('path' => '/etc/apache2/mods-available/passenger.conf') + expect(subject).to contain_file('passenger.conf').with('path' => '/etc/apache2/mods-available/passenger.conf') } passenger_config_options = { @@ -107,7 +109,7 @@ 'rails_ruby' => { type: 'String', pass_opt: :RailsRuby }, 'rails_spawn_method' => { type: 'String', pass_opt: :RailsSpawnMethod }, 'rails_user_switching' => { type: 'String', pass_opt: :RailsUserSwitching }, - 'wsgi_auto_detect' => { type: 'String', pass_opt: :WsgiAutoDetect }, + 'wsgi_auto_detect' => { type: 'String', pass_opt: :WsgiAutoDetect } } passenger_config_options.each do |config_option, config_hash| puppetized_config_option = config_option @@ -179,7 +181,7 @@ let :expected_value do { true => 'On', - false => 'Off', + false => 'Off' }[valid_value] end @@ -204,11 +206,13 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('passenger') } it { is_expected.to contain_package('libapache2-mod-passenger') } + it { - is_expected.to contain_file('zpassenger.load').with('path' => '/etc/apache2/mods-available/zpassenger.load') + expect(subject).to contain_file('zpassenger.load').with('path' => '/etc/apache2/mods-available/zpassenger.load') } + it { - is_expected.to contain_file('passenger.conf').with('path' => '/etc/apache2/mods-available/passenger.conf') + expect(subject).to contain_file('passenger.conf').with('path' => '/etc/apache2/mods-available/passenger.conf') } context 'passenger config with passenger_installed_version set', test: true do @@ -216,7 +220,7 @@ let :params do { passenger_installed_version: '4.0.0', - passenger_instance_registry_dir: '/some/path/to/nowhere', + passenger_instance_registry_dir: '/some/path/to/nowhere' } end @@ -227,7 +231,7 @@ let :params do { passenger_installed_version: '5.0.0', - rails_autodetect: 'on', + rails_autodetect: 'on' } end @@ -238,7 +242,7 @@ let :params do { passenger_installed_version: '5.0.0', - rails_ruby: '/some/path/to/ruby', + rails_ruby: '/some/path/to/ruby' } end @@ -253,6 +257,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{PassengerRoot "/usr/lib/example"}) } end + describe 'with passenger_ruby => /usr/lib/example/ruby' do let :params do { passenger_ruby: '/usr/lib/example/ruby' } @@ -260,6 +265,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{PassengerRuby "/usr/lib/example/ruby"}) } end + describe 'with passenger_default_ruby => /usr/lib/example/ruby1.9.3' do let :params do { passenger_ruby: '/usr/lib/example/ruby1.9.3' } @@ -267,6 +273,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{PassengerRuby "/usr/lib/example/ruby1.9.3"}) } end + describe 'with passenger_high_performance => on' do let :params do { passenger_high_performance: 'on' } @@ -274,6 +281,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerHighPerformance on$}) } end + describe 'with passenger_pool_idle_time => 1200' do let :params do { passenger_pool_idle_time: 1200 } @@ -281,6 +289,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerPoolIdleTime 1200$}) } end + describe 'with passenger_max_request_queue_size => 100' do let :params do { passenger_max_request_queue_size: 100 } @@ -296,6 +305,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerMaxRequests 20$}) } end + describe 'with passenger_spawn_method => direct' do let :params do { passenger_spawn_method: 'direct' } @@ -303,6 +313,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerSpawnMethod direct$}) } end + describe 'with passenger_stat_throttle_rate => 10' do let :params do { passenger_stat_throttle_rate: 10 } @@ -310,6 +321,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerStatThrottleRate 10$}) } end + describe 'with passenger_max_pool_size => 16' do let :params do { passenger_max_pool_size: 16 } @@ -317,6 +329,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerMaxPoolSize 16$}) } end + describe 'with passenger_min_instances => 5' do let :params do { passenger_min_instances: 5 } @@ -324,6 +337,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerMinInstances 5$}) } end + describe 'with passenger_max_instances_per_app => 8' do let :params do { passenger_max_instances_per_app: 8 } @@ -331,6 +345,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerMaxInstancesPerApp 8$}) } end + describe 'with rack_autodetect => on' do let :params do { rack_autodetect: 'on' } @@ -338,6 +353,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ RackAutoDetect on$}) } end + describe 'with rails_autodetect => on' do let :params do { rails_autodetect: 'on' } @@ -345,6 +361,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ RailsAutoDetect on$}) } end + describe 'with passenger_use_global_queue => on' do let :params do { passenger_use_global_queue: 'on' } @@ -352,6 +369,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerUseGlobalQueue on$}) } end + describe "with passenger_app_env => 'foo'" do let :params do { passenger_app_env: 'foo' } @@ -359,6 +377,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerAppEnv foo$}) } end + describe "with passenger_log_file => '/var/log/apache2/passenger.log'" do let :params do { passenger_log_file: '/var/log/apache2/passenger.log' } @@ -366,6 +385,7 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerLogFile "/var/log/apache2/passenger.log"$}) } end + describe 'with passenger_log_level => 3' do let :params do { passenger_log_level: 3 } @@ -373,33 +393,37 @@ it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerLogLevel 3$}) } end + describe "with mod_path => '/usr/lib/foo/mod_foo.so'" do let :params do { mod_path: '/usr/lib/foo/mod_foo.so' } end - it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module \/usr\/lib\/foo\/mod_foo\.so$}) } + it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module /usr/lib/foo/mod_foo\.so$}) } end + describe "with mod_lib_path => '/usr/lib/foo'" do let :params do { mod_lib_path: '/usr/lib/foo' } end - it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module \/usr\/lib\/foo\/mod_passenger\.so$}) } + it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module /usr/lib/foo/mod_passenger\.so$}) } end + describe "with mod_lib => 'mod_foo.so'" do let :params do { mod_lib: 'mod_foo.so' } end - it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module \/usr\/lib\/apache2\/modules\/mod_foo\.so$}) } + it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule passenger_module /usr/lib/apache2/modules/mod_foo\.so$}) } end + describe "with mod_id => 'mod_foo'" do let :params do { mod_id: 'mod_foo' } end - it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule mod_foo \/usr\/lib\/apache2\/modules\/mod_passenger\.so$}) } + it { is_expected.to contain_file('zpassenger.load').with_content(%r{^LoadModule mod_foo /usr/lib/apache2/modules/mod_passenger\.so$}) } end context 'with defaults' do @@ -415,49 +439,57 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('passenger') } it { is_expected.to contain_package('mod_passenger') } + it { - is_expected.to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') + expect(subject).to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') } + it { is_expected.to contain_file('passenger_package.conf').without_content } it { is_expected.to contain_file('passenger_package.conf').without_source } + it { - is_expected.to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.d/zpassenger.load') + expect(subject).to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.d/zpassenger.load') } + it { is_expected.to contain_file('passenger.conf').without_content(%r{PassengerRoot}) } it { is_expected.to contain_file('passenger.conf').without_content(%r{PassengerRuby}) } + describe "with passenger_root => '/usr/lib/example'" do let :params do { passenger_root: '/usr/lib/example' } end - it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerRoot "\/usr\/lib\/example"$}) } + it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerRoot "/usr/lib/example"$}) } end + describe 'with passenger_ruby => /usr/lib/example/ruby' do let :params do { passenger_ruby: '/usr/lib/example/ruby' } end - it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerRuby "\/usr\/lib\/example\/ruby"$}) } + it { is_expected.to contain_file('passenger.conf').with_content(%r{^ PassengerRuby "/usr/lib/example/ruby"$}) } end end when '7' context 'on EL7' do it { - is_expected.to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') + expect(subject).to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') } + it { - is_expected.to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.modules.d/zpassenger.load') + expect(subject).to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.modules.d/zpassenger.load') } end when '8' context 'on EL8' do it { - is_expected.to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') + expect(subject).to contain_file('passenger_package.conf').with('path' => '/etc/httpd/conf.d/passenger.conf') } + it { - is_expected.to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.modules.d/zpassenger.load') + expect(subject).to contain_file('zpassenger.load').with('path' => '/etc/httpd/conf.modules.d/zpassenger.load') } end end diff --git a/spec/classes/mod/perl_spec.rb b/spec/classes/mod/perl_spec.rb index c59f2bf2ac..ad41e97503 100644 --- a/spec/classes/mod/perl_spec.rb +++ b/spec/classes/mod/perl_spec.rb @@ -11,6 +11,7 @@ it { is_expected.to contain_apache__mod('perl') } it { is_expected.to contain_package('libapache2-mod-perl2') } end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -18,6 +19,7 @@ it { is_expected.to contain_apache__mod('perl') } it { is_expected.to contain_package('mod_perl') } end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -25,6 +27,7 @@ it { is_expected.to contain_apache__mod('perl') } it { is_expected.to contain_package('www/mod_perl2') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' diff --git a/spec/classes/mod/peruser_spec.rb b/spec/classes/mod/peruser_spec.rb index d514238044..b95904a3b9 100644 --- a/spec/classes/mod/peruser_spec.rb +++ b/spec/classes/mod/peruser_spec.rb @@ -12,6 +12,7 @@ it { is_expected.to compile.and_raise_error(%r{Unsupported osfamily FreeBSD}) } end + context 'on a Gentoo OS' do include_examples 'Gentoo' diff --git a/spec/classes/mod/php_spec.rb b/spec/classes/mod/php_spec.rb index 0a8a6b3b9c..67e7d86b76 100644 --- a/spec/classes/mod/php_spec.rb +++ b/spec/classes/mod/php_spec.rb @@ -4,7 +4,7 @@ describe 'apache::mod::php', type: :class do on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -19,13 +19,15 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::prefork') } end + case facts[:os]['release']['major'] when '9' context 'on stretch' do it { is_expected.to contain_apache__mod('php7.0') } it { is_expected.to contain_package('libapache2-mod-php7.0') } + it { - is_expected.to contain_file('php7.0.load').with( + expect(subject).to contain_file('php7.0.load').with( content: "LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so\n", ) } @@ -34,8 +36,9 @@ context 'on buster' do it { is_expected.to contain_apache__mod('php7.3') } it { is_expected.to contain_package('libapache2-mod-php7.3') } + it { - is_expected.to contain_file('php7.3.load').with( + expect(subject).to contain_file('php7.3.load').with( content: "LoadModule php7_module /usr/lib/apache2/modules/libphp7.3.so\n", ) } @@ -47,8 +50,9 @@ it { is_expected.to contain_apache__mod('php8.0') } it { is_expected.to contain_package('libapache2-mod-php8.0') } + it { - is_expected.to contain_file('php8.0.load').with( + expect(subject).to contain_file('php8.0.load').with( content: "LoadModule php_module /usr/lib/apache2/modules/libphp8.0.so\n", ) } @@ -58,8 +62,9 @@ context 'on bullseye' do it { is_expected.to contain_apache__mod('php7.4') } it { is_expected.to contain_package('libapache2-mod-php7.4') } + it { - is_expected.to contain_file('php7.4.load').with( + expect(subject).to contain_file('php7.4.load').with( content: "LoadModule php7_module /usr/lib/apache2/modules/libphp7.4.so\n", ) } @@ -71,8 +76,9 @@ it { is_expected.to contain_apache__mod('php8.0') } it { is_expected.to contain_package('libapache2-mod-php8.0') } + it { - is_expected.to contain_file('php8.0.load').with( + expect(subject).to contain_file('php8.0.load').with( content: "LoadModule php_module /usr/lib/apache2/modules/libphp8.0.so\n", ) } @@ -85,7 +91,7 @@ end it { - is_expected.to contain_file('php7.2.conf').with( + expect(subject).to contain_file('php7.2.conf').with( content: 'somecontent', ) } @@ -105,6 +111,7 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_package('php') } + if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } @@ -125,6 +132,7 @@ it { is_expected.to contain_file('php.load').with(content: "LoadModule php_module modules/libphp.so\n") } end end + context 'with alternative package name' do let :pre_condition do 'class { "apache": }' @@ -135,6 +143,7 @@ it { is_expected.to contain_package('php54') } end + context 'with alternative path' do let :pre_condition do 'class { "apache": }' @@ -144,6 +153,7 @@ end it { is_expected.to contain_package('php') } + if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module alternative-path\n") } @@ -155,18 +165,20 @@ it { is_expected.to contain_file('php.load').with(content: "LoadModule php_module alternative-path\n") } end end + context 'with alternative extensions' do let :pre_condition do 'class { "apache": }' end let :params do { - extensions: ['.php', '.php5'], + extensions: ['.php', '.php5'] } end it { is_expected.to contain_file('php5.conf').with_content(Regexp.new(Regexp.escape(''))) } if facts[:os]['release']['major'].to_i < 8 end + if facts[:os]['release']['major'].to_i > 5 context 'with specific version' do let :pre_condition do @@ -177,7 +189,7 @@ end it { - is_expected.to contain_package('php').with( + expect(subject).to contain_package('php').with( ensure: '5.3.13', ) } @@ -187,6 +199,7 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::prefork') } it { is_expected.to contain_package('php') } + if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } @@ -198,6 +211,7 @@ it { is_expected.to contain_file('php.load').with(content: "LoadModule php_module modules/libphp.so\n") } end end + context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' @@ -206,6 +220,7 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_class('apache::mod::itk') } it { is_expected.to contain_package('php') } + if facts[:os]['release']['major'].to_i < 8 it { is_expected.to contain_apache__mod('php5') } it { is_expected.to contain_file('php5.load').with(content: "LoadModule php5_module modules/libphp5.so\n") } @@ -227,6 +242,7 @@ it { is_expected.to contain_package('www/mod_php5') } it { is_expected.to contain_file('php5.load') } end + context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' @@ -247,6 +263,7 @@ it { is_expected.to contain_package('dev-lang/php') } it { is_expected.to contain_file('php5.load') } end + context 'with mpm_module => itk' do let :pre_condition do 'class { "apache": mpm_module => itk, }' @@ -275,82 +292,88 @@ end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( content: 'somecontent', ) } end + context 'with template param' do let :params do { template: 'apache/mod/php.conf.erb' } end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( content: %r{^# PHP is an HTML-embedded scripting language which attempts to make it}, ) } end + context 'with source param' do let :params do { source: 'some-path' } end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( source: 'some-path', ) } end + context 'content has priority over template' do let :params do { template: 'apache/mod/php5.conf.erb', - content: 'somecontent', + content: 'somecontent' } end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( content: 'somecontent', ) } end + context 'source has priority over template' do let :params do { template: 'apache/mod/php5.conf.erb', - source: 'some-path', + source: 'some-path' } end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( source: 'some-path', ) } end + context 'source has priority over content' do let :params do { content: 'somecontent', - source: 'some-path', + source: 'some-path' } end it { - is_expected.to contain_file('php5.conf').with( + expect(subject).to contain_file('php5.conf').with( source: 'some-path', ) } end + context 'with mpm_module => worker' do let :pre_condition do 'class { "apache": mpm_module => worker, }' end it 'raises an error' do - is_expected.to compile.and_raise_error(%r{mpm_module => 'prefork' or mpm_module => 'itk'}) + expect(subject).to compile.and_raise_error(%r{mpm_module => 'prefork' or mpm_module => 'itk'}) end end end diff --git a/spec/classes/mod/prefork_spec.rb b/spec/classes/mod/prefork_spec.rb index fa3739239c..0ebe44794a 100644 --- a/spec/classes/mod/prefork_spec.rb +++ b/spec/classes/mod/prefork_spec.rb @@ -16,22 +16,26 @@ it { is_expected.to contain_file('/etc/apache2/mods-enabled/prefork.conf').with_ensure('link') } it { - is_expected.to contain_file('/etc/apache2/mods-available/prefork.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/prefork.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_prefork_module /usr/lib/apache2/modules/mod_mpm_prefork.so\n") } + it { is_expected.to contain_file('/etc/apache2/mods-enabled/prefork.load').with_ensure('link') } end + context 'on a RedHat OS' do include_examples 'RedHat 8' it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('prefork') } it { is_expected.not_to contain_apache__mod('event') } + it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/prefork.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/prefork.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_prefork_module modules/mod_mpm_prefork.so\n") } end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -39,6 +43,7 @@ it { is_expected.not_to contain_apache__mod('prefork') } it { is_expected.to contain_file('/usr/local/etc/apache24/Modules/prefork.conf').with_ensure('file') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' diff --git a/spec/classes/mod/proxy_balancer_spec.rb b/spec/classes/mod/proxy_balancer_spec.rb index 0b28526926..d43cecd7fd 100644 --- a/spec/classes/mod/proxy_balancer_spec.rb +++ b/spec/classes/mod/proxy_balancer_spec.rb @@ -4,12 +4,12 @@ # Helper function for testing the contents of `proxy_balancer.conf` def balancer_manager_conf_spec(allow_from, manager_path) - expected = "\n"\ - " SetHandler balancer-manager\n"\ - " Require ip #{Array(allow_from).join(' ')}\n"\ + expected = "\n " \ + "SetHandler balancer-manager\n " \ + "Require ip #{Array(allow_from).join(' ')}\n" \ "\n" it do - is_expected.to contain_file('proxy_balancer.conf').with_content(expected) + expect(subject).to contain_file('proxy_balancer.conf').with_content(expected) end end @@ -41,13 +41,14 @@ def balancer_manager_conf_spec(allow_from, manager_path) it { is_expected.not_to contain_file('proxy_balancer.conf symlink') } end end + context "default configuration with custom parameters $manager => true, $allow_from => ['10.10.10.10','11.11.11.11'], $status_path => '/custom-manager' on a Debian OS" do include_examples 'Debian 11' let :params do { manager: true, allow_from: ['10.10.10.10', '11.11.11.11'], - manager_path: '/custom-manager', + manager_path: '/custom-manager' } end diff --git a/spec/classes/mod/proxy_html_spec.rb b/spec/classes/mod/proxy_html_spec.rb index 2122193990..a049f6aa71 100644 --- a/spec/classes/mod/proxy_html_spec.rb +++ b/spec/classes/mod/proxy_html_spec.rb @@ -16,18 +16,22 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('proxy_html').with(loadfiles: loadfiles) } end + include_examples 'Debian 11' context 'on i386' do let(:facts) { override_facts(super(), os: { hardware: 'i386' }) } it { is_expected.to contain_apache__mod('xml2enc').with(loadfiles: nil) } + it_behaves_like 'debian', ['/usr/lib/i386-linux-gnu/libxml2.so.2'] end + context 'on x64' do let(:facts) { override_facts(super(), os: { architecture: 'x86_64' }) } it { is_expected.to contain_apache__mod('xml2enc').with(loadfiles: nil) } + it_behaves_like 'debian', ['/usr/lib/x86_64-linux-gnu/libxml2.so.2'] end end @@ -40,6 +44,7 @@ it { is_expected.to contain_package('mod_proxy_html') } it { is_expected.to contain_apache__mod('xml2enc').with(loadfiles: nil) } end + context 'on a FreeBSD OS', :compile do include_examples 'FreeBSD 9' @@ -47,6 +52,7 @@ it { is_expected.to contain_apache__mod('proxy_html').with(loadfiles: nil) } it { is_expected.to contain_apache__mod('xml2enc').with(loadfiles: nil) } end + context 'on a Gentoo OS', :compile do include_examples 'Gentoo' diff --git a/spec/classes/mod/proxy_spec.rb b/spec/classes/mod/proxy_spec.rb index 841dd3833a..c14240353e 100644 --- a/spec/classes/mod/proxy_spec.rb +++ b/spec/classes/mod/proxy_spec.rb @@ -13,6 +13,7 @@ it { is_expected.to contain_file('proxy.conf').with_content(%r{ProxyRequests Off}) } it { is_expected.to contain_file('proxy.conf').without_content(%r{ProxyTimeout}) } + context 'with parameters set' do let(:params) do { proxy_timeout: 12_345 } diff --git a/spec/classes/mod/python_spec.rb b/spec/classes/mod/python_spec.rb index 4dbefd1bed..4fe137226c 100644 --- a/spec/classes/mod/python_spec.rb +++ b/spec/classes/mod/python_spec.rb @@ -12,6 +12,7 @@ it { is_expected.to contain_apache__mod('python') } it { is_expected.to contain_package('libapache2-mod-python') } end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -28,6 +29,7 @@ it { is_expected.to contain_file('FooBar').with_path('/etc/httpd/conf.modules.d/FooBar') } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -35,6 +37,7 @@ it { is_expected.to contain_apache__mod('python') } it { is_expected.to contain_package('www/mod_python3') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' diff --git a/spec/classes/mod/remoteip_spec.rb b/spec/classes/mod/remoteip_spec.rb index aab4d1478d..2ab7ee72aa 100644 --- a/spec/classes/mod/remoteip_spec.rb +++ b/spec/classes/mod/remoteip_spec.rb @@ -8,8 +8,9 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('remoteip') } + it { - is_expected.to contain_file('remoteip.conf').with('path' => '/etc/apache2/mods-available/remoteip.conf') + expect(subject).to contain_file('remoteip.conf').with('path' => '/etc/apache2/mods-available/remoteip.conf') } describe 'with header X-Forwarded-For' do @@ -19,6 +20,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPHeader X-Forwarded-For$}) } end + describe 'with internal_proxy => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { internal_proxy: ['10.42.17.8', '10.42.18.99'] } @@ -27,6 +29,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.18.99$}) } end + describe 'with IPv4 CIDR in internal_proxy => [ 192.168.1.0/24 ]' do let :params do { internal_proxy: ['192.168.1.0/24'] } @@ -34,6 +37,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 192.168.1.0/24$}) } end + describe 'with IPv6 CIDR in internal_proxy => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { internal_proxy: ['fd00:fd00:fd00:2000::/64'] } @@ -41,6 +45,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy fd00:fd00:fd00:2000::/64$}) } end + describe 'with proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_ips: ['10.42.17.8', '10.42.18.99'] } @@ -49,6 +54,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 10.42.18.99$}) } end + describe 'with IPv4 CIDR in proxy_ips => [ 192.168.1.0/24 ]' do let :params do { proxy_ips: ['192.168.1.0/24'] } @@ -56,6 +62,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy 192.168.1.0/24$}) } end + describe 'with IPv6 CIDR in proxy_ips => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { proxy_ips: ['fd00:fd00:fd00:2000::/64'] } @@ -63,6 +70,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPInternalProxy fd00:fd00:fd00:2000::/64$}) } end + describe 'with trusted_proxy => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { trusted_proxy: ['10.42.17.8', '10.42.18.99'] } @@ -71,6 +79,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.18.99$}) } end + describe 'with trusted_proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { trusted_proxy: ['10.42.17.8', '10.42.18.99'] } @@ -79,6 +88,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPTrustedProxy 10.42.18.99$}) } end + describe 'with proxy_protocol_exceptions => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_protocol_exceptions: ['10.42.17.8', '10.42.18.99'] } @@ -87,6 +97,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 10.42.17.8$}) } it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 10.42.18.99$}) } end + describe 'with IPv4 CIDR in proxy_protocol_exceptions => [ 192.168.1.0/24 ]' do let :params do { proxy_protocol_exceptions: ['192.168.1.0/24'] } @@ -94,6 +105,7 @@ it { is_expected.to contain_file('remoteip.conf').with_content(%r{^RemoteIPProxyProtocolExceptions 192.168.1.0/24$}) } end + describe 'with IPv6 CIDR in proxy_protocol_exceptions => [ fd00:fd00:fd00:2000::/64 ]' do let :params do { proxy_protocol_exceptions: ['fd00:fd00:fd00:2000::/64'] } diff --git a/spec/classes/mod/reqtimeout_spec.rb b/spec/classes/mod/reqtimeout_spec.rb index 9cf449c3cf..63b3415fc4 100644 --- a/spec/classes/mod/reqtimeout_spec.rb +++ b/spec/classes/mod/reqtimeout_spec.rb @@ -12,6 +12,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-40,minrate=500\nRequestReadTimeout body=10,minrate=500$}) } end + context "passing timeouts => ['header=20-60,minrate=600', 'body=60,minrate=600']" do let :params do { timeouts: ['header=20-60,minrate=600', 'body=60,minrate=600'] } @@ -21,6 +22,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600\nRequestReadTimeout body=60,minrate=600$}) } end + context "passing timeouts => 'header=20-60,minrate=600'" do let :params do { timeouts: 'header=20-60,minrate=600' } @@ -31,6 +33,7 @@ it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600$}) } end end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -39,6 +42,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-40,minrate=500\nRequestReadTimeout body=10,minrate=500$}) } end + context "passing timeouts => ['header=20-60,minrate=600', 'body=60,minrate=600']" do let :params do { timeouts: ['header=20-60,minrate=600', 'body=60,minrate=600'] } @@ -48,6 +52,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600\nRequestReadTimeout body=60,minrate=600$}) } end + context "passing timeouts => 'header=20-60,minrate=600'" do let :params do { timeouts: 'header=20-60,minrate=600' } @@ -58,6 +63,7 @@ it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600$}) } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -66,6 +72,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-40,minrate=500\nRequestReadTimeout body=10,minrate=500$}) } end + context "passing timeouts => ['header=20-60,minrate=600', 'body=60,minrate=600']" do let :params do { timeouts: ['header=20-60,minrate=600', 'body=60,minrate=600'] } @@ -75,6 +82,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600\nRequestReadTimeout body=60,minrate=600$}) } end + context "passing timeouts => 'header=20-60,minrate=600'" do let :params do { timeouts: 'header=20-60,minrate=600' } @@ -85,6 +93,7 @@ it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600$}) } end end + context 'on a Gentoo OS' do include_examples 'Gentoo' @@ -93,6 +102,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-40,minrate=500\nRequestReadTimeout body=10,minrate=500$}) } end + context "passing timeouts => ['header=20-60,minrate=600', 'body=60,minrate=600']" do let :params do { timeouts: ['header=20-60,minrate=600', 'body=60,minrate=600'] } @@ -102,6 +112,7 @@ it { is_expected.to contain_apache__mod('reqtimeout') } it { is_expected.to contain_file('reqtimeout.conf').with_content(%r{^RequestReadTimeout header=20-60,minrate=600\nRequestReadTimeout body=60,minrate=600$}) } end + context "passing timeouts => 'header=20-60,minrate=600'" do let :params do { timeouts: 'header=20-60,minrate=600' } diff --git a/spec/classes/mod/rpaf_spec.rb b/spec/classes/mod/rpaf_spec.rb index 5506317448..27b1dfdf93 100644 --- a/spec/classes/mod/rpaf_spec.rb +++ b/spec/classes/mod/rpaf_spec.rb @@ -10,9 +10,11 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('rpaf') } it { is_expected.to contain_package('libapache2-mod-rpaf') } + it { - is_expected.to contain_file('rpaf.conf').with('path' => '/etc/apache2/mods-available/rpaf.conf') + expect(subject).to contain_file('rpaf.conf').with('path' => '/etc/apache2/mods-available/rpaf.conf') } + it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFenable On$}) } describe 'with sethostname => true' do @@ -22,6 +24,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFsethostname On$}) } end + describe 'with proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_ips: ['10.42.17.8', '10.42.18.99'] } @@ -29,6 +32,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFproxy_ips 10.42.17.8 10.42.18.99$}) } end + describe 'with header => X-Real-IP' do let :params do { header: 'X-Real-IP' } @@ -37,15 +41,18 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFheader X-Real-IP$}) } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('rpaf') } it { is_expected.to contain_package('www/mod_rpaf2') } + it { - is_expected.to contain_file('rpaf.conf').with('path' => '/usr/local/etc/apache24/Modules/rpaf.conf') + expect(subject).to contain_file('rpaf.conf').with('path' => '/usr/local/etc/apache24/Modules/rpaf.conf') } + it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFenable On$}) } describe 'with sethostname => true' do @@ -55,6 +62,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFsethostname On$}) } end + describe 'with proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_ips: ['10.42.17.8', '10.42.18.99'] } @@ -62,6 +70,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFproxy_ips 10.42.17.8 10.42.18.99$}) } end + describe 'with header => X-Real-IP' do let :params do { header: 'X-Real-IP' } @@ -70,15 +79,18 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFheader X-Real-IP$}) } end end + context 'on a Gentoo OS' do include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('rpaf') } it { is_expected.to contain_package('www-apache/mod_rpaf') } + it { - is_expected.to contain_file('rpaf.conf').with('path' => '/etc/apache2/modules.d/rpaf.conf') + expect(subject).to contain_file('rpaf.conf').with('path' => '/etc/apache2/modules.d/rpaf.conf') } + it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFenable On$}) } describe 'with sethostname => true' do @@ -88,6 +100,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFsethostname On$}) } end + describe 'with proxy_ips => [ 10.42.17.8, 10.42.18.99 ]' do let :params do { proxy_ips: ['10.42.17.8', '10.42.18.99'] } @@ -95,6 +108,7 @@ it { is_expected.to contain_file('rpaf.conf').with_content(%r{^RPAFproxy_ips 10.42.17.8 10.42.18.99$}) } end + describe 'with header => X-Real-IP' do let :params do { header: 'X-Real-IP' } diff --git a/spec/classes/mod/security_spec.rb b/spec/classes/mod/security_spec.rb index 143208c42e..cd01d3a067 100644 --- a/spec/classes/mod/security_spec.rb +++ b/spec/classes/mod/security_spec.rb @@ -4,7 +4,7 @@ describe 'apache::mod::security', type: :class do on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end @@ -13,20 +13,21 @@ when 'Suse' context 'on Suse based systems' do it { - is_expected.to contain_file('security.conf') + expect(subject).to contain_file('security.conf') .with_content(%r{^\s+SecTmpDir /var/lib/mod_security$}) } end when 'RedHat' context 'on RedHat based systems' do it { - is_expected.to contain_apache__mod('security').with( + expect(subject).to contain_apache__mod('security').with( id: 'security2_module', lib: 'mod_security2.so', ) } + it { - is_expected.to contain_apache__mod('unique_id').with( + expect(subject).to contain_apache__mod('unique_id').with( id: 'unique_id_module', lib: 'mod_unique_id.so', ) @@ -36,14 +37,14 @@ if (facts[:os]['release']['major'].to_i > 6 && facts[:os]['release']['major'].to_i <= 7) || (facts[:os]['release']['major'].to_i >= 8) it { - is_expected.to contain_file('security.conf').with( + expect(subject).to contain_file('security.conf').with( path: '/etc/httpd/conf.modules.d/security.conf', ) } end it { - is_expected.to contain_file('security.conf') + expect(subject).to contain_file('security.conf') .with_content(%r{^\s+SecAuditLogRelevantStatus "\^\(\?:5\|4\(\?!04\)\)"$}) .with_content(%r{^\s+SecAuditLogParts ABIJDEFHZ$}) .with_content(%r{^\s+SecAuditLogType Serial$}) @@ -51,26 +52,31 @@ .with_content(%r{^\s+SecAuditLog /var/log/httpd/modsec_audit.log$}) .with_content(%r{^\s+SecTmpDir /var/lib/mod_security$}) } + it { - is_expected.to contain_file('/etc/httpd/modsecurity.d').with( + expect(subject).to contain_file('/etc/httpd/modsecurity.d').with( ensure: 'directory', path: '/etc/httpd/modsecurity.d', owner: 'root', group: 'root', mode: '0755' ) } + it { - is_expected.to contain_file('/etc/httpd/modsecurity.d/activated_rules').with( + expect(subject).to contain_file('/etc/httpd/modsecurity.d/activated_rules').with( ensure: 'directory', path: '/etc/httpd/modsecurity.d/activated_rules', owner: 'apache', group: 'apache' ) } + it { - is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with( + expect(subject).to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with( path: '/etc/httpd/modsecurity.d/security_crs.conf', ) } + it { is_expected.to contain_apache__security__rule_link('base_rules/modsecurity_35_bad_robots.data') } + it { - is_expected.to contain_file('modsecurity_35_bad_robots.data').with( + expect(subject).to contain_file('modsecurity_35_bad_robots.data').with( path: '/etc/httpd/modsecurity.d/activated_rules/modsecurity_35_bad_robots.data', target: '/usr/lib/modsecurity.d/base_rules/modsecurity_35_bad_robots.data', ) @@ -90,7 +96,7 @@ secrequestbodyaccess: 'Off', secresponsebodyaccess: 'On', secrequestbodylimitaction: 'ProcessPartial', - secresponsebodylimitaction: 'Reject', + secresponsebodylimitaction: 'Reject' } end @@ -103,47 +109,52 @@ it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecRequestBodyLimitAction ProcessPartial$} } it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecResponseBodyLimitAction Reject$} } it { is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content %r{^\s*SecDefaultAction "phase:2,deny,status:406,nolog,auditlog"$} } + it { - is_expected.to contain_file('bar.conf').with( + expect(subject).to contain_file('bar.conf').with( path: '/etc/httpd/modsecurity.d/activated_rules/bar.conf', target: '/tmp/foo/bar.conf', ) } end + describe 'with other modsec parameters' do let :params do { - manage_security_crs: false, + manage_security_crs: false } end it { is_expected.not_to contain_file('/etc/httpd/modsecurity.d/security_crs.conf') } end + describe 'with custom parameters' do let :params do { - custom_rules: false, + custom_rules: false } end it { - is_expected.not_to contain_file('/etc/httpd/modsecurity.d/custom_rules/custom_01_rules.conf') + expect(subject).not_to contain_file('/etc/httpd/modsecurity.d/custom_rules/custom_01_rules.conf') } end + describe 'with parameters' do let :params do { custom_rules: true, - custom_rules_set: ['REMOTE_ADDR "^127.0.0.1" "id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"'], + custom_rules_set: ['REMOTE_ADDR "^127.0.0.1" "id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"'] } end it { - is_expected.to contain_file('/etc/httpd/modsecurity.d/custom_rules').with( + expect(subject).to contain_file('/etc/httpd/modsecurity.d/custom_rules').with( ensure: 'directory', path: '/etc/httpd/modsecurity.d/custom_rules', owner: 'apache', group: 'apache' ) } + it { is_expected.to contain_file('/etc/httpd/modsecurity.d/custom_rules/custom_01_rules.conf').with_content %r{^\s*.*"id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"$} } end @@ -155,13 +166,13 @@ enable_dos_protection: true, dos_burst_time_slice: 30, dos_counter_threshold: 120, - dos_block_timeout: 300, + dos_block_timeout: 300 } end if facts[:os]['release']['major'].to_i < 8 && facts[:os]['family'] == 'RedHat' it { - is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ + expect(subject).to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ %r{ ^SecAction\ \\\n \ \ "id:'900001',\ \\\n @@ -177,14 +188,14 @@ } else it { - is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ - %r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$} - is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ - %r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=2"$} - is_expected.to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ + expect(subject).to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ + %r{^SecAction \\\n\s+"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$} + expect(subject).to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ + %r{^SecAction \\\n\s+"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=2"$} + expect(subject).to contain_file('/etc/httpd/modsecurity.d/security_crs.conf').with_content \ %r{ ^SecAction\ \\\n - \s+\"id:900700,\\\n + \s+"id:900700,\\\n \s+phase:1,\\\n \s+nolog,\\\n \s+pass,\\\n @@ -201,37 +212,41 @@ let :params do { paranoia_level: 2, - executing_paranoia_level: 1, + executing_paranoia_level: 1 } end it { - is_expected.to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level}) + expect(subject).to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level}) } end end when 'Debian' context 'on Debian based systems' do it { - is_expected.to contain_apache__mod('security').with( + expect(subject).to contain_apache__mod('security').with( id: 'security2_module', lib: 'mod_security2.so', ) } + it { - is_expected.to contain_apache__mod('unique_id').with( + expect(subject).to contain_apache__mod('unique_id').with( id: 'unique_id_module', lib: 'mod_unique_id.so', ) } + it { is_expected.to contain_package('modsecurity-crs') } + it { - is_expected.to contain_file('security.conf').with( + expect(subject).to contain_file('security.conf').with( path: '/etc/apache2/mods-available/security.conf', ) } + it { - is_expected.to contain_file('security.conf') + expect(subject).to contain_file('security.conf') .with_content(%r{^\s+SecAuditLogRelevantStatus "\^\(\?:5\|4\(\?!04\)\)"$}) .with_content(%r{^\s+SecAuditLogParts ABIJDEFHZ$}) .with_content(%r{^\s+SecAuditLogType Serial$}) @@ -239,28 +254,33 @@ .with_content(%r{^\s+SecAuditLog /var/log/apache2/modsec_audit.log$}) .with_content(%r{^\s+SecTmpDir /var/cache/modsecurity$}) } + it { - is_expected.to contain_file('/etc/modsecurity').with( + expect(subject).to contain_file('/etc/modsecurity').with( ensure: 'directory', path: '/etc/modsecurity', owner: 'root', group: 'root', mode: '0755' ) } + it { - is_expected.to contain_file('/etc/modsecurity/activated_rules').with( + expect(subject).to contain_file('/etc/modsecurity/activated_rules').with( ensure: 'directory', path: '/etc/modsecurity/activated_rules', owner: 'www-data', group: 'www-data' ) } + it { - is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with( + expect(subject).to contain_file('/etc/modsecurity/security_crs.conf').with( path: '/etc/modsecurity/security_crs.conf', ) } + if (facts[:os]['release']['major'].to_i < 18 && facts[:os]['name'] == 'Ubuntu') || (facts[:os]['release']['major'].to_i < 9 && facts[:os]['name'] == 'Debian') it { is_expected.to contain_apache__security__rule_link('base_rules/modsecurity_35_bad_robots.data') } + it { - is_expected.to contain_file('modsecurity_35_bad_robots.data').with( + expect(subject).to contain_file('modsecurity_35_bad_robots.data').with( path: '/etc/modsecurity/activated_rules/modsecurity_35_bad_robots.data', target: '/usr/share/modsecurity-crs/base_rules/modsecurity_35_bad_robots.data', ) @@ -281,7 +301,7 @@ secrequestbodyaccess: 'Off', secresponsebodyaccess: 'On', secrequestbodylimitaction: 'ProcessPartial', - secresponsebodylimitaction: 'Reject', + secresponsebodylimitaction: 'Reject' } end @@ -295,8 +315,9 @@ it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecRequestBodyLimitAction ProcessPartial$} } it { is_expected.to contain_file('security.conf').with_content %r{^\s+SecResponseBodyLimitAction Reject$} } it { is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content %r{^\s*SecDefaultAction "phase:2,deny,status:406,nolog,auditlog"$} } + it { - is_expected.to contain_file('bar.conf').with( + expect(subject).to contain_file('bar.conf').with( path: '/etc/modsecurity/activated_rules/bar.conf', target: '/tmp/foo/bar.conf', ) @@ -307,12 +328,12 @@ describe 'with custom parameters' do let :params do { - custom_rules: false, + custom_rules: false } end it { - is_expected.not_to contain_file('/etc/modsecurity/custom_rules/custom_01_rules.conf') + expect(subject).not_to contain_file('/etc/modsecurity/custom_rules/custom_01_rules.conf') } end @@ -320,29 +341,31 @@ let :params do { custom_rules: true, - custom_rules_set: ['REMOTE_ADDR "^127.0.0.1" "id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"'], + custom_rules_set: ['REMOTE_ADDR "^127.0.0.1" "id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"'] } end it { - is_expected.to contain_file('/etc/modsecurity/custom_rules').with( + expect(subject).to contain_file('/etc/modsecurity/custom_rules').with( ensure: 'directory', path: '/etc/modsecurity/custom_rules', owner: 'www-data', group: 'www-data' ) } + it { is_expected.to contain_file('/etc/modsecurity/custom_rules/custom_01_rules.conf').with_content %r{\s*.*"id:199999,phase:1,nolog,allow,ctl:ruleEngine=off"$} } end describe 'with mod security version' do let :params do { - version: 2, + version: 2 } end it { is_expected.to contain_apache__mod('security2') } + it { - is_expected.to contain_file('security.conf').with( + expect(subject).to contain_file('security.conf').with( path: '/etc/apache2/mods-available/security2.conf', ) } @@ -356,19 +379,19 @@ enable_dos_protection: true, dos_burst_time_slice: 30, dos_counter_threshold: 120, - dos_block_timeout: 300, + dos_block_timeout: 300 } end it { - is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \ - %r{^SecAction \\\n\s+\"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$} - is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \ - %r{^SecAction \\\n\s+\"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=1"$} - is_expected.to contain_file('/etc/modsecurity/security_crs.conf').with_content \ + expect(subject).to contain_file('/etc/modsecurity/security_crs.conf').with_content \ + %r{^SecAction \\\n\s+"id:900000,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.paranoia_level=1"$} + expect(subject).to contain_file('/etc/modsecurity/security_crs.conf').with_content \ + %r{^SecAction \\\n\s+"id:900001,\\\n\s+phase:1,\\\n\s+nolog,\\\n\s+pass,\\\n\s+t:none,\\\n\s+setvar:tx.executing_paranoia_level=1"$} + expect(subject).to contain_file('/etc/modsecurity/security_crs.conf').with_content \ %r{ ^SecAction\ \\\n - \s+\"id:900700,\\\n + \s+"id:900700,\\\n \s+phase:1,\\\n \s+nolog,\\\n \s+pass,\\\n @@ -384,12 +407,12 @@ let :params do { paranoia_level: 2, - executing_paranoia_level: 1, + executing_paranoia_level: 1 } end it { - is_expected.to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level}) + expect(subject).to compile.and_raise_error(%r{Executing paranoia level cannot be lower than paranoia level}) } end end diff --git a/spec/classes/mod/shib_spec.rb b/spec/classes/mod/shib_spec.rb index a1f25afb33..92168a7d56 100644 --- a/spec/classes/mod/shib_spec.rb +++ b/spec/classes/mod/shib_spec.rb @@ -11,6 +11,7 @@ it { is_expected.to contain_apache__mod('shib2').with_id('mod_shib') } end end + context 'on a RedHat OS' do include_examples 'RedHat 8' diff --git a/spec/classes/mod/ssl_spec.rb b/spec/classes/mod/ssl_spec.rb index ff1e3ee31b..d54be82016 100644 --- a/spec/classes/mod/ssl_spec.rb +++ b/spec/classes/mod/ssl_spec.rb @@ -17,8 +17,9 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_package('mod_ssl') } + it { - is_expected.to contain_file('ssl.conf') + expect(subject).to contain_file('ssl.conf') .with_path('/etc/httpd/conf.modules.d/ssl.conf') .without_content(%r{SSLProtocol}) .with_content(%r{^ SSLCipherSuite PROFILE=SYSTEM$}) @@ -28,7 +29,7 @@ context 'with ssl_proxy_cipher_suite' do let(:params) do { - ssl_proxy_cipher_suite: 'HIGH', + ssl_proxy_cipher_suite: 'HIGH' } end @@ -38,7 +39,7 @@ context 'with empty ssl_protocol' do let(:params) do { - ssl_protocol: [], + ssl_protocol: [] } end @@ -71,6 +72,7 @@ it { is_expected.not_to contain_package('libapache2-mod-ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{SSLProtocol all -SSLv3}) } end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -93,6 +95,7 @@ it { is_expected.to contain_apache__mod('ssl') } it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/var/lib/apache2/ssl_scache\(512000\)"$}) } end + # Template config doesn't vary by distro context 'on all distros' do include_examples 'RedHat 8' @@ -104,7 +107,7 @@ context 'setting ssl_cert' do let :params do { - ssl_cert: '/etc/pki/some/path/localhost.crt', + ssl_cert: '/etc/pki/some/path/localhost.crt' } end @@ -114,7 +117,7 @@ context 'setting ssl_key' do let :params do { - ssl_key: '/etc/pki/some/path/localhost.key', + ssl_key: '/etc/pki/some/path/localhost.key' } end @@ -124,7 +127,7 @@ context 'setting ssl_ca to a path' do let :params do { - ssl_ca: '/etc/pki/some/path/ca.crt', + ssl_ca: '/etc/pki/some/path/ca.crt' } end @@ -135,7 +138,7 @@ let :params do { ssl_cert: '/etc/pki/some/path/localhost.crt', - ssl_reload_on_change: true, + ssl_reload_on_change: true } end @@ -147,10 +150,11 @@ it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLCompression Off$}) } it { is_expected.not_to contain_file('ssl.conf').with_content(%r{^ SSLSessionTickets (Off|On)$}) } end + context 'with ssl_compression set to true' do let :params do { - ssl_compression: true, + ssl_compression: true } end @@ -160,7 +164,7 @@ context 'with ssl_sessiontickets set to false' do let :params do { - ssl_sessiontickets: false, + ssl_sessiontickets: false } end @@ -170,25 +174,27 @@ context 'with ssl_stapling set to true' do let :params do { - ssl_stapling: true, + ssl_stapling: true } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLUseStapling On$}) } end + context 'with ssl_stapling_return_errors set to true' do let :params do { - ssl_stapling_return_errors: true, + ssl_stapling_return_errors: true } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLStaplingReturnResponderErrors On$}) } end + context 'with stapling_cache' do let :params do { - stapling_cache: '/tmp/customstaplingcache(51200)', + stapling_cache: '/tmp/customstaplingcache(51200)' } end @@ -198,17 +204,17 @@ context 'setting ssl_pass_phrase_dialog' do let :params do { - ssl_pass_phrase_dialog: 'exec:/path/to/program', + ssl_pass_phrase_dialog: 'exec:/path/to/program' } end - it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLPassPhraseDialog exec:\/path\/to\/program$}) } + it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLPassPhraseDialog exec:/path/to/program$}) } end context 'setting ssl_random_seed_bytes' do let :params do { - ssl_random_seed_bytes: 1024, + ssl_random_seed_bytes: 1024 } end @@ -218,7 +224,7 @@ context 'setting ssl_openssl_conf_cmd' do let :params do { - ssl_openssl_conf_cmd: 'DHParameters "foo.pem"', + ssl_openssl_conf_cmd: 'DHParameters "foo.pem"' } end @@ -228,25 +234,27 @@ context 'setting ssl_mutex' do let :params do { - ssl_mutex: 'posixsem', + ssl_mutex: 'posixsem' } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ Mutex posixsem$}) } end + context 'setting ssl_sessioncache' do let :params do { - ssl_sessioncache: '/tmp/customsessioncache(51200)', + ssl_sessioncache: '/tmp/customsessioncache(51200)' } end it { is_expected.to contain_file('ssl.conf').with_content(%r{^ SSLSessionCache "shmcb:/tmp/customsessioncache\(51200\)"$}) } end + context 'setting ssl_proxy_protocol' do let :params do { - ssl_proxy_protocol: ['-ALL', '+TLSv1'], + ssl_proxy_protocol: ['-ALL', '+TLSv1'] } end @@ -261,7 +269,7 @@ context 'force on' do let :params do { - ssl_honorcipherorder: true, + ssl_honorcipherorder: true } end @@ -271,7 +279,7 @@ context 'force off' do let :params do { - ssl_honorcipherorder: false, + ssl_honorcipherorder: false } end @@ -281,7 +289,7 @@ context 'set on' do let :params do { - ssl_honorcipherorder: 'on', + ssl_honorcipherorder: 'on' } end @@ -291,7 +299,7 @@ context 'set off' do let :params do { - ssl_honorcipherorder: 'off', + ssl_honorcipherorder: 'off' } end diff --git a/spec/classes/mod/status_spec.rb b/spec/classes/mod/status_spec.rb index eebe8746c2..5e1a52cd2d 100644 --- a/spec/classes/mod/status_spec.rb +++ b/spec/classes/mod/status_spec.rb @@ -3,42 +3,43 @@ require 'spec_helper' def require_directives(requires) - if requires == :undef + case requires + when :undef " Require ip 127.0.0.1 ::1\n" - elsif requires.is_a?(String) + when String if ['', 'unmanaged'].include? requires.downcase '' else " Require #{requires}\n" end - elsif requires.is_a?(Array) - requires.map { |req| " Require #{req}\n" }.join('') - elsif requires.is_a?(Hash) + when Array + requires.map { |req| " Require #{req}\n" }.join + when Hash if requires.key?(:enforce) - \ + \ " \n" + \ - requires[:requires].map { |req| " Require #{req}\n" }.join('') + \ + requires[:requires].map { |req| " Require #{req}\n" }.join + \ " \n" else - requires[:requires].map { |req| " Require #{req}\n" }.join('') + requires[:requires].map { |req| " Require #{req}\n" }.join end end end shared_examples 'status_conf_spec_require' do |requires, extended_status, status_path| expected = - "\n"\ - " SetHandler server-status\n"\ - "#{require_directives(requires)}"\ - "\n"\ - "ExtendedStatus #{extended_status}\n"\ - "\n"\ - "\n"\ - " # Show Proxy LoadBalancer status in mod_status\n"\ - " ProxyStatus On\n"\ + "\n " \ + "SetHandler server-status\n" \ + "#{require_directives(requires)}" \ + "\n" \ + "ExtendedStatus #{extended_status}\n" \ + "\n" \ + "\n " \ + "# Show Proxy LoadBalancer status in mod_status\n " \ + "ProxyStatus On\n" \ "\n" it('status conf require') do - is_expected.to contain_file('status.conf').with_content(expected) + expect(subject).to contain_file('status.conf').with_content(expected) end end @@ -55,13 +56,13 @@ def require_directives(requires) include_examples 'status_conf_spec_require', 'ip 127.0.0.1 ::1', 'On', '/server-status' it { - is_expected.to contain_file('status.conf').with(ensure: 'file', - path: '/etc/apache2/mods-available/status.conf') + expect(subject).to contain_file('status.conf').with(ensure: 'file', + path: '/etc/apache2/mods-available/status.conf') } it { - is_expected.to contain_file('status.conf symlink').with(ensure: 'link', - path: '/etc/apache2/mods-enabled/status.conf') + expect(subject).to contain_file('status.conf symlink').with(ensure: 'link', + path: '/etc/apache2/mods-enabled/status.conf') } end @@ -69,7 +70,7 @@ def require_directives(requires) let :params do { extended_status: 'Off', - status_path: '/custom-status', + status_path: '/custom-status' } end @@ -86,7 +87,7 @@ def require_directives(requires) end it 'expects to succeed regular expression validation' do - is_expected.to compile + expect(subject).to compile end end end @@ -98,7 +99,7 @@ def require_directives(requires) end it 'expects to fail regular expression validation' do - is_expected.to compile.and_raise_error(%r{extended_status}) + expect(subject).to compile.and_raise_error(%r{extended_status}) end end end @@ -130,21 +131,21 @@ def require_directives(requires) requires: [ 'ip 10.1', 'host somehost', - ], + ] }, enforce: { enforce: 'all', requires: [ 'ip 127.0.0.1', 'host localhost', - ], - }, + ] + } } valid_requires.each do |req_key, req_value| context "with default params and #{req_key} requires" do let :params do { - requires: req_value, + requires: req_value } end @@ -156,13 +157,13 @@ def require_directives(requires) include_examples 'status_conf_spec_require', req_value, 'On', '/server-status' it { - is_expected.to contain_file('status.conf').with(ensure: 'file', - path: '/etc/apache2/mods-available/status.conf') + expect(subject).to contain_file('status.conf').with(ensure: 'file', + path: '/etc/apache2/mods-available/status.conf') } it { - is_expected.to contain_file('status.conf symlink').with(ensure: 'link', - path: '/etc/apache2/mods-enabled/status.conf') + expect(subject).to contain_file('status.conf symlink').with(ensure: 'link', + path: '/etc/apache2/mods-enabled/status.conf') } end diff --git a/spec/classes/mod/userdir_spec.rb b/spec/classes/mod/userdir_spec.rb index 3449373834..cad5269ad7 100644 --- a/spec/classes/mod/userdir_spec.rb +++ b/spec/classes/mod/userdir_spec.rb @@ -16,61 +16,67 @@ context 'default parameters' do it { is_expected.to compile } end + context 'with dir set to something' do let :params do { - dir: 'hi', + dir: 'hi' } end it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+/home/\*/hi$}) } - it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\$}) } + it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*$}) } end + context 'with home set to something' do let :params do { - home: '/u', + home: '/u' } end it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+/u/\*/public_html$}) } - it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\$}) } + it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*$}) } end + context 'with path set to something' do let :params do { - path: '/home/*/*/public_html', + path: '/home/*/*/public_html' } end it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+/home/\*/\*/public_html$}) } - it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\$}) } + it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*$}) } end + context 'with userdir set to something' do let :params do { path: '/home/*/*/public_html', - userdir: 'public_html', + userdir: 'public_html' } end it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+public_html$}) } - it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*\$}) } + it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*$}) } end + context 'with unmanaged_path set to true' do let :params do { - unmanaged_path: true, + unmanaged_path: true } end it { is_expected.to contain_file('userdir.conf').with_content(%r{^\s*UserDir\s+/home/\*/public_html$}) } - it { is_expected.not_to contain_file('userdir.conf').with_content(%r{^\s*\ 'file', - 'content' => "LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n") + expect(subject).to contain_file('/etc/apache2/mods-available/worker.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_worker_module /usr/lib/apache2/modules/mod_mpm_worker.so\n") } end + context 'on a RedHat OS' do include_examples 'RedHat 8' it { is_expected.to contain_class('apache::params') } it { is_expected.not_to contain_apache__mod('worker') } it { is_expected.not_to contain_apache__mod('event') } + it { - is_expected.to contain_file('/etc/httpd/conf.modules.d/worker.load').with('ensure' => 'file', - 'content' => "LoadModule mpm_worker_module modules/mod_mpm_worker.so\n") + expect(subject).to contain_file('/etc/httpd/conf.modules.d/worker.load').with('ensure' => 'file', + 'content' => "LoadModule mpm_worker_module modules/mod_mpm_worker.so\n") } end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' @@ -36,6 +40,7 @@ it { is_expected.not_to contain_apache__mod('worker') } it { is_expected.to contain_file('/usr/local/etc/apache24/Modules/worker.conf').with_ensure('file') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' @@ -72,7 +77,7 @@ threadsperchild: 15, maxrequestsperchild: 16, threadlimit: 17, - listenbacklog: 8, + listenbacklog: 8 } end diff --git a/spec/classes/mod/wsgi_spec.rb b/spec/classes/mod/wsgi_spec.rb index 95d10625d6..d3f9ff24f1 100644 --- a/spec/classes/mod/wsgi_spec.rb +++ b/spec/classes/mod/wsgi_spec.rb @@ -8,13 +8,16 @@ include_examples 'Debian 11' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_class('apache::mod::wsgi').with( + expect(subject).to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } + it { is_expected.to contain_package('libapache2-mod-wsgi-py3') } end + context 'on a RedHat OS' do include_examples 'RedHat 8' @@ -31,20 +34,23 @@ it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIRestrictEmbedded On$}) } end + describe 'with custom WSGISocketPrefix' do let :params do { wsgi_socket_prefix: 'run/wsgi' } end - it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGISocketPrefix run\/wsgi$}) } + it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGISocketPrefix run/wsgi$}) } end + describe 'with custom WSGIPythonHome' do let :params do { wsgi_python_home: '/path/to/virtenv' } end - it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIPythonHome "\/path\/to\/virtenv"$}) } + it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIPythonHome "/path/to/virtenv"$}) } end + describe 'with custom WSGIApplicationGroup' do let :params do { wsgi_application_group: '%{GLOBAL}' } @@ -52,6 +58,7 @@ it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIApplicationGroup "%{GLOBAL}"$}) } end + describe 'with custom WSGIPythonOptimize' do let :params do { wsgi_python_optimize: 1 } @@ -59,76 +66,89 @@ it { is_expected.to contain_file('wsgi.conf').with_content(%r{^ WSGIPythonOptimize 1$}) } end + describe 'with custom package_name and mod_path' do let :params do { package_name: 'mod_wsgi_package', - mod_path: '/foo/bar/baz', + mod_path: '/foo/bar/baz' } end it { - is_expected.to contain_apache__mod('wsgi').with('package' => 'mod_wsgi_package', - 'path' => '/foo/bar/baz') + expect(subject).to contain_apache__mod('wsgi').with('package' => 'mod_wsgi_package', + 'path' => '/foo/bar/baz') } + it { is_expected.to contain_package('mod_wsgi_package') } it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module /foo/bar/baz}) } end + describe 'with custom mod_path not containing /' do let :params do { package_name: 'mod_wsgi_package', - mod_path: 'wsgi_mod_name.so', + mod_path: 'wsgi_mod_name.so' } end it { - is_expected.to contain_apache__mod('wsgi').with('path' => 'modules/wsgi_mod_name.so', - 'package' => 'mod_wsgi_package') + expect(subject).to contain_apache__mod('wsgi').with('path' => 'modules/wsgi_mod_name.so', + 'package' => 'mod_wsgi_package') } + it { is_expected.to contain_file('wsgi.load').with_content(%r{LoadModule wsgi_module modules/wsgi_mod_name.so}) } end + describe 'with package_name but no mod_path' do let :params do { - mod_path: '/foo/bar/baz', + mod_path: '/foo/bar/baz' } end it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) } end + describe 'with mod_path but no package_name' do let :params do { - package_name: '/foo/bar/baz', + package_name: '/foo/bar/baz' } end it { is_expected.to compile.and_raise_error(%r{apache::mod::wsgi - both package_name and mod_path must be specified!}) } end end + context 'on a FreeBSD OS' do include_examples 'FreeBSD 9' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_class('apache::mod::wsgi').with( + expect(subject).to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } + it { is_expected.to contain_package('www/mod_wsgi') } end + context 'on a Gentoo OS' do include_examples 'Gentoo' it { is_expected.to contain_class('apache::params') } + it { - is_expected.to contain_class('apache::mod::wsgi').with( + expect(subject).to contain_class('apache::mod::wsgi').with( 'wsgi_socket_prefix' => nil, ) } + it { is_expected.to contain_package('www-apache/mod_wsgi') } end + context 'overriding mod_libs' do context 'on a RedHat OS', :compile do include_examples 'RedHat 8' diff --git a/spec/classes/service_spec.rb b/spec/classes/service_spec.rb index 5e9aba39f8..85a03fbb40 100644 --- a/spec/classes/service_spec.rb +++ b/spec/classes/service_spec.rb @@ -11,10 +11,10 @@ include_examples 'Debian 11' it { - is_expected.to contain_service('httpd').with( - 'name' => 'apache2', - 'ensure' => 'running', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'name' => 'apache2', + 'ensure' => 'running', + 'enable' => 'true', ) } @@ -22,7 +22,7 @@ let(:params) { { service_name: 'foo' } } it { - is_expected.to contain_service('httpd').with( + expect(subject).to contain_service('httpd').with( 'name' => 'foo', ) } @@ -32,10 +32,10 @@ let(:params) { { service_enable: true } } it { - is_expected.to contain_service('httpd').with( - 'name' => 'apache2', - 'ensure' => 'running', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'name' => 'apache2', + 'ensure' => 'running', + 'enable' => 'true', ) } end @@ -44,10 +44,10 @@ let(:params) { { service_enable: false } } it { - is_expected.to contain_service('httpd').with( - 'name' => 'apache2', - 'ensure' => 'running', - 'enable' => 'false', + expect(subject).to contain_service('httpd').with( + 'name' => 'apache2', + 'ensure' => 'running', + 'enable' => 'false', ) } end @@ -56,9 +56,9 @@ let(:params) { { service_ensure: 'running' } } it { - is_expected.to contain_service('httpd').with( - 'ensure' => 'running', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'ensure' => 'running', + 'enable' => 'true', ) } end @@ -67,9 +67,9 @@ let(:params) { { service_ensure: 'stopped' } } it { - is_expected.to contain_service('httpd').with( - 'ensure' => 'stopped', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'ensure' => 'stopped', + 'enable' => 'true', ) } end @@ -88,7 +88,7 @@ let(:params) { { service_restart: '/usr/sbin/apachectl graceful' } } it { - is_expected.to contain_service('httpd').with( + expect(subject).to contain_service('httpd').with( 'restart' => '/usr/sbin/apachectl graceful', ) } @@ -100,8 +100,8 @@ let(:params) do { 'service_ensure' => 'running', - 'service_name' => 'httpd', - 'service_manage' => false, + 'service_name' => 'httpd', + 'service_manage' => false } end @@ -112,10 +112,10 @@ include_examples 'FreeBSD 9' it { - is_expected.to contain_service('httpd').with( - 'name' => 'apache24', - 'ensure' => 'running', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'name' => 'apache24', + 'ensure' => 'running', + 'enable' => 'true', ) } end @@ -124,10 +124,10 @@ include_examples 'Gentoo' it { - is_expected.to contain_service('httpd').with( - 'name' => 'apache2', - 'ensure' => 'running', - 'enable' => 'true', + expect(subject).to contain_service('httpd').with( + 'name' => 'apache2', + 'ensure' => 'running', + 'enable' => 'true', ) } end diff --git a/spec/classes/vhosts_spec.rb b/spec/classes/vhosts_spec.rb index 01ae1848c3..70f0cae528 100644 --- a/spec/classes/vhosts_spec.rb +++ b/spec/classes/vhosts_spec.rb @@ -12,13 +12,13 @@ vhosts: { 'custom_vhost_1' => { 'docroot' => '/var/www/custom_vhost_1', - 'port' => 81, + 'port' => 81 }, 'custom_vhost_2' => { 'docroot' => '/var/www/custom_vhost_2', - 'port' => 82, - }, - }, + 'port' => 82 + } + } } end diff --git a/spec/defines/balancer_spec.rb b/spec/defines/balancer_spec.rb index 3b2078aae6..5626cff603 100644 --- a/spec/defines/balancer_spec.rb +++ b/spec/defines/balancer_spec.rb @@ -18,31 +18,34 @@ it { is_expected.to contain_concat('apache_balancer_myapp') } it { is_expected.to contain_concat__fragment('00-myapp-header').with_content(%r{^$}) } end + describe 'accept a target parameter and use it' do let :params do { - target: '/tmp/myapp.conf', + target: '/tmp/myapp.conf' } end it { - is_expected.to contain_concat('apache_balancer_myapp').with(path: '/tmp/myapp.conf') + expect(subject).to contain_concat('apache_balancer_myapp').with(path: '/tmp/myapp.conf') } end + describe 'accept an options parameter and use it' do let :params do { - options: ['timeout=0', 'nonce=none'], + options: ['timeout=0', 'nonce=none'] } end it { - is_expected.to contain_concat__fragment('00-myapp-header').with_content( + expect(subject).to contain_concat__fragment('00-myapp-header').with_content( %r{^$}, ) } end end + describe 'apache pre_condition with conf_dir set' do let :pre_condition do 'class{"apache": @@ -51,7 +54,7 @@ end it { - is_expected.to contain_concat('apache_balancer_myapp').with(path: '/junk/path/balancer_myapp.conf') + expect(subject).to contain_concat('apache_balancer_myapp').with(path: '/junk/path/balancer_myapp.conf') } end @@ -59,8 +62,8 @@ let :params do { proxy_set: { - 'lbmethod' => 'bytraffic', - }, + 'lbmethod' => 'bytraffic' + } } end diff --git a/spec/defines/balancermember_spec.rb b/spec/defines/balancermember_spec.rb index 9521d52ee6..acd06c1be6 100644 --- a/spec/defines/balancermember_spec.rb +++ b/spec/defines/balancermember_spec.rb @@ -24,12 +24,13 @@ { options: [], url: 'http://127.0.0.1:8080/', - balancer_cluster: 'balancer-internal', + balancer_cluster: 'balancer-internal' } end it { is_expected.to contain_concat__fragment('BalancerMember http://127.0.0.1:8080/') } end + describe 'allows balancermember with a different target' do let :pre_condition do 'include apache @@ -44,12 +45,12 @@ { options: [], url: 'http://127.0.0.1:8080/', - balancer_cluster: 'balancername', + balancer_cluster: 'balancername' } end it { - is_expected.to contain_concat__fragment('BalancerMember http://127.0.0.1:8080/').with(target: 'apache_balancer_balancername') + expect(subject).to contain_concat__fragment('BalancerMember http://127.0.0.1:8080/').with(target: 'apache_balancer_balancername') } end end diff --git a/spec/defines/custom_config_spec.rb b/spec/defines/custom_config_spec.rb index 9963d6bd2c..89ef1f1611 100644 --- a/spec/defines/custom_config_spec.rb +++ b/spec/defines/custom_config_spec.rb @@ -15,58 +15,64 @@ context 'defaults with content' do let :params do { - 'content' => '# Test', + 'content' => '# Test' } end it { - is_expected.to contain_exec('syntax verification for rspec') + expect(subject).to contain_exec('syntax verification for rspec') .with('refreshonly' => 'true', 'command' => ['/usr/sbin/apachectl', '-t']) .that_subscribes_to('File[apache_rspec]') .that_notifies('Class[Apache::Service]') .that_comes_before('Exec[remove rspec if invalid]') } + it { - is_expected.to contain_exec('remove rspec if invalid') + expect(subject).to contain_exec('remove rspec if invalid') .with('unless' => [['/usr/sbin/apachectl', '-t']], 'refreshonly' => 'true') .that_subscribes_to('File[apache_rspec]') } + it { - is_expected.to contain_file('apache_rspec') + expect(subject).to contain_file('apache_rspec') .with('ensure' => 'present', 'content' => '# Test') .that_requires('Package[httpd]') } end + context 'set everything with source' do let :params do { - 'confdir' => '/dne', - 'priority' => 30, - 'source' => 'puppet:///modules/apache/test', - 'verify_command' => ['/bin/true'], + 'confdir' => '/dne', + 'priority' => 30, + 'source' => 'puppet:///modules/apache/test', + 'verify_command' => ['/bin/true'] } end it { - is_expected.to contain_exec('syntax verification for rspec').with('command' => ['/bin/true']) + expect(subject).to contain_exec('syntax verification for rspec').with('command' => ['/bin/true']) } + it { - is_expected.to contain_exec('remove rspec if invalid').with('command' => ['/bin/rm', '/dne/30-rspec.conf'], - 'unless' => [['/bin/true']]) + expect(subject).to contain_exec('remove rspec if invalid').with('command' => ['/bin/rm', '/dne/30-rspec.conf'], + 'unless' => [['/bin/true']]) } + it { - is_expected.to contain_file('apache_rspec') + expect(subject).to contain_file('apache_rspec') .that_requires('Package[httpd]') .with('path' => '/dne/30-rspec.conf', 'ensure' => 'present', 'source' => 'puppet:///modules/apache/test') } end + context 'verify_config => false' do let :params do { - 'content' => '# test', - 'verify_config' => false, + 'content' => '# test', + 'verify_config' => false } end @@ -74,10 +80,11 @@ it { is_expected.not_to contain_exec('remove rspec if invalid') } it { is_expected.to contain_file('apache_rspec').that_notifies('Class[Apache::Service]') } end + context 'ensure => absent' do let :params do { - 'ensure' => 'absent', + 'ensure' => 'absent' } end @@ -85,12 +92,13 @@ it { is_expected.not_to contain_exec('remove rspec if invalid') } it { is_expected.to contain_file('apache_rspec').with('ensure' => 'absent') } end + describe 'validation' do context 'both content and source' do let :params do { 'content' => 'foo', - 'source' => 'bar', + 'source' => 'bar' } end diff --git a/spec/defines/mod_spec.rb b/spec/defines/mod_spec.rb index a510cd564c..dc7ddde243 100644 --- a/spec/defines/mod_spec.rb +++ b/spec/defines/mod_spec.rb @@ -16,12 +16,13 @@ describe 'for non-special modules' do it { is_expected.to contain_class('apache::params') } + it 'manages the module load file' do - is_expected.to contain_file('spec_m.load').with(path: '/etc/httpd/conf.modules.d/spec_m.load', - content: "LoadModule spec_m_module modules/mod_spec_m.so\n", - owner: 'root', - group: 'root', - mode: '0644') + expect(subject).to contain_file('spec_m.load').with(path: '/etc/httpd/conf.modules.d/spec_m.load', + content: "LoadModule spec_m_module modules/mod_spec_m.so\n", + owner: 'root', + group: 'root', + mode: '0644') end end @@ -31,7 +32,7 @@ end it 'manages the module load file' do - is_expected.to contain_file('spec_m.load').with(mode: '0640') + expect(subject).to contain_file('spec_m.load').with(mode: '0640') end end @@ -53,19 +54,21 @@ describe 'for non-special modules' do it { is_expected.to contain_class('apache::params') } + it 'manages the module load file' do - is_expected.to contain_file('spec_m.load').with(path: '/etc/apache2/mods-available/spec_m.load', - content: "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n", - owner: 'root', - group: 'root', - mode: '0644') + expect(subject).to contain_file('spec_m.load').with(path: '/etc/apache2/mods-available/spec_m.load', + content: "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n", + owner: 'root', + group: 'root', + mode: '0644') end + it 'links the module load file' do - is_expected.to contain_file('spec_m.load symlink').with(path: '/etc/apache2/mods-enabled/spec_m.load', - target: '/etc/apache2/mods-available/spec_m.load', - owner: 'root', - group: 'root', - mode: '0644') + expect(subject).to contain_file('spec_m.load symlink').with(path: '/etc/apache2/mods-enabled/spec_m.load', + target: '/etc/apache2/mods-available/spec_m.load', + owner: 'root', + group: 'root', + mode: '0644') end end end @@ -75,12 +78,13 @@ describe 'for non-special modules' do it { is_expected.to contain_class('apache::params') } + it 'manages the module load file' do - is_expected.to contain_file('spec_m.load').with(path: '/usr/local/etc/apache24/Modules/spec_m.load', - content: "LoadModule spec_m_module /usr/local/libexec/apache24/mod_spec_m.so\n", - owner: 'root', - group: 'wheel', - mode: '0644') + expect(subject).to contain_file('spec_m.load').with(path: '/usr/local/etc/apache24/Modules/spec_m.load', + content: "LoadModule spec_m_module /usr/local/libexec/apache24/mod_spec_m.so\n", + owner: 'root', + group: 'wheel', + mode: '0644') end end end @@ -90,12 +94,13 @@ describe 'for non-special modules' do it { is_expected.to contain_class('apache::params') } + it 'manages the module load file' do - is_expected.to contain_file('spec_m.load').with(path: '/etc/apache2/modules.d/spec_m.load', - content: "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n", - owner: 'root', - group: 'wheel', - mode: '0644') + expect(subject).to contain_file('spec_m.load').with(path: '/etc/apache2/modules.d/spec_m.load', + content: "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n", + owner: 'root', + group: 'wheel', + mode: '0644') end end end diff --git a/spec/defines/modsec_link_spec.rb b/spec/defines/modsec_link_spec.rb index 400ae555de..ec9f161e7a 100644 --- a/spec/defines/modsec_link_spec.rb +++ b/spec/defines/modsec_link_spec.rb @@ -14,23 +14,24 @@ class { "apache::mod::security": activated_rules => [] } end on_supported_os.each do |os, facts| - context "on #{os} " do + context "on #{os}" do let :facts do facts end it { is_expected.to compile.with_all_deps } + case facts[:os]['family'] when 'RedHat' it { - is_expected.to contain_file('modsecurity_35_bad_robots.data').with( + expect(subject).to contain_file('modsecurity_35_bad_robots.data').with( path: '/etc/httpd/modsecurity.d/activated_rules/modsecurity_35_bad_robots.data', target: '/usr/lib/modsecurity.d/base_rules/modsecurity_35_bad_robots.data', ) } when 'Debian' it { - is_expected.to contain_file('modsecurity_35_bad_robots.data').with( + expect(subject).to contain_file('modsecurity_35_bad_robots.data').with( path: '/etc/modsecurity/activated_rules/modsecurity_35_bad_robots.data', target: '/usr/share/modsecurity-crs/base_rules/modsecurity_35_bad_robots.data', ) diff --git a/spec/defines/vhost_custom_spec.rb b/spec/defines/vhost_custom_spec.rb index 43a0ab25e3..627afa29d1 100644 --- a/spec/defines/vhost_custom_spec.rb +++ b/spec/defines/vhost_custom_spec.rb @@ -8,7 +8,7 @@ end let(:params) do { - content: 'foobar', + content: 'foobar' } end @@ -18,40 +18,44 @@ it { is_expected.to compile } end + context 'on Debian based systems' do include_examples 'Debian 11' it { - is_expected.to contain_file('apache_rspec.example.com').with( + expect(subject).to contain_file('apache_rspec.example.com').with( ensure: 'present', content: 'foobar', path: '/etc/apache2/sites-available/25-rspec.example.com.conf', ) } + it { - is_expected.to contain_file('25-rspec.example.com.conf symlink').with( + expect(subject).to contain_file('25-rspec.example.com.conf symlink').with( ensure: 'link', path: '/etc/apache2/sites-enabled/25-rspec.example.com.conf', target: '/etc/apache2/sites-available/25-rspec.example.com.conf', ) } end + context 'on FreeBSD systems' do include_examples 'FreeBSD 9' it { - is_expected.to contain_file('apache_rspec.example.com').with( + expect(subject).to contain_file('apache_rspec.example.com').with( ensure: 'present', content: 'foobar', path: '/usr/local/etc/apache24/Vhosts/25-rspec.example.com.conf', ) } end + context 'on Gentoo systems' do include_examples 'Gentoo' it { - is_expected.to contain_file('apache_rspec.example.com').with( + expect(subject).to contain_file('apache_rspec.example.com').with( ensure: 'present', content: 'foobar', path: '/etc/apache2/vhosts.d/25-rspec.example.com.conf', diff --git a/spec/defines/vhost_fragment_spec.rb b/spec/defines/vhost_fragment_spec.rb index c5aac54c96..36aecc8c15 100644 --- a/spec/defines/vhost_fragment_spec.rb +++ b/spec/defines/vhost_fragment_spec.rb @@ -15,7 +15,7 @@ { vhost: 'default', port: 80, - priority: 15, + priority: 15 } end @@ -23,9 +23,9 @@ let(:params) { super().merge(content: '# Foo') } it 'creates a vhost concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('15-default-80.conf') - is_expected.to create_concat__fragment('default-myfragment') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('15-default-80.conf') + expect(subject).to create_concat__fragment('default-myfragment') .with_target('15-default-80.conf') .with_order(900) .with_content('# Foo') @@ -36,9 +36,9 @@ let(:params) { super().merge(content: '') } it 'does not create a vhost concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('15-default-80.conf') - is_expected.not_to contain_concat__fragment('default-myfragment') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('15-default-80.conf') + expect(subject).not_to contain_concat__fragment('default-myfragment') end end end @@ -47,7 +47,7 @@ let(:params) do { vhost: 'custom', - content: '# Foo', + content: '# Foo' } end @@ -64,9 +64,9 @@ end it 'creates a vhost concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('custom.conf') - is_expected.to create_concat__fragment('custom-myfragment') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('custom.conf') + expect(subject).to create_concat__fragment('custom-myfragment') .with_target('custom.conf') .with_order(900) .with_content('# Foo') @@ -86,9 +86,9 @@ end it 'creates a vhost concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('42-custom.conf') - is_expected.to create_concat__fragment('custom-myfragment') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('42-custom.conf') + expect(subject).to create_concat__fragment('custom-myfragment') .with_target('42-custom.conf') .with_order(900) .with_content('# Foo') @@ -106,9 +106,9 @@ end it 'creates a vhost concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('25-custom.conf') - is_expected.to create_concat__fragment('custom-myfragment') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('25-custom.conf') + expect(subject).to create_concat__fragment('custom-myfragment') .with_target('25-custom.conf') .with_order(900) .with_content('# Foo') diff --git a/spec/defines/vhost_proxy_spec.rb b/spec/defines/vhost_proxy_spec.rb index fbdf642386..b7b5c75c31 100644 --- a/spec/defines/vhost_proxy_spec.rb +++ b/spec/defines/vhost_proxy_spec.rb @@ -15,7 +15,7 @@ { vhost: 'default', port: 80, - priority: 15, + priority: 15 } end @@ -29,16 +29,16 @@ proxy_pass: [ { path: '/', - url: 'http://localhost:8080/', + url: 'http://localhost:8080/' }, ], ) end it 'creates a concat fragment' do - is_expected.to compile.with_all_deps - is_expected.to contain_concat('15-default-80.conf') - is_expected.to create_concat__fragment('default-myproxy-proxy') + expect(subject).to compile.with_all_deps + expect(subject).to contain_concat('15-default-80.conf') + expect(subject).to create_concat__fragment('default-myproxy-proxy') .with_target('15-default-80.conf') .with_order(170) .with_content( diff --git a/spec/defines/vhost_spec.rb b/spec/defines/vhost_spec.rb index b99f7b61b3..c267ef936d 100644 --- a/spec/defines/vhost_spec.rb +++ b/spec/defines/vhost_spec.rb @@ -5,7 +5,7 @@ describe 'apache::vhost', type: :define do describe 'os-independent items' do on_supported_os.each do |os, os_facts| - let(:apache_name) { facts[:os]['family'] == 'RedHat' ? 'httpd' : 'apache2' } + let(:apache_name) { (facts[:os]['family'] == 'RedHat') ? 'httpd' : 'apache2' } let :pre_condition do "class {'apache': default_vhost => false, default_mods => false, vhost_enable_dir => '/etc/#{apache_name}/sites-enabled'}" @@ -18,11 +18,11 @@ let :default_params do { docroot: '/rspec/docroot', - port: 84, + port: 84 } end - context "on #{os} " do + context "on #{os}" do let :facts do os_facts end @@ -34,352 +34,353 @@ it { is_expected.to contain_class('apache::params') } it { is_expected.to contain_apache__listen(params[:port]) } end + context 'set everything!' do let :params do { - 'docroot' => '/var/www/foo', - 'manage_docroot' => false, - 'virtual_docroot' => true, + 'docroot' => '/var/www/foo', + 'manage_docroot' => false, + 'virtual_docroot' => true, 'virtual_use_default_docroot' => false, - 'port' => 8080, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'add_listen' => false, - 'docroot_owner' => 'user', - 'docroot_group' => 'wheel', - 'docroot_mode' => '0664', - 'serveradmin' => 'foo@localhost', - 'ssl' => true, - 'ssl_cert' => '/ssl/cert', - 'ssl_key' => '/ssl/key', - 'ssl_chain' => '/ssl/chain', - 'ssl_crl_path' => '/ssl/crl', - 'ssl_crl' => '/ssl/foo.crl', - 'ssl_certs_dir' => '/ssl/certs', - 'ssl_protocol' => 'SSLv2', - 'ssl_cipher' => 'HIGH', - 'ssl_honorcipherorder' => 'Off', - 'ssl_verify_client' => 'optional', - 'ssl_verify_depth' => 3, - 'ssl_options' => '+ExportCertData', - 'ssl_openssl_conf_cmd' => 'DHParameters "foo.pem"', - 'ssl_proxy_verify' => 'require', - 'ssl_proxy_check_peer_cn' => 'on', - 'ssl_proxy_check_peer_name' => 'on', + 'port' => 8080, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'add_listen' => false, + 'docroot_owner' => 'user', + 'docroot_group' => 'wheel', + 'docroot_mode' => '0664', + 'serveradmin' => 'foo@localhost', + 'ssl' => true, + 'ssl_cert' => '/ssl/cert', + 'ssl_key' => '/ssl/key', + 'ssl_chain' => '/ssl/chain', + 'ssl_crl_path' => '/ssl/crl', + 'ssl_crl' => '/ssl/foo.crl', + 'ssl_certs_dir' => '/ssl/certs', + 'ssl_protocol' => 'SSLv2', + 'ssl_cipher' => 'HIGH', + 'ssl_honorcipherorder' => 'Off', + 'ssl_verify_client' => 'optional', + 'ssl_verify_depth' => 3, + 'ssl_options' => '+ExportCertData', + 'ssl_openssl_conf_cmd' => 'DHParameters "foo.pem"', + 'ssl_proxy_verify' => 'require', + 'ssl_proxy_check_peer_cn' => 'on', + 'ssl_proxy_check_peer_name' => 'on', 'ssl_proxy_check_peer_expire' => 'on', - 'ssl_proxyengine' => true, - 'ssl_proxy_cipher_suite' => 'HIGH', - 'ssl_proxy_protocol' => 'TLSv1.2', - 'ssl_user_name' => 'SSL_CLIENT_S_DN_CN', - 'ssl_reload_on_change' => true, - 'priority' => 30, - 'default_vhost' => true, - 'servername' => 'example.com', - 'serveraliases' => ['test-example.com'], - 'options' => ['MultiView'], - 'override' => ['All'], - 'directoryindex' => 'index.html', - 'vhost_name' => 'test', - 'logroot' => '/var/www/logs', - 'logroot_ensure' => 'directory', - 'logroot_mode' => '0600', - 'logroot_owner' => 'root', - 'logroot_group' => 'root', - 'log_level' => 'crit', - 'aliases' => [ + 'ssl_proxyengine' => true, + 'ssl_proxy_cipher_suite' => 'HIGH', + 'ssl_proxy_protocol' => 'TLSv1.2', + 'ssl_user_name' => 'SSL_CLIENT_S_DN_CN', + 'ssl_reload_on_change' => true, + 'priority' => 30, + 'default_vhost' => true, + 'servername' => 'example.com', + 'serveraliases' => ['test-example.com'], + 'options' => ['MultiView'], + 'override' => ['All'], + 'directoryindex' => 'index.html', + 'vhost_name' => 'test', + 'logroot' => '/var/www/logs', + 'logroot_ensure' => 'directory', + 'logroot_mode' => '0600', + 'logroot_owner' => 'root', + 'logroot_group' => 'root', + 'log_level' => 'crit', + 'aliases' => [ { 'alias' => '/image', - 'path' => '/rspec/image', + 'path' => '/rspec/image' }, ], - 'access_log' => false, - 'access_log_file' => 'httpd_access_log', - 'access_log_syslog' => true, - 'access_log_format' => '%h %l %u %t \"%r\" %>s %b', - 'access_log_env_var' => '', - 'directories' => [ + 'access_log' => false, + 'access_log_file' => 'httpd_access_log', + 'access_log_syslog' => true, + 'access_log_format' => '%h %l %u %t \"%r\" %>s %b', + 'access_log_env_var' => '', + 'directories' => [ { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'require' => ['valid-user', 'all denied'], + 'require' => ['valid-user', 'all denied'] }, { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'additional_includes' => ['/custom/path/includes', '/custom/path/another_includes'], + 'additional_includes' => ['/custom/path/includes', '/custom/path/another_includes'] }, { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'require' => 'all granted', + 'require' => 'all granted' }, { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'require' => + 'require' => { - 'enforce' => 'all', - 'requires' => ['all-valid1', 'all-valid2'], - }, + 'enforce' => 'all', + 'requires' => ['all-valid1', 'all-valid2'] + } }, { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'require' => + 'require' => { - 'enforce' => 'none', - 'requires' => ['none-valid1', 'none-valid2'], - }, + 'enforce' => 'none', + 'requires' => ['none-valid1', 'none-valid2'] + } }, { - 'path' => '/var/www/files', + 'path' => '/var/www/files', 'provider' => 'files', - 'require' => + 'require' => { - 'enforce' => 'any', - 'requires' => ['any-valid1', 'any-valid2'], - }, + 'enforce' => 'any', + 'requires' => ['any-valid1', 'any-valid2'] + } }, { - 'path' => '*', - 'provider' => 'proxy', + 'path' => '*', + 'provider' => 'proxy' }, - { 'path' => '/var/www/files/indexed_directory', - 'directoryindex' => 'disabled', - 'options' => ['Indexes', 'FollowSymLinks', 'MultiViews'], - 'index_options' => ['FancyIndexing'], + { 'path' => '/var/www/files/indexed_directory', + 'directoryindex' => 'disabled', + 'options' => ['Indexes', 'FollowSymLinks', 'MultiViews'], + 'index_options' => ['FancyIndexing'], 'index_style_sheet' => '/styles/style.css' }, - { 'path' => '/var/www/files/output_filtered', + { 'path' => '/var/www/files/output_filtered', 'set_output_filter' => 'output_filter' }, - { 'path' => '/var/www/files/input_filtered', + { 'path' => '/var/www/files/input_filtered', 'set_input_filter' => 'input_filter' }, - { 'path' => '/var/www/files', + { 'path' => '/var/www/files', 'provider' => 'location', - 'limit' => [ + 'limit' => [ { 'methods' => 'GET HEAD', 'require' => ['valid-user'] }, ] }, - { 'path' => '/var/www/files', - 'provider' => 'location', + { 'path' => '/var/www/files', + 'provider' => 'location', 'limit_except' => [ { 'methods' => 'GET HEAD', 'require' => ['valid-user'] }, ] }, - { 'path' => '/var/www/dav', - 'dav' => 'filesystem', + { 'path' => '/var/www/dav', + 'dav' => 'filesystem', 'dav_depth_infinity' => true, - 'dav_min_timeout' => 600 }, + 'dav_min_timeout' => 600 }, { - 'path' => '/var/www/http2', - 'h2_copy_files' => true, + 'path' => '/var/www/http2', + 'h2_copy_files' => true, 'h2_push_resource' => [ '/foo.css', '/foo.js', - ], + ] }, { - 'path' => '/', - 'provider' => 'location', + 'path' => '/', + 'provider' => 'location', 'auth_ldap_referrals' => 'off', - 'auth_basic_fake' => 'demo demopass', - 'auth_user_file' => '/path/to/authz_user_file', - 'auth_group_file' => '/path/to/authz_group_file', - 'setenv' => ['SPECIAL_PATH /foo/bin'], + 'auth_basic_fake' => 'demo demopass', + 'auth_user_file' => '/path/to/authz_user_file', + 'auth_group_file' => '/path/to/authz_group_file', + 'setenv' => ['SPECIAL_PATH /foo/bin'] }, { - 'path' => '/proxy', - 'provider' => 'location', + 'path' => '/proxy', + 'provider' => 'location', 'proxy_pass' => [ { - 'url' => 'http://backend-b/', - 'keywords' => ['noquery', 'interpolate'], + 'url' => 'http://backend-b/', + 'keywords' => ['noquery', 'interpolate'], 'params' => { - 'retry' => 0, - 'timeout' => 5, - }, + 'retry' => 0, + 'timeout' => 5 + } }, - ], + ] }, { - 'path' => '^/proxy', - 'provider' => 'locationmatch', + 'path' => '^/proxy', + 'provider' => 'locationmatch', 'proxy_pass_match' => [ { - 'url' => 'http://backend-b/', - 'keywords' => ['noquery', 'interpolate'], + 'url' => 'http://backend-b/', + 'keywords' => ['noquery', 'interpolate'], 'params' => { - 'retry' => 0, - 'timeout' => 5, - }, + 'retry' => 0, + 'timeout' => 5 + } }, - ], + ] }, { - 'path' => '/var/www/node-app/public', - 'passenger_enabled' => true, - 'passenger_base_uri' => '/app', - 'passenger_ruby' => '/path/to/ruby', - 'passenger_python' => '/path/to/python', - 'passenger_nodejs' => '/path/to/nodejs', - 'passenger_meteor_app_settings' => '/path/to/file.json', - 'passenger_app_env' => 'demo', - 'passenger_app_root' => '/var/www/node-app', - 'passenger_app_group_name' => 'foo_bar', - 'passenger_app_start_command' => 'start-command', - 'passenger_app_type' => 'node', - 'passenger_startup_file' => 'start.js', - 'passenger_restart_dir' => 'temp', - 'passenger_load_shell_envvars' => false, - 'passenger_preload_bundler' => false, - 'passenger_rolling_restarts' => false, - 'passenger_resist_deployment_errors' => false, - 'passenger_user' => 'nodeuser', - 'passenger_group' => 'nodegroup', - 'passenger_friendly_error_pages' => true, - 'passenger_min_instances' => 7, - 'passenger_max_instances' => 9, + 'path' => '/var/www/node-app/public', + 'passenger_enabled' => true, + 'passenger_base_uri' => '/app', + 'passenger_ruby' => '/path/to/ruby', + 'passenger_python' => '/path/to/python', + 'passenger_nodejs' => '/path/to/nodejs', + 'passenger_meteor_app_settings' => '/path/to/file.json', + 'passenger_app_env' => 'demo', + 'passenger_app_root' => '/var/www/node-app', + 'passenger_app_group_name' => 'foo_bar', + 'passenger_app_start_command' => 'start-command', + 'passenger_app_type' => 'node', + 'passenger_startup_file' => 'start.js', + 'passenger_restart_dir' => 'temp', + 'passenger_load_shell_envvars' => false, + 'passenger_preload_bundler' => false, + 'passenger_rolling_restarts' => false, + 'passenger_resist_deployment_errors' => false, + 'passenger_user' => 'nodeuser', + 'passenger_group' => 'nodegroup', + 'passenger_friendly_error_pages' => true, + 'passenger_min_instances' => 7, + 'passenger_max_instances' => 9, 'passenger_force_max_concurrent_requests_per_process' => 12, - 'passenger_start_timeout' => 10, - 'passenger_concurrency_model' => 'thread', - 'passenger_thread_count' => 20, - 'passenger_max_requests' => 2000, - 'passenger_max_request_time' => 1, - 'passenger_memory_limit' => 32, - 'passenger_high_performance' => false, - 'passenger_buffer_upload' => false, - 'passenger_buffer_response' => false, - 'passenger_error_override' => false, - 'passenger_max_request_queue_size' => 120, - 'passenger_max_request_queue_time' => 5, - 'passenger_sticky_sessions' => true, - 'passenger_sticky_sessions_cookie_name' => '_delicious_cookie', - 'passenger_sticky_sessions_cookie_attributes' => 'SameSite=Lax; Secure;', - 'passenger_allow_encoded_slashes' => false, - 'passenger_app_log_file' => '/tmp/app.log', - 'passenger_debugger' => false, - 'gssapi' => { - 'acceptor_name' => '{HOSTNAME}', - 'allowed_mech' => ['krb5', 'iakerb', 'ntlmssp'], - 'authname' => 'Kerberos 5', - 'authtype' => 'GSSAPI', - 'basic_auth' => true, - 'basic_auth_mech' => ['krb5', 'iakerb', 'ntlmssp'], - 'basic_ticket_timeout' => 300, - 'connection_bound' => true, - 'cred_store' => { - 'ccache' => ['/path/to/directory'], + 'passenger_start_timeout' => 10, + 'passenger_concurrency_model' => 'thread', + 'passenger_thread_count' => 20, + 'passenger_max_requests' => 2000, + 'passenger_max_request_time' => 1, + 'passenger_memory_limit' => 32, + 'passenger_high_performance' => false, + 'passenger_buffer_upload' => false, + 'passenger_buffer_response' => false, + 'passenger_error_override' => false, + 'passenger_max_request_queue_size' => 120, + 'passenger_max_request_queue_time' => 5, + 'passenger_sticky_sessions' => true, + 'passenger_sticky_sessions_cookie_name' => '_delicious_cookie', + 'passenger_sticky_sessions_cookie_attributes' => 'SameSite=Lax; Secure;', + 'passenger_allow_encoded_slashes' => false, + 'passenger_app_log_file' => '/tmp/app.log', + 'passenger_debugger' => false, + 'gssapi' => { + 'acceptor_name' => '{HOSTNAME}', + 'allowed_mech' => ['krb5', 'iakerb', 'ntlmssp'], + 'authname' => 'Kerberos 5', + 'authtype' => 'GSSAPI', + 'basic_auth' => true, + 'basic_auth_mech' => ['krb5', 'iakerb', 'ntlmssp'], + 'basic_ticket_timeout' => 300, + 'connection_bound' => true, + 'cred_store' => { + 'ccache' => ['/path/to/directory'], 'client_keytab' => ['/path/to/example.keytab'], - 'keytab' => ['/path/to/example.keytab'], + 'keytab' => ['/path/to/example.keytab'] }, - 'deleg_ccache_dir' => '/path/to/directory', - 'deleg_ccache_env_var' => 'KRB5CCNAME', - 'deleg_ccache_perms' => { + 'deleg_ccache_dir' => '/path/to/directory', + 'deleg_ccache_env_var' => 'KRB5CCNAME', + 'deleg_ccache_perms' => { 'mode' => '0600', - 'uid' => 'example-user', - 'gid' => 'example-group', + 'uid' => 'example-user', + 'gid' => 'example-group' }, - 'deleg_ccache_unique' => true, - 'impersonate' => true, - 'local_name' => true, - 'name_attributes' => 'json', - 'negotiate_once' => true, - 'publish_errors' => true, - 'publish_mech' => true, + 'deleg_ccache_unique' => true, + 'impersonate' => true, + 'local_name' => true, + 'name_attributes' => 'json', + 'negotiate_once' => true, + 'publish_errors' => true, + 'publish_mech' => true, 'required_name_attributes' => 'auth-indicators=high', - 'session_key' => 'file:/path/to/example.key', - 'signal_persistent_auth' => true, - 'ssl_only' => true, - 'use_s4u2_proxy' => true, - 'use_sessions' => true, - }, + 'session_key' => 'file:/path/to/example.key', + 'signal_persistent_auth' => true, + 'ssl_only' => true, + 'use_s4u2_proxy' => true, + 'use_sessions' => true + } }, { - 'path' => '/private_1', - 'provider' => 'location', - 'ssl_options' => ['+ExportCertData', '+StdEnvVars'], + 'path' => '/private_1', + 'provider' => 'location', + 'ssl_options' => ['+ExportCertData', '+StdEnvVars'], 'ssl_verify_client' => 'optional', - 'ssl_verify_depth' => 10, + 'ssl_verify_depth' => 10 }, ], - 'error_log' => false, - 'error_log_file' => 'httpd_error_log', - 'error_log_syslog' => true, - 'error_log_format' => ['[%t] [%l] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i'], - 'error_documents' => 'true', - 'fallbackresource' => '/index.php', - 'scriptalias' => '/usr/lib/cgi-bin', - 'scriptaliases' => [ + 'error_log' => false, + 'error_log_file' => 'httpd_error_log', + 'error_log_syslog' => true, + 'error_log_format' => ['[%t] [%l] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i'], + 'error_documents' => 'true', + 'fallbackresource' => '/index.php', + 'scriptalias' => '/usr/lib/cgi-bin', + 'scriptaliases' => [ { 'alias' => '/myscript', - 'path' => '/usr/share/myscript', + 'path' => '/usr/share/myscript' }, { 'aliasmatch' => '^/foo(.*)', - 'path' => '/usr/share/fooscripts$1', + 'path' => '/usr/share/fooscripts$1' }, ], - 'limitreqfieldsize' => 8190, - 'limitreqfields' => 100, - 'limitreqline' => 8190, - 'limitreqbody' => 0, - 'proxy_dest' => '/', - 'proxy_pass' => [ + 'limitreqfieldsize' => 8190, + 'limitreqfields' => 100, + 'limitreqline' => 8190, + 'limitreqbody' => 0, + 'proxy_dest' => '/', + 'proxy_pass' => [ { - 'path' => '/a', - 'url' => 'http://backend-a/', - 'keywords' => ['noquery', 'interpolate'], - 'no_proxy_uris' => ['/a/foo', '/a/bar'], + 'path' => '/a', + 'url' => 'http://backend-a/', + 'keywords' => ['noquery', 'interpolate'], + 'no_proxy_uris' => ['/a/foo', '/a/bar'], 'no_proxy_uris_match' => ['/a/foomatch'], 'reverse_cookies' => [ { 'path' => '/a', - 'url' => 'http://backend-a/', + 'url' => 'http://backend-a/' }, { 'domain' => 'foo', - 'url' => 'http://foo', + 'url' => 'http://foo' }, ], 'params' => { - 'retry' => 0, - 'timeout' => 5, + 'retry' => 0, + 'timeout' => 5 }, - 'setenv' => ['proxy-nokeepalive 1', 'force-proxy-request-1.0 1'], + 'setenv' => ['proxy-nokeepalive 1', 'force-proxy-request-1.0 1'] }, ], 'proxy_pass_match' => [ { - 'path' => '/a', - 'url' => 'http://backend-a/', + 'path' => '/a', + 'url' => 'http://backend-a/', 'keywords' => ['noquery', 'interpolate'], - 'no_proxy_uris' => ['/a/foo', '/a/bar'], + 'no_proxy_uris' => ['/a/foo', '/a/bar'], 'no_proxy_uris_match' => ['/a/foomatch'], 'params' => { - 'retry' => 0, - 'timeout' => 5, + 'retry' => 0, + 'timeout' => 5 }, - 'setenv' => ['proxy-nokeepalive 1', 'force-proxy-request-1.0 1'], + 'setenv' => ['proxy-nokeepalive 1', 'force-proxy-request-1.0 1'] }, ], - 'proxy_requests' => false, - 'php_admin_flags' => ['foo', 'bar'], - 'php_admin_values' => ['true', 'false'], - 'no_proxy_uris' => '/foo', - 'no_proxy_uris_match' => '/foomatch', - 'proxy_preserve_host' => true, - 'proxy_add_headers' => true, - 'proxy_error_override' => true, - 'redirect_source' => '/bar', - 'redirect_dest' => '/', - 'redirect_status' => 'temp', - 'redirectmatch_status' => ['404'], - 'redirectmatch_regexp' => ['\.git$'], - 'redirectmatch_dest' => ['http://www.example.com'], - 'headers' => ['Set X-Robots-Tag "noindex, noarchive, nosnippet"'], - 'request_headers' => ['append MirrorID "mirror 12"'], - 'rewrites' => [ + 'proxy_requests' => false, + 'php_admin_flags' => ['foo', 'bar'], + 'php_admin_values' => ['true', 'false'], + 'no_proxy_uris' => '/foo', + 'no_proxy_uris_match' => '/foomatch', + 'proxy_preserve_host' => true, + 'proxy_add_headers' => true, + 'proxy_error_override' => true, + 'redirect_source' => '/bar', + 'redirect_dest' => '/', + 'redirect_status' => 'temp', + 'redirectmatch_status' => ['404'], + 'redirectmatch_regexp' => ['\.git$'], + 'redirectmatch_dest' => ['http://www.example.com'], + 'headers' => ['Set X-Robots-Tag "noindex, noarchive, nosnippet"'], + 'request_headers' => ['append MirrorID "mirror 12"'], + 'rewrites' => [ { - 'rewrite_rule' => ['^index.html$ rewrites.html'], + 'rewrite_rule' => ['^index.html$ rewrites.html'] }, ], 'filters' => [ @@ -391,171 +392,177 @@ 'FilterChain COMPRESS', 'FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no', ], - 'rewrite_base' => '/', - 'rewrite_rule' => '^index.html$ welcome.html', - 'rewrite_cond' => ['%{HTTP_USER_AGENT} ^MSIE'], - 'rewrite_inherit' => true, - 'setenv' => ['FOO=/bin/true'], - 'setenvif' => 'Request_URI "\.gif$" object_is_image=gif', - 'setenvifnocase' => 'REMOTE_ADDR ^127.0.0.1 localhost=true', - 'block' => 'scm', - 'wsgi_application_group' => '%{GLOBAL}', - 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, + 'rewrite_base' => '/', + 'rewrite_rule' => '^index.html$ welcome.html', + 'rewrite_cond' => ['%{HTTP_USER_AGENT} ^MSIE'], + 'rewrite_inherit' => true, + 'setenv' => ['FOO=/bin/true'], + 'setenvif' => 'Request_URI "\.gif$" object_is_image=gif', + 'setenvifnocase' => 'REMOTE_ADDR ^127.0.0.1 localhost=true', + 'block' => 'scm', + 'wsgi_application_group' => '%{GLOBAL}', + 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, 'wsgi_daemon_process_options' => { - 'processes' => 2, - 'threads' => 15, - 'display-name' => '%{GROUP}', + 'processes' => 2, + 'threads' => 15, + 'display-name' => '%{GROUP}' }, - 'wsgi_import_script' => '/var/www/demo.wsgi', - 'wsgi_import_script_options' => { - 'process-group' => 'wsgi', - 'application-group' => '%{GLOBAL}', + 'wsgi_import_script' => '/var/www/demo.wsgi', + 'wsgi_import_script_options' => { + 'process-group' => 'wsgi', + 'application-group' => '%{GLOBAL}' }, - 'wsgi_process_group' => 'wsgi', - 'wsgi_script_aliases' => { - '/' => '/var/www/demo.wsgi', + 'wsgi_process_group' => 'wsgi', + 'wsgi_script_aliases' => { + '/' => '/var/www/demo.wsgi' }, 'wsgi_script_aliases_match' => { - '^/test/(^[/*)' => '/var/www/demo.wsgi', + '^/test/(^[/*)' => '/var/www/demo.wsgi' }, - 'wsgi_pass_authorization' => 'On', - 'custom_fragment' => '#custom string', - 'itk' => { - 'user' => 'someuser', - 'group' => 'somegroup', + 'wsgi_pass_authorization' => 'On', + 'custom_fragment' => '#custom string', + 'itk' => { + 'user' => 'someuser', + 'group' => 'somegroup' }, - 'wsgi_chunked_request' => 'On', - 'action' => 'foo', - 'additional_includes' => '/custom/path/includes', - 'use_optional_includes' => true, - 'suexec_user_group' => 'root root', - 'allow_encoded_slashes' => 'nodecode', - 'use_canonical_name' => 'dns', - - 'h2_copy_files' => false, - 'h2_direct' => true, - 'h2_early_hints' => false, - 'h2_max_session_streams' => 100, - 'h2_modern_tls_only' => true, - 'h2_push' => true, - 'h2_push_diary_size' => 256, - 'h2_push_priority' => [ + 'wsgi_chunked_request' => 'On', + 'action' => 'foo', + 'additional_includes' => '/custom/path/includes', + 'use_optional_includes' => true, + 'suexec_user_group' => 'root root', + 'allow_encoded_slashes' => 'nodecode', + 'use_canonical_name' => 'dns', + + 'h2_copy_files' => false, + 'h2_direct' => true, + 'h2_early_hints' => false, + 'h2_max_session_streams' => 100, + 'h2_modern_tls_only' => true, + 'h2_push' => true, + 'h2_push_diary_size' => 256, + 'h2_push_priority' => [ 'application/json 32', ], 'h2_push_resource' => [ '/css/main.css', '/js/main.js', ], - 'h2_serialize_headers' => false, - 'h2_stream_max_mem_size' => 65_536, - 'h2_tls_cool_down_secs' => 1, - 'h2_tls_warm_up_size' => 1_048_576, - 'h2_upgrade' => true, - 'h2_window_size' => 65_535, - - 'passenger_enabled' => false, - 'passenger_base_uri' => '/app', - 'passenger_ruby' => '/usr/bin/ruby1.9.1', - 'passenger_python' => '/usr/local/bin/python', - 'passenger_nodejs' => '/usr/bin/node', - 'passenger_meteor_app_settings' => '/path/to/some/file.json', - 'passenger_app_env' => 'test', - 'passenger_app_root' => '/usr/share/myapp', - 'passenger_app_group_name' => 'app_customer', - 'passenger_app_start_command' => 'start-my-app', - 'passenger_app_type' => 'rack', - 'passenger_startup_file' => 'bin/www', - 'passenger_restart_dir' => 'tmp', - 'passenger_spawn_method' => 'direct', - 'passenger_load_shell_envvars' => false, - 'passenger_preload_bundler' => false, - 'passenger_rolling_restarts' => false, - 'passenger_resist_deployment_errors' => true, - 'passenger_user' => 'sandbox', - 'passenger_group' => 'sandbox', - 'passenger_friendly_error_pages' => false, - 'passenger_min_instances' => 1, - 'passenger_max_instances' => 30, - 'passenger_max_preloader_idle_time' => 600, + 'h2_serialize_headers' => false, + 'h2_stream_max_mem_size' => 65_536, + 'h2_tls_cool_down_secs' => 1, + 'h2_tls_warm_up_size' => 1_048_576, + 'h2_upgrade' => true, + 'h2_window_size' => 65_535, + + 'passenger_enabled' => false, + 'passenger_base_uri' => '/app', + 'passenger_ruby' => '/usr/bin/ruby1.9.1', + 'passenger_python' => '/usr/local/bin/python', + 'passenger_nodejs' => '/usr/bin/node', + 'passenger_meteor_app_settings' => '/path/to/some/file.json', + 'passenger_app_env' => 'test', + 'passenger_app_root' => '/usr/share/myapp', + 'passenger_app_group_name' => 'app_customer', + 'passenger_app_start_command' => 'start-my-app', + 'passenger_app_type' => 'rack', + 'passenger_startup_file' => 'bin/www', + 'passenger_restart_dir' => 'tmp', + 'passenger_spawn_method' => 'direct', + 'passenger_load_shell_envvars' => false, + 'passenger_preload_bundler' => false, + 'passenger_rolling_restarts' => false, + 'passenger_resist_deployment_errors' => true, + 'passenger_user' => 'sandbox', + 'passenger_group' => 'sandbox', + 'passenger_friendly_error_pages' => false, + 'passenger_min_instances' => 1, + 'passenger_max_instances' => 30, + 'passenger_max_preloader_idle_time' => 600, 'passenger_force_max_concurrent_requests_per_process' => 10, - 'passenger_start_timeout' => 600, - 'passenger_concurrency_model' => 'thread', - 'passenger_thread_count' => 5, - 'passenger_max_requests' => 1000, - 'passenger_max_request_time' => 2, - 'passenger_memory_limit' => 64, - 'passenger_stat_throttle_rate' => 5, - 'passenger_pre_start' => 'http://localhost/myapp', - 'passenger_high_performance' => true, - 'passenger_buffer_upload' => false, - 'passenger_buffer_response' => false, - 'passenger_error_override' => true, - 'passenger_max_request_queue_size' => 10, - 'passenger_max_request_queue_time' => 2, - 'passenger_sticky_sessions' => true, + 'passenger_start_timeout' => 600, + 'passenger_concurrency_model' => 'thread', + 'passenger_thread_count' => 5, + 'passenger_max_requests' => 1000, + 'passenger_max_request_time' => 2, + 'passenger_memory_limit' => 64, + 'passenger_stat_throttle_rate' => 5, + 'passenger_pre_start' => 'http://localhost/myapp', + 'passenger_high_performance' => true, + 'passenger_buffer_upload' => false, + 'passenger_buffer_response' => false, + 'passenger_error_override' => true, + 'passenger_max_request_queue_size' => 10, + 'passenger_max_request_queue_time' => 2, + 'passenger_sticky_sessions' => true, 'passenger_sticky_sessions_cookie_name' => '_nom_nom_nom', 'passenger_sticky_sessions_cookie_attributes' => 'Nom=nom; Secure;', - 'passenger_allow_encoded_slashes' => true, - 'passenger_app_log_file' => '/app/log/file', - 'passenger_debugger' => true, - 'passenger_lve_min_uid' => 500, - 'add_default_charset' => 'UTF-8', - 'jk_mounts' => [ + 'passenger_allow_encoded_slashes' => true, + 'passenger_app_log_file' => '/app/log/file', + 'passenger_debugger' => true, + 'passenger_lve_min_uid' => 500, + 'add_default_charset' => 'UTF-8', + 'jk_mounts' => [ { 'mount' => '/*', 'worker' => 'tcnode1' }, { 'unmount' => '/*.jpg', 'worker' => 'tcnode1' }, ], - 'auth_kerb' => true, - 'krb_method_negotiate' => 'off', - 'krb_method_k5passwd' => 'off', - 'krb_authoritative' => 'off', - 'krb_auth_realms' => ['EXAMPLE.ORG', 'EXAMPLE.NET'], - 'krb_5keytab' => '/tmp/keytab5', - 'krb_local_user_mapping' => 'off', + 'auth_kerb' => true, + 'krb_method_negotiate' => 'off', + 'krb_method_k5passwd' => 'off', + 'krb_authoritative' => 'off', + 'krb_auth_realms' => ['EXAMPLE.ORG', 'EXAMPLE.NET'], + 'krb_5keytab' => '/tmp/keytab5', + 'krb_local_user_mapping' => 'off', 'http_protocol_options' => 'Strict LenientMethods Allow0.9', - 'keepalive' => 'on', - 'keepalive_timeout' => 100, - 'max_keepalive_requests' => 1000, - 'protocols' => ['h2', 'http/1.1'], - 'protocols_honor_order' => true, - 'auth_oidc' => true, - 'oidc_settings' => { 'ProviderMetadataURL' => 'https://login.example.com/.well-known/openid-configuration', - 'ClientID' => 'test', - 'RedirectURI' => 'https://login.example.com/redirect_uri', - 'ProviderTokenEndpointAuth' => 'client_secret_basic', - 'RemoteUserClaim' => 'sub', - 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', - 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, - 'mdomain' => 'example.com example.net auto', - 'userdir' => 'disabled', + 'keepalive' => 'on', + 'keepalive_timeout' => 100, + 'max_keepalive_requests' => 1000, + 'protocols' => ['h2', 'http/1.1'], + 'protocols_honor_order' => true, + 'auth_oidc' => true, + 'oidc_settings' => { 'ProviderMetadataURL' => 'https://login.example.com/.well-known/openid-configuration', + 'ClientID' => 'test', + 'RedirectURI' => 'https://login.example.com/redirect_uri', + 'ProviderTokenEndpointAuth' => 'client_secret_basic', + 'RemoteUserClaim' => 'sub', + 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', + 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, + 'mdomain' => 'example.com example.net auto', + 'userdir' => 'disabled' } end it { is_expected.to compile } it { is_expected.not_to contain_file('/var/www/foo') } it { is_expected.to contain_class('apache::mod::ssl') } + it { - is_expected.to contain_file('ssl.conf').with( + expect(subject).to contain_file('ssl.conf').with( content: %r{^\s+SSLHonorCipherOrder On$}, ) } + it { - is_expected.to contain_file('ssl.conf').with( + expect(subject).to contain_file('ssl.conf').with( content: %r{^\s+SSLPassPhraseDialog builtin$}, ) } + it { - is_expected.to contain_file('ssl.conf').with( + expect(subject).to contain_file('ssl.conf').with( content: %r{^\s+SSLSessionCacheTimeout 300$}, ) } + it { is_expected.to contain_file('rspec.example.com_ssl_cert') } it { is_expected.to contain_file('rspec.example.com_ssl_key') } it { is_expected.to contain_file('rspec.example.com_ssl_chain') } it { is_expected.to contain_file('rspec.example.com_ssl_foo.crl') } + it { - is_expected.to contain_file('/var/www/logs').with('ensure' => 'directory', - 'mode' => '0600') + expect(subject).to contain_file('/var/www/logs').with('ensure' => 'directory', + 'mode' => '0600') } + it { is_expected.to contain_class('apache::mod::alias') } it { is_expected.to contain_class('apache::mod::auth_basic') } it { is_expected.to contain_class('apache::mod::authn_file') } @@ -573,38 +580,44 @@ it { is_expected.to contain_class('apache::mod::suexec') } it { is_expected.to contain_class('apache::mod::vhost_alias') } it { is_expected.to contain_class('apache::mod::wsgi') } + it { - is_expected.to contain_concat('30-rspec.example.com.conf').with('owner' => 'root', - 'mode' => '0644', - 'require' => 'Package[httpd]', - 'notify' => 'Class[Apache::Service]') + expect(subject).to contain_concat('30-rspec.example.com.conf').with('owner' => 'root', + 'mode' => '0644', + 'require' => 'Package[httpd]', + 'notify' => 'Class[Apache::Service]') } + if os_facts[:os]['release']['major'].to_i >= 18 && os_facts[:os]['name'] == 'Ubuntu' it { - is_expected.to contain_file('30-rspec.example.com.conf symlink').with('ensure' => 'link', - 'path' => "/etc/#{apache_name}/sites-enabled/30-rspec.example.com.conf") + expect(subject).to contain_file('30-rspec.example.com.conf symlink').with('ensure' => 'link', + 'path' => "/etc/#{apache_name}/sites-enabled/30-rspec.example.com.conf") } end it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header') + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header') .with_content(%r{^\s+LimitRequestFieldSize 8190$}) .with_content(%r{^\s+LimitRequestFields 100$}) .with_content(%r{^\s+LimitRequestLine 8190$}) .with_content(%r{^\s+LimitRequestBody 0$}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-docroot') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-aliases').with( + expect(subject).to contain_concat__fragment('rspec.example.com-aliases').with( content: %r{^\s+Alias /image "/rspec/image"$}, ) } + it { is_expected.to contain_concat__fragment('rspec.example.com-itk') } it { is_expected.to contain_concat__fragment('rspec.example.com-fallbackresource') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-directories') + expect(subject).to contain_concat__fragment('rspec.example.com-directories') .with_content(%r{^\s+$}) - .with_content(%r{^\s+Include\s'\/custom\/path\/includes'$}) - .with_content(%r{^\s+Include\s'\/custom\/path\/another_includes'$}) + .with_content(%r{^\s+Include\s'/custom/path/includes'$}) + .with_content(%r{^\s+Include\s'/custom/path/another_includes'$}) .with_content(%r{^\s+H2CopyFiles\sOn$}) .with_content(%r{^\s+H2PushResource\s/foo.css$}) .with_content(%r{^\s+H2PushResource\s/foo.js$}) @@ -612,15 +625,15 @@ .with_content(%r{^\s+Require all denied$}) .with_content(%r{^\s+Require all granted$}) .with_content(%r{^\s+$}) - .with_content(%r{^\s+<\/RequireAll>$}) + .with_content(%r{^\s+$}) .with_content(%r{^\s+Require all-valid1$}) .with_content(%r{^\s+Require all-valid2$}) .with_content(%r{^\s+$}) - .with_content(%r{^\s+<\/RequireNone>$}) + .with_content(%r{^\s+$}) .with_content(%r{^\s+Require none-valid1$}) .with_content(%r{^\s+Require none-valid2$}) .with_content(%r{^\s+$}) - .with_content(%r{^\s+<\/RequireAny>$}) + .with_content(%r{^\s+$}) .with_content(%r{^\s+Require any-valid1$}) .with_content(%r{^\s+Require any-valid2$}) .with_content(%r{^\s+LDAPReferrals off$}) @@ -628,14 +641,14 @@ .with_content(%r{^\s+ProxyPassMatch http://backend-b/ retry=0 timeout=5 noquery interpolate$}) .with_content(%r{^\s+Options\sIndexes\sFollowSymLinks\sMultiViews$}) .with_content(%r{^\s+IndexOptions\sFancyIndexing$}) - .with_content(%r{^\s+IndexStyleSheet\s'\/styles\/style\.css'$}) + .with_content(%r{^\s+IndexStyleSheet\s'/styles/style\.css'$}) .with_content(%r{^\s+DirectoryIndex\sdisabled$}) .with_content(%r{^\s+SetOutputFilter\soutput_filter$}) .with_content(%r{^\s+SetInputFilter\sinput_filter$}) .with_content(%r{^\s+$}) - .with_content(%r{\s+\s*Require valid-user\s*<\/Limit>}m) + .with_content(%r{\s+\s*Require valid-user\s*}m) .with_content(%r{^\s+$}) - .with_content(%r{\s+\s*Require valid-user\s*<\/LimitExcept>}m) + .with_content(%r{\s+\s*Require valid-user\s*}m) .with_content(%r{^\s+Dav\sfilesystem$}) .with_content(%r{^\s+DavDepthInfinity\sOn$}) .with_content(%r{^\s+DavMinTimeout\s600$}) @@ -709,18 +722,22 @@ .with_content(%r{^\s+SSLVerifyClient\soptional$}) .with_content(%r{^\s+SSLVerifyDepth\s10$}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-additional_includes') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-logging') + expect(subject).to contain_concat__fragment('rspec.example.com-logging') .with_content(%r{^\s+ErrorLogFormat "\[%t\] \[%l\] %7F: %E: \[client\\ %a\] %M% ,\\ referer\\ %\{Referer\}i"$}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-serversignature') } it { is_expected.not_to contain_concat__fragment('rspec.example.com-access_log') } it { is_expected.to contain_concat__fragment('rspec.example.com-action') } it { is_expected.to contain_concat__fragment('rspec.example.com-block') } it { is_expected.to contain_concat__fragment('rspec.example.com-error_document') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-proxy') + expect(subject).to contain_concat__fragment('rspec.example.com-proxy') .with_content(%r{retry=0}) .with_content(%r{timeout=5}) .with_content(%r{SetEnv force-proxy-request-1.0 1}) @@ -728,33 +745,39 @@ .with_content(%r{noquery interpolate}) .with_content(%r{ProxyPreserveHost On}) .with_content(%r{ProxyAddHeaders On}) - .with_content(%r{ProxyPassReverseCookiePath\s+\/a\s+http:\/\/}) - .with_content(%r{ProxyPassReverseCookieDomain\s+foo\s+http:\/\/foo}) + .with_content(%r{ProxyPassReverseCookiePath\s+/a\s+http://}) + .with_content(%r{ProxyPassReverseCookieDomain\s+foo\s+http://foo}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-rewrite') + expect(subject).to contain_concat__fragment('rspec.example.com-rewrite') .with_content(%r{^\s+RewriteEngine On$}) .with_content(%r{^\s+RewriteOptions Inherit$}) .with_content(%r{^\s+RewriteBase /}) .with_content(%r{^\s+RewriteRule \^index\.html\$ rewrites.html$}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-scriptalias') } it { is_expected.to contain_concat__fragment('rspec.example.com-serveralias') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-setenv') + expect(subject).to contain_concat__fragment('rspec.example.com-setenv') .with_content(%r{SetEnv FOO=/bin/true}) .with_content(%r{SetEnvIf Request_URI "\\.gif\$" object_is_image=gif}) .with_content(%r{SetEnvIfNoCase REMOTE_ADDR \^127.0.0.1 localhost=true}) } + it { - is_expected.to contain_concat__fragment('rspec.example.com-ssl') + expect(subject).to contain_concat__fragment('rspec.example.com-ssl') .with_content(%r{^\s+SSLOpenSSLConfCmd\s+DHParameters "foo.pem"$}) .with_content(%r{^\s+SSLHonorCipherOrder\s+Off$}) .with_content(%r{^\s+SSLUserName\s+SSL_CLIENT_S_DN_CN$}) } + it { - is_expected.to contain_concat__fragment('rspec.example.com-sslproxy') + expect(subject).to contain_concat__fragment('rspec.example.com-sslproxy') .with_content(%r{^\s+SSLProxyEngine On$}) .with_content(%r{^\s+SSLProxyCheckPeerCN\s+on$}) .with_content(%r{^\s+SSLProxyCheckPeerName\s+on$}) @@ -762,13 +785,16 @@ .with_content(%r{^\s+SSLProxyCipherSuite\s+HIGH$}) .with_content(%r{^\s+SSLProxyProtocol\s+TLSv1.2$}) } + it { is_expected.to contain_concat__fragment('rspec.example.com-php_admin') } it { is_expected.to contain_concat__fragment('rspec.example.com-header') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-filters').with( + expect(subject).to contain_concat__fragment('rspec.example.com-filters').with( content: %r{^\s+FilterDeclare COMPRESS$}, ) } + it { is_expected.to contain_concat__fragment('rspec.example.com-requestheader') } it { is_expected.to contain_concat__fragment('rspec.example.com-wsgi') } it { is_expected.to contain_concat__fragment('rspec.example.com-custom_fragment') } @@ -779,22 +805,22 @@ it { is_expected.not_to contain_concat__fragment('rspec.example.com-security') } it { - is_expected.to contain_concat__fragment('rspec.example.com-file_footer') + expect(subject).to contain_concat__fragment('rspec.example.com-file_footer') .with_content(%r{^PassengerPreStart\shttp://localhost/myapp$}) } it { - is_expected.to contain_concat__fragment('rspec.example.com-jk_mounts') - .with_content(%r{^\s+JkMount\s+\/\*\s+tcnode1$}) - .with_content(%r{^\s+JkUnMount\s+\/\*\.jpg\s+tcnode1$}) + expect(subject).to contain_concat__fragment('rspec.example.com-jk_mounts') + .with_content(%r{^\s+JkMount\s+/\*\s+tcnode1$}) + .with_content(%r{^\s+JkUnMount\s+/\*\.jpg\s+tcnode1$}) } it { - is_expected.to contain_concat__fragment('rspec.example.com-auth_kerb') + expect(subject).to contain_concat__fragment('rspec.example.com-auth_kerb') .with_content(%r{^\s+KrbMethodNegotiate\soff$}) .with_content(%r{^\s+KrbAuthoritative\soff$}) .with_content(%r{^\s+KrbAuthRealms\sEXAMPLE.ORG\sEXAMPLE.NET$}) - .with_content(%r{^\s+Krb5Keytab\s\/tmp\/keytab5$}) + .with_content(%r{^\s+Krb5Keytab\s/tmp/keytab5$}) .with_content(%r{^\s+KrbLocalUserMapping\soff$}) .with_content(%r{^\s+KrbServiceName\sHTTP$}) .with_content(%r{^\s+KrbSaveCredentials\soff$}) @@ -802,26 +828,26 @@ } it { - is_expected.to contain_concat__fragment('rspec.example.com-http_protocol_options').with( + expect(subject).to contain_concat__fragment('rspec.example.com-http_protocol_options').with( content: %r{^\s*HttpProtocolOptions\s+Strict\s+LenientMethods\s+Allow0\.9$}, ) } it { - is_expected.to contain_concat__fragment('rspec.example.com-keepalive_options') + expect(subject).to contain_concat__fragment('rspec.example.com-keepalive_options') .with_content(%r{^\s+KeepAlive\son$}) .with_content(%r{^\s+KeepAliveTimeout\s100$}) .with_content(%r{^\s+MaxKeepAliveRequests\s1000$}) } it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header') + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header') .with_content(%r{^\s+Protocols\sh2 http/1.1$}) .with_content(%r{^\s+ProtocolsHonorOrder\sOn$}) } it { - is_expected.to contain_concat__fragment('rspec.example.com-http2') + expect(subject).to contain_concat__fragment('rspec.example.com-http2') .with_content(%r{^\s+H2CopyFiles\sOff$}) .with_content(%r{^\s+H2Direct\sOn$}) .with_content(%r{^\s+H2EarlyHints\sOff$}) @@ -841,7 +867,7 @@ } it { - is_expected.to contain_concat__fragment('rspec.example.com-passenger') + expect(subject).to contain_concat__fragment('rspec.example.com-passenger') .with_content(%r{^\s+PassengerEnabled\sOff$}) .with_content(%r{^\s+PassengerBaseURI\s/app$}) .with_content(%r{^\s+PassengerRuby\s/usr/bin/ruby1\.9\.1$}) @@ -887,10 +913,10 @@ } it { - is_expected.to contain_concat__fragment('rspec.example.com-auth_oidc') - .with_content(%r{^\s+OIDCProviderMetadataURL\shttps:\/\/login.example.com\/\.well-known\/openid-configuration$}) + expect(subject).to contain_concat__fragment('rspec.example.com-auth_oidc') + .with_content(%r{^\s+OIDCProviderMetadataURL\shttps://login.example.com/\.well-known/openid-configuration$}) .with_content(%r{^\s+OIDCClientID\stest$}) - .with_content(%r{^\s+OIDCRedirectURI\shttps:\/\/login\.example.com\/redirect_uri$}) + .with_content(%r{^\s+OIDCRedirectURI\shttps://login\.example.com/redirect_uri$}) .with_content(%r{^\s+OIDCProviderTokenEndpointAuth\sclient_secret_basic$}) .with_content(%r{^\s+OIDCRemoteUserClaim\ssub$}) .with_content(%r{^\s+OIDCClientSecret\saae053a9-4abf-4824-8956-e94b2af335c8$}) @@ -898,234 +924,254 @@ } it { is_expected.to contain_class('apache::mod::md') } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( content: %r{^MDomain example\.com example\.net auto$}, ) } end + context 'vhost with proxy_add_headers true' do let :params do { - 'docroot' => '/var/www/foo', - 'manage_docroot' => false, - 'virtual_docroot' => true, + 'docroot' => '/var/www/foo', + 'manage_docroot' => false, + 'virtual_docroot' => true, 'virtual_use_default_docroot' => false, - 'port' => 8080, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'add_listen' => false, - 'serveradmin' => 'foo@localhost', - 'priority' => 30, - 'default_vhost' => true, - 'servername' => 'example.com', - 'serveraliases' => ['test-example.com'], - 'options' => ['MultiView'], - 'override' => ['All'], - 'directoryindex' => 'index.html', - 'vhost_name' => 'test', - 'proxy_add_headers' => true, + 'port' => 8080, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'add_listen' => false, + 'serveradmin' => 'foo@localhost', + 'priority' => 30, + 'default_vhost' => true, + 'servername' => 'example.com', + 'serveraliases' => ['test-example.com'], + 'options' => ['MultiView'], + 'override' => ['All'], + 'directoryindex' => 'index.html', + 'vhost_name' => 'test', + 'proxy_add_headers' => true } end it { is_expected.to compile } it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders On}) } end + context 'vhost with proxy_add_headers false' do let :params do { - 'docroot' => '/var/www/foo', - 'manage_docroot' => false, - 'virtual_docroot' => true, + 'docroot' => '/var/www/foo', + 'manage_docroot' => false, + 'virtual_docroot' => true, 'virtual_use_default_docroot' => false, - 'port' => 8080, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'add_listen' => false, - 'serveradmin' => 'foo@localhost', - 'priority' => 30, - 'default_vhost' => true, - 'servername' => 'example.com', - 'serveraliases' => ['test-example.com'], - 'options' => ['MultiView'], - 'override' => ['All'], - 'directoryindex' => 'index.html', - 'vhost_name' => 'test', - 'proxy_add_headers' => false, + 'port' => 8080, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'add_listen' => false, + 'serveradmin' => 'foo@localhost', + 'priority' => 30, + 'default_vhost' => true, + 'servername' => 'example.com', + 'serveraliases' => ['test-example.com'], + 'options' => ['MultiView'], + 'override' => ['All'], + 'directoryindex' => 'index.html', + 'vhost_name' => 'test', + 'proxy_add_headers' => false } end it { is_expected.to compile } it { is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders Off}) } end + context 'vhost without proxy' do let :params do { - 'docroot' => '/var/www/foo', - 'manage_docroot' => false, - 'virtual_docroot' => true, + 'docroot' => '/var/www/foo', + 'manage_docroot' => false, + 'virtual_docroot' => true, 'virtual_use_default_docroot' => false, - 'port' => 8080, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'add_listen' => false, - 'serveradmin' => 'foo@localhost', - 'priority' => 30, - 'default_vhost' => true, - 'servername' => 'example.com', - 'serveraliases' => ['test-example.com'], - 'options' => ['MultiView'], - 'override' => ['All'], - 'directoryindex' => 'index.html', - 'vhost_name' => 'test', + 'port' => 8080, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'add_listen' => false, + 'serveradmin' => 'foo@localhost', + 'priority' => 30, + 'default_vhost' => true, + 'servername' => 'example.com', + 'serveraliases' => ['test-example.com'], + 'options' => ['MultiView'], + 'override' => ['All'], + 'directoryindex' => 'index.html', + 'vhost_name' => 'test' } end it { is_expected.to compile } it { is_expected.not_to contain_concat__fragment('rspec.example.com-proxy') } end + context 'vhost without proxy_add_headers' do let :params do { - 'docroot' => '/var/www/foo', - 'manage_docroot' => false, - 'virtual_docroot' => true, + 'docroot' => '/var/www/foo', + 'manage_docroot' => false, + 'virtual_docroot' => true, 'virtual_use_default_docroot' => false, - 'port' => 8080, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'add_listen' => false, - 'serveradmin' => 'foo@localhost', - 'priority' => 30, - 'default_vhost' => true, - 'servername' => 'example.com', - 'serveraliases' => ['test-example.com'], - 'options' => ['MultiView'], - 'override' => ['All'], - 'directoryindex' => 'index.html', - 'vhost_name' => 'test', - 'proxy_preserve_host' => true, + 'port' => 8080, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'add_listen' => false, + 'serveradmin' => 'foo@localhost', + 'priority' => 30, + 'default_vhost' => true, + 'servername' => 'example.com', + 'serveraliases' => ['test-example.com'], + 'options' => ['MultiView'], + 'override' => ['All'], + 'directoryindex' => 'index.html', + 'vhost_name' => 'test', + 'proxy_preserve_host' => true } end it { is_expected.to compile } it { is_expected.not_to contain_concat__fragment('rspec.example.com-proxy').with_content(%r{ProxyAddHeaders}) } end + context 'vhost with scheme and port in servername and use_servername_for_filenames' do let :params do { - 'port' => 80, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'servername' => 'https://www.example.com:443', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', - 'use_servername_for_filenames' => true + 'port' => 80, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'servername' => 'https://www.example.com:443', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present', + 'use_servername_for_filenames' => true } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{^\s+ServerName https:\/\/www\.example\.com:443$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{^\s+ServerName https://www\.example\.com:443$}, ) } + it { - is_expected.to contain_concat('25-www.example.com.conf') + expect(subject).to contain_concat('25-www.example.com.conf') } end + context 'vhost with scheme in servername and use_servername_for_filenames' do let :params do { - 'port' => 80, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'servername' => 'https://www.example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', - 'use_servername_for_filenames' => true + 'port' => 80, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'servername' => 'https://www.example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present', + 'use_servername_for_filenames' => true } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{^\s+ServerName https:\/\/www\.example\.com$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{^\s+ServerName https://www\.example\.com$}, ) } + it { - is_expected.to contain_concat('25-www.example.com.conf') + expect(subject).to contain_concat('25-www.example.com.conf') } end + context 'vhost with port in servername and use_servername_for_filenames' do let :params do { - 'port' => 80, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'servername' => 'www.example.com:443', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', - 'use_servername_for_filenames' => true + 'port' => 80, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'servername' => 'www.example.com:443', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present', + 'use_servername_for_filenames' => true } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( content: %r{^\s+ServerName www\.example\.com:443$}, ) } + it { - is_expected.to contain_concat('25-www.example.com.conf') + expect(subject).to contain_concat('25-www.example.com.conf') } end + context 'vhost with servername and use_servername_for_filenames' do let :params do { - 'port' => 80, - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'servername' => 'www.example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', - 'use_servername_for_filenames' => true + 'port' => 80, + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'servername' => 'www.example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present', + 'use_servername_for_filenames' => true } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( content: %r{^\s+ServerName www\.example\.com$}, ) } + it { - is_expected.to contain_concat('25-www.example.com.conf') + expect(subject).to contain_concat('25-www.example.com.conf') } end + context 'vhost with multiple ip addresses' do let :params do { - 'port' => 80, - 'ip' => ['127.0.0.1', '::1'], - 'ip_based' => true, - 'servername' => 'example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', + 'port' => 80, + 'ip' => ['127.0.0.1', '::1'], + 'ip_based' => true, + 'servername' => 'example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{[.\/m]*[.\/m]*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{[./m]*[./m]*$}, ) } + it { is_expected.to contain_concat__fragment('Listen 127.0.0.1:80') } it { is_expected.to contain_concat__fragment('Listen [::1]:80') } it { is_expected.not_to contain_concat__fragment('NameVirtualHost 127.0.0.1:80') } @@ -1135,22 +1181,24 @@ context 'vhost with multiple ports' do let :params do { - 'port' => [80, 8080], - 'ip' => '127.0.0.1', - 'ip_based' => true, - 'servername' => 'example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', + 'port' => [80, 8080], + 'ip' => '127.0.0.1', + 'ip_based' => true, + 'servername' => 'example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{[.\/m]*[.\/m]*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{[./m]*[./m]*$}, ) } + it { is_expected.to contain_concat__fragment('Listen 127.0.0.1:80') } it { is_expected.to contain_concat__fragment('Listen 127.0.0.1:8080') } it { is_expected.not_to contain_concat__fragment('NameVirtualHost 127.0.0.1:80') } @@ -1160,22 +1208,24 @@ context 'vhost with multiple ip addresses, multiple ports' do let :params do { - 'port' => [80, 8080], - 'ip' => ['127.0.0.1', '::1'], - 'ip_based' => true, - 'servername' => 'example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', + 'port' => [80, 8080], + 'ip' => ['127.0.0.1', '::1'], + 'ip_based' => true, + 'servername' => 'example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{[.\/m]*[.\/m]*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{[./m]*[./m]*$}, ) } + it { is_expected.to contain_concat__fragment('Listen 127.0.0.1:80') } it { is_expected.to contain_concat__fragment('Listen 127.0.0.1:8080') } it { is_expected.to contain_concat__fragment('Listen [::1]:80') } @@ -1189,22 +1239,24 @@ context 'vhost with ipv6 address' do let :params do { - 'port' => 80, - 'ip' => '::1', - 'ip_based' => true, - 'servername' => 'example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', + 'port' => 80, + 'ip' => '::1', + 'ip_based' => true, + 'servername' => 'example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{[.\/m]*[.\/m]*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{[./m]*[./m]*$}, ) } + it { is_expected.to contain_concat__fragment('Listen [::1]:80') } it { is_expected.not_to contain_concat__fragment('NameVirtualHost [::1]:80') } end @@ -1212,22 +1264,24 @@ context 'vhost with wildcard ip address' do let :params do { - 'port' => 80, - 'ip' => '*', - 'ip_based' => true, - 'servername' => 'example.com', - 'docroot' => '/var/www/html', - 'add_listen' => true, - 'ensure' => 'present', + 'port' => 80, + 'ip' => '*', + 'ip_based' => true, + 'servername' => 'example.com', + 'docroot' => '/var/www/html', + 'add_listen' => true, + 'ensure' => 'present' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( - content: %r{[.\/m]*[.\/m]*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( + content: %r{[./m]*[./m]*$}, ) } + it { is_expected.to contain_concat__fragment('Listen *:80') } it { is_expected.not_to contain_concat__fragment('NameVirtualHost *:80') } end @@ -1235,40 +1289,45 @@ context 'vhost with backwards compatible virtual_docroot' do let :params do { - 'docroot' => '/var/www/html', - 'virtual_docroot' => '/var/www/sites/%0', + 'docroot' => '/var/www/html', + 'virtual_docroot' => '/var/www/sites/%0' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-docroot').with( + expect(subject).to contain_concat__fragment('rspec.example.com-docroot').with( content: %r{^\s+VirtualDocumentRoot "/var/www/sites/%0"$}, ) } + it { - is_expected.not_to contain_concat__fragment('rspec.example.com-docroot').with( + expect(subject).not_to contain_concat__fragment('rspec.example.com-docroot').with( content: %r{^\s+DocumentRoot "/var/www/html"$}, ) } end + context 'vhost with virtual_docroot and docroot' do let :params do { - 'docroot' => '/var/www/html', + 'docroot' => '/var/www/html', 'virtual_use_default_docroot' => true, - 'virtual_docroot' => '/var/www/sites/%0', + 'virtual_docroot' => '/var/www/sites/%0' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-docroot').with( + expect(subject).to contain_concat__fragment('rspec.example.com-docroot').with( content: %r{^\s+VirtualDocumentRoot "/var/www/sites/%0"$}, ) } + it { - is_expected.to contain_concat__fragment('rspec.example.com-docroot').with( + expect(subject).to contain_concat__fragment('rspec.example.com-docroot').with( content: %r{^\s+DocumentRoot "/var/www/html"$}, ) } @@ -1277,30 +1336,33 @@ context 'modsec_audit_log' do let :params do { - 'docroot' => '/rspec/docroot', - 'modsec_audit_log' => true, + 'docroot' => '/rspec/docroot', + 'modsec_audit_log' => true } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-security').with( - content: %r{^\s*SecAuditLog "\/var\/log\/#{apache_name}\/rspec\.example\.com_security\.log"$}, + expect(subject).to contain_concat__fragment('rspec.example.com-security').with( + content: %r{^\s*SecAuditLog "/var/log/#{apache_name}/rspec\.example\.com_security\.log"$}, ) } end + context 'modsec_audit_log_file' do let :params do { - 'docroot' => '/rspec/docroot', - 'modsec_audit_log_file' => 'foo.log', + 'docroot' => '/rspec/docroot', + 'modsec_audit_log_file' => 'foo.log' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-security').with( - content: %r{\s*SecAuditLog "\/var\/log\/#{apache_name}\/foo.log"$}, + expect(subject).to contain_concat__fragment('rspec.example.com-security').with( + content: %r{\s*SecAuditLog "/var/log/#{apache_name}/foo.log"$}, ) } end @@ -1308,18 +1370,19 @@ context 'modsec_anomaly_threshold' do let :params do { - 'docroot' => '/rspec/docroot', - 'modsec_inbound_anomaly_threshold' => 10_000, - 'modsec_outbound_anomaly_threshold' => 10_000, + 'docroot' => '/rspec/docroot', + 'modsec_inbound_anomaly_threshold' => 10_000, + 'modsec_outbound_anomaly_threshold' => 10_000 } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-security').with( + expect(subject).to contain_concat__fragment('rspec.example.com-security').with( content: %r{ ^\s+SecAction\ \\\n - \s+\"id:900110,\\\n + \s+"id:900110,\\\n \s+phase:1,\\\n \s+nolog,\\\n \s+pass,\\\n @@ -1334,17 +1397,18 @@ context 'modsec_allowed_methods' do let :params do { - 'docroot' => '/rspec/docroot', - 'modsec_allowed_methods' => 'GET HEAD POST OPTIONS', + 'docroot' => '/rspec/docroot', + 'modsec_allowed_methods' => 'GET HEAD POST OPTIONS' } end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-security').with( + expect(subject).to contain_concat__fragment('rspec.example.com-security').with( content: %r{ ^\s+SecAction\ \\\n - \s+\"id:900200,\\\n + \s+"id:900200,\\\n \s+phase:1,\\\n \s+nolog,\\\n\s+pass,\\\n \s+t:none,\\\n @@ -1361,31 +1425,32 @@ 'aliases' => [ { 'alias' => '/alias', - 'path' => '/rspec/docroot', + 'path' => '/rspec/docroot' }, - ], + ] } end it { is_expected.to contain_class('apache::mod::alias') } end + context 'proxy_pass_match' do let :params do { 'docroot' => '/rspec/docroot', 'proxy_pass_match' => [ { - 'path' => '.*', - 'url' => 'http://backend-a/', - 'params' => { 'timeout' => 300 }, + 'path' => '.*', + 'url' => 'http://backend-a/', + 'params' => { 'timeout' => 300 } }, - ], + ] } end it { - is_expected.to contain_concat__fragment('rspec.example.com-proxy').with_content( - %r{ProxyPassMatch .* http:\/\/backend-a\/ timeout=300}, + expect(subject).to contain_concat__fragment('rspec.example.com-proxy').with_content( + %r{ProxyPassMatch .* http://backend-a/ timeout=300}, ).with_content(%r{## Proxy rules}) } end @@ -1393,8 +1458,8 @@ context 'proxy_dest_match and no proxy_dest_reverse_match' do let :params do { - 'docroot' => '/rspec/docroot', - 'proxy_dest_match' => '/', + 'docroot' => '/rspec/docroot', + 'proxy_dest_match' => '/' } end @@ -1406,9 +1471,9 @@ context 'proxy_dest_match and proxy_dest_reverse_match' do let :params do { - 'docroot' => '/rspec/docroot', - 'proxy_dest_match' => '/', - 'proxy_dest_reverse_match' => 'http://localhost:8180', + 'docroot' => '/rspec/docroot', + 'proxy_dest_match' => '/', + 'proxy_dest_reverse_match' => 'http://localhost:8180' } end @@ -1421,12 +1486,12 @@ let :params do { 'access_log_pipe' => '/dev/null', - 'error_log_pipe' => '/dev/null', - 'docroot' => '/var/www/foo', - 'ensure' => 'absent', - 'manage_docroot' => true, - 'logroot' => '/tmp/logroot', - 'logroot_ensure' => 'absent', + 'error_log_pipe' => '/dev/null', + 'docroot' => '/var/www/foo', + 'ensure' => 'absent', + 'manage_docroot' => true, + 'logroot' => '/tmp/logroot', + 'logroot_ensure' => 'absent' } end @@ -1447,12 +1512,15 @@ it { is_expected.not_to contain_file('rspec.example.com_ssl_chain') } it { is_expected.not_to contain_file('rspec.example.com_ssl_foo.crl') } it { is_expected.to contain_file('/var/www/foo') } + it { - is_expected.to contain_file('/tmp/logroot').with('ensure' => 'absent') + expect(subject).to contain_file('/tmp/logroot').with('ensure' => 'absent') } + it { - is_expected.to contain_concat('25-rspec.example.com.conf').with('ensure' => 'absent') + expect(subject).to contain_concat('25-rspec.example.com.conf').with('ensure' => 'absent') } + it { is_expected.to contain_concat__fragment('rspec.example.com-apache-header') } it { is_expected.not_to contain_concat__fragment('rspec.example.com-docroot') } it { is_expected.not_to contain_concat__fragment('rspec.example.com-aliases') } @@ -1484,122 +1552,133 @@ it { is_expected.not_to contain_concat__fragment('rspec.example.com-limits') } it { is_expected.to contain_concat__fragment('rspec.example.com-file_footer') } end + context 'wsgi_application_group should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_application_group' => '%{GLOBAL}', + 'docroot' => '/rspec/docroot', + 'wsgi_application_group' => '%{GLOBAL}' } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'wsgi_daemon_process should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} }, + 'docroot' => '/rspec/docroot', + 'wsgi_daemon_process' => { 'foo' => { 'python-home' => '/usr' }, 'bar' => {} } } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'wsgi_import_script on its own should not set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_import_script' => '/var/www/demo.wsgi', + 'docroot' => '/rspec/docroot', + 'wsgi_import_script' => '/var/www/demo.wsgi' } end it { is_expected.not_to contain_class('apache::mod::wsgi') } end + context 'wsgi_import_script_options on its own should not set apache::mod::wsgi' do let :params do { 'docroot' => '/rspec/docroot', 'wsgi_import_script_options' => { - 'process-group' => 'wsgi', - 'application-group' => '%{GLOBAL}', - }, + 'process-group' => 'wsgi', + 'application-group' => '%{GLOBAL}' + } } end it { is_expected.not_to contain_class('apache::mod::wsgi') } end + context 'wsgi_import_script and wsgi_import_script_options should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_import_script' => '/var/www/demo.wsgi', - 'wsgi_import_script_options' => { - 'process-group' => 'wsgi', - 'application-group' => '%{GLOBAL}', - }, + 'docroot' => '/rspec/docroot', + 'wsgi_import_script' => '/var/www/demo.wsgi', + 'wsgi_import_script_options' => { + 'process-group' => 'wsgi', + 'application-group' => '%{GLOBAL}' + } } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'wsgi_process_group should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_daemon_process' => 'wsgi', + 'docroot' => '/rspec/docroot', + 'wsgi_daemon_process' => 'wsgi' } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'wsgi_script_aliases with non-empty aliases should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_script_aliases' => { - '/' => '/var/www/demo.wsgi', - }, + 'docroot' => '/rspec/docroot', + 'wsgi_script_aliases' => { + '/' => '/var/www/demo.wsgi' + } } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'wsgi_script_aliases with empty aliases should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_script_aliases' => {}, + 'docroot' => '/rspec/docroot', + 'wsgi_script_aliases' => {} } end it { is_expected.not_to contain_class('apache::mod::wsgi') } end + context 'wsgi_pass_authorization should set apache::mod::wsgi' do let :params do { - 'docroot' => '/rspec/docroot', - 'wsgi_pass_authorization' => 'On', + 'docroot' => '/rspec/docroot', + 'wsgi_pass_authorization' => 'On' } end it { is_expected.to contain_class('apache::mod::wsgi') } end + context 'when not setting nor managing the docroot' do let :params do { - 'docroot' => false, - 'manage_docroot' => false, + 'docroot' => false, + 'manage_docroot' => false } end it { is_expected.to compile } it { is_expected.not_to contain_concat__fragment('rspec.example.com-docroot') } end + context 'ssl_proxyengine without ssl' do let :params do { - 'docroot' => '/rspec/docroot', - 'ssl' => false, - 'ssl_proxyengine' => true, + 'docroot' => '/rspec/docroot', + 'ssl' => false, + 'ssl_proxyengine' => true } end @@ -1607,13 +1686,14 @@ it { is_expected.not_to contain_concat__fragment('rspec.example.com-ssl') } it { is_expected.to contain_concat__fragment('rspec.example.com-sslproxy') } end + context 'ssl_proxy_protocol without ssl_proxyengine' do let :params do { - 'docroot' => '/rspec/docroot', - 'ssl' => true, - 'ssl_proxyengine' => false, - 'ssl_proxy_protocol' => 'TLSv1.2', + 'docroot' => '/rspec/docroot', + 'ssl' => true, + 'ssl_proxyengine' => false, + 'ssl_proxy_protocol' => 'TLSv1.2' } end @@ -1621,11 +1701,12 @@ it { is_expected.to contain_concat__fragment('rspec.example.com-ssl') } it { is_expected.not_to contain_concat__fragment('rspec.example.com-sslproxy') } end + context 'ssl_honorcipherorder' do let :params do { - 'docroot' => '/rspec/docroot', - 'ssl' => true, + 'docroot' => '/rspec/docroot', + 'ssl' => true } end @@ -1642,6 +1723,7 @@ it { is_expected.to compile } it { is_expected.to contain_concat__fragment('rspec.example.com-ssl').with_content(%r{^\s*SSLHonorCipherOrder\s+On$}) } end + context 'ssl_honorcipherorder true' do let :params do super().merge({ 'ssl_honorcipherorder' => true }) @@ -1650,6 +1732,7 @@ it { is_expected.to compile } it { is_expected.to contain_concat__fragment('rspec.example.com-ssl').with_content(%r{^\s*SSLHonorCipherOrder\s+On$}) } end + context 'ssl_honorcipherorder off' do let :params do super().merge({ 'ssl_honorcipherorder' => 'off' }) @@ -1658,6 +1741,7 @@ it { is_expected.to compile } it { is_expected.to contain_concat__fragment('rspec.example.com-ssl').with_content(%r{^\s*SSLHonorCipherOrder\s+Off$}) } end + context 'ssl_honorcipherorder false' do let :params do super().merge({ 'ssl_honorcipherorder' => false }) @@ -1667,76 +1751,82 @@ it { is_expected.to contain_concat__fragment('rspec.example.com-ssl').with_content(%r{^\s*SSLHonorCipherOrder\s+Off$}) } end end + describe 'access logs' do context 'single log file' do let(:params) do { - 'docroot' => '/rspec/docroot', - 'access_log_file' => 'my_log_file', + 'docroot' => '/rspec/docroot', + 'access_log_file' => 'my_log_file' } end it { - is_expected.to contain_concat__fragment('rspec.example.com-access_log').with( + expect(subject).to contain_concat__fragment('rspec.example.com-access_log').with( content: %r{^\s+CustomLog.*my_log_file" combined\s*$}, ) } end + context 'single log file with environment' do let(:params) do { - 'docroot' => '/rspec/docroot', - 'access_log_file' => 'my_log_file', - 'access_log_env_var' => 'prod', + 'docroot' => '/rspec/docroot', + 'access_log_file' => 'my_log_file', + 'access_log_env_var' => 'prod' } end it { - is_expected.to contain_concat__fragment('rspec.example.com-access_log').with( + expect(subject).to contain_concat__fragment('rspec.example.com-access_log').with( content: %r{^\s+CustomLog.*my_log_file" combined\s+env=prod$}, ) } end + context 'multiple log files' do let(:params) do { - 'docroot' => '/rspec/docroot', + 'docroot' => '/rspec/docroot', 'access_logs' => [ { 'file' => '/tmp/log1', 'env' => 'dev' }, { 'file' => 'log2' }, { 'syslog' => 'syslog', 'format' => '%h %l' }, - ], + ] } end it { - is_expected.to contain_concat__fragment('rspec.example.com-access_log').with( - content: %r{^\s+CustomLog "\/tmp\/log1"\s+combined\s+env=dev$}, + expect(subject).to contain_concat__fragment('rspec.example.com-access_log').with( + content: %r{^\s+CustomLog "/tmp/log1"\s+combined\s+env=dev$}, ) } + it { - is_expected.to contain_concat__fragment('rspec.example.com-access_log').with( - content: %r{^\s+CustomLog "\/var\/log\/#{apache_name}\/log2"\s+combined\s*$}, + expect(subject).to contain_concat__fragment('rspec.example.com-access_log').with( + content: %r{^\s+CustomLog "/var/log/#{apache_name}/log2"\s+combined\s*$}, ) } + it { - is_expected.to contain_concat__fragment('rspec.example.com-access_log').with( + expect(subject).to contain_concat__fragment('rspec.example.com-access_log').with( content: %r{^\s+CustomLog "syslog" "%h %l"\s*$}, ) } end - end # access logs + end + describe 'error logs format' do context 'single log format directive as a string' do let(:params) do { - 'docroot' => '/rspec/docroot', - 'error_log_format' => ['[%t] [%l] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i'], + 'docroot' => '/rspec/docroot', + 'error_log_format' => ['[%t] [%l] %7F: %E: [client\ %a] %M% ,\ referer\ %{Referer}i'] } end it { - is_expected.to contain_concat__fragment('rspec.example.com-logging').with( + expect(subject).to contain_concat__fragment('rspec.example.com-logging').with( content: %r{^\s+ErrorLogFormat "\[%t\] \[%l\] %7F: %E: \[client\\ %a\] %M% ,\\ referer\\ %\{Referer\}i"$}, ) } @@ -1745,19 +1835,19 @@ context 'multiple log format directives' do let(:params) do { - 'docroot' => '/rspec/docroot', + 'docroot' => '/rspec/docroot', 'error_log_format' => [ '[%{uc}t] [%-m:%-l] [R:%L] [C:%{C}L] %7F: %E: %M', { '[%{uc}t] [R:%L] Request %k on C:%{c}L pid:%P tid:%T' => 'request' }, { "[%{uc}t] [R:%L] UA:'%+{User-Agent}i'" => 'request' }, { "[%{uc}t] [R:%L] Referer:'%+{Referer}i'" => 'request' }, { '[%{uc}t] [C:%{c}L] local\ %a remote\ %A' => 'connection' }, - ], + ] } end it { - is_expected.to contain_concat__fragment('rspec.example.com-logging') + expect(subject).to contain_concat__fragment('rspec.example.com-logging') .with_content(%r{^\s+ErrorLogFormat "\[%\{uc\}t\] \[%-m:%-l\] \[R:%L\] \[C:%\{C\}L\] %7F: %E: %M"$}) .with_content(%r{^\s+ErrorLogFormat request "\[%\{uc\}t\] \[R:%L\] Request %k on C:%\{c\}L pid:%P tid:%T"$}) .with_content(%r{^\s+ErrorLogFormat request "\[%\{uc\}t\] \[R:%L\] UA:'%\+\{User-Agent\}i'"$}) @@ -1765,11 +1855,12 @@ .with_content(%r{^\s+ErrorLogFormat connection "\[%\{uc\}t\] \[C:%\{c\}L\] local\\ %a remote\\ %A"$}) } end - end # error logs format + end + describe 'validation' do let(:params) do { - 'docroot' => '/rspec/docroot', + 'docroot' => '/rspec/docroot' } end @@ -1792,6 +1883,7 @@ it { is_expected.to raise_error(Puppet::Error) } end + context 'empty rewrites' do let(:params) do super().merge( @@ -1801,10 +1893,11 @@ end it { - is_expected.to compile - is_expected.not_to contain_concat__fragment('rspec.example.com-rewrite') + expect(subject).to compile + expect(subject).not_to contain_concat__fragment('rspec.example.com-rewrite') } end + context 'empty rewrites_with_rewrite_inherit' do let(:params) do super().merge( @@ -1814,12 +1907,13 @@ end it { - is_expected.not_to contain_concat__fragment('rspec.example.com-rewrite') + expect(subject).not_to contain_concat__fragment('rspec.example.com-rewrite') .with_content(%r{^\s+RewriteOptions Inherit$}) .with_content(%r{^\s+RewriteEngine On$}) .with_content(%r{^\s+RewriteRule \^index\.html\$ welcome.html$}) } end + context 'empty rewrites_without_rewrite_inherit' do let(:params) do super().merge( @@ -1829,7 +1923,7 @@ end it { - is_expected.not_to contain_concat__fragment('rspec.example.com-rewrite') + expect(subject).not_to contain_concat__fragment('rspec.example.com-rewrite') .with_content(%r{^\s+RewriteEngine On$}) .with_content(%r{^\s+RewriteRule \^index\.html\$ welcome.html$}) .without(content: %r{^\s+RewriteOptions Inherit$}) @@ -1847,6 +1941,7 @@ it { is_expected.to raise_error(Puppet::Error) } end + context 'access_log_file and access_log_pipe' do let :params do super().merge( @@ -1857,6 +1952,7 @@ it { is_expected.to raise_error(Puppet::Error) } end + context 'error_log_file and error_log_pipe' do let :params do super().merge( @@ -1867,36 +1963,40 @@ it { is_expected.to raise_error(Puppet::Error) } end + context 'bad custom_fragment' do let(:params) { super().merge('custom_fragment' => true) } it { is_expected.to raise_error(Puppet::Error) } end + context 'bad access_logs' do let(:params) { super().merge('access_logs' => '/var/log/somewhere') } it { is_expected.to raise_error(Puppet::Error) } end + context 'default of require all granted' do let :params do { - 'docroot' => '/var/www/foo', - 'directories' => [ + 'docroot' => '/var/www/foo', + 'directories' => [ { - 'path' => '/var/www/foo/files', - 'provider' => 'files', + 'path' => '/var/www/foo/files', + 'provider' => 'files' }, - ], + ] } end it { is_expected.to compile } it { is_expected.to contain_concat('25-rspec.example.com.conf') } + if (os_facts[:os]['family'] == 'RedHat' && os_facts[:os]['release']['major'].to_i > 6) || (os_facts[:os]['name'] == 'SLES' && os_facts[:os]['release']['major'].to_i > 11) it { - is_expected.to contain_concat__fragment('rspec.example.com-directories').with( + expect(subject).to contain_concat__fragment('rspec.example.com-directories').with( content: %r{^\s+Require all granted$}, ) } @@ -1908,58 +2008,63 @@ context 'require unmanaged' do let :params do { - 'docroot' => '/var/www/foo', - 'directories' => [ + 'docroot' => '/var/www/foo', + 'directories' => [ { - 'path' => '/var/www/foo', - 'require' => 'unmanaged', + 'path' => '/var/www/foo', + 'require' => 'unmanaged' }, - ], + ] } end it { is_expected.to compile } it { is_expected.to contain_concat('25-rspec.example.com.conf') } + it { - is_expected.not_to contain_concat__fragment('rspec.example.com-directories').with( + expect(subject).not_to contain_concat__fragment('rspec.example.com-directories').with( content: %r{^\s+Require all granted$}, ) } end + describe 'redirectmatch_*' do let(:params) { super().merge(port: 84) } context 'dest and regexp' do - let(:params) { super().merge(redirectmatch_dest: 'http://other.example.com$1.jpg', redirectmatch_regexp: "(.*)\.gif$") } + let(:params) { super().merge(redirectmatch_dest: 'http://other.example.com$1.jpg', redirectmatch_regexp: '(.*).gif$') } it { is_expected.to contain_concat__fragment('rspec.example.com-redirect') } it { is_expected.to contain_class('apache::mod::alias') } end + context 'none' do it { is_expected.not_to contain_concat__fragment('rspec.example.com-redirect') } it { is_expected.not_to contain_class('apache::mod::alias') } end end end + context 'oidc_settings RedirectURL' do describe 'with VALID relative URI' do let :params do default_params.merge( 'auth_oidc' => true, 'oidc_settings' => { 'ProviderMetadataURL' => 'https://login.example.com/.well-known/openid-configuration', - 'ClientID' => 'test', - 'RedirectURI' => '/some/valid/relative/uri', + 'ClientID' => 'test', + 'RedirectURI' => '/some/valid/relative/uri', 'ProviderTokenEndpointAuth' => 'client_secret_basic', - 'RemoteUserClaim' => 'sub', - 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', - 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, + 'RemoteUserClaim' => 'sub', + 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', + 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, ) end it { is_expected.to compile } + it { - is_expected.to contain_concat__fragment('rspec.example.com-auth_oidc').with( + expect(subject).to contain_concat__fragment('rspec.example.com-auth_oidc').with( content: %r{^\s+OIDCRedirectURI\s/some/valid/relative/uri$}, ) } @@ -1970,18 +2075,19 @@ default_params.merge( 'auth_oidc' => true, 'oidc_settings' => { 'ProviderMetadataURL' => 'https://login.example.com/.well-known/openid-configuration', - 'ClientID' => 'test', - 'RedirectURI' => 'invalid_uri', + 'ClientID' => 'test', + 'RedirectURI' => 'invalid_uri', 'ProviderTokenEndpointAuth' => 'client_secret_basic', - 'RemoteUserClaim' => 'sub', - 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', - 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, + 'RemoteUserClaim' => 'sub', + 'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8', + 'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd' }, ) end it { is_expected.not_to compile } end end + context 'mdomain' do let :params do default_params.merge( @@ -1990,7 +2096,7 @@ end it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-header').with( + expect(subject).to contain_concat__fragment('rspec.example.com-apache-header').with( content: %r{^MDomain rspec.example.com$}, ) } @@ -2006,7 +2112,7 @@ ) it { - is_expected.to contain_concat__fragment('rspec.example.com-apache-userdir') + expect(subject).to contain_concat__fragment('rspec.example.com-apache-userdir') .with(content: %r{^\s+UserDir disabled$}) .with(content: %r{^\s+UUserDir enabled bob$}) } diff --git a/spec/functions/bool2httpd_spec.rb b/spec/functions/bool2httpd_spec.rb index e3f40af43d..eb7bcf1c28 100644 --- a/spec/functions/bool2httpd_spec.rb +++ b/spec/functions/bool2httpd_spec.rb @@ -8,14 +8,18 @@ it { is_expected.to run.with_params('1', '2').and_raise_error(ArgumentError) } it { is_expected.to run.with_params(true).and_return('On') } it { is_expected.to run.with_params('true').and_return('On') } + it 'expected to return a string "On"' do expect(subject.execute(true)).to be_an_instance_of(String) end + it { is_expected.to run.with_params(false).and_return('Off') } it { is_expected.to run.with_params('false').and_return('Off') } + it 'expected to return a string "Off"' do expect(subject.execute(false)).to be_an_instance_of(String) end + it { is_expected.to run.with_params('mail').and_return('mail') } it { is_expected.to run.with_params(nil).and_return('Off') } it { is_expected.to run.with_params(:undef).and_return('Off') } diff --git a/spec/functions/pw_hash_spec.rb b/spec/functions/pw_hash_spec.rb index 5faf7d43e9..40674aa890 100644 --- a/spec/functions/pw_hash_spec.rb +++ b/spec/functions/pw_hash_spec.rb @@ -20,6 +20,7 @@ describe 'apache_pw_hash', type: :puppet_function do it_behaves_like 'apache::pw_hash function' end + describe 'apache::apache_pw_hash', type: :puppet_function do it_behaves_like 'apache::pw_hash function' end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07db73426e..1a8b68bde8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,11 +9,11 @@ require 'spec_helper_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_local.rb')) -include RspecPuppetFacts +include RspecPuppetFacts # rubocop:disable Style/MixinUsage default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ @@ -26,7 +26,7 @@ begin default_facts.merge!(YAML.safe_load(File.read(f), [], [], true)) - rescue => e + rescue StandardError => e RSpec.configuration.reporter.message "WARNING: Unable to load #{f}: #{e}" end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index f5eb0e59d9..974921d9c6 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -29,13 +29,9 @@ def print_parsing_errors RSpec.configure do |c| # IPv6 is not enabled by default in the new travis-ci Trusty environment (see https://github.com/travis-ci/travis-ci/issues/8891 ) - if ENV['CI'] == 'true' - c.filter_run_excluding ipv6: true - end + c.filter_run_excluding ipv6: true if ENV['CI'] == 'true' c.before :suite do - if %r{redhat|oracle}.match?(os[:family]) - LitmusHelper.instance.run_shell('puppet module install puppet/epel') - end + LitmusHelper.instance.run_shell('puppet module install puppet/epel') if %r{redhat|oracle}.match?(os[:family]) LitmusHelper.instance.apply_manifest(File.read(File.join(__dir__, 'setup_acceptance_node.pp'))) end @@ -151,5 +147,6 @@ def apache_settings_hash def mod_supported_on_platform?(mod) return false if ENV['DISABLE_MOD_TEST_EXCLUSION'] + ApacheModTestFilterHelper.instance.mod_supported_on_platform?(mod) end diff --git a/spec/spec_helper_local.rb b/spec/spec_helper_local.rb index a7211b68bb..d2c5fc09bf 100644 --- a/spec/spec_helper_local.rb +++ b/spec/spec_helper_local.rb @@ -29,7 +29,7 @@ end end -shared_examples :compile, compile: true do +shared_examples 'compile', compile: true do it { is_expected.to compile.with_all_deps } end @@ -67,12 +67,12 @@ family: 'Redhat', release: { major: '28', - full: '28', - }, + full: '28' + } }, identity: { - uid: 'root', - }, + uid: 'root' + } } end end @@ -86,12 +86,12 @@ name: 'FreeBSD', family: 'FreeBSD', release: { - full: '9', - }, + full: '9' + } }, identity: { - uid: 'root', - }, + uid: 'root' + } } end end @@ -105,12 +105,12 @@ name: 'FreeBSD', family: 'FreeBSD', release: { - full: '10', - }, + full: '10' + } }, identity: { - uid: 'root', - }, + uid: 'root' + } } end end @@ -125,12 +125,12 @@ family: 'Gentoo', release: { major: '2.7', - full: '2.7', - }, + full: '2.7' + } }, identity: { - uid: 'root', - }, + uid: 'root' + } } end end @@ -142,9 +142,9 @@ family: 'Darwin', name: 'Darwin', release: { - full: '13.1.0', - }, - }, + full: '13.1.0' + } + } } end end @@ -158,12 +158,12 @@ name: 'Magic', family: 'Magic', release: { - full: '0', - }, + full: '0' + } }, identity: { - uid: 'root', - }, + uid: 'root' + } } end end diff --git a/spec/type_aliases/modproxy_spec.rb b/spec/type_aliases/modproxy_spec.rb index a655e2517a..ab7c1bcf1a 100644 --- a/spec/type_aliases/modproxy_spec.rb +++ b/spec/type_aliases/modproxy_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe 'Apache::ModProxyProtocol' do diff --git a/spec/util/apache_mod_platform_compatibility_spec.rb b/spec/util/apache_mod_platform_compatibility_spec.rb index 3ca5bb7481..d2fe142542 100644 --- a/spec/util/apache_mod_platform_compatibility_spec.rb +++ b/spec/util/apache_mod_platform_compatibility_spec.rb @@ -18,7 +18,7 @@ 'scientific' => [6, 7], 'debian' => [8, 9, 10], 'sles' => [11, 12, 15], - 'ubuntu' => [14, 16, 18], + 'ubuntu' => [14, 16, 18] } context 'when initialized' do @@ -27,9 +27,11 @@ it 'returns an empty hash when given garbage line' do expect(ampc.process_line('foobar')).to eq({}) end + it 'returns a hash with type: :unsupported_platform_declaration and extracted value' do expect(ampc.process_line('# @note Unsupported platforms: foobar')).to eq(type: :unsupported_platform_declaration, value: 'foobar') end + it 'returns a hash with type: :class_declaration and extracted value' do expect(ampc.process_line(foobar_class)).to eq(type: :class_declaration, value: foobar_mod) end @@ -40,27 +42,35 @@ it 'handles single OS with single Version' do expect(ampc.extract_os_ver_pairs('Debian: 5')).to eq('debian' => [5]) end + it 'handles single OS with multiple Versions' do expect(ampc.extract_os_ver_pairs('Debian: 5, 6, 7')).to eq('debian' => [5, 6, 7]) end + it 'handles multiple OSs with multiple Versions' do expect(ampc.extract_os_ver_pairs('Debian: 5, 6, 7; CentOS: 5,6,7')).to eq('debian' => [5, 6, 7], 'centos' => [5, 6, 7]) end + it 'handles Versions in \d+\.\d+ format' do expect(ampc.extract_os_ver_pairs('Ubuntu: 18.04, 20.04')).to eq('ubuntu' => [18, 20]) end + it 'handles Versions with "SP"' do expect(ampc.extract_os_ver_pairs('SLES: 11 SP1, 12')).to eq('sles' => [11, 12]) end + it 'returns an empty Hash when given data in an entirely invalid format' do expect(ampc.extract_os_ver_pairs('foobar')).to eq({}) end + it 'returns an empty Hash when given data with incorrect OS/Version group separator' do expect(ampc.extract_os_ver_pairs('Ubuntu#18.04, 20.04')).to eq({}) end + it 'returns an empty Hash when given data with incorrect OS + Version separator' do expect(ampc.extract_os_ver_pairs('CentOS:7,8#Debian:10,11')).to eq({}) end + it 'returns an empty Hash when given data with incorrect Version separator' do expect(ampc.extract_os_ver_pairs('CentOS:5@6')).to eq({}) end @@ -74,6 +84,7 @@ ampc.register_unsupported_platforms(foobar_pp, 1, foobar_mod, 'debian' => [8]) expect(ampc.mod_supported_on_platform?(foobar_mod)).to be(false) end + it 'registers multiple valid unsupported platforms' do expect(ampc).to receive(:valid_os?).with('debian').and_return(true) expect(ampc).to receive(:valid_os?).with('ubuntu').and_return(true) @@ -84,6 +95,7 @@ ampc.register_running_platform(family: 'ubuntu', release: '14.04', arch: 'x86_64') expect(ampc.mod_supported_on_platform?(foobar_mod)).to be(false) end + it 'registers an :os_parse error when given an invalid platform' do expect(ampc).to receive(:valid_os?).with(foobar_linux).and_return(false) expect(ampc).to receive(:register_error).with(foobar_pp, 1, :os_parse, foobar_linux) @@ -130,16 +142,19 @@ ampc.register_unsupported_platforms(foobar_pp, 1, foobar_mod, 'ubuntu' => [0]) expect(ampc.mod_supported_on_platform?(foobar_mod)).to be(false) end + it 'returns false when running on an OS with one specific version incompatible' do ampc.register_running_platform(ubuntu_14_04_os) ampc.register_unsupported_platforms(foobar_pp, 1, foobar_mod, 'ubuntu' => [14]) expect(ampc.mod_supported_on_platform?(foobar_mod)).to be(false) end + it 'returns true when running on an OS with no versions marked as incompatible' do ampc.register_running_platform(ubuntu_14_04_os) ampc.register_unsupported_platforms(foobar_pp, 1, foobar_mod, 'debian' => [6, 7]) expect(ampc.mod_supported_on_platform?(foobar_mod)).to be(true) end + it 'returns true when running on an OS version not marked as incompatible' do ampc.register_running_platform(ubuntu_14_04_os) ampc.register_unsupported_platforms(foobar_pp, 1, foobar_mod, 'ubuntu' => [16, 18]) @@ -162,9 +177,9 @@ tag_format_help_msg_txt = ['succint', 'warning'] - expected_stderr_msg = "The following errors were encountered when trying to parse the 'Unsupported platforms' tag(s) in 'manifests/mod':\n" \ - " * #{abc_pp} (line #{abc_pp_error_line}): #{abc_pp_error_type_msg} #{abc_pp_error_detail}\n" \ - " * #{def_pp} (line #{def_pp_error_line}): #{def_pp_error_type_msg} #{def_pp_error_detail}\n" \ + expected_stderr_msg = "The following errors were encountered when trying to parse the 'Unsupported platforms' tag(s) in 'manifests/mod':\n " \ + "* #{abc_pp} (line #{abc_pp_error_line}): #{abc_pp_error_type_msg} #{abc_pp_error_detail}\n " \ + "* #{def_pp} (line #{def_pp_error_line}): #{def_pp_error_type_msg} #{def_pp_error_detail}\n" \ "#{tag_format_help_msg_txt[0]}\n" \ "#{tag_format_help_msg_txt[1]}\n" diff --git a/tasks/init.rb b/tasks/init.rb index bb82d9aa7e..caf5b58843 100755 --- a/tasks/init.rb +++ b/tasks/init.rb @@ -19,10 +19,11 @@ def service(action, service_name) end _stdout, stderr, status = Open3.capture3('service', service_name, action) raise Puppet::Error, stderr if status != 0 + { status: "#{action} successful" } end -params = JSON.parse(STDIN.read) +params = JSON.parse($stdin.read) action = params['action'] service_name = params['service_name'] diff --git a/util/apache_mod_platform_support.rb b/util/apache_mod_platform_support.rb index 5c608cf53d..0add6f0e0b 100644 --- a/util/apache_mod_platform_support.rb +++ b/util/apache_mod_platform_support.rb @@ -22,8 +22,8 @@ # ... class ApacheModPlatformCompatibility ERROR_MSG = { - tag_parse: 'OS and version information in incorrect format:', - os_parse: 'OS name is not present in metadata.json:', + tag_parse: 'OS and version information in incorrect format:', + os_parse: 'OS name is not present in metadata.json:' }.freeze def initialize @@ -59,12 +59,13 @@ def initialize(manifest, line_num, error_type, error_detail) def print_parsing_errors return if @manifest_errors.empty? - $stderr.puts "The following errors were encountered when trying to parse the 'Unsupported platforms' tag(s) in 'manifests/mod':\n" + + warn "The following errors were encountered when trying to parse the 'Unsupported platforms' tag(s) in 'manifests/mod':\n" @manifest_errors.each do |manifest_error| - $stderr.puts " * #{manifest_error.manifest} (line #{manifest_error.line_num}): #{ERROR_MSG[manifest_error.error_type]} #{manifest_error.error_detail}" + warn " * #{manifest_error.manifest} (line #{manifest_error.line_num}): #{ERROR_MSG[manifest_error.error_type]} #{manifest_error.error_detail}" end File.readlines('util/_resources/tag_format_help_msg.txt').each do |line| - $stderr.puts line + warn line end end @@ -107,6 +108,7 @@ def extract_os_ver_pairs(line) def process_line(line) data = {} return data unless %r{@note\sUnsupported\splatforms?:\s?|class\sapache::mod}i.match?(line) + if (match = %r{@note\sUnsupported\splatforms?:\s?(?.*)$}i.match(line)) data[:type] = :unsupported_platform_declaration data[:value] = match[:os_vers] @@ -125,6 +127,7 @@ def generate_mod_platform_exclusions line_num += 1 data = process_line(line) next if data.empty? + if data[:type] == :unsupported_platform_declaration platforms_versions = extract_os_ver_pairs(data[:value]) register_error(manifest, line_num, :tag_parse, line) if platforms_versions.empty? @@ -144,6 +147,7 @@ def mod_supported_on_platform?(mod) return true unless @mod_platform_compatibility_mapping.key? mod return true unless @mod_platform_compatibility_mapping[mod].key? @os[:family] return false if @mod_platform_compatibility_mapping[mod][@os[:family]] == [0] + !@mod_platform_compatibility_mapping[mod][@os[:family]].include? @os[:release] end end