From 4f7da218e5521dd4e34bcdc69ea8403dfc02063b Mon Sep 17 00:00:00 2001 From: Steven Pritchard Date: Tue, 17 Dec 2024 09:18:54 -0600 Subject: [PATCH] Clean up for rubocop --- .github/workflows/pr_tests.yml | 11 +- .rubocop.yml | 667 ++++++++++++++++-- Gemfile | 11 +- .../suites/default/01_accounts_spec.rb | 65 +- .../suites/default/02_accounts_simp_spec.rb | 82 ++- .../default/03_accounts_password_spec.rb | 131 ++-- spec/classes/instances/accounts_spec.rb | 130 ++-- spec/spec_helper.rb | 15 +- spec/spec_helper_acceptance.rb | 39 +- 9 files changed, 843 insertions(+), 308 deletions(-) diff --git a/.github/workflows/pr_tests.yml b/.github/workflows/pr_tests.yml index 21ca28c..bcc5fb0 100644 --- a/.github/workflows/pr_tests.yml +++ b/.github/workflows/pr_tests.yml @@ -35,7 +35,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: "Install Ruby ${{matrix.puppet.ruby_version}}" + - name: "Install Ruby 2.7" uses: ruby/setup-ruby@v1 # ruby/setup-ruby@ec106b438a1ff6ff109590de34ddc62c540232e0 with: ruby-version: 2.7 @@ -47,7 +47,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: "Install Ruby ${{matrix.puppet.ruby_version}}" + - name: "Install Ruby 2.7" uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 @@ -56,13 +56,12 @@ jobs: - run: "bundle exec rake metadata_lint" ruby-style: - if: false # TODO Modules will need: rubocop in Gemfile, .rubocop.yml - name: 'Ruby Style (experimental)' + name: 'Ruby Style' runs-on: ubuntu-latest continue-on-error: true steps: - uses: actions/checkout@v3 - - name: "Install Ruby ${{matrix.puppet.ruby_version}}" + - name: "Install Ruby 2.7" uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 @@ -89,7 +88,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - name: 'Install Ruby ${{matrix.puppet.ruby_version}}' + - name: 'Install Ruby 2.7' uses: ruby/setup-ruby@v1 with: ruby-version: 2.7 diff --git a/.rubocop.yml b/.rubocop.yml index f960a45..65c8c0a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,61 +1,41 @@ --- require: -- rubocop-rspec -- rubocop-i18n + - rubocop-performance + - rubocop-rake + - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.6' + TargetRubyVersion: "2.7" Include: - - "**/*.rb" + - "**/*.rb" Exclude: - - bin/* - - ".vendor/**/*" - - "**/Gemfile" - - "**/Rakefile" - - pkg/**/* - - spec/fixtures/**/* - - vendor/**/* - - "**/Puppetfile" - - "**/Vagrantfile" - - "**/Guardfile" -Layout/EmptyLinesAroundAttributeAccessor: - Enabled: true + - bin/* + - ".vendor/**/*" + - pkg/**/* + - spec/fixtures/**/* + - vendor/**/* + - "**/Puppetfile" + - "**/Vagrantfile" + - "**/Guardfile" Layout/LineLength: Description: People have wide screens, use them. Max: 200 -Layout/SpaceAroundMethodCallOperator: - Enabled: true -Lint/RaiseException: - Enabled: true -Lint/StructNewOverride: - Enabled: false -I18n/GetText: - Enabled: false -I18n/GetText/DecorateString: - Description: We don't want to decorate test output. - Exclude: - - spec/**/* - Enabled: false -Naming/AccessorMethodName: - Exclude: - - spec/**/* RSpec/BeforeAfterAll: - Description: Beware of using after(:all) as it may cause state to leak between tests. + Description: + Beware of using after(:all) as it may cause state to leak between tests. A necessary evil in acceptance testing. Exclude: - - spec/acceptance/**/*.rb -RSpec/ExpectInHook: - Exclude: - - spec/unit/**/*.rb + - spec/acceptance/**/*.rb RSpec/HookArgument: Description: Prefer explicit :each argument, matching existing module's style EnforcedStyle: each -RSpec/NamedSubject: +RSpec/DescribeSymbol: Exclude: - - spec/classes/**/* - - spec/defines/**/* + - spec/unit/facter/**/*.rb Style/BlockDelimiters: - Description: Prefer braces for chaining. Mostly an aesthetical choice. Better to + Description: + Prefer braces for chaining. Mostly an aesthetical choice. Better to be consistent then. EnforcedStyle: braces_for_chaining Style/ClassAndModuleChildren: @@ -64,49 +44,36 @@ Style/ClassAndModuleChildren: Style/EmptyElse: Description: Enforce against empty else clauses, but allow `nil` for clarity. EnforcedStyle: empty -Style/ExponentialNotation: - Enabled: true Style/FormatString: Description: Following the main puppet project's style, prefer the % format format. EnforcedStyle: percent Style/FormatStringToken: - Description: Following the main puppet project's style, prefer the simpler template + Description: + Following the main puppet project's style, prefer the simpler template tokens over annotated ones. EnforcedStyle: template -Style/HashEachMethods: - Enabled: true -Style/HashSyntax: - Enabled: false -Style/HashTransformKeys: - Enabled: false -Style/HashTransformValues: - Enabled: true Style/Lambda: Description: Prefer the keyword for easier discoverability. EnforcedStyle: literal -Style/MixinUsage: - Exclude: - - spec/**/* -Style/RedundantBegin: - Enabled: false Style/RegexpLiteral: Description: Community preference. See https://github.com/voxpupuli/modulesync_config/issues/168 EnforcedStyle: percent_r Style/TernaryParentheses: - Description: Checks for use of parentheses around ternary conditions. Enforce parentheses + Description: + Checks for use of parentheses around ternary conditions. Enforce parentheses on complex expressions for better readability, but seriously consider breaking it up. EnforcedStyle: require_parentheses_when_complex Style/TrailingCommaInArguments: - Description: Prefer always trailing comma on multiline argument lists. This makes + Description: + Prefer always trailing comma on multiline argument lists. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma Style/TrailingCommaInArrayLiteral: - Description: Prefer always trailing comma on multiline literals. This makes diffs, + Description: + Prefer always trailing comma on multiline literals. This makes diffs, and re-ordering nicer. EnforcedStyleForMultiline: comma -Style/SlicingWithRange: - Enabled: true Style/SymbolArray: Description: Using percent style obscures symbolic intent of array's contents. EnforcedStyle: brackets @@ -114,30 +81,176 @@ RSpec/MessageSpies: EnforcedStyle: receive Style/Documentation: Exclude: - - lib/puppet/parser/functions/**/* - - spec/**/* + - lib/puppet/parser/functions/**/* + - 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 -I18n/GetText/DecorateFunctionMessage: +Bundler/GemFilename: + Enabled: false +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 -I18n/GetText/DecorateStringFormattingUsingInterpolation: +Layout/EmptyLineAfterGuardClause: Enabled: false -I18n/GetText/DecorateStringFormattingUsingPercent: +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: @@ -150,21 +263,437 @@ 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/Dialect: + Enabled: false +RSpec/ContainExactly: + 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/MessageExpectation: +RSpec/ExampleWithoutDescription: + Enabled: false +RSpec/ExpectChange: + Enabled: false +RSpec/ExpectInHook: + Enabled: false +RSpec/HooksBeforeExamples: + Enabled: false +RSpec/ImplicitBlockExpectation: + Enabled: false +RSpec/ImplicitSubject: + Enabled: false +RSpec/LeakyConstantDeclaration: + Enabled: false +RSpec/LetBeforeExamples: + Enabled: false +RSpec/MatchArray: + Enabled: false +RSpec/MissingExampleGroupArgument: Enabled: false RSpec/MultipleExpectations: Enabled: false RSpec/MultipleMemoizedHelpers: Enabled: false +RSpec/MultipleSubjects: + Enabled: false RSpec/NestedGroups: Enabled: false -Style/AsciiComments: +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/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 +Gemspec/DeprecatedAttributeAssignment: + Enabled: false +Gemspec/DevelopmentDependencies: + Enabled: false +Gemspec/RequireMFA: + Enabled: false +Layout/LineContinuationLeadingSpace: + Enabled: false +Layout/LineContinuationSpacing: + Enabled: false +Layout/LineEndStringConcatenationIndentation: + Enabled: false +Layout/SpaceBeforeBrackets: + Enabled: false +Lint/AmbiguousAssignment: + Enabled: false +Lint/AmbiguousOperatorPrecedence: + Enabled: false +Lint/AmbiguousRange: + Enabled: false +Lint/ConstantOverwrittenInRescue: + Enabled: false +Lint/DeprecatedConstants: + Enabled: false +Lint/DuplicateBranch: + Enabled: false +Lint/DuplicateMagicComment: + Enabled: false +Lint/DuplicateMatchPattern: + Enabled: false +Lint/DuplicateRegexpCharacterClassElement: + Enabled: false +Lint/EmptyBlock: + Enabled: false +Lint/EmptyClass: + Enabled: false +Lint/EmptyInPattern: + Enabled: false +Lint/IncompatibleIoSelectWithFiberScheduler: + Enabled: false +Lint/LambdaWithoutLiteralBlock: + Enabled: false +Lint/NoReturnInBeginEndBlocks: + Enabled: false +Lint/NonAtomicFileOperation: + Enabled: false +Lint/NumberedParameterAssignment: + Enabled: false +Lint/OrAssignmentToConstant: + Enabled: false +Lint/RedundantDirGlobSort: + Enabled: false +Lint/RefinementImportMethods: + Enabled: false +Lint/RequireRangeParentheses: + Enabled: false +Lint/RequireRelativeSelfPath: + Enabled: false +Lint/SymbolConversion: + Enabled: false +Lint/ToEnumArguments: + Enabled: false +Lint/TripleQuotes: + Enabled: false +Lint/UnexpectedBlockArity: + Enabled: false +Lint/UnmodifiedReduceAccumulator: + Enabled: false +Lint/UselessRescue: + Enabled: false +Lint/UselessRuby2Keywords: + Enabled: false +Metrics/CollectionLiteralLength: + Enabled: false +Naming/BlockForwarding: + Enabled: false +Performance/CollectionLiteralInLoop: + Enabled: false +Performance/ConcurrentMonotonicTime: + Enabled: false +Performance/MapCompact: + Enabled: false +Performance/RedundantEqualityComparisonBlock: + Enabled: false +Performance/RedundantSplitRegexpArgument: + Enabled: false +Performance/StringIdentifierArgument: + Enabled: false +RSpec/BeEq: + Enabled: false +RSpec/BeNil: + Enabled: false +RSpec/ChangeByZero: + Enabled: false +RSpec/ClassCheck: + Enabled: false +RSpec/DuplicatedMetadata: + Enabled: false +RSpec/ExcessiveDocstringSpacing: + Enabled: false +RSpec/IdenticalEqualityAssertion: + Enabled: false +RSpec/NoExpectationExample: + Enabled: false +RSpec/PendingWithoutReason: + Enabled: false +RSpec/RedundantAround: + Enabled: false +RSpec/SkipBlockInsideExample: + Enabled: false +RSpec/SortMetadata: + Enabled: false +RSpec/SubjectDeclaration: + Enabled: false +RSpec/VerifiedDoubleReference: + Enabled: false +Security/CompoundHash: + Enabled: false +Security/IoMethods: + Enabled: false +Style/ArgumentsForwarding: + Enabled: false +Style/ArrayIntersect: + Enabled: false +Style/CollectionCompact: + Enabled: false +Style/ComparableClamp: + Enabled: false +Style/ConcatArrayLiterals: + Enabled: false +Style/DataInheritance: + Enabled: false +Style/DirEmpty: + Enabled: false +Style/DocumentDynamicEvalDefinition: + Enabled: false +Style/EmptyHeredoc: + Enabled: false +Style/EndlessMethod: + Enabled: false +Style/EnvHome: + Enabled: false +Style/FetchEnvVar: + Enabled: false +Style/FileEmpty: + Enabled: false +Style/FileRead: + Enabled: false +Style/FileWrite: + Enabled: false +Style/HashConversion: + Enabled: false +Style/HashExcept: + Enabled: false +Style/IfWithBooleanLiteralBranches: + Enabled: false +Style/InPatternThen: + Enabled: false +Style/MagicCommentFormat: + Enabled: false +Style/MapCompactWithConditionalBlock: + Enabled: false +Style/MapToHash: + Enabled: false +Style/MapToSet: + Enabled: false +Style/MinMaxComparison: + Enabled: false +Style/MultilineInPatternThen: + Enabled: false +Style/NegatedIfElseCondition: + Enabled: false +Style/NestedFileDirname: + Enabled: false +Style/NilLambda: + Enabled: false +Style/NumberedParameters: + Enabled: false +Style/NumberedParametersLimit: + Enabled: false +Style/ObjectThen: + Enabled: false +Style/OpenStructUse: + Enabled: false +Style/OperatorMethodCall: + Enabled: false +Style/QuotedSymbols: + Enabled: false +Style/RedundantArgument: + Enabled: false +Style/RedundantConstantBase: + Enabled: false +Style/RedundantDoubleSplatHashBraces: + Enabled: false +Style/RedundantEach: + Enabled: false +Style/RedundantHeredocDelimiterQuotes: + Enabled: false +Style/RedundantInitialize: + Enabled: false +Style/RedundantLineContinuation: + Enabled: false +Style/RedundantSelfAssignmentBranch: + Enabled: false +Style/RedundantStringEscape: + Enabled: false +Style/SelectByRegexp: + Enabled: false +Style/StringChars: + Enabled: false +Style/SwapValues: + Enabled: false diff --git a/Gemfile b/Gemfile index e74c3da..7c330d6 100644 --- a/Gemfile +++ b/Gemfile @@ -10,16 +10,23 @@ ENV['PDK_DISABLE_ANALYTICS'] ||= 'true' gem_sources.each { |gem_source| source gem_source } +group :syntax do + gem 'metadata-json-lint' + gem 'puppet-lint-trailing_comma-check', require: false + gem 'rubocop', '~> 1.68.0' + gem 'rubocop-performance', '~> 1.23.0' + gem 'rubocop-rake', '~> 0.6.0' + gem 'rubocop-rspec', '~> 3.2.0' +end + group :test do puppet_version = ENV.fetch('PUPPET_VERSION', ['>= 7', '< 9']) major_puppet_version = Array(puppet_version).first.scan(%r{(\d+)(?:\.|\Z)}).flatten.first.to_i gem 'hiera-puppet-helper' - gem 'metadata-json-lint' gem 'pathspec', '~> 0.2' if Gem::Requirement.create('< 2.6').satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem('pdk', ENV.fetch('PDK_VERSION', ['>= 2.0', '< 4.0']), require: false) if major_puppet_version > 5 gem 'puppet', puppet_version gem 'puppetlabs_spec_helper' - gem 'puppet-lint-trailing_comma-check', require: false gem 'puppet-strings' gem 'rake' gem 'rspec' diff --git a/spec/acceptance/suites/default/01_accounts_spec.rb b/spec/acceptance/suites/default/01_accounts_spec.rb index 6a3dba7..02748ec 100644 --- a/spec/acceptance/suites/default/01_accounts_spec.rb +++ b/spec/acceptance/suites/default/01_accounts_spec.rb @@ -7,85 +7,86 @@ servers.each do |server| context "on #{server} " do - let(:server_manifest) { + let(:server_manifest) do <<-EOS include 'simp_ds389::instances::accounts' EOS - } + end let(:server_fqdn) { fact_on(server, 'fqdn') } - let(:root_pw) { 's00perSekr!tP@ssw0rd'} - #default base_dn should be domain - let(:domain) { fact_on(server,'domain') } + let(:root_pw) { 's00perSekr!tP@ssw0rd' } + # default base_dn should be domain + let(:domain) { fact_on(server, 'domain') } - let(:base_dn) { 'dc=' + "#{domain}".split('.').join(',dc=') } + let(:base_dn) { 'dc=' + domain.to_s.split('.').join(',dc=') } # These are expected defaults. Will use these for tests not to set things. - let(:bind_dn) { "cn=hostAuth,ou=Hosts,#{base_dn}"} - let(:root_dn) { 'cn=Directory_Manager'} - let(:ds_root_name) { 'accounts'} + let(:bind_dn) { "cn=hostAuth,ou=Hosts,#{base_dn}" } + let(:root_dn) { 'cn=Directory_Manager' } + let(:ds_root_name) { 'accounts' } - let(:hieradata) {{ - 'simp_ds389::instances::accounts::root_pw' => "#{root_pw}", - }} + let(:hieradata) do + { + 'simp_ds389::instances::accounts::root_pw' => root_pw.to_s, + } + end context 'set up an ldapserver with defaults' do # Using puppet_apply as a helper - it 'should work with no errors' do + it 'works with no errors' do set_hieradata_on(server, hieradata) - apply_manifest_on(server, server_manifest, :catch_failures => true) + apply_manifest_on(server, server_manifest, catch_failures: true) end - it 'should be idempotent' do - apply_manifest_on(server, server_manifest, :catch_changes => true) + it 'is idempotent' do + apply_manifest_on(server, server_manifest, catch_changes: true) end - it 'should have a dirsrv accounts instance' do + it 'has a dirsrv accounts instance' do result = on(server, '/sbin/dsctl -l').output.strip expect(result).to include("slapd-#{ds_root_name}") end - it 'should log into ldapi' do + it 'logs into ldapi' do on(server, %(ldapsearch -x -w "#{root_pw}" -D "#{root_dn}" -H ldapi://%2fvar%2frun%2fslapd-#{ds_root_name}.socket -b "cn=tasks,cn=config")) end - it 'should login to 389DS without' do + it 'logins to 389DS without' do on(server, %(ldapsearch -x -w "#{root_pw}" -D "#{root_dn}" -H ldap://#{server_fqdn}:389 -b "cn=tasks,cn=config")) end - it 'should not login to 389DS encrypted' do + it 'does not login to 389DS encrypted' do expect { on(server, %(ldapsearch -x -w "#{root_pw}" -D "#{root_dn}" -H ldaps://#{server_fqdn}:636 -b "cn=tasks,cn=config")) }.to raise_error(Beaker::Host::CommandFailure) end - it 'should have the bind account and the users and administrators groups' do + it 'has the bind account and the users and administrators groups' do result = on(server, %(ldapsearch x -w "#{root_pw}" -D "#{root_dn}" -H ldap://#{server_fqdn} -b "#{base_dn}")).output.strip - expect(result).to include("#{bind_dn}") + expect(result).to include(bind_dn.to_s) expect(result).to include("cn=administrators,ou=Groups,#{base_dn}") expect(result).to include("cn=users,ou=Groups,#{base_dn}") end - end - context "remove the instance" do - let(:remove_manifest) { + context 'remove the instance' do + let(:remove_manifest) do <<-EOS ds389::instance { "#{ds_root_name}": ensure => 'absent' } EOS - } - it 'should work with no errors' do - apply_manifest_on(server, remove_manifest, :catch_failures => true) end - it 'should be idempotent' do - apply_manifest_on(server, remove_manifest, :catch_changes => true) + it 'works with no errors' do + apply_manifest_on(server, remove_manifest, catch_failures: true) + end + + it 'is idempotent' do + apply_manifest_on(server, remove_manifest, catch_changes: true) end - it 'should not have a dirsrv accounts instance' do + it 'does not have a dirsrv accounts instance' do result = on(server, '/sbin/dsctl -l').output.strip expect(result).not_to include("slapd-#{ds_root_name}") end end - end end end diff --git a/spec/acceptance/suites/default/02_accounts_simp_spec.rb b/spec/acceptance/suites/default/02_accounts_simp_spec.rb index b16c52e..583b7d8 100644 --- a/spec/acceptance/suites/default/02_accounts_simp_spec.rb +++ b/spec/acceptance/suites/default/02_accounts_simp_spec.rb @@ -13,7 +13,7 @@ clients = hosts_with_role(hosts, 'client') servers.each do |server| - let(:server_manifest) { + let(:server_manifest) do <<-EOS include 'simp_ds389::instances::accounts' @@ -25,37 +25,39 @@ protocol => 'tcp' } EOS - } + end let(:server_fqdn) { fact_on(server, 'fqdn') } - let(:root_pw) { 's00perSekr!tP@ssw0rd'} - let(:root_dn) { 'cn=Directory_Manager'} - let(:ds_root_name) { 'accounts'} - let(:base_dn) { 'dc=test,dc=org'} - let(:bind_dn) { "cn=myhostAuth,ou=Hosts,#{base_dn}"} + let(:root_pw) { 's00perSekr!tP@ssw0rd' } + let(:root_dn) { 'cn=Directory_Manager' } + let(:ds_root_name) { 'accounts' } + let(:base_dn) { 'dc=test,dc=org' } + let(:bind_dn) { "cn=myhostAuth,ou=Hosts,#{base_dn}" } let(:bind_pw) { 'P@ssw0rdP@ssw0rd' } - let(:hieradata) {{ - 'simp_options::pki' => true, - 'simp_options::pki::source' => '/etc/pki/simp-testing/pki', - 'simp_options::ldap::bind_dn' => "#{bind_dn}", - 'simp_options::ldap::base_dn' => "#{base_dn}", - 'simp_options::ldap::bind_hash' => '{SHA256}UPh9BmVFn/Pg2Fx/L+Qgf7pjmr7mjR7f0WOVhAlalRc=', - 'simp_options::ldap::bind_pw' => "#{bind_pw}", - 'simp_options::firewall' => true, - 'simp_ds389::instances::accounts::root_pw' => "#{root_pw}", - 'simp_options::trusted_nets' => [ 'ALL' ], - 'simp_options::ldap::uri' => [ "ldaps://#{server_fqdn}" ] - }} + let(:hieradata) do + { + 'simp_options::pki' => true, + 'simp_options::pki::source' => '/etc/pki/simp-testing/pki', + 'simp_options::ldap::bind_dn' => bind_dn.to_s, + 'simp_options::ldap::base_dn' => base_dn.to_s, + 'simp_options::ldap::bind_hash' => '{SHA256}UPh9BmVFn/Pg2Fx/L+Qgf7pjmr7mjR7f0WOVhAlalRc=', + 'simp_options::ldap::bind_pw' => bind_pw.to_s, + 'simp_options::firewall' => true, + 'simp_ds389::instances::accounts::root_pw' => root_pw.to_s, + 'simp_options::trusted_nets' => [ 'ALL' ], + 'simp_options::ldap::uri' => [ "ldaps://#{server_fqdn}" ] + } + end context 'set up an ldapserver with tls enabled' do # Using puppet_apply as a helper - it 'should work with no errors' do + it 'works with no errors' do set_hieradata_on(server, hieradata) - apply_manifest_on(server, server_manifest, :catch_failures => true) + apply_manifest_on(server, server_manifest, catch_failures: true) end - it 'should be idempotent' do - apply_manifest_on(server, server_manifest, :catch_changes => true) + it 'is idempotent' do + apply_manifest_on(server, server_manifest, catch_changes: true) end it 'sets the environment variables for ldapsearch' do @@ -64,37 +66,35 @@ server.add_env_var('LDAPTLS_CERT', "/etc/pki/simp_apps/ds389_#{ds_root_name}/x509/public/#{server_fqdn}.pub") end - it 'should log into ldapi' do + it 'logs into ldapi' do on(server, %(ldapsearch -x -w "#{root_pw}" -D "#{root_dn}" -H ldapi://%2fvar%2frun%2fslapd-#{ds_root_name}.socket -b "cn=tasks,cn=config")) end - it 'should login to 389DS Start TLS' do + it 'logins to 389DS Start TLS' do on(server, %(ldapsearch -ZZ -x -w "#{root_pw}" -D "#{root_dn}" -H ldap://#{server_fqdn}:389 -b "cn=tasks,cn=config")) end - it 'should login to 389DS encrypted' do + it 'logins to 389DS encrypted' do on(server, %(ldapsearch -x -w "#{root_pw}" -D "#{root_dn}" -H ldaps://#{server_fqdn}:636 -b "cn=tasks,cn=config")) end - it 'should have the bind account and the users and administrators groups' do + it 'has the bind account and the users and administrators groups' do result = on(server, %(ldapsearch -ZZ -x -w "#{root_pw}" -D "#{root_dn}" -H ldap://#{server_fqdn} -b "#{base_dn}")).output.strip - expect(result).to include("#{bind_dn}") + expect(result).to include(bind_dn.to_s) expect(result).to include("cn=administrators,ou=Groups,#{base_dn}") expect(result).to include("cn=users,ou=Groups,#{base_dn}") end - it 'should get results with the bind account' do + it 'gets results with the bind account' do result = on(server, %(ldapsearch -ZZ -x -w "#{bind_pw}" -D "#{bind_dn}" -H ldap://#{server_fqdn} -b "#{base_dn}")).output.strip expect(result).to include("cn=users,ou=Groups,#{base_dn}") end end clients.each do |client| - context "#{client} connecting to #{server}" do - - let(:client_manifest) { - <<-EOS + let(:client_manifest) do + <<-EOS include 'simp_openldap::client' #let vagrant ssh in @@ -105,24 +105,22 @@ protocol => 'tcp' } EOS - } + end - it 'should work with no errors' do + it 'works with no errors' do set_hieradata_on(client, hieradata) - apply_manifest_on(client, client_manifest, :catch_failures => true) + apply_manifest_on(client, client_manifest, catch_failures: true) end - it 'should be idempotent' do - apply_manifest_on(client, client_manifest, :catch_changes => true) + it 'is idempotent' do + apply_manifest_on(client, client_manifest, catch_changes: true) end - it 'should be able to connect using the bind DN and password' do + it 'is able to connect using the bind DN and password' do # LDAP server parameters are set in /etc/openldap/ldap.conf by simp_openldap result = on(client, "ldapsearch -D #{bind_dn} -w #{bind_pw}") - expect(result.output).to match(/dn: cn=users,ou=Groups,/) + expect(result.output).to match(%r{dn: cn=users,ou=Groups,}) end - end end - end end diff --git a/spec/acceptance/suites/default/03_accounts_password_spec.rb b/spec/acceptance/suites/default/03_accounts_password_spec.rb index f871e85..e7aaee8 100644 --- a/spec/acceptance/suites/default/03_accounts_password_spec.rb +++ b/spec/acceptance/suites/default/03_accounts_password_spec.rb @@ -10,10 +10,10 @@ # sure the firewall is open and the the bind_dn can access the base_dn. # servers = hosts_with_role(hosts, 'directory_server') - clients = hosts_with_role(hosts, 'client') + hosts_with_role(hosts, 'client') servers.each do |server| - let(:server_manifest) { + let(:server_manifest) do <<-EOS include 'simp_ds389::instances::accounts' @@ -25,80 +25,81 @@ protocol => 'tcp' } EOS - } + end let(:server_fqdn) { fact_on(server, 'fqdn') } - let(:root_pw) { 's00perSekr!tP@ssw0rd'} - let(:root_dn) { 'cn=Directory_Manager'} - let(:ds_root_name) { 'accounts'} - let(:base_dn) { 'dc=test,dc=org'} - let(:bind_dn) { "cn=myhostAuth,ou=Hosts,#{base_dn}"} + let(:root_pw) { 's00perSekr!tP@ssw0rd' } + let(:root_dn) { 'cn=Directory_Manager' } + let(:ds_root_name) { 'accounts' } + let(:base_dn) { 'dc=test,dc=org' } + let(:bind_dn) { "cn=myhostAuth,ou=Hosts,#{base_dn}" } let(:bind_pw) { 'P@ssw0rdP@ssw0rd' } - let(:hieradata) {{ - 'simp_options::pki' => true, - 'simp_options::pki::source' => '/etc/pki/simp-testing/pki', - 'simp_options::ldap::bind_dn' => "#{bind_dn}", - 'simp_options::ldap::base_dn' => "#{base_dn}", - 'simp_options::ldap::bind_hash' => '{SHA256}UPh9BmVFn/Pg2Fx/L+Qgf7pjmr7mjR7f0WOVhAlalRc=', - 'simp_options::ldap::bind_pw' => "#{bind_pw}", - 'simp_options::firewall' => true, - 'simp_ds389::instances::accounts::root_pw' => "#{root_pw}", - 'simp_options::trusted_nets' => [ 'ALL' ], - 'simp_options::ldap::uri' => [ "ldaps://#{server_fqdn}" ], - 'simp_ds389::instances::accounts::password_policy' => { - 'passwordWarning' => 99999, - 'passwordMinAge' => 0 + let(:hieradata) do + { + 'simp_options::pki' => true, + 'simp_options::pki::source' => '/etc/pki/simp-testing/pki', + 'simp_options::ldap::bind_dn' => bind_dn.to_s, + 'simp_options::ldap::base_dn' => base_dn.to_s, + 'simp_options::ldap::bind_hash' => '{SHA256}UPh9BmVFn/Pg2Fx/L+Qgf7pjmr7mjR7f0WOVhAlalRc=', + 'simp_options::ldap::bind_pw' => bind_pw.to_s, + 'simp_options::firewall' => true, + 'simp_ds389::instances::accounts::root_pw' => root_pw.to_s, + 'simp_options::trusted_nets' => [ 'ALL' ], + 'simp_options::ldap::uri' => [ "ldaps://#{server_fqdn}" ], + 'simp_ds389::instances::accounts::password_policy' => { + 'passwordWarning' => 99_999, + 'passwordMinAge' => 0 + } } - }} - let(:default_passwordpolicy) {{ - 'nsslapd-pwpolicy-local' => 'on', - 'passwordChange'=> 'on', - 'passwordMustChange' => 'on', - 'passwordInHistory' => 6, - 'passwordTrackUpdateTime' => 'on', - 'passwordWarning' => 86400, - 'passwordIsGlobalPolicy' => 'on', - 'passwordExp' => 'on', - 'passwordMaxAge' => 7776000, - 'passwordMinAge' => 1800, - 'passwordGraceLimit' => 0, - 'passwordLockout' => 'on', - 'passwordUnlock' => 'on', - 'passwordLockoutDuration' => 900, - 'passwordMaxFailure' => 3, - 'passwordResetFailureCount' => 600, - 'passwordCheckSyntax' => 'on', - 'passwordMinLength' => 15, - 'passwordMinDigits' => 1, - 'passwordMinAlphas' => 1, - 'passwordMinUppers' => 1, - 'passwordMinLowers' => 1, - 'passwordMinSpecials' => 1, - 'passwordMaxRepeats' => 3, - 'passwordMinCategories' => 3, - 'passwordMinTokenLength' => 3, - 'nsslapd-pwpolicy-inherit-global' => 'on', - 'passwordMaxClassChars' => 3, - 'passwordMaxSequence' => 4, - 'passwordMaxSeqSets' => 2, - 'passwordPalindrome' => 'on', - 'passwordDictCheck' => 'on', - 'passwordHistory' => 'on', - }} - + end + let(:default_passwordpolicy) do + { + 'nsslapd-pwpolicy-local' => 'on', + 'passwordChange' => 'on', + 'passwordMustChange' => 'on', + 'passwordInHistory' => 6, + 'passwordTrackUpdateTime' => 'on', + 'passwordWarning' => 86_400, + 'passwordIsGlobalPolicy' => 'on', + 'passwordExp' => 'on', + 'passwordMaxAge' => 7_776_000, + 'passwordMinAge' => 1800, + 'passwordGraceLimit' => 0, + 'passwordLockout' => 'on', + 'passwordUnlock' => 'on', + 'passwordLockoutDuration' => 900, + 'passwordMaxFailure' => 3, + 'passwordResetFailureCount' => 600, + 'passwordCheckSyntax' => 'on', + 'passwordMinLength' => 15, + 'passwordMinDigits' => 1, + 'passwordMinAlphas' => 1, + 'passwordMinUppers' => 1, + 'passwordMinLowers' => 1, + 'passwordMinSpecials' => 1, + 'passwordMaxRepeats' => 3, + 'passwordMinCategories' => 3, + 'passwordMinTokenLength' => 3, + 'nsslapd-pwpolicy-inherit-global' => 'on', + 'passwordMaxClassChars' => 3, + 'passwordMaxSequence' => 4, + 'passwordMaxSeqSets' => 2, + 'passwordPalindrome' => 'on', + 'passwordDictCheck' => 'on', + 'passwordHistory' => 'on', + } + end context 'check password policy' do - - it "should have default password policy " do + it 'has default password policy' do result = on(server, %(dsconf -j -w "#{root_pw}" -D "#{root_dn}" accounts config get)).output.strip config_hash = JSON.parse(result) attrs_hash = config_hash['attrs'] - default_passwordpolicy.each do |key,value| - expect(attrs_hash).to have_key("#{key.downcase}") - expect(attrs_hash[key.downcase]).to include("#{value}") + default_passwordpolicy.each do |key, value| + expect(attrs_hash).to have_key(key.downcase.to_s) + expect(attrs_hash[key.downcase]).to include(value.to_s) end end end - end end diff --git a/spec/classes/instances/accounts_spec.rb b/spec/classes/instances/accounts_spec.rb index c6d6de3..d3ddfbd 100644 --- a/spec/classes/instances/accounts_spec.rb +++ b/spec/classes/instances/accounts_spec.rb @@ -1,7 +1,6 @@ require 'spec_helper' describe 'simp_ds389::instances::accounts' do - context 'supported operating systems' do on_supported_os.each do |os, os_facts| context "on #{os}" do @@ -11,29 +10,31 @@ let(:exp_dir) { File.join(__dir__, 'expected') } - context "simp_ds389 class without any parameters" do + context 'simp_ds389 class without any parameters' do it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_ds389__instance('accounts') - .with_listen_address('0.0.0.0') - .with_enable_tls(false) - .with_port(389) - .with_secure_port(636) - .with_tls_params({}) - .with_base_dn(%r{^dc=}) - .with_root_dn('cn=Directory_Manager') + it { + is_expected.to contain_ds389__instance('accounts') + .with_listen_address('0.0.0.0') + .with_enable_tls(false) + .with_port(389) + .with_secure_port(636) + .with_tls_params({}) + .with_base_dn(%r{^dc=}) + .with_root_dn('cn=Directory_Manager') } - it { is_expected.to contain_ds389__instance('accounts') - .with_password_policy({ - 'nsslapd-pwpolicy-local' => 'on', - 'passwordChange'=> 'on', + it { + is_expected.to contain_ds389__instance('accounts') + .with_password_policy({ + 'nsslapd-pwpolicy-local' => 'on', + 'passwordChange' => 'on', 'passwordMustChange' => 'on', 'passwordHistory' => 'on', 'passwordInHistory' => 6, 'passwordTrackUpdateTime' => 'on', - 'passwordWarning' => 86400, + 'passwordWarning' => 86_400, 'passwordIsGlobalPolicy' => 'on', 'passwordExp' => 'on', - 'passwordMaxAge' => 7776000, + 'passwordMaxAge' => 7_776_000, 'passwordMinAge' => 1800, 'passwordGraceLimit' => 0, 'passwordLockout' => 'on', @@ -57,61 +58,66 @@ 'passwordMaxSeqSets' => 2, 'passwordPalindrome' => 'on', 'passwordDictCheck' => 'on', - }) + }) } - it { is_expected.not_to contain_simp_firewalld__rule('Allow 389DS accounts instance')} + it { is_expected.not_to contain_simp_firewalld__rule('Allow 389DS accounts instance') } end - context "with params set" do - let(:params) {{ - :instance_name => 'myaccounts', - :base_dn => 'dc=test,dc=org', - :root_dn => 'cn=myDirectory_Manager', - :root_pw => 'myrootpassword', - :listen_address => '1.2.3.4', - :enable_tls => true, - :firewall => true, - :trusted_nets => ['ALL'], - :port => 388, - :secure_port => 638, - :tls_params => { 'source' => '/my/source' }, - :instance_params => { 'service_user' => 'myuser' } - }} + context 'with params set' do + let(:params) do + { + instance_name: 'myaccounts', + base_dn: 'dc=test,dc=org', + root_dn: 'cn=myDirectory_Manager', + root_pw: 'myrootpassword', + listen_address: '1.2.3.4', + enable_tls: true, + firewall: true, + trusted_nets: ['ALL'], + port: 388, + secure_port: 638, + tls_params: { 'source' => '/my/source' }, + instance_params: { 'service_user' => 'myuser' } + } + end - it { is_expected.to contain_ds389__instance('myaccounts').with({ - :listen_address => '1.2.3.4', - :enable_tls => true, - :port => 388, - :secure_port => 638, - :tls_params => { - 'source' => '/my/source' + it { + is_expected.to contain_ds389__instance('myaccounts').with({ + listen_address: '1.2.3.4', + enable_tls: true, + port: 388, + secure_port: 638, + tls_params: { + 'source' => '/my/source' }, - :base_dn => 'dc=test,dc=org', - :root_dn => 'cn=myDirectory_Manager', - :root_dn_password => 'myrootpassword', - :service_user => 'myuser', - })} - it { is_expected.to contain_simp_firewalld__rule('Allow 389DS myaccounts instance')} - + base_dn: 'dc=test,dc=org', + root_dn: 'cn=myDirectory_Manager', + root_dn_password: 'myrootpassword', + service_user: 'myuser', + }) + } + it { is_expected.to contain_simp_firewalld__rule('Allow 389DS myaccounts instance') } end - context "with params set test bootstrap ldif" do - let(:params) {{ - :base_dn => 'dc=test,dc=org', - :root_dn => 'cn=myDirectory_Manager', - :bind_dn => 'cn=myhostAuth,ou=Hosts,dc=test,dc=org', - :bind_pw => 'mypassword', - :users_group_id => 666, - :administrators_group_id => 777 - }} - let(:expected_bootstrap) { File.read("#{exp_dir}/accounts_bootstrap.txt")} - it { is_expected.to contain_ds389__instance('accounts').with({ - :bootstrap_ldif_content => "#{expected_bootstrap}" - })} + context 'with params set test bootstrap ldif' do + let(:params) do + { + base_dn: 'dc=test,dc=org', + root_dn: 'cn=myDirectory_Manager', + bind_dn: 'cn=myhostAuth,ou=Hosts,dc=test,dc=org', + bind_pw: 'mypassword', + users_group_id: 666, + administrators_group_id: 777 + } + end + let(:expected_bootstrap) { File.read("#{exp_dir}/accounts_bootstrap.txt") } + it { + is_expected.to contain_ds389__instance('accounts').with({ + bootstrap_ldif_content: expected_bootstrap.to_s + }) + } end - end end end - end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 1b21aa4..5799a78 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + # # ------------------------------------------------------------------------------ # NOTICE: **This file is maintained with puppetsync** @@ -90,7 +91,7 @@ def set_hieradata(hieradata) # If nothing else... c.default_facts = { production: { - #:fqdn => 'production.rspec.test.localdomain', + # :fqdn => 'production.rspec.test.localdomain', path: '/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin', concat_basedir: '/tmp' } @@ -151,9 +152,9 @@ def set_hieradata(hieradata) # sanitize hieradata if defined?(hieradata) - set_hieradata(hieradata.gsub(':', '_')) + set_hieradata(hieradata.tr(':', '_')) elsif defined?(class_name) - set_hieradata(class_name.gsub(':', '_')) + set_hieradata(class_name.tr(':', '_')) end end @@ -165,9 +166,7 @@ def set_hieradata(hieradata) end Dir.glob("#{RSpec.configuration.module_path}/*").each do |dir| - begin - Pathname.new(dir).realpath - rescue StandardError - raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue." - end + Pathname.new(dir).realpath +rescue StandardError + raise "ERROR: The module '#{dir}' is not installed. Tests cannot continue." end diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index 9631ed6..c283286 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -15,7 +15,6 @@ end end - RSpec.configure do |c| # ensure that environment OS is ready on each host fix_errata_on hosts @@ -29,29 +28,25 @@ # Configure all nodes in nodeset c.before :suite do + # Install modules and dependencies from spec/fixtures/modules + copy_fixture_modules_to(hosts) begin - # Install modules and dependencies from spec/fixtures/modules - copy_fixture_modules_to( hosts ) - begin - server = only_host_with_role(hosts, 'server') - rescue ArgumentError =>e - server = only_host_with_role(hosts, 'default') - end - - # Generate and install PKI certificates on each SUT - Dir.mktmpdir do |cert_dir| - run_fake_pki_ca_on(server, hosts, cert_dir ) - hosts.each{ |sut| copy_pki_to( sut, cert_dir, '/etc/pki/simp-testing' )} - end + server = only_host_with_role(hosts, 'server') + rescue ArgumentError => e + server = only_host_with_role(hosts, 'default') + end - # add PKI keys - copy_keydist_to(server) - rescue StandardError, ScriptError => e - if ENV['PRY'] - require 'pry'; binding.pry - else - raise e - end + # Generate and install PKI certificates on each SUT + Dir.mktmpdir do |cert_dir| + run_fake_pki_ca_on(server, hosts, cert_dir) + hosts.each { |sut| copy_pki_to(sut, cert_dir, '/etc/pki/simp-testing') } end + + # add PKI keys + copy_keydist_to(server) + rescue StandardError, ScriptError => e + raise e unless ENV['PRY'] + require 'pry' + binding.pry # rubocop:disable Lint/Debugger end end