Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/azure/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,8 @@ fn url_from_env(env_name: &str, default_url: &str) -> Result<Url> {
Ok(url)
}

fn split_sas(sas: &str) -> Result<Vec<(String, String)>, Error> {
/// Parse a SAS token string into the query pairs expected by [`AzureCredential::SASToken`].
pub fn split_sas(sas: &str) -> Result<Vec<(String, String)>> {
let sas = percent_decode_str(sas)
.decode_utf8()
.map_err(|source| Error::DecodeSasKey { source })?;
Expand Down Expand Up @@ -1273,6 +1274,27 @@ mod tests {
assert_eq!(expected, pairs);
}

#[test]
fn azure_test_split_sas_trims_leading_question_mark_and_skips_empties() {
let pairs = split_sas("?&sv=2021-10-04& &sp=r").unwrap();
assert_eq!(
pairs,
vec![
("sv".to_string(), "2021-10-04".to_string()),
("sp".to_string(), "r".to_string()),
],
);
}

#[test]
fn azure_test_split_sas_rejects_missing_equals() {
let err = split_sas("sv=2021-10-04&bogus").unwrap_err();
assert!(
err.to_string().contains("Missing component"),
"unexpected error: {err}",
);
}

#[test]
fn azure_test_client_opts() {
let key = "AZURE_PROXY_URL";
Expand Down
2 changes: 1 addition & 1 deletion src/azure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub type AzureCredentialProvider = Arc<dyn CredentialProvider<Credential = Azure
use crate::azure::client::AzureClient;
use crate::client::parts::Parts;
use crate::list::{PaginatedListOptions, PaginatedListResult, PaginatedListStore};
pub use builder::{AzureConfigKey, MicrosoftAzureBuilder};
pub use builder::{AzureConfigKey, MicrosoftAzureBuilder, split_sas};
pub use credential::AzureCredential;

const STORE: &str = "MicrosoftAzure";
Expand Down
Loading