From ab84e4766e171351f282e884d66f0d123737be07 Mon Sep 17 00:00:00 2001 From: g42-dev <250489233+g42-dev@users.noreply.github.com> Date: Mon, 29 Jun 2026 11:01:26 +0200 Subject: [PATCH] Fix wildfly_resource path validation regex Update the regex in wildfly_resource to allow forward slashes, dots, colons, and dashes in unquoted values. The previous implementation was too restrictive and failed to validate standard Wildfly CLI paths, such as file paths or datasources (e.g., data-source=java:jboss/datasources/ExampleDS). This change ensures valid paths are accepted while maintaining strict validation for the overall key=value structure. --- lib/puppet/type/wildfly_resource.rb | 4 +- .../unit/puppet/type/wildfly_resource_spec.rb | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 spec/unit/puppet/type/wildfly_resource_spec.rb diff --git a/lib/puppet/type/wildfly_resource.rb b/lib/puppet/type/wildfly_resource.rb index c5ec8ad8..5dc7e0e1 100644 --- a/lib/puppet/type/wildfly_resource.rb +++ b/lib/puppet/type/wildfly_resource.rb @@ -14,7 +14,7 @@ isnamevar validate do |value| - raise("Invalid resource path #{value}") unless value =~ %r{(\/[\w\-]+=[\w\-]+)} + raise("Invalid resource path #{value}") unless value =~ %r{\A(?:/[\w.-]+=(?:[\w.:/-]+|"[^"\\]*(?:\\.[^"\\]*)*"))+\z} end end @@ -44,7 +44,7 @@ newparam(:secure) do desc 'Use TLS to connect with the management API' - defaultto false + defaultto false end newparam(:recursive) do diff --git a/spec/unit/puppet/type/wildfly_resource_spec.rb b/spec/unit/puppet/type/wildfly_resource_spec.rb new file mode 100644 index 00000000..fefa4690 --- /dev/null +++ b/spec/unit/puppet/type/wildfly_resource_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe Puppet::Type.type(:wildfly_resource) do + let(:resource_class) { Puppet::Type.type(:wildfly_resource) } + + describe 'path validation' do + context 'with valid paths' do + [ + '/system-property="app/config/path"', + '/system-property=log4j2.formatMsgNoLookups', + '/subsystem=modcluster/mod-cluster-config=configuration', + '/subsystem=datasources/data-source=java:jboss/datasources/ExampleDS', + '/core-service=management/security-realm=ApplicationRealm/server-identity=ssl', + '/subsystem=undertow/server=default-server/host=default-host/location=" / "', + ].each do |path| + it "accepts #{path}" do + expect do + resource_class.new(title: path, state: { 'value' => 'true' }) + end.not_to raise_error + end + end + end + + context 'with invalid paths' do + [ + '/subsystem=modcluster/key=value=extra', + '/subsystem=modcluster/invalid!key=value', + '/subsystem=modcluster/key="unclosed-quote', + 'subsystem=modcluster', + '/subsystem', + '/subsystem=modcluster/mod-cluster-config=', + ].each do |path| + it "rejects #{path}" do + expect do + resource_class.new(title: path, state: { 'value' => 'true' }) + end.to raise_error(Puppet::Error, %r{Invalid resource path}) + end + end + end + end +end