From 4aa8e1055adcb2d91c652b1bc7e0e8946926561f Mon Sep 17 00:00:00 2001 From: Andrew Bayer Date: Wed, 11 Jul 2012 16:42:31 -0700 Subject: [PATCH] Issue #1020. Fill in GECOS field when creating a user. We'll just use the username there as well for now. --- .../callables/RunScriptOnNodeUsingSshTest.java | 2 +- .../src/test/resources/initscript_with_java.sh | 2 +- .../test/resources/initscript_with_jboss.sh | 2 +- .../test/resources/runscript_adminUpdate.sh | 2 +- .../statements/login/UserAdd.java | 3 +++ .../statements/login/UserAddTest.java | 18 +++++++++--------- .../test/resources/test_adminaccess_flipped.sh | 2 +- .../test/resources/test_adminaccess_params.sh | 2 +- .../resources/test_adminaccess_plainuser.sh | 2 +- .../resources/test_adminaccess_standard.sh | 2 +- 10 files changed, 20 insertions(+), 17 deletions(-) diff --git a/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java b/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java index 2a6bed2249..0aa383c480 100644 --- a/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java +++ b/compute/src/test/java/org/jclouds/compute/callables/RunScriptOnNodeUsingSshTest.java @@ -127,7 +127,7 @@ public class RunScriptOnNodeUsingSshTest { expect(sshClient.getHostAddress()).andReturn("somewhere.example.com"); expect( 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( new ExecResponse("done", null, 0)); sshClient.disconnect(); diff --git a/compute/src/test/resources/initscript_with_java.sh b/compute/src/test/resources/initscript_with_java.sh index 8736539720..936b3ec5f7 100644 --- a/compute/src/test/resources/initscript_with_java.sh +++ b/compute/src/test/resources/initscript_with_java.sh @@ -202,7 +202,7 @@ END_OF_JCLOUDS_SCRIPT chmod 0440 /etc/sudoers mkdir -p /home/users 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 cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' publicKey diff --git a/compute/src/test/resources/initscript_with_jboss.sh b/compute/src/test/resources/initscript_with_jboss.sh index cf88c7512c..5101010a90 100644 --- a/compute/src/test/resources/initscript_with_jboss.sh +++ b/compute/src/test/resources/initscript_with_jboss.sh @@ -202,7 +202,7 @@ END_OF_JCLOUDS_SCRIPT chmod 0440 /etc/sudoers mkdir -p /home/users 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 cat >> /home/users/web/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' publicKey diff --git a/compute/src/test/resources/runscript_adminUpdate.sh b/compute/src/test/resources/runscript_adminUpdate.sh index f239e40061..c9c7791e12 100644 --- a/compute/src/test/resources/runscript_adminUpdate.sh +++ b/compute/src/test/resources/runscript_adminUpdate.sh @@ -91,7 +91,7 @@ END_OF_JCLOUDS_SCRIPT chmod 0440 /etc/sudoers mkdir -p /over/ridden 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 cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' publicKey diff --git a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java index aa76afb100..b6a76b098b 100644 --- a/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java +++ b/scriptbuilder/src/main/java/org/jclouds/scriptbuilder/statements/login/UserAdd.java @@ -186,6 +186,9 @@ public class UserAdd implements Statement { statements.add(Statements.exec("{md} " + homeDir.substring(0, homeDir.lastIndexOf('/')))); ImmutableMap.Builder userAddOptions = ImmutableMap.builder(); + // Include the username as the full name for now. + userAddOptions.put("-c", login); + userAddOptions.put("-s", shell); if (groups.size() > 0) { for (String group : groups) diff --git a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java index fd11d75528..27e2ac1f6c 100644 --- a/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java +++ b/scriptbuilder/src/test/java/org/jclouds/scriptbuilder/statements/login/UserAddTest.java @@ -33,51 +33,51 @@ public class UserAddTest { public void testUNIX() { 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() { 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() { 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() { assertEquals(UserAdd.builder().login("me").groups(ImmutableList.of("wheel", "candy")).build().render( 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() { 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; } public void testWithSshAuthorizedKeyUNIX() { assertEquals( 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() { assertEquals( 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() { assertEquals(UserAdd.builder().login("me").home("/myhome/myme").build().render( 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( 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) diff --git a/scriptbuilder/src/test/resources/test_adminaccess_flipped.sh b/scriptbuilder/src/test/resources/test_adminaccess_flipped.sh index bfe8478fc1..b6fe4a94da 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_flipped.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_flipped.sh @@ -6,7 +6,7 @@ END_OF_FILE chmod 0440 /etc/sudoers mkdir -p /home/users 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 cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<'END_OF_FILE' publicKey diff --git a/scriptbuilder/src/test/resources/test_adminaccess_params.sh b/scriptbuilder/src/test/resources/test_adminaccess_params.sh index 2eed6fa609..123be324ce 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_params.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_params.sh @@ -5,7 +5,7 @@ END_OF_JCLOUDS_FILE chmod 0440 /etc/sudoers mkdir -p /over/ridden 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 cat >> /over/ridden/foo/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' fooPublicKey diff --git a/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh b/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh index 68325f9e01..f954fa83d1 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_plainuser.sh @@ -1,5 +1,5 @@ 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 cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' publicKey diff --git a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh index b567afcd42..5430a4ee41 100644 --- a/scriptbuilder/src/test/resources/test_adminaccess_standard.sh +++ b/scriptbuilder/src/test/resources/test_adminaccess_standard.sh @@ -5,7 +5,7 @@ END_OF_JCLOUDS_FILE chmod 0440 /etc/sudoers mkdir -p /home/users 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 cat >> /home/users/defaultAdminUsername/.ssh/authorized_keys <<-'END_OF_JCLOUDS_FILE' publicKey