diff --git a/Cargo.lock b/Cargo.lock index 505c71c9..b3b1498f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -415,6 +415,7 @@ dependencies = [ "serde_json", "serde_yaml", "sha-1", + "sha2", "thiserror", "thread_local", "threadpool", diff --git a/Cargo.toml b/Cargo.toml index 36ffb13e..84310847 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -88,6 +88,7 @@ thread_local = "1.1.3" # used for TURN server authentication hmac = "0.12.1" sha-1 = "0.10.0" +sha2 = "0.9" # used for conduit's CLI and admin room command parsing clap = { version = "4.0.11", default-features = false, features = ["std", "derive", "help", "usage", "error-context"] } futures-util = { version = "0.3.17", default-features = false } diff --git a/src/service/media/mod.rs b/src/service/media/mod.rs index f5f499e0..4f9c35b6 100644 --- a/src/service/media/mod.rs +++ b/src/service/media/mod.rs @@ -229,6 +229,8 @@ impl Service { mod tests { use std::path::PathBuf; + use sha2::Digest; + use super::*; struct MockedKVDatabase; @@ -298,7 +300,13 @@ mod tests { let mut r = PathBuf::new(); r.push("/tmp"); r.push("media"); - r.push(base64::encode_config(key, base64::URL_SAFE_NO_PAD)); + // r.push(base64::encode_config(key, base64::URL_SAFE_NO_PAD)); + // use the sha256 hash of the key as the file name instead of the key itself + // this is because the base64 encoded key can be longer than 255 characters. + r.push(base64::encode_config( + sha2::Sha256::digest(&key), + base64::URL_SAFE_NO_PAD, + )); // Check that the file path is not longer than 255 characters // (255 is the maximum length of a file path on most file systems) assert!(