Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RHELC-1532] Require username and password to be specified #1209

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions convert2rhel/toolopts.py
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,18 @@ def _process_cli_options(self):
"Either the --org or the --activationkey option is missing. You can't use one without the other."
)

if (parsed_opts.password or config_opts.password) and not (parsed_opts.username or config_opts.username):
loggerinst.warning(
"You have passed the RHSM password without an associated username. Please provide a username together"
" with the password."
)

if (parsed_opts.username or config_opts.username) and not (parsed_opts.password or config_opts.password):
loggerinst.warning(
"You have passed the RHSM username without an associated password. Please provide a password together"
" with the username."
)


def _log_command_used():
"""We want to log the command used for convert2rhel to make it easier to know what command was used
Expand Down
26 changes: 26 additions & 0 deletions convert2rhel/unit_tests/toolopts_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,3 +668,29 @@ def test_setting_no_rpm_va(argv, env_var, expected, message, monkeypatch, global
assert global_tool_opts.no_rpm_va == expected
if message:
assert caplog.records[-1].message == message


@pytest.mark.parametrize(
("argv", "message"),
(
# The message is a log of used command
(mock_cli_arguments(["-u", "user", "-p", "pass"]), "-u ***** -p *****"),
(
mock_cli_arguments(["-p", "pass"]),
"You have passed the RHSM password without an associated username. Please provide a username together with the password",
),
(
mock_cli_arguments(["-u", "user"]),
"You have passed the RHSM username without an associated password. Please provide a password together with the username",
),
),
)
def test_cli_userpass_specified(argv, message, monkeypatch, caplog, global_tool_opts):
monkeypatch.setattr(sys, "argv", argv)

try:
convert2rhel.toolopts.CLI()
except SystemExit:
# Don't care about the exception, focus on output message
pass
assert message in caplog.text
Loading