From 914df896d915cea5acade2732526d3bbc75b176d Mon Sep 17 00:00:00 2001 From: mh Date: Tue, 1 Nov 2016 21:29:31 +0100 Subject: make it possible to also add pregenerated private keys for onion services or even let them pregenerate on the fly --- spec/defines/daemon_hidden_service_spec.rb | 122 +++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 spec/defines/daemon_hidden_service_spec.rb (limited to 'spec/defines') diff --git a/spec/defines/daemon_hidden_service_spec.rb b/spec/defines/daemon_hidden_service_spec.rb new file mode 100644 index 0000000..7a3aae6 --- /dev/null +++ b/spec/defines/daemon_hidden_service_spec.rb @@ -0,0 +1,122 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) +require 'openssl' + +describe 'tor::daemon::hidden_service', :type => 'define' do + let(:default_facts) { + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + } + } + let(:title){ 'test_os' } + let(:facts){ default_facts } + let(:pre_condition){'Exec{path => "/bin"} + include tor::daemon' } + describe 'with standard' do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with( + :ensure => 'present', + :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, + :order => '05', + :target => '/etc/tor/torrc', + )} + it { is_expected.to_not contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with( + :ensure => 'present', + :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, + :order => '05', + :target => '/etc/tor/torrc', + )} + it { is_expected.to_not contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + end + context 'with differt port params' do + let(:params){ + { + :ports => ['25','443 192.168.0.1:8443'] + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 25 127.0.0.1:25/) } + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 443 192.168.0.1:8443/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + end + context 'with private_key' do + let(:params){ + { + :ports => ['80'], + :private_key => OpenSSL::PKey::RSA.generate(1024).to_s, + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } + it { is_expected.to contain_file('/var/lib/tor/test_os').with( + :ensure => 'directory', + :purge => true, + :force => true, + :recurse => true, + :owner => 'toranon', + :group => 'toranon', + :mode => '0750', + :require => 'Package[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( + :content => /^[a-z2-7]{16}\.onion\n/, + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + end + context 'with private key to generate' do + let(:params){ + { + :ports => ['80'], + :private_key_name => 'test_os', + :private_key_store_path => File.expand_path(File.join(File.dirname(__FILE__),'..','tmp')), + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } + it { is_expected.to contain_file('/var/lib/tor/test_os').with( + :ensure => 'directory', + :purge => true, + :force => true, + :recurse => true, + :owner => 'toranon', + :group => 'toranon', + :mode => '0750', + :require => 'Package[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( + :content => /^[a-z2-7]{16}\.onion\n/, + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + end + end +end -- cgit v1.2.3 From 34ef388fcfc92d37faad08ca9216d787a53e186c Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 4 Nov 2016 15:17:40 +0100 Subject: rename hidden service to onion service to follow the new naming conventions --- spec/defines/daemon_hidden_service_spec.rb | 122 ----------------------------- spec/defines/daemon_onion_service_spec.rb | 122 +++++++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 122 deletions(-) delete mode 100644 spec/defines/daemon_hidden_service_spec.rb create mode 100644 spec/defines/daemon_onion_service_spec.rb (limited to 'spec/defines') diff --git a/spec/defines/daemon_hidden_service_spec.rb b/spec/defines/daemon_hidden_service_spec.rb deleted file mode 100644 index 7a3aae6..0000000 --- a/spec/defines/daemon_hidden_service_spec.rb +++ /dev/null @@ -1,122 +0,0 @@ -require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) -require 'openssl' - -describe 'tor::daemon::hidden_service', :type => 'define' do - let(:default_facts) { - { - :osfamily => 'RedHat', - :operatingsystem => 'CentOS', - } - } - let(:title){ 'test_os' } - let(:facts){ default_facts } - let(:pre_condition){'Exec{path => "/bin"} - include tor::daemon' } - describe 'with standard' do - it { is_expected.to compile.with_all_deps } - - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with( - :ensure => 'present', - :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, - :order => '05', - :target => '/etc/tor/torrc', - )} - it { is_expected.to_not contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort/) } - it { is_expected.to_not contain_file('/var/lib/tor/test_os') } - context 'on Debian' do - let(:facts) { - { - :osfamily => 'Debian', - :operatingsystem => 'Debian', - } - } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with( - :ensure => 'present', - :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, - :order => '05', - :target => '/etc/tor/torrc', - )} - it { is_expected.to_not contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort/) } - it { is_expected.to_not contain_file('/var/lib/tor/test_os') } - end - context 'with differt port params' do - let(:params){ - { - :ports => ['25','443 192.168.0.1:8443'] - } - } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 25 127.0.0.1:25/) } - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 443 192.168.0.1:8443/) } - it { is_expected.to_not contain_file('/var/lib/tor/test_os') } - end - context 'with private_key' do - let(:params){ - { - :ports => ['80'], - :private_key => OpenSSL::PKey::RSA.generate(1024).to_s, - } - } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } - it { is_expected.to contain_file('/var/lib/tor/test_os').with( - :ensure => 'directory', - :purge => true, - :force => true, - :recurse => true, - :owner => 'toranon', - :group => 'toranon', - :mode => '0750', - :require => 'Package[tor]', - )} - it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( - :content => /^[a-z2-7]{16}\.onion\n/, - :owner => 'toranon', - :group => 'toranon', - :mode => '0600', - :notify => 'Service[tor]', - )} - it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( - :owner => 'toranon', - :group => 'toranon', - :mode => '0600', - :notify => 'Service[tor]', - )} - end - context 'with private key to generate' do - let(:params){ - { - :ports => ['80'], - :private_key_name => 'test_os', - :private_key_store_path => File.expand_path(File.join(File.dirname(__FILE__),'..','tmp')), - } - } - it { is_expected.to compile.with_all_deps } - it { is_expected.to contain_concat__fragment('05.hidden_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } - it { is_expected.to contain_file('/var/lib/tor/test_os').with( - :ensure => 'directory', - :purge => true, - :force => true, - :recurse => true, - :owner => 'toranon', - :group => 'toranon', - :mode => '0750', - :require => 'Package[tor]', - )} - it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( - :content => /^[a-z2-7]{16}\.onion\n/, - :owner => 'toranon', - :group => 'toranon', - :mode => '0600', - :notify => 'Service[tor]', - )} - it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( - :owner => 'toranon', - :group => 'toranon', - :mode => '0600', - :notify => 'Service[tor]', - )} - end - end -end diff --git a/spec/defines/daemon_onion_service_spec.rb b/spec/defines/daemon_onion_service_spec.rb new file mode 100644 index 0000000..bf9641d --- /dev/null +++ b/spec/defines/daemon_onion_service_spec.rb @@ -0,0 +1,122 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) +require 'openssl' + +describe 'tor::daemon::onion_service', :type => 'define' do + let(:default_facts) { + { + :osfamily => 'RedHat', + :operatingsystem => 'CentOS', + } + } + let(:title){ 'test_os' } + let(:facts){ default_facts } + let(:pre_condition){'Exec{path => "/bin"} + include tor::daemon' } + describe 'with standard' do + it { is_expected.to compile.with_all_deps } + + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with( + :ensure => 'present', + :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, + :order => '05', + :target => '/etc/tor/torrc', + )} + it { is_expected.to_not contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + :operatingsystem => 'Debian', + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with( + :ensure => 'present', + :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, + :order => '05', + :target => '/etc/tor/torrc', + )} + it { is_expected.to_not contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + end + context 'with differt port params' do + let(:params){ + { + :ports => ['25','443 192.168.0.1:8443'] + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 25 127.0.0.1:25/) } + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 443 192.168.0.1:8443/) } + it { is_expected.to_not contain_file('/var/lib/tor/test_os') } + end + context 'with private_key' do + let(:params){ + { + :ports => ['80'], + :private_key => OpenSSL::PKey::RSA.generate(1024).to_s, + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } + it { is_expected.to contain_file('/var/lib/tor/test_os').with( + :ensure => 'directory', + :purge => true, + :force => true, + :recurse => true, + :owner => 'toranon', + :group => 'toranon', + :mode => '0750', + :require => 'Package[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( + :content => /^[a-z2-7]{16}\.onion\n/, + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + end + context 'with private key to generate' do + let(:params){ + { + :ports => ['80'], + :private_key_name => 'test_os', + :private_key_store_path => File.expand_path(File.join(File.dirname(__FILE__),'..','tmp')), + } + } + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with_content(/^HiddenServicePort 80 127.0.0.1:80/) } + it { is_expected.to contain_file('/var/lib/tor/test_os').with( + :ensure => 'directory', + :purge => true, + :force => true, + :recurse => true, + :owner => 'toranon', + :group => 'toranon', + :mode => '0750', + :require => 'Package[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( + :content => /^[a-z2-7]{16}\.onion\n/, + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + it { is_expected.to contain_file('/var/lib/tor/test_os/private_key').with( + :owner => 'toranon', + :group => 'toranon', + :mode => '0600', + :notify => 'Service[tor]', + )} + end + end +end -- cgit v1.2.3 From bf16597ec2c0ad155527742fe07e655f555d7f62 Mon Sep 17 00:00:00 2001 From: mh Date: Fri, 4 Nov 2016 18:52:20 +0100 Subject: fix tests --- spec/defines/daemon_onion_service_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'spec/defines') diff --git a/spec/defines/daemon_onion_service_spec.rb b/spec/defines/daemon_onion_service_spec.rb index bf9641d..fba8efd 100644 --- a/spec/defines/daemon_onion_service_spec.rb +++ b/spec/defines/daemon_onion_service_spec.rb @@ -67,7 +67,7 @@ describe 'tor::daemon::onion_service', :type => 'define' do :recurse => true, :owner => 'toranon', :group => 'toranon', - :mode => '0750', + :mode => '0600', :require => 'Package[tor]', )} it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( @@ -101,7 +101,7 @@ describe 'tor::daemon::onion_service', :type => 'define' do :recurse => true, :owner => 'toranon', :group => 'toranon', - :mode => '0750', + :mode => '0600', :require => 'Package[tor]', )} it { is_expected.to contain_file('/var/lib/tor/test_os/hostname').with( -- cgit v1.2.3 From 1fcbe72115d57d53fced2777c8b54a4ee4ec17e9 Mon Sep 17 00:00:00 2001 From: mh Date: Wed, 30 Aug 2017 18:30:12 +0200 Subject: make it work with newer concat module --- spec/defines/daemon_onion_service_spec.rb | 2 -- 1 file changed, 2 deletions(-) (limited to 'spec/defines') diff --git a/spec/defines/daemon_onion_service_spec.rb b/spec/defines/daemon_onion_service_spec.rb index fba8efd..95be8c4 100644 --- a/spec/defines/daemon_onion_service_spec.rb +++ b/spec/defines/daemon_onion_service_spec.rb @@ -16,7 +16,6 @@ describe 'tor::daemon::onion_service', :type => 'define' do it { is_expected.to compile.with_all_deps } it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with( - :ensure => 'present', :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, :order => '05', :target => '/etc/tor/torrc', @@ -32,7 +31,6 @@ describe 'tor::daemon::onion_service', :type => 'define' do } it { is_expected.to compile.with_all_deps } it { is_expected.to contain_concat__fragment('05.onion_service.test_os').with( - :ensure => 'present', :content => /HiddenServiceDir \/var\/lib\/tor\/test_os/, :order => '05', :target => '/etc/tor/torrc', -- cgit v1.2.3