mirror of https://github.com/apache/jclouds.git
Issue 741:UserAdd doesn't copy skeleton directory
This commit is contained in:
parent
debabe632f
commit
29ee165de2
|
@ -129,8 +129,8 @@ public class RunScriptOnNodeUsingSshTest {
|
|||
expect(sshClient.getUsername()).andReturn("tester");
|
||||
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
|
||||
expect(sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" +
|
||||
"mkdir -p /home/users/testuser\n" +
|
||||
"useradd -s /bin/bash -d /home/users/testuser testuser\n" +
|
||||
"mkdir -p /home/users\n" +
|
||||
"useradd -s /bin/bash -m -d /home/users/testuser testuser\n" +
|
||||
"chown -R testuser /home/users/testuser\n" +
|
||||
"RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("done", null, 0));
|
||||
sshClient.disconnect();
|
||||
|
|
|
@ -32,7 +32,7 @@ import com.google.common.collect.Multimap;
|
|||
* @author Adrian Cole
|
||||
*/
|
||||
public class SaveHttpResponseTo extends InterpretableStatement {
|
||||
static final String CURL = "curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20";
|
||||
public static final String CURL = "curl -q -s -S -L --connect-timeout 10 --max-time 600 --retry 20";
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -161,7 +161,8 @@ public class UserAdd implements Statement {
|
|||
throw new UnsupportedOperationException("windows not yet implemented");
|
||||
String homeDir = defaultHome + "{fs}" + login;
|
||||
ImmutableList.Builder<Statement> statements = ImmutableList.<Statement> builder();
|
||||
statements.add(Statements.exec("{md} " + homeDir));
|
||||
// useradd cannot create the default homedir
|
||||
statements.add(Statements.exec("{md} " + defaultHome));
|
||||
|
||||
ImmutableMap.Builder<String, String> userAddOptions = ImmutableMap.<String, String> builder();
|
||||
userAddOptions.put("-s", shell);
|
||||
|
@ -176,6 +177,7 @@ public class UserAdd implements Statement {
|
|||
userAddOptions.put("-G", Joiner.on(',').join(groups));
|
||||
|
||||
}
|
||||
userAddOptions.put("-m", "");
|
||||
userAddOptions.put("-d", homeDir);
|
||||
if (password != null) {
|
||||
try {
|
||||
|
|
|
@ -33,41 +33,41 @@ public class UserAddTest {
|
|||
|
||||
public void testUNIX() {
|
||||
assertEquals(UserAdd.builder().login("me").build().render(OsFamily.UNIX),
|
||||
"mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
"mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
}
|
||||
|
||||
public void testWithBaseUNIX() {
|
||||
assertEquals(UserAdd.builder().login("me").defaultHome("/export/home").build().render(OsFamily.UNIX),
|
||||
"mkdir -p /export/home/me\nuseradd -s /bin/bash -d /export/home/me me\nchown -R me /export/home/me\n");
|
||||
"mkdir -p /export/home\nuseradd -s /bin/bash -m -d /export/home/me me\nchown -R me /export/home/me\n");
|
||||
}
|
||||
|
||||
public void testWithGroupUNIX() {
|
||||
assertEquals(UserAdd.builder().login("me").group("wheel").build().render(OsFamily.UNIX),
|
||||
"mkdir -p /home/users/me\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
"mkdir -p /home/users\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
}
|
||||
|
||||
public void testWithGroupsUNIX() {
|
||||
assertEquals(UserAdd.builder().login("me").groups(ImmutableList.of("wheel", "candy")).build().render(
|
||||
OsFamily.UNIX),
|
||||
"mkdir -p /home/users/me\ngroupadd -f wheel\ngroupadd -f candy\nuseradd -s /bin/bash -g wheel -G candy -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
"mkdir -p /home/users\ngroupadd -f wheel\ngroupadd -f candy\nuseradd -s /bin/bash -g wheel -G candy -m -d /home/users/me me\nchown -R me /home/users/me\n");
|
||||
}
|
||||
|
||||
public void testWithPasswordUNIX() {
|
||||
String userAdd = UserAdd.builder().login("me").password("foo").group("wheel").build().render(OsFamily.UNIX);
|
||||
assert userAdd.startsWith("mkdir -p /home/users/me\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -d /home/users/me -p '$6$") : userAdd;
|
||||
assert userAdd.startsWith("mkdir -p /home/users\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me -p '$6$") : userAdd;
|
||||
assert userAdd.endsWith("' me\nchown -R me /home/users/me\n") : userAdd;
|
||||
}
|
||||
|
||||
public void testWithSshAuthorizedKeyUNIX() {
|
||||
assertEquals(
|
||||
UserAdd.builder().login("me").authorizeRSAPublicKey("rsapublickey").build().render(OsFamily.UNIX),
|
||||
"mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nmkdir -p /home/users/me/.ssh\ncat >> /home/users/me/.ssh/authorized_keys <<'END_OF_FILE'\nrsapublickey\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/authorized_keys\nchown -R me /home/users/me\n");
|
||||
"mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nmkdir -p /home/users/me/.ssh\ncat >> /home/users/me/.ssh/authorized_keys <<'END_OF_FILE'\nrsapublickey\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/authorized_keys\nchown -R me /home/users/me\n");
|
||||
}
|
||||
|
||||
public void testWithSshInstalledKeyUNIX() {
|
||||
assertEquals(
|
||||
UserAdd.builder().login("me").installRSAPrivateKey("rsaprivate").build().render(OsFamily.UNIX),
|
||||
"mkdir -p /home/users/me\nuseradd -s /bin/bash -d /home/users/me me\nmkdir -p /home/users/me/.ssh\nrm /home/users/me/.ssh/id_rsa\ncat >> /home/users/me/.ssh/id_rsa <<'END_OF_FILE'\nrsaprivate\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n");
|
||||
"mkdir -p /home/users\nuseradd -s /bin/bash -m -d /home/users/me me\nmkdir -p /home/users/me/.ssh\nrm /home/users/me/.ssh/id_rsa\ncat >> /home/users/me/.ssh/id_rsa <<'END_OF_FILE'\nrsaprivate\nEND_OF_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n");
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||
|
|
|
@ -4,9 +4,9 @@ root ALL = (ALL) ALL
|
|||
%wheel ALL = (ALL) NOPASSWD:ALL
|
||||
END_OF_FILE
|
||||
chmod 0440 /etc/sudoers
|
||||
mkdir -p /home/users/foo
|
||||
mkdir -p /home/users
|
||||
groupadd -f wheel
|
||||
useradd -s /bin/bash -g wheel -d /home/users/foo -p 'crypt(bar)' foo
|
||||
useradd -s /bin/bash -g wheel -m -d /home/users/foo -p 'crypt(bar)' foo
|
||||
mkdir -p /home/users/foo/.ssh
|
||||
cat >> /home/users/foo/.ssh/authorized_keys <<'END_OF_FILE'
|
||||
fooPublicKey
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mkdir -p /home/users/defaultAdminUsername
|
||||
useradd -s /bin/bash -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
||||
mkdir -p /home/users
|
||||
useradd -s /bin/bash -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
||||
mkdir -p /home/users/defaultAdminUsername/.ssh
|
||||
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
||||
publicKey
|
||||
|
|
|
@ -4,9 +4,9 @@ root ALL = (ALL) ALL
|
|||
%wheel ALL = (ALL) NOPASSWD:ALL
|
||||
END_OF_FILE
|
||||
chmod 0440 /etc/sudoers
|
||||
mkdir -p /home/users/defaultAdminUsername
|
||||
mkdir -p /home/users
|
||||
groupadd -f wheel
|
||||
useradd -s /bin/bash -g wheel -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
||||
useradd -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
||||
mkdir -p /home/users/defaultAdminUsername/.ssh
|
||||
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
||||
publicKey
|
||||
|
|
Loading…
Reference in New Issue