Skip to content

Commit d561535

Browse files
committed
create live tests for createSession
- downgrade blobserviceversion to 2026_04_06 - change AZURE_LIVE_TEST_SERVICE_VERSION to V2026_04_06 in ci.system.properties in azure-storage-common - create both sync and async
1 parent 4c94ea6 commit d561535

File tree

7 files changed

+116
-20
lines changed

7 files changed

+116
-20
lines changed

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobContainerAsyncClient.java

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
import com.azure.storage.blob.implementation.models.EncryptionScope;
2929
import com.azure.storage.blob.implementation.models.ListBlobsFlatSegmentResponse;
3030
import com.azure.storage.blob.implementation.models.ListBlobsHierarchySegmentResponse;
31+
import com.azure.storage.blob.implementation.models.AuthenticationType;
32+
import com.azure.storage.blob.implementation.models.CreateSessionConfiguration;
33+
import com.azure.storage.blob.implementation.models.CreateSessionResponse;
3134
import com.azure.storage.blob.implementation.util.BlobConstants;
3235
import com.azure.storage.blob.implementation.util.BlobSasImplUtil;
3336
import com.azure.storage.blob.implementation.util.ModelHelper;
@@ -1691,11 +1694,39 @@ public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureV
16911694
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
16921695
}
16931696

1694-
// private boolean validateNoTime(BlobRequestConditions modifiedRequestConditions) {
1695-
// if (modifiedRequestConditions == null) {
1696-
// return true;
1697-
// }
1698-
// return modifiedRequestConditions.getIfModifiedSince() == null
1699-
// && modifiedRequestConditions.getIfUnmodifiedSince() == null;
1700-
// }
1697+
/**
1698+
* Creates a session scoped to this container. The session provides temporary credentials (a session token and
1699+
* session key) that can be used to sign subsequent requests using the Shared Key protocol.
1700+
*
1701+
* @return A {@link Mono} containing the {@link CreateSessionResponse} with session credentials.
1702+
*/
1703+
@ServiceMethod(returns = ReturnType.SINGLE)
1704+
public Mono<CreateSessionResponse> createSession() {
1705+
return createSessionWithResponse().flatMap(FluxUtil::toMono);
1706+
}
1707+
1708+
/**
1709+
* Creates a session scoped to this container. The session provides temporary credentials (a session token and
1710+
* session key) that can be used to sign subsequent requests using the Shared Key protocol.
1711+
*
1712+
* @return A {@link Mono} containing a {@link Response} with the {@link CreateSessionResponse}.
1713+
*/
1714+
@ServiceMethod(returns = ReturnType.SINGLE)
1715+
public Mono<Response<CreateSessionResponse>> createSessionWithResponse() {
1716+
try {
1717+
return withContext(this::createSessionWithResponse);
1718+
} catch (RuntimeException ex) {
1719+
return monoError(LOGGER, ex);
1720+
}
1721+
}
1722+
1723+
Mono<Response<CreateSessionResponse>> createSessionWithResponse(Context context) {
1724+
context = context == null ? Context.NONE : context;
1725+
CreateSessionConfiguration config
1726+
= new CreateSessionConfiguration().setAuthenticationType(AuthenticationType.HMAC);
1727+
return this.azureBlobStorage.getContainers()
1728+
.createSessionWithResponseAsync(containerName, config, context)
1729+
.map(response -> new SimpleResponse<>(response, response.getValue()));
1730+
}
1731+
17011732
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobContainerClient.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
import com.azure.storage.blob.implementation.models.FilterBlobSegment;
3232
import com.azure.storage.blob.implementation.models.ListBlobsFlatSegmentResponse;
3333
import com.azure.storage.blob.implementation.models.ListBlobsHierarchySegmentResponse;
34+
import com.azure.storage.blob.implementation.models.AuthenticationType;
35+
import com.azure.storage.blob.implementation.models.CreateSessionConfiguration;
36+
import com.azure.storage.blob.implementation.models.CreateSessionResponse;
3437
import com.azure.storage.blob.implementation.util.BlobConstants;
3538
import com.azure.storage.blob.implementation.util.BlobSasImplUtil;
3639
import com.azure.storage.blob.implementation.util.ModelHelper;
@@ -1509,4 +1512,33 @@ public String generateSas(BlobServiceSasSignatureValues blobServiceSasSignatureV
15091512
.generateSas(SasImplUtils.extractSharedKeyCredential(getHttpPipeline()), stringToSignHandler, context);
15101513
}
15111514

