Skip to content

Commit

Permalink
fix truncating signature on SAS (#1007)
Browse files Browse the repository at this point in the history
# Description
This fixes the truncation of Azure SAS signatures ending in "=", i.e.
when using non-url-encoded SAS tokens.

# Related Issue(s)
<!---
For example:

- closes #1003
--->
closes #1003

Co-authored-by: Damion Werner <damion.werner@arisense.live>
  • Loading branch information
damiondoesthings and Damion Werner authored Dec 12, 2022
1 parent e0f953b commit 3a9b9b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
18 changes: 18 additions & 0 deletions python/tests/test_fs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import urllib

import pyarrow as pa
import pyarrow.parquet as pq
import pytest
Expand Down Expand Up @@ -204,3 +206,19 @@ def test_roundtrip_azure_sas(azurite_sas_creds, sample_data: pa.Table):
table = dt.to_pyarrow_table()
assert table == sample_data
assert dt.version() == 0


@pytest.mark.azure
@pytest.mark.integration
@pytest.mark.timeout(timeout=5, method="thread")
def test_roundtrip_azure_decoded_sas(azurite_sas_creds, sample_data: pa.Table):
table_path = "az://deltars/roundtrip4"
azurite_sas_creds["SAS_TOKEN"] = urllib.parse.unquote(
azurite_sas_creds["SAS_TOKEN"]
)

write_deltalake(table_path, sample_data, storage_options=azurite_sas_creds)
dt = DeltaTable(table_path, storage_options=azurite_sas_creds)
table = dt.to_pyarrow_table()
assert table == sample_data
assert dt.version() == 0
15 changes: 4 additions & 11 deletions rust/src/builder/azure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,17 +226,10 @@ fn split_sas(sas: &str) -> Result<Vec<(String, String)>, BuilderError> {
.filter(|s| !s.chars().all(char::is_whitespace));
let mut pairs = Vec::new();
for kv_pair_str in kv_str_pairs {
let mut kv = kv_pair_str.trim().split('=');
let k = match kv.next().filter(|k| !k.chars().all(char::is_whitespace)) {
None => {
return Err(BuilderError::MissingCredential);
}
Some(k) => k,
};
let v = match kv.next().filter(|k| !k.chars().all(char::is_whitespace)) {
None => return Err(BuilderError::MissingCredential),
Some(v) => v,
};
let (k, v) = kv_pair_str
.trim()
.split_once('=')
.ok_or(BuilderError::MissingCredential)?;
pairs.push((k.into(), v.into()))
}
Ok(pairs)
Expand Down

0 comments on commit 3a9b9b3

Please sign in to comment.