Skip to content

Commit

Permalink
update tests, FileOnMasterPrivateKeySource is deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
jetersen committed Apr 25, 2019
1 parent 4a0d199 commit 202ab7b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ public void testGlobalScopedCredentials() {

List<BasicSSHUserPrivateKey> 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"));

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,13 @@ public void configure_system_credentials() throws Exception {
List<BasicSSHUserPrivateKey> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 202ab7b

Please sign in to comment.