Skip to content

Commit ee209aa

Browse files
authored
fix: input validation gap in rsconnect add (#758)
* add early check * bandaid test
1 parent 13b63b5 commit ee209aa

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

rsconnect/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,12 @@ def add(
741741
set_verbosity(verbose)
742742
output_params(ctx, locals().items())
743743

744+
if not server and not any([token, secret, account]):
745+
raise RSConnectException(
746+
"`rsconnect add` requires -s/--server (for Posit Connect) or -A/--account, -T/--token, "
747+
"and -S/--secret (for shinyapps.io)."
748+
)
749+
744750
validation.validate_connection_options(
745751
ctx=ctx,
746752
url=server,

tests/test_main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,28 @@ def test_add_shinyapps(self):
715715
if original_server_value:
716716
os.environ["CONNECT_SERVER"] = original_server_value
717717

718+
def test_add_name_only_missing_server_and_credentials(self):
719+
"""Regression test: `rsconnect add -n x` should produce a validation error, not a TypeError."""
720+
original_api_key_value = os.environ.pop("CONNECT_API_KEY", None)
721+
original_server_value = os.environ.pop("CONNECT_SERVER", None)
722+
try:
723+
runner = CliRunner()
724+
result = runner.invoke(
725+
cli,
726+
[
727+
"add",
728+
"--name",
729+
"some-name",
730+
],
731+
)
732+
assert result.exit_code == 1, result.output
733+
assert "`rsconnect add` requires" in str(result.exception)
734+
finally:
735+
if original_api_key_value:
736+
os.environ["CONNECT_API_KEY"] = original_api_key_value
737+
if original_server_value:
738+
os.environ["CONNECT_SERVER"] = original_server_value
739+
718740
def test_add_shinyapps_missing_options(self):
719741
original_api_key_value = os.environ.pop("CONNECT_API_KEY", None)
720742
original_server_value = os.environ.pop("CONNECT_SERVER", None)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pandas
22
numpy
3-
pydantic
3+
pydantic<2
44
pytest
55
pins
66
vetiver

0 commit comments

Comments
 (0)