From fa51f4cd26414357b1e2f6f88180c587a5de93fb Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 09:43:09 +0100 Subject: [PATCH 01/51] (CONT-800) PDK Update --- .github/workflows/auto_release.yml | 1 - .github/workflows/release.yml | 3 +-- Gemfile | 2 +- Rakefile | 1 - metadata.json | 4 ++-- 5 files changed, 4 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto_release.yml b/.github/workflows/auto_release.yml index ca677186..d6270c56 100644 --- a/.github/workflows/auto_release.yml +++ b/.github/workflows/auto_release.yml @@ -5,6 +5,5 @@ on: jobs: release_prep: - name: "Release Prep" uses: "puppetlabs/cat-github-actions/.github/workflows/module_release_prep.yml@main" secrets: "inherit" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 82caec76..0b7b8a05 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -4,7 +4,6 @@ on: workflow_dispatch: jobs: - release: - name: "Release" + release: uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" secrets: "inherit" diff --git a/Gemfile b/Gemfile index 8298eb74..952b2bd2 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ group :development do 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 "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 diff --git a/Rakefile b/Rakefile index 0f8754eb..53152e21 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/metadata.json b/metadata.json index 113f9617..a5f2d29c 100644 --- a/metadata.json +++ b/metadata.json @@ -49,7 +49,7 @@ "tsql", "database" ], - "pdk-version": "2.6.1", + "pdk-version": "2.7.1", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "heads/main-0-g6e2b72d" + "template-ref": "tags/2.7.5-0-ge5b0114" } From dcc0c7e12f97c13669e757a52e60e8d237172bff Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 09:43:51 +0100 Subject: [PATCH 02/51] (CONT-800) Add Support for Puppet 8 / Remove Support for Puppet 6 --- metadata.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.json b/metadata.json index a5f2d29c..8a7f758a 100644 --- a/metadata.json +++ b/metadata.json @@ -32,7 +32,7 @@ "requirements": [ { "name": "puppet", - "version_requirement": ">=6.0.0 < 8.0.0" + "version_requirement": ">=7.0.0 < 9.0.0" } ], "tags": [ From 25fc51e507ebaa640866f4d9714469909c9ed112 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 09:44:22 +0100 Subject: [PATCH 03/51] (CONT-800) Re-pin puppet_agent --- .fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index 39cbdd00..b7af544a 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -3,7 +3,7 @@ fixtures: facts: 'https://github.com/puppetlabs/puppetlabs-facts.git' puppet_agent: repo: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git' - ref: v4.12.1 + ref: v4.13.0 provision: 'https://github.com/puppetlabs/provision.git' stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git' mount_iso: 'https://github.com/puppetlabs/puppetlabs-mount_iso.git' From 1d20f921bba2cba3f1843f35cf0281af89ad6055 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 09:47:56 +0100 Subject: [PATCH 04/51] (CONT-800) Update Rubocop Versions New Versions: rubocop = 1.48.1 rubocop-performance = 1.16.0 rubocop-rspec = 2.19.0 --- .rubocop.yml | 448 +---------------------------------------- .rubocop_todo.yml | 502 +++++++++++++++++++++++++++++++++++++++++++++- Gemfile | 6 +- 3 files changed, 508 insertions(+), 448 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index a886d8db..2dbf4503 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,10 +1,15 @@ --- +inherit_from: .rubocop_todo.yml + require: - rubocop-performance - rubocop-rspec AllCops: + NewCops: enable DisplayCopNames: true - TargetRubyVersion: '2.5' + ExtraDetails: true + DisplayStyleGuide: true + TargetRubyVersion: '2.7' Include: - "**/*.rb" Exclude: @@ -18,7 +23,6 @@ AllCops: - "**/Puppetfile" - "**/Vagrantfile" - "**/Guardfile" -inherit_from: ".rubocop_todo.yml" Layout/LineLength: Description: People have wide screens, use them. Max: 200 @@ -80,441 +84,7 @@ 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 + Max: 3 +Naming/MethodParameterName: + AllowedNames: 'is' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b57cce5..b5f295df 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,25 +1,280 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-12-17 20:22:52 UTC using RuboCop version 1.6.1. +# on 2023-04-24 08:47:50 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: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, IndentationWidth. +# SupportedStyles: with_first_argument, with_fixed_indentation +Layout/ArgumentAlignment: + Exclude: + - 'spec/acceptance/sqlserver_config_spec.rb' + +# Offense count: 15 +# This cop supports safe autocorrection (--autocorrect). +Layout/ClosingHeredocIndentation: + Exclude: + - 'lib/puppet/provider/sqlserver.rb' + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/acceptance/sqlserver_user_spec.rb' + - 'spec/acceptance/z_last_sqlserver_features_spec.rb' + - 'spec/defines/database_spec.rb' + - 'spec/defines/login/permissions_spec.rb' + - 'spec/defines/login_spec.rb' + - 'spec/defines/sp_configure_spec.rb' + - 'spec/defines/user/permissions_spec.rb' + - 'spec/defines/user_spec.rb' + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + +# Offense count: 33 +# This cop supports safe autocorrection (--autocorrect). +Layout/EmptyLineAfterGuardClause: + Enabled: false + +# Offense count: 46 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. +# SupportedHashRocketStyles: key, separator, table +# SupportedColonStyles: key, separator, table +# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit +Layout/HashAlignment: + Exclude: + - 'lib/puppet/provider/sqlserver.rb' + - 'lib/puppet/provider/sqlserver_instance/mssql.rb' + - 'lib/puppet_x/sqlserver/features.rb' + - 'lib/puppet_x/sqlserver/sql_connection.rb' + - 'spec/acceptance/sqlserver_config_spec.rb' + - 'spec/defines/database_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +Layout/HeredocIndentation: + Exclude: + - 'lib/puppet/property/sqlserver_tsql.rb' + - 'lib/puppet/provider/sqlserver.rb' + - 'spec/sql_testing_helpers.rb' + - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Layout/SpaceAroundMethodCallOperator: + Exclude: + - 'spec/acceptance/z_last_sqlserver_features_spec.rb' + +# Offense count: 2 +# Configuration parameters: AllowedMethods. +# AllowedMethods: enums +Lint/ConstantDefinitionInBlock: + Exclude: + - 'lib/puppet/provider/sqlserver_instance/mssql.rb' + - 'spec/functions/sqlserver_upcase_spec.rb' + # Offense count: 3 +# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. +Lint/DuplicateBranch: + Exclude: + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/DuplicateRegexpCharacterClassElement: + Exclude: + - 'lib/puppet/type/sqlserver_tsql.rb' + +# Offense count: 7 +# Configuration parameters: AllowComments, AllowEmptyLambdas. +Lint/EmptyBlock: + Exclude: + - 'lib/puppet/type/sqlserver_instance.rb' + - 'lib/puppet_x/sqlserver/features.rb' + - 'spec/defines/manifest_shared_examples.rb' + - 'spec/functions/functions_shared_examples.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowComments. +Lint/EmptyConditionalBody: + Exclude: + - 'lib/puppet/parser/functions/sqlserver_validate_range.rb' + +# Offense count: 10 +# This cop supports unsafe autocorrection (--autocorrect-all). +Lint/OrAssignmentToConstant: + Exclude: + - 'lib/puppet_x/sqlserver/features.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopDisableDirective: + Exclude: + - 'lib/puppet_x/sqlserver/server_helper.rb' + +# Offense count: 15 +# This cop supports safe autocorrection (--autocorrect). +Lint/RedundantCopEnableDirective: + Exclude: + - 'spec/acceptance/sqlserver_database_spec.rb' + - 'spec/acceptance/sqlserver_instance_spec.rb' + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/acceptance/sqlserver_role_spec.rb' + - 'spec/acceptance/sqlserver_tsql_spec.rb' + - 'spec/acceptance/sqlserver_user_spec.rb' + - 'spec/defines/role/permissions_spec.rb' + - 'spec/defines/role_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 3 +# Configuration parameters: AllowComments, AllowNil. Lint/SuppressedException: Exclude: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' +# Offense count: 16 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 36 + +# Offense count: 6 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 177 + # Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect. +# Configuration parameters: CountComments, CountAsOne. +Metrics/ClassLength: + Max: 158 + +# Offense count: 10 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 12 + +# Offense count: 40 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 41 + +# Offense count: 10 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/PerceivedComplexity: + Max: 13 + +# Offense count: 12 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/puppet/type/sqlserver_tsql.rb' + - 'spec/defines/database_spec.rb' + - 'spec/defines/login/permissions_spec.rb' + - 'spec/defines/login_spec.rb' + - 'spec/defines/sp_configure_spec.rb' + - 'spec/defines/user/permissions_spec.rb' + - 'spec/defines/user_spec.rb' + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + +# Offense count: 2 +# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# SupportedStyles: snake_case, normalcase, non_integer +# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +Naming/VariableNumber: + Exclude: + - 'lib/puppet/provider/sqlserver_features/mssql.rb' + - 'lib/puppet/provider/sqlserver_instance/mssql.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Performance/InefficientHashSearch: + Exclude: + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). Performance/StringInclude: Exclude: + - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' - 'lib/puppet/provider/sqlserver_tsql/mssql.rb' +# Offense count: 66 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Enabled: false + +# Offense count: 28 +# Configuration parameters: IgnoredMetadata. +RSpec/DescribeClass: + Enabled: false + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/EmptyHook: + Exclude: + - 'spec/acceptance/sqlserver_user_spec.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterExample: + Exclude: + - 'spec/acceptance/sqlserver_instance_spec.rb' + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/functions/sqlserver_upcase_spec.rb' + - 'spec/unit/puppet/property/tsql_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 56 +# This cop supports safe autocorrection (--autocorrect). +RSpec/EmptyLineAfterExampleGroup: + Exclude: + - 'spec/defines/database_spec.rb' + - 'spec/defines/login/permissions_spec.rb' + - 'spec/defines/login_spec.rb' + - 'spec/defines/role/permissions_spec.rb' + - 'spec/defines/role_spec.rb' + - 'spec/defines/user/permissions_spec.rb' + - 'spec/defines/user_spec.rb' + - 'spec/functions/sqlserver_validate_size_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 6 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowConsecutiveOneLiners. +RSpec/EmptyLineAfterHook: + Exclude: + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/acceptance/sqlserver_role_spec.rb' + - 'spec/acceptance/sqlserver_user_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 51 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 59 + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ExcessiveDocstringSpacing: + Exclude: + - 'spec/defines/user/permissions_spec.rb' + # Offense count: 2 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. # Include: **/*_spec*rb*, **/spec/**/* @@ -28,7 +283,22 @@ RSpec/FilePath: - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 301 +# Offense count: 23 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit +RSpec/ImplicitSubject: + Exclude: + - 'spec/defines/config_spec.rb' + - 'spec/defines/database_spec.rb' + - 'spec/defines/login_spec.rb' + - 'spec/defines/manifest_shared_examples.rb' + - 'spec/defines/role/permissions_spec.rb' + - 'spec/defines/role_spec.rb' + - 'spec/defines/sp_configure_spec.rb' + - 'spec/defines/user_spec.rb' + +# Offense count: 302 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: @@ -46,28 +316,248 @@ RSpec/InstanceVariable: - 'spec/unit/puppet/type/sqlserver_instance_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' +# Offense count: 1 +RSpec/LeakyConstantDeclaration: + Exclude: + - 'spec/functions/sqlserver_upcase_spec.rb' + +# Offense count: 6 +RSpec/MultipleExpectations: + Max: 8 + +# Offense count: 10 +# Configuration parameters: AllowSubject. +RSpec/MultipleMemoizedHelpers: + Max: 10 + # Offense count: 17 -# Configuration parameters: IgnoreSharedExamples. +# Configuration parameters: EnforcedStyle, IgnoreSharedExamples. +# SupportedStyles: always, named_only RSpec/NamedSubject: Exclude: - 'spec/unit/puppet_x/sql_connection_spec.rb' +# Offense count: 31 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 4 + +# Offense count: 70 +# Configuration parameters: AllowedPatterns. +# AllowedPatterns: ^expect_, ^assert_ +RSpec/NoExpectationExample: + Exclude: + - 'spec/acceptance/sqlserver_config_spec.rb' + - 'spec/acceptance/sqlserver_database_spec.rb' + - 'spec/acceptance/sqlserver_instance_spec.rb' + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/acceptance/sqlserver_role_spec.rb' + - 'spec/acceptance/sqlserver_tsql_spec.rb' + - 'spec/acceptance/sqlserver_user_spec.rb' + - 'spec/acceptance/z_last_sqlserver_features_spec.rb' + - 'spec/functions/sqlserver_upcase_spec.rb' + - 'spec/functions/sqlserver_validate_size_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' + - 'spec/unit/puppet/type/sqlserver_instance_spec.rb' + - 'spec/unit/puppet_x/server_helper_spec.rb' + +# Offense count: 5 +# This cop supports safe autocorrection (--autocorrect). +RSpec/ReceiveNever: + Exclude: + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 4 +RSpec/RepeatedExampleGroupBody: + Exclude: + - 'spec/defines/login/permissions_spec.rb' + - 'spec/defines/user/permissions_spec.rb' + +# Offense count: 4 +RSpec/RepeatedExampleGroupDescription: + Exclude: + - 'spec/defines/config_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + +# Offense count: 7 +RSpec/StubbedMock: + Exclude: + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + +# Offense count: 2 +RSpec/SubjectDeclaration: + Exclude: + - 'spec/unit/puppet_x/server_helper_spec.rb' + - 'spec/unit/puppet_x/sql_connection_spec.rb' + # Offense count: 6 RSpec/SubjectStub: Exclude: - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' +# Offense count: 4 +RSpec/UnspecifiedException: + Exclude: + - 'spec/functions/sqlserver_validate_hash_uniq_values_spec.rb' + - 'spec/functions/sqlserver_validate_instance_name_spec.rb' + # Offense count: 2 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/unit/puppet_x/sql_connection_spec.rb' +# Offense count: 7 +Security/Open: + Exclude: + - 'lib/puppet_x/sqlserver/features.rb' + - 'lib/puppet_x/sqlserver/sql_connection.rb' + +# Offense count: 4 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowedVars. +Style/FetchEnvVar: + Exclude: + - 'lib/puppet/provider/sqlserver.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowSplatArgument. +Style/HashConversion: + Exclude: + - 'lib/puppet_x/sqlserver/features.rb' + +# Offense count: 30 +# This cop supports safe autocorrection (--autocorrect). +Style/IfUnlessModifier: + Exclude: + - 'lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb' + - 'lib/puppet/parser/functions/sqlserver_validate_instance_name.rb' + - 'lib/puppet/parser/functions/sqlserver_validate_range.rb' + - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' + - 'lib/puppet/property/sqlserver_login.rb' + - 'lib/puppet/provider/sqlserver_features/mssql.rb' + - 'lib/puppet/provider/sqlserver_instance/mssql.rb' + - 'lib/puppet/provider/sqlserver_tsql/mssql.rb' + - 'lib/puppet/type/sqlserver_instance.rb' + - 'lib/puppet/type/sqlserver_tsql.rb' + - 'lib/puppet_x/sqlserver/sql_connection.rb' + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' + - 'spec/unit/puppet/sqlserver_spec_helper.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowedMethods. +# AllowedMethods: nonzero? +Style/IfWithBooleanLiteralBranches: + Exclude: + - 'lib/puppet_x/sqlserver/server_helper.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'spec/spec_helper.rb' + # Offense count: 1 -# Cop supports --auto-correct. +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/puppet/type/sqlserver_instance.rb' + +# Offense count: 3 +# Configuration parameters: AllowedMethods. +# AllowedMethods: respond_to_missing? +Style/OptionalBooleanParameter: + Exclude: + - 'lib/puppet/provider/sqlserver_instance/mssql.rb' + - 'lib/puppet/type/sqlserver_tsql.rb' + - 'spec/defines/manifest_shared_examples.rb' + +# Offense count: 28 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantRegexpEscape: + Exclude: + - 'lib/puppet/parser/functions/sqlserver_validate_instance_name.rb' + - 'lib/puppet/type/sqlserver_instance.rb' + - 'spec/defines/database_spec.rb' + - 'spec/unit/puppet/property/tsql_spec.rb' + +# Offense count: 2 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantSelfAssignmentBranch: + Exclude: + - 'spec/acceptance/sqlserver_instance_spec.rb' + - 'spec/acceptance/z_last_sqlserver_features_spec.rb' + +# Offense count: 16 +# This cop supports safe autocorrection (--autocorrect). +Style/RedundantStringEscape: + Exclude: + - 'spec/spec_helper_acceptance_local.rb' + - 'spec/sql_testing_helpers.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Exclude: - 'spec/defines/user_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: implicit, explicit +Style/RescueStandardError: + Exclude: + - 'lib/puppet_x/sqlserver/features.rb' + - 'spec/spec_helper.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowModifier. +Style/SoleNestedConditional: + Exclude: + - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' + - 'lib/puppet/provider/sqlserver.rb' + - 'spec/spec_helper_acceptance_local.rb' + +# Offense count: 34 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: Mode. +Style/StringConcatenation: + Exclude: + - 'spec/acceptance/sqlserver_config_spec.rb' + - 'spec/acceptance/sqlserver_database_spec.rb' + - 'spec/acceptance/sqlserver_instance_spec.rb' + - 'spec/acceptance/sqlserver_login_spec.rb' + - 'spec/acceptance/sqlserver_role_spec.rb' + - 'spec/acceptance/sqlserver_tsql_spec.rb' + - 'spec/acceptance/sqlserver_user_spec.rb' + - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyle, AllowSafeAssignment. +# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex +Style/TernaryParentheses: + Exclude: + - 'lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb' + +# Offense count: 88 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: EnforcedStyleForMultiline. +# SupportedStylesForMultiline: comma, consistent_comma, no_comma +Style/TrailingCommaInHashLiteral: + Enabled: false diff --git a/Gemfile b/Gemfile index 952b2bd2..2f7e2ff7 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ group :development do 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 "rubocop", '= 1.48.1', require: false + gem "rubocop-performance", '= 1.16.0', require: false + gem "rubocop-rspec", '= 2.19.0', require: false gem "rb-readline", '= 0.5.5', require: false, platforms: [:mswin, :mingw, :x64_mingw] gem "ruby-pwsh", require: false gem "github_changelog_generator", '= 1.15.2', require: false From 10f931f8e03f819913d66672280246f444e88fd9 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 09:54:03 +0100 Subject: [PATCH 05/51] (CONT-800) Rubocop Manual Fix 1 - Lint/RedundantCopEnableDirective --- .rubocop_todo.yml | 19 +------------------ spec/acceptance/sqlserver_database_spec.rb | 1 - spec/acceptance/sqlserver_instance_spec.rb | 1 - spec/acceptance/sqlserver_login_spec.rb | 1 - spec/acceptance/sqlserver_role_spec.rb | 1 - spec/acceptance/sqlserver_tsql_spec.rb | 1 - spec/acceptance/sqlserver_user_spec.rb | 1 - spec/defines/role/permissions_spec.rb | 1 - spec/defines/role_spec.rb | 3 --- .../provider/sqlserver_features_spec.rb | 1 - .../provider/sqlserver_instance_spec.rb | 1 - .../puppet/provider/sqlserver_tsql_spec.rb | 1 - spec/unit/puppet_x/sql_connection_spec.rb | 2 -- 13 files changed, 1 insertion(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b5f295df..4d0a51ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-04-24 08:47:50 UTC using RuboCop version 1.48.1. +# on 2023-04-24 08:53:48 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 @@ -117,23 +117,6 @@ Lint/RedundantCopDisableDirective: Exclude: - 'lib/puppet_x/sqlserver/server_helper.rb' -# Offense count: 15 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopEnableDirective: - Exclude: - - 'spec/acceptance/sqlserver_database_spec.rb' - - 'spec/acceptance/sqlserver_instance_spec.rb' - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/acceptance/sqlserver_role_spec.rb' - - 'spec/acceptance/sqlserver_tsql_spec.rb' - - 'spec/acceptance/sqlserver_user_spec.rb' - - 'spec/defines/role/permissions_spec.rb' - - 'spec/defines/role_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' - - 'spec/unit/puppet_x/sql_connection_spec.rb' - # Offense count: 3 # Configuration parameters: AllowComments, AllowNil. Lint/SuppressedException: diff --git a/spec/acceptance/sqlserver_database_spec.rb b/spec/acceptance/sqlserver_database_spec.rb index a49bc6d2..7c1f94b0 100644 --- a/spec/acceptance/sqlserver_database_spec.rb +++ b/spec/acceptance/sqlserver_database_spec.rb @@ -298,7 +298,6 @@ def run_sql_query_opts(query, expected_row_count) AND default_language_lcid = '1028';" run_sql_query(run_sql_query_opts(query, 1)) - # rubocop:enable RSpec/InstanceVariable end end end diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index b9e25369..81935e73 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -99,7 +99,6 @@ def sql_query_is_user_sysadmin(username) it "#{inst_name} instance has ExtraSQLAdmin as a sysadmin" do run_sql_query(run_sql_query_opts(inst_name, sql_query_is_user_sysadmin(@extra_admin_user), 1)) end - # rubocop:enable RSpec/InstanceVariable it "remove #{inst_name} instance" do ensure_sqlserver_instance(features, inst_name, 'absent') diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index 992901e4..a499734b 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -351,7 +351,6 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) query = "SELECT principal_id FROM SYS.server_principals WHERE name = '#{@login_under_test}' AND [type] = '#{@sql_principal_type}'" run_sql_query(run_sql_query_opts_as_sa(query, 0)) end - # rubocop:enable RSpec/InstanceVariable end end end diff --git a/spec/acceptance/sqlserver_role_spec.rb b/spec/acceptance/sqlserver_role_spec.rb index b05da34b..ad122b3c 100644 --- a/spec/acceptance/sqlserver_role_spec.rb +++ b/spec/acceptance/sqlserver_role_spec.rb @@ -255,7 +255,6 @@ def ensure_sqlserver_logins_users(db_name) OR spr.name = '#{LOGIN3}';" run_sql_query(query: query, server: hostname, expected_row_count: 1) - # rubocop:enable RSpec/InstanceVariable end end end diff --git a/spec/acceptance/sqlserver_tsql_spec.rb b/spec/acceptance/sqlserver_tsql_spec.rb index 14967388..d578dc96 100644 --- a/spec/acceptance/sqlserver_tsql_spec.rb +++ b/spec/acceptance/sqlserver_tsql_spec.rb @@ -225,7 +225,6 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') command => "CREATE TABLE #{@table_name} (id INT, name VARCHAR(20), email VARCHAR(20));", } MANIFEST - # rubocop:enable RSpec/InstanceVariable apply_manifest(pp, expect_failures: true) end end diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index 4ea795c9..c166eb56 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -200,7 +200,6 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') # validate that the database user '#{@db_user}' should be deleted: query = "USE #{db_name}; SELECT * FROM SYS.DATABASE_PRINCIPALS WHERE name = '#{@db_user}';" run_sql_query(query: query, server: hostname, expected_row_count: 0) - # rubocop:enable RSpec/InstanceVariable end end end diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index 67d4a3d1..6d11b55b 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -61,7 +61,6 @@ 'GRANT DELETE TO [myCustomRole];', 'GRANT SELECT TO [myCustomRole];', ] - # rubocop:enable Layout/IndentArray let(:should_contain_command) { base_commands + should_commands } let(:should_contain_onlyif) { base_commands } diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index e19f4343..fd051ace 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -261,11 +261,8 @@ ] end - # rubocop:enable Style/RegexpLiteral it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end end - # rubocop:enable RSpec/EmptyLineAfterFinalLet - # rubocop:enable Layout/IndentArray end diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index f0af0856..00540668 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -171,6 +171,5 @@ let(:feature_add) { ['BC', 'IS', 'SSMS'] } it_behaves_like 'features=', @feature_params - # rubocop:enable RSpec/InstanceVariable end end diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index 2378cd0e..61086f4d 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -310,7 +310,6 @@ def stub_uninstall(args, installed_features, exit_code = 0) args = basic_args args[:install_switches] = { 'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup' } let(:additional_install_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] } - # rubocop:enable RSpec/InstanceVariable let(:args) { args } munged = { features: Array.new(args[:features]) } munged[:features].delete('SQL') diff --git a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb index d82448fb..68de4f6e 100644 --- a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb @@ -81,7 +81,6 @@ def gen_query(query) stub_get_instance_config(config) stub_open_and_run('fozy wozy', config.merge(database: 'myDb')) @provider.run(gen_query('fozy wozy')) - # rubocop:enable RSpec/InstanceVariable } end end diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index e685715f..39e134ea 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -139,10 +139,8 @@ def stub_connection stub_connection err_message = 'ConnectionFailed' allow(@connection).to receive(:Open).and_raise(Exception.new(err_message)) - # rubocop:enable RSpec/InstanceVariable expect { result = subject.open_and_run_command('whacka whacka whacka', config) - # rubocop:enable RSpec/NamedSubject expect(result.exitstatus).to eq(1) expect(result.error_message).to eq 'ConnectionFailed' }.not_to raise_error(Exception) From 1f073be281684db79adbc805aca423d6a167e2a5 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 10:02:00 +0100 Subject: [PATCH 06/51] (CONT-800) Disable .rubocop.yml rule to prevent interaction with .rubocop-todo.yml --- .rubocop.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2dbf4503..3185fa98 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -84,7 +84,7 @@ Style/Documentation: - spec/**/* Style/WordArray: EnforcedStyle: brackets -RSpec/MultipleExpectations: - Max: 3 +# RSpec/MultipleExpectations: +# Max: 3 Naming/MethodParameterName: AllowedNames: 'is' From 3a5f9fc6bdc6098394faa6c53ca7d3ec68956321 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 10:16:45 +0100 Subject: [PATCH 07/51] (CONT-800) Set Rubocop to 2.6 Ruby --- .rubocop.yml | 2 +- .sync.yml | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 3185fa98..e365cd83 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,7 +9,7 @@ AllCops: DisplayCopNames: true ExtraDetails: true DisplayStyleGuide: true - TargetRubyVersion: '2.7' + TargetRubyVersion: '2.6' Include: - "**/*.rb" Exclude: diff --git a/.sync.yml b/.sync.yml index 505552ce..9a7be77a 100644 --- a/.sync.yml +++ b/.sync.yml @@ -33,3 +33,5 @@ spec/spec_helper.rb: unmanaged: false .travis.yml: delete: true +.rubocop.yml: + unmanaged: true From 6b91257e76894222830da6094d2e8a3d26961761 Mon Sep 17 00:00:00 2001 From: david22swan Date: Mon, 24 Apr 2023 10:40:39 +0100 Subject: [PATCH 08/51] (CONT-800) Unit Test Fix --- spec/unit/puppet/provider/sqlserver_features_spec.rb | 2 +- spec/unit/puppet/provider/sqlserver_instance_spec.rb | 6 +++--- spec/unit/puppet/sqlserver_spec_helper.rb | 2 +- spec/unit/puppet_x/sql_connection_spec.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index 00540668..fb95ddcb 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -157,7 +157,7 @@ '/ACTION=uninstall', '/Q', '/IACCEPTSQLSERVERLICENSETERMS', - "/FEATURES=#{['SSMS', 'ADV_SSMS', 'Conn'].join(',')}"], failonfail: false + "/FEATURES=#{['SSMS', 'ADV_SSMS', 'Conn'].join(',')}"], { failonfail: false } ).and_return(result) @provider.create } diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index 61086f4d..28f645a4 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -40,7 +40,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) "/FEATURES=#{installed_features.join(',')}"] result = Puppet::Util::Execution::ProcessOutput.new('', exit_code) - allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, failonfail: false).and_return(result) + allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, { failonfail: false }).and_return(result) end shared_examples 'create' do |exit_code, warning_matcher| @@ -78,7 +78,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) allow(@provider).to receive(:warn).with(anything) unless warning_matcher result = Puppet::Util::Execution::ProcessOutput.new('', exit_code || 0) - allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, failonfail: false).and_return(result) + allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, { failonfail: false }).and_return(result) @provider.create } end @@ -117,7 +117,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) allow(@provider).to receive(:warn).with(anything) result = Puppet::Util::Execution::ProcessOutput.new('', exit_code || 0) - allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, failonfail: false).and_return(result) + allow(Puppet::Util::Execution).to receive(:execute).with(cmd_args.compact, { failonfail: false }).and_return(result) expect { @provider.create }.to raise_error(error_matcher) } end diff --git a/spec/unit/puppet/sqlserver_spec_helper.rb b/spec/unit/puppet/sqlserver_spec_helper.rb index 564ceb6a..786217cd 100644 --- a/spec/unit/puppet/sqlserver_spec_helper.rb +++ b/spec/unit/puppet/sqlserver_spec_helper.rb @@ -34,5 +34,5 @@ def stub_modify_features(action, args, features, additional_switches = [], exit_ result = Puppet::Util::Execution::ProcessOutput.new('', exit_code) - allow(Puppet::Util::Execution).to receive(:execute).with(cmds, failonfail: false).and_return(result) + allow(Puppet::Util::Execution).to receive(:execute).with(cmds, { failonfail: false }).and_return(result) end diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index 39e134ea..f420d1ae 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -126,7 +126,7 @@ def stub_connection allow(@connection.Errors).to receive(:count).and_return(1) allow(@connection.Errors).to receive(:Description).and_return('SQL Error in Connection') allow(@connection).to receive(:Execute).and_raise(Exception) - expect(subject).to receive(:open).with(admin_user: 'sa', admin_pass: 'Pupp3t1@', instance_name: 'MSSQLSERVER') + expect(subject).to receive(:open).with({ admin_user: 'sa', admin_pass: 'Pupp3t1@', instance_name: 'MSSQLSERVER' }) expect(subject).to receive(:close).once result = subject.open_and_run_command('SELECT * FROM sys.databases', config) From ff684730e51548574edbdbb7a705dfd38cd71756 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:49:34 +0100 Subject: [PATCH 09/51] (CONT-800) - Correct Layout/ArgumentAlignment --- .rubocop_todo.yml | 16 ---------------- spec/acceptance/sqlserver_config_spec.rb | 2 +- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4d0a51ed..d5207ada 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,19 +1,3 @@ -# This configuration was generated by -# `rubocop --auto-gen-config` -# on 2023-04-24 08:53:48 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: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, IndentationWidth. -# SupportedStyles: with_first_argument, with_fixed_indentation -Layout/ArgumentAlignment: - Exclude: - - 'spec/acceptance/sqlserver_config_spec.rb' - # Offense count: 15 # This cop supports safe autocorrection (--autocorrect). Layout/ClosingHeredocIndentation: diff --git a/spec/acceptance/sqlserver_config_spec.rb b/spec/acceptance/sqlserver_config_spec.rb index 8768be73..ce6a1270 100644 --- a/spec/acceptance/sqlserver_config_spec.rb +++ b/spec/acceptance/sqlserver_config_spec.rb @@ -81,7 +81,7 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present') query = "USE #{db_name}; SELECT * from master..sysdatabases WHERE name = '#{db_name}'" run_sql_query(query: query, server: hostname, instance: inst_name, \ - sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, expected_row_count: 1) + sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, expected_row_count: 1) end it 'Validate New Config WITHOUT using instance_name in sqlserver::config' do From bb2e9ff8b3a75ac4428428a0fec28148636e6809 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:49:57 +0100 Subject: [PATCH 10/51] (CONT-800) - Correct Layout/ClosingHeredocIndentation --- .rubocop_todo.yml | 17 ----------------- lib/puppet/provider/sqlserver.rb | 2 +- spec/acceptance/sqlserver_login_spec.rb | 2 +- spec/acceptance/sqlserver_user_spec.rb | 2 +- .../z_last_sqlserver_features_spec.rb | 2 +- spec/defines/database_spec.rb | 2 +- spec/defines/login/permissions_spec.rb | 4 ++-- spec/defines/login_spec.rb | 2 +- spec/defines/sp_configure_spec.rb | 2 +- spec/defines/user/permissions_spec.rb | 4 ++-- spec/defines/user_spec.rb | 2 +- spec/spec_helper_acceptance_local.rb | 2 +- spec/sql_testing_helpers.rb | 4 ++-- 13 files changed, 15 insertions(+), 32 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d5207ada..8ca121dc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,20 +1,3 @@ -# Offense count: 15 -# This cop supports safe autocorrection (--autocorrect). -Layout/ClosingHeredocIndentation: - Exclude: - - 'lib/puppet/provider/sqlserver.rb' - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/acceptance/sqlserver_user_spec.rb' - - 'spec/acceptance/z_last_sqlserver_features_spec.rb' - - 'spec/defines/database_spec.rb' - - 'spec/defines/login/permissions_spec.rb' - - 'spec/defines/login_spec.rb' - - 'spec/defines/sp_configure_spec.rb' - - 'spec/defines/user/permissions_spec.rb' - - 'spec/defines/user_spec.rb' - - 'spec/spec_helper_acceptance_local.rb' - - 'spec/sql_testing_helpers.rb' - # Offense count: 33 # This cop supports safe autocorrection (--autocorrect). Layout/EmptyLineAfterGuardClause: diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 9cf5f9bf..5e8a5428 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -79,7 +79,7 @@ def self.run_install_dot_net(source_location = nil) #exit 1 } } -DOTNET + DOTNET powershell([install_dot_net]) end end diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index a499734b..921a3ecb 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -73,7 +73,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) #{"disabled => #{options['disabled']}," unless options['disabled'].nil?} #{"ensure => '#{options['ensure']}'," unless options['ensure'].nil?} } - MANIFEST + MANIFEST end before(:all) do diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index c166eb56..bc7261eb 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -96,7 +96,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') user => '#{@db_user}', require => Sqlserver::Login['#{@db_user}'], } - MANIFEST + MANIFEST apply_manifest(pp, catch_failures: true) # validate that the database user '#{@db_user}' is successfully created: diff --git a/spec/acceptance/z_last_sqlserver_features_spec.rb b/spec/acceptance/z_last_sqlserver_features_spec.rb index 6c5bf20f..f73a0c85 100644 --- a/spec/acceptance/z_last_sqlserver_features_spec.rb +++ b/spec/acceptance/z_last_sqlserver_features_spec.rb @@ -181,7 +181,7 @@ def remove_sql_instance source => 'H:', sql_sysadmin_accounts => ['#{user}'], } - MANIFEST + MANIFEST idempotent_apply(pp) end diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index fde8594e..46a50549 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -17,7 +17,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end end diff --git a/spec/defines/login/permissions_spec.rb b/spec/defines/login/permissions_spec.rb index 8d3be4f3..6369be47 100644 --- a/spec/defines/login/permissions_spec.rb +++ b/spec/defines/login/permissions_spec.rb @@ -8,7 +8,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end context 'validation errors' do @@ -137,7 +137,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end it_behaves_like 'compile' diff --git a/spec/defines/login_spec.rb b/spec/defines/login_spec.rb index 0559ee61..7c4231d1 100644 --- a/spec/defines/login_spec.rb +++ b/spec/defines/login_spec.rb @@ -17,7 +17,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end end diff --git a/spec/defines/sp_configure_spec.rb b/spec/defines/sp_configure_spec.rb index 0b15e941..e8c9c185 100644 --- a/spec/defines/sp_configure_spec.rb +++ b/spec/defines/sp_configure_spec.rb @@ -17,7 +17,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end end describe 'basic usage' do diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index 0c1f5def..ca23e319 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -8,7 +8,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end context 'validation errors' do @@ -161,7 +161,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end let(:should_contain_command) { ['USE [loggingDb];'] } diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 858016fe..2ac8ad7d 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -12,7 +12,7 @@ <<-EOF define sqlserver::config{} sqlserver::config {'MSSQLSERVER': } - EOF + EOF end end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index eb68be52..6a0bc982 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -156,7 +156,7 @@ def install_sqlserver(features) }, windows_feature_source => 'I:\\sources\\sxs', } - MANIFEST + MANIFEST Helper.instance.apply_manifest(pp) end diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 79d215f6..73df8bda 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -44,7 +44,7 @@ def install_sqlserver(host, opts = {}) }, windows_feature_source => 'I:\\sources\\sxs', } - MANIFEST + MANIFEST apply_manifest_on(host, pp) end @@ -201,7 +201,7 @@ def install_pe_license(host) ##################### # End License File # ##################### -EOF + EOF create_remote_file(host, '/etc/puppetlabs/license.key', license) end From 756ba8b1bca7c543301ea7474f73229cc48d606a Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:50:21 +0100 Subject: [PATCH 11/51] (CONT-800) - Correct Layout/EmptyLineAfterGuardClause --- .rubocop_todo.yml | 5 ----- .../parser/functions/sqlserver_is_domain_or_local_user.rb | 1 + .../parser/functions/sqlserver_validate_instance_name.rb | 1 + lib/puppet/parser/functions/sqlserver_validate_range.rb | 1 + lib/puppet/parser/functions/sqlserver_validate_size.rb | 1 + lib/puppet/property/sqlserver_login.rb | 1 + lib/puppet/provider/sqlserver_features/mssql.rb | 2 ++ lib/puppet/provider/sqlserver_instance/mssql.rb | 3 +++ lib/puppet/type/sqlserver_features.rb | 2 ++ lib/puppet/type/sqlserver_instance.rb | 4 ++++ lib/puppet/type/sqlserver_tsql.rb | 1 + lib/puppet_x/sqlserver/features.rb | 4 ++++ lib/puppet_x/sqlserver/server_helper.rb | 3 +++ lib/puppet_x/sqlserver/sql_connection.rb | 2 ++ spec/defines/manifest_shared_examples.rb | 1 + spec/spec_helper_acceptance_local.rb | 3 +++ spec/sql_testing_helpers.rb | 3 +++ 17 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ca121dc..994459e9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,8 +1,3 @@ -# Offense count: 33 -# This cop supports safe autocorrection (--autocorrect). -Layout/EmptyLineAfterGuardClause: - Enabled: false - # Offense count: 46 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. diff --git a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb index dd78a1ed..55efae8a 100644 --- a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb +++ b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb @@ -7,6 +7,7 @@ module Puppet::Parser::Functions if args.length != 1 raise Puppet::ParseError, "is_domain_or_local_user(): requires exactly 1 argument, you provided #{args.length}" end + PuppetX::Sqlserver::ServerHelper.is_domain_or_local_user?(args[0], Facter.value(:hostname)) end end diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index ebb1341b..6194e5ed 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -19,6 +19,7 @@ module Puppet::Parser::Functions if args.length != 1 raise Puppet::ParseError, "mssql_validate_instance_name(): requires exactly 1 argument, you provided #{args.length}" end + value = args[0] errors = [] if value.empty? diff --git a/lib/puppet/parser/functions/sqlserver_validate_range.rb b/lib/puppet/parser/functions/sqlserver_validate_range.rb index f9d79429..6a67ee4d 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_range.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_range.rb @@ -5,6 +5,7 @@ module Puppet::Parser::Functions if (args.length < 3) || (args.length > 4) raise Puppet::ParseError, "validate_range(): wrong number of arguments (#{args.length}; must be 3)" end + values, lower, upper, msg = args values = [] << values unless values.is_a?(Array) diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index 8dc8929b..2e5d6fb7 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -5,6 +5,7 @@ module Puppet::Parser::Functions if args.length != 1 raise(Puppet::ParseError, "mssql_validate_size(): requires exactly 1 argument, you provided #{args.length}") end + value = args[0] match = %r{^(?\d+)(?KB|MB|GB|TB)$}.match(value) diff --git a/lib/puppet/property/sqlserver_login.rb b/lib/puppet/property/sqlserver_login.rb index a3bb692e..b8c69ad3 100644 --- a/lib/puppet/property/sqlserver_login.rb +++ b/lib/puppet/property/sqlserver_login.rb @@ -12,6 +12,7 @@ class Puppet::Property::SqlserverLogin < Puppet::Property # rubocop:disable Styl if %r{\\.*\\}.match?(value) raise 'More than one \ found, maximum of one for users is allowed' end + if %r{@}.match?(value) raise ArgumentError, _('@ sybmol is not allowed in the username, please follow the pattern of domain\login if you are attempting to add domain user') diff --git a/lib/puppet/provider/sqlserver_features/mssql.rb b/lib/puppet/provider/sqlserver_features/mssql.rb index cbcfb415..9748bd57 100644 --- a/lib/puppet/provider/sqlserver_features/mssql.rb +++ b/lib/puppet/provider/sqlserver_features/mssql.rb @@ -25,6 +25,7 @@ def self.instances featurelist = [] ALL_SQL_VERSIONS.each do |sql_version| next if result[sql_version].empty? + featurelist += result[sql_version] end @@ -58,6 +59,7 @@ def add_features(features) def modify_features(action, features) return unless not_nil_and_not_empty? features + debug "#{action.capitalize}ing features '#{features.join(',')}'" cmd_args = ["#{@resource[:source]}/setup.exe", "/ACTION=#{action}", diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index e3733915..76ae3e6f 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -62,6 +62,7 @@ def add_features(features) def modify_features(features, action) return unless not_nil_and_not_empty? features + debug "#{action.capitalize}ing features '#{features.join(',')}'" cmd_args, obfuscated_strings = build_cmd_args(features, action) @@ -152,6 +153,7 @@ def build_cmd_args(features, action = 'install') if action == 'install' RESOURCEKEY_TO_CMDARG.keys.sort.map do |key| next unless not_nil_and_not_empty? @resource[key] + cmd_args << "/#{RESOURCEKEY_TO_CMDARG[key]}=\"#{@resource[key.to_sym]}\"" if %r{(_pwd|_password)$}i.match?(key.to_s) obfuscated_strings.push(@resource[key]) @@ -166,6 +168,7 @@ def build_cmd_args(features, action = 'install') def format_cmd_args_array(switch, arr, cmd_args, use_discrete = false) return unless not_nil_and_not_empty? arr + arr = [arr] unless arr.is_a?(Array) # The default action is to join the array elements with a space ' ' so the cmd_args ends up like; diff --git a/lib/puppet/type/sqlserver_features.rb b/lib/puppet/type/sqlserver_features.rb index 3d87983b..6744e8b6 100644 --- a/lib/puppet/type/sqlserver_features.rb +++ b/lib/puppet/type/sqlserver_features.rb @@ -60,6 +60,7 @@ def validate # IS_SVC_ACCOUNT validation return unless set?(:features) && self[:features].include?('IS') return unless set?(:is_svc_account) || set?(:is_svc_password) + validate_user_password_required(:is_svc_account, :is_svc_password) end @@ -70,6 +71,7 @@ def domain_or_local_user?(user) def validate_user_password_required(account, pass) raise("User #{account} is required") unless set?(account) return unless domain_or_local_user?(self[account]) && self[pass].nil? + raise("#{pass} required when using domain account") end diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index ca80dbd9..28e9406f 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -132,6 +132,7 @@ def validate strong_password?(:rs_svc_password) end return unless self[:security_mode] == 'SQL' + strong_password?(:sa_pwd) end @@ -143,6 +144,7 @@ def validate_user_password_required(account, pass) # rubocop:disable Style/SignalException fail("User #{account} is required") unless set?(account) return unless domain_or_local_user?(self[account]) && self[pass].nil? + fail("#{pass} required when using domain account") # rubocop:enable Style/SignalException end @@ -154,6 +156,7 @@ def domain_or_local_user?(user) def strong_password?(key) password = self[key] return unless password + message_start = "Password for #{key} is not strong" failures = [] failures << 'must be at least 8 characters long' unless password.length >= 8 @@ -162,6 +165,7 @@ def strong_password?(key) failures << 'must contain numbers' unless %r{\d}.match?(password) failures << 'must contain a special character' unless %r{}.match?(password) fail("#{message_start}:\n#{failures.join("\n")}") if failures.count > 0 # rubocop:disable Style/SignalException + true end end diff --git a/lib/puppet/type/sqlserver_tsql.rb b/lib/puppet/type/sqlserver_tsql.rb index fe153cd7..a9467abb 100644 --- a/lib/puppet/type/sqlserver_tsql.rb +++ b/lib/puppet/type/sqlserver_tsql.rb @@ -116,6 +116,7 @@ def sync unless @output.exitstatus.to_s == '0' raise("#{resource[:command]} returned #{@output.exitstatus} instead of one of [#{should.join(',')}]") end + event end end diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 1cb249c8..479f3d0d 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -84,6 +84,7 @@ def self.get_sql_reg_val_features(key_name, reg_val_feat_hash) def self.get_reg_instance_info(friendly_version) instance_root = 'SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names' return [] unless key_exists?(instance_root) + discovered = {} open(HKLM, instance_root.to_s, KEY_READ | KEY64) do |registry| each_key(registry) do |instance_type, _| @@ -91,6 +92,7 @@ def self.get_reg_instance_info(friendly_version) each_value(instance) do |short_name, _, long_name| root = "Software\\Microsoft\\Microsoft SQL Server\\#{long_name}" next unless key_exists?("#{root}\\MSSQLServer\\CurrentVersion") + discovered[short_name] ||= { 'name' => short_name, 'reg_root' => [], @@ -215,6 +217,7 @@ def self.instances # by inspecting the major version of the instance_version instances.select! do |value| return true if value[1]['version'].nil? + ver = Gem::Version.new(value[1]['version']) # Segment 0 is the major version number of the SQL Instance ver.segments[0] == major_version @@ -260,6 +263,7 @@ def self.get_instance_info(version, sql_instance) # it's possible to request information for a valid instance_name but not for version. In this case # we just return nil. return nil if sql_instance['reg_root'].nil? + feats = [] sql_instance['reg_root'].each do |reg_root| feats += get_instance_features(reg_root, sql_instance['name']) diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index 26128485..85a2a73c 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -30,14 +30,17 @@ def self.sql_version_from_install_source(source_dir) # Attempt to read the Mediainfo.xml file in the root of the install media media_file = File.expand_path("#{source_dir}/MediaInfo.xml") return nil unless File.exist?(media_file) + # As we don't have a XML parser easily, just use simple text matching to find the following XML element. This # also means we can just ignore BOM markers etc. # content = File.read(media_file) index1 = content.index('"BaselineVersion"') return nil if index1.nil? + index2 = content.index('/>', index1) return nil if index2.nil? + content = content.slice(index1 + 18, index2 - index1 - 18) # Extract the version number from the text snippet # Value="xx.yyy.zz." diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index c35c86e2..c8420a08 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -45,11 +45,13 @@ def get_connection_string(config) # Windows based authentication raise ArgumentError, _('admin_user must be empty or nil') unless admin_user == '' raise ArgumentError, _('admin_pass must be empty or nil') unless admin_pass == '' + params.store('Integrated Security', 'SSPI') else # SQL Server based authentication raise ArgumentError, _('admin_user must not be empty or nil') unless admin_user != '' raise ArgumentError, _('admin_pass must not be empty or nil') unless admin_pass != '' + params.store('UID', admin_user) params.store('PWD', admin_pass) end diff --git a/spec/defines/manifest_shared_examples.rb b/spec/defines/manifest_shared_examples.rb index 9e4f7b6a..c145a74d 100644 --- a/spec/defines/manifest_shared_examples.rb +++ b/spec/defines/manifest_shared_examples.rb @@ -14,6 +14,7 @@ def convert_to_regexp(str) return str if str.is_a? Regexp + Regexp.new(Regexp.escape(str)) end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 6a0bc982..1c6febe5 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -191,11 +191,13 @@ def run_sql_query(opts = {}, &block) Helper.instance.run_shell("powershell -NonInteractive -NoLogo -File 'c:\\users\\#{USER}\\tmp.ps1'") do |r| match = %r{(\d*) rows affected}.match(r.stdout) raise 'Could not match number of rows for SQL query' unless match + rows_observed = match[1] error_message = "Expected #{opts[:expected_row_count]} rows but observed #{rows_observed}" raise error_message unless opts[:expected_row_count] == rows_observed.to_i end return unless block + case block.arity when 0 yield self @@ -215,6 +217,7 @@ def validate_sql_install(opts = {}, &block) cmd = "type \"#{bootstrap_dir}\\Log\\Summary.txt\"" result = Helper.instance.run_shell(cmd) return unless block + case block.arity when 0 yield self diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 73df8bda..7ec0d930 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -75,11 +75,13 @@ def run_sql_query(host, opts = {}, &block) on(host, 'powershell -NonInteractive -NoLogo -File "C:\\cygwin64\\home\\Administrator\\tmp.ps1"') do |r| match = %r{(\d*) rows affected}.match(r.stdout) raise 'Could not match number of rows for SQL query' unless match + rows_observed = match[1] error_message = "Expected #{opts[:expected_row_count]} rows but observed #{rows_observed}" raise error_message unless opts[:expected_row_count] == rows_observed.to_i end return unless block + case block.arity when 0 yield self @@ -145,6 +147,7 @@ def validate_sql_install(host, opts = {}, &block) cmd = "type \\\"#{bootstrap_dir}\\Log\\Summary.txt\\\"" result = on(host, "cmd.exe /c \"#{cmd}\"") return unless block + case block.arity when 0 yield self From da19ef56ef295687b9e99c64736a56cc1c7a12a4 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:50:53 +0100 Subject: [PATCH 12/51] (CONT-800) - Correct Layout/HashAlignment --- .rubocop_todo.yml | 16 ---------- lib/puppet/provider/sqlserver.rb | 14 ++++---- .../provider/sqlserver_instance/mssql.rb | 24 +++++++------- lib/puppet_x/sqlserver/features.rb | 32 +++++++++---------- lib/puppet_x/sqlserver/sql_connection.rb | 8 ++--- spec/defines/database_spec.rb | 2 +- .../provider/sqlserver_instance_spec.rb | 22 ++++++------- 7 files changed, 51 insertions(+), 67 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 994459e9..7c77ff57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,19 +1,3 @@ -# Offense count: 46 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowMultipleStyles, EnforcedHashRocketStyle, EnforcedColonStyle, EnforcedLastArgumentHashStyle. -# SupportedHashRocketStyles: key, separator, table -# SupportedColonStyles: key, separator, table -# SupportedLastArgumentHashStyles: always_inspect, always_ignore, ignore_implicit, ignore_explicit -Layout/HashAlignment: - Exclude: - - 'lib/puppet/provider/sqlserver.rb' - - 'lib/puppet/provider/sqlserver_instance/mssql.rb' - - 'lib/puppet_x/sqlserver/features.rb' - - 'lib/puppet_x/sqlserver/sql_connection.rb' - - 'spec/acceptance/sqlserver_config_spec.rb' - - 'spec/defines/database_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' - # Offense count: 4 # This cop supports safe autocorrection (--autocorrect). Layout/HeredocIndentation: diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 5e8a5428..099fd8f2 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -10,13 +10,13 @@ class Puppet::Provider::Sqlserver < Puppet::Provider # rubocop:disable Style/Doc initvars - commands powershell: if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") - "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" - elsif File.exist?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") - "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" - else - 'powershell.exe' - end + commands powershell: if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" + elsif File.exist?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" + else + 'powershell.exe' + end def try_execute(command, msg = nil, obfuscate_strings = nil, acceptable_exit_codes = [0]) command&.compact diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 76ae3e6f..b9318e00 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -8,19 +8,19 @@ Puppet::Type.type(:sqlserver_instance).provide(:mssql, parent: Puppet::Provider::Sqlserver) do desc 'SQLServer instance provider' RESOURCEKEY_TO_CMDARG = { - 'agt_svc_account' => 'AGTSVCACCOUNT', - 'agt_svc_password' => 'AGTSVCPASSWORD', - 'as_svc_account' => 'ASSVCACCOUNT', - 'as_svc_password' => 'ASSVCPASSWORD', - 'pid' => 'PID', - 'rs_svc_account' => 'RSSVCACCOUNT', - 'rs_svc_password' => 'RSSVCPASSWORD', - 'polybase_svc_account' => 'PBENGSVCACCOUNT', + 'agt_svc_account' => 'AGTSVCACCOUNT', + 'agt_svc_password' => 'AGTSVCPASSWORD', + 'as_svc_account' => 'ASSVCACCOUNT', + 'as_svc_password' => 'ASSVCPASSWORD', + 'pid' => 'PID', + 'rs_svc_account' => 'RSSVCACCOUNT', + 'rs_svc_password' => 'RSSVCPASSWORD', + 'polybase_svc_account' => 'PBENGSVCACCOUNT', 'polybase_svc_password' => 'PBDMSSVCPASSWORD', - 'sa_pwd' => 'SAPWD', - 'security_mode' => 'SECURITYMODE', - 'sql_svc_account' => 'SQLSVCACCOUNT', - 'sql_svc_password' => 'SQLSVCPASSWORD', + 'sa_pwd' => 'SAPWD', + 'security_mode' => 'SECURITYMODE', + 'sql_svc_account' => 'SQLSVCACCOUNT', + 'sql_svc_password' => 'SQLSVCPASSWORD', }.freeze def instance_reserved_switches diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 479f3d0d..7e03db42 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -124,11 +124,11 @@ def self.get_instance_features(reg_root, instance_name) # also reg Replication/IsInstalled set to 1 'SQL_Replication_Core_Inst' => 'Replication', # SQL Server Replication # also WMI: SqlService WHERE SQLServiceType = 1 # MSSQLSERVER - 'SQL_Engine_Core_Inst' => 'SQLEngine', # Database Engine Services - 'SQL_FullText_Adv' => 'FullText', # Full-Text and Semantic Extractions for Search - 'SQL_DQ_Full' => 'DQ', # Data Quality Services - 'sql_inst_mr' => 'ADVANCEDANALYTICS', # R Services (In-Database) - 'SQL_Polybase_Core_Inst' => 'POLYBASE', # PolyBase Query Service for External Data + 'SQL_Engine_Core_Inst' => 'SQLEngine', # Database Engine Services + 'SQL_FullText_Adv' => 'FullText', # Full-Text and Semantic Extractions for Search + 'SQL_DQ_Full' => 'DQ', # Data Quality Services + 'sql_inst_mr' => 'ADVANCEDANALYTICS', # R Services (In-Database) + 'SQL_Polybase_Core_Inst' => 'POLYBASE', # PolyBase Query Service for External Data } feat_root = "#{reg_root}\\ConfigurationState" @@ -154,20 +154,20 @@ def self.get_shared_features(version) shared_features = { # Client tools support removed with SQLServer 2022 # (ref https://learn.microsoft.com/en-us/sql/database-engine/install-windows/install-sql-server-on-server-core?view=sql-server-ver16#BK_SupportedFeatures) - 'Connectivity_Full' => 'Conn', # Client Tools Connectivity - 'SDK_Full' => 'SDK', # Client Tools SDK - 'MDSCoreFeature' => 'MDS', # Master Data Services - 'Tools_Legacy_Full' => 'BC', # Client Tools Backwards Compatibility - 'SQL_SSMS_Full' => 'ADV_SSMS', # Management Tools - Complete (Does not exist in SQL 2016+) - 'SQL_SSMS_Adv' => 'SSMS', # Management Tools - Basic (Does not exist in SQL 2016) - 'SQL_DQ_CLIENT_Full' => 'DQC', # Data Quality Client - 'SQL_BOL_Components' => 'BOL', # Documentation Components + 'Connectivity_Full' => 'Conn', # Client Tools Connectivity + 'SDK_Full' => 'SDK', # Client Tools SDK + 'MDSCoreFeature' => 'MDS', # Master Data Services + 'Tools_Legacy_Full' => 'BC', # Client Tools Backwards Compatibility + 'SQL_SSMS_Full' => 'ADV_SSMS', # Management Tools - Complete (Does not exist in SQL 2016+) + 'SQL_SSMS_Adv' => 'SSMS', # Management Tools - Basic (Does not exist in SQL 2016) + 'SQL_DQ_CLIENT_Full' => 'DQC', # Data Quality Client + 'SQL_BOL_Components' => 'BOL', # Documentation Components 'SQL_DReplay_Controller' => 'DREPLAY_CTLR', # Distributed Replay Controller - 'SQL_DReplay_Client' => 'DREPLAY_CLT', # Distributed Replay Client - 'sql_shared_mr' => 'SQL_SHARED_MR', # R Server (Standalone) + 'SQL_DReplay_Client' => 'DREPLAY_CLT', # Distributed Replay Client + 'sql_shared_mr' => 'SQL_SHARED_MR', # R Server (Standalone) # SQL Client Connectivity SDK (Installed by default) # also WMI: SqlService WHERE SQLServiceType = 4 # MsDtsServer - 'SQL_DTS_Full' => 'IS', # Integration Services + 'SQL_DTS_Full' => 'IS', # Integration Services # currently ignoring Reporting Services Shared # currently ignoring R Server Standalone } diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index c8420a08..41fc2a26 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -31,10 +31,10 @@ def open(config) def get_connection_string(config) params = { - 'Provider' => 'MSOLEDBSQL', - 'Initial Catalog' => config[:database] || 'master', - 'Application Name' => 'Puppet', - 'Data Source' => '.', + 'Provider' => 'MSOLEDBSQL', + 'Initial Catalog' => config[:database] || 'master', + 'Application Name' => 'Puppet', + 'Data Source' => '.', 'DataTypeComptibility' => 80, } diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index 46a50549..5df2b0ab 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -43,7 +43,7 @@ let(:additional_params) do { filespec_filename: 'c:/test/test.mdf', - filespec_name: 'OMGthisISsoReallyLongAndBoringProcessImeanAReallyOMGthisISsoReallyLongAndBoringProcessMakeItOMGthisISsoReallyLongAndBoringProcess', + filespec_name: 'OMGthisISsoReallyLongAndBoringProcessImeanAReallyOMGthisISsoReallyLongAndBoringProcessMakeItOMGthisISsoReallyLongAndBoringProcess', } end let(:raise_error_check) { "'filespec_name' expects" } diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index 28f645a4..ffaa9c00 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -16,18 +16,18 @@ let(:resourcekey_to_cmdarg) do { 'agt_svc_account' => 'AGTSVCACCOUNT', - 'agt_svc_password' => 'AGTSVCPASSWORD', - 'as_svc_account' => 'ASSVCACCOUNT', - 'as_svc_password' => 'ASSVCPASSWORD', - 'pid' => 'PID', - 'rs_svc_account' => 'RSSVCACCOUNT', - 'rs_svc_password' => 'RSSVCPASSWORD', - 'polybase_svc_account' => 'PBENGSVCACCOUNT', + 'agt_svc_password' => 'AGTSVCPASSWORD', + 'as_svc_account' => 'ASSVCACCOUNT', + 'as_svc_password' => 'ASSVCPASSWORD', + 'pid' => 'PID', + 'rs_svc_account' => 'RSSVCACCOUNT', + 'rs_svc_password' => 'RSSVCPASSWORD', + 'polybase_svc_account' => 'PBENGSVCACCOUNT', 'polybase_svc_password' => 'PBDMSSVCPASSWORD', - 'sa_pwd' => 'SAPWD', - 'security_mode' => 'SECURITYMODE', - 'sql_svc_account' => 'SQLSVCACCOUNT', - 'sql_svc_password' => 'SQLSVCPASSWORD', + 'sa_pwd' => 'SAPWD', + 'security_mode' => 'SECURITYMODE', + 'sql_svc_account' => 'SQLSVCACCOUNT', + 'sql_svc_password' => 'SQLSVCPASSWORD', } end From 0f3dd8cc736b5529eac3f291551349003109ffb6 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:51:18 +0100 Subject: [PATCH 13/51] (CONT-800) - Correct Layout/HeredocIndentation --- .rubocop_todo.yml | 9 ---- lib/puppet/property/sqlserver_tsql.rb | 24 +++++----- lib/puppet/provider/sqlserver.rb | 48 +++++++++---------- spec/sql_testing_helpers.rb | 24 +++++----- .../puppet/provider/sqlserver_tsql_spec.rb | 22 ++++----- 5 files changed, 59 insertions(+), 68 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7c77ff57..b1cf7b9b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,12 +1,3 @@ -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -Layout/HeredocIndentation: - Exclude: - - 'lib/puppet/property/sqlserver_tsql.rb' - - 'lib/puppet/provider/sqlserver.rb' - - 'spec/sql_testing_helpers.rb' - - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Layout/SpaceAroundMethodCallOperator: diff --git a/lib/puppet/property/sqlserver_tsql.rb b/lib/puppet/property/sqlserver_tsql.rb index 1bd7586a..98b7ce20 100644 --- a/lib/puppet/property/sqlserver_tsql.rb +++ b/lib/puppet/property/sqlserver_tsql.rb @@ -6,18 +6,18 @@ class Puppet::Property::SqlserverTsql < Puppet::Property # rubocop:disable Style desc 'TSQL property that we are going to wrap with a try catch' munge do |value| quoted_value = value.gsub('\'', '\'\'') - erb_template = <<-TEMPLATE -BEGIN TRY - SET NOCOUNT ON - DECLARE @sql_text as NVARCHAR(max); - SET @sql_text = N'#{quoted_value}' - EXECUTE sp_executesql @sql_text; -END TRY -BEGIN CATCH - DECLARE @msg as VARCHAR(max); - SELECT @msg = 'THROW CAUGHT: ' + ERROR_MESSAGE(); - THROW 51000, @msg, 10 -END CATCH + erb_template = <<~TEMPLATE + BEGIN TRY + SET NOCOUNT ON + DECLARE @sql_text as NVARCHAR(max); + SET @sql_text = N'#{quoted_value}' + EXECUTE sp_executesql @sql_text; + END TRY + BEGIN CATCH + DECLARE @msg as VARCHAR(max); + SELECT @msg = 'THROW CAUGHT: ' + ERROR_MESSAGE(); + THROW 51000, @msg, 10 + END CATCH TEMPLATE erb_template end diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 099fd8f2..612e8ab8 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -55,30 +55,30 @@ def self.run_install_dot_net(source_location = nil) warn("The specified windows_source_location directory for sqlserver of \"#{source_location}\" does not exist") unless Puppet::FileSystem.directory?(source_location) end - install_dot_net = <<-DOTNET -$Result = Dism /online /Get-featureinfo /featurename:NetFx3 -If($Result -contains "State : Enabled") -{ - Write-Host ".Net Framework 3.5 is already installed." -} -Else -{ - Write-Host "Installing .Net Framework 3.5, do not close this prompt..." - $InstallResult = DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /NoRestart /Quiet /LimitAccess #{"/Source:\"#{source_location}\"" unless source_location.nil?} - $Result = Dism /online /Get-featureinfo /featurename:NetFx3 - If($Result -contains "State : Enabled") - { - Write-Host "Install .Net Framework 3.5 successfully." - } - Else - { - Write-Host "Failed to install Install .Net Framework 3.5#{', please make sure the windows_feature_source is correct' unless source_location.nil?}." - Write-Host "DISM Install Result" - Write-Host "-----------" - Write-Host ($InstallResult -join "`n") - #exit 1 - } -} + install_dot_net = <<~DOTNET + $Result = Dism /online /Get-featureinfo /featurename:NetFx3 + If($Result -contains "State : Enabled") + { + Write-Host ".Net Framework 3.5 is already installed." + } + Else + { + Write-Host "Installing .Net Framework 3.5, do not close this prompt..." + $InstallResult = DISM /Online /Enable-Feature /FeatureName:NetFx3 /All /NoRestart /Quiet /LimitAccess #{"/Source:\"#{source_location}\"" unless source_location.nil?} + $Result = Dism /online /Get-featureinfo /featurename:NetFx3 + If($Result -contains "State : Enabled") + { + Write-Host "Install .Net Framework 3.5 successfully." + } + Else + { + Write-Host "Failed to install Install .Net Framework 3.5#{', please make sure the windows_feature_source is correct' unless source_location.nil?}." + Write-Host "DISM Install Result" + Write-Host "-----------" + Write-Host ($InstallResult -join "`n") + #exit 1 + } + } DOTNET powershell([install_dot_net]) end diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 7ec0d930..4a2f17c7 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -192,18 +192,18 @@ def get_install_paths(version) def install_pe_license(host) # Init - license = <<-EOF -####################### -# Begin License File # -####################### -# PUPPET ENTERPRISE LICENSE - Puppet Labs -to: qa -nodes: 100 -start: 2016-03-31 -end: 2026-03-31 -##################### -# End License File # -##################### + license = <<~EOF + ####################### + # Begin License File # + ####################### + # PUPPET ENTERPRISE LICENSE - Puppet Labs + to: qa + nodes: 100 + start: 2016-03-31 + end: 2026-03-31 + ##################### + # End License File # + ##################### EOF create_remote_file(host, '/etc/puppetlabs/license.key', license) diff --git a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb index 68de4f6e..5cb88190 100644 --- a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb @@ -25,17 +25,17 @@ def stub_get_instance_config(config) def gen_query(query) quoted_query = query.gsub('\'', '\'\'') - <<-PP -BEGIN TRY - DECLARE @sql_text as NVARCHAR(max); - SET @sql_text = N'#{quoted_query}' - EXECUTE sp_executesql @sql_text; -END TRY -BEGIN CATCH - DECLARE @msg as VARCHAR(max); - SELECT @msg = 'THROW CAUGHT: ' + ERROR_MESSAGE(); - THROW 51000, @msg, 10 -END CATCH + <<~PP + BEGIN TRY + DECLARE @sql_text as NVARCHAR(max); + SET @sql_text = N'#{quoted_query}' + EXECUTE sp_executesql @sql_text; + END TRY + BEGIN CATCH + DECLARE @msg as VARCHAR(max); + SELECT @msg = 'THROW CAUGHT: ' + ERROR_MESSAGE(); + THROW 51000, @msg, 10 + END CATCH PP end From 8a1b360f04b582783bce55748f2c6bd04f1e26c4 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:51:42 +0100 Subject: [PATCH 14/51] (CONT-800) - Correct Layout/SpaceAroundMethodCallOperator --- .rubocop_todo.yml | 6 ------ spec/acceptance/z_last_sqlserver_features_spec.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b1cf7b9b..b9921f2f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,9 +1,3 @@ -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Layout/SpaceAroundMethodCallOperator: - Exclude: - - 'spec/acceptance/z_last_sqlserver_features_spec.rb' - # Offense count: 2 # Configuration parameters: AllowedMethods. # AllowedMethods: enums diff --git a/spec/acceptance/z_last_sqlserver_features_spec.rb b/spec/acceptance/z_last_sqlserver_features_spec.rb index f73a0c85..51617077 100644 --- a/spec/acceptance/z_last_sqlserver_features_spec.rb +++ b/spec/acceptance/z_last_sqlserver_features_spec.rb @@ -156,7 +156,7 @@ def bind_and_apply_failing_manifest(features, ensure_val = 'present') end it 'fails when ADV_SSMS is supplied but SSMS is not - FM-2712', unless: version.to_i >= 2016 do - pending('error not shown on Sql Server 2014') if version .to_i == 2014 + pending('error not shown on Sql Server 2014') if version.to_i == 2014 features = ['BC', 'Conn', 'ADV_SSMS', 'SDK'] bind_and_apply_failing_manifest(features) end From 7ef51bd485a3c07ecaa9c0e8ca58583ba8d04f2a Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:52:36 +0100 Subject: [PATCH 15/51] (CONT-800) - Correct Lint/ConstantDefinitionInBlock --- .rubocop_todo.yml | 3 +- .../provider/sqlserver_instance/mssql.rb | 31 ++++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b9921f2f..7e829161 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,9 +1,8 @@ -# Offense count: 2 +# Offense count: 1 # Configuration parameters: AllowedMethods. # AllowedMethods: enums Lint/ConstantDefinitionInBlock: Exclude: - - 'lib/puppet/provider/sqlserver_instance/mssql.rb' - 'spec/functions/sqlserver_upcase_spec.rb' # Offense count: 3 diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index b9318e00..fcef7c93 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -5,23 +5,24 @@ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/server_helper')) require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'puppet_x/sqlserver/features')) +RESOURCEKEY_TO_CMDARG = { + 'agt_svc_account' => 'AGTSVCACCOUNT', + 'agt_svc_password' => 'AGTSVCPASSWORD', + 'as_svc_account' => 'ASSVCACCOUNT', + 'as_svc_password' => 'ASSVCPASSWORD', + 'pid' => 'PID', + 'rs_svc_account' => 'RSSVCACCOUNT', + 'rs_svc_password' => 'RSSVCPASSWORD', + 'polybase_svc_account' => 'PBENGSVCACCOUNT', + 'polybase_svc_password' => 'PBDMSSVCPASSWORD', + 'sa_pwd' => 'SAPWD', + 'security_mode' => 'SECURITYMODE', + 'sql_svc_account' => 'SQLSVCACCOUNT', + 'sql_svc_password' => 'SQLSVCPASSWORD', +}.freeze + Puppet::Type.type(:sqlserver_instance).provide(:mssql, parent: Puppet::Provider::Sqlserver) do desc 'SQLServer instance provider' - RESOURCEKEY_TO_CMDARG = { - 'agt_svc_account' => 'AGTSVCACCOUNT', - 'agt_svc_password' => 'AGTSVCPASSWORD', - 'as_svc_account' => 'ASSVCACCOUNT', - 'as_svc_password' => 'ASSVCPASSWORD', - 'pid' => 'PID', - 'rs_svc_account' => 'RSSVCACCOUNT', - 'rs_svc_password' => 'RSSVCPASSWORD', - 'polybase_svc_account' => 'PBENGSVCACCOUNT', - 'polybase_svc_password' => 'PBDMSSVCPASSWORD', - 'sa_pwd' => 'SAPWD', - 'security_mode' => 'SECURITYMODE', - 'sql_svc_account' => 'SQLSVCACCOUNT', - 'sql_svc_password' => 'SQLSVCPASSWORD', - }.freeze def instance_reserved_switches # List of all puppet managed install switches From 428c5da68dfaf9a895d10fd4444902a19b123f26 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:56:28 +0100 Subject: [PATCH 16/51] (CONT-800) - Correct Lint/DuplicateRegexpCharacterClassElement --- .rubocop_todo.yml | 14 -------------- lib/puppet/type/sqlserver_tsql.rb | 2 +- 2 files changed, 1 insertion(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7e829161..6bee6625 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,20 +5,6 @@ Lint/ConstantDefinitionInBlock: Exclude: - 'spec/functions/sqlserver_upcase_spec.rb' -# Offense count: 3 -# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. -Lint/DuplicateBranch: - Exclude: - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/spec_helper_acceptance_local.rb' - - 'spec/sql_testing_helpers.rb' - -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/DuplicateRegexpCharacterClassElement: - Exclude: - - 'lib/puppet/type/sqlserver_tsql.rb' - # Offense count: 7 # Configuration parameters: AllowComments, AllowEmptyLambdas. Lint/EmptyBlock: diff --git a/lib/puppet/type/sqlserver_tsql.rb b/lib/puppet/type/sqlserver_tsql.rb index a9467abb..0f24c81b 100644 --- a/lib/puppet/type/sqlserver_tsql.rb +++ b/lib/puppet/type/sqlserver_tsql.rb @@ -35,7 +35,7 @@ def self.checks desc 'initial database to connect to during query execution' defaultto 'master' validate do |value| - raise("Invalid database name #{value}") unless %r{^[[:word:]|#|@]+}.match?(value) + raise("Invalid database name #{value}") unless %r{^[[:word:]|#@]+}.match?(value) end end From b6f3007facef6dd1f9d52d5a9bf186c74dd91568 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:57:35 +0100 Subject: [PATCH 17/51] (CONT-800) - Correct Lint/DuplicateBranch --- spec/acceptance/sqlserver_login_spec.rb | 4 +--- spec/spec_helper_acceptance_local.rb | 4 +--- spec/sql_testing_helpers.rb | 4 +--- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index 921a3ecb..e401f7a2 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -48,9 +48,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) case testcase when 'SQL_LOGIN user' login_type = 'SQL_LOGIN' - when 'WINDOWS_LOGIN user' - login_type = 'WINDOWS_LOGIN' - when 'WINDOWS_LOGIN group' + when 'WINDOWS_LOGIN user', 'WINDOWS_LOGIN group' login_type = 'WINDOWS_LOGIN' else raise "Unknown testcase name #{testcase}" diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 1c6febe5..2103a38a 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -233,12 +233,10 @@ def get_install_paths(version) dir = "C://Program Files/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap" sql_directory = case version - when '2022' + when '2022', '2017' "SQL#{version}" when '2019' "SQL#{version}CTP2.4" - when '2017' - "SQL#{version}" else "SQLServer#{version}" end diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 4a2f17c7..2f3e7753 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -177,12 +177,10 @@ def get_install_paths(version) dir = "C://Program Files/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap" sql_directory = case version - when '2022' + when '2022', '2017' "SQL#{version}" when '2019' "SQL#{version}CTP2.4" - when '2017' - "SQL#{version}" else "SQLServer#{version}" end From 3d3ad2ff8530209368d8f6b99ccb93b56f39a4cf Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 10:58:27 +0100 Subject: [PATCH 18/51] (CONT-800) - Correct Lint/EmptyConditionalBody --- .rubocop_todo.yml | 7 ------- lib/puppet/parser/functions/sqlserver_validate_range.rb | 3 +-- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6bee6625..2a0d099e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,13 +14,6 @@ Lint/EmptyBlock: - 'spec/defines/manifest_shared_examples.rb' - 'spec/functions/functions_shared_examples.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowComments. -Lint/EmptyConditionalBody: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_validate_range.rb' - # Offense count: 10 # This cop supports unsafe autocorrection (--autocorrect-all). Lint/OrAssignmentToConstant: diff --git a/lib/puppet/parser/functions/sqlserver_validate_range.rb b/lib/puppet/parser/functions/sqlserver_validate_range.rb index 6a67ee4d..48f9e776 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_range.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_range.rb @@ -12,8 +12,7 @@ module Puppet::Parser::Functions values.each do |value| msg ||= "validate_range(): #{args[0].inspect} is not between #{args[1].inspect} and #{args[2].inspect}" - if value.is_a? Numeric - elsif %r{^\d+(|\.\d+)$}.match?(value) + if %r{^\d+(|\.\d+)$}.match?(value) raise(Puppet::ParseError, msg) unless Float(value).between?(Float(lower), Float(upper)) else value.strip! From f04b1667530831751b3d8ad6207b7cd9ffcfbbe6 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:00:21 +0100 Subject: [PATCH 19/51] (CONT-800) - Correct Lint/OrAssignmentToConstant --- .rubocop_todo.yml | 6 ------ lib/puppet_x/sqlserver/features.rb | 20 ++++++++++---------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2a0d099e..f03d2b64 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,12 +14,6 @@ Lint/EmptyBlock: - 'spec/defines/manifest_shared_examples.rb' - 'spec/functions/functions_shared_examples.rb' -# Offense count: 10 -# This cop supports unsafe autocorrection (--autocorrect-all). -Lint/OrAssignmentToConstant: - Exclude: - - 'lib/puppet_x/sqlserver/features.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). Lint/RedundantCopDisableDirective: diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 7e03db42..a178ec17 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -2,14 +2,14 @@ require 'puppet/util/windows' -SQL_2012 ||= 'SQL_2012' -SQL_2014 ||= 'SQL_2014' -SQL_2016 ||= 'SQL_2016' -SQL_2017 ||= 'SQL_2017' -SQL_2019 ||= 'SQL_2019' -SQL_2022 ||= 'SQL_2022' +SQL_2012 = 'SQL_2012' +SQL_2014 = 'SQL_2014' +SQL_2016 = 'SQL_2016' +SQL_2017 = 'SQL_2017' +SQL_2019 = 'SQL_2019' +SQL_2022 = 'SQL_2022' -ALL_SQL_VERSIONS ||= [SQL_2012, SQL_2014, SQL_2016, SQL_2017, SQL_2019, SQL_2022].freeze +ALL_SQL_VERSIONS = [SQL_2012, SQL_2014, SQL_2016, SQL_2017, SQL_2019, SQL_2022].freeze # rubocop:disable Style/ClassAndModuleChildren module PuppetX @@ -19,7 +19,7 @@ class Features # rubocop:disable Style/Documentation include Puppet::Util::Windows::Registry extend Puppet::Util::Windows::Registry - SQL_CONFIGURATION ||= { + SQL_CONFIGURATION = { SQL_2012 => { major_version: 11, registry_path: '110', @@ -46,8 +46,8 @@ class Features # rubocop:disable Style/Documentation }, }.freeze - SQL_REG_ROOT ||= 'Software\Microsoft\Microsoft SQL Server' - HKLM ||= 'HKEY_LOCAL_MACHINE' + SQL_REG_ROOT = 'Software\Microsoft\Microsoft SQL Server' + HKLM = 'HKEY_LOCAL_MACHINE' def self.get_parent_path(key_path) # should be the same as SQL_REG_ROOT From f4063a713bc2a5f79b5a4d21116c6e8bf9a91c63 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:00:51 +0100 Subject: [PATCH 20/51] (CONT-800) - Correct Lint/RedundantCopDisableDirective --- .rubocop_todo.yml | 5 ----- lib/puppet_x/sqlserver/server_helper.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f03d2b64..5c416d57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,11 +14,6 @@ Lint/EmptyBlock: - 'spec/defines/manifest_shared_examples.rb' - 'spec/functions/functions_shared_examples.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -Lint/RedundantCopDisableDirective: - Exclude: - - 'lib/puppet_x/sqlserver/server_helper.rb' # Offense count: 3 # Configuration parameters: AllowComments, AllowNil. diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index 85a2a73c..41d6d0a4 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module PuppetX # rubocop:disable Style/ClassAndModuleChildren - module Sqlserver # rubocop:disable Style/ClassAndModuleChildren + module Sqlserver class ServerHelper # rubocop:disable Style/Documentation @super_feature_hash = { SQL: [:DQ, :FullText, :Replication, :SQLEngine], From b402bbfd8b212ae3bee3827326fc57dcf3169674 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:02:23 +0100 Subject: [PATCH 21/51] (CONT-800) - Correct Naming/VariableNumber --- .rubocop_todo.yml | 17 ++++++++--------- lib/puppet/provider/sqlserver_features/mssql.rb | 4 ++-- lib/puppet/provider/sqlserver_instance/mssql.rb | 4 ++-- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5c416d57..97f436e6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -14,7 +14,6 @@ Lint/EmptyBlock: - 'spec/defines/manifest_shared_examples.rb' - 'spec/functions/functions_shared_examples.rb' - # Offense count: 3 # Configuration parameters: AllowComments, AllowNil. Lint/SuppressedException: @@ -68,14 +67,14 @@ Naming/HeredocDelimiterNaming: - 'spec/spec_helper_acceptance_local.rb' - 'spec/sql_testing_helpers.rb' -# Offense count: 2 -# Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. -# SupportedStyles: snake_case, normalcase, non_integer -# AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 -Naming/VariableNumber: - Exclude: - - 'lib/puppet/provider/sqlserver_features/mssql.rb' - - 'lib/puppet/provider/sqlserver_instance/mssql.rb' +# # Offense count: 2 +# # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. +# # SupportedStyles: snake_case, normalcase, non_integer +# # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 +# Naming/VariableNumber: +# Exclude: +# - 'lib/puppet/provider/sqlserver_features/mssql.rb' +# - 'lib/puppet/provider/sqlserver_instance/mssql.rb' # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/lib/puppet/provider/sqlserver_features/mssql.rb b/lib/puppet/provider/sqlserver_features/mssql.rb index 9748bd57..35108fea 100644 --- a/lib/puppet/provider/sqlserver_features/mssql.rb +++ b/lib/puppet/provider/sqlserver_features/mssql.rb @@ -117,7 +117,7 @@ def create_temp_for_install_switch nil end - def install_net_35(source_location = nil) + def install_net35(source_location = nil) Puppet::Provider::Sqlserver.run_install_dot_net(source_location) end @@ -130,7 +130,7 @@ def create instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source]) Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil? - install_net_35(@resource[:windows_feature_source]) if [SQL_2012, SQL_2014].include? instance_version + install_net35(@resource[:windows_feature_source]) if [SQL_2012, SQL_2014].include? instance_version debug "Installing features #{@resource[:features]}" add_features(@resource[:features]) diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index fcef7c93..700e632f 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -82,7 +82,7 @@ def modify_features(features, action) end end - def install_net_35(source_location = nil) + def install_net35(source_location = nil) Puppet::Provider::Sqlserver.run_install_dot_net(source_location) end @@ -107,7 +107,7 @@ def create instance_version = PuppetX::Sqlserver::ServerHelper.sql_version_from_install_source(@resource[:source]) Puppet.debug("Installation source detected as version #{instance_version}") unless instance_version.nil? - install_net_35(@resource[:windows_feature_source]) if [SQL_2012, SQL_2014].include? instance_version + install_net35(@resource[:windows_feature_source]) if [SQL_2012, SQL_2014].include? instance_version add_features(@resource[:features]) end From 3df2b4e9a2594640d28523cfe6b860be31248749 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:02:55 +0100 Subject: [PATCH 22/51] (CONT-800) - Correct Performance/InefficientHashSearch --- .rubocop_todo.yml | 16 ---------------- spec/spec_helper_acceptance_local.rb | 2 +- spec/sql_testing_helpers.rb | 2 +- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 97f436e6..e15fefc7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -67,22 +67,6 @@ Naming/HeredocDelimiterNaming: - 'spec/spec_helper_acceptance_local.rb' - 'spec/sql_testing_helpers.rb' -# # Offense count: 2 -# # Configuration parameters: EnforcedStyle, CheckMethodNames, CheckSymbols, AllowedIdentifiers, AllowedPatterns. -# # SupportedStyles: snake_case, normalcase, non_integer -# # AllowedIdentifiers: capture3, iso8601, rfc1123_date, rfc822, rfc2822, rfc3339, x86_64 -# Naming/VariableNumber: -# Exclude: -# - 'lib/puppet/provider/sqlserver_features/mssql.rb' -# - 'lib/puppet/provider/sqlserver_instance/mssql.rb' - -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/InefficientHashSearch: - Exclude: - - 'spec/spec_helper_acceptance_local.rb' - - 'spec/sql_testing_helpers.rb' - # Offense count: 2 # This cop supports unsafe autocorrection (--autocorrect-all). Performance/StringInclude: diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 2103a38a..72a59bb0 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -229,7 +229,7 @@ def validate_sql_install(opts = {}, &block) def get_install_paths(version) vers = { '2012' => '110', '2014' => '120', '2016' => '130', '2017' => '140', '2019' => '150', '2022' => '160' } - raise _('Valid version must be specified') unless vers.keys.include?(version) + raise _('Valid version must be specified') unless vers.key?(version) dir = "C://Program Files/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap" sql_directory = case version diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 2f3e7753..942d2424 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -173,7 +173,7 @@ def remove_sql_instances(host, opts = {}) def get_install_paths(version) vers = { '2012' => '110', '2014' => '120', '2016' => '130', '2017' => '140', '2019' => '150', '2022' => '160' } - raise _('Valid version must be specified') unless vers.keys.include?(version) + raise _('Valid version must be specified') unless vers.key?(version) dir = "C://Program Files/Microsoft SQL Server/#{vers[version]}/Setup Bootstrap" sql_directory = case version From 2f87c44ba3cb7043cf6bee766ce1e56fb3cf275e Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:03:41 +0100 Subject: [PATCH 23/51] (CONT-800) - Correct Performance/InefficientHashSearch --- .rubocop_todo.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e15fefc7..d8948e06 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -67,12 +67,6 @@ Naming/HeredocDelimiterNaming: - 'spec/spec_helper_acceptance_local.rb' - 'spec/sql_testing_helpers.rb' -# Offense count: 2 -# This cop supports unsafe autocorrection (--autocorrect-all). -Performance/StringInclude: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' - - 'lib/puppet/provider/sqlserver_tsql/mssql.rb' # Offense count: 66 # Configuration parameters: Prefixes, AllowedPatterns. From c5659fd81bbad2699a2cec35071d33e00125852e Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:04:32 +0100 Subject: [PATCH 24/51] (CONT-800) - Correct RSpec/EmptyHook --- .rubocop_todo.yml | 6 ------ lib/puppet/parser/functions/sqlserver_validate_size.rb | 2 +- lib/puppet/provider/sqlserver_tsql/mssql.rb | 2 +- spec/acceptance/sqlserver_user_spec.rb | 6 ------ 4 files changed, 2 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d8948e06..67410c4b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -79,12 +79,6 @@ RSpec/ContextWording: RSpec/DescribeClass: Enabled: false -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyHook: - Exclude: - - 'spec/acceptance/sqlserver_user_spec.rb' - # Offense count: 7 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowConsecutiveOneLiners. diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index 2e5d6fb7..9f5fcd2b 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -14,7 +14,7 @@ module Puppet::Parser::Functions raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") end end - if %r{\.}.match?(value) + if value.include?('.') raise(Puppet::ParseError, "Number must be an integer, you provided #{value}") end end diff --git a/lib/puppet/provider/sqlserver_tsql/mssql.rb b/lib/puppet/provider/sqlserver_tsql/mssql.rb index be7968de..7aa52ede 100644 --- a/lib/puppet/provider/sqlserver_tsql/mssql.rb +++ b/lib/puppet/provider/sqlserver_tsql/mssql.rb @@ -15,7 +15,7 @@ def run(query) def get_config(instance = resource[:instance]) config_resc = resource.catalog.resources.find do |resc| - resc.title =~ %r{Sqlserver::Config} && + resc.title.include?('Sqlserver::Config') && resc.original_parameters[:instance_name] =~ %r{#{instance}}i end if config_resc.nil? diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index bc7261eb..74e4c6aa 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -43,12 +43,6 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') @db_user = 'DBuser' + SecureRandom.hex(2) end - after(:all) do - # remove the newly created database - # Temporarily skip delete database because of MODULES-2554 - # ensure_sqlserver_database(host, 'absent') - end - it 'Create database user with optional default_schema' do pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': From d9c0c1eecdff97109f0e83c4f900ed206fb660dd Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:04:59 +0100 Subject: [PATCH 25/51] (CONT-800) - Correct Spec/EmptyLineAfterExample --- .rubocop_todo.yml | 11 ----------- spec/acceptance/sqlserver_instance_spec.rb | 1 + spec/acceptance/sqlserver_login_spec.rb | 1 + spec/functions/sqlserver_upcase_spec.rb | 2 ++ spec/unit/puppet/property/tsql_spec.rb | 1 + spec/unit/puppet_x/sql_connection_spec.rb | 2 ++ 6 files changed, 7 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 67410c4b..2652758f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -79,17 +79,6 @@ RSpec/ContextWording: RSpec/DescribeClass: Enabled: false -# Offense count: 7 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterExample: - Exclude: - - 'spec/acceptance/sqlserver_instance_spec.rb' - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/functions/sqlserver_upcase_spec.rb' - - 'spec/unit/puppet/property/tsql_spec.rb' - - 'spec/unit/puppet_x/sql_connection_spec.rb' - # Offense count: 56 # This cop supports safe autocorrection (--autocorrect). RSpec/EmptyLineAfterExampleGroup: diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index 81935e73..c67d74c9 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -99,6 +99,7 @@ def sql_query_is_user_sysadmin(username) it "#{inst_name} instance has ExtraSQLAdmin as a sysadmin" do run_sql_query(run_sql_query_opts(inst_name, sql_query_is_user_sysadmin(@extra_admin_user), 1)) end + it "remove #{inst_name} instance" do ensure_sqlserver_instance(features, inst_name, 'absent') diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index e401f7a2..ef45097b 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -290,6 +290,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) AND pri.name = '#{@login_under_test}'" run_sql_query(run_sql_query_opts_as_sa(query, 1)) end + it 'has the specified serveradmin role' do # Note - IS_SRVROLEMEMBER always returns false for a disabled WINDOWS_LOGIN user login query = "SELECT pri.name from sys.server_role_members member diff --git a/spec/functions/sqlserver_upcase_spec.rb b/spec/functions/sqlserver_upcase_spec.rb index 884809b3..7a0b0120 100644 --- a/spec/functions/sqlserver_upcase_spec.rb +++ b/spec/functions/sqlserver_upcase_spec.rb @@ -38,11 +38,13 @@ class AlsoString < String scope.function_sqlserver_upcase([{ test: [:this, :that, :other] }]), ).to eq(TEST: [:THIS, :THAT, :OTHER]) end + it 'returns upcase symbol' do expect( scope.function_sqlserver_upcase([:test]), ).to eq(:TEST) end + it 'returns mixed objects in upcease' do expect( scope.function_sqlserver_upcase([[:test, 'woot']]), diff --git a/spec/unit/puppet/property/tsql_spec.rb b/spec/unit/puppet/property/tsql_spec.rb index c7cbf49f..ac471597 100644 --- a/spec/unit/puppet/property/tsql_spec.rb +++ b/spec/unit/puppet/property/tsql_spec.rb @@ -12,6 +12,7 @@ expect(@node[:command]).to match(%r{BEGIN TRY}) expect(@node[:command]).to include('UPDATE [my_login] SET PASSWORD = "MYSillyPassword"') } + it 'munges value to have begin and end try' do @node[:command] = 'function foo' @node[:onlyif] = 'exec bar' diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index f420d1ae..037e4c6e 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -36,6 +36,7 @@ def stub_connection expect(result.error_message).to eq("SQL Error in Connection\nRowdy Roddy Piper") }.not_to raise_error(Exception) end + it 'yields when passed a block' do allow(subject).to receive(:execute).and_return('results') subject.open_and_run_command('myquery', config) do |r| @@ -77,6 +78,7 @@ def stub_connection expect(@connection).to receive(:Open).with('Provider=MSOLEDBSQL;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;UID=sa;PWD=Pupp3t1@') subject.open_and_run_command('query', admin_user: 'sa', admin_pass: 'Pupp3t1@', instance_name: 'MSSQLSERVER') end + it 'adds a non default instance to connection string' do expect(@connection).to receive(:Open).with('Provider=MSOLEDBSQL;Initial Catalog=master;Application Name=Puppet;Data Source=.\\LOGGING;DataTypeComptibility=80;UID=sa;PWD=Pupp3t1@') subject.open_and_run_command('query', admin_user: 'sa', admin_pass: 'Pupp3t1@', instance_name: 'LOGGING') From a48c983b90b73ba8c787324de2cbf789cea2d256 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:05:40 +0100 Subject: [PATCH 26/51] (CONT-800) - Correct RSpec/EmptyLineAfterExampleGroup --- .rubocop_todo.yml | 14 -------------- spec/defines/database_spec.rb | 14 ++++++++++++++ spec/defines/login/permissions_spec.rb | 8 ++++++++ spec/defines/login_spec.rb | 3 +++ spec/defines/role/permissions_spec.rb | 3 +++ spec/defines/role_spec.rb | 8 ++++++++ spec/defines/user/permissions_spec.rb | 11 +++++++++++ spec/defines/user_spec.rb | 1 + spec/functions/sqlserver_validate_size_spec.rb | 1 + spec/unit/puppet/provider/sqlserver_tsql_spec.rb | 3 +++ spec/unit/puppet_x/sql_connection_spec.rb | 4 ++++ 11 files changed, 56 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2652758f..083791b6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -79,20 +79,6 @@ RSpec/ContextWording: RSpec/DescribeClass: Enabled: false -# Offense count: 56 -# This cop supports safe autocorrection (--autocorrect). -RSpec/EmptyLineAfterExampleGroup: - Exclude: - - 'spec/defines/database_spec.rb' - - 'spec/defines/login/permissions_spec.rb' - - 'spec/defines/login_spec.rb' - - 'spec/defines/role/permissions_spec.rb' - - 'spec/defines/role_spec.rb' - - 'spec/defines/user/permissions_spec.rb' - - 'spec/defines/user_spec.rb' - - 'spec/functions/sqlserver_validate_size_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_tsql_spec.rb' - - 'spec/unit/puppet_x/sql_connection_spec.rb' # Offense count: 6 # This cop supports safe autocorrection (--autocorrect). diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index 5df2b0ab..b9cf8a26 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -49,6 +49,7 @@ let(:raise_error_check) { "'filespec_name' expects" } end end + it_behaves_like 'sqlserver_tsql command' do let(:additional_params) do { @@ -67,6 +68,7 @@ end end end + describe 'collation_name' do let(:additional_params) { { collation_name: 'SQL_Latin1_General_CP1_CI_AS' } } let(:should_contain_command) do @@ -85,6 +87,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'filestream failure' do let(:title) { 'myTitle' } let(:params) do @@ -101,6 +104,7 @@ }.to raise_error(Puppet::Error) end end + describe 'include filestream_non_transacted_access' do let(:additional_params) { { filestream_non_transacted_access: 'FULL' } } let(:should_contain_command) { [%r{FILESTREAM\s+\(\s+NON_TRANSACTED_ACCESS\s+=\s+FULL}] } @@ -109,6 +113,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql without_command' end + describe 'should not contain filestream by default' do let(:should_not_contain_command) { [%r{FILESTREAM}] } @@ -154,42 +159,49 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql without_command' end + describe 'default_fulltext_language' do let(:additional_params) { { containment: 'PARTIAL', default_fulltext_language: 'us_english' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{SET DEFAULT_FULLTEXT_LANGUAGE = \[us_english\]}, %r{,\s*DEFAULT_FULLTEXT_LANGUAGE=\[us_english\]}m] } it_behaves_like 'sqlserver_tsql command' end + describe 'transform_noise_words ON' do let(:additional_params) { { containment: 'PARTIAL', transform_noise_words: 'ON' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{,\s*TRANSFORM_NOISE_WORDS = ON}, %r{SET TRANSFORM_NOISE_WORDS = ON}, %r{is_transform_noise_words_on = 1}] } it_behaves_like 'sqlserver_tsql command' end + describe 'transform_noise_words OFF' do let(:additional_params) { { containment: 'PARTIAL', transform_noise_words: 'OFF' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{,\s*TRANSFORM_NOISE_WORDS = OFF}, %r{SET TRANSFORM_NOISE_WORDS = OFF}, %r{is_transform_noise_words_on = 0}] } it_behaves_like 'sqlserver_tsql command' end + describe 'nested_triggers OFF' do let(:additional_params) { { containment: 'PARTIAL', nested_triggers: 'OFF' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{NESTED_TRIGGERS = OFF}, %r{is_nested_triggers_on = 0}] } it_behaves_like 'sqlserver_tsql command' end + describe 'nested_triggers ON' do let(:additional_params) { { containment: 'PARTIAL', nested_triggers: 'ON' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{NESTED_TRIGGERS = ON}, %r{is_nested_triggers_on = 1}] } it_behaves_like 'sqlserver_tsql command' end + describe 'trustworthy OFF' do let(:additional_params) { { containment: 'PARTIAL', trustworthy: 'OFF' } } let(:should_contain_command) { [%r{CONTAINMENT\s=\sPARTIAL}, %r{,\s*TRUSTWORTHY OFF}, %r{SET TRUSTWORTHY OFF}, %r{is_trustworthy_on = 0}] } it_behaves_like 'sqlserver_tsql command' end + describe 'trustwothy ON' do let(:additional_params) { { containment: 'PARTIAL', trustworthy: 'ON' } } let(:should_contain_command) do @@ -211,6 +223,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'db_chainging ON' do let(:additional_params) { { containment: 'PARTIAL', db_chaining: 'ON' } } let(:should_contain_command) do @@ -233,6 +246,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'db_chainging OFF' do let(:additional_params) { { containment: 'PARTIAL', db_chaining: 'OFF' } } let(:should_contain_command) do diff --git a/spec/defines/login/permissions_spec.rb b/spec/defines/login/permissions_spec.rb index 6369be47..244a2b32 100644 --- a/spec/defines/login/permissions_spec.rb +++ b/spec/defines/login/permissions_spec.rb @@ -32,17 +32,20 @@ end it_behaves_like 'validation error' end + describe 'empty' do let(:additional_params) { { login: '' } } it_behaves_like 'validation error' end + describe 'over limit' do let(:additional_params) { { login: random_string_of_size(129) } } it_behaves_like 'validation error' end end + context 'permissions' do let(:params) do { @@ -56,17 +59,20 @@ it_behaves_like 'validation error' end + describe 'under limit' do let(:additional_params) { { permissions: [random_string_of_size(3, false)] } } it_behaves_like 'validation error' end + describe 'over limit' do let(:additional_params) { { permissions: [random_string_of_size(129, false)] } } it_behaves_like 'validation error' end end + context 'state =>' do let(:params) do { @@ -83,6 +89,7 @@ end end end + context 'successfully' do include_context 'manifests' do let(:title) { 'myTitle' } @@ -123,6 +130,7 @@ it_behaves_like 'sqlserver_tsql command' end + describe 'alter' do let(:additional_params) { { permissions: ['ALTER'] } } let(:should_contain_command) { ['USE [master];', 'GRANT ALTER TO [loggingUser];'] } diff --git a/spec/defines/login_spec.rb b/spec/defines/login_spec.rb index 7c4231d1..57b1a487 100644 --- a/spec/defines/login_spec.rb +++ b/spec/defines/login_spec.rb @@ -26,6 +26,7 @@ is_expected.to contain_sqlserver_tsql('login-MSSQLSERVER-myTitle') end end + describe 'parameter assignment' do let(:should_contain_command) do [ @@ -49,12 +50,14 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'check_policy' do let(:additional_params) { { check_policy: false, check_expiration: true } } let(:raise_error_check) { 'Can not have check expiration enabled when check_policy is disabled' } it_behaves_like 'validation error' end + context 'permissions =>' do let(:title) { 'myTitle' } let(:params) do diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index 6d11b55b..0b581874 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -40,6 +40,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + context 'type =>' do shared_examples 'GRANT Permissions' do |type| base_commands = [ @@ -111,6 +112,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe '[]' do let(:params) do { @@ -134,6 +136,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'customDatabase' do let(:additional_params) { { database: 'customDatabase' } } let(:should_contain_command) { ['USE [customDatabase];'] } diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index fd051ace..eb3af013 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -20,6 +20,7 @@ it_behaves_like 'validation error' end + describe 'SERVER' do let(:should_contain_command) do [ @@ -39,6 +40,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'DATABASE' do let(:additional_params) do { @@ -78,6 +80,7 @@ it_behaves_like 'validation error' end + describe 'with database role type' do let(:additional_params) do { @@ -103,6 +106,7 @@ is_expected.to contain_sqlserver_tsql('role-MYCUSTOM-master-myCustomRole').with_instance('MYCUSTOM') } end + describe 'empty instance' do let(:additional_params) { { 'instance' => '' } } let(:raise_error_check) { "instance' expects a String[1, 16]" } @@ -122,6 +126,7 @@ it_behaves_like 'sqlserver_tsql without_command' end + describe 'myUser' do let(:additional_params) do { @@ -137,6 +142,7 @@ it_behaves_like 'sqlserver_tsql command' end + describe 'myUser on Database' do let(:additional_params) do { @@ -178,6 +184,7 @@ it_behaves_like 'sqlserver_tsql onlyif' end end + context 'members_purge =>' do let(:sqlserver_tsql_title) { 'role-MSSQLSERVER-master-myCustomRole-members' } @@ -241,6 +248,7 @@ it_behaves_like 'sqlserver_tsql onlyif' end end + describe '[test these users]' do let(:additional_params) do { diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index ca23e319..0644d50a 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -30,17 +30,20 @@ it_behaves_like 'validation error' end + describe 'empty' do let(:additional_params) { { user: '' } } it_behaves_like 'validation error' end + describe 'over limit' do let(:additional_params) { { user: random_string_of_size(129) } } it_behaves_like 'validation error' end end + context 'permissions' do let(:params) do { @@ -56,17 +59,20 @@ it_behaves_like 'validation error' end + describe 'under limit' do let(:additional_params) { { permissions: [random_string_of_size(3, false)] } } it_behaves_like 'validation error' end + describe 'over limit' do let(:additional_params) { { permissions: [random_string_of_size(129, false)] } } it_behaves_like 'validation error' end end + context 'state =>' do let(:params) do { @@ -83,6 +89,7 @@ it_behaves_like 'validation error' end end + context 'with_grant_option => ' do let(:params) do { @@ -98,6 +105,7 @@ it_behaves_like 'validation error' end + describe 'invalid' do let(:additional_params) { { with_grant_option: 'invalid' } } let(:raise_error_check) { "'with_grant_option' expects" } @@ -106,6 +114,7 @@ end end end + context 'successfully' do include_context 'manifests' do let(:title) { 'myTitle' } @@ -147,6 +156,7 @@ it_behaves_like 'sqlserver_tsql command' end + describe 'alter' do let(:additional_params) { { permissions: ['ALTER'] } } let(:should_contain_command) { ['USE [loggingDb];', 'GRANT ALTER TO [loggingUser];'] } @@ -189,6 +199,7 @@ it_behaves_like 'sqlserver_tsql without_command' it_behaves_like 'sqlserver_tsql onlyif' end + describe 'false' do let(:should_contain_command) do [ diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 2ac8ad7d..a11e1915 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -146,6 +146,7 @@ it_behaves_like 'sqlserver_tsql command' it_behaves_like 'sqlserver_tsql onlyif' end + context 'permissions =>' do let(:title) { 'myTitle' } let(:params) { { user: 'loggingUser', database: 'myDatabase' } } diff --git a/spec/functions/sqlserver_validate_size_spec.rb b/spec/functions/sqlserver_validate_size_spec.rb index 1eea650c..a6a88414 100644 --- a/spec/functions/sqlserver_validate_size_spec.rb +++ b/spec/functions/sqlserver_validate_size_spec.rb @@ -35,6 +35,7 @@ describe 'when giving a decimal value' do it_behaves_like 'should raise error', "0.2#{measure}", %r{Number must be an integer} end + describe 'when giving a value larger than 2147483647' do it_behaves_like 'should raise error', "2147483648#{measure}", %r{Please use larger measurement for values greater than 2147483647} end diff --git a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb index 5cb88190..f70e51cd 100644 --- a/spec/unit/puppet/provider/sqlserver_tsql_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_tsql_spec.rb @@ -49,6 +49,7 @@ def gen_query(query) @provider.run(gen_query('whacka whacka')) } end + describe 'against default database' do it { create_sqlserver_tsql(title: 'runme', command: 'whacka whacka', instance: 'MSSQLSERVER') @@ -59,6 +60,7 @@ def gen_query(query) } end end + context 'run with onlyif' do describe 'against default database' do it { @@ -69,6 +71,7 @@ def gen_query(query) @provider.run(gen_query('fozy wozy')) } end + describe 'against non master database' do it { create_sqlserver_tsql( diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index 037e4c6e..980adadc 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -44,6 +44,7 @@ def stub_connection end end end + context 'closed connection' do before :each do stub_connection @@ -113,6 +114,7 @@ def stub_connection end end end + context 'open connection' do it 'does not reopen an existing connection' do stub_connection @@ -122,6 +124,7 @@ def stub_connection subject.open_and_run_command('query', config) end end + context 'return result with errors' do it { stub_connection @@ -136,6 +139,7 @@ def stub_connection expect(result.error_message).to eq('SQL Error in Connection') } end + context 'open connection failure' do it { stub_connection From 9652e03176181c9f2e8fb378456d6a9a6b3dcd1c Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:06:02 +0100 Subject: [PATCH 27/51] (CONT-800) - Correct RSpec/EmptyLineAfterHook --- .rubocop_todo.yml | 12 ------------ spec/acceptance/sqlserver_login_spec.rb | 1 + spec/acceptance/sqlserver_role_spec.rb | 2 ++ spec/acceptance/sqlserver_user_spec.rb | 1 + spec/unit/puppet/provider/sqlserver_features_spec.rb | 1 + spec/unit/puppet_x/sql_connection_spec.rb | 1 + 6 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 083791b6..dcc4d120 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -79,18 +79,6 @@ RSpec/ContextWording: RSpec/DescribeClass: Enabled: false - -# Offense count: 6 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowConsecutiveOneLiners. -RSpec/EmptyLineAfterHook: - Exclude: - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/acceptance/sqlserver_role_spec.rb' - - 'spec/acceptance/sqlserver_user_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' - - 'spec/unit/puppet_x/sql_connection_spec.rb' - # Offense count: 51 # Configuration parameters: CountAsOne. RSpec/ExampleLength: diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index ef45097b..ec62f150 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -177,6 +177,7 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) # check_expiration and check_policy are only applicable to SQL based logins before(:all) { remove_test_logins(host) } + it "can create an #{testcase} with 'check_expiration','check_policy' set" do options = { 'check_expiration' => true, 'check_policy' => true } pp = create_login_manifest(testcase, @login_under_test, @login_passwd, options) diff --git a/spec/acceptance/sqlserver_role_spec.rb b/spec/acceptance/sqlserver_role_spec.rb index ad122b3c..68834157 100644 --- a/spec/acceptance/sqlserver_role_spec.rb +++ b/spec/acceptance/sqlserver_role_spec.rb @@ -50,9 +50,11 @@ def ensure_sqlserver_logins_users(db_name) # Create database users ensure_sqlserver_logins_users(db_name) end + before(:each) do @role = 'Role_' + SecureRandom.hex(2) end + after(:each) do pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index 74e4c6aa..a75f3347 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -38,6 +38,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') # Create new database ensure_sqlserver_database(db_name) end + before(:each) do @new_sql_login = 'Login' + SecureRandom.hex(2) @db_user = 'DBuser' + SecureRandom.hex(2) diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index fb95ddcb..ebba7a73 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -60,6 +60,7 @@ allow(@file_double).to receive(:close) allow(Tempfile).to receive(:new).with(['sqlconfig', '.ini']).and_return(@file_double) end + it_behaves_like 'create' do let(:additional_params) { { install_switches: { 'ERRORREPORTING' => 1, 'SQLBACKUPDIR' => 'I:\DBbackup' } } } let(:additional_switches) { ["/ConfigurationFile=\"#{@file_double.path}\""] } diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index 980adadc..e6ec06c2 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -26,6 +26,7 @@ def stub_connection stub_connection allow(@connection).to receive(:Open).with('Provider=MSOLEDBSQL;Initial Catalog=master;Application Name=Puppet;Data Source=.;DataTypeComptibility=80;UID=sa;PWD=Pupp3t1@') end + it 'does not raise an error but populate has_errors with message' do allow(@connection.Errors).to receive(:count).and_return(2) expect(@connection).to receive(:Errors).with(0).and_return(double(Description: 'SQL Error in Connection')) From ae4498e80e1043b0fe7e17619507d772c2be88e0 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:06:22 +0100 Subject: [PATCH 28/51] (CONT-800) - Correct RSpec/ExcessiveDocstringSpacing --- .rubocop_todo.yml | 6 ------ spec/defines/user/permissions_spec.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dcc4d120..6743e286 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -84,12 +84,6 @@ RSpec/DescribeClass: RSpec/ExampleLength: Max: 59 -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ExcessiveDocstringSpacing: - Exclude: - - 'spec/defines/user/permissions_spec.rb' - # Offense count: 2 # Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. # Include: **/*_spec*rb*, **/spec/**/* diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index 0644d50a..162be9d2 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -90,7 +90,7 @@ end end - context 'with_grant_option => ' do + context 'with_grant_option =>' do let(:params) do { permissions: ['SELECT'], From e135abfcdc78b93469a0710216c003f15b56aabe Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:07:17 +0100 Subject: [PATCH 29/51] (CONT-800) - Correct RSpec/ImplicitSubject --- .rubocop_todo.yml | 17 ++--------------- spec/defines/config_spec.rb | 12 ++++++------ spec/defines/database_spec.rb | 2 +- spec/defines/login_spec.rb | 6 +++--- spec/defines/manifest_shared_examples.rb | 10 +++++----- spec/defines/role/permissions_spec.rb | 6 +++--- spec/defines/role_spec.rb | 2 +- spec/defines/sp_configure_spec.rb | 2 +- spec/defines/user_spec.rb | 6 +++--- 9 files changed, 25 insertions(+), 38 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6743e286..89230bb8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -92,21 +92,8 @@ RSpec/FilePath: - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -# Offense count: 23 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: single_line_only, single_statement_only, disallow, require_implicit -RSpec/ImplicitSubject: - Exclude: - - 'spec/defines/config_spec.rb' - - 'spec/defines/database_spec.rb' - - 'spec/defines/login_spec.rb' - - 'spec/defines/manifest_shared_examples.rb' - - 'spec/defines/role/permissions_spec.rb' - - 'spec/defines/role_spec.rb' - - 'spec/defines/sp_configure_spec.rb' - - 'spec/defines/user_spec.rb' - +RSpec/NamedSubject: + Enabled: false # Offense count: 302 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb index cde3065d..9f0d4473 100644 --- a/spec/defines/config_spec.rb +++ b/spec/defines/config_spec.rb @@ -17,8 +17,8 @@ end it { - is_expected.not_to contain_file('C:/ProgramData/PuppetLabs/puppet/var/cache/sqlserver/.MSSQLSERVER.cfg') - is_expected.not_to contain_file('C:/ProgramData/PuppetLabs/puppet/var/cache/sqlserver') + expect(subject).not_to contain_file('C:/ProgramData/PuppetLabs/puppet/var/cache/sqlserver/.MSSQLSERVER.cfg') + expect(subject).not_to contain_file('C:/ProgramData/PuppetLabs/puppet/var/cache/sqlserver') } end @@ -35,7 +35,7 @@ let(:error_message) { %r{expects admin_pass to be set for a admin_login_type of SQL_LOGIN} } it { - is_expected.not_to compile + expect(subject).not_to compile expect { catalogue }.to raise_error(Puppet::Error, error_message) } end @@ -52,7 +52,7 @@ let(:error_message) { %r{expects admin_user to be set for a admin_login_type of SQL_LOGIN} } it { - is_expected.not_to compile + expect(subject).not_to compile expect { catalogue }.to raise_error(Puppet::Error, error_message) } end @@ -71,7 +71,7 @@ let(:error_message) { %r{expects admin_user to be empty for a admin_login_type of WINDOWS_LOGIN} } it { - is_expected.not_to compile + expect(subject).not_to compile expect { catalogue }.to raise_error(Puppet::Error, error_message) } end @@ -88,7 +88,7 @@ let(:error_message) { %r{expects admin_pass to be empty for a admin_login_type of WINDOWS_LOGIN} } it { - is_expected.not_to compile + expect(subject).not_to compile expect { catalogue }.to raise_error(Puppet::Error, error_message) } end diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index b9cf8a26..9347b637 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -100,7 +100,7 @@ it 'does not compile' do params[:filestream_directory_name] = 'C:/TestDirectory' expect { - is_expected.to contain_sqlserver_tsql('database-MSSQLSERVER-myTestDb') + expect(subject).to contain_sqlserver_tsql('database-MSSQLSERVER-myTestDb') }.to raise_error(Puppet::Error) end end diff --git a/spec/defines/login_spec.rb b/spec/defines/login_spec.rb index 57b1a487..f61ef8c5 100644 --- a/spec/defines/login_spec.rb +++ b/spec/defines/login_spec.rb @@ -23,7 +23,7 @@ describe 'Minimal Params' do it 'compiles' do - is_expected.to contain_sqlserver_tsql('login-MSSQLSERVER-myTitle') + expect(subject).to contain_sqlserver_tsql('login-MSSQLSERVER-myTitle') end end @@ -71,7 +71,7 @@ it { params[:permissions] = permissions type_title = ((type =~ %r{GRANT_WITH_OPTION}i) ? 'GRANT-WITH_GRANT_OPTION' : type.upcase) - is_expected.to contain_sqlserver__login__permissions("Sqlserver::Login[#{title}]-#{type_title}-myLogin").with( + expect(subject).to contain_sqlserver__login__permissions("Sqlserver::Login[#{title}]-#{type_title}-myLogin").with( 'login' => 'myLogin', 'state' => (type == 'GRANT_WITH_OPTION') ? 'GRANT' : type.upcase, 'with_grant_option' => type == 'GRANT_WITH_OPTION', @@ -85,7 +85,7 @@ it { params[:permissions] = permissions type_title = ((type =~ %r{GRANT_WITH_OPTION}i) ? 'GRANT-WITH_GRANT_OPTION' : type.upcase) - is_expected.not_to contain_sqlserver__login__permissions("Sqlserver::Login[#{title}]-#{type_title}-myLogin") + expect(subject).not_to contain_sqlserver__login__permissions("Sqlserver::Login[#{title}]-#{type_title}-myLogin") } end diff --git a/spec/defines/manifest_shared_examples.rb b/spec/defines/manifest_shared_examples.rb index c145a74d..46d9ad65 100644 --- a/spec/defines/manifest_shared_examples.rb +++ b/spec/defines/manifest_shared_examples.rb @@ -22,7 +22,7 @@ def convert_to_regexp(str) it { params.merge!(additional_params) should_contain_onlyif.each do |check| - is_expected.to contain_sqlserver_tsql(sqlserver_tsql_title).with_onlyif(convert_to_regexp(check)) + expect(subject).to contain_sqlserver_tsql(sqlserver_tsql_title).with_onlyif(convert_to_regexp(check)) end } end @@ -30,7 +30,7 @@ def convert_to_regexp(str) it { params.merge!(additional_params) should_not_contain_onlyif.each do |check| - is_expected.to contain_sqlserver_tsql(sqlserver_tsql_title).with_onlyif(convert_to_regexp(check)) + expect(subject).to contain_sqlserver_tsql(sqlserver_tsql_title).with_onlyif(convert_to_regexp(check)) end } end @@ -39,7 +39,7 @@ def convert_to_regexp(str) it { params.merge!(additional_params) should_contain_command.each do |check| - is_expected.to contain_sqlserver_tsql(sqlserver_tsql_title).with_command(convert_to_regexp(check)) + expect(subject).to contain_sqlserver_tsql(sqlserver_tsql_title).with_command(convert_to_regexp(check)) end } end @@ -48,7 +48,7 @@ def convert_to_regexp(str) it { params.merge!(additional_params) should_not_contain_command.each do |check| - is_expected.not_to contain_sqlserver_tsql(sqlserver_tsql_title).with_command(convert_to_regexp(check)) + expect(subject).not_to contain_sqlserver_tsql(sqlserver_tsql_title).with_command(convert_to_regexp(check)) end } end @@ -56,7 +56,7 @@ def convert_to_regexp(str) shared_examples 'compile' do it { params.merge!(additional_params) - is_expected.to compile + expect(subject).to compile } end diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index 0b581874..be5bfffc 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -122,8 +122,8 @@ end it { - is_expected.to compile - is_expected.not_to contain_sqlserver_tsql(sqlserver_tsql_title) + expect(subject).to compile + expect(subject).not_to contain_sqlserver_tsql(sqlserver_tsql_title) } end end @@ -164,7 +164,7 @@ end it { - is_expected.to contain_sqlserver_tsql("role-permissions-myCustomRole-GRANT-#{instance}-master").with_instance(instance) + expect(subject).to contain_sqlserver_tsql("role-permissions-myCustomRole-GRANT-#{instance}-master").with_instance(instance) } end end diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index eb3af013..87ccd122 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -103,7 +103,7 @@ let(:params) { { instance: 'MYCUSTOM' } } it { - is_expected.to contain_sqlserver_tsql('role-MYCUSTOM-master-myCustomRole').with_instance('MYCUSTOM') + expect(subject).to contain_sqlserver_tsql('role-MYCUSTOM-master-myCustomRole').with_instance('MYCUSTOM') } end diff --git a/spec/defines/sp_configure_spec.rb b/spec/defines/sp_configure_spec.rb index e8c9c185..e440d878 100644 --- a/spec/defines/sp_configure_spec.rb +++ b/spec/defines/sp_configure_spec.rb @@ -96,7 +96,7 @@ describe 'service' do it 'is defined' do - is_expected.to contain_exec('restart-service-MSSQLSERVER-filestream access level').with_refreshonly(true) + expect(subject).to contain_exec('restart-service-MSSQLSERVER-filestream access level').with_refreshonly(true) end end end diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index a11e1915..0e32180e 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -125,7 +125,7 @@ describe 'have dependency on Sqlserver::Config[MSSQLSERVER]' do it 'requires ::config' do - is_expected.to contain_sqlserver_tsql(sqlserver_tsql_title).with_require('Sqlserver::Config[MSSQLSERVER]') + expect(subject).to contain_sqlserver_tsql(sqlserver_tsql_title).with_require('Sqlserver::Config[MSSQLSERVER]') end end @@ -156,7 +156,7 @@ it { params[:permissions] = permissions type_title = ((type =~ %r{GRANT_WITH_OPTION}i) ? 'GRANT-WITH_GRANT_OPTION' : type.upcase) - is_expected.to contain_sqlserver__user__permissions("Sqlserver::User[#{title}]-#{type_title}-loggingUser").with( + expect(subject).to contain_sqlserver__user__permissions("Sqlserver::User[#{title}]-#{type_title}-loggingUser").with( 'user' => 'loggingUser', 'database' => 'myDatabase', 'state' => (type == 'GRANT_WITH_OPTION') ? 'GRANT' : type.upcase, @@ -171,7 +171,7 @@ it { params[:permissions] = permissions type_title = ((type =~ %r{GRANT_WITH_OPTION}i) ? 'GRANT-WITH_GRANT_OPTION' : type.upcase) - is_expected.not_to contain_sqlserver__user__permissions("Sqlserver::User[#{title}]-#{type_title}-loggingUser") + expect(subject).not_to contain_sqlserver__user__permissions("Sqlserver::User[#{title}]-#{type_title}-loggingUser") } end From 8b04d79191d0bc3b080a2786a0bf8393d3785fcd Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:11:47 +0100 Subject: [PATCH 30/51] (CONT-800) - Install mount_iso v4 --- spec/spec_helper_acceptance_local.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 72a59bb0..56305541 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -23,7 +23,7 @@ class Helper RSpec.configure do |c| c.before(:suite) do - Helper.instance.run_shell('puppet module install puppetlabs/mount_iso') + Helper.instance.run_shell('puppet module install puppetlabs-mount_iso --version 4.0.0') Helper.instance.run_shell('puppet module install puppet/archive') iso_opts = { From 69a521874e3e55f5ae918e43385722cf950c0bc5 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:13:27 +0100 Subject: [PATCH 31/51] (CONT-800) - Correct RSpec/ReceiveNever --- .rubocop_todo.yml | 30 ++++++++++++++--------- spec/unit/puppet_x/sql_connection_spec.rb | 10 ++++---- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 89230bb8..fae3c8ff 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,3 +1,11 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2023-04-25 10:07:49 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: 1 # Configuration parameters: AllowedMethods. # AllowedMethods: enums @@ -30,7 +38,7 @@ Metrics/AbcSize: # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 177 + Max: 162 # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. @@ -42,7 +50,7 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 12 -# Offense count: 40 +# Offense count: 39 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: Max: 41 @@ -67,7 +75,6 @@ Naming/HeredocDelimiterNaming: - 'spec/spec_helper_acceptance_local.rb' - 'spec/sql_testing_helpers.rb' - # Offense count: 66 # Configuration parameters: Prefixes, AllowedPatterns. # Prefixes: when, with, without @@ -92,8 +99,6 @@ RSpec/FilePath: - 'spec/unit/puppet_x/server_helper_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' -RSpec/NamedSubject: - Enabled: false # Offense count: 302 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: @@ -126,11 +131,18 @@ RSpec/MultipleExpectations: RSpec/MultipleMemoizedHelpers: Max: 10 -# Offense count: 17 +# Offense count: 31 # Configuration parameters: EnforcedStyle, IgnoreSharedExamples. # SupportedStyles: always, named_only RSpec/NamedSubject: Exclude: + - 'spec/defines/config_spec.rb' + - 'spec/defines/database_spec.rb' + - 'spec/defines/login_spec.rb' + - 'spec/defines/role/permissions_spec.rb' + - 'spec/defines/role_spec.rb' + - 'spec/defines/sp_configure_spec.rb' + - 'spec/defines/user_spec.rb' - 'spec/unit/puppet_x/sql_connection_spec.rb' # Offense count: 31 @@ -159,12 +171,6 @@ RSpec/NoExpectationExample: - 'spec/unit/puppet/type/sqlserver_instance_spec.rb' - 'spec/unit/puppet_x/server_helper_spec.rb' -# Offense count: 5 -# This cop supports safe autocorrection (--autocorrect). -RSpec/ReceiveNever: - Exclude: - - 'spec/unit/puppet_x/sql_connection_spec.rb' - # Offense count: 4 RSpec/RepeatedExampleGroupBody: Exclude: diff --git a/spec/unit/puppet_x/sql_connection_spec.rb b/spec/unit/puppet_x/sql_connection_spec.rb index e6ec06c2..40f34010 100644 --- a/spec/unit/puppet_x/sql_connection_spec.rb +++ b/spec/unit/puppet_x/sql_connection_spec.rb @@ -61,7 +61,7 @@ def stub_connection context 'SQL Server based authentication' do it 'results with error if set admin_user is not set' do - expect(@connection).to receive(:Open).never + expect(@connection).not_to receive(:Open) expect { result = subject.open_and_run_command('query', admin_pass: 'Pupp3t1@', admin_login_type: 'SQL_LOGIN') expect(result.exitstatus).to eq(1) @@ -69,7 +69,7 @@ def stub_connection end it 'results with error if set admin_pass is not set' do - expect(@connection).to receive(:Open).never + expect(@connection).not_to receive(:Open) expect { result = subject.open_and_run_command('query', admin_user: 'sa', admin_login_type: 'SQL_LOGIN') expect(result.exitstatus).to eq(1) @@ -89,7 +89,7 @@ def stub_connection context 'Windows based authentication' do it 'results with error if set admin_user is set' do - expect(@connection).to receive(:Open).never + expect(@connection).not_to receive(:Open) expect { result = subject.open_and_run_command('query', admin_user: 'sa', admin_pass: '', admin_login_type: 'WINDOWS_LOGIN') expect(result.exitstatus).to eq(1) @@ -97,7 +97,7 @@ def stub_connection end it 'results with error if set admin_pass is set' do - expect(@connection).to receive(:Open).never + expect(@connection).not_to receive(:Open) expect { result = subject.open_and_run_command('query', admin_user: '', admin_pass: 'Pupp3t1@', admin_login_type: 'WINDOWS_LOGIN') expect(result.exitstatus).to eq(1) @@ -119,7 +119,7 @@ def stub_connection context 'open connection' do it 'does not reopen an existing connection' do stub_connection - expect(@connection).to receive(:open).never + expect(@connection).not_to receive(:open) allow(@connection).to receive(:State).and_return(1) # any value other than CONNECTION_CLOSED expect(@connection).to receive(:Execute).with('query', nil, nil) subject.open_and_run_command('query', config) From d749b52a617b88ad2e2cd2726a4a8e7363ba6dd4 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:13:59 +0100 Subject: [PATCH 32/51] (CONT-800) - Correct Style/FetchEnvVar --- .rubocop_todo.yml | 7 ------- lib/puppet/provider/sqlserver.rb | 8 ++++---- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fae3c8ff..4e7b27ed 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -221,13 +221,6 @@ Security/Open: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' -# Offense count: 4 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowedVars. -Style/FetchEnvVar: - Exclude: - - 'lib/puppet/provider/sqlserver.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowSplatArgument. diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 612e8ab8..449bb1e2 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -10,10 +10,10 @@ class Puppet::Provider::Sqlserver < Puppet::Provider # rubocop:disable Style/Doc initvars - commands powershell: if File.exist?("#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") - "#{ENV['SYSTEMROOT']}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" - elsif File.exist?("#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") - "#{ENV['SYSTEMROOT']}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" + commands powershell: if File.exist?("#{ENV.fetch('SYSTEMROOT', nil)}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV.fetch('SYSTEMROOT', nil)}\\sysnative\\WindowsPowershell\\v1.0\\powershell.exe" + elsif File.exist?("#{ENV.fetch('SYSTEMROOT', nil)}\\system32\\WindowsPowershell\\v1.0\\powershell.exe") + "#{ENV.fetch('SYSTEMROOT', nil)}\\system32\\WindowsPowershell\\v1.0\\powershell.exe" else 'powershell.exe' end From 26b6107a802112bee295938eda30b0981b18231e Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:14:32 +0100 Subject: [PATCH 33/51] (CONT-800) - Correct Style/HashConversion --- .rubocop_todo.yml | 8 -------- lib/puppet_x/sqlserver/features.rb | 4 ++-- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4e7b27ed..40d3b71f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -220,14 +220,6 @@ Security/Open: Exclude: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' - -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowSplatArgument. -Style/HashConversion: - Exclude: - - 'lib/puppet_x/sqlserver/features.rb' - # Offense count: 30 # This cop supports safe autocorrection (--autocorrect). Style/IfUnlessModifier: diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index a178ec17..852f970c 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -223,10 +223,10 @@ def self.instances ver.segments[0] == major_version end - [version, Hash[instances]] + [version, instances.to_h] end - Hash[version_instance_map] + version_instance_map.to_h end # return a hash of version => shared features array From b9d65fc3666094bedb75c7a1e0df925037757c0c Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:15:38 +0100 Subject: [PATCH 34/51] (CONT-800) - Correct Style/IfUnlessModifier --- .rubocop_todo.yml | 20 +------------------ .../sqlserver_is_domain_or_local_user.rb | 4 +--- .../sqlserver_validate_instance_name.rb | 16 ++++----------- .../functions/sqlserver_validate_range.rb | 4 +--- .../functions/sqlserver_validate_size.rb | 12 +++-------- lib/puppet/property/sqlserver_login.rb | 4 +--- .../provider/sqlserver_features/mssql.rb | 16 ++++----------- .../provider/sqlserver_instance/mssql.rb | 8 ++------ lib/puppet/provider/sqlserver_tsql/mssql.rb | 4 +--- lib/puppet/type/sqlserver_instance.rb | 12 +++-------- lib/puppet/type/sqlserver_tsql.rb | 8 ++------ lib/puppet_x/sqlserver/sql_connection.rb | 4 +--- spec/spec_helper_acceptance_local.rb | 12 +++-------- spec/sql_testing_helpers.rb | 4 +--- .../provider/sqlserver_features_spec.rb | 8 ++------ spec/unit/puppet/sqlserver_spec_helper.rb | 4 +--- 16 files changed, 31 insertions(+), 109 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 40d3b71f..794447e5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -220,25 +220,7 @@ Security/Open: Exclude: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' -# Offense count: 30 -# This cop supports safe autocorrection (--autocorrect). -Style/IfUnlessModifier: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb' - - 'lib/puppet/parser/functions/sqlserver_validate_instance_name.rb' - - 'lib/puppet/parser/functions/sqlserver_validate_range.rb' - - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' - - 'lib/puppet/property/sqlserver_login.rb' - - 'lib/puppet/provider/sqlserver_features/mssql.rb' - - 'lib/puppet/provider/sqlserver_instance/mssql.rb' - - 'lib/puppet/provider/sqlserver_tsql/mssql.rb' - - 'lib/puppet/type/sqlserver_instance.rb' - - 'lib/puppet/type/sqlserver_tsql.rb' - - 'lib/puppet_x/sqlserver/sql_connection.rb' - - 'spec/spec_helper_acceptance_local.rb' - - 'spec/sql_testing_helpers.rb' - - 'spec/unit/puppet/provider/sqlserver_features_spec.rb' - - 'spec/unit/puppet/sqlserver_spec_helper.rb' + # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb index 55efae8a..3c95afb0 100644 --- a/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb +++ b/lib/puppet/parser/functions/sqlserver_is_domain_or_local_user.rb @@ -4,9 +4,7 @@ module Puppet::Parser::Functions newfunction(:sqlserver_is_domain_or_local_user, type: :rvalue, doc: '@return [Boolean] Returns true is the username is for local/domain.') do |args| - if args.length != 1 - raise Puppet::ParseError, "is_domain_or_local_user(): requires exactly 1 argument, you provided #{args.length}" - end + raise Puppet::ParseError, "is_domain_or_local_user(): requires exactly 1 argument, you provided #{args.length}" if args.length != 1 PuppetX::Sqlserver::ServerHelper.is_domain_or_local_user?(args[0], Facter.value(:hostname)) end diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index 6194e5ed..e7cbc1be 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -16,24 +16,16 @@ # http://msdn.microsoft.com/en-us/library/ms143531(v=sql.120).aspx module Puppet::Parser::Functions newfunction(:sqlserver_validate_instance_name, doc: '@return Error if not a valid instance name.') do |args| - if args.length != 1 - raise Puppet::ParseError, "mssql_validate_instance_name(): requires exactly 1 argument, you provided #{args.length}" - end + raise Puppet::ParseError, "mssql_validate_instance_name(): requires exactly 1 argument, you provided #{args.length}" if args.length != 1 value = args[0] errors = [] - if value.empty? - errors << 'Instance name must be between 1 to 16 characters' - end - if value.length > 16 - errors << "Instance name can not be larger than 16 characters, you provided #{value}" - end + errors << 'Instance name must be between 1 to 16 characters' if value.empty? + errors << "Instance name can not be larger than 16 characters, you provided #{value}" if value.length > 16 if %r{\\|\:|;|\,|\@|\'|\s|\&}.match?(value) errors << "Instance name can not contain whitespaces, backslashes(\\), commas(,), colons(:), semi-colons(;), at symbols (@), single quotes(') or ampersand(&) sybmols, you provided '#{value}'" end - if %r{^_|_$}.match?(value) - errors << "Instance name can not start or end with underscore (_), you provided #{value}" - end + errors << "Instance name can not start or end with underscore (_), you provided #{value}" if %r{^_|_$}.match?(value) raise Puppet::ParseError, errors.join("\n") unless errors.empty? end end diff --git a/lib/puppet/parser/functions/sqlserver_validate_range.rb b/lib/puppet/parser/functions/sqlserver_validate_range.rb index 48f9e776..8966e2f3 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_range.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_range.rb @@ -2,9 +2,7 @@ module Puppet::Parser::Functions newfunction(:sqlserver_validate_range, doc: '@return Error if value is not between range') do |args| - if (args.length < 3) || (args.length > 4) - raise Puppet::ParseError, "validate_range(): wrong number of arguments (#{args.length}; must be 3)" - end + raise Puppet::ParseError, "validate_range(): wrong number of arguments (#{args.length}; must be 3)" if (args.length < 3) || (args.length > 4) values, lower, upper, msg = args diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index 9f5fcd2b..60b51ea6 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -2,20 +2,14 @@ module Puppet::Parser::Functions newfunction(:sqlserver_validate_size, doc: '@return Error if not a valid size value') do |args| - if args.length != 1 - raise(Puppet::ParseError, "mssql_validate_size(): requires exactly 1 argument, you provided #{args.length}") - end + raise(Puppet::ParseError, "mssql_validate_size(): requires exactly 1 argument, you provided #{args.length}") if args.length != 1 value = args[0] match = %r{^(?\d+)(?KB|MB|GB|TB)$}.match(value) if match - if Integer(match[:size]) > 2_147_483_647 - raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") - end - end - if value.include?('.') - raise(Puppet::ParseError, "Number must be an integer, you provided #{value}") + raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") if Integer(match[:size]) > 2_147_483_647 end + raise(Puppet::ParseError, "Number must be an integer, you provided #{value}") if value.include?('.') end end diff --git a/lib/puppet/property/sqlserver_login.rb b/lib/puppet/property/sqlserver_login.rb index b8c69ad3..7b508b98 100644 --- a/lib/puppet/property/sqlserver_login.rb +++ b/lib/puppet/property/sqlserver_login.rb @@ -9,9 +9,7 @@ class Puppet::Property::SqlserverLogin < Puppet::Property # rubocop:disable Styl # value.length > 1 # does not contain two back slashes, contains no forward slashes # Determine what characters are valid for SQLLogin vs Domain Logins - if %r{\\.*\\}.match?(value) - raise 'More than one \ found, maximum of one for users is allowed' - end + raise 'More than one \ found, maximum of one for users is allowed' if %r{\\.*\\}.match?(value) if %r{@}.match?(value) raise ArgumentError, diff --git a/lib/puppet/provider/sqlserver_features/mssql.rb b/lib/puppet/provider/sqlserver_features/mssql.rb index 35108fea..564b4fdb 100644 --- a/lib/puppet/provider/sqlserver_features/mssql.rb +++ b/lib/puppet/provider/sqlserver_features/mssql.rb @@ -68,15 +68,9 @@ def modify_features(action, features) "/FEATURES=#{features.join(',')}"] if action == 'install' cmd_args << '/UPDATEENABLED=False' - if not_nil_and_not_empty?(@resource[:is_svc_account]) - cmd_args << "/ISSVCACCOUNT=#{@resource[:is_svc_account]}" - end - if not_nil_and_not_empty?(@resource[:is_svc_password]) - cmd_args << "/ISSVCPASSWORD=#{@resource[:is_svc_password]}" - end - if not_nil_and_not_empty?(@resource[:pid]) - cmd_args << "/PID=#{@resource[:pid]}" - end + cmd_args << "/ISSVCACCOUNT=#{@resource[:is_svc_account]}" if not_nil_and_not_empty?(@resource[:is_svc_account]) + cmd_args << "/ISSVCPASSWORD=#{@resource[:is_svc_password]}" if not_nil_and_not_empty?(@resource[:is_svc_password]) + cmd_args << "/PID=#{@resource[:pid]}" if not_nil_and_not_empty?(@resource[:pid]) end begin config_file = create_temp_for_install_switch unless action == 'uninstall' @@ -97,9 +91,7 @@ def create_temp_for_install_switch if not_nil_and_not_empty? @resource[:install_switches] config_file = ['[OPTIONS]'] @resource[:install_switches].each_pair do |k, v| - if FEATURE_RESERVED_SWITCHES.include? k - warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments") - end + warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments") if FEATURE_RESERVED_SWITCHES.include? k config_file << if v.is_a?(Numeric) || (v.is_a?(String) && v =~ %r{^(true|false|1|0)$}i) "#{k}=#{v}" elsif v.nil? diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 700e632f..8d08373a 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -117,9 +117,7 @@ def create_temp_for_install_switch if not_nil_and_not_empty? @resource[:install_switches] config_file = ['[OPTIONS]'] @resource[:install_switches].each_pair do |k, v| - if instance_reserved_switches.include? k - warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments") - end + warn("Reserved switch [#{k}] found for `install_switches`, please know the provided value may be overridden by some command line arguments") if instance_reserved_switches.include? k config_file << if v.is_a?(Numeric) || (v.is_a?(String) && v =~ %r{^(true|false|1|0)$}i) "#{k}=#{v}" elsif v.nil? @@ -156,9 +154,7 @@ def build_cmd_args(features, action = 'install') next unless not_nil_and_not_empty? @resource[key] cmd_args << "/#{RESOURCEKEY_TO_CMDARG[key]}=\"#{@resource[key.to_sym]}\"" - if %r{(_pwd|_password)$}i.match?(key.to_s) - obfuscated_strings.push(@resource[key]) - end + obfuscated_strings.push(@resource[key]) if %r{(_pwd|_password)$}i.match?(key.to_s) end format_cmd_args_array('/SQLSYSADMINACCOUNTS', @resource[:sql_sysadmin_accounts], cmd_args, true) diff --git a/lib/puppet/provider/sqlserver_tsql/mssql.rb b/lib/puppet/provider/sqlserver_tsql/mssql.rb index 7aa52ede..edb05a60 100644 --- a/lib/puppet/provider/sqlserver_tsql/mssql.rb +++ b/lib/puppet/provider/sqlserver_tsql/mssql.rb @@ -18,9 +18,7 @@ def get_config(instance = resource[:instance]) resc.title.include?('Sqlserver::Config') && resc.original_parameters[:instance_name] =~ %r{#{instance}}i end - if config_resc.nil? - raise("Sqlserver_tsql[#{resource.title}] was unable to retrieve the config, please ensure the catalog contains sqlserver::config{'#{resource[:instance]}':}") - end + raise("Sqlserver_tsql[#{resource.title}] was unable to retrieve the config, please ensure the catalog contains sqlserver::config{'#{resource[:instance]}':}") if config_resc.nil? config_resc.original_parameters end diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index 28e9406f..c5b20086 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -85,9 +85,7 @@ validate do |value| value.is_a? String matches = value.scan(%r{(\/|\\|\[|\]|\:|\;|\||\=|\,|\+|\*|\?|\<|\>)}) - unless matches.empty? - raise("rs_svc_account can not contain any of the special characters, / \\ [ ] : ; | = , + * ? < >, your entry contained #{matches}") - end + raise("rs_svc_account can not contain any of the special characters, / \\ [ ] : ; | = , + * ? < >, your entry contained #{matches}") unless matches.empty? end end @@ -122,15 +120,11 @@ end def validate - if set?(:agt_svc_account) - validate_user_password_required(:agt_svc_account, :agt_svc_password) - end + validate_user_password_required(:agt_svc_account, :agt_svc_password) if set?(:agt_svc_account) self[:features] = self[:features].flatten.sort.uniq if set?(:features) # RS Must have Strong Password - if set?(:rs_svc_password) && self[:features].include?('RS') - strong_password?(:rs_svc_password) - end + strong_password?(:rs_svc_password) if set?(:rs_svc_password) && self[:features].include?('RS') return unless self[:security_mode] == 'SQL' strong_password?(:sa_pwd) diff --git a/lib/puppet/type/sqlserver_tsql.rb b/lib/puppet/type/sqlserver_tsql.rb index 0f24c81b..4cf465ef 100644 --- a/lib/puppet/type/sqlserver_tsql.rb +++ b/lib/puppet/type/sqlserver_tsql.rb @@ -109,13 +109,9 @@ def sync event = :executed_command @output = provider.run(resource[:command]) - if @output.has_errors - raise("Unable to apply changes, failed with error message #{@output.error_message}") - end + raise("Unable to apply changes, failed with error message #{@output.error_message}") if @output.has_errors - unless @output.exitstatus.to_s == '0' - raise("#{resource[:command]} returned #{@output.exitstatus} instead of one of [#{should.join(',')}]") - end + raise("#{resource[:command]} returned #{@output.exitstatus} instead of one of [#{should.join(',')}]") unless @output.exitstatus.to_s == '0' event end diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index 41fc2a26..f20180c3 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -56,9 +56,7 @@ def get_connection_string(config) params.store('PWD', admin_pass) end - if !config[:instance_name].nil? && config[:instance_name] !~ %r{^MSSQLSERVER$} - params['Data Source'] = ".\\#{config[:instance_name]}" - end + params['Data Source'] = ".\\#{config[:instance_name]}" if !config[:instance_name].nil? && config[:instance_name] !~ %r{^MSSQLSERVER$} params.map { |k, v| "#{k}=#{v}" }.join(';') end diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 56305541..8fcb6ba1 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -46,9 +46,7 @@ def node_vars? hash['groups'].each do |group| group['targets'].each do |node| - if ENV['TARGET_HOST'] == node['uri'] - return node['vars'] - end + return node['vars'] if ENV['TARGET_HOST'] == node['uri'] end end end @@ -56,9 +54,7 @@ def node_vars? def sql_version? vars = node_vars? unless vars.nil? - if vars['sqlversion'] - return vars['sqlversion'].match(%r{sqlserver_(.*)})[1] - end + return vars['sqlversion'].match(%r{sqlserver_(.*)})[1] if vars['sqlversion'] end # Return's a default version if none was given '2019' @@ -178,9 +174,7 @@ def run_sql_query(opts = {}, &block) EOS # sqlcmd has problem authenticate to sqlserver if the instance is the default one MSSQLSERVER # Below is a work-around for it (remove "-S server\instance" from the connection string) - if instance.nil? || instance == 'MSSQLSERVER' - powershell.dup.gsub!("-S #{server}\\#{instance}", '') - end + powershell.dup.gsub!("-S #{server}\\#{instance}", '') if instance.nil? || instance == 'MSSQLSERVER' Tempfile.open 'tmp.ps1' do |tempfile| File.open(tempfile.path, 'w') { |file| file.puts powershell } diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 942d2424..1e7b6576 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -66,9 +66,7 @@ def run_sql_query(host, opts = {}, &block) EOS # sqlcmd has problem authenticate to sqlserver if the instance is the default one MSSQLSERVER # Below is a work-around for it (remove "-S server\instance" from the connection string) - if instance.nil? || instance == 'MSSQLSERVER' - powershell.gsub!("-S #{server}\\#{instance}", '') - end + powershell.gsub!("-S #{server}\\#{instance}", '') if instance.nil? || instance == 'MSSQLSERVER' create_remote_file(host, 'tmp.ps1', powershell) diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index ebba7a73..d8d58d86 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -81,12 +81,8 @@ stub_powershell_call(provider_class_ut) stub_source_which_call args - unless feature_remove.empty? - stub_remove_features(args, feature_remove, exit_code || 0) - end - unless feature_add.empty? - stub_add_features(args, feature_add, [], exit_code || 0) - end + stub_remove_features(args, feature_remove, exit_code || 0) unless feature_remove.empty? + stub_add_features(args, feature_add, [], exit_code || 0) unless feature_add.empty? # If warning_matcher supplied ensure warnings raised match, otherwise no warnings raised allow(@provider).to receive(:warn).with(match(warning_matcher)).and_return(nil) if warning_matcher diff --git a/spec/unit/puppet/sqlserver_spec_helper.rb b/spec/unit/puppet/sqlserver_spec_helper.rb index 786217cd..217776a9 100644 --- a/spec/unit/puppet/sqlserver_spec_helper.rb +++ b/spec/unit/puppet/sqlserver_spec_helper.rb @@ -25,9 +25,7 @@ def stub_modify_features(action, args, features, additional_switches = [], exit_ "/FEATURES=#{features.join(',')}"] cmds << '/UPDATEENABLED=False' if action == 'install' cmds << "/ISSVCACCOUNT=#{args[:is_svc_account]}" if args.key?(:is_svc_account) - if args.key?(:is_svc_password) - cmds << "/ISSVCPASSWORD=#{args[:is_svc_password]}" - end + cmds << "/ISSVCPASSWORD=#{args[:is_svc_password]}" if args.key?(:is_svc_password) additional_switches.each do |switch| cmds << switch end From a29e2d37108510a8c61c407c54da940376bcf08d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:15:56 +0100 Subject: [PATCH 35/51] (CONT-800) - Fix specs --- .rubocop_todo.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 794447e5..13fe86b9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2023-04-25 10:07:49 UTC using RuboCop version 1.48.1. +# on 2023-04-25 10:15:50 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 @@ -34,11 +34,11 @@ Lint/SuppressedException: Metrics/AbcSize: Max: 36 -# Offense count: 6 +# Offense count: 5 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode. # AllowedMethods: refine Metrics/BlockLength: - Max: 162 + Max: 158 # Offense count: 1 # Configuration parameters: CountComments, CountAsOne. @@ -122,7 +122,7 @@ RSpec/LeakyConstantDeclaration: Exclude: - 'spec/functions/sqlserver_upcase_spec.rb' -# Offense count: 6 +# Offense count: 22 RSpec/MultipleExpectations: Max: 8 @@ -221,7 +221,6 @@ Security/Open: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: AllowedMethods. From 0ad8aff4e18fe6511c2b43d92f43b1b842717979 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:18:42 +0100 Subject: [PATCH 36/51] (CONT-800) - Correct Style/IfWithBooleanLiteralBranches --- .rubocop_todo.yml | 8 -------- lib/puppet_x/sqlserver/server_helper.rb | 6 +----- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 13fe86b9..f98f9dd5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -221,14 +221,6 @@ Security/Open: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: AllowedMethods. -# AllowedMethods: nonzero? -Style/IfWithBooleanLiteralBranches: - Exclude: - - 'lib/puppet_x/sqlserver/server_helper.rb' - # Offense count: 1 Style/MixinUsage: Exclude: diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index 41d6d0a4..054a3a34 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -17,11 +17,7 @@ def self.is_super_feature(feature) # rubocop:disable Naming/PredicateName end def self.is_domain_or_local_user?(user, hostname) # rubocop:disable Naming/PredicateName - if %r{(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$}i.match?(user) - false - else - true - end + !%r{(^(((nt (authority|service))|#{hostname})\\\w+)$)|^(\w+)$}i.match?(user) end # Returns either SQL_2016, SQL_2014 or SQL_2012 if it can determine the SQL Version from the install source From ecb388df84e26c1186f3393a24c9eb9cb1fb58b9 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:19:10 +0100 Subject: [PATCH 37/51] (CONT-800) - Correct Style/MixinUsage --- .rubocop_todo.yml | 6 ------ spec/spec_helper.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f98f9dd5..45a42fc7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -220,12 +220,6 @@ Security/Open: Exclude: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' - -# Offense count: 1 -Style/MixinUsage: - Exclude: - - 'spec/spec_helper.rb' - # Offense count: 1 # This cop supports unsafe autocorrection (--autocorrect-all). # Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20239e64..a3745336 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -9,7 +9,7 @@ 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, From 80e987ec125f407bfef23fc7985164840acfacc2 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:21:01 +0100 Subject: [PATCH 38/51] (CONT-800) - Correct Style/NumericPredicate --- .rubocop_todo.yml | 8 -------- lib/puppet/type/sqlserver_instance.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45a42fc7..45180746 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -220,14 +220,6 @@ Security/Open: Exclude: - 'lib/puppet_x/sqlserver/features.rb' - 'lib/puppet_x/sqlserver/sql_connection.rb' -# Offense count: 1 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns. -# SupportedStyles: predicate, comparison -Style/NumericPredicate: - Exclude: - - 'spec/**/*' - - 'lib/puppet/type/sqlserver_instance.rb' # Offense count: 3 # Configuration parameters: AllowedMethods. diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index c5b20086..eaaf0154 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -158,7 +158,7 @@ def strong_password?(key) failures << 'must contain uppercase letters' unless %r{[A-Z]}.match?(password) failures << 'must contain numbers' unless %r{\d}.match?(password) failures << 'must contain a special character' unless %r{}.match?(password) - fail("#{message_start}:\n#{failures.join("\n")}") if failures.count > 0 # rubocop:disable Style/SignalException + fail("#{message_start}:\n#{failures.join("\n")}") if failures.count.positive? # rubocop:disable Style/SignalException true end From edb4c76fae602cdde8af9509a7102a93173e5a94 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:21:29 +0100 Subject: [PATCH 39/51] (CONT-800) - Correct Style/RedundantRegexpEscape --- .rubocop_todo.yml | 9 --------- .../functions/sqlserver_validate_instance_name.rb | 2 +- lib/puppet/type/sqlserver_instance.rb | 2 +- spec/defines/database_spec.rb | 12 ++++++------ spec/unit/puppet/property/tsql_spec.rb | 2 +- 5 files changed, 9 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45180746..2e46fd22 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,15 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 28 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantRegexpEscape: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_validate_instance_name.rb' - - 'lib/puppet/type/sqlserver_instance.rb' - - 'spec/defines/database_spec.rb' - - 'spec/unit/puppet/property/tsql_spec.rb' - # Offense count: 2 # This cop supports safe autocorrection (--autocorrect). Style/RedundantSelfAssignmentBranch: diff --git a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb index e7cbc1be..dd869279 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_instance_name.rb @@ -22,7 +22,7 @@ module Puppet::Parser::Functions errors = [] errors << 'Instance name must be between 1 to 16 characters' if value.empty? errors << "Instance name can not be larger than 16 characters, you provided #{value}" if value.length > 16 - if %r{\\|\:|;|\,|\@|\'|\s|\&}.match?(value) + if %r{\\|:|;|,|@|'|\s|&}.match?(value) errors << "Instance name can not contain whitespaces, backslashes(\\), commas(,), colons(:), semi-colons(;), at symbols (@), single quotes(') or ampersand(&) sybmols, you provided '#{value}'" end errors << "Instance name can not start or end with underscore (_), you provided #{value}" if %r{^_|_$}.match?(value) diff --git a/lib/puppet/type/sqlserver_instance.rb b/lib/puppet/type/sqlserver_instance.rb index eaaf0154..b33f4d09 100644 --- a/lib/puppet/type/sqlserver_instance.rb +++ b/lib/puppet/type/sqlserver_instance.rb @@ -84,7 +84,7 @@ following characters: " / \ [ ] : ; | = , + * ? < > ' validate do |value| value.is_a? String - matches = value.scan(%r{(\/|\\|\[|\]|\:|\;|\||\=|\,|\+|\*|\?|\<|\>)}) + matches = value.scan(%r{(/|\\|\[|\]|:|;|\||=|,|\+|\*|\?|<|>)}) raise("rs_svc_account can not contain any of the special characters, / \\ [ ] : ; | = , + * ? < >, your entry contained #{matches}") unless matches.empty? end end diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index 9347b637..a03024a3 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -61,9 +61,9 @@ let(:should_contain_command) do [ %r{NAME = N'myCre-Cre'}, - %r{FILENAME = N'c\:/test/test\.mdf'}, + %r{FILENAME = N'c:/test/test\.mdf'}, %r{NAME = N'myCrazy_Log'}, - %r{FILENAME = N'c\:/test/logfile\.ldf'}, + %r{FILENAME = N'c:/test/logfile\.ldf'}, ] end end @@ -73,9 +73,9 @@ let(:additional_params) { { collation_name: 'SQL_Latin1_General_CP1_CI_AS' } } let(:should_contain_command) do [ - %r{\-\-\s*UPDATE SECTION.*ALTER\sDATABASE\s\[myTestDb\]\sCOLLATE\sSQL_Latin1_General_CP1_CI_AS}m, - %r{\-\-\s*CREATE SECTION.*IF\ NOT\ EXISTS\(SELECT\ name\ FROM\ sys\.databases\ WHERE\ name\ =\ 'myTestDb'\ AND\ collation_name\ =\ 'SQL_Latin1_General_CP1_CI_AS'\)}m, - %r{\-\-\s*UPDATE SECTION.*IF\ NOT\ EXISTS\(SELECT\ name\ FROM\ sys\.databases\ WHERE\ name\ =\ 'myTestDb'\ AND\ collation_name\ =\ 'SQL_Latin1_General_CP1_CI_AS'\)}m, + %r{--\s*UPDATE SECTION.*ALTER\sDATABASE\s\[myTestDb\]\sCOLLATE\sSQL_Latin1_General_CP1_CI_AS}m, + %r{--\s*CREATE SECTION.*IF\ NOT\ EXISTS\(SELECT\ name\ FROM\ sys\.databases\ WHERE\ name\ =\ 'myTestDb'\ AND\ collation_name\ =\ 'SQL_Latin1_General_CP1_CI_AS'\)}m, + %r{--\s*UPDATE SECTION.*IF\ NOT\ EXISTS\(SELECT\ name\ FROM\ sys\.databases\ WHERE\ name\ =\ 'myTestDb'\ AND\ collation_name\ =\ 'SQL_Latin1_General_CP1_CI_AS'\)}m, ] end let(:should_contain_onlyif) do @@ -143,7 +143,7 @@ %r{WITH\s*DB_CHAINING}m, # Should have no comma between, newlines are fine %r{DEFAULT_FULLTEXT_LANGUAGE=\[English\]\s*,}, # Should enclose default language of us_english in brackets %r{TRUSTWORTHY OFF\s*,}, - %r{\-\- CREATE.*TWO_DIGIT_YEAR_CUTOFF = 2049.*\-\- UPDATE}m, + %r{-- CREATE.*TWO_DIGIT_YEAR_CUTOFF = 2049.*-- UPDATE}m, ] end let(:should_not_contain_command) do diff --git a/spec/unit/puppet/property/tsql_spec.rb b/spec/unit/puppet/property/tsql_spec.rb index ac471597..8946836c 100644 --- a/spec/unit/puppet/property/tsql_spec.rb +++ b/spec/unit/puppet/property/tsql_spec.rb @@ -22,6 +22,6 @@ it 'properlies escape single quotes in queries' do @node[:command] = 'SELECT \'FOO\'' - expect(@node[:command]).to match(%r{SET @sql_text = N'SELECT \'\'FOO\'\'}) + expect(@node[:command]).to match(%r{SET @sql_text = N'SELECT ''FOO''}) end end From 79583b9909016c6e41345310e1afe915a3e18ad5 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:22:26 +0100 Subject: [PATCH 40/51] (CONT-800) - Correct Style/RedundantSelfAssignmentBranch --- .rubocop_todo.yml | 7 ------- spec/acceptance/sqlserver_instance_spec.rb | 2 +- spec/acceptance/z_last_sqlserver_features_spec.rb | 2 +- 3 files changed, 2 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2e46fd22..49775df3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,13 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 2 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantSelfAssignmentBranch: - Exclude: - - 'spec/acceptance/sqlserver_instance_spec.rb' - - 'spec/acceptance/z_last_sqlserver_features_spec.rb' - # Offense count: 16 # This cop supports safe autocorrection (--autocorrect). Style/RedundantStringEscape: diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index c67d74c9..a32212af 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -16,7 +16,7 @@ def ensure_sqlserver_instance(features, inst_name, ensure_val = 'present', sysad sysadmin_accounts << user # If no password env variable set (by CI), then default to vagrant password = Helper.instance.run_shell('$env:pass').stdout.chomp - password = password.empty? ? 'vagrant' : password + password = 'vagrant' if password.empty? pp = <<-MANIFEST sqlserver_instance{'#{inst_name}': diff --git a/spec/acceptance/z_last_sqlserver_features_spec.rb b/spec/acceptance/z_last_sqlserver_features_spec.rb index 51617077..75881cdb 100644 --- a/spec/acceptance/z_last_sqlserver_features_spec.rb +++ b/spec/acceptance/z_last_sqlserver_features_spec.rb @@ -11,7 +11,7 @@ def ensure_sql_features(features, ensure_val = 'present') user = Helper.instance.run_shell('$env:UserName').stdout.chomp # If no password env variable set (by CI), then default to vagrant password = Helper.instance.run_shell('$env:pass').stdout.chomp - password = password.empty? ? 'vagrant' : password + password = 'vagrant' if password.empty? pp = <<-MANIFEST sqlserver::config{ 'MSSQLSERVER': From e8c3ba15a3c69da2bd8cb420cc48641e7d5500fe Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:22:50 +0100 Subject: [PATCH 41/51] (CONT-800) - Correct Style/RedundantStringEscape --- .rubocop_todo.yml | 7 ------- spec/spec_helper_acceptance_local.rb | 14 +++++++------- spec/sql_testing_helpers.rb | 14 +++++++------- 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49775df3..dd2def8a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,13 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 16 -# This cop supports safe autocorrection (--autocorrect). -Style/RedundantStringEscape: - Exclude: - - 'spec/spec_helper_acceptance_local.rb' - - 'spec/sql_testing_helpers.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowInnerSlashes. diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index 8fcb6ba1..c80f7886 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -164,13 +164,13 @@ def run_sql_query(opts = {}, &block) sql_admin_user = opts[:sql_admin_user] ||= SQL_ADMIN_USER powershell = <<-EOS - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\120\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\140\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\140\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\150\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\170\\Tools\\Binn\\" - sqlcmd.exe -S #{server}\\#{instance} -U #{sql_admin_user} -P #{sql_admin_pass} -Q \"#{query}\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\120\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\140\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\140\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\150\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\170\\Tools\\Binn\\" + sqlcmd.exe -S #{server}\\#{instance} -U #{sql_admin_user} -P #{sql_admin_pass} -Q "#{query}" EOS # sqlcmd has problem authenticate to sqlserver if the instance is the default one MSSQLSERVER # Below is a work-around for it (remove "-S server\instance" from the connection string) diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 1e7b6576..62f97980 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -56,13 +56,13 @@ def run_sql_query(host, opts = {}, &block) sql_admin_user = opts[:sql_admin_user] ||= SQL_ADMIN_USER powershell = <<-EOS - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\120\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\140\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\140\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\150\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\" - $Env:Path +=\";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\170\\Tools\\Binn\\" - sqlcmd.exe -S #{server}\\#{instance} -U #{sql_admin_user} -P #{sql_admin_pass} -Q \"#{query}\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\110\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\110\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\120\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\120\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\130\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\140\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\140\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\150\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\150\\Tools\\Binn\\" + $Env:Path +=";C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn;C:\\Program Files\\Microsoft SQL Server\\170\\Tools\\Binn\\" + sqlcmd.exe -S #{server}\\#{instance} -U #{sql_admin_user} -P #{sql_admin_pass} -Q "#{query}" EOS # sqlcmd has problem authenticate to sqlserver if the instance is the default one MSSQLSERVER # Below is a work-around for it (remove "-S server\instance" from the connection string) From 097ee2f01391960a9fcc3bf3fea68ac443569e27 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:24:58 +0100 Subject: [PATCH 42/51] (CONT-800) - Correct Style/RegexpLiteral --- .rubocop_todo.yml | 8 -------- spec/defines/user_spec.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dd2def8a..f4470472 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,14 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowInnerSlashes. -# SupportedStyles: slashes, percent_r, mixed -Style/RegexpLiteral: - Exclude: - - 'spec/defines/user_spec.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle. diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index 0e32180e..a3e84cc7 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -116,7 +116,7 @@ let(:should_contain_command) do [ 'USE [myDatabase]', - /CREATE USER \[myMachineName\/myUser\]\n\s+FROM LOGIN \[myMachineName\/myUser\]/, + %r{CREATE USER \[myMachineName/myUser\]\n\s+FROM LOGIN \[myMachineName/myUser\]}, ] end From 46ab3d924ae30f29cc7bb169eaddb43c8b03f21a Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:25:20 +0100 Subject: [PATCH 43/51] (CONT-800) - Correct Style/RescueStandardError --- .rubocop_todo.yml | 9 --------- lib/puppet_x/sqlserver/features.rb | 4 ++-- spec/spec_helper.rb | 2 +- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f4470472..7e6ec0b6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,15 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle. -# SupportedStyles: implicit, explicit -Style/RescueStandardError: - Exclude: - - 'lib/puppet_x/sqlserver/features.rb' - - 'spec/spec_helper.rb' - # Offense count: 3 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: AllowModifier. diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index 852f970c..d9c1182c 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -56,14 +56,14 @@ def self.get_parent_path(key_path) def self.get_reg_key_val(win32_reg_key, val_name, reg_type) win32_reg_key[val_name, reg_type] - rescue + rescue StandardError nil end def self.key_exists?(path) open(HKLM, path, KEY_READ | KEY64) {} true - rescue + rescue StandardError false end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index a3745336..9c2837a8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -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 From c3a8710005d5b9d4403a5f3b1fe0238b26ab8b49 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:26:05 +0100 Subject: [PATCH 44/51] (CONT-800) - Correct Style/SoleNestedConditional --- .rubocop_todo.yml | 8 -------- lib/puppet/parser/functions/sqlserver_validate_size.rb | 4 +--- lib/puppet/provider/sqlserver.rb | 4 +--- spec/spec_helper_acceptance_local.rb | 5 ++--- 4 files changed, 4 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7e6ec0b6..795eced9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -230,14 +230,6 @@ Style/OptionalBooleanParameter: - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 3 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: AllowModifier. -Style/SoleNestedConditional: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_validate_size.rb' - - 'lib/puppet/provider/sqlserver.rb' - - 'spec/spec_helper_acceptance_local.rb' # Offense count: 34 # This cop supports unsafe autocorrection (--autocorrect-all). diff --git a/lib/puppet/parser/functions/sqlserver_validate_size.rb b/lib/puppet/parser/functions/sqlserver_validate_size.rb index 60b51ea6..df6ecb15 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_size.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_size.rb @@ -7,9 +7,7 @@ module Puppet::Parser::Functions value = args[0] match = %r{^(?\d+)(?KB|MB|GB|TB)$}.match(value) - if match - raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") if Integer(match[:size]) > 2_147_483_647 - end + raise(Puppet::ParseError, "Please use larger measurement for values greater than 2147483647, you provided #{value}") if match && (Integer(match[:size]) > 2_147_483_647) raise(Puppet::ParseError, "Number must be an integer, you provided #{value}") if value.include?('.') end end diff --git a/lib/puppet/provider/sqlserver.rb b/lib/puppet/provider/sqlserver.rb index 449bb1e2..e06c0ae1 100644 --- a/lib/puppet/provider/sqlserver.rb +++ b/lib/puppet/provider/sqlserver.rb @@ -51,9 +51,7 @@ def not_nil_and_not_empty?(obj) # @api private def self.run_install_dot_net(source_location = nil) - unless source_location.nil? - warn("The specified windows_source_location directory for sqlserver of \"#{source_location}\" does not exist") unless Puppet::FileSystem.directory?(source_location) - end + warn("The specified windows_source_location directory for sqlserver of \"#{source_location}\" does not exist") if !source_location.nil? && !Puppet::FileSystem.directory?(source_location) install_dot_net = <<~DOTNET $Result = Dism /online /Get-featureinfo /featurename:NetFx3 diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index c80f7886..dd93fdc0 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -53,9 +53,8 @@ def node_vars? def sql_version? vars = node_vars? - unless vars.nil? - return vars['sqlversion'].match(%r{sqlserver_(.*)})[1] if vars['sqlversion'] - end + return vars['sqlversion'].match(%r{sqlserver_(.*)})[1] if !vars.nil? && (vars['sqlversion']) + # Return's a default version if none was given '2019' end From 79cc92bf11df8b31cfecdd0cd4b5608be946c97c Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:27:09 +0100 Subject: [PATCH 45/51] (CONT-800) - Correct Style/StringConcatenation --- .rubocop_todo.yml | 14 -------------- spec/acceptance/sqlserver_config_spec.rb | 8 ++++---- spec/acceptance/sqlserver_database_spec.rb | 4 ++-- spec/acceptance/sqlserver_instance_spec.rb | 2 +- spec/acceptance/sqlserver_login_spec.rb | 16 ++++++++-------- spec/acceptance/sqlserver_role_spec.rb | 12 ++++++------ spec/acceptance/sqlserver_tsql_spec.rb | 16 ++++++++-------- spec/acceptance/sqlserver_user_spec.rb | 6 +++--- .../puppet/provider/sqlserver_instance_spec.rb | 4 ++-- 9 files changed, 34 insertions(+), 48 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 795eced9..cbef6397 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -231,20 +231,6 @@ Style/OptionalBooleanParameter: - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 34 -# This cop supports unsafe autocorrection (--autocorrect-all). -# Configuration parameters: Mode. -Style/StringConcatenation: - Exclude: - - 'spec/acceptance/sqlserver_config_spec.rb' - - 'spec/acceptance/sqlserver_database_spec.rb' - - 'spec/acceptance/sqlserver_instance_spec.rb' - - 'spec/acceptance/sqlserver_login_spec.rb' - - 'spec/acceptance/sqlserver_role_spec.rb' - - 'spec/acceptance/sqlserver_tsql_spec.rb' - - 'spec/acceptance/sqlserver_user_spec.rb' - - 'spec/unit/puppet/provider/sqlserver_instance_spec.rb' - # Offense count: 1 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyle, AllowSafeAssignment. diff --git a/spec/acceptance/sqlserver_config_spec.rb b/spec/acceptance/sqlserver_config_spec.rb index ce6a1270..6788563f 100644 --- a/spec/acceptance/sqlserver_config_spec.rb +++ b/spec/acceptance/sqlserver_config_spec.rb @@ -5,9 +5,9 @@ require 'erb' # Get instance name -inst_name = ('MSSQL' + SecureRandom.hex(4)).upcase +inst_name = "MSSQL#{SecureRandom.hex(4)}".upcase # Get database name -db_name = ('DB' + SecureRandom.hex(4)).upcase +db_name = "DB#{SecureRandom.hex(4)}".upcase describe 'sqlserver::config test' do def ensure_sqlserver_instance(inst_name, ensure_val = 'present') @@ -32,11 +32,11 @@ def ensure_sqlserver_instance(inst_name, ensure_val = 'present') ensure_sqlserver_instance(inst_name) # get credentials for new config - @admin_user = 'test_user' + SecureRandom.hex(2) + @admin_user = "test_user#{SecureRandom.hex(2)}" @admin_pass = 'Pupp3t1@' # get database user - @db_user = 'dbuser' + SecureRandom.hex(2) + @db_user = "dbuser#{SecureRandom.hex(2)}" end after(:all) do diff --git a/spec/acceptance/sqlserver_database_spec.rb b/spec/acceptance/sqlserver_database_spec.rb index 7c1f94b0..e41fc86c 100644 --- a/spec/acceptance/sqlserver_database_spec.rb +++ b/spec/acceptance/sqlserver_database_spec.rb @@ -16,8 +16,8 @@ def run_sql_query_opts(query, expected_row_count) context 'Start testing...' do before(:each) do - @db_name = ('DB' + SecureRandom.hex(4)).upcase - @table_name = 'Tables_' + SecureRandom.hex(3) + @db_name = "DB#{SecureRandom.hex(4)}".upcase + @table_name = "Tables_#{SecureRandom.hex(3)}" end after(:each) do diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index a32212af..1e51923c 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -5,7 +5,7 @@ require 'erb' def new_random_instance_name - ('MSSQL' + SecureRandom.hex(4)).upcase.to_s + "MSSQL#{SecureRandom.hex(4)}".upcase.to_s end describe 'sqlserver_instance' do diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index ec62f150..643cea5b 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -3,8 +3,8 @@ require 'spec_helper_acceptance' require 'securerandom' -db_name = ('DB' + SecureRandom.hex(4)).upcase -table_name = 'Tables_' + SecureRandom.hex(3) +db_name = "DB#{SecureRandom.hex(4)}".upcase +table_name = "Tables_#{SecureRandom.hex(3)}" # Covers testrail => ['89118', '89119', '89120', '89121', '89122', '89123', '89124', '89125', '89540'] describe 'Test sqlserver::login' do @@ -75,14 +75,14 @@ def create_login_manifest(testcase, login_name, login_password, options = {}) end before(:all) do - @login_user = 'Login' + SecureRandom.hex(4) - @login_passwd = 'Password1!' + SecureRandom.hex(5) - @windows_user = 'User' + SecureRandom.hex(4) - @windows_group = 'Group' + SecureRandom.hex(4) + @login_user = "Login#{SecureRandom.hex(4)}" + @login_passwd = "Password1!#{SecureRandom.hex(5)}" + @windows_user = "User#{SecureRandom.hex(4)}" + @windows_group = "Group#{SecureRandom.hex(4)}" host_shortname = Helper.instance.run_shell('$env:computername').stdout.upcase.strip # Require the NETBIOS name for later database searches - @login_windows_user = host_shortname + '\\' + @windows_user - @login_windows_group = host_shortname + '\\' + @windows_group + @login_windows_user = "#{host_shortname}\\#{@windows_user}" + @login_windows_group = "#{host_shortname}\\#{@windows_group}" # Create a database, a simple table and windows accounts fixtures pp = <<-MANIFEST diff --git a/spec/acceptance/sqlserver_role_spec.rb b/spec/acceptance/sqlserver_role_spec.rb index 68834157..e1982fc0 100644 --- a/spec/acceptance/sqlserver_role_spec.rb +++ b/spec/acceptance/sqlserver_role_spec.rb @@ -7,11 +7,11 @@ hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip # database name -db_name = ('DB' + SecureRandom.hex(4)).upcase -LOGIN1 = 'Login1_' + SecureRandom.hex(2) -LOGIN2 = 'Login2_' + SecureRandom.hex(2) -LOGIN3 = 'Login3_' + SecureRandom.hex(2) -USER1 = 'User1_' + SecureRandom.hex(2) +db_name = "DB#{SecureRandom.hex(4)}".upcase +LOGIN1 = "Login1_#{SecureRandom.hex(2)}" +LOGIN2 = "Login2_#{SecureRandom.hex(2)}" +LOGIN3 = "Login3_#{SecureRandom.hex(2)}" +USER1 = "User1_#{SecureRandom.hex(2)}" describe 'Test sqlserver::role' do def ensure_sqlserver_logins_users(db_name) @@ -52,7 +52,7 @@ def ensure_sqlserver_logins_users(db_name) end before(:each) do - @role = 'Role_' + SecureRandom.hex(2) + @role = "Role_#{SecureRandom.hex(2)}" end after(:each) do diff --git a/spec/acceptance/sqlserver_tsql_spec.rb b/spec/acceptance/sqlserver_tsql_spec.rb index d578dc96..0224ab0d 100644 --- a/spec/acceptance/sqlserver_tsql_spec.rb +++ b/spec/acceptance/sqlserver_tsql_spec.rb @@ -7,10 +7,10 @@ version = sql_version? # database name -db_name = ('DB' + SecureRandom.hex(4)).upcase +db_name = "DB#{SecureRandom.hex(4)}".upcase # database user: -DB_LOGIN_USER = 'loginuser' + SecureRandom.hex(2) +DB_LOGIN_USER = "loginuser#{SecureRandom.hex(2)}" describe 'sqlserver_tsql test' do def ensure_sqlserver_database(db_name, _ensure_val = 'present') @@ -29,7 +29,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') context 'Test sqlserver_tsql with Windows based authentication' do before(:all) do # Create new database - @table_name = 'Tables_' + SecureRandom.hex(3) + @table_name = "Tables_#{SecureRandom.hex(3)}" @query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" ensure_sqlserver_database(db_name) @@ -68,7 +68,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') context 'Test sqlserver_tsql with default SQL Server based authentication' do before(:all) do # Create new database - @table_name = 'Tables_' + SecureRandom.hex(3) + @table_name = "Tables_#{SecureRandom.hex(3)}" @query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" ensure_sqlserver_database(db_name) @@ -107,7 +107,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') it 'Run sqlserver_tsql WITH onlyif is true:', if: version.to_i != 2016 do # Timeout issues with command run on Sql Server 2016. Functionality of test covered by test below. # Initilize a new table name: - @table_name = 'Table_' + SecureRandom.hex(3) + @table_name = "Table_#{SecureRandom.hex(3)}" @query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': @@ -136,7 +136,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') it 'Run sqlserver_tsql WITH onlyif is false:' do # Initilize a new table name: - @table_name = 'Table_' + SecureRandom.hex(3) + @table_name = "Table_#{SecureRandom.hex(3)}" @query = "USE #{db_name}; SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE table_name = '#{@table_name}';" pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': @@ -166,7 +166,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') it 'Run sqlserver_tsql WITH onlyif that does a table insert:' do # Initilize a new table name: - @table_name = 'Table_' + SecureRandom.hex(3) + @table_name = "Table_#{SecureRandom.hex(3)}" @query = "USE #{db_name}; SELECT * FROM #{@table_name} WHERE id = 2;" pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': @@ -212,7 +212,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') end it 'Negative test: Run tsql with non-existing database:' do - @table_name = 'Table_' + SecureRandom.hex(3) + @table_name = "Table_#{SecureRandom.hex(3)}" pp = <<-MANIFEST sqlserver::config{'MSSQLSERVER': instance_name => 'MSSQLSERVER', diff --git a/spec/acceptance/sqlserver_user_spec.rb b/spec/acceptance/sqlserver_user_spec.rb index a75f3347..b5a652d7 100644 --- a/spec/acceptance/sqlserver_user_spec.rb +++ b/spec/acceptance/sqlserver_user_spec.rb @@ -7,7 +7,7 @@ hostname = Helper.instance.run_shell('hostname').stdout.upcase.strip # database name -db_name = ('DB' + SecureRandom.hex(4)).upcase +db_name = "DB#{SecureRandom.hex(4)}".upcase describe 'sqlserver::user test' do def ensure_sqlserver_database(db_name, _ensure_val = 'present') @@ -40,8 +40,8 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') end before(:each) do - @new_sql_login = 'Login' + SecureRandom.hex(2) - @db_user = 'DBuser' + SecureRandom.hex(2) + @new_sql_login = "Login#{SecureRandom.hex(2)}" + @db_user = "DBuser#{SecureRandom.hex(2)}" end it 'Create database user with optional default_schema' do diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index ffaa9c00..2f111385 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -67,7 +67,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) # Extrace the SQL Sysadmins admin_args = execute_args[:sql_sysadmin_accounts].map(&:to_s) # prepend first arg only with CLI switch - admin_args[0] = '/SQLSYSADMINACCOUNTS=' + admin_args[0] + admin_args[0] = "/SQLSYSADMINACCOUNTS=#{admin_args[0]}" cmd_args += admin_args additional_install_switches.each do |switch| @@ -107,7 +107,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) # wrap each arg in doublequotes admin_args = execute_args[:sql_sysadmin_accounts].map { |a| "\"#{a}\"" } # prepend first arg only with CLI switch - admin_args[0] = '/SQLSYSADMINACCOUNTS=' + admin_args[0] + admin_args[0] = "/SQLSYSADMINACCOUNTS=#{admin_args[0]}" cmd_args += admin_args additional_install_switches.each do |switch| From 2d5a6c3c2165d2b95f64eb2fdde8c58599addfbe Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:27:50 +0100 Subject: [PATCH 46/51] (CONT-800) - Correct Style/TernaryParentheses --- .rubocop_todo.yml | 8 -------- .../functions/sqlserver_validate_hash_uniq_values.rb | 2 +- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cbef6397..823d2e85 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -231,14 +231,6 @@ Style/OptionalBooleanParameter: - 'spec/defines/manifest_shared_examples.rb' -# Offense count: 1 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyle, AllowSafeAssignment. -# SupportedStyles: require_parentheses, require_no_parentheses, require_parentheses_when_complex -Style/TernaryParentheses: - Exclude: - - 'lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb' - # Offense count: 88 # This cop supports safe autocorrection (--autocorrect). # Configuration parameters: EnforcedStyleForMultiline. diff --git a/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb b/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb index 2d87e53d..1fdc7200 100644 --- a/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb +++ b/lib/puppet/parser/functions/sqlserver_validate_hash_uniq_values.rb @@ -15,7 +15,7 @@ module Puppet::Parser::Functions total_count = value.count uniq_count = value.uniq.count - msg = (arguments[1]) ? arguments[1] : "Duplicate values passed to hash #{value}" + msg = arguments[1] || "Duplicate values passed to hash #{value}" raise(Puppet::ParseError, msg) if uniq_count != total_count end end From 563c464db2ad4a2fb2bf9ac9fe6010a82b82a5bf Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:28:22 +0100 Subject: [PATCH 47/51] (CONT-800) - Correct Style/TrailingCommaInHashLiteral --- .rubocop_todo.yml | 8 -------- .../provider/sqlserver_instance/mssql.rb | 2 +- lib/puppet_x/sqlserver/features.rb | 20 +++++++++---------- lib/puppet_x/sqlserver/server_helper.rb | 2 +- lib/puppet_x/sqlserver/sql_connection.rb | 2 +- spec/acceptance/sqlserver_database_spec.rb | 2 +- spec/acceptance/sqlserver_instance_spec.rb | 2 +- spec/acceptance/sqlserver_login_spec.rb | 2 +- spec/acceptance/sqlserver_tsql_spec.rb | 10 +++++----- spec/defines/config_spec.rb | 10 +++++----- spec/defines/database_spec.rb | 8 ++++---- spec/defines/login/permissions_spec.rb | 10 +++++----- spec/defines/login_spec.rb | 6 +++--- spec/defines/role/permissions_spec.rb | 12 +++++------ spec/defines/role_spec.rb | 20 +++++++++---------- spec/defines/sp_configure_spec.rb | 6 +++--- spec/defines/user/permissions_spec.rb | 12 +++++------ spec/defines/user_spec.rb | 2 +- spec/spec_helper.rb | 2 +- spec/spec_helper_acceptance_local.rb | 12 +++++------ spec/sql_testing_helpers.rb | 10 +++++----- .../provider/sqlserver_features_spec.rb | 6 +++--- .../provider/sqlserver_instance_spec.rb | 12 +++++------ spec/unit/puppet/sqlserver_install_context.rb | 2 +- .../puppet/type/sqlserver_features_spec.rb | 2 +- .../puppet/type/sqlserver_instance_spec.rb | 2 +- 26 files changed, 88 insertions(+), 96 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 823d2e85..9fbaf4aa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -229,11 +229,3 @@ Style/OptionalBooleanParameter: - 'lib/puppet/provider/sqlserver_instance/mssql.rb' - 'lib/puppet/type/sqlserver_tsql.rb' - 'spec/defines/manifest_shared_examples.rb' - - -# Offense count: 88 -# This cop supports safe autocorrection (--autocorrect). -# Configuration parameters: EnforcedStyleForMultiline. -# SupportedStylesForMultiline: comma, consistent_comma, no_comma -Style/TrailingCommaInHashLiteral: - Enabled: false diff --git a/lib/puppet/provider/sqlserver_instance/mssql.rb b/lib/puppet/provider/sqlserver_instance/mssql.rb index 8d08373a..b7cd3985 100644 --- a/lib/puppet/provider/sqlserver_instance/mssql.rb +++ b/lib/puppet/provider/sqlserver_instance/mssql.rb @@ -18,7 +18,7 @@ 'sa_pwd' => 'SAPWD', 'security_mode' => 'SECURITYMODE', 'sql_svc_account' => 'SQLSVCACCOUNT', - 'sql_svc_password' => 'SQLSVCPASSWORD', + 'sql_svc_password' => 'SQLSVCPASSWORD' }.freeze Puppet::Type.type(:sqlserver_instance).provide(:mssql, parent: Puppet::Provider::Sqlserver) do diff --git a/lib/puppet_x/sqlserver/features.rb b/lib/puppet_x/sqlserver/features.rb index d9c1182c..20f649de 100644 --- a/lib/puppet_x/sqlserver/features.rb +++ b/lib/puppet_x/sqlserver/features.rb @@ -22,28 +22,28 @@ class Features # rubocop:disable Style/Documentation SQL_CONFIGURATION = { SQL_2012 => { major_version: 11, - registry_path: '110', + registry_path: '110' }, SQL_2014 => { major_version: 12, - registry_path: '120', + registry_path: '120' }, SQL_2016 => { major_version: 13, - registry_path: '130', + registry_path: '130' }, SQL_2017 => { major_version: 14, - registry_path: '140', + registry_path: '140' }, SQL_2019 => { major_version: 15, - registry_path: '150', + registry_path: '150' }, SQL_2022 => { major_version: 16, - registry_path: '160', - }, + registry_path: '160' + } }.freeze SQL_REG_ROOT = 'Software\Microsoft\Microsoft SQL Server' @@ -97,7 +97,7 @@ def self.get_reg_instance_info(friendly_version) 'name' => short_name, 'reg_root' => [], 'version' => open(HKLM, "#{root}\\MSSQLServer\\CurrentVersion", KEY_READ | KEY64) { |r| values(r)['CurrentVersion'] }, - 'version_friendly' => friendly_version, + 'version_friendly' => friendly_version } discovered[short_name]['reg_root'].push(root) @@ -128,7 +128,7 @@ def self.get_instance_features(reg_root, instance_name) 'SQL_FullText_Adv' => 'FullText', # Full-Text and Semantic Extractions for Search 'SQL_DQ_Full' => 'DQ', # Data Quality Services 'sql_inst_mr' => 'ADVANCEDANALYTICS', # R Services (In-Database) - 'SQL_Polybase_Core_Inst' => 'POLYBASE', # PolyBase Query Service for External Data + 'SQL_Polybase_Core_Inst' => 'POLYBASE' # PolyBase Query Service for External Data } feat_root = "#{reg_root}\\ConfigurationState" @@ -167,7 +167,7 @@ def self.get_shared_features(version) 'sql_shared_mr' => 'SQL_SHARED_MR', # R Server (Standalone) # SQL Client Connectivity SDK (Installed by default) # also WMI: SqlService WHERE SQLServiceType = 4 # MsDtsServer - 'SQL_DTS_Full' => 'IS', # Integration Services + 'SQL_DTS_Full' => 'IS' # Integration Services # currently ignoring Reporting Services Shared # currently ignoring R Server Standalone } diff --git a/lib/puppet_x/sqlserver/server_helper.rb b/lib/puppet_x/sqlserver/server_helper.rb index 054a3a34..f2daed42 100644 --- a/lib/puppet_x/sqlserver/server_helper.rb +++ b/lib/puppet_x/sqlserver/server_helper.rb @@ -5,7 +5,7 @@ module Sqlserver class ServerHelper # rubocop:disable Style/Documentation @super_feature_hash = { SQL: [:DQ, :FullText, :Replication, :SQLEngine], - Tools: [:BC, :SSMS, :ADV_SSMS, :Conn, :SDK], + Tools: [:BC, :SSMS, :ADV_SSMS, :Conn, :SDK] } def self.get_sub_features(super_feature) diff --git a/lib/puppet_x/sqlserver/sql_connection.rb b/lib/puppet_x/sqlserver/sql_connection.rb index f20180c3..08e476a8 100644 --- a/lib/puppet_x/sqlserver/sql_connection.rb +++ b/lib/puppet_x/sqlserver/sql_connection.rb @@ -35,7 +35,7 @@ def get_connection_string(config) 'Initial Catalog' => config[:database] || 'master', 'Application Name' => 'Puppet', 'Data Source' => '.', - 'DataTypeComptibility' => 80, + 'DataTypeComptibility' => 80 } admin_user = config[:admin_user] || '' diff --git a/spec/acceptance/sqlserver_database_spec.rb b/spec/acceptance/sqlserver_database_spec.rb index e41fc86c..afe23678 100644 --- a/spec/acceptance/sqlserver_database_spec.rb +++ b/spec/acceptance/sqlserver_database_spec.rb @@ -10,7 +10,7 @@ def run_sql_query_opts(query, expected_row_count) query: query, sql_admin_user: 'sa', sql_admin_pass: 'Pupp3t1@', - expected_row_count: expected_row_count, + expected_row_count: expected_row_count } end diff --git a/spec/acceptance/sqlserver_instance_spec.rb b/spec/acceptance/sqlserver_instance_spec.rb index 1e51923c..e2ba6c4f 100644 --- a/spec/acceptance/sqlserver_instance_spec.rb +++ b/spec/acceptance/sqlserver_instance_spec.rb @@ -43,7 +43,7 @@ def run_sql_query_opts(inst_name, query, expected_row_count) server: '.', sql_admin_user: 'sa', sql_admin_pass: 'Pupp3t1@', - expected_row_count: expected_row_count, + expected_row_count: expected_row_count } end diff --git a/spec/acceptance/sqlserver_login_spec.rb b/spec/acceptance/sqlserver_login_spec.rb index 643cea5b..de814877 100644 --- a/spec/acceptance/sqlserver_login_spec.rb +++ b/spec/acceptance/sqlserver_login_spec.rb @@ -14,7 +14,7 @@ def run_sql_query_opts(user, passwd, query, expected_row_count) query: query, sql_admin_user: user, sql_admin_pass: passwd, - expected_row_count: expected_row_count, + expected_row_count: expected_row_count } end diff --git a/spec/acceptance/sqlserver_tsql_spec.rb b/spec/acceptance/sqlserver_tsql_spec.rb index 0224ab0d..a8a5801b 100644 --- a/spec/acceptance/sqlserver_tsql_spec.rb +++ b/spec/acceptance/sqlserver_tsql_spec.rb @@ -59,7 +59,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') query: @query, sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, - expected_row_count: 1, + expected_row_count: 1 } run_sql_query(run_sql_query_opts) end @@ -99,7 +99,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') query: @query, sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, - expected_row_count: 1, + expected_row_count: 1 } run_sql_query(run_sql_query_opts) end @@ -129,7 +129,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') query: @query, sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, - expected_row_count: 1, + expected_row_count: 1 } run_sql_query(run_sql_query_opts) end @@ -159,7 +159,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') query: @query, sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, - expected_row_count: 0, + expected_row_count: 0 } run_sql_query(run_sql_query_opts) end @@ -190,7 +190,7 @@ def ensure_sqlserver_database(db_name, _ensure_val = 'present') query: @query, sql_admin_user: @admin_user, sql_admin_pass: @admin_pass, - expected_row_count: 1, + expected_row_count: 1 } run_sql_query(run_sql_query_opts) end diff --git a/spec/defines/config_spec.rb b/spec/defines/config_spec.rb index 9f0d4473..cd48f323 100644 --- a/spec/defines/config_spec.rb +++ b/spec/defines/config_spec.rb @@ -12,7 +12,7 @@ { instance_name: 'MSSQLSERVER', admin_user: 'sa', - admin_pass: 'Pupp3t1@', + admin_pass: 'Pupp3t1@' } end @@ -28,7 +28,7 @@ { instance_name: 'MSSQLSERVER', admin_user: 'sa', - admin_login_type: 'SQL_LOGIN', + admin_login_type: 'SQL_LOGIN' } end @@ -45,7 +45,7 @@ { instance_name: 'MSSQLSERVER', admin_pass: 'Pupp3t1@', - admin_login_type: 'SQL_LOGIN', + admin_login_type: 'SQL_LOGIN' } end @@ -64,7 +64,7 @@ { instance_name: 'MSSQLSERVER', admin_user: 'sa', - admin_login_type: 'WINDOWS_LOGIN', + admin_login_type: 'WINDOWS_LOGIN' } end @@ -81,7 +81,7 @@ { instance_name: 'MSSQLSERVER', admin_pass: 'Pupp3t1@', - admin_login_type: 'WINDOWS_LOGIN', + admin_login_type: 'WINDOWS_LOGIN' } end diff --git a/spec/defines/database_spec.rb b/spec/defines/database_spec.rb index a03024a3..b0ba5966 100644 --- a/spec/defines/database_spec.rb +++ b/spec/defines/database_spec.rb @@ -10,7 +10,7 @@ let(:params) do { db_name: 'myTestDb', - instance: 'MSSQLSERVER', + instance: 'MSSQLSERVER' } end let(:pre_condition) do @@ -33,7 +33,7 @@ it_behaves_like 'validation error' do let(:additional_params) do { - filespec_filename: 'c:/test/test.mdf', + filespec_filename: 'c:/test/test.mdf' } end let(:raise_error_check) { %r{filespec_name must also be specified when specifying filespec_filename} } @@ -43,7 +43,7 @@ let(:additional_params) do { filespec_filename: 'c:/test/test.mdf', - filespec_name: 'OMGthisISsoReallyLongAndBoringProcessImeanAReallyOMGthisISsoReallyLongAndBoringProcessMakeItOMGthisISsoReallyLongAndBoringProcess', + filespec_name: 'OMGthisISsoReallyLongAndBoringProcessImeanAReallyOMGthisISsoReallyLongAndBoringProcessMakeItOMGthisISsoReallyLongAndBoringProcess' } end let(:raise_error_check) { "'filespec_name' expects" } @@ -93,7 +93,7 @@ let(:params) do { db_name: 'myTestDb', - instance: 'MSSQLSERVER', + instance: 'MSSQLSERVER' } end diff --git a/spec/defines/login/permissions_spec.rb b/spec/defines/login/permissions_spec.rb index 244a2b32..30f42210 100644 --- a/spec/defines/login/permissions_spec.rb +++ b/spec/defines/login/permissions_spec.rb @@ -19,7 +19,7 @@ context 'login =>' do let(:params) do { - permissions: ['SELECT'], + permissions: ['SELECT'] } end let(:raise_error_check) { %r{'login' expects a String.+ value} } @@ -49,7 +49,7 @@ context 'permissions' do let(:params) do { - login: 'loggingUser', + login: 'loggingUser' } end let(:raise_error_check) { %r{'permissions' .+ expects a String.+ value} } @@ -77,7 +77,7 @@ let(:params) do { permissions: ['SELECT'], - login: 'loggingUser', + login: 'loggingUser' } end @@ -97,7 +97,7 @@ let(:params) do { login: 'loggingUser', - permissions: ['SELECT'], + permissions: ['SELECT'] } end end @@ -159,7 +159,7 @@ let(:params) do { login: 'loggingUser', - permissions: ['SELECT'], + permissions: ['SELECT'] } end diff --git a/spec/defines/login_spec.rb b/spec/defines/login_spec.rb index f61ef8c5..28cb4297 100644 --- a/spec/defines/login_spec.rb +++ b/spec/defines/login_spec.rb @@ -10,7 +10,7 @@ let(:params) do { login: 'myTitle', - instance: 'MSSQLSERVER', + instance: 'MSSQLSERVER' } end let(:pre_condition) do @@ -62,7 +62,7 @@ let(:title) { 'myTitle' } let(:params) do { - login: 'myLogin', + login: 'myLogin' } end let(:permissions) { {} } @@ -131,7 +131,7 @@ describe 'duplicate permissions' do let(:additional_params) do { - permissions: { 'GRANT' => ['CONNECT SQL'], 'REVOKE' => ['CONNECT SQL'] }, + permissions: { 'GRANT' => ['CONNECT SQL'], 'REVOKE' => ['CONNECT SQL'] } } end let(:raise_error_check) { "Duplicate permissions found for sqlserver::login[#{title}" } diff --git a/spec/defines/role/permissions_spec.rb b/spec/defines/role/permissions_spec.rb index be5bfffc..6e3738e8 100644 --- a/spec/defines/role/permissions_spec.rb +++ b/spec/defines/role/permissions_spec.rb @@ -10,7 +10,7 @@ let(:params) do { role: 'myCustomRole', - permissions: ['INSERT', 'UPDATE', 'DELETE', 'SELECT'], + permissions: ['INSERT', 'UPDATE', 'DELETE', 'SELECT'] } end end @@ -33,7 +33,7 @@ let(:params) do { role: 'myCustomRole', - permissions: ['INSERT', 'UPDATE', 'DELETE', 'SELECT'], + permissions: ['INSERT', 'UPDATE', 'DELETE', 'SELECT'] } end @@ -72,7 +72,7 @@ describe 'DATABASE' do let(:additional_params) do { - type: 'DATABASE', + type: 'DATABASE' } end @@ -82,7 +82,7 @@ describe 'SERVER' do let(:additional_params) do { - type: 'SERVER', + type: 'SERVER' } end @@ -117,7 +117,7 @@ let(:params) do { role: 'myCustomRole', - permissions: [], + permissions: [] } end @@ -159,7 +159,7 @@ { role: 'myCustomRole', permissions: ['INSERT', 'UPDATE', 'DELETE', 'SELECT'], - instance: instance, + instance: instance } end diff --git a/spec/defines/role_spec.rb b/spec/defines/role_spec.rb index 87ccd122..82ebaf32 100644 --- a/spec/defines/role_spec.rb +++ b/spec/defines/role_spec.rb @@ -13,7 +13,7 @@ describe 'invalid' do let(:additional_params) do { - type: 'invalid', + type: 'invalid' } end let(:raise_error_check) { "'type' expects" } @@ -44,7 +44,7 @@ describe 'DATABASE' do let(:additional_params) do { - 'type' => 'DATABASE', + 'type' => 'DATABASE' } end let(:should_contain_command) do @@ -70,7 +70,7 @@ context 'database =>' do let(:additional_params) do { - 'database' => 'myCrazyDb', + 'database' => 'myCrazyDb' } end let(:sqlserver_tsql_title) { 'role-MSSQLSERVER-myCrazyDb-myCustomRole' } @@ -85,7 +85,7 @@ let(:additional_params) do { 'database' => 'myCrazyDb', - 'type' => 'DATABASE', + 'type' => 'DATABASE' } end let(:should_contain_command) do @@ -130,7 +130,7 @@ describe 'myUser' do let(:additional_params) do { - authorization: 'myUser', + authorization: 'myUser' } end let(:should_contain_command) do @@ -147,7 +147,7 @@ let(:additional_params) do { authorization: 'myUser', - type: 'DATABASE', + type: 'DATABASE' } end let(:should_contain_command) do @@ -165,7 +165,7 @@ describe 'absent' do let(:additional_params) do { - ensure: 'absent', + ensure: 'absent' } end let(:should_contain_command) do @@ -192,7 +192,7 @@ describe 'type => SERVER and members => []' do let(:additional_params) do { - members_purge: true, + members_purge: true } end let(:should_contain_command) do @@ -222,7 +222,7 @@ let(:additional_params) do { type: 'DATABASE', - members_purge: true, + members_purge: true } end let(:should_contain_command) do @@ -253,7 +253,7 @@ let(:additional_params) do { members_purge: true, - members: ['test', 'these', 'users'], + members: ['test', 'these', 'users'] } end let(:should_contain_command) do diff --git a/spec/defines/sp_configure_spec.rb b/spec/defines/sp_configure_spec.rb index e440d878..1c959407 100644 --- a/spec/defines/sp_configure_spec.rb +++ b/spec/defines/sp_configure_spec.rb @@ -10,7 +10,7 @@ let(:params) do { config_name: 'filestream access level', - value: 1, + value: 1 } end let(:pre_condition) do @@ -43,7 +43,7 @@ describe 'reconfigure => false' do let(:additional_params) do { - reconfigure: false, + reconfigure: false } end let(:should_not_contain_command) do @@ -73,7 +73,7 @@ describe 'with_override => false' do let(:additional_params) do { - with_override: false, + with_override: false } end let(:should_not_contain_command) do diff --git a/spec/defines/user/permissions_spec.rb b/spec/defines/user/permissions_spec.rb index 162be9d2..dc1ffbdc 100644 --- a/spec/defines/user/permissions_spec.rb +++ b/spec/defines/user/permissions_spec.rb @@ -20,7 +20,7 @@ let(:params) do { permissions: ['SELECT'], - database: 'loggingDb', + database: 'loggingDb' } end let(:raise_error_check) { "'user' expects a String[1, 128] value" } @@ -48,7 +48,7 @@ let(:params) do { user: 'loggingUser', - database: 'loggingDb', + database: 'loggingDb' } end let(:raise_error_check) { %r{'permissions' .+ expects a String.+ value} } @@ -78,7 +78,7 @@ { permissions: ['SELECT'], database: 'loggingDb', - user: 'loggingUser', + user: 'loggingUser' } end @@ -95,7 +95,7 @@ { permissions: ['SELECT'], database: 'loggingDb', - user: 'loggingUser', + user: 'loggingUser' } end @@ -123,7 +123,7 @@ { user: 'loggingUser', permissions: ['SELECT'], - database: 'loggingDb', + database: 'loggingDb' } end end @@ -225,7 +225,7 @@ { user: 'loggingUser', permissions: ['SELECT'], - database: 'loggingDb', + database: 'loggingDb' } end diff --git a/spec/defines/user_spec.rb b/spec/defines/user_spec.rb index a3e84cc7..81693ee8 100644 --- a/spec/defines/user_spec.rb +++ b/spec/defines/user_spec.rb @@ -217,7 +217,7 @@ describe 'duplicate permissions' do let(:additional_params) do { - permissions: { 'GRANT' => ['CONNECT SQL'], 'REVOKE' => ['CONNECT SQL'] }, + permissions: { 'GRANT' => ['CONNECT SQL'], 'REVOKE' => ['CONNECT SQL'] } } end let(:raise_error_check) { "Duplicate permissions found for sqlserver::user[#{title}" } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9c2837a8..ec79997f 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -13,7 +13,7 @@ default_facts = { puppetversion: Puppet.version, - facterversion: Facter.version, + facterversion: Facter.version } default_fact_files = [ diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index dd93fdc0..e15dd749 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -29,7 +29,7 @@ class Helper iso_opts = { folder: WIN_ISO_ROOT, file: WIN_2019_ISO, - drive_letter: 'I', + drive_letter: 'I' } # Allows litmus to use SSH, by explicitly setting specinfra # os family to windows (would fail when using ssh on windows) @@ -90,31 +90,31 @@ def base_install(sql_version) iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2012_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2014 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2014_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2016 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2016_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2017 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2017_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2019 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2019_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2022 iso_opts = { diff --git a/spec/sql_testing_helpers.rb b/spec/sql_testing_helpers.rb index 62f97980..55a986b8 100644 --- a/spec/sql_testing_helpers.rb +++ b/spec/sql_testing_helpers.rb @@ -94,31 +94,31 @@ def base_install(sql_version) iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2012_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2014 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2014_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2016 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2016_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2017 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2017_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2019 iso_opts = { folder: QA_RESOURCE_ROOT, file: SQL_2019_ISO, - drive_letter: 'H', + drive_letter: 'H' } when 2022 iso_opts = { diff --git a/spec/unit/puppet/provider/sqlserver_features_spec.rb b/spec/unit/puppet/provider/sqlserver_features_spec.rb index d8d58d86..a4f6220f 100644 --- a/spec/unit/puppet/provider/sqlserver_features_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_features_spec.rb @@ -15,7 +15,7 @@ { name: 'Base features', source: 'C:\myinstallexecs', - features: ['BC', 'SSMS'], + features: ['BC', 'SSMS'] } end let(:additional_params) { {} } @@ -41,7 +41,7 @@ @feature_params = { name: 'Base features', source: 'C:\myinstallexecs', - features: ['BC', 'SSMS'], + features: ['BC', 'SSMS'] } let(:feature_remove) { [] } let(:feature_add) { [] } @@ -142,7 +142,7 @@ feature_params = { name: 'Base features', source: 'C:\myinstallexecs', - features: [], + features: [] } @resource = Puppet::Type::Sqlserver_features.new(feature_params) @provider = provider_class.new(@resource) diff --git a/spec/unit/puppet/provider/sqlserver_instance_spec.rb b/spec/unit/puppet/provider/sqlserver_instance_spec.rb index 2f111385..67edab38 100644 --- a/spec/unit/puppet/provider/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/provider/sqlserver_instance_spec.rb @@ -27,7 +27,7 @@ 'sa_pwd' => 'SAPWD', 'security_mode' => 'SECURITYMODE', 'sql_svc_account' => 'SQLSVCACCOUNT', - 'sql_svc_password' => 'SQLSVCPASSWORD', + 'sql_svc_password' => 'SQLSVCPASSWORD' } end @@ -228,7 +228,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) { name: 'MYSQLSERVER', source: 'C:\myinstallexecs', - features: [], + features: [] } end end @@ -240,7 +240,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) { name: 'MYSQLSERVER', source: 'C:\myinstallexecs', - features: [], + features: [] } end let(:installed_features) { ['SQLEngine', 'Replication'] } @@ -253,7 +253,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) { name: 'MYSQLSERVER', source: 'C:\myinstallexecs', - features: [], + features: [] } end let(:installed_features) { ['SQLEngine', 'Replication'] } @@ -266,7 +266,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) { name: 'MYSQLSERVER', source: 'C:\myinstallexecs', - features: [], + features: [] } end let(:installed_features) { ['SQLEngine', 'Replication'] } @@ -279,7 +279,7 @@ def stub_uninstall(args, installed_features, exit_code = 0) { name: 'MYSQLSERVER', source: 'C:\myinstallexecs', - features: ['SQL'], + features: ['SQL'] } end let(:installed_features) { ['SQLEngine', 'Replication'] } diff --git a/spec/unit/puppet/sqlserver_install_context.rb b/spec/unit/puppet/sqlserver_install_context.rb index dcfc3424..3b90eb5e 100644 --- a/spec/unit/puppet/sqlserver_install_context.rb +++ b/spec/unit/puppet/sqlserver_install_context.rb @@ -15,6 +15,6 @@ def basic_args polybase_svc_account: 'nexus\polyuser', polybase_svc_password: 'P@ssword1', sql_svc_account: 'NT Service\MSSQLSERVER', - sql_sysadmin_accounts: ['localAdminAccount', 'nexus\domainUser'], + sql_sysadmin_accounts: ['localAdminAccount', 'nexus\domainUser'] } end diff --git a/spec/unit/puppet/type/sqlserver_features_spec.rb b/spec/unit/puppet/type/sqlserver_features_spec.rb index a09e18ad..85a6b11a 100644 --- a/spec/unit/puppet/type/sqlserver_features_spec.rb +++ b/spec/unit/puppet/type/sqlserver_features_spec.rb @@ -12,7 +12,7 @@ args = { name: 'Generic Features', ensure: 'present', - features: [feature_name], + features: [feature_name] } expect(Puppet).to receive(:deprecation_warning).at_least(:once) Puppet::Type.type(:sqlserver_features).new(args) diff --git a/spec/unit/puppet/type/sqlserver_instance_spec.rb b/spec/unit/puppet/type/sqlserver_instance_spec.rb index 9a9a4b92..e3d87bda 100644 --- a/spec/unit/puppet/type/sqlserver_instance_spec.rb +++ b/spec/unit/puppet/type/sqlserver_instance_spec.rb @@ -39,7 +39,7 @@ args = { name: 'MSSQLSERVER', ensure: 'present', - features: [feature_name], + features: [feature_name] } expect(Puppet).to receive(:deprecation_warning).at_least(:once) Puppet::Type.type(:sqlserver_instance).new(args) From 26db924d35c661326911a48721d4e5461f158b6a Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 11:33:30 +0100 Subject: [PATCH 48/51] (CONT-800) - fix mount_iso install --- spec/spec_helper_acceptance_local.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper_acceptance_local.rb b/spec/spec_helper_acceptance_local.rb index e15dd749..7d46cc36 100644 --- a/spec/spec_helper_acceptance_local.rb +++ b/spec/spec_helper_acceptance_local.rb @@ -23,7 +23,7 @@ class Helper RSpec.configure do |c| c.before(:suite) do - Helper.instance.run_shell('puppet module install puppetlabs-mount_iso --version 4.0.0') + Helper.instance.run_shell('puppet module install puppetlabs-mount_iso') Helper.instance.run_shell('puppet module install puppet/archive') iso_opts = { From 084c6491c83c7a352c979887f9ecfc3aee1e667d Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 12:34:07 +0100 Subject: [PATCH 49/51] (CONT-800) - Fix Acceptance --- lib/puppet/provider/sqlserver_tsql/mssql.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/sqlserver_tsql/mssql.rb b/lib/puppet/provider/sqlserver_tsql/mssql.rb index edb05a60..c5ac5b42 100644 --- a/lib/puppet/provider/sqlserver_tsql/mssql.rb +++ b/lib/puppet/provider/sqlserver_tsql/mssql.rb @@ -15,7 +15,7 @@ def run(query) def get_config(instance = resource[:instance]) config_resc = resource.catalog.resources.find do |resc| - resc.title.include?('Sqlserver::Config') && + resc.title.to_s.include?('Sqlserver::Config') && resc.original_parameters[:instance_name] =~ %r{#{instance}}i end raise("Sqlserver_tsql[#{resource.title}] was unable to retrieve the config, please ensure the catalog contains sqlserver::config{'#{resource[:instance]}':}") if config_resc.nil? From ab5b684cb3c6d28a7bc69e27f47ae1555c33b30f Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Tue, 25 Apr 2023 13:52:03 +0100 Subject: [PATCH 50/51] (CONT-800) - Remove instances of deprecated is_array --- manifests/login.pp | 8 ++++---- manifests/role.pp | 8 ++++---- manifests/user.pp | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/manifests/login.pp b/manifests/login.pp index dba55fa1..45c881f6 100644 --- a/manifests/login.pp +++ b/manifests/login.pp @@ -92,25 +92,25 @@ instance => $instance, require => Sqlserver_tsql["login-${instance}-${login}"], } - if has_key($_upermissions, 'GRANT') and is_array($_upermissions['GRANT']) { + if has_key($_upermissions, 'GRANT') and $_upermissions['GRANT'] =~ Array { sqlserver::login::permissions { "Sqlserver::Login[${title}]-GRANT-${login}": state => 'GRANT', permissions => $_upermissions['GRANT'], } } - if has_key($_upermissions, 'DENY') and is_array($_upermissions['DENY']) { + if has_key($_upermissions, 'DENY') and $_upermissions['DENY'] =~ Array { sqlserver::login::permissions { "Sqlserver::Login[${title}]-DENY-${login}": state => 'DENY', permissions => $_upermissions['DENY'], } } - if has_key($_upermissions, 'REVOKE') and is_array($_upermissions['REVOKE']) { + if has_key($_upermissions, 'REVOKE') and $_upermissions['REVOKE'] =~ Array { sqlserver::login::permissions { "Sqlserver::Login[${title}]-REVOKE-${login}": state => 'REVOKE', permissions => $_upermissions['REVOKE'], } } - if has_key($_upermissions, 'GRANT_WITH_OPTION') and is_array($_upermissions['GRANT_WITH_OPTION']) { + if has_key($_upermissions, 'GRANT_WITH_OPTION') and $_upermissions['GRANT_WITH_OPTION'] =~ Array { sqlserver::login::permissions { "Sqlserver::Login[${title}]-GRANT-WITH_GRANT_OPTION-${login}": state => 'GRANT', with_grant_option => true, diff --git a/manifests/role.pp b/manifests/role.pp index 54719d2b..82aa96fd 100644 --- a/manifests/role.pp +++ b/manifests/role.pp @@ -79,25 +79,25 @@ type => $type, require => Sqlserver_tsql[$sqlserver_tsql_title], } - if has_key($_upermissions, 'GRANT') and is_array($_upermissions['GRANT']) { + if has_key($_upermissions, 'GRANT') and $_upermissions['GRANT'] =~ Array { sqlserver::role::permissions { "Sqlserver::Role[${title}]-GRANT-${role}": state => 'GRANT', permissions => $_upermissions['GRANT'], } } - if has_key($_upermissions, 'DENY') and is_array($_upermissions['DENY']) { + if has_key($_upermissions, 'DENY') and $_upermissions['DENY'] =~ Array { sqlserver::role::permissions { "Sqlserver::Role[${title}]-DENY-${role}": state => 'DENY', permissions => $_upermissions['DENY'], } } - if has_key($_upermissions, 'REVOKE') and is_array($_upermissions['REVOKE']) { + if has_key($_upermissions, 'REVOKE') and $_upermissions['REVOKE'] =~ Array { sqlserver::role::permissions { "Sqlserver::Role[${title}]-REVOKE-${role}": state => 'REVOKE', permissions => $_upermissions['REVOKE'], } } - if has_key($_upermissions, 'GRANT_WITH_OPTION') and is_array($_upermissions['GRANT_WITH_OPTION']) { + if has_key($_upermissions, 'GRANT_WITH_OPTION') and $_upermissions['GRANT_WITH_OPTION'] =~ Array { sqlserver::role::permissions { "Sqlserver::Role[${title}]-GRANT-WITH_GRANT_OPTION-${role}": state => 'GRANT', with_grant_option => true, diff --git a/manifests/user.pp b/manifests/user.pp index 2cdf0ddd..529d466a 100644 --- a/manifests/user.pp +++ b/manifests/user.pp @@ -79,25 +79,25 @@ instance => $instance, require => Sqlserver_tsql["user-${instance}-${database}-${user}"], } - if has_key($_upermissions, 'GRANT') and is_array($_upermissions['GRANT']) { + if has_key($_upermissions, 'GRANT') and $_upermissions['GRANT'] =~ Array { sqlserver::user::permissions { "Sqlserver::User[${title}]-GRANT-${user}": state => 'GRANT', permissions => $_upermissions['GRANT'], } } - if has_key($_upermissions, 'DENY') and is_array($_upermissions['DENY']) { + if has_key($_upermissions, 'DENY') and $_upermissions['DENY'] =~ Array { sqlserver::user::permissions { "Sqlserver::User[${title}]-DENY-${user}": state => 'DENY', permissions => $_upermissions['DENY'], } } - if has_key($_upermissions, 'REVOKE') and is_array($_upermissions['REVOKE']) { + if has_key($_upermissions, 'REVOKE') and $_upermissions['REVOKE'] =~ Array { sqlserver::user::permissions { "Sqlserver::User[${title}]-REVOKE-${user}": state => 'REVOKE', permissions => $_upermissions['REVOKE'], } } - if has_key($_upermissions, 'GRANT_WITH_OPTION') and is_array($_upermissions['GRANT_WITH_OPTION']) { + if has_key($_upermissions, 'GRANT_WITH_OPTION') and $_upermissions['GRANT_WITH_OPTION'] =~ Array { sqlserver::user::permissions { "Sqlserver::User[${title}]-GRANT-WITH_GRANT_OPTION-${user}": state => 'GRANT', with_grant_option => true, From e1fc3afcccc46ea8376512be8217e88a0fae5f44 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 26 Apr 2023 08:38:06 +0100 Subject: [PATCH 51/51] (CONT-800) - Add Env variables to ci/nightly --- .github/workflows/ci.yml | 4 ++++ .github/workflows/nightly.yml | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac4d74b4..2d665b03 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,10 @@ jobs: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} + env: + PUPPET_GEM_VERSION: '~> 7.24' + FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' + steps: - name: Checkout Source uses: actions/checkout@v2 diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index c560300b..4a2c7cae 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -55,6 +55,10 @@ jobs: fail-fast: false matrix: ${{fromJson(needs.setup_matrix.outputs.matrix)}} + env: + PUPPET_GEM_VERSION: '~> 7.24' + FACTER_GEM_VERSION: 'https://github.com/puppetlabs/facter#main' + steps: - name: Checkout Source uses: actions/checkout@v2