1515+
/**
1516+
* Creates a session scoped to this container. The session provides temporary credentials (a session token and
1517+
* session key) that can be used to sign subsequent requests using the Shared Key protocol.
1518+
*
1519+
* @param timeout An optional timeout value beyond which a {@link RuntimeException} will be raised.
1520+
* @param context Additional context that is passed through the Http pipeline during the service call.
1521+
* @return A response containing the {@link CreateSessionResponse} with session credentials.
1522+
*/
1523+
@ServiceMethod(returns = ReturnType.SINGLE)
1524+
public Response<CreateSessionResponse> createSessionWithResponse(Duration timeout, Context context) {
1525+
Context finalContext = context == null ? Context.NONE : context;
1526+
CreateSessionConfiguration config
1527+
= new CreateSessionConfiguration().setAuthenticationType(AuthenticationType.HMAC);
1528+
Callable<Response<CreateSessionResponse>> operation = () -> this.azureBlobStorage.getContainers()
1529+
.createSessionWithResponse(containerName, config, finalContext);
1530+
return sendRequest(operation, timeout, BlobStorageException.class);
1531+
}
1532+
1533+
/**
1534+
* Creates a session scoped to this container. The session provides temporary credentials (a session token and
1535+
* session key) that can be used to sign subsequent requests using the Shared Key protocol.
1536+
*
1537+
* @return The {@link CreateSessionResponse} with session credentials.
1538+
*/
1539+
@ServiceMethod(returns = ReturnType.SINGLE)
1540+
public CreateSessionResponse createSession() {
1541+
return createSessionWithResponse(null, Context.NONE).getValue();
1542+
}
1543+
15121544
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/BlobServiceVersion.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,7 @@ public enum BlobServiceVersion implements ServiceVersion {
157157
/**
158158
* Service version {@code 2026-04-06}.
159159
*/
160-
V2026_04_06("2026-04-06"),
161-
162-
/**
163-
* Service version {@code 2026-06-06}.
164-
*/
165-
V2026_06_06("2026-06-06");
160+
V2026_04_06("2026-04-06");
166161

167162
private final String version;
168163

@@ -184,6 +179,6 @@ public String getVersion() {
184179
* @return the latest {@link BlobServiceVersion}
185180
*/
186181
public static BlobServiceVersion getLatest() {
187-
return V2026_06_06;
182+
return V2026_04_06;
188183
}
189184
}

sdk/storage/azure-storage-blob/src/main/java/com/azure/storage/blob/implementation/ContainersImpl.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ Mono<Response<CreateSessionResponse>> createSession(@HostParam("url") String url
948948
@PathParam("containerName") String containerName, @QueryParam("restype") String restype,
949949
@QueryParam("comp") String comp,
950950
@BodyParam("application/xml") CreateSessionConfiguration createSessionConfiguration,
951-
@HeaderParam("Accept") String accept, Context context);
951+
@HeaderParam("x-ms-version") String version, @HeaderParam("Accept") String accept, Context context);
952952

953953
@Post("/{containerName}")
954954
@ExpectedResponses({ 201 })
@@ -957,7 +957,7 @@ Response<CreateSessionResponse> createSessionSync(@HostParam("url") String url,
957957
@PathParam("containerName") String containerName, @QueryParam("restype") String restype,
958958
@QueryParam("comp") String comp,
959959
@BodyParam("application/xml") CreateSessionConfiguration createSessionConfiguration,
960-
@HeaderParam("Accept") String accept, Context context);
960+
@HeaderParam("x-ms-version") String version, @HeaderParam("Accept") String accept, Context context);
961961
}
962962

