Skip to content

Commit

Permalink
Fix test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
EmmaZhu committed Dec 16, 2024
1 parent 6e3044d commit b1d0a39
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 167 deletions.
20 changes: 5 additions & 15 deletions tests/blob/apis/blobbatch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ describe("Blob batch API", () => {
it("SubmitBatch batch deleting @loki @sql", async () => {
const blobBatchClient = serviceClient.getBlobBatchClient();

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

// Submit batch request and verify response.
const urls = blobClients.map((b) => b.url);
Expand Down Expand Up @@ -107,9 +105,7 @@ describe("Blob batch API", () => {
it("SubmitBatch within container scope - batch set tier @loki @sql", async () => {
const blobBatchClient = containerClient.getBlobBatchClient();

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

// Submit batch request and verify response.
const urls = blobClients.map((b) => b.url);
Expand All @@ -136,9 +132,7 @@ describe("Blob batch API", () => {
it("SubmitBatch batch set tier @loki @sql", async () => {
const blobBatchClient = serviceClient.getBlobBatchClient();

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

// Submit batch request and verify response.
const urls = blobClients.map((b) => b.url);
Expand Down Expand Up @@ -173,9 +167,7 @@ describe("Blob batch API", () => {
const blobclientsNew: BlobClient[] = [];
blobclientsNew.push(blockBlobClientNew);

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

// Submit batch request and verify response.
const urls = blobclientsNew.map((b) => b.url);
Expand Down Expand Up @@ -332,9 +324,7 @@ describe("Blob batch API", () => {
it("SubmitBatch batch with different operations @loki @sql", async () => {
const blobBatchClient = serviceClient.getBlobBatchClient();

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

// Submit batch request and verify response.
const urls = blobClients.map((b) => b.url);
Expand Down
8 changes: 3 additions & 5 deletions tests/blob/apis/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe("ServiceAPIs", () => {
await serviceClient.getUserDelegationKey(startTime, expiryTime);
assert.fail("Should fail to invoke getUserDelegationKey with account key credentials")
} catch (error) {
assert.strictEqual((error as any).details.AuthenticationErrorDetail, "Only authentication scheme Bearer is supported");
assert.strictEqual((error as any).details.authenticationErrorDetail, "Only authentication scheme Bearer is supported");
}
});

Expand All @@ -77,9 +77,7 @@ describe("ServiceAPIs", () => {
const sasTokenExpiry = new Date();
sasTokenExpiry.setDate(sasTokenExpiry.getDate() + 1);

// By default, credential is always the last element of pipeline factories
const factories = (serviceClient as any).pipeline.factories;
const sharedKeyCredential = factories[factories.length - 1];
const sharedKeyCredential = serviceClient.credential as StorageSharedKeyCredential;

const sas = generateAccountSASQueryParameters(
{
Expand Down Expand Up @@ -107,7 +105,7 @@ describe("ServiceAPIs", () => {
await serviceClientWithSAS.getUserDelegationKey(skStart, skExpiry);
assert.fail("Should fail to invoke getUserDelegationKey with SAS token credentials")
} catch (error) {
assert.strictEqual((error as any).details.AuthenticationErrorDetail, "Only authentication scheme Bearer is supported");
assert.strictEqual((error as any).details.authenticationErrorDetail, "Only authentication scheme Bearer is supported");
}
});

Expand Down
43 changes: 21 additions & 22 deletions tests/blob/blobCorsRequest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import BlobTestServerFactory from "../BlobTestServerFactory";
import {
EMULATOR_ACCOUNT_KEY,
EMULATOR_ACCOUNT_NAME,
getResponseHeader,
sleep
} from "../testutils";
import OPTIONSRequestPolicyFactory from "./RequestPolicy/OPTIONSRequestPolicyFactory";
Expand Down Expand Up @@ -629,9 +630,9 @@ describe("Blob Cors requests test", () => {

const res: any = await serviceClientWithOrigin.getProperties();

assert.ok(res["access-control-allow-origin"] === undefined);
assert.ok(res["access-control-expose-headers"] === undefined);
assert.ok(res.vary === undefined);
assert.ok(getResponseHeader(res, "access-control-allow-origin") === undefined);
assert.ok(getResponseHeader(res, "access-control-expose-headers") === undefined);
assert.ok(getResponseHeader(res, "vary") === undefined);
});

it("Service with mismatching cors rules should response header Vary @loki @sql", async () => {
Expand Down Expand Up @@ -667,10 +668,10 @@ describe("Blob Cors requests test", () => {
const serviceClientWithOrigin = new BlobServiceClient(baseURL, pipeline);

let res: any = await serviceClientWithOrigin.getProperties();
assert.ok(res.vary !== undefined);
assert.ok(getResponseHeader(res, "vary") !== undefined);

res = await serviceClient.getProperties();
assert.ok(res.vary === undefined);
assert.ok(getResponseHeader(res, "vary") === undefined);
});

it("Request Match rule exists that allows all origins (*) @loki @sql", async () => {
Expand Down Expand Up @@ -706,14 +707,14 @@ describe("Blob Cors requests test", () => {
const serviceClientWithOrigin = new BlobServiceClient(baseURL, pipeline);

let res: any = await serviceClientWithOrigin.getProperties();
assert.ok(res["access-control-allow-origin"] === "*");
assert.ok(res.vary === undefined);
assert.ok(res["access-control-expose-headers"] !== undefined);
assert.ok(getResponseHeader(res, "access-control-allow-origin") === "*");
assert.ok(getResponseHeader(res, "vary") === undefined);
assert.ok(getResponseHeader(res, "access-control-expose-headers") !== undefined);

res = await serviceClient.getProperties();
assert.ok(res["access-control-allow-origin"] === undefined);
assert.ok(res.vary === undefined);
assert.ok(res["access-control-expose-headers"] === undefined);
assert.ok(getResponseHeader(res, "access-control-allow-origin") === undefined);
assert.ok(getResponseHeader(res, "vary") === undefined);
assert.ok(getResponseHeader(res, "access-control-expose-headers") === undefined);
});

it("Request Match rule exists for exact origin @loki @sql", async () => {
Expand Down Expand Up @@ -749,9 +750,9 @@ describe("Blob Cors requests test", () => {
const serviceClientWithOrigin = new BlobServiceClient(baseURL, pipeline);

const res: any = await serviceClientWithOrigin.getProperties();
assert.ok(res["access-control-allow-origin"] === origin);
assert.ok(res.vary !== undefined);
assert.ok(res["access-control-expose-headers"] !== undefined);
assert.ok(getResponseHeader(res, "access-control-allow-origin") === origin);
assert.ok(getResponseHeader(res, "vary") !== undefined);
assert.ok(getResponseHeader(res, "access-control-expose-headers") !== undefined);
});

it("Requests with error response should apply for CORS @loki @sql", async () => {
Expand Down Expand Up @@ -793,13 +794,11 @@ describe("Blob Cors requests test", () => {
await containerClientWithOrigin.getProperties();
} catch (err) {
assert.ok(
err.response.headers._headersMap["access-control-allow-origin"]
.value === origin
err.response.headers.get("access-control-allow-origin") === origin
);
assert.ok(err.response.headers._headersMap.vary !== undefined);
assert.ok(err.response.headers.get("vary") !== undefined);
assert.ok(
err.response.headers._headersMap["access-control-expose-headers"] !==
undefined
err.response.headers.get("access-control-expose-headers") !== undefined
);
}
});
Expand Down Expand Up @@ -846,8 +845,8 @@ describe("Blob Cors requests test", () => {
const serviceClientWithOrigin = new BlobServiceClient(baseURL, pipeline);

const res: any = await serviceClientWithOrigin.getProperties();
assert.ok(res["access-control-allow-origin"] === origin);
assert.ok(res.vary !== undefined);
assert.ok(res["access-control-expose-headers"] !== undefined);
assert.ok(getResponseHeader(res, "access-control-allow-origin") === origin);
assert.ok(getResponseHeader(res, "vary") !== undefined);
assert.ok(getResponseHeader(res, "access-control-expose-headers") !== undefined);
});
});
8 changes: 4 additions & 4 deletions tests/blob/oauth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ describe("Blob OAuth Basic", () => {
err.message.includes("Server failed to authenticate the request."),
true
);
assert.deepStrictEqual(err.details.AuthenticationErrorDetail.includes("audience"), true);
assert.deepStrictEqual(err.details.authenticationErrorDetail.includes("audience"), true);
return;
}
assert.fail();
Expand Down Expand Up @@ -653,7 +653,7 @@ describe("Blob OAuth Basic", () => {
err.message.includes("Server failed to authenticate the request."),
true
);
assert.deepStrictEqual(err.details.AuthenticationErrorDetail.includes("issuer"), true);
assert.deepStrictEqual(err.details.authenticationErrorDetail.includes("issuer"), true);
return;
}
assert.fail();
Expand Down Expand Up @@ -691,7 +691,7 @@ describe("Blob OAuth Basic", () => {
err.message.includes("Server failed to authenticate the request."),
true
);
assert.deepStrictEqual(err.details.AuthenticationErrorDetail.includes("Lifetime"), true);
assert.deepStrictEqual(err.details.authenticationErrorDetail.includes("Lifetime"), true);
return;
}
assert.fail();
Expand Down Expand Up @@ -729,7 +729,7 @@ describe("Blob OAuth Basic", () => {
err.message.includes("Server failed to authenticate the request."),
true
);
assert.deepStrictEqual(err.details.AuthenticationErrorDetail.includes("expire"), true);
assert.deepStrictEqual(err.details.authenticationErrorDetail.includes("expire"), true);
return;
}
assert.fail();
Expand Down
Loading

0 comments on commit b1d0a39

Please sign in to comment.