@@ -30,6 +30,12 @@ import { safeDelete, safeMkdirSync } from '@socketsecurity/lib/fs'
3030import {
3131 findSocketYmlSync ,
3232 getConfigValue ,
33+ getConfigValueOrUndef ,
34+ getSupportedConfigEntries ,
35+ getSupportedConfigKeys ,
36+ isConfigFromFlag ,
37+ isSensitiveConfigKey ,
38+ isSupportedConfigKey ,
3339 overrideCachedConfig ,
3440 overrideConfigApiToken ,
3541 resetConfigForTesting ,
@@ -360,4 +366,103 @@ describe('utils/config', () => {
360366 expect ( result . ok ) . toBe ( true )
361367 } )
362368 } )
369+
370+ describe ( 'getSupportedConfigEntries / getSupportedConfigKeys' , ( ) => {
371+ it ( 'returns a non-empty array of [key, value] entries' , ( ) => {
372+ const entries = getSupportedConfigEntries ( )
373+ expect ( Array . isArray ( entries ) ) . toBe ( true )
374+ expect ( entries . length ) . toBeGreaterThan ( 0 )
375+ for ( const entry of entries ) {
376+ expect ( Array . isArray ( entry ) ) . toBe ( true )
377+ expect ( entry ) . toHaveLength ( 2 )
378+ }
379+ } )
380+
381+ it ( 'returns a non-empty array of supported keys' , ( ) => {
382+ const keys = getSupportedConfigKeys ( )
383+ expect ( Array . isArray ( keys ) ) . toBe ( true )
384+ expect ( keys . length ) . toBeGreaterThan ( 0 )
385+ expect ( keys ) . toContain ( 'defaultOrg' )
386+ } )
387+ } )
388+
389+ describe ( 'isConfigFromFlag' , ( ) => {
390+ it ( 'returns false initially' , ( ) => {
391+ resetConfigForTesting ( )
392+ expect ( isConfigFromFlag ( ) ) . toBe ( false )
393+ } )
394+
395+ it ( 'returns true after invalid override (line 315)' , ( ) => {
396+ resetConfigForTesting ( )
397+ // overrideCachedConfig with non-object JSON triggers the catch branch
398+ // that sets _configFromFlag = true.
399+ overrideCachedConfig ( 'not valid json{{{{' )
400+ expect ( isConfigFromFlag ( ) ) . toBe ( true )
401+ } )
402+ } )
403+
404+ describe ( 'isSensitiveConfigKey' , ( ) => {
405+ it ( 'returns true for apiToken' , ( ) => {
406+ expect ( isSensitiveConfigKey ( 'apiToken' ) ) . toBe ( true )
407+ } )
408+
409+ it ( 'returns false for non-sensitive keys' , ( ) => {
410+ expect ( isSensitiveConfigKey ( 'defaultOrg' ) ) . toBe ( false )
411+ } )
412+
413+ it ( 'returns false for unknown keys' , ( ) => {
414+ expect ( isSensitiveConfigKey ( 'totally-bogus' ) ) . toBe ( false )
415+ } )
416+ } )
417+
418+ describe ( 'isSupportedConfigKey' , ( ) => {
419+ it ( 'returns true for known keys' , ( ) => {
420+ expect ( isSupportedConfigKey ( 'defaultOrg' ) ) . toBe ( true )
421+ expect ( isSupportedConfigKey ( 'apiToken' ) ) . toBe ( true )
422+ } )
423+
424+ it ( 'returns false for unknown keys' , ( ) => {
425+ expect ( isSupportedConfigKey ( 'totally-bogus' ) ) . toBe ( false )
426+ } )
427+ } )
428+
429+ describe ( 'overrideCachedConfig' , ( ) => {
430+ afterEach ( ( ) => {
431+ resetConfigForTesting ( )
432+ } )
433+
434+ it ( 'returns parse error for non-object JSON (line 315)' , ( ) => {
435+ // A primitive (number) is valid JSON but not a config object.
436+ const result = overrideCachedConfig ( '42' )
437+ expect ( result . ok ) . toBe ( false )
438+ if ( ! result . ok ) {
439+ expect ( result . message ) . toBe ( 'Could not parse Config as JSON' )
440+ }
441+ } )
442+
443+ it ( 'returns parse error for null JSON (line 315)' , ( ) => {
444+ const result = overrideCachedConfig ( 'null' )
445+ expect ( result . ok ) . toBe ( false )
446+ if ( ! result . ok ) {
447+ expect ( result . message ) . toBe ( 'Could not parse Config as JSON' )
448+ }
449+ } )
450+ } )
451+
452+ describe ( 'getConfigValueOrUndef' , ( ) => {
453+ afterEach ( ( ) => {
454+ resetConfigForTesting ( )
455+ } )
456+
457+ it ( 'returns undefined for invalid keys' , ( ) => {
458+ // The internal normalizeConfigKey returns !ok for unsupported keys.
459+ // getConfigValueOrUndef squashes that to undefined.
460+ expect ( getConfigValueOrUndef ( 'totally-bogus' as any ) ) . toBeUndefined ( )
461+ } )
462+
463+ it ( 'returns the config value for valid keys' , ( ) => {
464+ overrideCachedConfig ( JSON . stringify ( { defaultOrg : 'my-org' } ) )
465+ expect ( getConfigValueOrUndef ( 'defaultOrg' ) ) . toBe ( 'my-org' )
466+ } )
467+ } )
363468} )
0 commit comments