fix and test for 682, disallowing root as the AdminAccess target

This commit is contained in:
Alex Heneveld 2011-10-20 14:58:41 +01:00
parent 9fc33dc120
commit 181bc4ead8
2 changed files with 15 additions and 0 deletions

View File

@ -35,6 +35,7 @@ import org.jclouds.scriptbuilder.domain.StatementList;
import org.jclouds.scriptbuilder.statements.ssh.SshStatements; import org.jclouds.scriptbuilder.statements.ssh.SshStatements;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Supplier; import com.google.common.base.Supplier;
import com.google.common.base.Throwables; import com.google.common.base.Throwables;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
@ -344,6 +345,8 @@ public class AdminAccess implements Statement {
if (family == OsFamily.WINDOWS) if (family == OsFamily.WINDOWS)
throw new UnsupportedOperationException("windows not yet implemented"); throw new UnsupportedOperationException("windows not yet implemented");
checkNotNull(config.getAdminUsername(), "adminUsername"); checkNotNull(config.getAdminUsername(), "adminUsername");
Preconditions.checkArgument(!"root".equals(config.getAdminUsername()), "cannot create admin user 'root'; " +
"ensure jclouds is not running as root, or specify an explicit non-root username in AdminAccess");
checkNotNull(config.getAdminPassword(), "adminPassword"); checkNotNull(config.getAdminPassword(), "adminPassword");
checkNotNull(config.getAdminPublicKey(), "adminPublicKey"); checkNotNull(config.getAdminPublicKey(), "adminPublicKey");
checkNotNull(config.getAdminPrivateKey(), "adminPrivateKey"); checkNotNull(config.getAdminPrivateKey(), "adminPrivateKey");

View File

@ -76,4 +76,16 @@ public class AdminAccessTest {
public void testCreateWheelWindowsNotSupported() { public void testCreateWheelWindowsNotSupported() {
AdminAccess.standard().init(TestConfiguration.INSTANCE).render(OsFamily.WINDOWS); AdminAccess.standard().init(TestConfiguration.INSTANCE).render(OsFamily.WINDOWS);
} }
@Test(expectedExceptions=IllegalArgumentException.class)
//for issue 682
public void testRootNotAllowed() throws IOException {
TestConfiguration.INSTANCE.reset();
try {
AdminAccess.builder().adminUsername("root").build().init(TestConfiguration.INSTANCE).render(OsFamily.UNIX);
} finally {
TestConfiguration.INSTANCE.reset();
}
}
} }