@@ -17,22 +17,25 @@ describe('getEntPasswdShellCommand', function () {
1717 {
1818 image : 'busybox' ,
1919 getentPath : undefined ,
20- addUserOptions : '-D -h' ,
20+ addUserCommand : 'adduser -D -h /home/foo foo\\\\bar ' ,
2121 userName : 'foo\\bar' ,
22+ homeFolder : '/home/foo' ,
2223 } ,
2324 {
2425 image : 'debian' ,
2526 getentPath : '/usr/bin/getent' ,
26- addUserOptions : '--disabled-password --allow-all-names --gecos "" --home ' ,
27+ addUserCommand : 'useradd -m -d /home/foo --badname foo\\\\bar ' ,
2728 userName : 'foo\\bar' ,
29+ homeFolder : '/home/foo' ,
2830 } ,
2931 {
3032 image : 'alpine' ,
3133 getentPath : '/usr/bin/getent' ,
32- addUserOptions : '-D -h' ,
34+ addUserCommand : 'adduser -D -h /home/foo foo_bar ' ,
3335 userName : 'foo_bar' , // Alpine doesn't support backslash in user names.
36+ homeFolder : '/home/foo' ,
3437 } ,
35- ] . forEach ( ( { image, getentPath, addUserOptions , userName } ) => {
38+ ] . forEach ( ( { image, getentPath, addUserCommand , userName, homeFolder } ) => {
3639 it ( `should work with ${ image } ${ getentPath ? 'with' : 'without' } getent command` , async ( ) => {
3740 const res = await shellExec ( `docker run -d ${ image } sleep inf` ) ;
3841 const containerId = res . stdout . trim ( ) ;
@@ -48,17 +51,17 @@ describe('getEntPasswdShellCommand', function () {
4851 . catch ( ( ) => undefined ) ;
4952 assert . strictEqual ( which ?. stdout . trim ( ) , getentPath ) ;
5053
51- await shellServer . exec ( `adduser ${ addUserOptions } /home/foo ${ userName . replaceAll ( '\\' , '\\\\' ) } ` ) ;
54+ await shellServer . exec ( addUserCommand ) ;
5255
5356 const userByName = await getUserFromPasswdDB ( shellServer , userName ) ;
5457 assert . ok ( userByName ) ;
5558 assert . strictEqual ( userByName . name , userName ) ;
56- assert . strictEqual ( userByName . home , '/home/foo' ) ;
59+ assert . strictEqual ( userByName . home , homeFolder ) ;
5760
5861 const userById = await getUserFromPasswdDB ( shellServer , userByName . uid ) ;
5962 assert . ok ( userById ) ;
6063 assert . strictEqual ( userById . name , userName ) ;
61- assert . strictEqual ( userById . home , '/home/foo' ) ;
64+ assert . strictEqual ( userById . home , homeFolder ) ;
6265
6366 const nonexistentUser = await getUserFromPasswdDB ( shellServer , '123456' ) ;
6467 assert . strictEqual ( undefined , nonexistentUser ) ;
0 commit comments