module-postgresql/spec/unit/functions/postgresql_acls_to_resources_hash_spec.rb
Ken Barber 86a0453f2f Provide new defined resources for managing pg_hba.conf
This patch provides a more advanced way of managing pg_hba rules, by providing a
defined resource to manage a pg_hba file, and a defined resource for managing
rules within such a file (pg_hba_rule).

These new resources are wrappers around ripinaar-concat, and utilise file
assemblies instead of a template to compose the pg_hba.conf file.

I've provided a function that interprets the old ip4|6acl arrays and converts
them to this new format for backwards compatibility as well.

I slightly reformatted our documentation to allow for better documentation of
defined resources in 'Usage' as well, and provided examples of how to use this
new resource.

This hopefully should go a long way to solving the PR's related to lack of full
functionality for pg_hba.conf.

Signed-off-by: Ken Barber <ken@bob.sh>
2013-02-12 00:34:42 +00:00

137 lines
3.8 KiB
Ruby

require 'spec_helper'
describe 'postgresql_acls_to_resources_hash', :type => :puppet_function do
context 'individual transform tests' do
it do
input = 'local all postgres ident'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"local",
"database"=>"all",
"user"=>"postgres",
"auth_method"=>"ident",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input = 'local all root ident'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"local",
"database"=>"all",
"user"=>"root",
"auth_method"=>"ident",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input_array = [
'local all all ident',
]
result = {
"postgresql class generated rule test 0"=>{
"type"=>"local",
"database"=>"all",
"user"=>"all",
"auth_method"=>"ident",
"order"=>"100",
},
}
should run.with_params(input_array, 'test', 100).and_return(result)
end
it do
input = 'host all all 127.0.0.1/32 md5'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"host",
"database"=>"all",
"user"=>"all",
"address"=>"127.0.0.1/32",
"auth_method"=>"md5",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input = 'host all all 0.0.0.0/0 md5'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"host",
"database"=>"all",
"user"=>"all",
"address"=>"0.0.0.0/0",
"auth_method"=>"md5",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input = 'host all all ::1/128 md5'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"host",
"database"=>"all",
"user"=>"all",
"address"=>"::1/128",
"auth_method"=>"md5",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input = 'host all all 1.1.1.1 255.255.255.0 md5'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"host",
"database"=>"all",
"user"=>"all",
"address"=>"1.1.1.1 255.255.255.0",
"auth_method"=>"md5",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
it do
input = 'host all all 1.1.1.1 255.255.255.0 ldap ldapserver=ldap.example.net ldapprefix="cn=" ldapsuffix=", dc=example, dc=net"'
result = {
"postgresql class generated rule test 0"=>{
"type"=>"host",
"database"=>"all",
"user"=>"all",
"address"=>"1.1.1.1 255.255.255.0",
"auth_method"=>"ldap",
"auth_option"=>"ldapserver=ldap.example.net ldapprefix=\"cn=\" ldapsuffix=\", dc=example, dc=net\"",
"order"=>"100",
},
}
should run.with_params([input], 'test', 100).and_return(result)
end
end
it 'should return an empty hash when input is empty array' do
should run.with_params([], 'test', 100).and_return({})
end
end