Skip to content

Commit

Permalink
Fix: insecure id not set during registration on self hosted (#284)
Browse files Browse the repository at this point in the history
## Manual Testing
### Verify Bug
- Follow instructions
[here](https://ubuntu.com/landscape/docs/install-landscape-client#heading--install-landscape-client-from-a-PPA)
to install client and use `ppa:landscape/self-hosted-beta`
- Connect client to ppa beta version of self hosted server following
instructions
[here](https://ubuntu.com/landscape/docs/quickstart-deployment)
- After connecting client wait a few minutes and client should go
offline as it is not pinging the server

### Verify fix
- Use this version of client
- Connect client to self hosted server
- Verify ping is working and connection doesn't go offline
  • Loading branch information
david-mclain authored Nov 26, 2024
1 parent 71e5933 commit 0bd090d
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
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

0 comments on commit 0bd090d

Please sign in to comment.