summaryrefslogtreecommitdiff
path: root/spec/defines/daemon_onion_service_spec.rb
blob: 95be8c4f267e31fd0e20f550f14916e7a6c5cd12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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(
      :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(
        :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    => '0600',
        :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    => '0600',
        :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