Skip to content

Commit d6b7ad0

Browse files
authored
Merge pull request #327 from jkroepke/tcp6
Allow 4 and 6 suffix inside proto to limit ip4 or ip6 connection only.
2 parents 6c3e2ce + 05962e5 commit d6b7ad0

File tree

3 files changed

+77
-2
lines changed

3 files changed

+77
-2
lines changed

manifests/server.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
Variant[Boolean, String] $logfile = false,
137137
String $port = '1194',
138138
Optional[String] $portshare = undef,
139-
Enum['tcp', 'udp'] $proto = 'tcp',
139+
Enum['tcp', 'tcp4', 'tcp6', 'udp', 'udp4', 'udp6'] $proto = 'tcp',
140140
Enum['1', '2', '3', ''] $status_version = '',
141141
String $status_log = "/var/log/openvpn/${name}-status.log",
142142
String $server = '',

spec/defines/openvpn_server_spec.rb

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,81 @@
110110
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^rcvbuf\s+393215$}) }
111111
end
112112

113+
context 'when using udp4' do
114+
let(:params) do
115+
{
116+
'country' => 'CO',
117+
'province' => 'ST',
118+
'city' => 'Some City',
119+
'organization' => 'example.org',
120+
'email' => '[email protected]',
121+
'proto' => 'udp4'
122+
}
123+
end
124+
125+
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^proto\s+udp4$}) }
126+
end
127+
128+
context 'when using udp6' do
129+
let(:params) do
130+
{
131+
'country' => 'CO',
132+
'province' => 'ST',
133+
'city' => 'Some City',
134+
'organization' => 'example.org',
135+
'email' => '[email protected]',
136+
'proto' => 'udp6'
137+
}
138+
end
139+
140+
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^proto\s+udp6$}) }
141+
end
142+
143+
context 'when using tcp4' do
144+
let(:params) do
145+
{
146+
'country' => 'CO',
147+
'province' => 'ST',
148+
'city' => 'Some City',
149+
'organization' => 'example.org',
150+
'email' => '[email protected]',
151+
'proto' => 'tcp4'
152+
}
153+
end
154+
155+
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^proto\s+tcp4-server$}) }
156+
end
157+
158+
context 'when using tcp6' do
159+
let(:params) do
160+
{
161+
'country' => 'CO',
162+
'province' => 'ST',
163+
'city' => 'Some City',
164+
'organization' => 'example.org',
165+
'email' => '[email protected]',
166+
'proto' => 'tcp6'
167+
}
168+
end
169+
170+
it { is_expected.to contain_file('/etc/openvpn/test_server.conf').with_content(%r{^proto\s+tcp6-server$}) }
171+
end
172+
173+
context 'when using invalid value for proto' do
174+
let(:params) do
175+
{
176+
'country' => 'CO',
177+
'province' => 'ST',
178+
'city' => 'Some City',
179+
'organization' => 'example.org',
180+
'email' => '[email protected]',
181+
'proto' => 'tcp5'
182+
}
183+
end
184+
185+
it { expect { is_expected.to contain_file('/etc/openvpn/test_server') }.to raise_error(Puppet::PreformattedError) }
186+
end
187+
113188
context 'creating a server in client mode' do
114189
let(:title) { 'test_client' }
115190
let(:nobind) { false }

templates/server.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dh <%= @etc_directory -%>/openvpn/<%= @ca_name %>/keys/dh.pem
4646
crl-verify <%= @etc_directory -%>/openvpn/<%= @ca_name %>/crl.pem
4747
<% end -%>
4848
<% end -%>
49-
<% if @proto == 'tcp' -%>
49+
<% if @proto.include?('tcp') -%>
5050
proto <%= @proto %>-server
5151
<% else -%>
5252
proto <%= @proto %>

0 commit comments

Comments
 (0)