@Test public void shouldAddKey() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair(); ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath); int numOfKeys = user.getSSHKeys().size(); // operation String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, publicKey); // verifications assertThat(new SSHPublicKeyAssertion(key)) .hasName(keyName) .hasPublicKey(publicKey.getPublicKey()) .isType(publicKey.getKeyType()); List<IOpenShiftSSHKey> keys = user.getSSHKeys(); assertThat(keys.size()).isEqualTo(numOfKeys + 1); IOpenShiftSSHKey keyInList = SSHKeyTestUtils.getKey(keyName, keys); assertThat(key).isEqualTo(keyInList); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }
@Test public void shouldRefreshKeys() throws Exception { IOpenShiftSSHKey key = null; int originalNumOfKeys = user.getSSHKeys().size(); try { // pre-conditions String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair(); IUser user = new TestConnectionBuilder() .defaultCredentials() .disableSSLCertificateChecks() .create() .getUser(); // operation assertThat(user.getSSHKeys().size()).isEqualTo(originalNumOfKeys); String newKeyName = SSHKeyTestUtils.createRandomKeyName(); user.addSSHKey(newKeyName, new SSHPublicKey(publicKeyPath)); // verification assertThat(user.getSSHKeys().size()).isEqualTo(originalNumOfKeys + 1); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }
@Test public void shouldReturnExistingKeys() throws HttpClientException, Throwable { // pre-conditions // operation List<IOpenShiftSSHKey> sshKeys = user.getSSHKeys(); // verifications assertThat(sshKeys).isNotNull(); }
@Test public void shouldRemoveKeyByName() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair(); String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, new SSHPublicKey(publicKeyPath)); int numOfKeys = user.getSSHKeys().size(); // operation user.deleteKey(keyName); // verification assertThat(user.getSSHKeyByName(keyName)).isNull(); assertThat(user.getSSHKeys().size()).isEqualTo(numOfKeys - 1); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }