diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-02-06 07:39:14 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-02-06 07:39:14 +0000 |
commit | b426e6e89e077fce0b74c79c13751cf4db5af75e (patch) | |
tree | 0d824b05fc2cd2ed8d841bc38af89f0848b744ff | |
parent | ac460fecfa2795f1eeb2d2171b977e52af7dd24e (diff) | |
parent | 6461ea45a26d0858cd2205ba97c200239f531008 (diff) | |
download | obnam2-b426e6e89e077fce0b74c79c13751cf4db5af75e.tar.gz |
Merge branch 'http' into 'main'
feat: client requires an HTTPS URL for server
Closes #12
See merge request larswirzenius/obnam!86
-rw-r--r-- | obnam.md | 19 | ||||
-rw-r--r-- | src/client.rs | 13 |
2 files changed, 31 insertions, 1 deletions
@@ -1001,6 +1001,25 @@ server_url: https://backup.example.com ~~~ +## Client requires https + +This scenario verifies that the client rejects a configuration with a +server URL using `http:` instead of `https:`. + + +~~~scenario +given an installed obnam +and file http.yaml +when I try to run obnam --config http.yaml config +then command fails +then stderr contains "https:" +~~~ + +~~~{#http.yaml .file .yaml .numberLines} +root: live +server_url: http://backup.example.com +~~~ + # Acceptance criteria for Obnam as a whole The scenarios in this chapter apply to Obnam as a whole: the client diff --git a/src/client.rs b/src/client.rs index e8e20eb..3d3b2a5 100644 --- a/src/client.rs +++ b/src/client.rs @@ -26,6 +26,9 @@ pub struct ClientConfig { #[derive(Debug, thiserror::Error)] pub enum ClientConfigError { + #[error("server URL doesn't use https: {0}")] + NotHttps(String), + #[error(transparent)] IoError(#[from] std::io::Error), @@ -39,9 +42,17 @@ impl ClientConfig { pub fn read_config(filename: &Path) -> ClientConfigResult<Self> { trace!("read_config: filename={:?}", filename); let config = std::fs::read_to_string(filename)?; - let config = serde_yaml::from_str(&config)?; + let config: ClientConfig = serde_yaml::from_str(&config)?; + config.check()?; Ok(config) } + + fn check(&self) -> Result<(), ClientConfigError> { + if !self.server_url.starts_with("https://") { + return Err(ClientConfigError::NotHttps(self.server_url.to_string())); + } + Ok(()) + } } #[derive(Debug, thiserror::Error)] |