ssh: pass the autorized_keys in GET /ssh

Signed-off-by: Olivier Gayot <olivier.gayot@canonical.com>
This commit is contained in:
Olivier Gayot 2023-03-04 00:08:00 +01:00
parent 5a301bcdd6
commit b1cdd74775
2 changed files with 21 additions and 1 deletions

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(