mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-16 15:21:24 +01:00
reject overlapping media and database paths
This commit is contained in:
parent
81a449d1d2
commit
b01b70fc20
20 changed files with 146 additions and 4 deletions
|
|
@ -538,5 +538,27 @@ where
|
|||
return Err(Error::RegistrationTokenEmpty);
|
||||
}
|
||||
|
||||
match &config.media.backend {
|
||||
MediaBackendConfig::Filesystem(x) => {
|
||||
let media_path = x
|
||||
.path
|
||||
.canonicalize()
|
||||
.map_err(|e| Error::Canonicalize(e, x.path.clone()))?;
|
||||
|
||||
let database_path =
|
||||
config.database.path.canonicalize().map_err(|e| {
|
||||
Error::Canonicalize(e, config.database.path.clone())
|
||||
})?;
|
||||
|
||||
let overlap = media_path == database_path
|
||||
|| media_path.starts_with(&database_path)
|
||||
|| database_path.starts_with(&media_path);
|
||||
|
||||
if overlap {
|
||||
return Err(Error::DatabaseMediaOverlap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(config)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -134,8 +134,14 @@ pub(crate) enum Config {
|
|||
#[error("failed to parse configuration file {1:?}")]
|
||||
Parse(#[source] toml::de::Error, PathBuf),
|
||||
|
||||
#[error("failed to canonicalize path {}", .1.display())]
|
||||
Canonicalize(#[source] std::io::Error, PathBuf),
|
||||
|
||||
#[error("registration token must not be empty")]
|
||||
RegistrationTokenEmpty,
|
||||
|
||||
#[error("database and media paths overlap")]
|
||||
DatabaseMediaOverlap,
|
||||
}
|
||||
|
||||
/// Errors that can occur while searching for a config file
|
||||
|
|
|
|||
|
|
@ -93,3 +93,21 @@ make_snapshot_test!(
|
|||
"A config with invalid values fails",
|
||||
"invalid-values.toml",
|
||||
);
|
||||
|
||||
make_snapshot_test!(
|
||||
overlapping_paths_equal,
|
||||
"A config with equal paths fails",
|
||||
"equal-paths.toml",
|
||||
);
|
||||
|
||||
make_snapshot_test!(
|
||||
overlapping_paths_media,
|
||||
"A config with the media path inside the database path fails",
|
||||
"media-in-database.toml",
|
||||
);
|
||||
|
||||
make_snapshot_test!(
|
||||
overlapping_paths_database,
|
||||
"A config with the database path inside the media path fails",
|
||||
"database-in-media.toml",
|
||||
);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
server_name = "example.com"
|
||||
|
||||
[server_discovery]
|
||||
client.base_url = "https://matrix.example.com"
|
||||
|
||||
[database]
|
||||
backend = "rocksdb"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/c/a"
|
||||
|
||||
[media.backend]
|
||||
type = "filesystem"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/c"
|
||||
2
tests/integrations/fixtures/check_config/dirs/a/.gitignore
vendored
Normal file
2
tests/integrations/fixtures/check_config/dirs/a/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
2
tests/integrations/fixtures/check_config/dirs/b/.gitignore
vendored
Normal file
2
tests/integrations/fixtures/check_config/dirs/b/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
2
tests/integrations/fixtures/check_config/dirs/c/a/.gitignore
vendored
Normal file
2
tests/integrations/fixtures/check_config/dirs/c/a/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
*
|
||||
!.gitignore
|
||||
12
tests/integrations/fixtures/check_config/equal-paths.toml
Normal file
12
tests/integrations/fixtures/check_config/equal-paths.toml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
server_name = "example.com"
|
||||
|
||||
[server_discovery]
|
||||
client.base_url = "https://matrix.example.com"
|
||||
|
||||
[database]
|
||||
backend = "rocksdb"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/a"
|
||||
|
||||
[media.backend]
|
||||
type = "filesystem"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/a"
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
server_name = "example.com"
|
||||
|
||||
[server_discovery]
|
||||
client.base_url = "https://matrix.example.com"
|
||||
|
||||
[database]
|
||||
backend = "rocksdb"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/c"
|
||||
|
||||
[media.backend]
|
||||
type = "filesystem"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/c/a"
|
||||
|
|
@ -5,8 +5,8 @@ client.base_url = "https://matrix.example.com"
|
|||
|
||||
[database]
|
||||
backend = "rocksdb"
|
||||
path = "/var/lib/grapevine/database"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/a"
|
||||
|
||||
[media.backend]
|
||||
type = "filesystem"
|
||||
path = "/var/lib/grapevine/media"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/b"
|
||||
|
|
|
|||
|
|
@ -10,11 +10,11 @@ client.base_url = "https://matrix.example.com"
|
|||
|
||||
[database]
|
||||
backend = "rocksdb"
|
||||
path = "/var/lib/grapevine/database"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/a"
|
||||
|
||||
[media.backend]
|
||||
type = "filesystem"
|
||||
path = "/var/lib/grapevine/media"
|
||||
path = "tests/integrations/fixtures/check_config/dirs/b"
|
||||
|
||||
[federation]
|
||||
enable = true
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the database path inside the media path fails
|
||||
---
|
||||
Some(
|
||||
1,
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the database path inside the media path fails
|
||||
---
|
||||
Error: failed to validate configuration
|
||||
Caused by: database and media paths overlap
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the database path inside the media path fails
|
||||
---
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with equal paths fails
|
||||
---
|
||||
Some(
|
||||
1,
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with equal paths fails
|
||||
---
|
||||
Error: failed to validate configuration
|
||||
Caused by: database and media paths overlap
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with equal paths fails
|
||||
---
|
||||
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the media path inside the database path fails
|
||||
---
|
||||
Some(
|
||||
1,
|
||||
)
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the media path inside the database path fails
|
||||
---
|
||||
Error: failed to validate configuration
|
||||
Caused by: database and media paths overlap
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
source: tests/integrations/check_config.rs
|
||||
description: A config with the media path inside the database path fails
|
||||
---
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue