Skip to content

Commit f27efb7

Browse files
AlexTugarevroboquat
authored andcommitted
[server] fix infinite init loop of dynamic providers
... which is caused by casing mismatch.
1 parent b45182d commit f27efb7

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

components/gitpod-db/src/auth-provider-entry-db.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ export interface AuthProviderEntryDB {
1515
delete(ap: AuthProviderEntry): Promise<void>;
1616

1717
findAll(exceptOAuthRevisions?: string[]): Promise<AuthProviderEntry[]>;
18+
/**
19+
* `host`s contained in the result array are expected to be lower case.
20+
*/
1821
findAllHosts(): Promise<string[]>;
1922
findByHost(host: string): Promise<AuthProviderEntry | undefined>;
2023
findByUserId(userId: string): Promise<AuthProviderEntry[]>;

components/gitpod-db/src/auth-provider-entry.spec.db.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ export class AuthProviderEntryDBSpec {
8181
expect(await this.db.findAll([ap1.oauthRevision!]), "findAll([ap1])").to.deep.equal([ap2]);
8282
}
8383

84+
@test public async findAllHosts() {
85+
const ap1 = this.authProvider({ id: "1", oauthRevision: "rev1", host: "foo" });
86+
const ap2 = this.authProvider({ id: "2", oauthRevision: "rev2", host: "BAR" });
87+
await this.db.storeAuthProvider(ap1, false);
88+
await this.db.storeAuthProvider(ap2, false);
89+
90+
const all = await this.db.findAllHosts();
91+
expect(all, "findAllHosts([])").to.deep.equal(["foo", "bar"]);
92+
}
93+
8494
@test public async oauthRevision() {
8595
const ap = this.authProvider({ id: "1" });
8696
await this.db.storeAuthProvider(ap, true);

components/gitpod-db/src/typeorm/auth-provider-entry-db-impl.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ export class AuthProviderEntryDBImpl implements AuthProviderEntryDB {
7070
const repo = await this.getAuthProviderRepo();
7171
const query = repo.createQueryBuilder("auth_provider").select(hostField).where("auth_provider.deleted != true");
7272
const result = (await query.execute()) as Pick<DBAuthProviderEntry, "host">[];
73-
return result.map((r) => r.host);
73+
// HINT: host is expected to be lower case
74+
return result.map((r) => r.host?.toLowerCase()).filter((h) => !!h);
7475
}
7576

7677
async findByHost(host: string): Promise<AuthProviderEntry | undefined> {

components/server/src/auth/host-context-provider-impl.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ export class HostContextProviderImpl implements HostContextProvider {
112112
// remove obsolete entries
113113
const currentHosts = new Set(await this.authProviderService.getAllAuthProviderHosts());
114114
ctx.span?.setTag("updateDynamicHosts.currentHostProviders", currentHosts.size);
115+
// HINT: values of `currentHosts` are expected to be lower case
115116
const tobeRemoved = [...this.dynamicHosts.keys()].filter((h) => !currentHosts.has(h));
116117
for (const host of tobeRemoved) {
117-
const hostContext = this.dynamicHosts.get(host);
118-
log.debug("Disposing dynamic Auth Provider: " + host, { host, hostContext });
118+
log.debug("Disposing dynamic Auth Provider: " + host);
119119

120120
this.dynamicHosts.delete(host);
121121
}

0 commit comments

Comments
 (0)