From 10f899404ef31cd05fd566da29e374a312452953 Mon Sep 17 00:00:00 2001 From: martyewings Date: Tue, 25 Apr 2023 16:01:05 +0100 Subject: [PATCH 1/2] Remove deprecated is_absolute_path function --- lib/puppet/functions/is_absolute_path.rb | 29 ------ .../parser/functions/is_absolute_path.rb | 61 ------------- .../parser/functions/is_absolute_path_spec.rb | 89 ------------------- 3 files changed, 179 deletions(-) delete mode 100644 lib/puppet/functions/is_absolute_path.rb delete mode 100644 lib/puppet/parser/functions/is_absolute_path.rb delete mode 100644 spec/unit/puppet/parser/functions/is_absolute_path_spec.rb diff --git a/lib/puppet/functions/is_absolute_path.rb b/lib/puppet/functions/is_absolute_path.rb deleted file mode 100644 index b801ecb61..000000000 --- a/lib/puppet/functions/is_absolute_path.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# @summary -# Wrapper that calls the Puppet 3.x function of the same name. -Puppet::Functions.create_function(:is_absolute_path) do - # @param scope - # The main value that will be passed to the wrapped method - # - # @param args - # Any additional values that are to be passed to the wrapped method - # - # @return [Boolea] - # A boolean value returned from the called 3.x function. - dispatch :deprecation_gen do - param 'Any', :scope - repeated_param 'Any', :args - end - # Workaround PUP-4438 (fixed: https://github.com/puppetlabs/puppet/commit/e01c4dc924cd963ff6630008a5200fc6a2023b08#diff - # -c937cc584953271bb3d3b3c2cb141790R221) to support puppet < 4.1.0 and puppet < 3.8.1. - def call(scope, *args) - manipulated_args = [scope] + args - self.class.dispatcher.dispatch(self, scope, manipulated_args) - end - - def deprecation_gen(scope, *args) - call_function('deprecation', 'is_absolute_path', 'This method is deprecated, please use match expressions with Stdlib::Compat::Absolute_Path instead. They are described at https://docs.puppet.com/puppet/latest/reference/lang_data_type.html#match-expressions.') - scope.send('function_is_absolute_path', args) - end -end diff --git a/lib/puppet/parser/functions/is_absolute_path.rb b/lib/puppet/parser/functions/is_absolute_path.rb deleted file mode 100644 index c464afa46..000000000 --- a/lib/puppet/parser/functions/is_absolute_path.rb +++ /dev/null @@ -1,61 +0,0 @@ -# frozen_string_literal: true - -# -# is_absolute_path.rb -# -module Puppet::Parser::Functions - newfunction(:is_absolute_path, type: :rvalue, arity: 1, doc: <<-'DOC') do |args| - @summary - **Deprecated:** Returns boolean true if the string represents an absolute path in the filesystem. - - This function works for windows and unix style paths. - - @example The following values will return true: - $my_path = 'C:/Program Files (x86)/Puppet Labs/Puppet' - is_absolute_path($my_path) - $my_path2 = '/var/lib/puppet' - is_absolute_path($my_path2) - $my_path3 = ['C:/Program Files (x86)/Puppet Labs/Puppet'] - is_absolute_path($my_path3) - $my_path4 = ['/var/lib/puppet'] - is_absolute_path($my_path4) - - @example The following values will return false: - is_absolute_path(true) - is_absolute_path('../var/lib/puppet') - is_absolute_path('var/lib/puppet') - $undefined = undef - is_absolute_path($undefined) - - @return [Boolean] - Returns `true` or `false` - - > **Note:* **Deprecated** Will be removed in a future version of stdlib. See - [`validate_legacy`](#validate_legacy). - DOC - function_deprecation([:is_absolute_path, 'This method is deprecated, please use the stdlib validate_legacy function, - with Stdlib::Compat::Absolute_path. There is further documentation for validate_legacy function in the README.']) - require 'puppet/util' - - path = args[0] - # This logic was borrowed from - # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/main/lib/puppet/file_serving/base.rb) - # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise. - if Puppet::Util.respond_to?(:absolute_path?) - value = (Puppet::Util.absolute_path?(path, :posix) || Puppet::Util.absolute_path?(path, :windows)) - else - # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? - # Determine in a platform-specific way whether a path is absolute. This - # defaults to the local platform if none is specified. - # Escape once for the string literal, and once for the regex. - slash = '[\\\\/]' - name = '[^\\\\/]+' - regexes = { - windows: %r{^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))}i, - posix: %r{^/}, - } - value = !!(path =~ regexes[:posix]) || !!(path =~ regexes[:windows]) # rubocop:disable Style/DoubleNegation : No alternative known - end - value - end -end diff --git a/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb b/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb deleted file mode 100644 index 097b3db1a..000000000 --- a/spec/unit/puppet/parser/functions/is_absolute_path_spec.rb +++ /dev/null @@ -1,89 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'is_absolute_path' do - let(:scope) { PuppetlabsSpec::PuppetInternals.scope } - - let(:function_args) do - [] - end - - let(:function) do - scope.function_is_absolute_path(function_args) - end - - describe 'validate arity' do - let(:function_args) do - [1, 2] - end - - it 'raises a ParseError if there is more than 1 arguments' do - -> { function }.should(raise_error(ArgumentError)) - end - end - - it 'exists' do - Puppet::Parser::Functions.function(subject).should == "function_#{subject}" - end - - # help enforce good function defination - it 'contains arity' do - end - - it 'raises a ParseError if there is less than 1 arguments' do - -> { function }.should(raise_error(ArgumentError)) - end - - describe 'should retrun true' do - let(:return_value) do - true - end - - describe 'windows' do - let(:function_args) do - ['c:\temp\test.txt'] - end - - it 'returns data' do - function.should eq(return_value) - end - end - - describe 'non-windows' do - let(:function_args) do - ['/temp/test.txt'] - end - - it 'returns data' do - function.should eq(return_value) - end - end - end - - describe 'should return false' do - let(:return_value) do - false - end - - describe 'windows' do - let(:function_args) do - ['..\temp\test.txt'] - end - - it 'returns data' do - function.should eq(return_value) - end - end - - describe 'non-windows' do - let(:function_args) do - ['../var/lib/puppet'] - end - - it 'returns data' do - function.should eq(return_value) - end - end - end -end From 03a1976af5520aa93c850defd25da38bd0fda764 Mon Sep 17 00:00:00 2001 From: martyewings Date: Tue, 25 Apr 2023 16:12:06 +0100 Subject: [PATCH 2/2] Remove deprecated validate_absolute_path test --- spec/functions/validate_absolute_path_spec.rb | 53 ------------------- 1 file changed, 53 deletions(-) delete mode 100644 spec/functions/validate_absolute_path_spec.rb diff --git a/spec/functions/validate_absolute_path_spec.rb b/spec/functions/validate_absolute_path_spec.rb deleted file mode 100644 index 4365229b9..000000000 --- a/spec/functions/validate_absolute_path_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'validate_absolute_path' do - after(:each) do - ENV.delete('STDLIB_LOG_DEPRECATIONS') - end - - # Checking for deprecation warning - it 'displays a single deprecation' do - ENV['STDLIB_LOG_DEPRECATIONS'] = 'true' - expect(scope).to receive(:warning).with(include('This method is deprecated')) - is_expected.to run.with_params('c:/') - end - - describe 'signature validation' do - it { is_expected.not_to eq(nil) } - it { is_expected.to run.with_params.and_raise_error(Puppet::ParseError, %r{wrong number of arguments}i) } - end - - describe 'valid paths handling' do - ['C:/', 'C:\\', 'C:\\WINDOWS\\System32', 'C:/windows/system32', 'X:/foo/bar', 'X:\\foo\\bar', '\\\\host\\windows', '//host/windows', '/', '/var/tmp', '/var/opt/../lib/puppet'].each do |path| - it { is_expected.to run.with_params(path) } - it { is_expected.to run.with_params(['/tmp', path]) } - end - end - - describe 'invalid path handling' do - context 'with garbage inputs' do - [ - nil, - [nil], - [nil, nil], - { 'foo' => 'bar' }, - {}, - '', - ].each do |path| - it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - end - end - - context 'with relative paths' do - ['relative1', '.', '..', './foo', '../foo', 'etc/puppetlabs/puppet', 'relative\\windows'].each do |path| - it { is_expected.to run.with_params(path).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - it { is_expected.to run.with_params([path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - it { is_expected.to run.with_params(['/tmp', path]).and_raise_error(Puppet::ParseError, %r{is not an absolute path}) } - end - end - end -end