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

Fix: insecure id not set during registration on self hosted #284

Merged
merged 2 commits into from
Nov 26, 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
14 changes: 12 additions & 2 deletions landscape/client/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ def attempt_registration(

:returns: an exit code based on the registration result.
"""

client_info = ClientRegistrationInfo.from_identity(identity)

for retry in range(retries):
Expand All @@ -750,6 +751,7 @@ def attempt_registration(
config.url,
cainfo=config.ssl_public_key,
)

break
except RegistrationException as e:
# This is unlikely to be resolved by the time we retry, so we fail
Expand All @@ -763,7 +765,12 @@ def attempt_registration(
# We're finished retrying and haven't succeeded yet.
return 2

set_secure_id(config, registration_info.secure_id)
set_secure_id(
config,
registration_info.secure_id,
registration_info.insecure_id,
)

print("Registration request sent successfully")
restart_client(config)

Expand Down Expand Up @@ -805,7 +812,7 @@ def registration_info_text(config, registration_status):
return text


def set_secure_id(config, new_id):
def set_secure_id(config, new_id, insecure_id=None):
"""Persists a secure id in the identity data file. This is used to indicate
whether we are currently in the process of registering.
"""
Expand All @@ -819,6 +826,8 @@ def set_secure_id(config, new_id):
)
identity = Identity(config, persist)
identity.secure_id = new_id
if insecure_id is not None:
identity.insecure_id = insecure_id
persist.save()


Expand Down Expand Up @@ -910,6 +919,7 @@ def main(args, print=print):
)

exit_code = 0

if should_register:
exit_code = attempt_registration(identity, config)
restart_client(config)
Expand Down
1 change: 1 addition & 0 deletions landscape/client/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def from_identity(
cls: Type["ClientRegistrationInfo"],
identity: Identity,
) -> "ClientRegistrationInfo":

return cls(
identity.access_group,
identity.account_name,
Expand Down
43 changes: 43 additions & 0 deletions landscape/client/tests/test_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from landscape.client.configuration import setup
from landscape.client.configuration import show_help
from landscape.client.configuration import store_public_key_data
from landscape.client.registration import RegistrationInfo
from landscape.client.serviceconfig import ServiceConfigException
from landscape.client.tests.helpers import LandscapeTest
from landscape.lib.compat import ConfigParser
Expand Down Expand Up @@ -1496,6 +1497,48 @@ def test_register_silent(
mock_register.assert_called_once()
mock_input.assert_not_called()

@mock.patch(
"landscape.client.configuration.ClientRegistrationInfo.from_identity",
)
@mock.patch("landscape.client.configuration.restart_client")
@mock.patch("landscape.client.configuration.input")
@mock.patch("landscape.client.configuration.set_secure_id")
@mock.patch("landscape.client.configuration.register")
@mock.patch("landscape.client.configuration.setup")
def test_register_insecure_id(
self,
mock_setup,
mock_register,
mock_set_secure_id,
mock_input,
mock_restart_client,
mock_client_info,
):
"""
Tests that silent registration sets insecure id when provided
"""

mock_register.return_value = RegistrationInfo(
10,
"fake-secure-id",
"fake-server-uuid",
)

self.assertRaises(
SystemExit,
main,
["--silent", "-c", self.make_working_config()],
print=noop_print,
)

mock_setup.assert_called_once()
mock_input.assert_not_called()
mock_set_secure_id.assert_called_once_with(
mock.ANY,
"fake-secure-id",
10,
)

@mock.patch("landscape.client.configuration.input")
@mock.patch("landscape.client.configuration.attempt_registration")
@mock.patch(
Expand Down
Loading