@@ -222,4 +222,38 @@ describe('profile storage', () => {
222222 expect ( profileExists ( 'nonexistent' ) ) . toBe ( false )
223223 } )
224224 } )
225+
226+ describe ( 'getProfilePath' , ( ) => {
227+ it ( 'accepts valid profile names' , ( ) => {
228+ expect ( ( ) => getProfilePath ( 'valid-profile' ) ) . not . toThrow ( )
229+ expect ( ( ) => getProfilePath ( 'profile_123' ) ) . not . toThrow ( )
230+ expect ( ( ) => getProfilePath ( 'MyProfile' ) ) . not . toThrow ( )
231+ } )
232+
233+ it ( 'rejects empty profile names' , ( ) => {
234+ expect ( ( ) => getProfilePath ( '' ) ) . toThrow ( 'Invalid profile name' )
235+ } )
236+
237+ it ( 'rejects profile names with forward slashes' , ( ) => {
238+ expect ( ( ) => getProfilePath ( 'foo/bar' ) ) . toThrow ( 'Invalid profile name' )
239+ expect ( ( ) => getProfilePath ( '/etc/passwd' ) ) . toThrow ( 'Invalid profile name' )
240+ } )
241+
242+ it ( 'rejects profile names with backslashes' , ( ) => {
243+ expect ( ( ) => getProfilePath ( String . raw `foo\bar` ) ) . toThrow ( 'Invalid profile name' )
244+ expect ( ( ) => getProfilePath ( String . raw `C:\Windows\System32` ) ) . toThrow ( 'Invalid profile name' )
245+ } )
246+
247+ it ( 'rejects profile names with parent directory references' , ( ) => {
248+ expect ( ( ) => getProfilePath ( '..' ) ) . toThrow ( 'Invalid profile name' )
249+ expect ( ( ) => getProfilePath ( '../../etc/passwd' ) ) . toThrow ( 'Invalid profile name' )
250+ expect ( ( ) => getProfilePath ( 'foo..bar' ) ) . toThrow ( 'Invalid profile name' )
251+ } )
252+
253+ it ( 'rejects path traversal attempts' , ( ) => {
254+ expect ( ( ) => getProfilePath ( '../../../../some-place-you-should-not-have-access-to' ) ) . toThrow (
255+ 'Invalid profile name' ,
256+ )
257+ } )
258+ } )
225259} )
0 commit comments