Merge pull request #1893 from ogayot/ssh-fixes

Fix empty list of authorized_keys in /ssh endpoint
This commit is contained in:
Olivier Gayot 2024-01-25 17:35:30 +01:00 committed by GitHub
commit 9d4bd5708c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 5 deletions

View File

@ -26,10 +26,6 @@ class SSHModel:
self.install_server = False
self.authorized_keys: List[str] = []
self.pwauth = True
# Although the generated config just contains the key above,
# we store the imported id so that we can re-fill the form if
# we go back to it.
self.ssh_import_id = ""
async def target_packages(self) -> List[TargetPkg]:
if not self.install_server:

View File

@ -70,7 +70,9 @@ class SSHController(SubiquityController):
async def GET(self) -> SSHData:
return SSHData(
install_server=self.model.install_server, allow_pw=self.model.pwauth
install_server=self.model.install_server,
allow_pw=self.model.pwauth,
authorized_keys=self.model.authorized_keys,
)
async def POST(self, data: SSHData) -> None:

View File

@ -29,6 +29,24 @@ class TestSSHController(unittest.IsolatedAsyncioTestCase):
def setUp(self):
self.controller = SSHController(make_app())
async def test_GET(self):
model = self.controller.model
model.pwauth = False
model.authorized_keys = [
"ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAA # ssh-import-id lp:subiquity",
]
model.install_server = True
data = await self.controller.GET()
self.assertFalse(data.allow_pw)
self.assertTrue(data.install_server)
self.assertIn(
"ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAA # ssh-import-id lp:subiquity",
data.authorized_keys,
)
async def test_fetch_id_GET_ok(self):
key = "ssh-rsa AAAAA[..] user@host # ssh-import-id lp:user"
mock_fetch_keys = mock.patch.object(