Skip to content

Commit 0736446

Browse files
committed
roles: support ssl_verify_client option
Since http server supports a new `ssl_verify_client` option it is necessary to support it in role api as well. This patch introduces a new config parameter in httpd role with the same `ssl_verify_client` name. Closes #207
1 parent 4c518a0 commit 0736446

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed

roles/httpd.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ local function parse_params(node)
104104
ssl_password_file = node.ssl_password_file,
105105
ssl_ca_file = node.ssl_ca_file,
106106
ssl_ciphers = node.ssl_ciphers,
107+
ssl_verify_client = node.ssl_verify_client,
107108
}
108109
end
109110

test/integration/httpd_role_test.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,59 @@ g.test_enable_tls_on_config_reload = function(cg)
255255
local resp = http_client:get('http://localhost:13000/ping')
256256
t.assert_equals(resp.status, 444, 'response not 444')
257257
end
258+
259+
g.test_ssl_verify_client = function(cg)
260+
t.skip_if(not cg.params.use_tls, 'tls config required')
261+
262+
local cfg = table.copy(tls_config)
263+
264+
cfg.groups['group-001'].replicasets['replicaset-001'].roles_cfg['roles.httpd'].default
265+
.ssl_ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt')
266+
cfg.groups['group-001'].replicasets['replicaset-001'].roles_cfg['roles.httpd'].default
267+
.ssl_verify_client = "on"
268+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(cfg))
269+
local _, err = cg.server:eval("require('config'):reload()")
270+
t.assert_not(err)
271+
272+
t.assert_error_msg_contains(helpers.CONNECTION_REFUSED_ERR_MSG, function()
273+
http_client:get('https://localhost:13000/ping', {
274+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt')
275+
})
276+
end)
277+
278+
local resp = http_client:get('https://localhost:13000/ping', {
279+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt'),
280+
ssl_cert = fio.pathjoin(ssl_data_dir, 'client.crt'),
281+
ssl_key = fio.pathjoin(ssl_data_dir, 'client.key'),
282+
})
283+
t.assert_equals(resp.status, 200, 'response not 200')
284+
t.assert_equals(resp.body, 'pong')
285+
286+
cfg.groups['group-001'].replicasets['replicaset-001'].roles_cfg['roles.httpd'].default
287+
.ssl_verify_client = "optional"
288+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(cfg))
289+
_, err = cg.server:eval("require('config'):reload()")
290+
t.assert_not(err)
291+
292+
t.assert_error_msg_contains(helpers.CONNECTION_REFUSED_ERR_MSG, function()
293+
http_client:get('https://localhost:13000/ping', {
294+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt'),
295+
ssl_cert = fio.pathjoin(ssl_data_dir, 'bad_client.crt'),
296+
ssl_key = fio.pathjoin(ssl_data_dir, 'bad_client.key'),
297+
})
298+
end)
299+
300+
resp = http_client:get('https://localhost:13000/ping', {
301+
ca_file = fio.pathjoin(ssl_data_dir, 'ca.crt'),
302+
ssl_cert = fio.pathjoin(ssl_data_dir, 'client.crt'),
303+
ssl_key = fio.pathjoin(ssl_data_dir, 'client.key'),
304+
})
305+
t.assert_equals(resp.status, 200, 'response not 200')
306+
t.assert_equals(resp.body, 'pong')
307+
end
308+
309+
g.after_test('test_ssl_verify_client', function(cg)
310+
treegen.write_file(cg.server.chdir, 'config.yaml', yaml.encode(tls_config))
311+
local _, err = cg.server:eval("require('config'):reload()")
312+
t.assert_not(err)
313+
end)

test/unit/httpd_role_test.lua

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,24 @@ local validation_cases = {
226226
},
227227
},
228228
err = "log_requests option should be a string",
229+
},
230+
["ssl_verify_client_invalid_type"] = {
231+
cfg = {
232+
server = {
233+
listen = "localhost:123",
234+
ssl_verify_client = 1,
235+
}
236+
},
237+
err = "ssl_verify_client option must be a string",
238+
},
239+
["ssl_verify_client_invalid_value"] = {
240+
cfg = {
241+
server = {
242+
listen = "localhost:123",
243+
ssl_verify_client = "unknown",
244+
}
245+
},
246+
err = '"unknown" option not exists. Available options: "on", "off", "optional"',
229247
}
230248
}
231249

0 commit comments

Comments
 (0)