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.getUsername()).andReturn("tester");
|
||||||
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
|
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
|
||||||
expect(sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" +
|
expect(sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" +
|
||||||
"mkdir -p /home/users/testuser\n" +
|
"mkdir -p /home/users\n" +
|
||||||
"useradd -s /bin/bash -d /home/users/testuser testuser\n" +
|
"useradd -s /bin/bash -m -d /home/users/testuser testuser\n" +
|
||||||
"chown -R testuser /home/users/testuser\n" +
|
"chown -R testuser /home/users/testuser\n" +
|
||||||
"RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("done", null, 0));
|
"RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(new ExecResponse("done", null, 0));
|
||||||
sshClient.disconnect();
|
sshClient.disconnect();
|
||||||
|
|
|
@ -32,7 +32,7 @@ import com.google.common.collect.Multimap;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class SaveHttpResponseTo extends InterpretableStatement {
|
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");
|
throw new UnsupportedOperationException("windows not yet implemented");
|
||||||
String homeDir = defaultHome + "{fs}" + login;
|
String homeDir = defaultHome + "{fs}" + login;
|
||||||
ImmutableList.Builder<Statement> statements = ImmutableList.<Statement> builder();
|
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();
|
ImmutableMap.Builder<String, String> userAddOptions = ImmutableMap.<String, String> builder();
|
||||||
userAddOptions.put("-s", shell);
|
userAddOptions.put("-s", shell);
|
||||||
|
@ -176,6 +177,7 @@ public class UserAdd implements Statement {
|
||||||
userAddOptions.put("-G", Joiner.on(',').join(groups));
|
userAddOptions.put("-G", Joiner.on(',').join(groups));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
userAddOptions.put("-m", "");
|
||||||
userAddOptions.put("-d", homeDir);
|
userAddOptions.put("-d", homeDir);
|
||||||
if (password != null) {
|
if (password != null) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -33,41 +33,41 @@ public class UserAddTest {
|
||||||
|
|
||||||
public void testUNIX() {
|
public void testUNIX() {
|
||||||
assertEquals(UserAdd.builder().login("me").build().render(OsFamily.UNIX),
|
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() {
|
public void testWithBaseUNIX() {
|
||||||
assertEquals(UserAdd.builder().login("me").defaultHome("/export/home").build().render(OsFamily.UNIX),
|
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() {
|
public void testWithGroupUNIX() {
|
||||||
assertEquals(UserAdd.builder().login("me").group("wheel").build().render(OsFamily.UNIX),
|
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() {
|
public void testWithGroupsUNIX() {
|
||||||
assertEquals(UserAdd.builder().login("me").groups(ImmutableList.of("wheel", "candy")).build().render(
|
assertEquals(UserAdd.builder().login("me").groups(ImmutableList.of("wheel", "candy")).build().render(
|
||||||
OsFamily.UNIX),
|
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() {
|
public void testWithPasswordUNIX() {
|
||||||
String userAdd = UserAdd.builder().login("me").password("foo").group("wheel").build().render(OsFamily.UNIX);
|
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;
|
assert userAdd.endsWith("' me\nchown -R me /home/users/me\n") : userAdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithSshAuthorizedKeyUNIX() {
|
public void testWithSshAuthorizedKeyUNIX() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
UserAdd.builder().login("me").authorizeRSAPublicKey("rsapublickey").build().render(OsFamily.UNIX),
|
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() {
|
public void testWithSshInstalledKeyUNIX() {
|
||||||
assertEquals(
|
assertEquals(
|
||||||
UserAdd.builder().login("me").installRSAPrivateKey("rsaprivate").build().render(OsFamily.UNIX),
|
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)
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
|
|
@ -4,9 +4,9 @@ root ALL = (ALL) ALL
|
||||||
%wheel ALL = (ALL) NOPASSWD:ALL
|
%wheel ALL = (ALL) NOPASSWD:ALL
|
||||||
END_OF_FILE
|
END_OF_FILE
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users/foo
|
mkdir -p /home/users
|
||||||
groupadd -f wheel
|
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
|
mkdir -p /home/users/foo/.ssh
|
||||||
cat >> /home/users/foo/.ssh/authorized_keys <<'END_OF_FILE'
|
cat >> /home/users/foo/.ssh/authorized_keys <<'END_OF_FILE'
|
||||||
fooPublicKey
|
fooPublicKey
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mkdir -p /home/users/defaultAdminUsername
|
mkdir -p /home/users
|
||||||
useradd -s /bin/bash -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
useradd -s /bin/bash -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
||||||
mkdir -p /home/users/defaultAdminUsername/.ssh
|
mkdir -p /home/users/defaultAdminUsername/.ssh
|
||||||
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
|
@ -4,9 +4,9 @@ root ALL = (ALL) ALL
|
||||||
%wheel ALL = (ALL) NOPASSWD:ALL
|
%wheel ALL = (ALL) NOPASSWD:ALL
|
||||||
END_OF_FILE
|
END_OF_FILE
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users/defaultAdminUsername
|
mkdir -p /home/users
|
||||||
groupadd -f wheel
|
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
|
mkdir -p /home/users/defaultAdminUsername/.ssh
|
||||||
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
Loading…
Reference in New Issue