Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JENKINS-50181] add trailing newline to private keys entered in web UI to appease ssh-add #33

Merged
merged 1 commit into from
Jul 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public static class DirectEntryPrivateKeySource extends PrivateKeySource impleme
private final Secret privateKey;

public DirectEntryPrivateKeySource(String privateKey) {
this(Secret.fromString(privateKey));
this(Secret.fromString(privateKey.endsWith("\n") ? privateKey : privateKey + "\n"));
}

@DataBoundConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ public void readOldCredentials() throws Exception {
assertTrue(privateKey.endsWith(TESTKEY_END));
}

@Test
public void ensureDirectEntryHasTrailingNewline() throws Exception {
String key = (new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource("test")).getPrivateKey().toString();
assertEquals("test\n", key);
}

// TODO demonstrate that all private key sources are round-tripped in XStream

@Test
Expand Down