From 5ad1f523d569e020548fe17713165775d53995b8 Mon Sep 17 00:00:00 2001 From: Marcus Eide Date: Wed, 13 Oct 2021 14:25:06 +0200 Subject: [PATCH] Make the create function async Signed-off-by: Marcus Eide --- .../src/identity/FirestoreKeyStore.test.ts | 24 +++++++++---------- .../src/identity/FirestoreKeyStore.ts | 4 +++- .../auth-backend/src/identity/KeyStores.ts | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/plugins/auth-backend/src/identity/FirestoreKeyStore.test.ts b/plugins/auth-backend/src/identity/FirestoreKeyStore.test.ts index 03fcc15a77..a12e2ed40e 100644 --- a/plugins/auth-backend/src/identity/FirestoreKeyStore.test.ts +++ b/plugins/auth-backend/src/identity/FirestoreKeyStore.test.ts @@ -53,14 +53,14 @@ describe('FirestoreKeyStore', () => { process.env = OLD_ENV; }); - it('can create an instance without settings', () => { - const keyStore = FirestoreKeyStore.create(); + it('can create an instance without settings', async () => { + const keyStore = await FirestoreKeyStore.create(); expect(keyStore).toBeInstanceOf(FirestoreKeyStore); }); it('can set the project id', async () => { - FirestoreKeyStore.create({ projectId: 'my-project' }); + await FirestoreKeyStore.create({ projectId: 'my-project' }); expect(Firestore).toHaveBeenCalledWith( expect.objectContaining({ @@ -70,7 +70,7 @@ describe('FirestoreKeyStore', () => { }); it('can handle keyfile file', async () => { - FirestoreKeyStore.create({ keyFilename: 'keyFile.json' }); + await FirestoreKeyStore.create({ keyFilename: 'keyFile.json' }); expect(Firestore).toHaveBeenCalledWith( expect.objectContaining({ @@ -79,9 +79,9 @@ describe('FirestoreKeyStore', () => { ); }); - it('can use default google credentials', () => { + it('can use default google credentials', async () => { process.env.GOOGLE_APPLICATION_CREDENTIALS = 'cred.json'; - FirestoreKeyStore.create(); + await FirestoreKeyStore.create(); expect(Firestore).toHaveBeenCalledWith( expect.objectContaining({ @@ -91,14 +91,14 @@ describe('FirestoreKeyStore', () => { }); it('can uses a default path', async () => { - const keyStore = FirestoreKeyStore.create(); + const keyStore = await FirestoreKeyStore.create(); await keyStore.addKey(key); expect(firestoreMock.collection).toBeCalledWith('sessions'); }); it('can set the path', async () => { - const keyStore = FirestoreKeyStore.create({ + const keyStore = await FirestoreKeyStore.create({ path: 'my-path', }); await keyStore.addKey(key); @@ -107,7 +107,7 @@ describe('FirestoreKeyStore', () => { }); it('can add keys', async () => { - const keyStore = FirestoreKeyStore.create(); + const keyStore = await FirestoreKeyStore.create(); await keyStore.addKey(key); expect(firestoreMock.collection).toBeCalledWith('sessions'); @@ -119,7 +119,7 @@ describe('FirestoreKeyStore', () => { }); it('can delete a single key', async () => { - const keyStore = FirestoreKeyStore.create(); + const keyStore = await FirestoreKeyStore.create(); await keyStore.removeKeys(['123']); expect(firestoreMock.collection).toBeCalledWith('sessions'); @@ -128,7 +128,7 @@ describe('FirestoreKeyStore', () => { }); it('can delete a multiple keys', async () => { - const keyStore = FirestoreKeyStore.create(); + const keyStore = await FirestoreKeyStore.create(); await keyStore.removeKeys(['123', '456']); expect(firestoreMock.collection).toBeCalledWith('sessions'); @@ -138,7 +138,7 @@ describe('FirestoreKeyStore', () => { }); it('can list keys', async () => { - const keyStore = FirestoreKeyStore.create(); + const keyStore = await FirestoreKeyStore.create(); const items = await keyStore.listKeys(); expect(firestoreMock.collection).toBeCalledWith('sessions'); diff --git a/plugins/auth-backend/src/identity/FirestoreKeyStore.ts b/plugins/auth-backend/src/identity/FirestoreKeyStore.ts index cf8c082540..74122f2849 100644 --- a/plugins/auth-backend/src/identity/FirestoreKeyStore.ts +++ b/plugins/auth-backend/src/identity/FirestoreKeyStore.ts @@ -23,7 +23,9 @@ type FirestoreSettings = Settings & { }; export class FirestoreKeyStore implements KeyStore { - static create(settings?: FirestoreSettings): FirestoreKeyStore { + static async create( + settings?: FirestoreSettings, + ): Promise { const { projectId, keyFilename, path } = settings ?? {}; const database = new Firestore({ projectId, diff --git a/plugins/auth-backend/src/identity/KeyStores.ts b/plugins/auth-backend/src/identity/KeyStores.ts index 0991f7ea7b..ec236e2074 100644 --- a/plugins/auth-backend/src/identity/KeyStores.ts +++ b/plugins/auth-backend/src/identity/KeyStores.ts @@ -63,7 +63,7 @@ export class KeyStores { } if (provider === 'firestore') { - return FirestoreKeyStore.create({ + return await FirestoreKeyStore.create({ projectId: providerConfig?.getOptionalString('projectId'), keyFilename: providerConfig?.getOptionalString('keyFilename'), path: providerConfig?.getOptionalString('path'),