Skip to content

Commit 6061e77

Browse files
committed
Treat an empty username as unresolved in the connection cache lookup
An unresolved BasicAuthorization reports username "", which used to fall through to "match any known connection to this address" (intersystems#416) but was being filtered as a literal "" and always missing. Also drop values() in favor of list({}).
1 parent 0896bdf commit 6061e77

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

‎client/src/extension.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ const resolvedServerSpecs = new (class {
8080
return `${server.username}@${server.host}:${server.port}${server.pathPrefix}`.toLowerCase();
8181
}
8282

83-
/** Known connections matching the given connection fields (`serverName` and `namespace` are ignored). */
83+
/** Known connections matching the given connection fields (`serverName` and `namespace` are ignored; an empty `username` means "not resolved yet" and matches any). */
8484
list(query: Partial<Pick<ServerSpec, "host" | "port" | "pathPrefix" | "username">>): Omit<ServerSpec, "namespace">[] {
8585
const lower = (s?: string) => s?.toLowerCase();
8686
return [...this.map.values()].filter(
8787
(value) =>
8888
(query.host === undefined || lower(value.host) === lower(query.host)) &&
8989
(query.port === undefined || value.port === query.port) &&
9090
(query.pathPrefix === undefined || lower(value.pathPrefix) === lower(query.pathPrefix)) &&
91-
(query.username === undefined || lower(value.username) === lower(query.username)),
91+
(!query.username || lower(value.username) === lower(query.username)),
9292
);
9393
}
9494

@@ -107,10 +107,6 @@ const resolvedServerSpecs = new (class {
107107
clear(): void {
108108
this.map.clear();
109109
}
110-
111-
values(): IterableIterator<Omit<ServerSpec, "namespace">> {
112-
return this.map.values();
113-
}
114110
})();
115111

116112
export async function activate(context: ExtensionContext) {
@@ -208,7 +204,7 @@ export async function activate(context: ExtensionContext) {
208204
return;
209205
}
210206
const auth = serverSpec.auth ?? new BasicAuthorization(serverSpec.username, serverSpec.password);
211-
for (const cached of resolvedServerSpecs.list({ ...serverSpec, username: auth?.username })) {
207+
for (const cached of resolvedServerSpecs.list({ ...serverSpec, username: auth.username })) {
212208
// Auth is namespace-independent, but the caller needs the namespace it actually asked for
213209
return { ...cached, namespace: serverSpec.namespace };
214210
}
@@ -287,7 +283,7 @@ export async function activate(context: ExtensionContext) {
287283
// Create a CSP session for all resolved server connections
288284
// Ignore any failures; the sessions will be created on demand instead
289285
const headPromises: Promise<any>[] = [];
290-
for (const server of resolvedServerSpecs.values()) {
286+
for (const server of resolvedServerSpecs.list({})) {
291287
// namespace is irrelevant here because api=0
292288
headPromises.push(makeRESTRequest("HEAD", 0, "", { ...server, namespace: "" }));
293289
}
@@ -476,7 +472,7 @@ export async function activate(context: ExtensionContext) {
476472
export async function deactivate(): Promise<void> {
477473
// Stop the server and log out of all CSP sessions
478474
const promises: Promise<any>[] = client ? [client.stop()] : [];
479-
for (const server of resolvedServerSpecs.values()) {
475+
for (const server of resolvedServerSpecs.list({})) {
480476
promises.push(
481477
makeRESTRequest(
482478
"HEAD",

0 commit comments

Comments
 (0)