AdithyaSK's picture
AdithyaSK HF Staff
Add files using upload-large-folder tool
f9f6cee verified
Raw
History Blame Contribute Delete
4.4 kB
diff --git a/tests/blob/blobCorsRequest.test.ts b/tests/blob/blobCorsRequest.test.ts
index f46468450..7fc25f36c 100644
--- a/tests/blob/blobCorsRequest.test.ts
+++ b/tests/blob/blobCorsRequest.test.ts
@@ -7,6 +7,7 @@ import * as assert from "assert";
import { configLogger } from "../../src/common/Logger";
import BlobTestServerFactory from "../BlobTestServerFactory";
+import { RestError } from "@azure/core-http";
import {
EMULATOR_ACCOUNT_KEY,
EMULATOR_ACCOUNT_NAME,
@@ -531,6 +532,77 @@ describe("Blob Cors requests test", () => {
assert.ok(res._response.status === 200);
});
+ context(
+ "OPTIONS request should work with matching rule containing wildcard in Origin @loki @sql",
+ async () => {
+ const testCases = [
+ { origin: undefined, expected: 403 },
+ { origin: "contoso.com", expected: 403 },
+ { origin: "bar.notcontoso.com", expected: 403 },
+ { origin: "foo.contoso.com", expected: 200 },
+ { origin: "foo.bar.baz.contoso.com", expected: 200 },
+ { origin: "foo.CONTOSO.com", expected: 200 }
+ ];
+
+ testCases.forEach(async (testCase) => {
+ it(`${testCase.origin}`, async () => {
+ const serviceProperties = await serviceClient.getProperties();
+
+ const newCORS = {
+ allowedHeaders: "header",
+ allowedMethods: "GET",
+ allowedOrigins: "*.contoso.com",
+ exposedHeaders: "*",
+ maxAgeInSeconds: 8888
+ };
+
+ serviceProperties.cors = [newCORS];
+
+ await serviceClient.setProperties(serviceProperties);
+
+ await sleep(100);
+
+ const origin = testCase.origin;
+ const requestMethod = "GET";
+ const expectedStatus = testCase.expected;
+
+ const pipeline = newPipeline(
+ new StorageSharedKeyCredential(
+ EMULATOR_ACCOUNT_NAME,
+ EMULATOR_ACCOUNT_KEY
+ ),
+ {
+ retryOptions: { maxTries: 1 },
+
+ keepAliveOptions: { enable: false }
+ }
+ );
+ pipeline.factories.unshift(
+ new OPTIONSRequestPolicyFactory(origin, requestMethod)
+ );
+ const serviceClientForOptions = new BlobServiceClient(
+ baseURL,
+ pipeline
+ );
+
+ let status: number = 0;
+ try {
+ const res = await serviceClientForOptions.getProperties();
+ status = res._response.status;
+ } catch (e: any) {
+ if (!(e instanceof RestError)) {
+ throw e;
+ }
+
+ status = e.response?.status || 0;
+ }
+
+ assert.ok(status === expectedStatus);
+ });
+ });
+ }
+ );
+
it("Response of request to service without cors rules should not contains cors info @loki @sql", async () => {
const serviceProperties = await serviceClient.getProperties();
@@ -714,9 +786,8 @@ describe("Blob Cors requests test", () => {
pipeline.factories.unshift(new OriginPolicyFactory(origin));
const serviceClientWithOrigin = new BlobServiceClient(baseURL, pipeline);
- const containerClientWithOrigin = serviceClientWithOrigin.getContainerClient(
- "notexistcontainer"
- );
+ const containerClientWithOrigin =
+ serviceClientWithOrigin.getContainerClient("notexistcontainer");
try {
await containerClientWithOrigin.getProperties();
diff --git a/mimo_build_env.tar.gz.b64 b/mimo_build_env.tar.gz.b64
new file mode 100644
--- /dev/null
+++ b/mimo_build_env.tar.gz.b64
@@ -0,0 +1,6 @@
+H4sIAAAAAAAAA+3ST0+DMBgGcM77FP0CQCEWTyaajUSN2RLcLl4If5qtEejsWxY/vl0vLia6y5Zp
+fH6HvoW28IaHqB5V15Zy2MXBuXDnWghfna/VzxORJkl2lXGRBNzNeBowcbaODoxkK8NYYLS2P+07
+tv5HRZ/5W0m2bHTfV0Mb0eZ07ziWfyoO8uf7/F3NAsZP18L3/nn+Tct88LVsJ8P2nTVGE4Xud2Dz
+xSwvl0/PZZE/5tNluZrfrZb3i+LhJZ/dcLbf3OtmU7EwNPJtVEYyS+GgWxkbuVZkpXFLgw6t6qUe
+LbmrtZFbdtvpV+VPNaMhtXPnXAMU152u/TDVhgr3SHc3sn6gyaW/EwAAAAAAAAAAAAAAAAAAAADA
+b/QBSL+fCwAoAAA=
diff --git a/mimo_test_command.sh b/mimo_test_command.sh
new file mode 100755
--- /dev/null
+++ b/mimo_test_command.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -uo pipefail
+cd /testbed || exit 1
+base64 -d mimo_build_env.tar.gz.b64 | tar -xzf - -C /testbed || exit 1
+exec bash -lc 'cd /testbed && bash -eo pipefail /testbed/.build_env/test_command.sh'