File size: 4,395 Bytes
f9f6cee | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 | 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'
|