@sudoplatform/sudo-common 5.9.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +2 -4
- package/bin/outdated-with-suppression.sh +20 -0
- package/bin/suppress-outdated.sh +15 -0
- package/dependencies-report.json +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/AccountLockedError.html +4 -3
- package/docs/classes/AuthenticationError.html +4 -3
- package/docs/classes/Base64.html +2 -2
- package/docs/classes/Buffer.html +2 -2
- package/docs/classes/ConfigurationNotSetError.html +4 -3
- package/docs/classes/ConfigurationSetNotFoundError.html +4 -3
- package/docs/classes/DecodeError.html +4 -3
- package/docs/classes/DefaultConfigurationManager.html +6 -6
- package/docs/classes/DefaultLogger.html +13 -7
- package/docs/classes/DefaultSudoKeyArchive.html +13 -13
- package/docs/classes/DefaultSudoKeyManager.html +31 -27
- package/docs/classes/FatalError.html +4 -3
- package/docs/classes/IllegalArgumentError.html +4 -3
- package/docs/classes/IllegalStateError.html +4 -3
- package/docs/classes/InsufficientEntitlementsError.html +4 -3
- package/docs/classes/InvalidOwnershipProofError.html +4 -3
- package/docs/classes/InvalidTokenError.html +4 -3
- package/docs/classes/KeyArchiveDecodingError.html +4 -3
- package/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
- package/docs/classes/KeyArchiveMissingError.html +4 -3
- package/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
- package/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
- package/docs/classes/KeyArchiveTypeError.html +4 -3
- package/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
- package/docs/classes/KeyArchiveVersionError.html +4 -3
- package/docs/classes/KeyNotFoundError.html +4 -3
- package/docs/classes/KeyStoreNotExportableError.html +4 -3
- package/docs/classes/LimitExceededError.html +4 -3
- package/docs/classes/NoEntitlementsError.html +4 -3
- package/docs/classes/NotAuthorizedError.html +4 -3
- package/docs/classes/NotRegisteredError.html +4 -3
- package/docs/classes/NotSignedInError.html +4 -3
- package/docs/classes/OperationNotImplementedError.html +4 -3
- package/docs/classes/RegisterError.html +4 -3
- package/docs/classes/RequestFailedError.html +6 -5
- package/docs/classes/ServiceError.html +4 -3
- package/docs/classes/SignOutError.html +4 -3
- package/docs/classes/SudoCryptoProviderDefaults.html +1 -1
- package/docs/classes/UnknownGraphQLError.html +6 -4
- package/docs/classes/UnrecognizedAlgorithmError.html +4 -3
- package/docs/classes/UserNotConfirmedError.html +4 -3
- package/docs/classes/VersionMismatchError.html +4 -3
- package/docs/enums/CachePolicy.html +2 -2
- package/docs/enums/EncryptionAlgorithm.html +2 -2
- package/docs/enums/KeyArchiveKeyType.html +2 -2
- package/docs/enums/KeyDataKeyFormat.html +3 -3
- package/docs/enums/KeyDataKeyType.html +2 -2
- package/docs/enums/ListOperationResultStatus.html +4 -4
- package/docs/enums/PublicKeyFormat.html +1 -1
- package/docs/index.html +1 -1
- package/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
- package/docs/interfaces/BooleanFilter.html +2 -2
- package/docs/interfaces/ConfigurationManager.html +5 -5
- package/docs/interfaces/KeyData.html +2 -2
- package/docs/interfaces/ListOperationFailureResult.html +2 -2
- package/docs/interfaces/ListOperationPartialResult.html +4 -4
- package/docs/interfaces/ListOperationSuccessResult.html +3 -3
- package/docs/interfaces/ListOutput.html +2 -2
- package/docs/interfaces/Logger.html +13 -7
- package/docs/interfaces/Owner.html +1 -1
- package/docs/interfaces/PublicKey.html +1 -1
- package/docs/interfaces/StringFilter.html +2 -2
- package/docs/interfaces/SudoCryptoProvider.html +39 -31
- package/docs/interfaces/SudoKeyArchive.html +10 -10
- package/docs/interfaces/SudoKeyManager.html +39 -31
- package/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
- package/docs/modules.html +4 -4
- package/github/.eslintrc.js +2 -4
- package/github/bin/outdated-with-suppression.sh +20 -0
- package/github/bin/suppress-outdated.sh +15 -0
- package/github/docs/assets/search.js +1 -1
- package/github/docs/classes/AccountLockedError.html +4 -3
- package/github/docs/classes/AuthenticationError.html +4 -3
- package/github/docs/classes/Base64.html +2 -2
- package/github/docs/classes/Buffer.html +2 -2
- package/github/docs/classes/ConfigurationNotSetError.html +4 -3
- package/github/docs/classes/ConfigurationSetNotFoundError.html +4 -3
- package/github/docs/classes/DecodeError.html +4 -3
- package/github/docs/classes/DefaultConfigurationManager.html +6 -6
- package/github/docs/classes/DefaultLogger.html +13 -7
- package/github/docs/classes/DefaultSudoKeyArchive.html +13 -13
- package/github/docs/classes/DefaultSudoKeyManager.html +31 -27
- package/github/docs/classes/FatalError.html +4 -3
- package/github/docs/classes/IllegalArgumentError.html +4 -3
- package/github/docs/classes/IllegalStateError.html +4 -3
- package/github/docs/classes/InsufficientEntitlementsError.html +4 -3
- package/github/docs/classes/InvalidOwnershipProofError.html +4 -3
- package/github/docs/classes/InvalidTokenError.html +4 -3
- package/github/docs/classes/KeyArchiveDecodingError.html +4 -3
- package/github/docs/classes/KeyArchiveIncorrectPasswordError.html +4 -3
- package/github/docs/classes/KeyArchiveMissingError.html +4 -3
- package/github/docs/classes/KeyArchiveNoPasswordRequiredError.html +4 -3
- package/github/docs/classes/KeyArchivePasswordRequiredError.html +4 -3
- package/github/docs/classes/KeyArchiveTypeError.html +4 -3
- package/github/docs/classes/KeyArchiveUnknownKeyTypeError.html +4 -3
- package/github/docs/classes/KeyArchiveVersionError.html +4 -3
- package/github/docs/classes/KeyNotFoundError.html +4 -3
- package/github/docs/classes/KeyStoreNotExportableError.html +4 -3
- package/github/docs/classes/LimitExceededError.html +4 -3
- package/github/docs/classes/NoEntitlementsError.html +4 -3
- package/github/docs/classes/NotAuthorizedError.html +4 -3
- package/github/docs/classes/NotRegisteredError.html +4 -3
- package/github/docs/classes/NotSignedInError.html +4 -3
- package/github/docs/classes/OperationNotImplementedError.html +4 -3
- package/github/docs/classes/RegisterError.html +4 -3
- package/github/docs/classes/RequestFailedError.html +6 -5
- package/github/docs/classes/ServiceError.html +4 -3
- package/github/docs/classes/SignOutError.html +4 -3
- package/github/docs/classes/SudoCryptoProviderDefaults.html +1 -1
- package/github/docs/classes/UnknownGraphQLError.html +6 -4
- package/github/docs/classes/UnrecognizedAlgorithmError.html +4 -3
- package/github/docs/classes/UserNotConfirmedError.html +4 -3
- package/github/docs/classes/VersionMismatchError.html +4 -3
- package/github/docs/enums/CachePolicy.html +2 -2
- package/github/docs/enums/EncryptionAlgorithm.html +2 -2
- package/github/docs/enums/KeyArchiveKeyType.html +2 -2
- package/github/docs/enums/KeyDataKeyFormat.html +3 -3
- package/github/docs/enums/KeyDataKeyType.html +2 -2
- package/github/docs/enums/ListOperationResultStatus.html +4 -4
- package/github/docs/enums/PublicKeyFormat.html +1 -1
- package/github/docs/index.html +1 -1
- package/github/docs/interfaces/AsymmetricEncryptionOptions.html +2 -2
- package/github/docs/interfaces/BooleanFilter.html +2 -2
- package/github/docs/interfaces/ConfigurationManager.html +5 -5
- package/github/docs/interfaces/KeyData.html +2 -2
- package/github/docs/interfaces/ListOperationFailureResult.html +2 -2
- package/github/docs/interfaces/ListOperationPartialResult.html +4 -4
- package/github/docs/interfaces/ListOperationSuccessResult.html +3 -3
- package/github/docs/interfaces/ListOutput.html +2 -2
- package/github/docs/interfaces/Logger.html +13 -7
- package/github/docs/interfaces/Owner.html +1 -1
- package/github/docs/interfaces/PublicKey.html +1 -1
- package/github/docs/interfaces/StringFilter.html +2 -2
- package/github/docs/interfaces/SudoCryptoProvider.html +39 -31
- package/github/docs/interfaces/SudoKeyArchive.html +10 -10
- package/github/docs/interfaces/SudoKeyManager.html +39 -31
- package/github/docs/interfaces/SymmetricEncryptionOptions.html +2 -2
- package/github/docs/modules.html +4 -4
- package/github/package.json +13 -10
- package/github/src/errors/error.ts +17 -8
- package/github/src/logging/logger.ts +65 -6
- package/github/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
- package/github/src/sudoKeyManager/sudoKeyManager.ts +22 -0
- package/github/test/logging/logger.spec.ts +122 -0
- package/github/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
- package/github/yarn.lock +566 -687
- package/lib/errors/error.d.ts +3 -2
- package/lib/errors/error.js +30 -20
- package/lib/logging/logger.d.ts +30 -0
- package/lib/logging/logger.js +12 -0
- package/lib/sudoKeyManager/sudoCryptoProvider.d.ts +12 -0
- package/lib/sudoKeyManager/sudoKeyManager.d.ts +14 -0
- package/lib/sudoKeyManager/sudoKeyManager.js +8 -0
- package/package.json +13 -10
- package/src/errors/error.ts +17 -8
- package/src/logging/logger.ts +65 -6
- package/src/sudoKeyManager/sudoCryptoProvider.ts +14 -0
- package/src/sudoKeyManager/sudoKeyManager.ts +22 -0
- package/test/logging/logger.spec.ts +122 -0
- package/test/sudoKeyManager/sudoKeyManager.spec.ts +37 -0
- package/yarn.lock +566 -687
package/github/package.json
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"license": "Apache-2.0",
|
|
10
10
|
"scripts": {
|
|
11
11
|
"audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
|
|
12
|
+
"outdated-with-suppressions": "bin/yarn-outdated-with-suppression.sh",
|
|
12
13
|
"clean": "rimraf ./lib ./test-lib",
|
|
13
14
|
"lint": "yarn lint:eslint && yarn lint:prettier",
|
|
14
15
|
"lint:eslint": "eslint \"{bin,integration-tests,src,test}/**/*.{ts,tsx}\"",
|
|
@@ -24,7 +25,9 @@
|
|
|
24
25
|
"types": "./lib/index.d.ts",
|
|
25
26
|
"bin": {
|
|
26
27
|
"audit-with-suppressions": "bin/yarn-audit-with-suppression.sh",
|
|
27
|
-
"suppress-audit": "bin/suppress-audit.sh"
|
|
28
|
+
"suppress-audit": "bin/suppress-audit.sh",
|
|
29
|
+
"outdated-with-suppressions": "bin/yarn-outdated-with-suppression.sh",
|
|
30
|
+
"suppress-outdated": "bin/suppress-outdated.sh"
|
|
28
31
|
},
|
|
29
32
|
"files": [
|
|
30
33
|
"lib",
|
|
@@ -53,23 +56,23 @@
|
|
|
53
56
|
"@babel/preset-env": "^7.15.8",
|
|
54
57
|
"@babel/preset-typescript": "^7.15.0",
|
|
55
58
|
"@types/jest": "^27.0.2",
|
|
56
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
57
|
-
"@typescript-eslint/parser": "^
|
|
58
|
-
"eslint": "^
|
|
59
|
+
"@typescript-eslint/eslint-plugin": "^5.1.0",
|
|
60
|
+
"@typescript-eslint/parser": "^5.1.0",
|
|
61
|
+
"eslint": "^8.0.1",
|
|
59
62
|
"eslint-config-prettier": "^8.3.0",
|
|
60
|
-
"eslint-plugin-import": "^2.
|
|
63
|
+
"eslint-plugin-import": "^2.25.2",
|
|
61
64
|
"eslint-plugin-prettier": "^4.0.0",
|
|
62
|
-
"fp-ts": "^2.11.
|
|
65
|
+
"fp-ts": "^2.11.5",
|
|
63
66
|
"io-ts": "^2.2.16",
|
|
64
67
|
"io-ts-types": "^0.5.16",
|
|
65
68
|
"isomorphic-webcrypto": "^2.3.8",
|
|
66
|
-
"jest": "^27.
|
|
69
|
+
"jest": "^27.3.1",
|
|
67
70
|
"monocle-ts": "^2.3.11",
|
|
68
71
|
"newtype-ts": "^0.3.2",
|
|
69
72
|
"prettier": "^2.4.1",
|
|
70
73
|
"rimraf": "^3.0.2",
|
|
71
74
|
"ts-mockito": "^2.6.1",
|
|
72
|
-
"typedoc": "^0.22.
|
|
73
|
-
"typescript": "^4.4.
|
|
75
|
+
"typedoc": "^0.22.6",
|
|
76
|
+
"typescript": "^4.4.4"
|
|
74
77
|
}
|
|
75
|
-
}
|
|
78
|
+
}
|
|
@@ -16,16 +16,25 @@ export function isAppSyncNetworkError(u: Error): u is AppSyncNetworkError {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* Indicates the GraphQL API returned an error that's not recognized by
|
|
19
|
+
* Indicates the GraphQL API returned an error that's not recognized by
|
|
20
|
+
* the client.
|
|
20
21
|
*/
|
|
21
22
|
export class UnknownGraphQLError extends Error {
|
|
22
|
-
constructor(cause:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
)
|
|
28
|
-
|
|
23
|
+
constructor(cause: unknown) {
|
|
24
|
+
const maybeAppSyncError = cause as AppSyncError
|
|
25
|
+
let message: string
|
|
26
|
+
if (maybeAppSyncError?.errorType) {
|
|
27
|
+
message = `type: ${maybeAppSyncError.errorType}, message: ${maybeAppSyncError.message}`
|
|
28
|
+
} else if (maybeAppSyncError?.message) {
|
|
29
|
+
message = maybeAppSyncError?.message
|
|
30
|
+
} else if (maybeAppSyncError?.name) {
|
|
31
|
+
message = maybeAppSyncError.name
|
|
32
|
+
} else {
|
|
33
|
+
message = 'unknown cause'
|
|
34
|
+
}
|
|
35
|
+
super(message)
|
|
36
|
+
|
|
37
|
+
this.name = 'UnknownGraphQLError'
|
|
29
38
|
}
|
|
30
39
|
}
|
|
31
40
|
|
|
@@ -4,36 +4,71 @@ import { BunyanLogger, createBunyanLogger } from './bunyanLogger'
|
|
|
4
4
|
* Interface encapsulating logger functions.
|
|
5
5
|
*/
|
|
6
6
|
export interface Logger {
|
|
7
|
+
/**
|
|
8
|
+
* @returns Whether or not trace level logging is enabled
|
|
9
|
+
*/
|
|
10
|
+
trace(): boolean
|
|
11
|
+
|
|
7
12
|
/**
|
|
8
13
|
* Will log the given message with the logger implementation using the TRACE level
|
|
9
14
|
* @param message the message to be logged
|
|
10
15
|
* @param fields optional fields that represent an object
|
|
11
16
|
*/
|
|
12
17
|
trace(message: string, fields?: Record<string, unknown>): void
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @returns Whether or not debug level logging is enabled
|
|
21
|
+
*/
|
|
22
|
+
debug(): boolean
|
|
23
|
+
|
|
13
24
|
/**
|
|
14
25
|
* Will log the given message with the logger implementation using the DEBUG level
|
|
15
26
|
* @param message the message to be logged
|
|
16
27
|
* @param fields optional fields that represent an object
|
|
17
28
|
*/
|
|
18
29
|
debug(message: string, fields?: Record<string, unknown>): void
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @returns Whether or not info level logging is enabled
|
|
33
|
+
*/
|
|
34
|
+
info(): boolean
|
|
35
|
+
|
|
19
36
|
/**
|
|
20
37
|
* Will log the given message with the logger implementation using the INFO level
|
|
21
38
|
* @param message the message to be logged
|
|
22
39
|
* @param fields optional fields that represent an object
|
|
23
40
|
*/
|
|
24
41
|
info(message: string, fields?: Record<string, unknown>): void
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @returns Whether or not warn level logging is enabled
|
|
45
|
+
*/
|
|
46
|
+
warn(): boolean
|
|
47
|
+
|
|
25
48
|
/**
|
|
26
49
|
* Will log the given message with the logger implementation using the WARN level
|
|
27
50
|
* @param message the message to be logged
|
|
28
51
|
* @param fields optional fields that represent an object
|
|
29
52
|
*/
|
|
30
53
|
warn(message: string, fields?: Record<string, unknown>): void
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @returns Whether or not error level logging is enabled
|
|
57
|
+
*/
|
|
58
|
+
error(): boolean
|
|
59
|
+
|
|
31
60
|
/**
|
|
32
61
|
* Will log the given message with the logger implementation using the ERROR level
|
|
33
62
|
* @param message the message to be logged
|
|
34
63
|
* @param fields optional fields that represent an object
|
|
35
64
|
*/
|
|
36
65
|
error(message: string, fields?: Record<string, unknown>): void
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @returns Whether or not fatal level logging is enabled
|
|
69
|
+
*/
|
|
70
|
+
fatal(): boolean
|
|
71
|
+
|
|
37
72
|
/**
|
|
38
73
|
* Will log the given message with the logger implementation using the FATAL level
|
|
39
74
|
* @param message the message to be logged
|
|
@@ -55,7 +90,11 @@ export class DefaultLogger implements Logger {
|
|
|
55
90
|
this.logger = createBunyanLogger(identifier, logLevel)
|
|
56
91
|
}
|
|
57
92
|
|
|
58
|
-
trace(
|
|
93
|
+
trace(): boolean
|
|
94
|
+
trace(message: string, fields?: Record<string, unknown>): void
|
|
95
|
+
trace(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
96
|
+
if (message === undefined) return this.logger.trace()
|
|
97
|
+
|
|
59
98
|
if (fields) {
|
|
60
99
|
this.logger.trace({ obj: fields }, message)
|
|
61
100
|
} else {
|
|
@@ -63,7 +102,11 @@ export class DefaultLogger implements Logger {
|
|
|
63
102
|
}
|
|
64
103
|
}
|
|
65
104
|
|
|
66
|
-
debug(
|
|
105
|
+
debug(): boolean
|
|
106
|
+
debug(message: string, fields?: Record<string, unknown>): void
|
|
107
|
+
debug(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
108
|
+
if (message === undefined) return this.logger.debug()
|
|
109
|
+
|
|
67
110
|
if (fields) {
|
|
68
111
|
this.logger.debug({ obj: fields }, message)
|
|
69
112
|
} else {
|
|
@@ -71,7 +114,11 @@ export class DefaultLogger implements Logger {
|
|
|
71
114
|
}
|
|
72
115
|
}
|
|
73
116
|
|
|
74
|
-
info(
|
|
117
|
+
info(): boolean
|
|
118
|
+
info(message: string, fields?: Record<string, unknown>): void
|
|
119
|
+
info(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
120
|
+
if (message === undefined) return this.logger.info()
|
|
121
|
+
|
|
75
122
|
if (fields) {
|
|
76
123
|
this.logger.info({ obj: fields }, message)
|
|
77
124
|
} else {
|
|
@@ -79,7 +126,11 @@ export class DefaultLogger implements Logger {
|
|
|
79
126
|
}
|
|
80
127
|
}
|
|
81
128
|
|
|
82
|
-
warn(
|
|
129
|
+
warn(): boolean
|
|
130
|
+
warn(message: string, fields?: Record<string, unknown>): void
|
|
131
|
+
warn(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
132
|
+
if (message === undefined) return this.logger.warn()
|
|
133
|
+
|
|
83
134
|
if (fields) {
|
|
84
135
|
this.logger.warn({ obj: fields }, message)
|
|
85
136
|
} else {
|
|
@@ -87,7 +138,11 @@ export class DefaultLogger implements Logger {
|
|
|
87
138
|
}
|
|
88
139
|
}
|
|
89
140
|
|
|
90
|
-
error(
|
|
141
|
+
error(): boolean
|
|
142
|
+
error(message: string, fields?: Record<string, unknown>): void
|
|
143
|
+
error(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
144
|
+
if (message === undefined) return this.logger.error()
|
|
145
|
+
|
|
91
146
|
if (fields) {
|
|
92
147
|
this.logger.error({ obj: fields }, message)
|
|
93
148
|
} else {
|
|
@@ -95,7 +150,11 @@ export class DefaultLogger implements Logger {
|
|
|
95
150
|
}
|
|
96
151
|
}
|
|
97
152
|
|
|
98
|
-
fatal(
|
|
153
|
+
fatal(): boolean
|
|
154
|
+
fatal(message: string, fields?: Record<string, unknown>): void
|
|
155
|
+
fatal(message?: string, fields?: Record<string, unknown>): boolean | void {
|
|
156
|
+
if (message === undefined) return this.logger.fatal()
|
|
157
|
+
|
|
99
158
|
if (fields) {
|
|
100
159
|
this.logger.fatal({ obj: fields }, message)
|
|
101
160
|
} else {
|
|
@@ -85,6 +85,13 @@ export interface SudoCryptoProvider {
|
|
|
85
85
|
*/
|
|
86
86
|
getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>
|
|
87
87
|
|
|
88
|
+
/**
|
|
89
|
+
* Checks to see if the specified symmetric key exists.
|
|
90
|
+
*
|
|
91
|
+
* @param name The name of the symmetric key.
|
|
92
|
+
*/
|
|
93
|
+
doesSymmetricKeyExists(name: string): Promise<boolean>
|
|
94
|
+
|
|
88
95
|
/**
|
|
89
96
|
* Deletes a symmetric key from the secure store.
|
|
90
97
|
*
|
|
@@ -147,6 +154,13 @@ export interface SudoCryptoProvider {
|
|
|
147
154
|
*/
|
|
148
155
|
getPrivateKey(name: string): Promise<ArrayBuffer | undefined>
|
|
149
156
|
|
|
157
|
+
/**
|
|
158
|
+
* Checks to see if the specified private key exists.
|
|
159
|
+
*
|
|
160
|
+
* @param name The name of the private key.
|
|
161
|
+
*/
|
|
162
|
+
doesPrivateKeyExists(name: string): Promise<boolean>
|
|
163
|
+
|
|
150
164
|
/**
|
|
151
165
|
* Adds a public key to the secure store.
|
|
152
166
|
*
|
|
@@ -63,6 +63,13 @@ export interface SudoKeyManager {
|
|
|
63
63
|
*/
|
|
64
64
|
getSymmetricKey(name: string): Promise<ArrayBuffer | undefined>
|
|
65
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Checks to see if the specified symmetric key exists.
|
|
68
|
+
*
|
|
69
|
+
* @param name The name of the symmetric key.
|
|
70
|
+
*/
|
|
71
|
+
doesSymmetricKeyExists(name: string): Promise<boolean>
|
|
72
|
+
|
|
66
73
|
/**
|
|
67
74
|
* Deletes a symmetric key from the secure store.
|
|
68
75
|
*
|
|
@@ -87,6 +94,13 @@ export interface SudoKeyManager {
|
|
|
87
94
|
*/
|
|
88
95
|
getPrivateKey(name: string): Promise<ArrayBuffer | undefined>
|
|
89
96
|
|
|
97
|
+
/**
|
|
98
|
+
* Checks to see if the specified private key exists.
|
|
99
|
+
*
|
|
100
|
+
* @param name The name of the private key.
|
|
101
|
+
*/
|
|
102
|
+
doesPrivateKeyExists(name: string): Promise<boolean>
|
|
103
|
+
|
|
90
104
|
/**
|
|
91
105
|
* Adds a public key to the secure store.
|
|
92
106
|
*
|
|
@@ -379,6 +393,10 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
|
|
|
379
393
|
return this.sudoCryptoProvider.getSymmetricKey(name)
|
|
380
394
|
}
|
|
381
395
|
|
|
396
|
+
public doesSymmetricKeyExists(name: string): Promise<boolean> {
|
|
397
|
+
return this.sudoCryptoProvider.doesSymmetricKeyExists(name)
|
|
398
|
+
}
|
|
399
|
+
|
|
382
400
|
public deleteSymmetricKey(name: string): Promise<void> {
|
|
383
401
|
return this.sudoCryptoProvider.deleteSymmetricKey(name)
|
|
384
402
|
}
|
|
@@ -395,6 +413,10 @@ export class DefaultSudoKeyManager implements SudoKeyManager {
|
|
|
395
413
|
return this.sudoCryptoProvider.getPrivateKey(name)
|
|
396
414
|
}
|
|
397
415
|
|
|
416
|
+
public doesPrivateKeyExists(name: string): Promise<boolean> {
|
|
417
|
+
return this.sudoCryptoProvider.doesPrivateKeyExists(name)
|
|
418
|
+
}
|
|
419
|
+
|
|
398
420
|
public addPublicKey(key: ArrayBuffer, name: string): Promise<void> {
|
|
399
421
|
return this.sudoCryptoProvider.addPublicKey(key, name)
|
|
400
422
|
}
|
|
@@ -57,4 +57,126 @@ describe('Logging utility test suite', () => {
|
|
|
57
57
|
),
|
|
58
58
|
)
|
|
59
59
|
})
|
|
60
|
+
|
|
61
|
+
it('should log with logger name at level set by environment variables', () => {
|
|
62
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
63
|
+
process.env.LOG_LEVEL = 'debug'
|
|
64
|
+
const logger = new DefaultLogger()
|
|
65
|
+
console.log = jest.fn()
|
|
66
|
+
logger.debug('logger name at level set by environment variables')
|
|
67
|
+
expect(console.log).toBeCalledTimes(1)
|
|
68
|
+
expect(console.log).toBeCalledWith(
|
|
69
|
+
expect.stringContaining(
|
|
70
|
+
'DEBUG: DummyProject: logger name at level set by environment variables',
|
|
71
|
+
),
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it.each`
|
|
76
|
+
level | traceEnabled
|
|
77
|
+
${'trace'} | ${true}
|
|
78
|
+
${'debug'} | ${false}
|
|
79
|
+
${'info'} | ${false}
|
|
80
|
+
${'warn'} | ${false}
|
|
81
|
+
${'error'} | ${false}
|
|
82
|
+
${'fatal'} | ${false}
|
|
83
|
+
`(
|
|
84
|
+
'should return trace enabled $traceEnabled when level is $level',
|
|
85
|
+
({ level, traceEnabled }) => {
|
|
86
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
87
|
+
process.env.LOG_LEVEL = level
|
|
88
|
+
const logger = new DefaultLogger()
|
|
89
|
+
expect(logger.trace()).toEqual(traceEnabled)
|
|
90
|
+
},
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
it.each`
|
|
94
|
+
level | debugEnabled
|
|
95
|
+
${'trace'} | ${true}
|
|
96
|
+
${'debug'} | ${true}
|
|
97
|
+
${'info'} | ${false}
|
|
98
|
+
${'warn'} | ${false}
|
|
99
|
+
${'error'} | ${false}
|
|
100
|
+
${'fatal'} | ${false}
|
|
101
|
+
`(
|
|
102
|
+
'should return debug enabled $debugEnabled when level is $level',
|
|
103
|
+
({ level, debugEnabled }) => {
|
|
104
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
105
|
+
process.env.LOG_LEVEL = level
|
|
106
|
+
const logger = new DefaultLogger()
|
|
107
|
+
expect(logger.debug()).toEqual(debugEnabled)
|
|
108
|
+
},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
it.each`
|
|
112
|
+
level | infoEnabled
|
|
113
|
+
${'trace'} | ${true}
|
|
114
|
+
${'debug'} | ${true}
|
|
115
|
+
${'info'} | ${true}
|
|
116
|
+
${'warn'} | ${false}
|
|
117
|
+
${'error'} | ${false}
|
|
118
|
+
${'fatal'} | ${false}
|
|
119
|
+
`(
|
|
120
|
+
'should return info enabled $infoEnabled when level is $level',
|
|
121
|
+
({ level, infoEnabled }) => {
|
|
122
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
123
|
+
process.env.LOG_LEVEL = level
|
|
124
|
+
const logger = new DefaultLogger()
|
|
125
|
+
expect(logger.info()).toEqual(infoEnabled)
|
|
126
|
+
},
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
it.each`
|
|
130
|
+
level | warnEnabled
|
|
131
|
+
${'trace'} | ${true}
|
|
132
|
+
${'debug'} | ${true}
|
|
133
|
+
${'info'} | ${true}
|
|
134
|
+
${'warn'} | ${true}
|
|
135
|
+
${'error'} | ${false}
|
|
136
|
+
${'fatal'} | ${false}
|
|
137
|
+
`(
|
|
138
|
+
'should return warn enabled $warnEnabled when level is $level',
|
|
139
|
+
({ level, warnEnabled }) => {
|
|
140
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
141
|
+
process.env.LOG_LEVEL = level
|
|
142
|
+
const logger = new DefaultLogger()
|
|
143
|
+
expect(logger.warn()).toEqual(warnEnabled)
|
|
144
|
+
},
|
|
145
|
+
)
|
|
146
|
+
|
|
147
|
+
it.each`
|
|
148
|
+
level | errorEnabled
|
|
149
|
+
${'trace'} | ${true}
|
|
150
|
+
${'debug'} | ${true}
|
|
151
|
+
${'info'} | ${true}
|
|
152
|
+
${'warn'} | ${true}
|
|
153
|
+
${'error'} | ${true}
|
|
154
|
+
${'fatal'} | ${false}
|
|
155
|
+
`(
|
|
156
|
+
'should return error enabled $errorEnabled when level is $level',
|
|
157
|
+
({ level, errorEnabled }) => {
|
|
158
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
159
|
+
process.env.LOG_LEVEL = level
|
|
160
|
+
const logger = new DefaultLogger()
|
|
161
|
+
expect(logger.error()).toEqual(errorEnabled)
|
|
162
|
+
},
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
it.each`
|
|
166
|
+
level | fatalEnabled
|
|
167
|
+
${'trace'} | ${true}
|
|
168
|
+
${'debug'} | ${true}
|
|
169
|
+
${'info'} | ${true}
|
|
170
|
+
${'warn'} | ${true}
|
|
171
|
+
${'error'} | ${true}
|
|
172
|
+
${'fatal'} | ${true}
|
|
173
|
+
`(
|
|
174
|
+
'should return fatal enabled $fatalEnabled when level is $level',
|
|
175
|
+
({ level, fatalEnabled }) => {
|
|
176
|
+
process.env.PROJECT_NAME = 'DummyProject'
|
|
177
|
+
process.env.LOG_LEVEL = level
|
|
178
|
+
const logger = new DefaultLogger()
|
|
179
|
+
expect(logger.fatal()).toEqual(fatalEnabled)
|
|
180
|
+
},
|
|
181
|
+
)
|
|
60
182
|
})
|
|
@@ -177,6 +177,24 @@ describe('DefaultSudoKeyManager', () => {
|
|
|
177
177
|
})
|
|
178
178
|
})
|
|
179
179
|
|
|
180
|
+
describe('doesSymmetricKeyExists', () => {
|
|
181
|
+
it('should call crypto provider doesSymmetricKeyExists', async () => {
|
|
182
|
+
when(
|
|
183
|
+
sudoCryptoProviderMock.doesSymmetricKeyExists(anything()),
|
|
184
|
+
).thenResolve(true)
|
|
185
|
+
|
|
186
|
+
await expect(
|
|
187
|
+
sudoKeyManager.doesSymmetricKeyExists('VpnKey'),
|
|
188
|
+
).resolves.toEqual(true)
|
|
189
|
+
const [actualKey] = capture(
|
|
190
|
+
sudoCryptoProviderMock.doesSymmetricKeyExists,
|
|
191
|
+
).first()
|
|
192
|
+
expect(actualKey).toStrictEqual('VpnKey')
|
|
193
|
+
|
|
194
|
+
verify(sudoCryptoProviderMock.doesSymmetricKeyExists(anything())).once()
|
|
195
|
+
})
|
|
196
|
+
})
|
|
197
|
+
|
|
180
198
|
describe('deleteSymmetricKey', () => {
|
|
181
199
|
it('should call crypto provider deleteSymmetricKey', async () => {
|
|
182
200
|
when(sudoCryptoProviderMock.deleteSymmetricKey(anything())).thenResolve()
|
|
@@ -263,6 +281,25 @@ describe('DefaultSudoKeyManager', () => {
|
|
|
263
281
|
})
|
|
264
282
|
})
|
|
265
283
|
|
|
284
|
+
describe('doesPrivateKeyExists', () => {
|
|
285
|
+
it('should call crypto provider doesPrivateKeyExists', async () => {
|
|
286
|
+
when(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).thenResolve(
|
|
287
|
+
true,
|
|
288
|
+
)
|
|
289
|
+
|
|
290
|
+
await expect(
|
|
291
|
+
sudoKeyManager.doesPrivateKeyExists('VpnKeyPair'),
|
|
292
|
+
).resolves.toBeTruthy()
|
|
293
|
+
|
|
294
|
+
const [actualKeyName] = capture(
|
|
295
|
+
sudoCryptoProviderMock.doesPrivateKeyExists,
|
|
296
|
+
).first()
|
|
297
|
+
expect(actualKeyName).toStrictEqual('VpnKeyPair')
|
|
298
|
+
|
|
299
|
+
verify(sudoCryptoProviderMock.doesPrivateKeyExists(anything())).once()
|
|
300
|
+
})
|
|
301
|
+
})
|
|
302
|
+
|
|
266
303
|
describe('addPublicKey', () => {
|
|
267
304
|
it('should call crypto provider addPublicKey', async () => {
|
|
268
305
|
when(
|