Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/puppet/type/wildfly_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -44,7 +44,7 @@

newparam(:secure) do
desc 'Use TLS to connect with the management API'
defaultto false
defaultto false
end

newparam(:recursive) do
Expand Down
41 changes: 41 additions & 0 deletions spec/unit/puppet/type/wildfly_resource_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Loading