-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathMockUUIDCredentialManager.ts
More file actions
39 lines (33 loc) · 1.4 KB
/
MockUUIDCredentialManager.ts
File metadata and controls
39 lines (33 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtCredentialManager } from "../../../api/src/auth/credentialManager/AzExtCredentialManager";
import { maskValue } from "../../../api/src/utils/maskValue";
/**
* A mock credential manager with the same implementation as `AzExtUUIDCredentialManager`,
* but with a public getter to inspect the UUIDs during test.
*/
export class MockUUIDCredentialManager implements AzExtCredentialManager {
#uuidMap = new Map<string, string>();
get uuidMap() {
return this.#uuidMap;
}
createCredential(extensionId: string): string {
const uuid: string = crypto.randomUUID();
this.#uuidMap.set(extensionId, uuid);
return uuid;
}
verifyCredential(credential: string, extensionId: string): boolean {
if (!credential || !extensionId) {
return false;
}
return credential === this.#uuidMap.get(extensionId);
}
maskCredentials(data: string): string {
for (const uuid of this.#uuidMap.values()) {
data = maskValue(data, uuid);
}
return data;
}
}