@@ -131,5 +131,82 @@ describe('base/config', () => {
131131 expect ( ( ) => validateConfig ( config ) ) . not . toThrow ( ) ;
132132 expect ( config . app . package ) . toBe ( '$TMP' ) ;
133133 } ) ;
134+
135+ describe ( 'validateCredentials' , ( ) => {
136+ test ( 'throws when username is plaintext (no env: prefix)' , ( ) => {
137+ // given a config with a plaintext username
138+ const config = {
139+ ...validConfig ,
140+ credentials : { username : 'admin' , password : 'env:MY_PASSWORD' }
141+ } as AbapDeployConfig ;
142+
143+ // when validateConfig is called
144+ // then it throws with the expected message
145+ expect ( ( ) => validateConfig ( config ) ) . toThrow (
146+ 'Credentials must be provided as environment variable references'
147+ ) ;
148+ } ) ;
149+
150+ test ( 'throws when password is plaintext (no env: prefix)' , ( ) => {
151+ // given a config with a plaintext password
152+ const config = {
153+ ...validConfig ,
154+ credentials : { username : 'env:MY_USER' , password : 'secret' }
155+ } as AbapDeployConfig ;
156+
157+ // when validateConfig is called
158+ // then it throws with the expected message
159+ expect ( ( ) => validateConfig ( config ) ) . toThrow (
160+ 'Credentials must be provided as environment variable references'
161+ ) ;
162+ } ) ;
163+
164+ test ( 'throws when both username and password are plaintext' , ( ) => {
165+ // given a config with plaintext username and password
166+ const config = {
167+ ...validConfig ,
168+ credentials : { username : 'admin' , password : 'secret' }
169+ } as AbapDeployConfig ;
170+
171+ // when validateConfig is called
172+ // then it throws with the expected message
173+ expect ( ( ) => validateConfig ( config ) ) . toThrow (
174+ 'Credentials must be provided as environment variable references'
175+ ) ;
176+ } ) ;
177+
178+ test ( 'passes when both username and password use env: prefix' , ( ) => {
179+ // given a config with env-referenced credentials
180+ const config = {
181+ ...validConfig ,
182+ credentials : { username : 'env:MY_USER' , password : 'env:MY_PASSWORD' }
183+ } as AbapDeployConfig ;
184+
185+ // when validateConfig is called
186+ // then it does not throw
187+ expect ( ( ) => validateConfig ( config ) ) . not . toThrow ( ) ;
188+ } ) ;
189+
190+ test ( 'passes when credentials are absent' , ( ) => {
191+ // given a config without credentials
192+ const config = { ...validConfig } as AbapDeployConfig ;
193+
194+ // when validateConfig is called
195+ // then it does not throw
196+ expect ( ( ) => validateConfig ( config ) ) . not . toThrow ( ) ;
197+ } ) ;
198+
199+ test ( 'passes when only username is set with env: prefix and password is absent' , ( ) => {
200+ // given a config with only username set via env:
201+ const config = {
202+ ...validConfig ,
203+ credentials : { username : 'env:MY_USER' }
204+ } as unknown as AbapDeployConfig ;
205+
206+ // when validateConfig is called
207+ // then it does not throw
208+ expect ( ( ) => validateConfig ( config ) ) . not . toThrow ( ) ;
209+ } ) ;
210+ } ) ;
134211 } ) ;
135212} ) ;
0 commit comments