Skip to content

Commit 71cb6ab

Browse files
committed
update
1 parent 4e2ef21 commit 71cb6ab

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

sdk/storage/Azure.Storage.Blobs/tests/BlobSasTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ public async Task ContainerIdentitySas_AllPermissions()
285285
}
286286

287287
[RecordedTest]
288+
[LiveOnly] // Cannot record Entra ID token
288289
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2026_02_06)]
289290
public async Task ContainerIdentitySAS_DelegatedObjectId()
290291
{
@@ -303,11 +304,11 @@ public async Task ContainerIdentitySAS_DelegatedObjectId()
303304
// We need to get the object ID from the token credential used to authenticate the request
304305
TokenCredential tokenCredential = TestEnvironment.Credential;
305306
AccessToken accessToken = await tokenCredential.GetTokenAsync(
306-
new TokenRequestContext(new[] { "https://storage.azure.com/.default" }),
307+
new TokenRequestContext(Scopes),
307308
CancellationToken.None);
308309

309310
JwtSecurityToken jwtSecurityToken = new JwtSecurityTokenHandler().ReadJwtToken(accessToken.Token);
310-
jwtSecurityToken.Payload.TryGetValue("oid", out object objectId);
311+
jwtSecurityToken.Payload.TryGetValue(Constants.Sas.ObjectId, out object objectId);
311312

312313
BlobSasBuilder blobSasBuilder = new BlobSasBuilder(BlobContainerSasPermissions.Read, Recording.UtcNow.AddHours(1))
313314
{
@@ -333,6 +334,7 @@ public async Task ContainerIdentitySAS_DelegatedObjectId()
333334
}
334335

335336
[RecordedTest]
337+
[LiveOnly] // Cannot record Entra ID token
336338
[ServiceVersion(Min = BlobClientOptions.ServiceVersion.V2026_02_06)]
337339
public async Task ContainerIdentitySAS_DelegatedObjectId_Fail()
338340
{
@@ -351,11 +353,11 @@ public async Task ContainerIdentitySAS_DelegatedObjectId_Fail()
351353
// We need to get the object ID from the token credential used to authenticate the request
352354
TokenCredential tokenCredential = TestEnvironment.Credential;
353355
AccessToken accessToken = await tokenCredential.GetTokenAsync(
354-
new TokenRequestContext(new[] { "https://storage.azure.com/.default" }),
356+
new TokenRequestContext(Scopes),
355357
CancellationToken.None);
356358

357359
JwtSecurityToken jwtSecurityToken = new JwtSecurityTokenHandler().ReadJwtToken(accessToken.Token);
358-
jwtSecurityToken.Payload.TryGetValue("oid", out object objectId);
360+
jwtSecurityToken.Payload.TryGetValue(Constants.Sas.ObjectId, out object objectId);
359361

360362
BlobSasBuilder blobSasBuilder = new BlobSasBuilder(BlobContainerSasPermissions.Read, Recording.UtcNow.AddHours(1))
361363
{

sdk/storage/Azure.Storage.Common/src/Shared/Constants.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ internal static class QuickQuery
539539
/// </summary>
540540
internal static class Sas
541541
{
542+
public const string ObjectId = "oid";
543+
542544
internal static class Permissions
543545
{
544546
public const char Read = 'r';

sdk/storage/Azure.Storage.Common/tests/Shared/StorageTestBase.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,14 @@ public async Task<string> GetAuthToken(string[] scopes = default, TenantConfigur
406406
return "auth token";
407407
}
408408

409-
scopes ??= new string[] { "https://storage.azure.com/.default" };
409+
scopes ??= scopes;
410410
TokenRequestContext tokenRequestContext = new TokenRequestContext(scopes);
411411
AccessToken accessToken = await TestEnvironment.Credential.GetTokenAsync(tokenRequestContext, CancellationToken.None);
412412
return accessToken.Token;
413413
}
414414

415+
public string[] Scopes => ["https://storage.azure.com/.default"];
416+
415417
public string CreateRandomDirectory(string parentPath, string directoryName = default)
416418
{
417419
return Directory.CreateDirectory(Path.Combine(parentPath, string.IsNullOrEmpty(directoryName) ? Recording.Random.NewGuid().ToString() : directoryName)).FullName;

0 commit comments

Comments
 (0)