diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 05:43:14 +0000 |
commit | 8dd16259287f58f9273002717ec4d27e97127719 (patch) | |
tree | 3863e62a53829a84037444beab3abd4ed9dfc7d0 /third_party/rust/remote_settings/src/client.rs | |
parent | Releasing progress-linux version 126.0.1-1~progress7.99u1. (diff) | |
download | firefox-8dd16259287f58f9273002717ec4d27e97127719.tar.xz firefox-8dd16259287f58f9273002717ec4d27e97127719.zip |
Merging upstream version 127.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/remote_settings/src/client.rs')
-rw-r--r-- | third_party/rust/remote_settings/src/client.rs | 89 |
1 files changed, 75 insertions, 14 deletions
diff --git a/third_party/rust/remote_settings/src/client.rs b/third_party/rust/remote_settings/src/client.rs index 2cf26b7319..601b5c451a 100644 --- a/third_party/rust/remote_settings/src/client.rs +++ b/third_party/rust/remote_settings/src/client.rs @@ -4,7 +4,7 @@ use crate::config::RemoteSettingsConfig; use crate::error::{RemoteSettingsError, Result}; -use crate::UniffiCustomTypeConverter; +use crate::{RemoteSettingsServer, UniffiCustomTypeConverter}; use parking_lot::Mutex; use serde::Deserialize; use std::{ @@ -31,11 +31,17 @@ pub struct Client { impl Client { /// Create a new [Client] with properties matching config. pub fn new(config: RemoteSettingsConfig) -> Result<Self> { - let server_url = config - .server_url - .unwrap_or_else(|| String::from("https://firefox.settings.services.mozilla.com")); + let server = match (config.server, config.server_url) { + (Some(server), None) => server, + (None, Some(server_url)) => RemoteSettingsServer::Custom { url: server_url }, + (None, None) => RemoteSettingsServer::Prod, + (Some(_), Some(_)) => Err(RemoteSettingsError::ConfigError( + "`RemoteSettingsConfig` takes either `server` or `server_url`, not both".into(), + ))?, + }; + let bucket_name = config.bucket_name.unwrap_or_else(|| String::from("main")); - let base_url = Url::parse(&server_url)?; + let base_url = server.url()?; Ok(Self { base_url, @@ -519,6 +525,7 @@ mod test { #[test] fn test_defaults() { let config = RemoteSettingsConfig { + server: None, server_url: None, bucket_name: None, collection_name: String::from("the-collection"), @@ -532,6 +539,33 @@ mod test { } #[test] + fn test_deprecated_server_url() { + let config = RemoteSettingsConfig { + server: None, + server_url: Some("https://example.com".into()), + bucket_name: None, + collection_name: String::from("the-collection"), + }; + let client = Client::new(config).unwrap(); + assert_eq!(Url::parse("https://example.com").unwrap(), client.base_url); + } + + #[test] + fn test_invalid_config() { + let config = RemoteSettingsConfig { + server: Some(RemoteSettingsServer::Prod), + server_url: Some("https://example.com".into()), + bucket_name: None, + collection_name: String::from("the-collection"), + }; + match Client::new(config) { + Ok(_) => panic!("Wanted config error; got client"), + Err(RemoteSettingsError::ConfigError(_)) => {} + Err(err) => panic!("Wanted config error; got {}", err), + } + } + + #[test] fn test_attachment_can_be_downloaded() { viaduct_reqwest::use_reqwest_backend(); let server_info_m = mock("GET", "/") @@ -552,7 +586,10 @@ mod test { .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: None, }; @@ -588,7 +625,10 @@ mod test { .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: None, }; @@ -617,7 +657,10 @@ mod test { .with_header("etag", "\"1000\"") .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: Some(String::from("the-bucket")), }; @@ -644,7 +687,10 @@ mod test { .with_header("Retry-After", "60") .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: Some(String::from("the-bucket")), }; @@ -686,7 +732,10 @@ mod test { .with_header("etag", "\"1000\"") .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: Some(String::from("the-bucket")), }; @@ -810,7 +859,10 @@ mod test { .with_header("etag", "\"1000\"") .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: Some(String::from("the-bucket")), }; @@ -850,7 +902,10 @@ mod test { .with_header("etag", "\"1000\"") .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, collection_name: String::from("the-collection"), bucket_name: Some(String::from("the-bucket")), }; @@ -953,7 +1008,10 @@ mod test { .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, bucket_name: Some(String::from("the-bucket")), collection_name: String::from("the-collection"), }; @@ -982,7 +1040,10 @@ mod test { .create(); let config = RemoteSettingsConfig { - server_url: Some(mockito::server_url()), + server: Some(RemoteSettingsServer::Custom { + url: mockito::server_url(), + }), + server_url: None, bucket_name: Some(String::from("the-bucket")), collection_name: String::from("the-collection"), }; |