963963
/**
@@ -6764,8 +6764,8 @@ public Mono<Response<CreateSessionResponse>> createSessionWithResponseAsync(Stri
67646764
final String comp = "session";
67656765
final String accept = "application/xml";
67666766
return service
6767-
.createSession(this.client.getUrl(), containerName, restype, comp, createSessionConfiguration, accept,
6768-
context)
6767+
.createSession(this.client.getUrl(), containerName, restype, comp, createSessionConfiguration,
6768+
this.client.getVersion(), accept, context)
67696769
.onErrorMap(BlobStorageExceptionInternal.class, ModelHelper::mapToBlobStorageException);
67706770
}
67716771

@@ -6825,7 +6825,7 @@ public Response<CreateSessionResponse> createSessionWithResponse(String containe
68256825
final String comp = "session";
68266826
final String accept = "application/xml";
68276827
return service.createSessionSync(this.client.getUrl(), containerName, restype, comp,
6828-
createSessionConfiguration, accept, context);
6828+
createSessionConfiguration, this.client.getVersion(), accept, context);
68296829
} catch (BlobStorageExceptionInternal internalException) {
68306830
throw ModelHelper.mapToBlobStorageException(internalException);
68316831
}

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerApiTests.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import com.azure.core.test.utils.MockTokenCredential;
1111
import com.azure.core.util.Context;
1212
import com.azure.identity.DefaultAzureCredentialBuilder;
13+
import com.azure.storage.blob.implementation.models.AuthenticationType;
14+
import com.azure.storage.blob.implementation.models.CreateSessionResponse;
1315
import com.azure.storage.blob.models.AccessTier;
1416
import com.azure.storage.blob.models.AppendBlobItem;
1517
import com.azure.storage.blob.models.BlobAccessPolicy;
@@ -2128,4 +2130,20 @@ public void getBlobContainerUrlEncodesContainerName() {
21282130
// then:
21292131
// assertThrows(BlobStorageException.class, () ->
21302132
// }
2133+
2134+
@Test
2135+
// @RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2026-06-06")
2136+
public void createSessionReturnsTokenAndKey() {
2137+
BlobContainerClient oauthCc = getOAuthServiceClient().getBlobContainerClient(cc.getBlobContainerName());
2138+
Response<CreateSessionResponse> response = oauthCc.createSessionWithResponse(null, null);
2139+
2140+
assertResponseStatusCode(response, 201);
2141+
CreateSessionResponse session = response.getValue();
2142+
assertNotNull(session.getId());
2143+
assertNotNull(session.getExpiration());
2144+
assertNotNull(session.getCredentials());
2145+
assertNotNull(session.getCredentials().getSessionToken());
2146+
assertNotNull(session.getCredentials().getSessionKey());
2147+
assertEquals(AuthenticationType.HMAC, session.getAuthenticationType());
2148+
}
21312149
}

sdk/storage/azure-storage-blob/src/test/java/com/azure/storage/blob/ContainerAsyncApiTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import com.azure.core.util.Context;
1313
import com.azure.core.util.polling.PollerFlux;
1414
import com.azure.identity.DefaultAzureCredentialBuilder;
15+
import com.azure.storage.blob.implementation.models.AuthenticationType;
16+
import com.azure.storage.blob.implementation.models.CreateSessionResponse;
1517
import com.azure.storage.blob.models.*;
1618
import com.azure.storage.blob.options.BlobContainerCreateOptions;
1719
import com.azure.storage.blob.options.BlobParallelUploadOptions;
@@ -2142,4 +2144,22 @@ public void getBlobContainerUrlEncodesContainerName() {
21422144

21432145
assertTrue(containerClient.getBlobContainerUrl().contains("my%20container"));
21442146
}
2147+
2148+
@Test
2149+
// @RequiredServiceVersion(clazz = BlobServiceVersion.class, min = "2026-06-06")
2150+
public void createSessionReturnsTokenAndKey() {
2151+
BlobContainerAsyncClient oauthCcAsync
2152+
= getOAuthServiceAsyncClient().getBlobContainerAsyncClient(ccAsync.getBlobContainerName());
2153+
2154+
StepVerifier.create(oauthCcAsync.createSessionWithResponse()).assertNext(response -> {
2155+
assertEquals(201, response.getStatusCode());
2156+
CreateSessionResponse session = response.getValue();
2157+
assertNotNull(session.getId());
2158+
assertNotNull(session.getExpiration());
2159+
assertNotNull(session.getCredentials());
2160+
assertNotNull(session.getCredentials().getSessionToken());
2161+
assertNotNull(session.getCredentials().getSessionKey());
2162+
assertEquals(AuthenticationType.HMAC, session.getAuthenticationType());
2163+
}).verifyComplete();
2164+
}
21452165
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
AZURE_LIVE_TEST_SERVICE_VERSION=V2026_06_06
1+
AZURE_LIVE_TEST_SERVICE_VERSION=V2026_04_06
22
AZURE_STORAGE_SAS_SERVICE_VERSION=2026-06-06

0 commit comments

Comments
 (0)