Skip to content

Commit 60e4eff

Browse files
authored
[copilot-finds] Bug: Connection string parser uses case-sensitive key lookup (#196)
1 parent a683e90 commit 60e4eff

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

packages/durabletask-js-azuremanaged/src/connection-string.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ export class DurableTaskAzureManagedConnectionString {
8787
}
8888

8989
private getValue(name: string): string | undefined {
90-
return this.properties.get(name);
90+
return this.properties.get(name.toLowerCase());
9191
}
9292

9393
private getRequiredValue(name: string): string {
@@ -108,7 +108,7 @@ export class DurableTaskAzureManagedConnectionString {
108108
if (equalsIndex > 0) {
109109
const key = pair.substring(0, equalsIndex).trim();
110110
const value = pair.substring(equalsIndex + 1).trim();
111-
properties.set(key, value);
111+
properties.set(key.toLowerCase(), value);
112112
}
113113
}
114114

packages/durabletask-js-azuremanaged/test/unit/connection-string.spec.ts

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,46 @@ describe("DurableTaskAzureManagedConnectionString", () => {
6767
"The connection string must contain a TaskHub property",
6868
);
6969
});
70+
71+
it("should parse connection string with all-lowercase keys", () => {
72+
const connectionString = new DurableTaskAzureManagedConnectionString(
73+
"endpoint=https://example.com;authentication=ManagedIdentity;taskhub=myTaskHub",
74+
);
75+
76+
expect(connectionString.getEndpoint()).toBe("https://example.com");
77+
expect(connectionString.getAuthentication()).toBe("ManagedIdentity");
78+
expect(connectionString.getTaskHubName()).toBe("myTaskHub");
79+
});
80+
81+
it("should parse connection string with all-uppercase keys", () => {
82+
const connectionString = new DurableTaskAzureManagedConnectionString(
83+
"ENDPOINT=https://example.com;AUTHENTICATION=ManagedIdentity;TASKHUB=myTaskHub",
84+
);
85+
86+
expect(connectionString.getEndpoint()).toBe("https://example.com");
87+
expect(connectionString.getAuthentication()).toBe("ManagedIdentity");
88+
expect(connectionString.getTaskHubName()).toBe("myTaskHub");
89+
});
90+
91+
it("should parse connection string with mixed-case keys", () => {
92+
const connectionString = new DurableTaskAzureManagedConnectionString(
93+
"endPoint=https://example.com;AUTHENTICATION=ManagedIdentity;taskHub=myTaskHub",
94+
);
95+
96+
expect(connectionString.getEndpoint()).toBe("https://example.com");
97+
expect(connectionString.getAuthentication()).toBe("ManagedIdentity");
98+
expect(connectionString.getTaskHubName()).toBe("myTaskHub");
99+
});
100+
101+
it("should preserve value casing with case-insensitive keys", () => {
102+
const connectionString = new DurableTaskAzureManagedConnectionString(
103+
"endpoint=https://MyHost.example.com;authentication=ManagedIdentity;taskhub=MyTaskHub;clientid=My-Client-ID",
104+
);
105+
106+
expect(connectionString.getEndpoint()).toBe("https://MyHost.example.com");
107+
expect(connectionString.getTaskHubName()).toBe("MyTaskHub");
108+
expect(connectionString.getClientId()).toBe("My-Client-ID");
109+
});
70110
});
71111

72112
describe("getAdditionallyAllowedTenants", () => {
@@ -87,6 +127,16 @@ describe("DurableTaskAzureManagedConnectionString", () => {
87127

88128
expect(connectionString.getAdditionallyAllowedTenants()).toBeUndefined();
89129
});
130+
131+
it("should match property name case-insensitively", () => {
132+
const connectionStringWithTenants =
133+
VALID_CONNECTION_STRING + ";additionallyallowedtenants=tenant1,tenant2";
134+
135+
const connectionString = new DurableTaskAzureManagedConnectionString(connectionStringWithTenants);
136+
const tenants = connectionString.getAdditionallyAllowedTenants();
137+
138+
expect(tenants).toEqual(["tenant1", "tenant2"]);
139+
});
90140
});
91141

92142
describe("getClientId", () => {

0 commit comments

Comments
 (0)