Skip to content

Commit c672a1d

Browse files
committed
Fix regression in #13 + add a test
1 parent b404284 commit c672a1d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Fix a regression in #13 + fix add a test
4+
35
## [0.5.9] 2025-05-31
46

57
- Add support for additional headers to all endpoints

lib/azure_blob/entra_id_signer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def authorization_header(uri:, verb:, headers: {})
2525
end
2626

2727
def sas_token(uri, options = {})
28+
delegation_key.refresh
2829
to_sign = [
2930
options[:permissions],
3031
options[:start],
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "test_helper"
4+
require "securerandom"
5+
6+
class TestUserDelegationKeyExpiration < TestCase
7+
attr_reader :client, :key, :content
8+
9+
EXPIRATION = 120
10+
11+
def setup
12+
skip if using_shared_key
13+
@account_name = ENV["AZURE_ACCOUNT_NAME"]
14+
@container = ENV["AZURE_PRIVATE_CONTAINER"]
15+
@principal_id = ENV["AZURE_PRINCIPAL_ID"]
16+
@host = ENV["STORAGE_BLOB_HOST"]
17+
@client = AzureBlob::Client.new(
18+
account_name: @account_name,
19+
container: @container,
20+
principal_id: @principal_id,
21+
host: @host,
22+
)
23+
@uid = SecureRandom.uuid
24+
@key = "test-delegation-expiration-#{@uid}"
25+
@content = "Test content for delegation key expiration"
26+
end
27+
28+
def teardown
29+
client.delete_blob(key) rescue AzureBlob::Http::FileNotFoundError
30+
end
31+
32+
def test_user_delegation_key_auto_refresh_on_expiration
33+
original_expiration = AzureBlob::UserDelegationKey.send(:remove_const, :EXPIRATION)
34+
original_buffer = AzureBlob::UserDelegationKey.send(:remove_const, :EXPIRATION_BUFFER)
35+
AzureBlob::UserDelegationKey.const_set(:EXPIRATION, 2)
36+
AzureBlob::UserDelegationKey.const_set(:EXPIRATION_BUFFER, 0)
37+
38+
begin
39+
client.create_block_blob(key, content)
40+
41+
uri = client.signed_uri(
42+
key,
43+
permissions: "r",
44+
expiry: Time.at(Time.now.to_i + EXPIRATION).utc.iso8601,
45+
)
46+
47+
response = AzureBlob::Http.new(uri, { "x-ms-blob-type": "BlockBlob" }).get
48+
49+
assert_equal response, content
50+
51+
sleep 3
52+
53+
uri = client.signed_uri(
54+
key,
55+
permissions: "r",
56+
expiry: Time.at(Time.now.to_i + EXPIRATION).utc.iso8601,
57+
)
58+
59+
response = AzureBlob::Http.new(uri, { "x-ms-blob-type": "BlockBlob" }).get
60+
61+
assert_equal response, content
62+
ensure
63+
AzureBlob::UserDelegationKey.send(:remove_const, :EXPIRATION)
64+
AzureBlob::UserDelegationKey.send(:remove_const, :EXPIRATION_BUFFER)
65+
AzureBlob::UserDelegationKey.const_set(:EXPIRATION, original_expiration)
66+
AzureBlob::UserDelegationKey.const_set(:EXPIRATION_BUFFER, original_buffer)
67+
end
68+
end
69+
end

0 commit comments

Comments
 (0)