diff --git a/src/HostedExplorer.test.tsx b/src/HostedExplorer.test.tsx index 083700e0e..22629c078 100644 --- a/src/HostedExplorer.test.tsx +++ b/src/HostedExplorer.test.tsx @@ -63,11 +63,15 @@ const dispatchPostMessage = (data: unknown, origin: string) => { window.dispatchEvent(event); }; +// Deliberately invalid account name +const FAKE_ACCOUNT_NAME: string = "-FakeAccount-"; +const FAKE_KEY: string = ""; + describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("accepts a valid SQL connection string from an allowed origin", async () => { render(); - const validConnStr = "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGVzdGtleQ==;"; + const validConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.documents.azure.com:443/;AccountKey=${FAKE_KEY};`; await act(async () => { dispatchPostMessage( @@ -83,7 +87,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("accepts a valid Mongo connection string from an allowed origin", async () => { render(); - const mongoConnStr = "mongodb://myaccount:dGVzdGtleQ==@myaccount.documents.azure.com:10255"; + const mongoConnStr = `mongodb://${FAKE_ACCOUNT_NAME}:${FAKE_KEY}@${FAKE_ACCOUNT_NAME}.documents.azure.com:10255`; await act(async () => { dispatchPostMessage( @@ -99,8 +103,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("accepts a valid Cassandra connection string from an allowed origin", async () => { render(); - const cassandraConnStr = - "AccountEndpoint=https://myaccount.cassandra.cosmosdb.azure.com:443/;AccountKey=dGVzdGtleQ==;"; + const cassandraConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.cassandra.cosmosdb.azure.com:443/;AccountKey=${FAKE_KEY};`; await act(async () => { dispatchPostMessage( @@ -116,8 +119,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("accepts a valid Table connection string from an allowed origin", async () => { render(); - const tableConnStr = - "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=dGVzdGtleQ==;TableEndpoint=https://myaccount.table.cosmosdb.azure.com:443/;"; + const tableConnStr = `DefaultEndpointsProtocol=https;AccountName=${FAKE_ACCOUNT_NAME};AccountKey=${FAKE_KEY};TableEndpoint=https://${FAKE_ACCOUNT_NAME}.table.cosmosdb.azure.com:443/;`; await act(async () => { dispatchPostMessage( @@ -133,8 +135,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("accepts a valid Gremlin connection string from an allowed origin", async () => { render(); - const gremlinConnStr = - "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGVzdGtleQ==;ApiKind=Gremlin;"; + const gremlinConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.documents.azure.com:443/;AccountKey=${FAKE_KEY};ApiKind=Gremlin;`; await act(async () => { dispatchPostMessage( @@ -150,7 +151,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("rejects messages from a disallowed origin", async () => { render(); - const validConnStr = "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGVzdGtleQ==;"; + const validConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.documents.azure.com:443/;AccountKey=${FAKE_KEY};`; await act(async () => { dispatchPostMessage( @@ -198,7 +199,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => { it("ignores messages with an unrelated type", async () => { render(); - const validConnStr = "AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGVzdGtleQ==;"; + const validConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.documents.azure.com:443/;AccountKey=${FAKE_KEY};`; await act(async () => { dispatchPostMessage({ type: "someOtherMessage", connectionString: validConnStr }, "https://cosmos.azure.com");