From 4152a38d692e0dfeb0c60dbc76aca80569f504d5 Mon Sep 17 00:00:00 2001 From: Matt Wilde Date: Mon, 9 Dec 2024 11:52:45 -0500 Subject: [PATCH] don't compute role from key name string when calling frontdoor --- src/lib/auth/databaseKeys.mjs | 14 ++++++++------ test/credentials.mjs | 12 ++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/lib/auth/databaseKeys.mjs b/src/lib/auth/databaseKeys.mjs index 521c3e1b..44a82000 100644 --- a/src/lib/auth/databaseKeys.mjs +++ b/src/lib/auth/databaseKeys.mjs @@ -16,9 +16,9 @@ const DEFAULT_ROLE = "admin"; */ export class DatabaseKeys { constructor(argv, accountKey) { - const { database } = argv; + this.path = argv.database; this.role = argv.role || DEFAULT_ROLE; - this.keyName = DatabaseKeys.getKeyName(database, this.role); + this.keyName = DatabaseKeys.getKeyName(this.path, this.role); this.keyStore = new SecretKeyStorage(accountKey); this.ttlMs = TTL_DEFAULT_MS; @@ -113,13 +113,15 @@ export class DatabaseKeys { * @returns {string} - The new secret */ async refreshKey() { - this.logger.debug(`Creating new db key for ${this.keyName}`, "creds"); - const [path, role] = this.keyName.split(":"); + this.logger.debug( + `Creating new db key for path ${this.path} and role ${this.role}`, + "creds", + ); const expiration = this.getKeyExpiration(); const accountClient = new FaunaAccountClient(); const newSecret = await accountClient.createKey({ - path, - role, + path: this.path, + role: this.role, name: "System generated shell key", ttl: new Date(expiration).toISOString(), }); diff --git a/test/credentials.mjs b/test/credentials.mjs index 53fdfedb..61551410 100644 --- a/test/credentials.mjs +++ b/test/credentials.mjs @@ -129,6 +129,18 @@ describe("credentials", function () { }, }, }, + { + command: `query "Database.all()" -d us-std/test:badpath --no-color`, + localCreds: defaultLocalCreds, + expected: { + databaseKeys: { + role: "admin", + path: "us-std/test:badpath", + key: undefined, + keySource: "credentials-file", + }, + }, + }, ].forEach(({ command, expected, localCreds }) => { it(`builds credentials from: '${command}'`, async () => { setCredsFiles(localCreds.accountKeys, localCreds.databaseKeys);