Skip to content

Commit dc267cc

Browse files
committed
Add deprecation warning for --ssl-* and update tests
1 parent 5b13a11 commit dc267cc

2 files changed

Lines changed: 69 additions & 45 deletions

File tree

saltyrtc/server/bin.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
)
3333

3434

35+
def _echo_deprecated(message: str) -> None:
36+
click.echo(click.style('DeprecationWarning: {}'.format(message), fg='yellow'))
37+
38+
3539
def _h(text: str) -> str:
3640
"""
3741
For some reason, :mod:`click` does not strip new line characters
@@ -165,15 +169,22 @@ def generate(key_file: str) -> None:
165169
@click.pass_context
166170
def serve(ctx: click.Context, **arguments: Any) -> None:
167171
# Get arguments
168-
tls_cert = arguments.get('tlscert', None) or arguments.get('sslcert', None) # type: Optional[str]
169-
tls_key = arguments.get('tlskey', None) or arguments.get('sslkey', None) # type: Optional[str]
172+
ssl_cert = arguments.get('sslcert', None) # type: Optional[str]
173+
ssl_key = arguments.get('sslkey', None) # type: Optional[str]
174+
tls_cert = arguments.get('tlscert', None) or ssl_cert # type: Optional[str]
175+
tls_key = arguments.get('tlskey', None) or ssl_key # type: Optional[str]
170176
dh_params = arguments.get('dhparams', None) # type: Optional[str]
171177
keys_str = arguments['key'] # type: Sequence[str]
172178
host = arguments.get('host') # type: Optional[str]
173179
port = arguments['port'] # type: int
174180
loop_str = arguments['loop'] # type: str
175181
safety_off = os.environ.get('SALTYRTC_SAFETY_OFF') == 'yes-and-i-know-what-im-doing'
176182

183+
# Deprecation warning
184+
if ssl_cert is not None or ssl_key is not None:
185+
_echo_deprecated(('The options -sc, --sslcert and -sk, --sslkey are deprecated. '
186+
'Use -tc, --tlscert and -tk, --tlskey instead.'))
187+
177188
# Make sure the user provides cert & keys or has safety turned off
178189
if tls_cert is None or len(keys_str) == 0:
179190
if safety_off:

tests/test_cli.py

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ async def test_serve_cert_missing(self, cli):
8484
with pytest.raises(subprocess.CalledProcessError) as exc_info:
8585
await cli(
8686
'serve',
87-
'-sc', pytest.saltyrtc.cert,
88-
'-sk', pytest.saltyrtc.key,
87+
'-tc', pytest.saltyrtc.cert,
88+
'-tk', pytest.saltyrtc.key,
8989
'-p', '8443',
9090
)
9191
assert 'It is REQUIRED' in exc_info.value.output
@@ -97,7 +97,7 @@ async def test_serve_invalid_cert(self, cli, tmpdir):
9797
with pytest.raises(subprocess.CalledProcessError) as exc_info:
9898
await cli(
9999
'serve',
100-
'-sc', str(cert),
100+
'-tc', str(cert),
101101
'-k', pytest.saltyrtc.permanent_key_primary,
102102
'-p', '8443',
103103
)
@@ -110,8 +110,8 @@ async def test_serve_invalid_key_file(self, cli, tmpdir):
110110
with pytest.raises(subprocess.CalledProcessError) as exc_info:
111111
await cli(
112112
'serve',
113-
'-sc', pytest.saltyrtc.cert,
114-
'-sk', pytest.saltyrtc.key,
113+
'-tc', pytest.saltyrtc.cert,
114+
'-tk', pytest.saltyrtc.key,
115115
'-k', str(keyfile),
116116
'-p', '8443',
117117
)
@@ -124,8 +124,8 @@ async def test_serve_invalid_dh_params_file(self, cli, tmpdir):
124124
with pytest.raises(subprocess.CalledProcessError) as exc_info:
125125
await cli(
126126
'serve',
127-
'-sc', pytest.saltyrtc.cert,
128-
'-sk', pytest.saltyrtc.key,
127+
'-tc', pytest.saltyrtc.cert,
128+
'-tk', pytest.saltyrtc.key,
129129
'-k', pytest.saltyrtc.permanent_key_primary,
130130
'-dhp', str(dh_params_file),
131131
'-p', '8443',
@@ -138,8 +138,8 @@ async def test_serve_invalid_hex_encoded_key(self, cli):
138138
with pytest.raises(subprocess.CalledProcessError) as exc_info:
139139
await cli(
140140
'serve',
141-
'-sc', pytest.saltyrtc.cert,
142-
'-sk', pytest.saltyrtc.key,
141+
'-tc', pytest.saltyrtc.cert,
142+
'-tk', pytest.saltyrtc.key,
143143
'-k', key,
144144
'-p', '8443',
145145
)
@@ -150,8 +150,8 @@ async def test_serve_invalid_host(self, cli):
150150
with pytest.raises(subprocess.CalledProcessError) as exc_info:
151151
await cli(
152152
'serve',
153-
'-sc', pytest.saltyrtc.cert,
154-
'-sk', pytest.saltyrtc.key,
153+
'-tc', pytest.saltyrtc.cert,
154+
'-tk', pytest.saltyrtc.key,
155155
'-k', pytest.saltyrtc.permanent_key_primary,
156156
'-h', 'meow',
157157
'-p', '8443',
@@ -163,8 +163,8 @@ async def test_serve_invalid_port(self, cli):
163163
with pytest.raises(subprocess.CalledProcessError) as exc_info:
164164
await cli(
165165
'serve',
166-
'-sc', pytest.saltyrtc.cert,
167-
'-sk', pytest.saltyrtc.key,
166+
'-tc', pytest.saltyrtc.cert,
167+
'-tk', pytest.saltyrtc.key,
168168
'-k', pytest.saltyrtc.permanent_key_primary,
169169
'-p', 'meow',
170170
)
@@ -175,8 +175,8 @@ async def test_serve_invalid_loop(self, cli):
175175
with pytest.raises(subprocess.CalledProcessError) as exc_info:
176176
await cli(
177177
'serve',
178-
'-sc', pytest.saltyrtc.cert,
179-
'-sk', pytest.saltyrtc.key,
178+
'-tc', pytest.saltyrtc.cert,
179+
'-tk', pytest.saltyrtc.key,
180180
'-k', pytest.saltyrtc.permanent_key_primary,
181181
'-p', '8443',
182182
'-l', 'meow',
@@ -189,8 +189,8 @@ async def test_serve_uvloop_unavailable(self, cli):
189189
with pytest.raises(subprocess.CalledProcessError) as exc_info:
190190
await cli(
191191
'serve',
192-
'-sc', pytest.saltyrtc.cert,
193-
'-sk', pytest.saltyrtc.key,
192+
'-tc', pytest.saltyrtc.cert,
193+
'-tk', pytest.saltyrtc.key,
194194
'-k', pytest.saltyrtc.permanent_key_primary,
195195
'-p', '8443',
196196
'-l', 'uvloop',
@@ -201,8 +201,8 @@ async def test_serve_uvloop_unavailable(self, cli):
201201
async def test_serve_asyncio(self, cli):
202202
output = await cli(
203203
'serve',
204-
'-sc', pytest.saltyrtc.cert,
205-
'-sk', pytest.saltyrtc.key,
204+
'-tc', pytest.saltyrtc.cert,
205+
'-tk', pytest.saltyrtc.key,
206206
'-k', pytest.saltyrtc.permanent_key_primary,
207207
'-p', '8443',
208208
signal=signal.SIGINT,
@@ -213,8 +213,8 @@ async def test_serve_asyncio(self, cli):
213213
async def test_serve_asyncio_dh_params(self, cli):
214214
output = await cli(
215215
'serve',
216-
'-sc', pytest.saltyrtc.cert,
217-
'-sk', pytest.saltyrtc.key,
216+
'-tc', pytest.saltyrtc.cert,
217+
'-tk', pytest.saltyrtc.key,
218218
'-k', pytest.saltyrtc.permanent_key_primary,
219219
'-dhp', pytest.saltyrtc.dh_params,
220220
'-p', '8443',
@@ -226,8 +226,8 @@ async def test_serve_asyncio_dh_params(self, cli):
226226
async def test_serve_asyncio_hex_encoded_key(self, cli):
227227
output = await cli(
228228
'serve',
229-
'-sc', pytest.saltyrtc.cert,
230-
'-sk', pytest.saltyrtc.key,
229+
'-tc', pytest.saltyrtc.cert,
230+
'-tk', pytest.saltyrtc.key,
231231
'-k', open(pytest.saltyrtc.permanent_key_primary, 'r').read(),
232232
'-p', '8443',
233233
signal=signal.SIGINT,
@@ -239,8 +239,8 @@ async def test_serve_asyncio_plus_logging(self, cli):
239239
output = await cli(
240240
'-v', '7',
241241
'serve',
242-
'-sc', pytest.saltyrtc.cert,
243-
'-sk', pytest.saltyrtc.key,
242+
'-tc', pytest.saltyrtc.cert,
243+
'-tk', pytest.saltyrtc.key,
244244
'-k', pytest.saltyrtc.permanent_key_primary,
245245
'-p', '8443',
246246
signal=signal.SIGINT,
@@ -253,8 +253,8 @@ async def test_serve_asyncio_plus_logging(self, cli):
253253
async def test_serve_uvloop(self, cli):
254254
output = await cli(
255255
'serve',
256-
'-sc', pytest.saltyrtc.cert,
257-
'-sk', pytest.saltyrtc.key,
256+
'-tc', pytest.saltyrtc.cert,
257+
'-tk', pytest.saltyrtc.key,
258258
'-k', pytest.saltyrtc.permanent_key_primary,
259259
'-p', '8443',
260260
'-l', 'uvloop',
@@ -267,8 +267,8 @@ async def test_serve_uvloop(self, cli):
267267
async def test_serve_uvloop_dh_params(self, cli):
268268
output = await cli(
269269
'serve',
270-
'-sc', pytest.saltyrtc.cert,
271-
'-sk', pytest.saltyrtc.key,
270+
'-tc', pytest.saltyrtc.cert,
271+
'-tk', pytest.saltyrtc.key,
272272
'-k', pytest.saltyrtc.permanent_key_primary,
273273
'-dhp', pytest.saltyrtc.dh_params,
274274
'-p', '8443',
@@ -283,8 +283,8 @@ async def test_serve_uvloop_plus_logging(self, cli):
283283
output = await cli(
284284
'-v', '7',
285285
'serve',
286-
'-sc', pytest.saltyrtc.cert,
287-
'-sk', pytest.saltyrtc.key,
286+
'-tc', pytest.saltyrtc.cert,
287+
'-tk', pytest.saltyrtc.key,
288288
'-k', pytest.saltyrtc.permanent_key_primary,
289289
'-p', '8443',
290290
'-l', 'uvloop',
@@ -297,8 +297,8 @@ async def test_serve_uvloop_plus_logging(self, cli):
297297
async def test_serve_asyncio_restart(self, cli):
298298
output = await cli(
299299
'serve',
300-
'-sc', pytest.saltyrtc.cert,
301-
'-sk', pytest.saltyrtc.key,
300+
'-tc', pytest.saltyrtc.cert,
301+
'-tk', pytest.saltyrtc.key,
302302
'-k', pytest.saltyrtc.permanent_key_primary,
303303
'-p', '8443',
304304
signal=[signal.SIGHUP, signal.SIGINT],
@@ -347,8 +347,8 @@ async def test_serve_repeated_key(self, cli):
347347
with pytest.raises(subprocess.CalledProcessError) as exc_info:
348348
await cli(*[
349349
'serve',
350-
'-sc', pytest.saltyrtc.cert,
351-
'-sk', pytest.saltyrtc.key,
350+
'-tc', pytest.saltyrtc.cert,
351+
'-tk', pytest.saltyrtc.key,
352352
'-p', '8443',
353353
] + key_arguments)
354354
assert 'key has been supplied more than once' in exc_info.value.output
@@ -360,8 +360,8 @@ async def test_serve_invalid_2nd_key_file(self, cli, tmpdir):
360360
with pytest.raises(subprocess.CalledProcessError) as exc_info:
361361
await cli(
362362
'serve',
363-
'-sc', pytest.saltyrtc.cert,
364-
'-sk', pytest.saltyrtc.key,
363+
'-tc', pytest.saltyrtc.cert,
364+
'-tk', pytest.saltyrtc.key,
365365
'-k', pytest.saltyrtc.permanent_key_primary,
366366
'-k', str(keyfile),
367367
'-p', '8443',
@@ -374,8 +374,8 @@ async def test_serve_invalid_2nd_hex_encoded_key(self, cli):
374374
with pytest.raises(subprocess.CalledProcessError) as exc_info:
375375
await cli(
376376
'serve',
377-
'-sc', pytest.saltyrtc.cert,
378-
'-sk', pytest.saltyrtc.key,
377+
'-tc', pytest.saltyrtc.cert,
378+
'-tk', pytest.saltyrtc.key,
379379
'-k', pytest.saltyrtc.permanent_key_primary,
380380
'-k', key,
381381
'-p', '8443',
@@ -393,8 +393,8 @@ async def test_serve_asyncio_2nd_key(self, cli):
393393
# Check output
394394
output = await cli(
395395
'serve',
396-
'-sc', pytest.saltyrtc.cert,
397-
'-sk', pytest.saltyrtc.key,
396+
'-tc', pytest.saltyrtc.cert,
397+
'-tk', pytest.saltyrtc.key,
398398
'-k', pytest.saltyrtc.permanent_key_primary,
399399
'-k', pytest.saltyrtc.permanent_key_secondary,
400400
'-p', '8443',
@@ -415,8 +415,8 @@ async def test_serve_asyncio_2nd_key_reversed(self, cli):
415415
# Check output
416416
output = await cli(
417417
'serve',
418-
'-sc', pytest.saltyrtc.cert,
419-
'-sk', pytest.saltyrtc.key,
418+
'-tc', pytest.saltyrtc.cert,
419+
'-tk', pytest.saltyrtc.key,
420420
'-k', pytest.saltyrtc.permanent_key_secondary,
421421
'-k', pytest.saltyrtc.permanent_key_primary,
422422
'-p', '8443',
@@ -425,3 +425,16 @@ async def test_serve_asyncio_2nd_key_reversed(self, cli):
425425
assert 'Primary public permanent key: {}'.format(secondary_key) in output
426426
assert 'Secondary key #1: {}'.format(primary_key) in output
427427
assert 'Stopped' in output
428+
429+
@pytest.mark.asyncio
430+
async def test_serve_deprecated_options(self, cli):
431+
output = await cli(
432+
'serve',
433+
'-sc', pytest.saltyrtc.cert,
434+
'-sk', pytest.saltyrtc.key,
435+
'-k', pytest.saltyrtc.permanent_key_primary,
436+
'-p', '8443',
437+
signal=signal.SIGINT,
438+
)
439+
assert 'DeprecationWarning' in output
440+
assert 'Stopped' in output

0 commit comments

Comments
 (0)