@Test public void shouldUpdateKeyTypeAndPublicKey() throws Exception { IOpenShiftSSHKey key = null; try { // pre-conditions String publicKeyPath = createRandomTempFile().getAbsolutePath(); String privateKeyPath = createRandomTempFile().getAbsolutePath(); SSHKeyTestUtils.createDsaKeyPair(publicKeyPath, privateKeyPath); ISSHPublicKey publicKey = new SSHPublicKey(publicKeyPath); assertThat(publicKey.getKeyType()).isEqualTo(SSHKeyType.SSH_DSA); String keyName = SSHKeyTestUtils.createRandomKeyName(); key = user.addSSHKey(keyName, publicKey); SSHKeyPair keyPair = SSHKeyPair.create( SSHKeyType.SSH_RSA, SSHKeyTestUtils.DEFAULT_PASSPHRASE, privateKeyPath, publicKeyPath); // operation key.setKeyType(SSHKeyType.SSH_RSA, keyPair.getPublicKey()); // verification assertThat(key.getKeyType()).isEqualTo(SSHKeyType.SSH_RSA); assertThat(key.getPublicKey()).isEqualTo(keyPair.getPublicKey()); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }
@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 shouldReturnKeyForPublicKey() 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 keyByPublicKey = user.getSSHKeyByPublicKey(publicKey.getPublicKey()); // verifications assertThat(key).isEqualTo(keyByPublicKey); } finally { SSHKeyTestUtils.silentlyDestroyKey(key); } }