@Test public void shouldReturnKeyForName() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair(); ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath); // operation String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, publicKey); IOpenShiftSSHKey keyByName = user.getSSHKeyByName(keyName); // verifications assertThat(key).isEqualTo(keyByName); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }
@Test public void shouldDestroyKey() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = SSHKeyTestUtils.createDsaKeyPair(); String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, new SSHPublicKey(publicKeyPath)); // operation key.destroy(); key = null; // verification assertThat(user.getSSHKeyByName(keyName)).isNull(); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }
@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); } }
@Test public void shouldUpdatePublicKey() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = createRandomTempFile().getAbsolutePath(); String privateKeyPath = createRandomTempFile().getAbsolutePath(); SSHKeyPair keyPair = SSHKeyPair.create( SSHKeyType.SSH_RSA, SSHKeyTestUtils.DEFAULT_PASSPHRASE, privateKeyPath, publicKeyPath); String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, keyPair); // operation String publicKey = SSHKeyPair.create( SSHKeyType.SSH_RSA, SSHKeyTestUtils.DEFAULT_PASSPHRASE, privateKeyPath, publicKeyPath) .getPublicKey(); key.setPublicKey(publicKey); // verification assertThat(key.getPublicKey()).isEqualTo(publicKey); IOpenShiftSSHKey openshiftKey = user.getSSHKeyByName(keyName); assertThat(new SSHPublicKeyAssertion(openshiftKey)) .hasName(keyName) .hasPublicKey(publicKey) .isType(openshiftKey.getKeyType()); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }