mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2026-02-11 10:05:41 +00:00
url prefix processing
This commit is contained in:
@@ -29,6 +29,7 @@ pub struct Server {
|
||||
pub domain: String,
|
||||
pub cookie_secret: String,
|
||||
pub ip: String,
|
||||
pub url_prefix: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -42,6 +43,15 @@ impl Server {
|
||||
pub fn get_ip(&self) -> String {
|
||||
format!("{}:{}", self.ip, self.port)
|
||||
}
|
||||
|
||||
fn check_url_prefix(&mut self) {
|
||||
if let Some(prefix) = self.url_prefix.clone() {
|
||||
self.url_prefix = Some(prefix.trim().into());
|
||||
if prefix.trim().is_empty() {
|
||||
panic!("URL prefix is set to empty string")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
@@ -162,3 +172,24 @@ fn set_database_url(s: &mut Config) {
|
||||
)
|
||||
.expect("Couldn't set databse url");
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn url_prefix_test() {
|
||||
let mut settings = Settings::new().unwrap();
|
||||
assert!(settings.server.url_prefix.is_none());
|
||||
settings.server.url_prefix = Some("test".into());
|
||||
settings.server.check_url_prefix();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn url_prefix_panic_test() {
|
||||
let mut settings = Settings::new().unwrap();
|
||||
settings.server.url_prefix = Some(" ".into());
|
||||
settings.server.check_url_prefix();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user