You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2018/09/06 16:03:20 UTC
[10/51] [abbrv] mina-sshd git commit: [SSHD-842] Split common
utilities code from sshd-core into sshd-common (new artifact)
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
deleted file mode 100644
index 78994cc..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.hosts;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
- public ConfigFileHostEntryResolverTest() {
- super();
- }
-
- @Test
- public void testConfigFileReload() throws IOException {
- Path dir = getTempTargetRelativeFile(getClass().getSimpleName());
- AtomicInteger reloadCount = new AtomicInteger();
- ConfigFileHostEntryResolver resolver = new ConfigFileHostEntryResolver(assertHierarchyTargetFolderExists(dir).resolve(getCurrentTestName() + ".config.txt")) {
- @Override
- protected List<HostConfigEntry> reloadHostConfigEntries(Path path, String host, int port, String username)
- throws IOException {
- reloadCount.incrementAndGet();
- return super.reloadHostConfigEntries(path, host, port, username);
- }
- };
- Path path = resolver.getPath();
-
- HostConfigEntry expected = new HostConfigEntry(getCurrentTestName(), getCurrentTestName(), 7365, getCurrentTestName());
- testConfigFileReload("Non-existing", path, reloadCount, null, resolver, expected, null);
- testConfigFileReload("Empty", path, reloadCount, Collections.emptyList(), resolver, expected, null);
- testConfigFileReload("Global", path, reloadCount,
- Collections.singletonList(new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN, expected.getHost(), expected.getPort(), expected.getUsername())),
- resolver, expected, expected);
- testConfigFileReload("Wildcard", path, reloadCount,
- Arrays.asList(
- new HostConfigEntry(
- HostPatternsHolder.ALL_HOSTS_PATTERN,
- getClass().getSimpleName(),
- 1234,
- getClass().getSimpleName()),
- new HostConfigEntry(
- expected.getHost() + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
- expected.getHost(),
- expected.getPort(),
- expected.getUsername())),
- resolver, expected, expected);
- testConfigFileReload("Specific", path, reloadCount,
- Arrays.asList(
- new HostConfigEntry(
- HostPatternsHolder.ALL_HOSTS_PATTERN,
- getClass().getSimpleName(),
- 1234,
- getClass().getSimpleName()),
- new HostConfigEntry(
- getClass().getSimpleName() + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
- getClass().getSimpleName(),
- 1234,
- getClass().getSimpleName()),
- expected),
- resolver, expected, expected);
- }
-
- private static void testConfigFileReload(
- String phase, Path path, AtomicInteger reloadCount,
- Collection<? extends HostConfigEntry> entries,
- HostConfigEntryResolver resolver,
- HostConfigEntry query,
- HostConfigEntry expected)
- throws IOException {
- if (entries == null) {
- if (Files.exists(path)) {
- Files.delete(path);
- }
- } else {
- HostConfigEntry.writeHostConfigEntries(path, entries, IoUtils.EMPTY_OPEN_OPTIONS);
- }
-
- reloadCount.set(0);
-
- for (int index = 1; index < Byte.SIZE; index++) {
- HostConfigEntry actual =
- resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername());
-
- if (entries == null) {
- assertEquals(phase + "[" + index + "]: mismatched reload count", 0, reloadCount.get());
- } else {
- assertEquals(phase + "[" + index + "]: mismatched reload count", 1, reloadCount.get());
- }
-
- if (expected == null) {
- assertNull(phase + "[" + index + "]: Unexpected success for " + query, actual);
- } else {
- assertNotNull(phase + "[" + index + "]: No result for " + query, actual);
- assertNotSame(phase + "[" + index + "]: No cloned result for " + query, expected, actual);
- assertEquals(phase + "[" + index + "]: Mismatched host for " + query,
- expected.getHostName(), actual.getHostName());
- assertEquals(phase + "[" + index + "]: Mismatched port for " + query,
- expected.getPort(), actual.getPort());
- assertEquals(phase + "[" + index + "]: Mismatched user for " + query,
- expected.getUsername(), actual.getUsername());
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
index ab3c591..0679fa3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
@@ -48,7 +48,7 @@ import org.apache.sshd.common.util.net.SshdSocketAddress;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator;
import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
@@ -132,7 +132,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
@Test
public void testPreloadedIdentities() throws Exception {
- KeyPair identity = Utils.getFirstKeyPair(sshd);
+ KeyPair identity = CommonTestSupportUtils.getFirstKeyPair(sshd);
String user = getCurrentTestName();
// make sure authentication is achieved only via the identity public key
sshd.setPublickeyAuthenticator((username, key, session) -> {
@@ -182,10 +182,9 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
public void testUseIdentitiesOnly() throws Exception {
Path clientIdFile = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
KeyPairProvider clientIdProvider =
- Utils.createTestHostKeyProvider(clientIdFile.resolve(getCurrentTestName() + ".pem"));
-
- KeyPair specificIdentity = Utils.getFirstKeyPair(sshd);
- KeyPair defaultIdentity = Utils.getFirstKeyPair(clientIdProvider);
+ CommonTestSupportUtils.createTestHostKeyProvider(clientIdFile.resolve(getCurrentTestName() + ".pem"));
+ KeyPair specificIdentity = CommonTestSupportUtils.getFirstKeyPair(sshd);
+ KeyPair defaultIdentity = CommonTestSupportUtils.getFirstKeyPair(clientIdProvider);
ValidateUtils.checkTrue(!KeyUtils.compareKeyPairs(specificIdentity, defaultIdentity),
"client identity not different then entry one");
client.setKeyPairProvider(clientIdProvider);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
deleted file mode 100644
index c306800..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
+++ /dev/null
@@ -1,325 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.hosts;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.regex.Pattern;
-
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class HostConfigEntryTest extends BaseTestSupport {
- public HostConfigEntryTest() {
- super();
- }
-
- @Test
- public void testNegatingPatternOverridesAll() {
- String testHost = "37.77.34.7";
- String[] elements = GenericUtils.split(testHost, '.');
- StringBuilder sb = new StringBuilder(testHost.length() + Byte.SIZE);
- List<HostPatternValue> patterns = new ArrayList<>(elements.length + 1);
- // all wildcard patterns are not negated - only the actual host
- patterns.add(HostPatternsHolder.toPattern(Character.toString(HostPatternsHolder.NEGATION_CHAR_PATTERN) + testHost));
-
- for (int i = 0; i < elements.length; i++) {
- sb.setLength(0);
-
- for (int j = 0; j < elements.length; j++) {
- if (j > 0) {
- sb.append('.');
- }
- if (i == j) {
- sb.append(HostPatternsHolder.WILDCARD_PATTERN);
- } else {
- sb.append(elements[j]);
- }
- }
-
- patterns.add(HostPatternsHolder.toPattern(sb));
- }
-
- for (int index = 0; index < patterns.size(); index++) {
- assertFalse("Unexpected match for " + patterns, HostPatternsHolder.isHostMatch(testHost, 0, patterns));
- Collections.shuffle(patterns);
- }
- }
-
- @Test
- public void testHostWildcardPatternMatching() {
- String pkgName = getClass().getPackage().getName();
- String[] elements = GenericUtils.split(pkgName, '.');
- StringBuilder sb = new StringBuilder(pkgName.length() + Long.SIZE + 1).append(HostPatternsHolder.WILDCARD_PATTERN);
- for (int index = elements.length - 1; index >= 0; index--) {
- sb.append('.').append(elements[index]);
- }
-
- String value = sb.toString();
- HostPatternValue pp = HostPatternsHolder.toPattern(value);
- Pattern pattern = pp.getPattern();
- String domain = value.substring(1); // chomp the wildcard prefix
- for (String host : new String[] {
- getClass().getSimpleName(),
- getCurrentTestName(),
- getClass().getSimpleName() + "-" + getCurrentTestName(),
- getClass().getSimpleName() + "." + getCurrentTestName(),
- }) {
- sb.setLength(0); // start from scratch
- sb.append(host).append(domain);
-
- testCaseInsensitivePatternMatching(sb.toString(), pattern, true);
- }
- }
-
- @Test
- public void testIPAddressWildcardPatternMatching() {
- StringBuilder sb = new StringBuilder().append("10.0.0.");
- int sbLen = sb.length();
-
- Pattern pattern = HostPatternsHolder.toPattern(sb.append(HostPatternsHolder.WILDCARD_PATTERN)).getPattern();
- for (int v = 0; v <= 255; v++) {
- sb.setLength(sbLen); // start from scratch
- sb.append(v);
-
- String address = sb.toString();
- assertTrue("No match for " + address, HostPatternsHolder.isHostMatch(address, pattern));
- }
- }
-
- @Test
- public void testHostSingleCharPatternMatching() {
- String value = getCurrentTestName();
- StringBuilder sb = new StringBuilder(value);
- for (boolean restoreOriginal : new boolean[] {true, false}) {
- for (int index = 0; index < value.length(); index++) {
- sb.setCharAt(index, HostPatternsHolder.SINGLE_CHAR_PATTERN);
- testCaseInsensitivePatternMatching(value, HostPatternsHolder.toPattern(sb.toString()).getPattern(), true);
- if (restoreOriginal) {
- sb.setCharAt(index, value.charAt(index));
- }
- }
- }
- }
-
- @Test
- public void testIPAddressSingleCharPatternMatching() {
- StringBuilder sb = new StringBuilder().append("10.0.0.");
- int sbLen = sb.length();
-
- for (int v = 0; v <= 255; v++) {
- sb.setLength(sbLen); // start from scratch
- sb.append(v);
-
- String address = sb.toString();
- // replace the added digits with single char pattern
- for (int index = sbLen; index < sb.length(); index++) {
- sb.setCharAt(index, HostPatternsHolder.SINGLE_CHAR_PATTERN);
- }
-
- String pattern = sb.toString();
- HostPatternValue pp = HostPatternsHolder.toPattern(pattern);
- assertTrue("No match for " + address + " on pattern=" + pattern, HostPatternsHolder.isHostMatch(address, 0, Collections.singletonList(pp)));
- }
- }
-
- @Test
- public void testIsValidPatternChar() {
- for (char ch = '\0'; ch <= ' '; ch++) {
- assertFalse("Unexpected valid character (0x" + Integer.toHexString(ch & 0xFF) + ")", HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch = 'a'; ch <= 'z'; ch++) {
- assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch = 'A'; ch <= 'Z'; ch++) {
- assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch = '0'; ch <= '9'; ch++) {
- assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch : new char[] {'-', '_', '.', HostPatternsHolder.SINGLE_CHAR_PATTERN, HostPatternsHolder.WILDCARD_PATTERN}) {
- assertTrue("Valid character not recognized: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch : new char[] {
- '(', ')', '{', '}', '[', ']', '@',
- '#', '$', '^', '&', '%', '~', '<', '>',
- ',', '/', '\\', '\'', '"', ':', ';'
- }) {
- assertFalse("Unexpected valid character: " + Character.toString(ch), HostPatternsHolder.isValidPatternChar(ch));
- }
-
- for (char ch = 0x7E; ch <= 0xFF; ch++) {
- assertFalse("Unexpected valid character (0x" + Integer.toHexString(ch & 0xFF) + ")", HostPatternsHolder.isValidPatternChar(ch));
- }
- }
-
- @Test
- public void testResolvePort() {
- final int originalPort = Short.MAX_VALUE;
- final int preferredPort = 7365;
- assertEquals("Mismatched entry port preference",
- preferredPort, HostConfigEntry.resolvePort(originalPort, preferredPort));
-
- for (int entryPort : new int[] {-1, 0}) {
- assertEquals("Non-preferred original port for entry port=" + entryPort,
- originalPort, HostConfigEntry.resolvePort(originalPort, entryPort));
- }
- }
-
- @Test
- public void testResolveUsername() {
- final String originalUser = getCurrentTestName();
- final String preferredUser = getClass().getSimpleName();
- assertSame("Mismatched entry user preference",
- preferredUser, HostConfigEntry.resolveUsername(originalUser, preferredUser));
-
- for (String entryUser : new String[] {null, ""}) {
- assertSame("Non-preferred original user for entry user='" + entryUser + "'",
- originalUser, HostConfigEntry.resolveUsername(originalUser, entryUser));
- }
- }
-
- @Test
- public void testReadSimpleHostsConfigEntries() throws IOException {
- validateHostConfigEntries(readHostConfigEntries());
- }
-
- @Test
- public void testReadGlobalHostsConfigEntries() throws IOException {
- List<HostConfigEntry> entries = validateHostConfigEntries(readHostConfigEntries());
- assertTrue("Not enough entries read", GenericUtils.size(entries) > 1);
-
- // global entry MUST be 1st one
- HostConfigEntry globalEntry = entries.get(0);
- assertEquals("Mismatched global entry pattern", HostPatternsHolder.ALL_HOSTS_PATTERN, globalEntry.getHost());
-
- for (int index = 1; index < entries.size(); index++) {
- HostConfigEntry entry = entries.get(index);
- assertFalse("No target host for " + entry, GenericUtils.isEmpty(entry.getHostName()));
- assertTrue("No target port for " + entry, entry.getPort() > 0);
- assertFalse("No username for " + entry, GenericUtils.isEmpty(entry.getUsername()));
- assertFalse("No identities for " + entry, GenericUtils.isEmpty(entry.getIdentities()));
- assertFalse("No properties for " + entry, GenericUtils.isEmpty(entry.getProperties()));
- }
- }
-
- @Test
- public void testReadMultipleHostPatterns() throws IOException {
- List<HostConfigEntry> entries = validateHostConfigEntries(readHostConfigEntries());
- assertEquals("Mismatched number of entries", 1, GenericUtils.size(entries));
- assertEquals("Mismatched number of patterns", 3, GenericUtils.size(entries.get(0).getPatterns()));
- }
-
- @Test
- public void testResolveIdentityFilePath() throws Exception {
- final String hostValue = getClass().getSimpleName();
- final int portValue = 7365;
- final String userValue = getCurrentTestName();
-
- Exception err = null;
- for (String pattern : new String[] {
- "~/.ssh/%h.key",
- "%d/.ssh/%h.key",
- "/home/%u/.ssh/id_rsa_%p",
- "/home/%u/.ssh/id_%r_rsa",
- "/home/%u/.ssh/%h/%l.key"
- }) {
- try {
- String result = HostConfigEntry.resolveIdentityFilePath(pattern, hostValue, portValue, userValue);
- System.out.append('\t').append(pattern).append(" => ").println(result);
- } catch (Exception e) {
- System.err.append("Failed (").append(e.getClass().getSimpleName())
- .append(") to process pattern=").append(pattern)
- .append(": ").println(e.getMessage());
- err = e;
- }
- }
-
- if (err != null) {
- throw err;
- }
- }
-
- @Test
- public void testFindBestMatch() {
- final String hostValue = getCurrentTestName();
- HostConfigEntry expected = new HostConfigEntry(hostValue, hostValue, 7365, hostValue);
- List<HostConfigEntry> matches = new ArrayList<>();
- matches.add(new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN,
- getClass().getSimpleName(), Short.MAX_VALUE, getClass().getSimpleName()));
- matches.add(new HostConfigEntry(hostValue + Character.toString(HostPatternsHolder.WILDCARD_PATTERN),
- getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
- matches.add(expected);
-
- for (int index = 0; index < matches.size(); index++) {
- HostConfigEntry actual = HostConfigEntry.findBestMatch(matches);
- assertSame("Mismatched best match for " + matches, expected, actual);
- Collections.shuffle(matches);
- }
- }
-
- private static <C extends Collection<HostConfigEntry>> C validateHostConfigEntries(C entries) {
- assertFalse("No entries", GenericUtils.isEmpty(entries));
-
- for (HostConfigEntry entry : entries) {
- assertFalse("No pattern for " + entry, GenericUtils.isEmpty(entry.getHost()));
- assertFalse("No extra properties for " + entry, GenericUtils.isEmpty(entry.getProperties()));
- }
-
- return entries;
- }
-
- private List<HostConfigEntry> readHostConfigEntries() throws IOException {
- return readHostConfigEntries(getCurrentTestName() + ".config.txt");
- }
-
- private List<HostConfigEntry> readHostConfigEntries(String resourceName) throws IOException {
- URL url = getClass().getResource(resourceName);
- assertNotNull("Missing resource " + resourceName, url);
- return HostConfigEntry.readHostConfigEntries(url);
- }
-
- private static void testCaseInsensitivePatternMatching(String value, Pattern pattern, boolean expected) {
- for (int index = 0; index < value.length(); index++) {
- boolean actual = HostPatternsHolder.isHostMatch(value, pattern);
- assertEquals("Mismatched match result for " + value + " on pattern=" + pattern.pattern(), expected, actual);
- value = shuffleCase(value);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
deleted file mode 100644
index efbf885..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.hosts;
-
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.MethodSorters;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-import org.junit.runners.Parameterized.UseParametersRunnerFactory;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests
-@UseParametersRunnerFactory(JUnit4ClassRunnerWithParametersFactory.class)
-@Category({ NoIoTestCase.class })
-public class KnownHostHashValueTest extends BaseTestSupport {
- private final String hostName;
- private final String hashValue;
- private final KnownHostHashValue hash;
-
- public KnownHostHashValueTest(String hostName, String hashValue) {
- this.hostName = hostName;
- this.hashValue = hashValue;
- this.hash = KnownHostHashValue.parse(hashValue);
- }
-
- @Parameters(name = "host={0}, hash={1}")
- public static Collection<Object[]> parameters() {
- return Arrays.<Object[]>asList(
- (Object[]) new String[]{"192.168.1.61", "|1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg="});
- }
-
- @Test
- public void testDecodeEncode() {
- assertSame("Mismatched digester", KnownHostHashValue.DEFAULT_DIGEST, hash.getDigester());
- assertEquals("Mismatched encoded form", hashValue, hash.toString());
- }
-
- @Test
- public void testHostMatch() {
- assertTrue("Specified host does not match", hash.isHostMatch(hostName));
- assertFalse("Unexpected host match", hash.isHostMatch(getCurrentTestName()));
- }
-
- @Test
- public void testCalculateHashValue() throws Exception {
- byte[] expected = hash.getDigestValue();
- byte[] actual = KnownHostHashValue.calculateHashValue(hostName, hash.getDigester(), hash.getSaltValue());
- assertArrayEquals("Mismatched hash value", expected, actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
deleted file mode 100644
index af720b8..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.keys;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.OpenOption;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.security.GeneralSecurityException;
-import java.security.KeyPair;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.EnumMap;
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.sshd.common.config.keys.BuiltinIdentities;
-import org.apache.sshd.common.config.keys.FilePasswordProvider;
-import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.keyprovider.KeyIdentityProvider;
-import org.apache.sshd.common.keyprovider.KeyPairProvider;
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.ValidateUtils;
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.apache.sshd.util.test.Utils;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class BuiltinClientIdentitiesWatcherTest extends BaseTestSupport {
- public BuiltinClientIdentitiesWatcherTest() {
- super();
- }
-
- @Test
- public void testMultipleFilesWatch() throws Exception {
- KeyPair identity = Utils.getFirstKeyPair(createTestHostKeyProvider());
- String keyType = ValidateUtils.checkNotNullAndNotEmpty(KeyUtils.getKeyType(identity), "Cannot determine identity key type");
-
- Path dir = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
- Map<BuiltinIdentities, Path> locationsMap = new EnumMap<>(BuiltinIdentities.class);
- Map<BuiltinIdentities, KeyPair> idsMap = new EnumMap<>(BuiltinIdentities.class);
- for (BuiltinIdentities id : BuiltinIdentities.VALUES) {
- Path idFile = dir.resolve(ClientIdentity.getIdentityFileName(id));
- Files.deleteIfExists(idFile);
- assertNull("Multiple file mappings for " + id, locationsMap.put(id, idFile));
- assertNull("Multiple identity mappings for " + id, idsMap.put(id, KeyUtils.cloneKeyPair(keyType, identity)));
- }
-
- ClientIdentityLoader loader = new ClientIdentityLoader() {
- @Override
- public KeyPair loadClientIdentity(String location, FilePasswordProvider provider) throws IOException, GeneralSecurityException {
- BuiltinIdentities id = findIdentity(location);
- assertNotNull("Invalid location: " + location, id);
- return idsMap.get(id);
- }
-
- @Override
- public boolean isValidLocation(String location) throws IOException {
- return findIdentity(location) != null;
- }
-
- private BuiltinIdentities findIdentity(String location) {
- if (GenericUtils.isEmpty(location)) {
- return null;
- }
-
- for (Map.Entry<BuiltinIdentities, Path> le : locationsMap.entrySet()) {
- Path path = le.getValue();
- if (String.CASE_INSENSITIVE_ORDER.compare(location, path.toString()) == 0) {
- return le.getKey();
- }
- }
-
- return null;
- }
- };
-
- Map<BuiltinIdentities, KeyPair> existing = new EnumMap<>(BuiltinIdentities.class);
- KeyPairProvider watcher = new BuiltinClientIdentitiesWatcher(dir, false, loader, FilePasswordProvider.EMPTY, false);
- testMultipleFilesWatch("No files", watcher, existing.values());
-
- for (BuiltinIdentities id : BuiltinIdentities.VALUES) {
- String phase = id + " + " + Objects.toString(existing.keySet());
- touchIdentityFile(locationsMap.get(id));
- existing.put(id, idsMap.get(id));
-
- for (int index = 0; index < Byte.SIZE; index++) {
- testMultipleFilesWatch(phase + "[" + index + "]", watcher, existing.values());
- }
- }
-
- testMultipleFilesWatch("All files", watcher, existing.values());
-
- for (BuiltinIdentities id : BuiltinIdentities.VALUES) {
- existing.remove(id);
- Files.deleteIfExists(locationsMap.get(id));
- String phase = Objects.toString(existing.keySet()) + " - " + id;
-
- for (int index = 0; index < Byte.SIZE; index++) {
- testMultipleFilesWatch(phase + "[" + index + "]", watcher, existing.values());
- }
- }
- }
-
- private static void touchIdentityFile(Path idFile) throws IOException {
- OpenOption[] options = IoUtils.EMPTY_OPEN_OPTIONS;
- if (Files.exists(idFile, IoUtils.EMPTY_LINK_OPTIONS)) {
- options = new OpenOption[]{StandardOpenOption.WRITE, StandardOpenOption.APPEND};
- }
-
- try (OutputStream out = Files.newOutputStream(idFile, options)) {
- out.write(new Date(System.currentTimeMillis()).toString().getBytes(StandardCharsets.UTF_8));
- out.write('\n');
- }
- }
-
- private static void testMultipleFilesWatch(String phase, KeyIdentityProvider watcher, Collection<? extends KeyPair> expected) {
- Iterable<KeyPair> keys = watcher.loadKeys();
- Collection<KeyPair> actual = new ArrayList<>();
- for (KeyPair kp : keys) {
- actual.add(kp);
- }
- assertEquals(phase + ": mismatched sizes", GenericUtils.size(expected), GenericUtils.size(actual));
-
- if (!GenericUtils.isEmpty(expected)) {
- for (KeyPair kp : expected) {
- assertTrue(phase + ": missing key", actual.contains(kp));
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
deleted file mode 100644
index 60ded0a..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.keys;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
-import java.nio.file.OpenOption;
-import java.nio.file.Path;
-import java.nio.file.StandardOpenOption;
-import java.security.GeneralSecurityException;
-import java.security.KeyPair;
-import java.util.Date;
-import java.util.Objects;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.sshd.common.config.keys.FilePasswordProvider;
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.apache.sshd.util.test.Utils;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class ClientIdentityFileWatcherTest extends BaseTestSupport {
- public ClientIdentityFileWatcherTest() {
- super();
- }
-
- @Test
- public void testIdentityReload() throws Exception {
- Path dir = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
- Path idFile = dir.resolve(getCurrentTestName() + ".pem");
- KeyPair identity = Utils.getFirstKeyPair(createTestHostKeyProvider());
- ClientIdentityLoader loader = new ClientIdentityLoader() {
- @Override
- public KeyPair loadClientIdentity(String location, FilePasswordProvider provider) throws IOException, GeneralSecurityException {
- assertTrue("Invalid location: " + location, isValidLocation(location));
- return identity;
- }
-
- @Override
- public boolean isValidLocation(String location) throws IOException {
- return Objects.equals(location, toString());
- }
-
- @Override
- public String toString() {
- return Objects.toString(idFile);
- }
- };
-
- AtomicInteger reloadCount = new AtomicInteger(0);
- ClientIdentityProvider idProvider = new ClientIdentityFileWatcher(idFile, loader, FilePasswordProvider.EMPTY, false) {
- @Override
- protected KeyPair reloadClientIdentity(Path path) throws IOException, GeneralSecurityException {
- assertEquals("Mismatched client identity path", idFile, path);
- reloadCount.incrementAndGet();
- return super.reloadClientIdentity(path);
- }
- };
- Files.deleteIfExists(idFile);
-
- testIdentityReload("Non-existing", reloadCount, idProvider, null, 0);
-
- touchIdentityFile(idFile);
- for (int index = 1; index < Byte.SIZE; index++) {
- testIdentityReload("Created iteration " + 1, reloadCount, idProvider, identity, 1);
- }
-
- touchIdentityFile(idFile);
- for (int index = 1; index < Byte.SIZE; index++) {
- testIdentityReload("Modified iteration " + 1, reloadCount, idProvider, identity, 2);
- }
- }
-
- private static void touchIdentityFile(Path idFile) throws IOException {
- OpenOption[] options = IoUtils.EMPTY_OPEN_OPTIONS;
- if (Files.exists(idFile, IoUtils.EMPTY_LINK_OPTIONS)) {
- options = new OpenOption[]{StandardOpenOption.WRITE, StandardOpenOption.APPEND};
- }
-
- try (OutputStream out = Files.newOutputStream(idFile, options)) {
- out.write(new Date(System.currentTimeMillis()).toString().getBytes(StandardCharsets.UTF_8));
- out.write('\n');
- }
- }
-
- private static void testIdentityReload(
- String phase, Number reloadCount, ClientIdentityProvider provider, KeyPair expectedIdentity, int expectedCount)
- throws Exception {
- KeyPair actualIdentity = provider.getClientIdentity();
- assertSame(phase + ": mismatched identity", expectedIdentity, actualIdentity);
- assertEquals(phase + ": mismatched re-load count", expectedCount, reloadCount.intValue());
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java
deleted file mode 100644
index 6861299..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.client.config.keys;
-
-import java.nio.file.Files;
-import java.nio.file.LinkOption;
-import java.nio.file.Path;
-import java.security.KeyPair;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.EnumSet;
-import java.util.Map;
-
-import org.apache.sshd.common.config.keys.BuiltinIdentities;
-import org.apache.sshd.common.config.keys.IdentityUtils;
-import org.apache.sshd.common.keyprovider.KeyIdentityProvider;
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.io.IoUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class ClientIdentityTest extends BaseTestSupport {
- public ClientIdentityTest() {
- super();
- }
-
- @Test
- public void testLoadClientIdentities() throws Exception {
- Path resFolder = getTestResourcesFolder();
- LinkOption[] options = IoUtils.getLinkOptions(true);
- Collection<BuiltinIdentities> expected = EnumSet.noneOf(BuiltinIdentities.class);
- for (BuiltinIdentities type : BuiltinIdentities.VALUES) {
- String fileName = ClientIdentity.getIdentityFileName(type);
- Path file = resFolder.resolve(fileName);
- if (!Files.exists(file, options)) {
- System.out.println("Skip non-existing identity file " + file);
- continue;
- }
-
- if (!type.isSupported()) {
- System.out.println("Skip unsupported identity file " + file);
- continue;
- }
-
- expected.add(type);
- }
-
- Map<String, KeyPair> ids = ClientIdentity.loadDefaultIdentities(
- resFolder,
- false, // don't be strict
- null, // none of the files is password protected
- options);
- assertEquals("Mismatched loaded ids count", GenericUtils.size(expected), GenericUtils.size(ids));
-
- Collection<KeyPair> pairs = new ArrayList<>(ids.size());
- for (BuiltinIdentities type : BuiltinIdentities.VALUES) {
- if (expected.contains(type)) {
- KeyPair kp = ids.get(type.getName());
- assertNotNull("No key pair loaded for " + type, kp);
- pairs.add(kp);
- }
- }
-
- KeyIdentityProvider provider = IdentityUtils.createKeyPairProvider(ids, true /* supported only */);
- assertNotNull("No provider generated", provider);
-
- Iterable<KeyPair> keys = provider.loadKeys();
- for (KeyPair kp : keys) {
- assertTrue("Unexpected loaded key: " + kp, pairs.remove(kp));
- }
-
- assertEquals("Not all pairs listed", 0, pairs.size());
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
index 6ad17b2..678521f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/kex/KexTest.java
@@ -41,9 +41,9 @@ import org.apache.sshd.common.kex.KeyExchange;
import org.apache.sshd.common.util.security.SecurityUtils;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
import org.apache.sshd.util.test.TeeOutputStream;
-import org.apache.sshd.util.test.Utils;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
@@ -81,11 +81,11 @@ public class KexTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(KexTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(KexTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(KexTest.class);
+ client = CoreTestSupportUtils.setupTestClient(KexTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
index c556553..9151af2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
@@ -51,8 +51,8 @@ import org.apache.sshd.common.util.GenericUtils;
import org.apache.sshd.common.util.ValidateUtils;
import org.apache.sshd.common.util.net.SshdSocketAddress;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
import org.apache.sshd.util.test.NoIoTestCase;
-import org.apache.sshd.util.test.Utils;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -230,7 +230,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
@Test
public void testRejectModifiedServerKey() throws Exception {
- KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair kp = CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
final PublicKey modifiedKey = kp.getPublic();
final AtomicInteger acceptCount = new AtomicInteger(0);
ServerKeyVerifier verifier = new KnownHostsServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE, createKnownHostsCopy()) {
@@ -258,7 +258,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
@Test
public void testAcceptModifiedServerKeyUpdatesFile() throws Exception {
- KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair kp = CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
final PublicKey modifiedKey = kp.getPublic();
Path path = createKnownHostsCopy();
ServerKeyVerifier verifier = new KnownHostsServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE, path) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
index 87dc5ff..12c416d 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java
@@ -29,7 +29,7 @@ import org.apache.sshd.client.SshClient;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
import org.apache.sshd.util.test.CommandExecutionHelper;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -51,11 +51,11 @@ public class ClientSessionTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(ClientSessionTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(ClientSessionTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(ClientSessionTest.class);
+ client = CoreTestSupportUtils.setupTestClient(ClientSessionTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
index ba3ee68..a095f81 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
@@ -32,7 +32,7 @@ import org.apache.sshd.common.session.SessionListener;
import org.apache.sshd.server.auth.password.PasswordAuthenticator;
import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator;
import org.apache.sshd.server.auth.pubkey.RejectAllPublickeyAuthenticator;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
import org.apache.sshd.util.test.client.simple.BaseSimpleClientTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -60,8 +60,8 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
@Test
public void testLoginSessionWithIdentity() throws Exception {
- final KeyPair identity = Utils.getFirstKeyPair(createTestHostKeyProvider());
- final AtomicBoolean identityQueried = new AtomicBoolean(false);
+ KeyPair identity = CommonTestSupportUtils.getFirstKeyPair(createTestHostKeyProvider());
+ AtomicBoolean identityQueried = new AtomicBoolean(false);
sshd.setPublickeyAuthenticator((username, key, session) -> {
if (username.equals(getCurrentTestName())) {
identityQueried.set(true);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
index c0f1a73..a8137f0 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java
@@ -44,38 +44,38 @@ public class AttributeStoreTest extends BaseTestSupport {
@Test
public void testResolveFactoryManagerAttribute() {
- assertNull("Unexpected null factory value", AttributeStore.resolveAttribute((FactoryManager) null, KEY));
+ assertNull("Unexpected null factory value", FactoryManager.resolveAttribute((FactoryManager) null, KEY));
FactoryManager manager = Mockito.mock(FactoryManager.class);
String expected = setAttributeValue(manager, getCurrentTestName());
- assertSame("Mismatched resolved value", expected, AttributeStore.resolveAttribute(manager, KEY));
+ assertSame("Mismatched resolved value", expected, FactoryManager.resolveAttribute(manager, KEY));
}
@Test
public void testResolveSessionAttribute() {
- assertNull("Unexpected null session value", AttributeStore.resolveAttribute((Session) null, KEY));
+ assertNull("Unexpected null session value", Session.resolveAttribute((Session) null, KEY));
Session session = Mockito.mock(Session.class);
- final AtomicInteger managerCount = new AtomicInteger(0);
+ AtomicInteger managerCount = new AtomicInteger(0);
Mockito.when(session.getFactoryManager()).then(invocation -> {
managerCount.incrementAndGet();
return null;
});
setAttributeValue(session, null);
- assertNull("Unexpected success for empty attribute", AttributeStore.resolveAttribute(session, KEY));
+ assertNull("Unexpected success for empty attribute", Session.resolveAttribute(session, KEY));
assertEquals("Factory manager not requested", 1, managerCount.getAndSet(0));
String expected = setAttributeValue(session, getCurrentTestName());
- assertSame("Mismatched attribute value", expected, AttributeStore.resolveAttribute(session, KEY));
+ assertSame("Mismatched attribute value", expected, Session.resolveAttribute(session, KEY));
assertEquals("Unexpected manager request", 0, managerCount.get());
}
@Test
public void testResolveChannelAttribute() {
- assertNull("Unexpected null channek value", AttributeStore.resolveAttribute((Channel) null, KEY));
+ assertNull("Unexpected null channek value", Channel.resolveAttribute((Channel) null, KEY));
- final Session session = Mockito.mock(Session.class);
- final AtomicInteger managerCount = new AtomicInteger(0);
+ Session session = Mockito.mock(Session.class);
+ AtomicInteger managerCount = new AtomicInteger(0);
Mockito.when(session.getFactoryManager()).thenAnswer(invocation -> {
managerCount.incrementAndGet();
return null;
@@ -83,19 +83,19 @@ public class AttributeStoreTest extends BaseTestSupport {
setAttributeValue(session, null);
Channel channel = Mockito.mock(Channel.class);
- final AtomicInteger sessionCount = new AtomicInteger(0);
+ AtomicInteger sessionCount = new AtomicInteger(0);
Mockito.when(channel.getSession()).thenAnswer(invocation -> {
sessionCount.incrementAndGet();
return session;
});
setAttributeValue(channel, null);
- assertNull("Unexpected success for empty attribute", AttributeStore.resolveAttribute(channel, KEY));
+ assertNull("Unexpected success for empty attribute", Channel.resolveAttribute(channel, KEY));
assertEquals("Session not requested", 1, sessionCount.getAndSet(0));
assertEquals("Factory manager not requested", 1, managerCount.getAndSet(0));
String expected = setAttributeValue(channel, getCurrentTestName());
- assertSame("Mismatched attribute value", expected, AttributeStore.resolveAttribute(channel, KEY));
+ assertSame("Mismatched attribute value", expected, Channel.resolveAttribute(channel, KEY));
assertEquals("Unexpected session request", 0, sessionCount.get());
assertEquals("Unexpected manager request", 0, managerCount.get());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
index 12319c0..69b6fe8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
@@ -30,7 +30,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.JUnitTestSupport;
import org.apache.sshd.util.test.NoIoTestCase;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -43,21 +43,21 @@ import org.mockito.Mockito;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Category({ NoIoTestCase.class })
-public class PropertyResolverUtilsTest extends BaseTestSupport {
+public class PropertyResolverUtilsTest extends JUnitTestSupport {
public PropertyResolverUtilsTest() {
super();
}
@Test
public void testResolveAndUpdateClosestPropertyValue() {
- final String propName = getCurrentTestName();
- final String rootValue = getClass().getPackage().getName();
+ String propName = getCurrentTestName();
+ String rootValue = getClass().getPackage().getName();
Session resolver = createMockSession();
FactoryManager root = Objects.requireNonNull(resolver.getFactoryManager(), "No manager");
assertNull("Unexpected root previous value", PropertyResolverUtils.updateProperty(root, propName, rootValue));
assertSame("Mismatched root value", rootValue, PropertyResolverUtils.getString(resolver, propName));
- final String nodeValue = getClass().getSimpleName();
+ String nodeValue = getClass().getSimpleName();
assertNull("Unexpected node previous value", PropertyResolverUtils.updateProperty(resolver, propName, nodeValue));
assertSame("Mismatched node value", nodeValue, PropertyResolverUtils.getString(resolver, propName));
}
@@ -90,7 +90,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
System.clearProperty(propKey);
}
- for (final boolean expected : new boolean[]{false, true}) {
+ for (boolean expected : new boolean[]{false, true}) {
try {
System.setProperty(propKey, Boolean.toString(expected));
testBooleanProperty(resolver, propName, expected);
@@ -102,8 +102,8 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
@Test
public void testLongProperty() {
- final long expected = System.currentTimeMillis();
- final String name = getCurrentTestName();
+ long expected = System.currentTimeMillis();
+ String name = getCurrentTestName();
Session session = createMockSession();
assertEquals("Mismatched empty props value", expected, PropertyResolverUtils.getLongProperty(session, name, expected));
@@ -137,8 +137,8 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
@Test
public void testIntegerProperty() {
- final int expected = 3777347;
- final String name = getCurrentTestName();
+ int expected = 3777347;
+ String name = getCurrentTestName();
Session session = createMockSession();
assertEquals("Mismatched empty props value", expected, PropertyResolverUtils.getIntProperty(session, name, expected));
@@ -176,8 +176,8 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
@Test
public void testBooleanProperty() {
- for (final boolean expected : new boolean[]{false, true}) {
- final String name = getCurrentTestName();
+ for (boolean expected : new boolean[]{false, true}) {
+ String name = getCurrentTestName();
Session session = createMockSession();
assertEquals("Mismatched empty props value", expected, PropertyResolverUtils.getBooleanProperty(session, name, expected));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
deleted file mode 100644
index a15ca6b..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common;
-
-import java.util.Collection;
-
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class SshConstantsTest extends BaseTestSupport {
- public SshConstantsTest() {
- super();
- }
-
- @Test
- public void testGetDisconnectReason() {
- for (int reason = SshConstants.SSH2_DISCONNECT_HOST_NOT_ALLOWED_TO_CONNECT; reason <= SshConstants.SSH2_DISCONNECT_ILLEGAL_USER_NAME; reason++) {
- String name = SshConstants.getDisconnectReasonName(reason);
- assertTrue("Mismatched name for reason=" + reason + ": " + name, name.startsWith("SSH2_DISCONNECT_"));
- }
- }
-
- @Test
- public void testGetOpenErrorName() {
- for (int code = SshConstants.SSH_OPEN_ADMINISTRATIVELY_PROHIBITED; code <= SshConstants.SSH_OPEN_RESOURCE_SHORTAGE; code++) {
- String name = SshConstants.getOpenErrorCodeName(code);
- assertTrue("Mismatched name for code=" + code + ": " + name, name.startsWith("SSH_OPEN_"));
- }
- }
-
- @Test
- public void testAmbiguousOpcodes() throws Exception {
- int[] knownAmbiguities = {30, 31, 60};
- Collection<Integer> opcodes = SshConstants.getAmbiguousOpcodes();
- assertTrue("Not enough ambiguities found", GenericUtils.size(opcodes) >= knownAmbiguities.length);
-
- for (int cmd : knownAmbiguities) {
- assertEquals("Mismatched mnemonic for known ambiguity=" + cmd, Integer.toString(cmd), SshConstants.getCommandMessageName(cmd));
- assertTrue("Known ambiguity not reported as such: " + cmd, SshConstants.isAmbiguousOpcode(cmd));
- assertTrue("Known ambiguity=" + cmd + " not listed: " + opcodes, opcodes.contains(cmd));
- }
-
- for (Integer cmd : opcodes) {
- assertEquals("Mismatched mnemonic for " + cmd, cmd.toString(), SshConstants.getCommandMessageName(cmd));
- assertTrue("Opcode not detected as ambiguous: " + cmd, SshConstants.isAmbiguousOpcode(cmd));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java
deleted file mode 100644
index 06cfffc..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/VersionPropertiesTest.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common;
-
-import java.util.Map;
-
-import org.apache.sshd.common.config.VersionProperties;
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class VersionPropertiesTest extends BaseTestSupport {
- public VersionPropertiesTest() {
- super();
- }
-
- @Test
- public void testNonEmptyProperties() {
- Map<?, ?> props = VersionProperties.getVersionProperties();
- assertTrue(GenericUtils.isNotEmpty(props));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 322f55c..d7df493 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -74,7 +74,7 @@ import org.apache.sshd.server.session.ServerSession;
import org.apache.sshd.server.session.ServerSessionImpl;
import org.apache.sshd.server.session.SessionFactory;
import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.Utils;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
import org.junit.After;
import org.junit.Before;
import org.junit.FixMethodOrder;
@@ -587,14 +587,14 @@ public class AuthenticationTest extends BaseTestSupport {
@Test // see SSHD-618
public void testPublicKeyAuthDifferentThanKex() throws Exception {
KeyPairProvider serverKeys = KeyPairProvider.wrap(
- Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024),
- Utils.generateKeyPair(KeyUtils.DSS_ALGORITHM, 512),
- Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256));
+ CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024),
+ CommonTestSupportUtils.generateKeyPair(KeyUtils.DSS_ALGORITHM, 512),
+ CommonTestSupportUtils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256));
sshd.setKeyPairProvider(serverKeys);
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE);
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
- final KeyPair clientIdentity = Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256);
+ final KeyPair clientIdentity = CommonTestSupportUtils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256);
sshd.setPublickeyAuthenticator((username, key, session) -> {
String keyType = KeyUtils.getKeyType(key);
String expType = KeyUtils.getKeyType(clientIdentity);
@@ -650,7 +650,7 @@ public class AuthenticationTest extends BaseTestSupport {
super.sendPublicKeyResponse(session, username, KeyPairProvider.SSH_DSS, key, keyBlob, offset, blobLen, buffer);
} else if (count == 2) {
// send another key
- KeyPair otherPair = org.apache.sshd.util.test.Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair otherPair = org.apache.sshd.util.test.CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
PublicKey otherKey = otherPair.getPublic();
Buffer buf = session.createBuffer(SshConstants.SSH_MSG_USERAUTH_PK_OK, blobLen + alg.length() + Long.SIZE);
buf.putString(alg);
@@ -666,7 +666,7 @@ public class AuthenticationTest extends BaseTestSupport {
}));
try (SshClient client = setupTestClient()) {
- KeyPair clientIdentity = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair clientIdentity = CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
client.start();
try {
@@ -693,7 +693,7 @@ public class AuthenticationTest extends BaseTestSupport {
public void testHostBasedAuthentication() throws Exception {
String hostClienUser = getClass().getSimpleName();
String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address());
- KeyPair hostClientKey = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair hostClientKey = CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
AtomicInteger invocationCount = new AtomicInteger(0);
sshd.setHostBasedAuthenticator((session, username, clientHostKey, clientHostName, clientUsername, certificates) -> {
invocationCount.incrementAndGet();
@@ -751,7 +751,7 @@ public class AuthenticationTest extends BaseTestSupport {
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE);
try (SshClient client = setupTestClient()) {
- KeyPair kp = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
+ KeyPair kp = CommonTestSupportUtils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024);
client.start();
try {
for (int index = 1; index < 3; index++) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
deleted file mode 100644
index 6611702..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.cipher;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AES192CTRTest extends BaseCipherTest {
- public AES192CTRTest() {
- super();
- }
-
- @Test
- public void testEncryptDecrypt() throws Exception {
- // for AES 256 bits we need the JCE unlimited strength policy
- ensureKeySizeSupported(16, 24, "AES", "AES/CTR/NoPadding");
- testEncryptDecrypt(BuiltinCiphers.aes192ctr);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
deleted file mode 100644
index dd39fd4..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.cipher;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class AES256CBCTest extends BaseCipherTest {
- public AES256CBCTest() {
- super();
- }
-
- @Test
- public void testEncryptDecrypt() throws Exception {
- // for AES 256 bits we need the JCE unlimited strength policy
- ensureKeySizeSupported(16, 32, "AES", "AES/CBC/NoPadding");
- testEncryptDecrypt(BuiltinCiphers.aes256cbc);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
deleted file mode 100644
index 1c37449..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.cipher;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class ARCFOUR128Test extends BaseCipherTest {
- public ARCFOUR128Test() {
- super();
- }
-
- @Test
- public void testEncryptDecrypt() throws Exception {
- testEncryptDecrypt(BuiltinCiphers.arcfour128);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
deleted file mode 100644
index 5511e0f..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.cipher;
-
-import org.junit.FixMethodOrder;
-import org.junit.Test;
-import org.junit.runners.MethodSorters;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-public class ARCFOUR256Test extends BaseCipherTest {
- public ARCFOUR256Test() {
- super();
- }
-
- @Test
- public void testEncryptDecrypt() throws Exception {
- // for RC4 256 bits we need the JCE unlimited strength policy
- ensureKeySizeSupported(32, "ARCFOUR", "RC4");
- testEncryptDecrypt(BuiltinCiphers.arcfour256);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
deleted file mode 100644
index fd30e18..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.common.cipher;
-
-import java.nio.charset.StandardCharsets;
-import java.security.GeneralSecurityException;
-import java.security.InvalidKeyException;
-
-import javax.crypto.spec.IvParameterSpec;
-import javax.crypto.spec.SecretKeySpec;
-
-import org.apache.sshd.common.NamedFactory;
-import org.apache.sshd.common.cipher.Cipher.Mode;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.Assume;
-import org.junit.experimental.categories.Category;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@Category({ NoIoTestCase.class })
-public abstract class BaseCipherTest extends BaseTestSupport {
- protected BaseCipherTest() {
- super();
- }
-
- protected void ensureKeySizeSupported(int bsize, String algorithm, String transformation) throws GeneralSecurityException {
- try {
- javax.crypto.Cipher cipher = SecurityUtils.getCipher(transformation);
- byte[] key = new byte[bsize];
- cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm));
- } catch (GeneralSecurityException e) {
- if (e instanceof InvalidKeyException) { // NOTE: assumption violations are NOT test failures...
- Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "] N/A", false);
- }
-
- throw e;
- }
- }
-
- protected void ensureKeySizeSupported(int ivsize, int bsize, String algorithm, String transformation) throws GeneralSecurityException {
- try {
- javax.crypto.Cipher cipher = SecurityUtils.getCipher(transformation);
- byte[] key = new byte[bsize];
- byte[] iv = new byte[ivsize];
- cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm), new IvParameterSpec(iv));
- } catch (GeneralSecurityException e) {
- if (e instanceof InvalidKeyException) {
- Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "/" + ivsize + "]", false /* force exception */);
- }
-
- throw e;
- }
- }
-
- protected void testEncryptDecrypt(NamedFactory<Cipher> factory) throws Exception {
- String facName = factory.getName();
- Cipher enc = factory.create();
- int keySize = enc.getBlockSize();
- int ivSize = enc.getIVSize();
- byte[] key = new byte[keySize];
- byte[] iv = new byte[ivSize];
- enc.init(Mode.Encrypt, key, iv);
-
- byte[] expected = facName.getBytes(StandardCharsets.UTF_8);
- byte[] workBuf = expected.clone(); // need to clone since the cipher works in-line
- enc.update(workBuf, 0, workBuf.length);
-
- Cipher dec = factory.create();
- dec.init(Mode.Decrypt, key, iv);
- byte[] actual = workBuf.clone();
- dec.update(actual, 0, actual.length);
-
- assertArrayEquals(facName, expected, actual);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
index 4a02074..0089782 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java
@@ -35,10 +35,11 @@ import org.apache.sshd.common.random.Random;
import org.apache.sshd.common.util.buffer.BufferUtils;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CommonTestSupportUtils;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.apache.sshd.util.test.JSchLogger;
import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
import org.apache.sshd.util.test.SimpleUserInfo;
-import org.apache.sshd.util.test.Utils;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
@@ -67,15 +68,15 @@ public class CipherTest extends BaseTestSupport {
* NOTE !!! order is important since we build from it the C2S/S2C ciphers proposal
*/
private static final List<Object[]> PARAMETERS =
- Collections.unmodifiableList(Arrays.asList(
- new Object[]{BuiltinCiphers.aes128cbc, com.jcraft.jsch.jce.AES128CBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.tripledescbc, com.jcraft.jsch.jce.TripleDESCBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.blowfishcbc, com.jcraft.jsch.jce.BlowfishCBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.aes192cbc, com.jcraft.jsch.jce.AES192CBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.arcfour128, com.jcraft.jsch.jce.ARCFOUR128.class, NUM_LOADTEST_ROUNDS},
- new Object[]{BuiltinCiphers.arcfour256, com.jcraft.jsch.jce.ARCFOUR256.class, NUM_LOADTEST_ROUNDS}
- ));
+ Collections.unmodifiableList(Arrays.asList(
+ new Object[]{BuiltinCiphers.aes128cbc, com.jcraft.jsch.jce.AES128CBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.tripledescbc, com.jcraft.jsch.jce.TripleDESCBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.blowfishcbc, com.jcraft.jsch.jce.BlowfishCBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.aes192cbc, com.jcraft.jsch.jce.AES192CBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.arcfour128, com.jcraft.jsch.jce.ARCFOUR128.class, NUM_LOADTEST_ROUNDS},
+ new Object[]{BuiltinCiphers.arcfour256, com.jcraft.jsch.jce.ARCFOUR256.class, NUM_LOADTEST_ROUNDS}
+ ));
private static final List<NamedResource> TEST_CIPHERS =
Collections.unmodifiableList(
@@ -86,7 +87,7 @@ public class CipherTest extends BaseTestSupport {
private static SshServer sshd;
private static int port;
- private final Random random = Utils.getRandomizerInstance();
+ private final Random random = CommonTestSupportUtils.getRandomizerInstance();
private final BuiltinCiphers builtInCipher;
private final Class<? extends com.jcraft.jsch.Cipher> jschCipher;
private final int loadTestRounds;
@@ -105,7 +106,7 @@ public class CipherTest extends BaseTestSupport {
@BeforeClass
public static void setupClientAndServer() throws Exception {
JSchLogger.init();
- sshd = Utils.setupTestServer(CipherTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(CipherTest.class);
sshd.start();
port = sshd.getPort();
}