Skip to content

Commit

Permalink
[tables] allows non-default port for Azurite emulator (#32262)
Browse files Browse the repository at this point in the history
This PR addresses the issue of Azurite emulator endpoint with a
non-default
port (one that is not 10002) being treated as Cosmos endpoint.

-------

### Packages impacted by this PR
`@azure/data-tables`

### Issues associated with this PR
#32239
  • Loading branch information
jeremymeng authored Dec 30, 2024
1 parent 2b60b8e commit 36a3ba2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sdk/tables/data-tables/src/utils/isCosmosEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@ export function isCosmosEndpoint(url: string): boolean {
return true;
}

if (parsedURL.hostname === "localhost" && parsedURL.port !== "10002") {
// Azurite emulator IP-style URL for table?
if (
(parsedURL.hostname === "localhost" || parsedURL.hostname === "127.0.0.1") &&
parsedURL.pathname.startsWith("/devstoreaccount1")
) {
return false;
}

const azuriteAccounts = process?.env?.AZURITE_ACCOUNTS?.split(":");
if (azuriteAccounts?.[0] && parsedURL.hostname.includes(azuriteAccounts[0])) {
return false;
}

if (parsedURL.hostname === "localhost") {
return true;
}

Expand Down
42 changes: 42 additions & 0 deletions sdk/tables/data-tables/test/internal/isCosmosEndpoint.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { describe, it, assert } from "vitest";
import { isCosmosEndpoint } from "../../src/utils/isCosmosEndpoint.js";

describe("isCosmosEndpoint", () => {
it("returns true for cosmosdb.* host", () => {
const result = isCosmosEndpoint("https://abc.table.cosmosdb.azure.com");
assert.isTrue(result);
});

it("returns true for cosmos.* host", () => {
const result = isCosmosEndpoint("https://abc.table.cosmos.azure.com");
assert.isTrue(result);
});

it("returns true for localhost", () => {
const result = isCosmosEndpoint("https://localhost:8092");
assert.isTrue(result);
});

it("returns false for azurite default endpoint", () => {
const result = isCosmosEndpoint("https://127.0.0.1:10002/devstoreaccount1");
assert.isFalse(result);
});

it("returns false for azurite default endpoint with non-default port", () => {
const result = isCosmosEndpoint("https://127.0.0.1:20002/devstoreaccount1");
assert.isFalse(result);
});

it("returns false for azurite default localhost endpoint", () => {
const result = isCosmosEndpoint("https://localhost:10002/devstoreaccount1");
assert.isFalse(result);
});

it("returns false for azurite default localhost endpoint with non-default port", () => {
const result = isCosmosEndpoint("https://localhost:20002/devstoreaccount1");
assert.isFalse(result);
});
});

0 comments on commit 36a3ba2

Please sign in to comment.