Resolve ability to delete ssh keys with spaces in tags (#1674)

This commit is contained in:
Firstyear 2023-05-29 16:11:00 +10:00 committed by GitHub
parent 7da1fd4879
commit 10fa229cf1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 31 additions and 8 deletions

1
Cargo.lock generated
View file

@ -2407,6 +2407,7 @@ dependencies = [
"tokio-util", "tokio-util",
"toml", "toml",
"tracing", "tracing",
"urlencoding",
"uuid", "uuid",
] ]

View file

@ -38,6 +38,7 @@ tokio-openssl = { workspace = true }
tokio-util = { workspace = true, features = ["codec"] } tokio-util = { workspace = true, features = ["codec"] }
toml = {workspace = true} toml = {workspace = true}
tracing = { workspace = true, features = ["attributes"] } tracing = { workspace = true, features = ["attributes"] }
urlencoding.workspace = true
uuid = { workspace = true, features = ["serde", "v4" ] } uuid = { workspace = true, features = ["serde", "v4" ] }
[build-dependencies] [build-dependencies]

View file

@ -144,10 +144,19 @@ impl RequestExtensions for tide::Request<AppState> {
} }
fn get_url_param(&self, param: &str) -> Result<String, tide::Error> { fn get_url_param(&self, param: &str) -> Result<String, tide::Error> {
self.param(param).map(str::to_string).map_err(|e| { self.param(param)
error!(?e); .map_err(|e| {
tide::Error::from_str(tide::StatusCode::ImATeapot, "teapot") error!(?e);
}) tide::Error::from_str(tide::StatusCode::ImATeapot, "teapot")
})
.and_then(|data| {
urlencoding::decode(data)
.map(|s| s.into_owned())
.map_err(|e| {
error!(?e);
tide::Error::from_str(tide::StatusCode::ImATeapot, "teapot")
})
})
} }
fn get_url_param_uuid(&self, param: &str) -> Result<Uuid, tide::Error> { fn get_url_param_uuid(&self, param: &str) -> Result<Uuid, tide::Error> {

View file

@ -424,11 +424,10 @@ impl std::fmt::Debug for DbEntry {
DbEntryVers::V2(dbe_v2) => { DbEntryVers::V2(dbe_v2) => {
write!(f, "v2 - {{ ")?; write!(f, "v2 - {{ ")?;
for (k, vs) in dbe_v2.attrs.iter() { for (k, vs) in dbe_v2.attrs.iter() {
write!(f, "{k} - [")?; write!(f, "\n{k:>16} - ")?;
write!(f, "{vs:?}, ")?; write!(f, "{vs:?}")?;
write!(f, "], ")?;
} }
write!(f, "}}") write!(f, "\n }}")
} }
} }
} }

View file

@ -451,6 +451,19 @@ async fn test_server_rest_sshkey_lifecycle(rsclient: KanidmClient) {
let skn = rsclient.idm_account_get_ssh_pubkey("admin", "k2").await; let skn = rsclient.idm_account_get_ssh_pubkey("admin", "k2").await;
assert!(skn.is_ok()); assert!(skn.is_ok());
assert!(skn.unwrap() == Some("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBx4TpJYQjd0YI5lQIHqblIsCIK5NKVFURYS/eM3o6/Z william@amethyst".to_string())); assert!(skn.unwrap() == Some("ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBx4TpJYQjd0YI5lQIHqblIsCIK5NKVFURYS/eM3o6/Z william@amethyst".to_string()));
// Add a key and delete with a space in the name.
let r5 = rsclient
.idm_service_account_post_ssh_pubkey("admin", "Yk 5 Nfc", "sk-ecdsa-sha2-nistp256@openssh.com AAAAInNrLWVjZHNhLXNoYTItbmlzdHAyNTZAb3BlbnNzaC5jb20AAAAIbmlzdHAyNTYAAABBBENubZikrb8hu+HeVRdZ0pp/VAk2qv4JDbuJhvD0yNdWDL2e3cBbERiDeNPkWx58Q4rVnxkbV1fa8E2waRtT91wAAAAEc3NoOg== william@maxixe").await;
assert!(r5.is_ok());
let r6 = rsclient
.idm_service_account_delete_ssh_pubkey("admin", "Yk 5 Nfc")
.await;
assert!(r6.is_ok());
let sk5 = rsclient.idm_account_get_ssh_pubkeys("admin").await.unwrap();
assert!(sk5.len() == 1);
} }
#[kanidmd_testkit::test] #[kanidmd_testkit::test]