@@ -854,6 +854,199 @@ describe("Profiles Unit Tests - function deleteProfile", () => {
854854 } ) ;
855855} ) ;
856856
857+ describe ( "Profiles Unit Tests - function profileHasSecureToken" , ( ) => {
858+ const globalMocks = createGlobalMocks ( ) ;
859+
860+ const environmentSetup = ( globalMocks ) : void => {
861+ globalMocks . testProfile . profile . password = null ;
862+ globalMocks . testProfile . profile . tokenType = "" ;
863+ Object . defineProperty ( Profiles . getInstance ( ) , "profilesForValidation" , {
864+ value : [
865+ {
866+ name : "sestest" ,
867+ message : "" ,
868+ type : "" ,
869+ status : "active" ,
870+ failNotFound : false ,
871+ } ,
872+ ] ,
873+ configurable : true ,
874+ } ) ;
875+ Object . defineProperty ( Profiles . getInstance ( ) , "profilesValidationSetting" , {
876+ value : [
877+ {
878+ name : "otherSestest" ,
879+ setting : false ,
880+ } ,
881+ ] ,
882+ configurable : true ,
883+ } ) ;
884+ } ;
885+
886+ beforeEach ( ( ) => {
887+ jest . clearAllMocks ( ) ;
888+ environmentSetup ( globalMocks ) ;
889+ } ) ;
890+
891+ it ( "should extract parent profiles" , async ( ) => {
892+ Object . defineProperty ( Constants , "PROFILES_CACHE" , { value : "test4" } ) ;
893+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
894+ getTeamConfig : ( ) => ( {
895+ api : {
896+ profiles : {
897+ getProfilePathFromName : ( ) => "profiles.test1.profiles.test2.profiles.test3" ,
898+ } ,
899+ secure : {
900+ secureFields : ( ) => [ "test1.test2.test3" ] ,
901+ } ,
902+ } ,
903+ } ) ,
904+ isSecured : ( ) => true ,
905+ } as any ) ;
906+ jest . spyOn ( Profiles . getInstance ( ) , "getDefaultProfile" ) . mockReturnValue ( { } as any ) ;
907+ expect ( ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( "test1.test2.test3" ) ) . toBeTruthy ( ) ;
908+ } ) ;
909+
910+ it ( "should return false when no secure fields match any profile paths" , async ( ) => {
911+ Object . defineProperty ( Constants , "PROFILES_CACHE" , { value : { getDefaultProfile : ( ) => null } } ) ;
912+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
913+ getTeamConfig : ( ) => ( {
914+ api : {
915+ profiles : {
916+ getProfilePathFromName : ( ) => "profiles.test1.profiles.test2" ,
917+ } ,
918+ secure : {
919+ secureFields : ( ) => [ "someother.field.tokenValue" ] ,
920+ } ,
921+ } ,
922+ } ) ,
923+ isSecured : ( ) => true ,
924+ } as any ) ;
925+
926+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "test2" } ) ;
927+ expect ( result ) . toBeFalsy ( ) ;
928+ } ) ;
929+
930+ it ( "should return true when base profile has secure token" , async ( ) => {
931+ const mockBaseProfile = { name : "base" } ;
932+ Object . defineProperty ( Constants , "PROFILES_CACHE" , {
933+ value : { getDefaultProfile : ( ) => mockBaseProfile } ,
934+ } ) ;
935+
936+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
937+ getTeamConfig : ( ) => ( {
938+ api : {
939+ profiles : {
940+ getProfilePathFromName : ( name ) => {
941+ if ( name === "base" ) return "profiles.base" ;
942+ return "profiles.test1.profiles.test2" ;
943+ } ,
944+ } ,
945+ secure : {
946+ secureFields : ( ) => [ "profiles.base.properties.tokenValue" ] ,
947+ } ,
948+ } ,
949+ } ) ,
950+ isSecured : ( ) => true ,
951+ } as any ) ;
952+
953+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "test2" } ) ;
954+ expect ( result ) . toBeTruthy ( ) ;
955+ } ) ;
956+
957+ it ( "should handle empty secure fields array" , async ( ) => {
958+ Object . defineProperty ( Constants , "PROFILES_CACHE" , { value : { getDefaultProfile : ( ) => null } } ) ;
959+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
960+ getTeamConfig : ( ) => ( {
961+ api : {
962+ profiles : {
963+ getProfilePathFromName : ( ) => "profiles.test1.profiles.test2" ,
964+ } ,
965+ secure : {
966+ secureFields : ( ) => [ ] ,
967+ } ,
968+ } ,
969+ } ) ,
970+ isSecured : ( ) => true ,
971+ } as any ) ;
972+
973+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "test2" } ) ;
974+ expect ( result ) . toBeFalsy ( ) ;
975+ } ) ;
976+
977+ it ( "should handle complex nested profile hierarchy" , async ( ) => {
978+ Object . defineProperty ( Constants , "PROFILES_CACHE" , { value : { getDefaultProfile : ( ) => null } } ) ;
979+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
980+ getTeamConfig : ( ) => ( {
981+ api : {
982+ profiles : {
983+ getProfilePathFromName : ( ) => "profiles.level1.profiles.level2.profiles.level3.profiles.level4" ,
984+ } ,
985+ secure : {
986+ secureFields : ( ) => [ "profiles.level1.profiles.level2.properties.tokenValue" , "other.field" ] ,
987+ } ,
988+ } ,
989+ } ) ,
990+ isSecured : ( ) => true ,
991+ } as any ) ;
992+
993+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "level4" } ) ;
994+ expect ( result ) . toBeTruthy ( ) ;
995+ } ) ;
996+
997+ it ( "should not include duplicate paths in allPaths array" , async ( ) => {
998+ Object . defineProperty ( Constants , "PROFILES_CACHE" , { value : { getDefaultProfile : ( ) => null } } ) ;
999+ const secureFieldsSpy = jest . fn ( ) . mockReturnValue ( [ "profiles.test1.properties.tokenValue" ] ) ;
1000+
1001+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
1002+ getTeamConfig : ( ) => ( {
1003+ api : {
1004+ profiles : {
1005+ getProfilePathFromName : ( ) => "profiles.test1.profiles.test1" , // duplicate segment
1006+ } ,
1007+ secure : {
1008+ secureFields : secureFieldsSpy ,
1009+ } ,
1010+ } ,
1011+ } ) ,
1012+ isSecured : ( ) => true ,
1013+ } as any ) ;
1014+
1015+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "test1" } ) ;
1016+
1017+ // Should still work correctly even with duplicate segments
1018+ expect ( result ) . toBeTruthy ( ) ;
1019+ expect ( secureFieldsSpy ) . toHaveBeenCalledTimes ( 1 ) ;
1020+ } ) ;
1021+
1022+ it ( "should handle base profile when it matches an existing path" , async ( ) => {
1023+ const mockBaseProfile = { name : "test1" } ;
1024+ Object . defineProperty ( Constants , "PROFILES_CACHE" , {
1025+ value : { getDefaultProfile : ( ) => mockBaseProfile } ,
1026+ } ) ;
1027+
1028+ jest . spyOn ( Profiles . getInstance ( ) , "getProfileInfo" ) . mockResolvedValue ( {
1029+ getTeamConfig : ( ) => ( {
1030+ api : {
1031+ profiles : {
1032+ getProfilePathFromName : ( name ) => {
1033+ if ( name === "test1" ) return "profiles.test1" ;
1034+ return "profiles.test1.profiles.test2" ;
1035+ } ,
1036+ } ,
1037+ secure : {
1038+ secureFields : ( ) => [ "profiles.test1.properties.tokenValue" ] ,
1039+ } ,
1040+ } ,
1041+ } ) ,
1042+ isSecured : ( ) => true ,
1043+ } as any ) ;
1044+
1045+ const result = await ( Profiles . getInstance ( ) as any ) . profileHasSecureToken ( { name : "test2" } ) ;
1046+ expect ( result ) . toBeTruthy ( ) ;
1047+ } ) ;
1048+ } ) ;
1049+
8571050describe ( "Profiles Unit Tests - function checkCurrentProfile" , ( ) => {
8581051 const environmentSetup = ( globalMocks ) : void => {
8591052 globalMocks . testProfile . profile . password = null ;
0 commit comments