Remove exposed connection string in test (#2523)

* Address exposed connection string in Data Explorer code

* Address exposed connection string in Data Explorer code

---------

Co-authored-by: Asier Isayas <aisayas@microsoft.com>
This commit is contained in:
asier-isayas
2026-06-23 13:15:15 -04:00
committed by GitHub
parent 9372a7fc34
commit 842051ad5d
+11 -10
View File
@@ -63,11 +63,15 @@ const dispatchPostMessage = (data: unknown, origin: string) => {
window.dispatchEvent(event); window.dispatchEvent(event);
}; };
// Deliberately invalid account name
const FAKE_ACCOUNT_NAME: string = "-FakeAccount-";
const FAKE_KEY: string = "<redacted-test-key>";
describe("HostedExplorer tryCosmosDB postMessage handler", () => { describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("accepts a valid SQL connection string from an allowed origin", async () => { it("accepts a valid SQL connection string from an allowed origin", async () => {
render(<App />); render(<App />);
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 () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -83,7 +87,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("accepts a valid Mongo connection string from an allowed origin", async () => { it("accepts a valid Mongo connection string from an allowed origin", async () => {
render(<App />); render(<App />);
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 () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -99,8 +103,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("accepts a valid Cassandra connection string from an allowed origin", async () => { it("accepts a valid Cassandra connection string from an allowed origin", async () => {
render(<App />); render(<App />);
const cassandraConnStr = const cassandraConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.cassandra.cosmosdb.azure.com:443/;AccountKey=${FAKE_KEY};`;
"AccountEndpoint=https://myaccount.cassandra.cosmosdb.azure.com:443/;AccountKey=dGVzdGtleQ==;";
await act(async () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -116,8 +119,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("accepts a valid Table connection string from an allowed origin", async () => { it("accepts a valid Table connection string from an allowed origin", async () => {
render(<App />); render(<App />);
const tableConnStr = const tableConnStr = `DefaultEndpointsProtocol=https;AccountName=${FAKE_ACCOUNT_NAME};AccountKey=${FAKE_KEY};TableEndpoint=https://${FAKE_ACCOUNT_NAME}.table.cosmosdb.azure.com:443/;`;
"DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=dGVzdGtleQ==;TableEndpoint=https://myaccount.table.cosmosdb.azure.com:443/;";
await act(async () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -133,8 +135,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("accepts a valid Gremlin connection string from an allowed origin", async () => { it("accepts a valid Gremlin connection string from an allowed origin", async () => {
render(<App />); render(<App />);
const gremlinConnStr = const gremlinConnStr = `AccountEndpoint=https://${FAKE_ACCOUNT_NAME}.documents.azure.com:443/;AccountKey=${FAKE_KEY};ApiKind=Gremlin;`;
"AccountEndpoint=https://myaccount.documents.azure.com:443/;AccountKey=dGVzdGtleQ==;ApiKind=Gremlin;";
await act(async () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -150,7 +151,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("rejects messages from a disallowed origin", async () => { it("rejects messages from a disallowed origin", async () => {
render(<App />); render(<App />);
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 () => { await act(async () => {
dispatchPostMessage( dispatchPostMessage(
@@ -198,7 +199,7 @@ describe("HostedExplorer tryCosmosDB postMessage handler", () => {
it("ignores messages with an unrelated type", async () => { it("ignores messages with an unrelated type", async () => {
render(<App />); render(<App />);
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 () => { await act(async () => {
dispatchPostMessage({ type: "someOtherMessage", connectionString: validConnStr }, "https://cosmos.azure.com"); dispatchPostMessage({ type: "someOtherMessage", connectionString: validConnStr }, "https://cosmos.azure.com");