public static Account createTestAccount(CloudStackGlobalApi client, String prefix) { return client.getAccountApi().createAccount(prefix + "-account", Account.Type.USER, "dummy@example.com", "First", "Last", base16().lowerCase().encode(md5().hashString("password", UTF_8).asBytes())); }
public String findDomainIdForAccount(String accountName) { Set<Account> accounts = client.getAccountClient().listAccounts(ListAccountsOptions.Builder.name(accountName)); Account account = Iterables.getOnlyElement(accounts, null); if (account == null) { throw new IllegalStateException("No account found in "+loc+"} with name "+accountName); } return account.getDomainId(); }
@Test public void testCreateAndRemoveAccount() { skipIfNotGlobalAdmin(); Account account = null; try { account = createTestAccount(globalAdminClient, prefix); assertNotNull(account); assertEquals(account.getName(), prefix + "-account"); assertEquals(account.getType(), Account.Type.USER); Account updated = globalAdminClient.getAccountApi().updateAccount( account.getName(), account.getDomainId(), prefix + "-account-2"); assertNotNull(updated); assertEquals(updated.getName(), prefix + "-account-2"); } finally { if (account != null) { globalAdminClient.getAccountApi().deleteAccount(account.getId()); } } }
@Test public void testEnableDisableAccount() { skipIfNotGlobalAdmin(); Account testAccount = null; try { testAccount = createTestAccount(globalAdminClient, prefix); AsyncCreateResponse response = domainAdminClient.getAccountApi() .disableAccount(testAccount.getName(), testAccount.getDomainId(), false); assertNotNull(response); assertTrue(adminJobComplete.apply(response.getJobId())); AsyncJob<Account> job = domainAdminClient.getAsyncJobApi().getAsyncJob(response.getJobId()); assertEquals(job.getResult().getState(), Account.State.DISABLED); Account updated = domainAdminClient.getAccountApi() .enableAccount(testAccount.getName(), testAccount.getDomainId()); assertNotNull(updated); assertEquals(updated.getState(), Account.State.ENABLED); } finally { if (testAccount != null) { globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } } }
@Test public void testCreateUser() { skipIfNotGlobalAdmin(); Account testAccount = createTestAccount(globalAdminClient, prefix); User testUser = null; try { testUser = createTestUser(globalAdminClient, testAccount, prefix); assertNotNull(testUser); assertEquals(testUser.getName(), prefix + "-user"); assertEquals(testUser.getAccount(), prefix + "-account"); User updatedUser = globalAdminClient.getUserClient() .updateUser(testUser.getId(), userName(prefix + "-user-2")); assertNotNull(updatedUser); assertEquals(updatedUser.getName(), prefix + "-user-2"); ApiKeyPair apiKeys = globalAdminClient.getUserClient() .registerUserKeys(updatedUser.getId()); assertNotNull(apiKeys.getApiKey()); assertNotNull(apiKeys.getSecretKey()); checkAuthAsUser(apiKeys); } finally { if (testUser != null) { globalAdminClient.getUserClient().deleteUser(testUser.getId()); } globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } }
globalAdminClient.getAccountApi().deleteAccount(testAccount.getId());
@Test public void testCreateContextUsingUserAndPasswordAuthentication() { skipIfNotGlobalAdmin(); Account testAccount = null; User testUser = null; String prefix = this.prefix + "-session"; try { testAccount = createTestAccount(globalAdminClient, prefix); testUser = createTestUser(globalAdminClient, testAccount, prefix); String expectedUsername = prefix + "-user"; assertEquals(testUser.getName(), expectedUsername); checkLoginAsTheNewUser(expectedUsername); ApiKeyPair expected = globalAdminClient.getUserClient().registerUserKeys(testUser.getId()); ApiKeyPair actual = ApiKeyPairs.loginToEndpointAsUsernameInDomainWithPasswordAndReturnApiKeyPair( URI.create(endpoint), prefix + "-user", "password", ""); assertEquals(actual, expected); } finally { if (testUser != null) globalAdminClient.getUserClient().deleteUser(testUser.getId()); if (testAccount != null) globalAdminClient.getAccountApi().deleteAccount(testAccount.getId()); } }