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

SSH key support #16

Open
natrem opened this issue Nov 13, 2018 · 2 comments
Open

SSH key support #16

natrem opened this issue Nov 13, 2018 · 2 comments

Comments

@natrem
Copy link

natrem commented Nov 13, 2018

The rule is working fine but I'd like to use it also with an identity file.
Would you mind a PR on this topic?

The aim is to support authentication via an SSH public/private key pair.

If it's ok for you then there is already an implementation in #15

@Assafkalfa
Copy link

Assafkalfa commented Feb 10, 2022

I know it's a little old (and using junit4) but I find a way to use a public key:

download the source (only one file) from the git and add to 'startServer' after 'setPort':

SimpleGeneratorHostKeyProvider keyPairProvider = hostKeyPath != null ? new SimpleGeneratorHostKeyProvider(hostKeyPath)
                : new SimpleGeneratorHostKeyProvider();
server.setKeyPairProvider(keyPairProvider);
server.setPublickeyAuthenticator(new AuthorizedKeysAuthenticator(new File(hostKeyPath.toString())));

of course, add private Path hostKeyPath = null in the variables and a setter:

public FakeSftpServerRule setHostKeyPath(Path hostKeyPath) {
       this.hostKeyPath = hostKeyPath;
       if (server != null)
           restartServer();
       return this;
}

@natrem
Copy link
Author

natrem commented Feb 10, 2022

@Assafkalfa I do not remember how the code under test was working but the test was implemented quite simply (based on the code in PR #15 :

	@Rule
	public final FakeSftpServerRule sftpServer = new FakeSftpServerRule();

	@Test
	public void should_send_file() throws Exception {
		// add identity
	        Path authorizedKeysPath = Paths.get(FtrServiceTest.class.getResource("/unit-test-user.pub").toURI());
	        sftpServer.addIdentity("jon.snow", authorizedKeysPath);
		
		// call code under test

		//check
		assertTrue("remote file not found", sftpServer.existsFile("/666_myfile.txt"));
	}

It was a one time usage so I cannot help you on other usage of this component.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants