From 109024fd916b67aebf983427bde8b8761a8d2a97 Mon Sep 17 00:00:00 2001 From: Adam Jahn Date: Sat, 11 Apr 2015 16:42:26 -0400 Subject: first set of specs --- spec/classes/samba__server_spec.rb | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 spec/classes/samba__server_spec.rb (limited to 'spec/classes/samba__server_spec.rb') diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb new file mode 100644 index 0000000..89d994f --- /dev/null +++ b/spec/classes/samba__server_spec.rb @@ -0,0 +1,9 @@ +require 'spec_helper' + +describe 'samba::server' do + let(:facts) {{ :osfamily => 'Debian' }} + + it { should contain_class('samba::server::install') } + it { should contain_class('samba::server::config') } + it { should contain_class('samba::server::service') } +end -- cgit v1.2.3 From b4e4a92ff4da6e34a8707ffb49c8ccf6ce316d2b Mon Sep 17 00:00:00 2001 From: Adam Jahn Date: Mon, 13 Apr 2015 13:28:45 -0400 Subject: more specs for samba::server use short hand for path to get specs passing --- manifests/server.pp | 6 ++---- spec/classes/samba__server_spec.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) (limited to 'spec/classes/samba__server_spec.rb') diff --git a/manifests/server.pp b/manifests/server.pp index 9eace3d..65ea660 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -45,18 +45,16 @@ class samba::server($interfaces = '', 'disable_spoolss': value => $disable_spoolss; } - file {'check_samba_user': + file {'/sbin/check_samba_user': # script checks to see if a samba account exists for a given user - path => '/sbin/check_samba_user', owner => root, group => root, mode => '0755', content => template("${module_name}/check_samba_user"), } - file {'add_samba_user': + file {'/sbin/add_samba_user': # script creates a new samba account for a given user and password - path => '/sbin/add_samba_user', owner => root, group => root, mode => '0755', diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index 89d994f..fce10bb 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -6,4 +6,21 @@ describe 'samba::server' do it { should contain_class('samba::server::install') } it { should contain_class('samba::server::config') } it { should contain_class('samba::server::service') } + + it { should contain_samba__server__option('interfaces') } + it { should contain_samba__server__option('bind interfaces only') } + it { should contain_samba__server__option('security') } + it { should contain_samba__server__option('server string') } + it { should contain_samba__server__option('unix password sync') } + it { should contain_samba__server__option('workgroup') } + it { should contain_samba__server__option('socket_options') } + it { should contain_samba__server__option('deadtime') } + it { should contain_samba__server__option('keepalive') } + it { should contain_samba__server__option('load_printers') } + it { should contain_samba__server__option('printing') } + it { should contain_samba__server__option('printcap_name') } + it { should contain_samba__server__option('disable_spoolss') } + + it { should contain_file('/sbin/check_samba_user').with_owner('root') } + it { should contain_file('/sbin/add_samba_user').with_owner('root') } end -- cgit v1.2.3 From 590d55da8dc735a9f955f6c9df7a424dd8609033 Mon Sep 17 00:00:00 2001 From: David Sheldon Date: Fri, 9 Oct 2015 18:24:22 +0100 Subject: Fix tests for all the _ options. --- spec/classes/samba__server_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'spec/classes/samba__server_spec.rb') diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index fce10bb..69fa0ec 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -13,13 +13,13 @@ describe 'samba::server' do it { should contain_samba__server__option('server string') } it { should contain_samba__server__option('unix password sync') } it { should contain_samba__server__option('workgroup') } - it { should contain_samba__server__option('socket_options') } + it { should contain_samba__server__option('socket options') } it { should contain_samba__server__option('deadtime') } it { should contain_samba__server__option('keepalive') } - it { should contain_samba__server__option('load_printers') } + it { should contain_samba__server__option('load printers') } it { should contain_samba__server__option('printing') } - it { should contain_samba__server__option('printcap_name') } - it { should contain_samba__server__option('disable_spoolss') } + it { should contain_samba__server__option('printcap name') } + it { should contain_samba__server__option('disable spoolss') } it { should contain_file('/sbin/check_samba_user').with_owner('root') } it { should contain_file('/sbin/add_samba_user').with_owner('root') } -- cgit v1.2.3 From 9d63c7be3fa57e4af93c787f8b740658ec14f1f6 Mon Sep 17 00:00:00 2001 From: Alexander Fisher Date: Fri, 22 Jan 2016 15:32:28 +0000 Subject: Remove check_samba_user and add_samba_user scripts Call the pdbedit commands directly from samba::server::user instead --- manifests/server.pp | 16 ---------------- manifests/server/user.pp | 8 +++++--- spec/classes/samba__server_spec.rb | 3 --- spec/defines/samba__server__user_spec.rb | 14 ++++++++++++++ templates/add_samba_user | 16 ---------------- templates/check_samba_user | 16 ---------------- 6 files changed, 19 insertions(+), 54 deletions(-) create mode 100644 spec/defines/samba__server__user_spec.rb delete mode 100644 templates/add_samba_user delete mode 100644 templates/check_samba_user (limited to 'spec/classes/samba__server_spec.rb') diff --git a/manifests/server.pp b/manifests/server.pp index 550659c..8a5853c 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -58,20 +58,4 @@ class samba::server($interfaces = '', 'os level': value => $os_level; 'preferred master': value => $preferred_master; } - - file {'/sbin/check_samba_user': - # script checks to see if a samba account exists for a given user - owner => root, - group => root, - mode => '0755', - content => template("${module_name}/check_samba_user"), - } - - file {'/sbin/add_samba_user': - # script creates a new samba account for a given user and password - owner => root, - group => root, - mode => '0755', - content => template("${module_name}/add_samba_user"), - } } diff --git a/manifests/server/user.pp b/manifests/server/user.pp index b8f2e61..d10a602 100644 --- a/manifests/server/user.pp +++ b/manifests/server/user.pp @@ -4,10 +4,12 @@ define samba::server::user ( $password, $user_name = $name, ) { + require ::samba::server::install + exec { "add smb account for ${user_name}": - command => "/sbin/add_samba_user '${user_name}' '${password}'" , - unless => "/sbin/check_samba_user '${user_name}'" , + command => "/bin/echo -e '${password}\\n${password}\\n' | /usr/bin/pdbedit --password-from-stdin -a '${user_name}'", + unless => "/usr/bin/pdbedit '${user_name}'", require => [ User[$user_name] ], - notify => Class['samba::server::service'] + notify => Class['samba::server::service'] #TODO: Is this really required?? } } diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index 69fa0ec..dbf840a 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -20,7 +20,4 @@ describe 'samba::server' do it { should contain_samba__server__option('printing') } it { should contain_samba__server__option('printcap name') } it { should contain_samba__server__option('disable spoolss') } - - it { should contain_file('/sbin/check_samba_user').with_owner('root') } - it { should contain_file('/sbin/add_samba_user').with_owner('root') } end diff --git a/spec/defines/samba__server__user_spec.rb b/spec/defines/samba__server__user_spec.rb new file mode 100644 index 0000000..c7ae00c --- /dev/null +++ b/spec/defines/samba__server__user_spec.rb @@ -0,0 +1,14 @@ +require 'spec_helper' + +describe 'samba::server::user', :type => :define do + let(:title) { 'test_user' } + let(:params) {{ :password => 'secret' }} + + it { is_expected.to contain_samba__server__user('test_user') } + it { is_expected.to contain_exec('add smb account for test_user').with( + :command => '/bin/echo -e \'secret\nsecret\n\' | /usr/bin/pdbedit --password-from-stdin -a \'test_user\'', + :unless => '/usr/bin/pdbedit \'test_user\'', + :require => 'User[test_user]', + :notify => 'Class[Samba::Server::Service]' + ) } +end diff --git a/templates/add_samba_user b/templates/add_samba_user deleted file mode 100644 index cc1d56b..0000000 --- a/templates/add_samba_user +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This script adds a samba account for a given user and password -# call as: -# > add_samba_user "USERNAME" "PASSWORD" - -/bin/echo -e "$2\n$2\n" | sudo /usr/bin/pdbedit -a "$1" -t 1>/dev/null -results=$? - -if [ $results = 0 ]; then - echo "added samba account for '$1'" -else - echo "could not add samba account for '$1'" -fi - -exit $results diff --git a/templates/check_samba_user b/templates/check_samba_user deleted file mode 100644 index 431c3c4..0000000 --- a/templates/check_samba_user +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash - -# This script checks to see if a given user account exists on samba -# if so, it returns 0 -# otherwise it returns 1 - -sudo /usr/bin/pdbedit -L | egrep -q "^$1:" -exists=$? - -if [ $exists = 0 ]; then - echo "'$1' is a samba user" -else - echo "no samba account matching '$1'" -fi - -exit $exists -- cgit v1.2.3 From 6c90437c34e749d42b0041097bd12747d63aad4c Mon Sep 17 00:00:00 2001 From: Jirgn Mssnr Date: Mon, 22 Feb 2016 13:38:48 +0100 Subject: added test for share definition in via samba::server --- spec/classes/samba__server_spec.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'spec/classes/samba__server_spec.rb') diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index dbf840a..d19fe6a 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -20,4 +20,24 @@ describe 'samba::server' do it { should contain_samba__server__option('printing') } it { should contain_samba__server__option('printcap name') } it { should contain_samba__server__option('disable spoolss') } + + context 'with hiera shares hash' do + let(:params) {{ + 'shares' => { + 'testShare' => { + 'path' => '/path/to/some/share', + 'browsable' => true, + 'writable' => true, + 'guest_ok' => true, + 'guest_only' => true, + }, + 'testShare2' => { + 'path' => '/some/other/path' + } + } + }} + it { should contain_samba__server__share( 'testShare' ) } + it { should contain_samba__server__share( 'testShare2' ) } + end + end -- cgit v1.2.3 From 0385193ee30c830e81be53b1d7484ae27cdd2b85 Mon Sep 17 00:00:00 2001 From: Jirgn Mssnr Date: Mon, 22 Feb 2016 13:47:19 +0100 Subject: added param users for use in hiera added tests for samba::server::users --- manifests/server.pp | 4 +++- spec/classes/samba__server_spec.rb | 27 +++++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) (limited to 'spec/classes/samba__server_spec.rb') diff --git a/manifests/server.pp b/manifests/server.pp index 59d5d51..cbc61a9 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -20,7 +20,8 @@ class samba::server($interfaces = '', $os_level = '', $preferred_master = '', $bind_interfaces_only = 'yes', - $shares = {},) { + $shares = {}, + $users = {}, ) { include samba::server::install include samba::server::config @@ -63,4 +64,5 @@ class samba::server($interfaces = '', } create_resources(samba::server::share, $shares) + create_resources(samba::server::user, $users) } diff --git a/spec/classes/samba__server_spec.rb b/spec/classes/samba__server_spec.rb index d19fe6a..46c5b15 100644 --- a/spec/classes/samba__server_spec.rb +++ b/spec/classes/samba__server_spec.rb @@ -36,8 +36,31 @@ describe 'samba::server' do } } }} - it { should contain_samba__server__share( 'testShare' ) } - it { should contain_samba__server__share( 'testShare2' ) } + it { + should contain_samba__server__share( 'testShare' ).with({ + 'path' => '/path/to/some/share', + 'browsable' => true, + 'writable' => true, + 'guest_ok' => true, + 'guest_only' => true, + }) + } + it { should contain_samba__server__share( 'testShare2' ).with_path('/some/other/path') } + end + + context 'with hiera users hash' do + let(:params) {{ + 'users' => { + 'testUser' => { + 'password' => 'testpass01' + }, + 'testUser2' => { + 'password' => 'testpass02' + } + } + }} + it { should contain_samba__server__user( 'testUser' ).with_password('testpass01') } + it { should contain_samba__server__user( 'testUser2' ).with_password('testpass02') } end end -- cgit v1.2.3