Skip to content

Commit 71bbee2

Browse files
authored
fix signing blob URLs where the blob name contains slashes (#514)
1 parent b5216cb commit 71bbee2

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

sdk/storage/src/blob/clients/blob_client.rs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ impl BlobClient {
6868
where
6969
I: IntoIterator<Item = &'a str>,
7070
{
71+
let blob_name_with_segments = self.blob_name.split('/').into_iter().chain(segments);
7172
self.container_client
72-
.url_with_segments(Some(self.blob_name.as_str()).into_iter().chain(segments))
73+
.url_with_segments(blob_name_with_segments)
7374
}
7475

7576
pub fn get(&self) -> GetBlobBuilder {
@@ -209,6 +210,49 @@ impl BlobClient {
209210
}
210211
}
211212

213+
#[cfg(test)]
214+
mod tests {
215+
use super::*;
216+
use crate::blob::clients::AsBlobClient;
217+
218+
struct FakeSas {
219+
token: String,
220+
}
221+
impl SasToken for FakeSas {
222+
fn token(&self) -> String {
223+
self.token.clone()
224+
}
225+
}
226+
227+
fn build_url(container_name: &str, blob_name: &str, sas: &FakeSas) -> url::Url {
228+
let storage_account = StorageAccountClient::new_emulator_default().as_storage_client();
229+
storage_account
230+
.as_container_client(container_name)
231+
.as_blob_client(blob_name)
232+
.generate_signed_blob_url(sas)
233+
.expect("build url failed")
234+
}
235+
236+
#[test]
237+
fn test_generate_url() {
238+
let sas = FakeSas {
239+
token: "fake_token".to_owned(),
240+
};
241+
242+
let url = build_url("a", "b", &sas);
243+
assert_eq!(
244+
url.as_str(),
245+
"http://127.0.0.1:10000/devstoreaccount1/a/b?fake_token"
246+
);
247+
248+
let url = build_url("a", "b/c/d", &sas);
249+
assert_eq!(
250+
url.as_str(),
251+
"http://127.0.0.1:10000/devstoreaccount1/a/b/c/d?fake_token"
252+
);
253+
}
254+
}
255+
212256
#[cfg(test)]
213257
#[cfg(feature = "test_integration")]
214258
mod integration_tests {

0 commit comments

Comments
 (0)