13
13
"configs/second.key" ,
14
14
"configs/ECcert.crt" ,
15
15
"configs/ECcert.key" ,
16
+ "configs/WithPassPhrase.crt" ,
17
+ "configs/WithPassPhrase.key" ,
16
18
"configs/cert.xml" ,
17
19
],
18
20
)
21
+ PASS_PHRASE_TEMPLATE = """<privateKeyPassphraseHandler>
22
+ <name>KeyFileHandler</name>
23
+ <options>
24
+ <password>{pass_phrase}</password>
25
+ </options>
26
+ </privateKeyPassphraseHandler>
27
+ """
19
28
20
29
21
30
@pytest .fixture (scope = "module" , autouse = True )
@@ -27,7 +36,7 @@ def started_cluster():
27
36
cluster .shutdown ()
28
37
29
38
30
- def change_config_to_key (name ):
39
+ def change_config_to_key (name , pass_phrase = "" ):
31
40
"""
32
41
* Generate config with certificate/key name from args.
33
42
* Reload config.
@@ -48,21 +57,23 @@ def change_config_to_key(name):
48
57
<cacheSessions>true</cacheSessions>
49
58
<disableProtocols>sslv2,sslv3</disableProtocols>
50
59
<preferServerCiphers>true</preferServerCiphers>
60
+ {pass_phrase}
51
61
</server>
52
62
</openSSL>
53
63
</clickhouse>
54
64
EOF""" .format (
55
- cur_name = name
65
+ cur_name = name , pass_phrase = pass_phrase
56
66
),
57
67
]
58
68
)
59
69
node .query ("SYSTEM RELOAD CONFIG" )
60
70
61
71
62
- def test_first_than_second_cert ():
63
- """Consistently set first key and check that only it will be accepted, then repeat same for second key."""
72
+ def check_certificate_switch (
73
+ first , second , pass_phrase_first = "" , pass_phrase_second = ""
74
+ ):
64
75
# Set first key
65
- change_config_to_key (" first" )
76
+ change_config_to_key (first , pass_phrase_first )
66
77
67
78
# Command with correct certificate
68
79
assert (
@@ -71,9 +82,7 @@ def test_first_than_second_cert():
71
82
"curl" ,
72
83
"--silent" ,
73
84
"--cacert" ,
74
- "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
75
- cur_name = "first"
76
- ),
85
+ "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (cur_name = first ),
77
86
"https://localhost:8443/" ,
78
87
]
79
88
)
@@ -90,7 +99,7 @@ def test_first_than_second_cert():
90
99
"--silent" ,
91
100
"--cacert" ,
92
101
"/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
93
- cur_name = " second"
102
+ cur_name = second
94
103
),
95
104
"https://localhost:8443/" ,
96
105
]
@@ -100,7 +109,7 @@ def test_first_than_second_cert():
100
109
assert True
101
110
102
111
# Change to other key
103
- change_config_to_key (" second" )
112
+ change_config_to_key (second , pass_phrase_second )
104
113
105
114
# Command with correct certificate
106
115
assert (
@@ -110,7 +119,7 @@ def test_first_than_second_cert():
110
119
"--silent" ,
111
120
"--cacert" ,
112
121
"/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
113
- cur_name = " second"
122
+ cur_name = second
114
123
),
115
124
"https://localhost:8443/" ,
116
125
]
@@ -126,9 +135,7 @@ def test_first_than_second_cert():
126
135
"curl" ,
127
136
"--silent" ,
128
137
"--cacert" ,
129
- "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
130
- cur_name = "first"
131
- ),
138
+ "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (cur_name = first ),
132
139
"https://localhost:8443/" ,
133
140
]
134
141
)
@@ -137,59 +144,18 @@ def test_first_than_second_cert():
137
144
assert True
138
145
139
146
140
- def test_ECcert_reload ():
141
- # Set first key
142
- change_config_to_key ("first" )
147
+ def test_first_than_second_cert ():
148
+ """Consistently set first key and check that only it will be accepted, then repeat same for second key."""
149
+ check_certificate_switch ("first" , "second " )
143
150
144
- # Command with correct certificate
145
- assert (
146
- node .exec_in_container (
147
- [
148
- "curl" ,
149
- "--silent" ,
150
- "--cacert" ,
151
- "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
152
- cur_name = "first"
153
- ),
154
- "https://localhost:8443/" ,
155
- ]
156
- )
157
- == "Ok.\n "
158
- )
159
151
160
- # Change to other key
161
- change_config_to_key ("ECcert" )
152
+ def test_ECcert_reload ():
153
+ """Check EC certificate"""
154
+ check_certificate_switch ("first" , "ECcert" )
162
155
163
- # Command with correct certificate
164
- assert (
165
- node .exec_in_container (
166
- [
167
- "curl" ,
168
- "--silent" ,
169
- "--cacert" ,
170
- "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
171
- cur_name = "ECcert"
172
- ),
173
- "https://localhost:8443/" ,
174
- ]
175
- )
176
- == "Ok.\n "
177
- )
178
156
179
- # Command with wrong certificate
180
- # Same as previous
181
- try :
182
- node .exec_in_container (
183
- [
184
- "curl" ,
185
- "--silent" ,
186
- "--cacert" ,
187
- "/etc/clickhouse-server/config.d/{cur_name}.crt" .format (
188
- cur_name = "first"
189
- ),
190
- "https://localhost:8443/" ,
191
- ]
192
- )
193
- assert False
194
- except :
195
- assert True
157
+ def test_cert_with_pass_phrase ():
158
+ pass_phrase_for_cert = PASS_PHRASE_TEMPLATE .format (pass_phrase = "test" )
159
+ check_certificate_switch (
160
+ "first" , "WithPassPhrase" , pass_phrase_second = pass_phrase_for_cert
161
+ )
0 commit comments