diff --git a/common/changes/@microsoft/rush/feat-credcache-custom-paths_2025-05-30-04-23.json b/common/changes/@microsoft/rush/feat-credcache-custom-paths_2025-05-30-04-23.json new file mode 100644 index 00000000000..2d208ba14fb --- /dev/null +++ b/common/changes/@microsoft/rush/feat-credcache-custom-paths_2025-05-30-04-23.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "@microsoft/rush", + "comment": "Update the `CredentialCache` options object to add support for custom cache file paths. This is useful if `CredentialCache` is used outside of Rush.", + "type": "none" + } + ], + "packageName": "@microsoft/rush" +} \ No newline at end of file diff --git a/common/reviews/api/rush-lib.api.md b/common/reviews/api/rush-lib.api.md index 76e081722d1..f997aa22e05 100644 --- a/common/reviews/api/rush-lib.api.md +++ b/common/reviews/api/rush-lib.api.md @@ -437,6 +437,7 @@ export interface ICredentialCacheEntry { // @beta (undocumented) export interface ICredentialCacheOptions { + cacheFilePath?: string; // (undocumented) supportEditing: boolean; } diff --git a/libraries/rush-lib/src/logic/CredentialCache.ts b/libraries/rush-lib/src/logic/CredentialCache.ts index de2bb123967..5c1c775821e 100644 --- a/libraries/rush-lib/src/logic/CredentialCache.ts +++ b/libraries/rush-lib/src/logic/CredentialCache.ts @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license. // See LICENSE in the project root for license information. +import * as path from 'path'; import { FileSystem, JsonFile, JsonSchema, LockFile } from '@rushstack/node-core-library'; import { Utilities } from '../utilities/Utilities'; @@ -8,7 +9,7 @@ import { RushUserConfiguration } from '../api/RushUserConfiguration'; import schemaJson from '../schemas/credentials.schema.json'; import { objectsAreDeepEqual } from '../utilities/objectUtilities'; -const CACHE_FILENAME: string = 'credentials.json'; +const DEFAULT_CACHE_FILENAME: 'credentials.json' = 'credentials.json'; const LATEST_CREDENTIALS_JSON_VERSION: string = '0.1.0'; interface ICredentialCacheJson { @@ -38,6 +39,10 @@ export interface ICredentialCacheEntry { */ export interface ICredentialCacheOptions { supportEditing: boolean; + /** + * If specified, use the specified path instead of the default path of `~/.rush-user/credentials.json` + */ + cacheFilePath?: string; } /** @@ -57,7 +62,7 @@ export class CredentialCache /* implements IDisposable */ { lockfile: LockFile | undefined ) { if (loadedJson && loadedJson.version !== LATEST_CREDENTIALS_JSON_VERSION) { - throw new Error(`Unexpected credentials.json file version: ${loadedJson.version}`); + throw new Error(`Unexpected ${cacheFilePath} file version: ${loadedJson.version}`); } this._cacheFilePath = cacheFilePath; @@ -67,8 +72,17 @@ export class CredentialCache /* implements IDisposable */ { } public static async initializeAsync(options: ICredentialCacheOptions): Promise { - const rushUserFolderPath: string = RushUserConfiguration.getRushUserFolderPath(); - const cacheFilePath: string = `${rushUserFolderPath}/${CACHE_FILENAME}`; + let cacheDirectory: string; + let cacheFileName: string; + if (options.cacheFilePath) { + cacheDirectory = path.dirname(options.cacheFilePath); + cacheFileName = options.cacheFilePath.slice(cacheDirectory.length + 1); + } else { + cacheDirectory = RushUserConfiguration.getRushUserFolderPath(); + cacheFileName = DEFAULT_CACHE_FILENAME; + } + const cacheFilePath: string = `${cacheDirectory}/${cacheFileName}`; + const jsonSchema: JsonSchema = JsonSchema.fromLoadedObject(schemaJson); let loadedJson: ICredentialCacheJson | undefined; @@ -82,7 +96,7 @@ export class CredentialCache /* implements IDisposable */ { let lockfile: LockFile | undefined; if (options.supportEditing) { - lockfile = await LockFile.acquireAsync(rushUserFolderPath, `${CACHE_FILENAME}.lock`); + lockfile = await LockFile.acquireAsync(cacheDirectory, `${cacheFileName}.lock`); } const credentialCache: CredentialCache = new CredentialCache(cacheFilePath, loadedJson, lockfile); diff --git a/libraries/rush-lib/src/logic/test/CredentialCache.test.ts b/libraries/rush-lib/src/logic/test/CredentialCache.test.ts index b2d8ac49a43..fe7e92fae97 100644 --- a/libraries/rush-lib/src/logic/test/CredentialCache.test.ts +++ b/libraries/rush-lib/src/logic/test/CredentialCache.test.ts @@ -3,10 +3,13 @@ import { LockFile, Async, FileSystem } from '@rushstack/node-core-library'; import { RushUserConfiguration } from '../../api/RushUserConfiguration'; -import { CredentialCache } from '../CredentialCache'; +import { CredentialCache, type ICredentialCacheOptions } from '../CredentialCache'; const FAKE_RUSH_USER_FOLDER: string = '~/.rush-user'; -const FAKE_CREDENTIALS_CACHE_FILE: string = `${FAKE_RUSH_USER_FOLDER}/credentials.json`; + +interface IPathsTestCase extends Required> { + testCaseName: string; +} describe(CredentialCache.name, () => { let fakeFilesystem: { [key: string]: string }; @@ -85,185 +88,270 @@ describe(CredentialCache.name, () => { jest.restoreAllMocks(); }); - it("initializes a credential cache correctly when one doesn't exist on disk", async () => { - const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: false }); - expect(credentialCache).toBeDefined(); - credentialCache.dispose(); - }); + describe.each([ + { + testCaseName: 'default cache path', + cacheFilePath: `${FAKE_RUSH_USER_FOLDER}/credentials.json` + }, + { + testCaseName: 'custom cache path with no suffix', + cacheFilePath: `${FAKE_RUSH_USER_FOLDER}/my-cache-name` + }, + { + testCaseName: 'custom cache path with json suffix', + cacheFilePath: `${FAKE_RUSH_USER_FOLDER}/my-cache-name.json` + } + ])('cache paths [$testCaseName]', ({ cacheFilePath }) => { + it("initializes a credential cache correctly when one doesn't exist on disk", async () => { + const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ + supportEditing: false + }); + expect(credentialCache).toBeDefined(); + credentialCache.dispose(); + }); - it('initializes a credential cache correctly when one exists on disk', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 0, - credential: credentialValue + it('initializes a credential cache correctly when one exists on disk', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 0, + credential: credentialValue + } } - } + }); + + const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); + expect(credentialCache.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); + credentialCache.dispose(); }); - const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: false }); - expect(credentialCache.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); - expect(credentialCache.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); - credentialCache.dispose(); - }); + it('initializes a credential cache correctly when one exists on disk with a expired credential', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 100, // Expired + credential: credentialValue + } + } + }); - it('initializes a credential cache correctly when one exists on disk with a expired credential', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 100, // Expired - credential: credentialValue + const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); + expect(credentialCache.tryGetCacheEntry(credentialId)?.expires).toMatchSnapshot('expiration'); + credentialCache.dispose(); + }); + + it('correctly trims expired credentials', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 100, // Expired + credential: credentialValue + } } - } + }); + + const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache.trimExpiredEntries(); + expect(credentialCache.tryGetCacheEntry(credentialId)).toBeUndefined(); + await credentialCache.saveIfModifiedAsync(); + credentialCache.dispose(); + + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); }); - const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: false }); - expect(credentialCache.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); - expect(credentialCache.tryGetCacheEntry(credentialId)?.expires).toMatchInlineSnapshot( - `1970-01-01T00:00:00.100Z` - ); - credentialCache.dispose(); - }); + it('correctly adds a new credential', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; - it('correctly trims expired credentials', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 100, // Expired - credential: credentialValue - } - } + const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache1.setCacheEntry(credentialId, { credential: credentialValue }); + expect(credentialCache1.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); + expect(credentialCache1.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); + await credentialCache1.saveIfModifiedAsync(); + credentialCache1.dispose(); + + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); + + const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache2.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); + expect(credentialCache2.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); + credentialCache2.dispose(); }); - const credentialCache: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache.trimExpiredEntries(); - expect(credentialCache.tryGetCacheEntry(credentialId)).toBeUndefined(); - await credentialCache.saveIfModifiedAsync(); - credentialCache.dispose(); + it('correctly updates an existing credential', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + const newCredentialValue: string = 'new-test-value'; + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 0, + credential: credentialValue + } + } + }); - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": {} -} -" -`); - }); + const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache1.setCacheEntry(credentialId, { credential: newCredentialValue }); + expect(credentialCache1.tryGetCacheEntry(credentialId)?.credential).toEqual(newCredentialValue); + expect(credentialCache1.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); + await credentialCache1.saveIfModifiedAsync(); + credentialCache1.dispose(); - it('correctly adds a new credential', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - - const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache1.setCacheEntry(credentialId, { credential: credentialValue }); - expect(credentialCache1.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); - expect(credentialCache1.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); - await credentialCache1.saveIfModifiedAsync(); - credentialCache1.dispose(); - - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": { - \\"test-credential\\": { - \\"expires\\": 0, - \\"credential\\": \\"test-value\\" - } - } -} -" -`); + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); - const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ - supportEditing: false + const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache2.tryGetCacheEntry(credentialId)?.credential).toEqual(newCredentialValue); + expect(credentialCache2.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); + credentialCache2.dispose(); }); - expect(credentialCache2.tryGetCacheEntry(credentialId)?.credential).toEqual(credentialValue); - expect(credentialCache2.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); - credentialCache2.dispose(); - }); - it('correctly updates an existing credential', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - const newCredentialValue: string = 'new-test-value'; - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 0, - credential: credentialValue + it('correctly deletes an existing credential', async () => { + const credentialId: string = 'test-credential'; + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 0, + credential: 'test-value' + } } - } + }); + + const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache1.deleteCacheEntry(credentialId); + expect(credentialCache1.tryGetCacheEntry(credentialId)).toBeUndefined(); + await credentialCache1.saveIfModifiedAsync(); + credentialCache1.dispose(); + + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); + + const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache2.tryGetCacheEntry(credentialId)).toBeUndefined(); + credentialCache2.dispose(); }); - const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache1.setCacheEntry(credentialId, { credential: newCredentialValue }); - expect(credentialCache1.tryGetCacheEntry(credentialId)?.credential).toEqual(newCredentialValue); - expect(credentialCache1.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); - await credentialCache1.saveIfModifiedAsync(); - credentialCache1.dispose(); - - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": { - \\"test-credential\\": { - \\"expires\\": 0, - \\"credential\\": \\"new-test-value\\" - } - } -} -" -`); + it('correctly sets credentialMetadata', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + const credentialMetadata: object = { + a: 1, + b: true + }; + + const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache1.setCacheEntry(credentialId, { credential: credentialValue, credentialMetadata }); + expect(credentialCache1.tryGetCacheEntry(credentialId)).toEqual({ + credential: credentialValue, + credentialMetadata + }); + await credentialCache1.saveIfModifiedAsync(); + credentialCache1.dispose(); + + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); - const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ - supportEditing: false + const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache2.tryGetCacheEntry(credentialId)).toEqual({ + credential: credentialValue, + credentialMetadata + }); + credentialCache2.dispose(); }); - expect(credentialCache2.tryGetCacheEntry(credentialId)?.credential).toEqual(newCredentialValue); - expect(credentialCache2.tryGetCacheEntry(credentialId)?.expires).toBeUndefined(); - credentialCache2.dispose(); - }); - it('correctly deletes an existing credential', async () => { - const credentialId: string = 'test-credential'; - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 0, - credential: 'test-value' + it('correctly updates credentialMetadata', async () => { + const credentialId: string = 'test-credential'; + const credentialValue: string = 'test-value'; + const oldCredentialMetadata: object = { + a: 1, + b: true + }; + const newCredentialMetadata: object = { + c: ['a', 'b', 'c'] + }; + + fakeFilesystem[cacheFilePath] = JSON.stringify({ + version: '0.1.0', + cacheEntries: { + [credentialId]: { + expires: 0, + credential: 'test-value', + credentialMetadata: oldCredentialMetadata + } } - } - }); + }); - const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache1.deleteCacheEntry(credentialId); - expect(credentialCache1.tryGetCacheEntry(credentialId)).toBeUndefined(); - await credentialCache1.saveIfModifiedAsync(); - credentialCache1.dispose(); + const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: true + }); + credentialCache1.setCacheEntry(credentialId, { + credential: credentialValue, + credentialMetadata: newCredentialMetadata + }); + expect(credentialCache1.tryGetCacheEntry(credentialId)).toEqual({ + credential: credentialValue, + credentialMetadata: newCredentialMetadata + }); + await credentialCache1.saveIfModifiedAsync(); + credentialCache1.dispose(); - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": {} -} -" -`); + expect(fakeFilesystem[cacheFilePath]).toMatchSnapshot('credential cache file'); - const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ - supportEditing: false + const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ + cacheFilePath: cacheFilePath, + supportEditing: false + }); + expect(credentialCache2.tryGetCacheEntry(credentialId)).toEqual({ + credential: credentialValue, + credentialMetadata: newCredentialMetadata + }); + credentialCache2.dispose(); }); - expect(credentialCache2.tryGetCacheEntry(credentialId)).toBeUndefined(); - credentialCache2.dispose(); }); it('does not allow interaction if already disposed', async () => { @@ -303,112 +391,4 @@ describe(CredentialCache.name, () => { `"This instance of CredentialCache does not support editing."` ); }); - - it('correctly sets credentialMetadata', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - const credentialMetadata: object = { - a: 1, - b: true - }; - - const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache1.setCacheEntry(credentialId, { credential: credentialValue, credentialMetadata }); - expect(credentialCache1.tryGetCacheEntry(credentialId)).toEqual({ - credential: credentialValue, - credentialMetadata - }); - await credentialCache1.saveIfModifiedAsync(); - credentialCache1.dispose(); - - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": { - \\"test-credential\\": { - \\"expires\\": 0, - \\"credential\\": \\"test-value\\", - \\"credentialMetadata\\": { - \\"a\\": 1, - \\"b\\": true - } - } - } -} -" -`); - - const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ - supportEditing: false - }); - expect(credentialCache2.tryGetCacheEntry(credentialId)).toEqual({ - credential: credentialValue, - credentialMetadata - }); - credentialCache2.dispose(); - }); - - it('correctly updates credentialMetadata', async () => { - const credentialId: string = 'test-credential'; - const credentialValue: string = 'test-value'; - const oldCredentialMetadata: object = { - a: 1, - b: true - }; - const newCredentialMetadata: object = { - c: ['a', 'b', 'c'] - }; - - fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE] = JSON.stringify({ - version: '0.1.0', - cacheEntries: { - [credentialId]: { - expires: 0, - credential: 'test-value', - credentialMetadata: oldCredentialMetadata - } - } - }); - - const credentialCache1: CredentialCache = await CredentialCache.initializeAsync({ supportEditing: true }); - credentialCache1.setCacheEntry(credentialId, { - credential: credentialValue, - credentialMetadata: newCredentialMetadata - }); - expect(credentialCache1.tryGetCacheEntry(credentialId)).toEqual({ - credential: credentialValue, - credentialMetadata: newCredentialMetadata - }); - await credentialCache1.saveIfModifiedAsync(); - credentialCache1.dispose(); - - expect(fakeFilesystem[FAKE_CREDENTIALS_CACHE_FILE]).toMatchInlineSnapshot(` -"{ - \\"version\\": \\"0.1.0\\", - \\"cacheEntries\\": { - \\"test-credential\\": { - \\"expires\\": 0, - \\"credential\\": \\"test-value\\", - \\"credentialMetadata\\": { - \\"c\\": [ - \\"a\\", - \\"b\\", - \\"c\\" - ] - } - } - } -} -" -`); - - const credentialCache2: CredentialCache = await CredentialCache.initializeAsync({ - supportEditing: false - }); - expect(credentialCache2.tryGetCacheEntry(credentialId)).toEqual({ - credential: credentialValue, - credentialMetadata: newCredentialMetadata - }); - credentialCache2.dispose(); - }); }); diff --git a/libraries/rush-lib/src/logic/test/__snapshots__/CredentialCache.test.ts.snap b/libraries/rush-lib/src/logic/test/__snapshots__/CredentialCache.test.ts.snap new file mode 100644 index 00000000000..f0c2c1e488b --- /dev/null +++ b/libraries/rush-lib/src/logic/test/__snapshots__/CredentialCache.test.ts.snap @@ -0,0 +1,244 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly adds a new credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly deletes an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly sets credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"a\\": 1, + \\"b\\": true + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly trims expired credentials: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly updates an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"new-test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] correctly updates credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"c\\": [ + \\"a\\", + \\"b\\", + \\"c\\" + ] + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with json suffix] initializes a credential cache correctly when one exists on disk with a expired credential: expiration 1`] = `1970-01-01T00:00:00.100Z`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly adds a new credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly deletes an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly sets credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"a\\": 1, + \\"b\\": true + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly trims expired credentials: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly updates an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"new-test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] correctly updates credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"c\\": [ + \\"a\\", + \\"b\\", + \\"c\\" + ] + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [custom cache path with no suffix] initializes a credential cache correctly when one exists on disk with a expired credential: expiration 1`] = `1970-01-01T00:00:00.100Z`; + +exports[`CredentialCache cache paths [default cache path] correctly adds a new credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [default cache path] correctly deletes an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [default cache path] correctly sets credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"a\\": 1, + \\"b\\": true + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [default cache path] correctly trims expired credentials: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": {} +} +" +`; + +exports[`CredentialCache cache paths [default cache path] correctly updates an existing credential: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"new-test-value\\" + } + } +} +" +`; + +exports[`CredentialCache cache paths [default cache path] correctly updates credentialMetadata: credential cache file 1`] = ` +"{ + \\"version\\": \\"0.1.0\\", + \\"cacheEntries\\": { + \\"test-credential\\": { + \\"expires\\": 0, + \\"credential\\": \\"test-value\\", + \\"credentialMetadata\\": { + \\"c\\": [ + \\"a\\", + \\"b\\", + \\"c\\" + ] + } + } + } +} +" +`; + +exports[`CredentialCache cache paths [default cache path] initializes a credential cache correctly when one exists on disk with a expired credential: expiration 1`] = `1970-01-01T00:00:00.100Z`;