@@ -4,6 +4,7 @@ import { SecretsRequireTTYError } from '@app-config/core';
4
4
import { loadMetaConfig } from '@app-config/meta' ;
5
5
import { withTempFiles , mockedStdin } from '@app-config/test-utils' ;
6
6
7
+ import { defaultEnvOptions } from '@app-config/node' ;
7
8
import {
8
9
initializeKeys ,
9
10
initializeKeysManually ,
@@ -102,6 +103,77 @@ describe('User Keys', () => {
102
103
} ) ;
103
104
} ) ;
104
105
106
+ const createKeys = async ( ) => {
107
+ const { privateKeyArmored, publicKeyArmored } = await initializeKeysManually ( {
108
+ name : 'Tester' ,
109
+
110
+ } ) ;
111
+
112
+ return {
113
+ privateKey : await loadPrivateKey ( privateKeyArmored ) ,
114
+ publicKey : await loadPublicKey ( publicKeyArmored ) ,
115
+ privateKeyArmored,
116
+ publicKeyArmored,
117
+ } ;
118
+ } ;
119
+
120
+ describe ( 'User keys from environment' , ( ) => {
121
+ it ( 'loads user keys from environment' , async ( ) => {
122
+ const keys = await createKeys ( ) ;
123
+
124
+ process . env . APP_CONFIG_SECRETS_PUBLIC_KEY = keys . publicKeyArmored ;
125
+ process . env . APP_CONFIG_SECRETS_KEY = keys . privateKeyArmored ;
126
+
127
+ const privateKey = await loadPrivateKey ( ) ;
128
+ const publicKey = await loadPublicKey ( ) ;
129
+
130
+ expect ( privateKey . getFingerprint ( ) ) . toEqual ( keys . privateKey . getFingerprint ( ) ) ;
131
+ expect ( publicKey . getFingerprint ( ) ) . toEqual ( keys . publicKey . getFingerprint ( ) ) ;
132
+ } ) ;
133
+
134
+ it ( 'loads environment user keys from environment' , async ( ) => {
135
+ const keys = await createKeys ( ) ;
136
+
137
+ process . env . APP_CONFIG_SECRETS_PUBLIC_KEY_PRODUCTION = keys . publicKeyArmored ;
138
+ process . env . APP_CONFIG_SECRETS_KEY_PRODUCTION = keys . privateKeyArmored ;
139
+ process . env . APP_CONFIG_ENV = 'prod' ;
140
+
141
+ const privateKey = await loadPrivateKey ( undefined , defaultEnvOptions ) ;
142
+ const publicKey = await loadPublicKey ( undefined , defaultEnvOptions ) ;
143
+
144
+ expect ( privateKey . getFingerprint ( ) ) . toEqual ( keys . privateKey . getFingerprint ( ) ) ;
145
+ expect ( publicKey . getFingerprint ( ) ) . toEqual ( keys . publicKey . getFingerprint ( ) ) ;
146
+ } ) ;
147
+
148
+ it ( 'loads aliased environment user keys from environment' , async ( ) => {
149
+ const keys = await createKeys ( ) ;
150
+
151
+ process . env . APP_CONFIG_SECRETS_PUBLIC_KEY_PROD = keys . publicKeyArmored ;
152
+ process . env . APP_CONFIG_SECRETS_KEY_PROD = keys . privateKeyArmored ;
153
+ process . env . APP_CONFIG_ENV = 'prod' ;
154
+
155
+ const privateKey = await loadPrivateKey ( undefined , defaultEnvOptions ) ;
156
+ const publicKey = await loadPublicKey ( undefined , defaultEnvOptions ) ;
157
+
158
+ expect ( privateKey . getFingerprint ( ) ) . toEqual ( keys . privateKey . getFingerprint ( ) ) ;
159
+ expect ( publicKey . getFingerprint ( ) ) . toEqual ( keys . publicKey . getFingerprint ( ) ) ;
160
+ } ) ;
161
+
162
+ it ( 'falls back to key with no environment' , async ( ) => {
163
+ const keys = await createKeys ( ) ;
164
+
165
+ process . env . APP_CONFIG_SECRETS_PUBLIC_KEY = keys . publicKeyArmored ;
166
+ process . env . APP_CONFIG_SECRETS_KEY = keys . privateKeyArmored ;
167
+ process . env . APP_CONFIG_ENV = 'prod' ;
168
+
169
+ const privateKey = await loadPrivateKey ( undefined , defaultEnvOptions ) ;
170
+ const publicKey = await loadPublicKey ( undefined , defaultEnvOptions ) ;
171
+
172
+ expect ( privateKey . getFingerprint ( ) ) . toEqual ( keys . privateKey . getFingerprint ( ) ) ;
173
+ expect ( publicKey . getFingerprint ( ) ) . toEqual ( keys . publicKey . getFingerprint ( ) ) ;
174
+ } ) ;
175
+ } ) ;
176
+
105
177
const createKey = async ( ) => {
106
178
const { privateKeyArmored } = await initializeKeysManually ( {
107
179
name : 'Tester' ,
0 commit comments