diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2020-06-10 10:14:28 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2020-06-10 10:33:50 +0200 |
commit | 4887894ffd637030a311ca8d60b78515b1a5cf35 (patch) | |
tree | a890edb80b54f5c5078a10b938b37f04ee12edca /org.eclipse.jgit.ssh.apache.test | |
parent | 629fa260c03a54cac35836010df34b565d13fe85 (diff) | |
parent | 0ec6e4b3d5becf0025dcf83e8b843c9c34043ba0 (diff) | |
download | jgit-4887894ffd637030a311ca8d60b78515b1a5cf35.tar.gz jgit-4887894ffd637030a311ca8d60b78515b1a5cf35.zip |
Merge branch 'master' into next
* master:
SimpleMergeTest: Clean up code style
Prepare 5.8.1-SNAPSHOT builds
Handle Fragment-Host declaration when updating version
JGit v5.8.0.202006091008-r
Prepare 5.9.0-SNAPSHOT builds
Handle Fragment-Host declaration when updating version
Add benchmark for strategies how to move a file
Add getter for unpackErrorHandler in ReceivePack
Upgrade maven-project-info-reports-plugin to 3.1.0
Upgrade maven-shade-plugin to 3.2.4
ObjectDirectoryInserter: Open FileOutputStream in try-with-resource
ObjectDirectoryInserter: Remove redundant 'throws' declarations
ObjectDirectory: Further clean up insertUnpackedObject
Add Git#shutdown for releasing resources held by JGit process
ApplyCommand: use context lines to determine hunk location
GPG: don't prompt for a passphrase for unprotected keys
Fix typo in org.eclipse.jgit.ssh.jsch.test MANIFEST
Fix ProtectedMembersInFinalClass warning flagged by error prone
Use version range to define fragment host bundle version
ObjectDirectory: Explicitly handle NoSuchFileException
ObjectDirectory: Fail immediately when atomic move is not supported
Fix jgit packaging
Fix InvalidInlineTag error flagged by error prone
Fix BadComparable error flagged by error prone
Add tests for RawTextComparator.WS_IGNORE_CHANGE.hash()
Update Orbit to R20200529191137 for final Eclipse release 2020-06
Organize manifest of org.eclipse.jgit.pgm
Do not include log4j implementation in jgit
Decouple JSch from JGit Core
Decouple BouncyCastle from JGit Core
Verify that the user home directory is valid
WindowCache: conditional JMX setup
RawTextComparator.WS_IGNORE_CHANGE must not compare whitespace
Revert "PackBitmapIndex: Not buffer inflated bitmap in
BasePackBitmapIndex"
Update jetty to 9.4.28.v20200408
Add 4.16 staging target platform
In-memory SSH keys for the "no files" sshd tests
Builder API to configure SshdSessionFactories
TransportHttp: abort on time-out or on SocketException
Ignore core.eol if core.autocrlf=input
Attributes: fix handling of text=auto in combination with eol
Bazel: Remove superfluous dependencies flagged by unused_deps
Log stack trace if CachingKeyPairProvider hits unexpected exception
Update Orbit to S20200519202422 and ant to 1.10.8
Include full IssuerFingerprint in GPG signature
Bazel: Fix src_sha1 of bcpg-jdk15on
Suppress API error for new method
BitmapIndex.Bitmap#retrieveCompressed
Fix wrong @since tags added in dcb0265
PackBitmapIndex: Set distance threshold
PackBitmapIndex: Not buffer inflated bitmap in BasePackBitmapIndex
PackBitmapIndex: Remove convertedBitmaps in the Remapper
PackBitmapIndex: Reduce memory usage in GC
PackBitmapIndex: Add AddToBitmapWithCacheFilter class
PackBitmapIndex: Add util methods and builder to BitmapCommit
PackBitmapIndex: Move BitmapCommit to a top-level class
Refactor: Make retriveCompressed an method of the Bitmap class
Fix downloading LFS Object fails behind proxy
Allow for using custom s3 host with lfs server
ReceivePack: adding IterativeConnectivityChecker
Moving transport/internal -> internal/transport
Fix error occurring during checkout
Change-Id: Ic11286e16ed6a72c6372297b310336dd040689d1
Diffstat (limited to 'org.eclipse.jgit.ssh.apache.test')
6 files changed, 173 insertions, 27 deletions
diff --git a/org.eclipse.jgit.ssh.apache.test/BUILD b/org.eclipse.jgit.ssh.apache.test/BUILD index 18a48dca09..b384464484 100644 --- a/org.eclipse.jgit.ssh.apache.test/BUILD +++ b/org.eclipse.jgit.ssh.apache.test/BUILD @@ -13,7 +13,7 @@ junit_tests( "//lib:sshd-osgi", "//lib:sshd-sftp", "//org.eclipse.jgit:jgit", + "//org.eclipse.jgit.junit.ssh:junit-ssh", "//org.eclipse.jgit.ssh.apache:ssh-apache", - "//org.eclipse.jgit.test:sshd-helpers", ], ) diff --git a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF index b69f89da6f..635ff75428 100644 --- a/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF +++ b/org.eclipse.jgit.ssh.apache.test/META-INF/MANIFEST.MF @@ -21,9 +21,9 @@ Import-Package: org.apache.sshd.client.config.hosts;version="[2.4.0,2.5.0)", org.eclipse.jgit.junit.ssh;version="[6.0.0,6.1.0)", org.eclipse.jgit.lib;version="[6.0.0,6.1.0)", org.eclipse.jgit.transport;version="[6.0.0,6.1.0)", - org.eclipse.jgit.transport.ssh;version="[6.0.0,6.1.0)", org.eclipse.jgit.transport.sshd;version="[6.0.0,6.1.0)", org.eclipse.jgit.util;version="[6.0.0,6.1.0)", org.junit;version="[4.13,5.0.0)", org.junit.experimental.theories;version="[4.13,5.0.0)", org.junit.runner;version="[4.13,5.0.0)" +Require-Bundle: org.hamcrest.core;bundle-version="[1.3.0,2.0.0)" diff --git a/org.eclipse.jgit.ssh.apache.test/pom.xml b/org.eclipse.jgit.ssh.apache.test/pom.xml index bcdb9af538..994fca1fc5 100644 --- a/org.eclipse.jgit.ssh.apache.test/pom.xml +++ b/org.eclipse.jgit.ssh.apache.test/pom.xml @@ -51,6 +51,12 @@ <dependency> <groupId>org.eclipse.jgit</groupId> + <artifactId>org.eclipse.jgit.junit.ssh</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>org.eclipse.jgit</groupId> <artifactId>org.eclipse.jgit.ssh.apache</artifactId> <version>${project.version}</version> </dependency> diff --git a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java index fa6450ef4d..bfee04219d 100644 --- a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java +++ b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/ApacheSshTest.java @@ -22,9 +22,9 @@ import java.util.List; import java.util.stream.Collectors; import org.apache.sshd.client.config.hosts.KnownHostEntry; import org.eclipse.jgit.api.errors.TransportException; +import org.eclipse.jgit.junit.ssh.SshTestBase; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.transport.SshSessionFactory; -import org.eclipse.jgit.transport.ssh.SshTestBase; import org.eclipse.jgit.util.FS; import org.junit.Test; import org.junit.experimental.theories.Theories; diff --git a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshBuilderTest.java b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshBuilderTest.java new file mode 100644 index 0000000000..9d64adc95e --- /dev/null +++ b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshBuilderTest.java @@ -0,0 +1,152 @@ +/* + * Copyright (C) 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.transport.sshd; + +import static org.junit.Assert.assertNotNull; + +import java.io.File; +import java.io.IOException; +import java.io.UncheckedIOException; +import java.net.InetSocketAddress; +import java.nio.file.Files; +import java.security.GeneralSecurityException; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.PublicKey; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; + +import org.apache.sshd.common.config.keys.KeyUtils; +import org.apache.sshd.common.keyprovider.KeyIdentityProvider; +import org.apache.sshd.common.session.SessionContext; +import org.apache.sshd.common.util.net.SshdSocketAddress; +import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.transport.CredentialsProvider; +import org.eclipse.jgit.transport.SshSessionFactory; +import org.eclipse.jgit.junit.ssh.SshTestHarness; +import org.eclipse.jgit.util.FS; +import org.junit.After; +import org.junit.Test; + +/** + * Test for using the SshdSessionFactory without files in ~/.ssh but with an + * in-memory setup, creating the factory via the builder API. + */ +public class NoFilesSshBuilderTest extends SshTestHarness { + + private PublicKey testServerKey; + + private KeyPair testUserKey; + + @Override + protected SshSessionFactory createSessionFactory() { + return new SshdSessionFactoryBuilder() // + .setConfigStoreFactory((h, f, u) -> null) + .setDefaultKeysProvider(f -> new KeyAuthenticator()) + .setServerKeyDatabase((h, s) -> new ServerKeyDatabase() { + + @Override + public List<PublicKey> lookup(String connectAddress, + InetSocketAddress remoteAddress, + Configuration config) { + return Collections.singletonList(testServerKey); + } + + @Override + public boolean accept(String connectAddress, + InetSocketAddress remoteAddress, + PublicKey serverKey, Configuration config, + CredentialsProvider provider) { + return KeyUtils.compareKeys(serverKey, testServerKey); + } + + }) // + .setPreferredAuthentications("publickey") + .setHomeDirectory(FS.DETECTED.userHome()) + .setSshDirectory(sshDir) // + .build(new JGitKeyCache()); + } + + private class KeyAuthenticator + implements KeyIdentityProvider, Iterable<KeyPair> { + + @Override + public Iterator<KeyPair> iterator() { + // Should not be called. The use of the Iterable interface in + // SshdSessionFactory.getDefaultKeys() made sense in sshd 2.0.0, + // but sshd 2.2.0 added the SessionContext, which although good + // (without it we couldn't check here) breaks the Iterable analogy. + // But we're stuck now with that interface for getDefaultKeys, and + // so this override throwing an exception is unfortunately needed. + throw new UnsupportedOperationException(); + } + + @Override + public Iterable<KeyPair> loadKeys(SessionContext session) + throws IOException, GeneralSecurityException { + if (!TEST_USER.equals(session.getUsername())) { + return Collections.emptyList(); + } + SshdSocketAddress remoteAddress = SshdSocketAddress + .toSshdSocketAddress(session.getRemoteAddress()); + switch (remoteAddress.getHostName()) { + case "localhost": + case "127.0.0.1": + return Collections.singletonList(testUserKey); + default: + return Collections.emptyList(); + } + } + } + + @After + public void cleanUp() { + testServerKey = null; + testUserKey = null; + } + + @Override + protected void installConfig(String... config) { + File configFile = new File(sshDir, Constants.CONFIG); + if (config != null) { + try { + Files.write(configFile.toPath(), Arrays.asList(config)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + } + } + + @Test + public void testCloneWithBuiltInKeys() throws Exception { + // This test should fail unless our in-memory setup is taken: no + // known_hosts file, a config that specifies a non-existing key, + // and the test is using a newly generated KeyPairs anyway. + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + testUserKey = generator.generateKeyPair(); + KeyPair hostKey = generator.generateKeyPair(); + server.addHostKey(hostKey, true); + testServerKey = hostKey.getPublic(); + assertNotNull(testServerKey); + assertNotNull(testUserKey); + server.setTestUserPublicKey(testUserKey.getPublic()); + cloneWith( + "ssh://" + TEST_USER + "@localhost:" + testPort + + "/doesntmatter", + new File(getTemporaryDirectory(), "cloned"), null, // + "Host localhost", // + "IdentityFile " + + new File(sshDir, "does_not_exist").getAbsolutePath()); + } + +} diff --git a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshTest.java b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshTest.java index 608f647bc5..7b6e508c31 100644 --- a/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshTest.java +++ b/org.eclipse.jgit.ssh.apache.test/tst/org/eclipse/jgit/transport/sshd/NoFilesSshTest.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Thomas Wolf <thomas.wolf@paranor.ch> and others + * Copyright (C) 2019, 2020 Thomas Wolf <thomas.wolf@paranor.ch> and others * * This program and the accompanying materials are made available under the * terms of the Eclipse Distribution License v. 1.0 which is available at @@ -10,33 +10,29 @@ package org.eclipse.jgit.transport.sshd; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.io.UncheckedIOException; import java.net.InetSocketAddress; import java.nio.file.Files; -import java.nio.file.Path; import java.security.GeneralSecurityException; import java.security.KeyPair; +import java.security.KeyPairGenerator; import java.security.PublicKey; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.config.keys.KeyUtils; import org.apache.sshd.common.keyprovider.KeyIdentityProvider; import org.apache.sshd.common.session.SessionContext; import org.apache.sshd.common.util.net.SshdSocketAddress; -import org.apache.sshd.common.util.security.SecurityUtils; +import org.eclipse.jgit.junit.ssh.SshTestHarness; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.transport.CredentialsProvider; import org.eclipse.jgit.transport.SshSessionFactory; -import org.eclipse.jgit.transport.ssh.SshTestHarness; import org.eclipse.jgit.util.FS; import org.junit.After; import org.junit.Test; @@ -47,7 +43,6 @@ import org.junit.Test; */ public class NoFilesSshTest extends SshTestHarness { - private PublicKey testServerKey; private KeyPair testUserKey; @@ -155,27 +150,20 @@ public class NoFilesSshTest extends SshTestHarness { } } - private KeyPair load(Path path) throws Exception { - try (InputStream in = Files.newInputStream(path)) { - return SecurityUtils - .loadKeyPairIdentities(null, - NamedResource.ofName(path.toString()), in, null) - .iterator().next(); - } - } - @Test public void testCloneWithBuiltInKeys() throws Exception { // This test should fail unless our in-memory setup is taken: no - // known_hosts file, and a config that specifies a non-existing key. - File newHostKey = new File(getTemporaryDirectory(), "newhostkey"); - copyTestResource("id_ed25519", newHostKey); - server.addHostKey(newHostKey.toPath(), true); - testServerKey = load(newHostKey.toPath()).getPublic(); - assertTrue(newHostKey.delete()); - testUserKey = load(privateKey1.getAbsoluteFile().toPath()); + // known_hosts file, a config that specifies a non-existing key, + // and the test is using a newly generated KeyPairs anyway. + KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA"); + generator.initialize(2048); + testUserKey = generator.generateKeyPair(); + KeyPair hostKey = generator.generateKeyPair(); + server.addHostKey(hostKey, true); + testServerKey = hostKey.getPublic(); assertNotNull(testServerKey); assertNotNull(testUserKey); + server.setTestUserPublicKey(testUserKey.getPublic()); cloneWith( "ssh://" + TEST_USER + "@localhost:" + testPort + "/doesntmatter", |