From 202ab7b2ff378c0a2ddb614b72a3d497d25b380c Mon Sep 17 00:00:00 2001 From: Joseph Petersen Date: Thu, 25 Apr 2019 15:22:32 +0200 Subject: [PATCH] update tests, FileOnMasterPrivateKeySource is deprecated --- .../java/io/jenkins/plugins/casc/CredentialsTest.java | 11 ++++++++--- .../jenkins/plugins/casc/SystemCredentialsTest.java | 9 ++++----- .../io/jenkins/plugins/casc/SystemCredentialsTest.yml | 9 --------- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/integrations/src/test/java/io/jenkins/plugins/casc/CredentialsTest.java b/integrations/src/test/java/io/jenkins/plugins/casc/CredentialsTest.java index b8261a98bd..09218eb43b 100644 --- a/integrations/src/test/java/io/jenkins/plugins/casc/CredentialsTest.java +++ b/integrations/src/test/java/io/jenkins/plugins/casc/CredentialsTest.java @@ -31,9 +31,14 @@ public void testGlobalScopedCredentials() { List creds2 = CredentialsProvider.lookupCredentials(BasicSSHUserPrivateKey.class,Jenkins.getInstanceOrNull(), null, Collections.emptyList()); assertThat(creds2.size(), is(1)); - assertEquals("agentuser", creds2.get(0).getUsername()); - assertEquals("password", creds2.get(0).getPassphrase().getPlainText()); - assertEquals("ssh private key used to connect ssh slaves", creds2.get(0).getDescription()); + BasicSSHUserPrivateKey basicSSHUserPrivateKey = creds2.get(0); + assertEquals("agentuser", basicSSHUserPrivateKey.getUsername()); + assertEquals("password", basicSSHUserPrivateKey.getPassphrase().getPlainText()); + assertEquals("ssh private key used to connect ssh slaves", basicSSHUserPrivateKey.getDescription()); + assertThat(basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().size(), is(1)); + String directKey = basicSSHUserPrivateKey.getPrivateKeySource().getPrivateKeys().get(0); + assertThat(directKey, is("sp0ds9d+skkfjf")); + } diff --git a/integrations/src/test/java/io/jenkins/plugins/casc/SystemCredentialsTest.java b/integrations/src/test/java/io/jenkins/plugins/casc/SystemCredentialsTest.java index ec99126273..ca5cb2276d 100644 --- a/integrations/src/test/java/io/jenkins/plugins/casc/SystemCredentialsTest.java +++ b/integrations/src/test/java/io/jenkins/plugins/casc/SystemCredentialsTest.java @@ -73,14 +73,13 @@ public void configure_system_credentials() throws Exception { List sshPrivateKeys = CredentialsProvider.lookupCredentials( BasicSSHUserPrivateKey.class, jenkins, ACL.SYSTEM, Collections.emptyList() ); - assertThat(sshPrivateKeys, hasSize(2)); - final BasicSSHUserPrivateKey ssh_with_passphrase = sshPrivateKeys.stream() - .filter(k -> k.getId().equals("ssh_with_passphrase_provided")) - .findFirst().orElseThrow(AssertionError::new); + assertThat(sshPrivateKeys, hasSize(1)); + + final BasicSSHUserPrivateKey ssh_with_passphrase = sshPrivateKeys.get(0); assertThat(ssh_with_passphrase.getPassphrase().getPlainText(), equalTo("ABCD")); final DirectEntryPrivateKeySource source = (DirectEntryPrivateKeySource) ssh_with_passphrase.getPrivateKeySource(); - assertThat(source.getPrivateKey(), equalTo("s3cr3t")); + assertThat(source.getPrivateKey().getPlainText(), equalTo("s3cr3t")); // credentials should not appear in plain text in log diff --git a/integrations/src/test/resources/io/jenkins/plugins/casc/SystemCredentialsTest.yml b/integrations/src/test/resources/io/jenkins/plugins/casc/SystemCredentialsTest.yml index 0397e20d19..7d28c6b5a4 100644 --- a/integrations/src/test/resources/io/jenkins/plugins/casc/SystemCredentialsTest.yml +++ b/integrations/src/test/resources/io/jenkins/plugins/casc/SystemCredentialsTest.yml @@ -23,15 +23,6 @@ credentials: keyStoreSource: fileOnMaster: keyStoreFile: /docker/secret/id_rsa - - basicSSHUserPrivateKey: - scope: SYSTEM - id: ssh_with_passphrase - username: ssh_root - passphrase: ${SSH_KEY_PASSWORD} - description: "SSH passphrase with private key file" - privateKeySource: - FileOnMasterPrivateKeySource: - privateKeyFile: /docker/secret/id_rsa_2 - basicSSHUserPrivateKey: scope: SYSTEM id: ssh_with_passphrase_provided