mirror of https://github.com/apache/jclouds.git
Merge pull request #711 from abayer/master
Issue #1020 - fill in GECOS field when creating users
This commit is contained in:
commit
07fa5528ca
|
@ -127,7 +127,7 @@ public class RunScriptOnNodeUsingSshTest {
|
||||||
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
|
expect(sshClient.getHostAddress()).andReturn("somewhere.example.com");
|
||||||
expect(
|
expect(
|
||||||
sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "mkdir -p /home/users\n"
|
sshClient.exec("sudo sh <<'RUN_SCRIPT_AS_ROOT_SSH'\n" + "mkdir -p /home/users\n"
|
||||||
+ "useradd -s /bin/bash -m -d /home/users/testuser testuser\n"
|
+ "useradd -c testuser -s /bin/bash -m -d /home/users/testuser testuser\n"
|
||||||
+ "chown -R testuser /home/users/testuser\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(
|
+ "chown -R testuser /home/users/testuser\n" + "RUN_SCRIPT_AS_ROOT_SSH\n")).andReturn(
|
||||||
new ExecResponse("done", null, 0));
|
new ExecResponse("done", null, 0));
|
||||||
sshClient.disconnect();
|
sshClient.disconnect();
|
||||||
|
|
|
@ -202,7 +202,7 @@ END_OF_JCLOUDS_SCRIPT
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users
|
mkdir -p /home/users
|
||||||
groupadd -f wheel
|
groupadd -f wheel
|
||||||
useradd -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(randompassword)' defaultAdminUsername
|
useradd -c defaultAdminUsername -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(randompassword)' defaultAdminUsername
|
||||||
mkdir -p /home/users/defaultAdminUsername/.ssh
|
mkdir -p /home/users/defaultAdminUsername/.ssh
|
||||||
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
|
@ -202,7 +202,7 @@ END_OF_JCLOUDS_SCRIPT
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users
|
mkdir -p /home/users
|
||||||
groupadd -f wheel
|
groupadd -f wheel
|
||||||
useradd -s /bin/bash -g wheel -m -d /home/users/web -p 'crypt(randompassword)' web
|
useradd -c web -s /bin/bash -g wheel -m -d /home/users/web -p 'crypt(randompassword)' web
|
||||||
mkdir -p /home/users/web/.ssh
|
mkdir -p /home/users/web/.ssh
|
||||||
cat >> /home/users/web/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
cat >> /home/users/web/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
|
@ -91,7 +91,7 @@ END_OF_JCLOUDS_SCRIPT
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /over/ridden
|
mkdir -p /over/ridden
|
||||||
groupadd -f wheel
|
groupadd -f wheel
|
||||||
useradd -s /bin/bash -g wheel -m -d /over/ridden/foo -p 'crypt(randompassword)' foo
|
useradd -c foo -s /bin/bash -g wheel -m -d /over/ridden/foo -p 'crypt(randompassword)' foo
|
||||||
mkdir -p /over/ridden/foo/.ssh
|
mkdir -p /over/ridden/foo/.ssh
|
||||||
cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
|
@ -186,6 +186,9 @@ public class UserAdd implements Statement {
|
||||||
statements.add(Statements.exec("{md} " + homeDir.substring(0, homeDir.lastIndexOf('/'))));
|
statements.add(Statements.exec("{md} " + homeDir.substring(0, homeDir.lastIndexOf('/'))));
|
||||||
|
|
||||||
ImmutableMap.Builder<String, String> userAddOptions = ImmutableMap.builder();
|
ImmutableMap.Builder<String, String> userAddOptions = ImmutableMap.builder();
|
||||||
|
// Include the username as the full name for now.
|
||||||
|
userAddOptions.put("-c", login);
|
||||||
|
|
||||||
userAddOptions.put("-s", shell);
|
userAddOptions.put("-s", shell);
|
||||||
if (groups.size() > 0) {
|
if (groups.size() > 0) {
|
||||||
for (String group : groups)
|
for (String group : groups)
|
||||||
|
|
|
@ -33,51 +33,51 @@ 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\nuseradd -s /bin/bash -m -d /home/users/me me\nchown -R me /home/users/me\n");
|
"mkdir -p /home/users\nuseradd -c me -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\nuseradd -s /bin/bash -m -d /export/home/me me\nchown -R me /export/home/me\n");
|
"mkdir -p /export/home\nuseradd -c me -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\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me me\nchown -R me /home/users/me\n");
|
"mkdir -p /home/users\ngroupadd -f wheel\nuseradd -c me -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\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");
|
"mkdir -p /home/users\ngroupadd -f wheel\ngroupadd -f candy\nuseradd -c me -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\ngroupadd -f wheel\nuseradd -s /bin/bash -g wheel -m -d /home/users/me -p '$6$") : userAdd;
|
assert userAdd.startsWith("mkdir -p /home/users\ngroupadd -f wheel\nuseradd -c me -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\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_JCLOUDS_FILE'\n\trsapublickey\nEND_OF_JCLOUDS_FILE\nchmod 600 /home/users/me/.ssh/authorized_keys\nchown -R me /home/users/me\n");
|
"mkdir -p /home/users\nuseradd -c me -s /bin/bash -m -d /home/users/me me\nmkdir -p /home/users/me/.ssh\ncat >> /home/users/me/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'\n\trsapublickey\nEND_OF_JCLOUDS_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\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_JCLOUDS_FILE'\n\trsaprivate\nEND_OF_JCLOUDS_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n");
|
"mkdir -p /home/users\nuseradd -c me -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_JCLOUDS_FILE'\n\trsaprivate\nEND_OF_JCLOUDS_FILE\nchmod 600 /home/users/me/.ssh/id_rsa\nchown -R me /home/users/me\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithHomeUNIX() {
|
public void testWithHomeUNIX() {
|
||||||
assertEquals(UserAdd.builder().login("me").home("/myhome/myme").build().render(
|
assertEquals(UserAdd.builder().login("me").home("/myhome/myme").build().render(
|
||||||
OsFamily.UNIX),
|
OsFamily.UNIX),
|
||||||
"mkdir -p /myhome\nuseradd -s /bin/bash -m -d /myhome/myme me\nchown -R me /myhome/myme\n");
|
"mkdir -p /myhome\nuseradd -c me -s /bin/bash -m -d /myhome/myme me\nchown -R me /myhome/myme\n");
|
||||||
|
|
||||||
assertEquals(UserAdd.builder().login("me").home("/myhome/myme").defaultHome("/ignoreddefault").build().render(
|
assertEquals(UserAdd.builder().login("me").home("/myhome/myme").defaultHome("/ignoreddefault").build().render(
|
||||||
OsFamily.UNIX),
|
OsFamily.UNIX),
|
||||||
"mkdir -p /myhome\nuseradd -s /bin/bash -m -d /myhome/myme me\nchown -R me /myhome/myme\n");
|
"mkdir -p /myhome\nuseradd -c me -s /bin/bash -m -d /myhome/myme me\nchown -R me /myhome/myme\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expectedExceptions = UnsupportedOperationException.class)
|
@Test(expectedExceptions = UnsupportedOperationException.class)
|
||||||
|
|
|
@ -6,7 +6,7 @@ END_OF_FILE
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users
|
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 -c defaultAdminUsername -s /bin/bash -g wheel -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
|
||||||
|
|
|
@ -5,7 +5,7 @@ END_OF_JCLOUDS_FILE
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /over/ridden
|
mkdir -p /over/ridden
|
||||||
groupadd -f wheel
|
groupadd -f wheel
|
||||||
useradd -s /bin/bash -g wheel -m -d /over/ridden/foo -p 'crypt(bar)' foo
|
useradd -c foo -s /bin/bash -g wheel -m -d /over/ridden/foo -p 'crypt(bar)' foo
|
||||||
mkdir -p /over/ridden/foo/.ssh
|
mkdir -p /over/ridden/foo/.ssh
|
||||||
cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
fooPublicKey
|
fooPublicKey
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
mkdir -p /home/users
|
mkdir -p /home/users
|
||||||
useradd -s /bin/bash -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
useradd -c defaultAdminUsername -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_JCLOUDS_FILE'
|
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
|
@ -5,7 +5,7 @@ END_OF_JCLOUDS_FILE
|
||||||
chmod 0440 /etc/sudoers
|
chmod 0440 /etc/sudoers
|
||||||
mkdir -p /home/users
|
mkdir -p /home/users
|
||||||
groupadd -f wheel
|
groupadd -f wheel
|
||||||
useradd -s /bin/bash -g wheel -m -d /home/users/defaultAdminUsername -p 'crypt(0)' defaultAdminUsername
|
useradd -c defaultAdminUsername -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_JCLOUDS_FILE'
|
cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE'
|
||||||
publicKey
|
publicKey
|
||||||
|
|
Loading…
Reference in New Issue