Skip to content

Commit

Permalink
fixes #6941: fixed load of ssh keyProvider from test resources
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek authored and jamesnetherton committed Jan 28, 2025
1 parent 859ea67 commit db54573
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
*/
package org.apache.camel.quarkus.component.ssh.it;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -79,8 +83,16 @@ public Map<String, String> start() {

sshd = SshServer.setUpDefaultServer();
sshd.setPort(edPort);
sshd.setKeyPairProvider(new FileKeyPairProvider(
Paths.get(Thread.currentThread().getContextClassLoader().getResource("edDSA/key_ed25519.pem").toURI())));

File tmpFile = File.createTempFile("key_ed25519-", ".pem");
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("edDSA/key_ed25519.pem")) {
Files.write(tmpFile.toPath(), in.readAllBytes());
sshd.setKeyPairProvider(new FileKeyPairProvider(tmpFile.toPath()));
} catch (NullPointerException | IOException e) {
String message = "An issue occurred while loading key: edDSA/key_ed25519.pem";
throw new RuntimeException(message, e);
}

sshd.setCommandFactory(new TestEchoCommandFactory());
sshd.setPasswordAuthenticator((username, password, session) -> true);
sshd.setPublickeyAuthenticator((username, key, session) -> true);
Expand Down

0 comments on commit db54573

Please sign in to comment.