1
1
local fio = require (' fio' )
2
2
local json = require (' json' )
3
3
local helpers = require (' test.helpers' )
4
- local http_client = require (' http.client' )
4
+ local http_client = require (' http.client' ): new ()
5
5
local server = require (' test.helpers.server' )
6
6
7
7
local t = require (' luatest' )
@@ -17,6 +17,7 @@ g.before_each(function(cg)
17
17
18
18
fio .copytree (" .rocks" , fio .pathjoin (cg .workdir , " .rocks" ))
19
19
fio .copytree (" roles" , fio .pathjoin (cg .workdir , " roles" ))
20
+ fio .copytree (fio .pathjoin (" test" , " ssl_data" ), fio .pathjoin (cg .workdir , " ssl_data" ))
20
21
21
22
cg .router = server :new ({
22
23
config_file = fio .abspath (fio .pathjoin (' test' , ' entrypoint' , ' config.yaml' )),
@@ -36,8 +37,8 @@ g.after_each(function(cg)
36
37
fio .rmtree (cg .workdir )
37
38
end )
38
39
39
- local function assert_json (uri )
40
- local response = http_client . get (uri )
40
+ local function assert_json (uri , tls_opts )
41
+ local response = http_client : get (uri , tls_opts )
41
42
t .assert_equals (response .status , 200 )
42
43
t .assert (response .body )
43
44
@@ -53,8 +54,8 @@ local function assert_json(uri)
53
54
t .assert (found )
54
55
end
55
56
56
- local function assert_prometheus (uri )
57
- local response = http_client . get (uri )
57
+ local function assert_prometheus (uri , tls_opts )
58
+ local response = http_client : get (uri , tls_opts )
58
59
t .assert_equals (response .status , 200 )
59
60
t .assert (response .body )
60
61
@@ -66,11 +67,11 @@ local function assert_prometheus(uri)
66
67
t .assert_not (ok )
67
68
end
68
69
69
- local function assert_observed (host , path )
70
+ local function assert_observed (host , path , tls_opts )
70
71
-- Trigger observation.
71
- http_client . get (host .. path )
72
+ http_client : get (host .. path , tls_opts )
72
73
73
- local response = http_client . get (host .. path )
74
+ local response = http_client : get (host .. path , tls_opts )
74
75
t .assert_equals (response .status , 200 )
75
76
t .assert (response .body )
76
77
@@ -80,11 +81,11 @@ local function assert_observed(host, path)
80
81
t .assert_not (ok )
81
82
end
82
83
83
- local function assert_not_observed (host , path )
84
+ local function assert_not_observed (host , path , tls_opts )
84
85
-- Trigger observation.
85
- http_client . get (host .. path )
86
+ http_client : get (host .. path , tls_opts )
86
87
87
- local response = http_client . get (host .. path )
88
+ local response = http_client : get (host .. path , tls_opts )
88
89
t .assert_equals (response .status , 200 )
89
90
t .assert (response .body )
90
91
@@ -121,3 +122,18 @@ g.test_endpoints = function()
121
122
assert_not_observed (" http://127.0.0.1:8086" , " /metrics/prometheus" )
122
123
assert_observed (" http://127.0.0.1:8086" , " /metrics/observed/prometheus/1" )
123
124
end
125
+
126
+ g .test_endpoint_with_tls = function (cg )
127
+ local client_tls_opts = {
128
+ ca_file = fio .pathjoin (cg .workdir , ' ssl_data' , ' ca.crt' ),
129
+ ssl_cert = fio .pathjoin (cg .workdir , ' ssl_data' , ' client.crt' ),
130
+ ssl_key = fio .pathjoin (cg .workdir , ' ssl_data' , ' client.key' ),
131
+ }
132
+
133
+ assert_prometheus (" https://localhost:8087/metrics/prometheus" , client_tls_opts )
134
+ assert_prometheus (" https://localhost:8087/metrics/prometheus/" , client_tls_opts )
135
+ assert_json (" https://localhost:8087/metrics/json" , client_tls_opts )
136
+ assert_json (" https://localhost:8087/metrics/json/" , client_tls_opts )
137
+ assert_not_observed (" https://localhost:8087" , " /metrics/prometheus" , client_tls_opts )
138
+ assert_observed (" https://localhost:8087" , " /metrics/observed/prometheus/1" , client_tls_opts )
139
+ end
0 commit comments