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:18 UTC
[08/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/common/digest/BuiltinDigestsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/digest/BuiltinDigestsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/digest/BuiltinDigestsTest.java
deleted file mode 100644
index 8cf7adf..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/digest/BuiltinDigestsTest.java
+++ /dev/null
@@ -1,65 +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.digest;
-
-import java.lang.reflect.Field;
-import java.util.EnumSet;
-import java.util.Set;
-
-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 BuiltinDigestsTest extends BaseTestSupport {
- public BuiltinDigestsTest() {
- super();
- }
-
- @Test
- public void testFromName() {
- for (BuiltinDigests expected : BuiltinDigests.VALUES) {
- String name = expected.getName();
- BuiltinDigests actual = BuiltinDigests.fromFactoryName(name);
- assertSame(name, expected, actual);
- }
- }
-
- @Test
- public void testAllConstantsCovered() throws Exception {
- Set<BuiltinDigests> avail = EnumSet.noneOf(BuiltinDigests.class);
- Field[] fields = BuiltinDigests.Constants.class.getFields();
- for (Field f : fields) {
- String name = (String) f.get(null);
- BuiltinDigests value = BuiltinDigests.fromFactoryName(name);
- assertNotNull("No match found for " + name, value);
- assertTrue(name + " re-specified", avail.add(value));
- }
-
- assertEquals("Incomplete coverage", BuiltinDigests.VALUES, avail);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java
index 1425400..86c8c93 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java
@@ -37,8 +37,8 @@ import java.util.Objects;
import java.util.Random;
import java.util.TreeSet;
+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;
@@ -67,7 +67,7 @@ public class RootedFileSystemProviderTest extends AssertableFile {
@BeforeClass
public static void initializeFileSystem() throws IOException {
Path targetFolder = Objects.requireNonNull(
- Utils.detectTargetFolder(RootedFileSystemProviderTest.class), "Failed to detect target folder").toPath();
+ CommonTestSupportUtils.detectTargetFolder(RootedFileSystemProviderTest.class), "Failed to detect target folder").toPath();
rootSandbox = FileHelper.createTestSandbox(targetFolder.resolve(TEMP_SUBFOLDER_NAME));
fileSystem = (RootedFileSystem) new RootedFileSystemProvider().newFileSystem(rootSandbox, Collections.emptyMap());
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
index c68e445..8fbf0ce 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java
@@ -51,9 +51,9 @@ import org.apache.sshd.common.util.net.SshdSocketAddress;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.apache.sshd.util.test.JSchLogger;
import org.apache.sshd.util.test.SimpleUserInfo;
-import org.apache.sshd.util.test.Utils;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
@@ -365,7 +365,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
ss.setReuseAddress(true);
ss.bind(new InetSocketAddress((InetAddress) null, 0));
int forwardedPort = ss.getLocalPort();
- int sinkPort = Utils.getFreePort();
+ int sinkPort = CoreTestSupportUtils.getFreePort();
session.setPortForwardingR(sinkPort, TEST_LOCALHOST, forwardedPort);
final boolean started[] = new boolean[1];
started[0] = false;
@@ -493,7 +493,7 @@ public class PortForwardingLoadTest extends BaseTestSupport {
Session session = createSession();
try {
final int forwardedPort1 = session.setPortForwardingL(0, host, port);
- final int forwardedPort2 = Utils.getFreePort();
+ final int forwardedPort2 = CoreTestSupportUtils.getFreePort();
session.setPortForwardingR(forwardedPort2, TEST_LOCALHOST, forwardedPort1);
outputDebugMessage("URL: http://localhost %s", forwardedPort2);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
index 79bc2db..3cd904f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java
@@ -58,9 +58,9 @@ import org.apache.sshd.server.forward.AcceptAllForwardingFilter;
import org.apache.sshd.server.global.CancelTcpipForwardHandler;
import org.apache.sshd.server.global.TcpipForwardHandler;
import org.apache.sshd.util.test.BaseTestSupport;
+import org.apache.sshd.util.test.CoreTestSupportUtils;
import org.apache.sshd.util.test.JSchLogger;
import org.apache.sshd.util.test.SimpleUserInfo;
-import org.apache.sshd.util.test.Utils;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
@@ -157,7 +157,7 @@ public class PortForwardingTest extends BaseTestSupport {
@BeforeClass
public static void setUpTestEnvironment() throws Exception {
JSchLogger.init();
- sshd = Utils.setupTestServer(PortForwardingTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(PortForwardingTest.class);
PropertyResolverUtils.updateProperty(sshd, FactoryManager.WINDOW_SIZE, 2048);
PropertyResolverUtils.updateProperty(sshd, FactoryManager.MAX_PACKET_SIZE, 256);
sshd.setForwardingFilter(AcceptAllForwardingFilter.INSTANCE);
@@ -221,7 +221,7 @@ public class PortForwardingTest extends BaseTestSupport {
acceptor.bind(new InetSocketAddress(0));
echoPort = acceptor.getLocalAddress().getPort();
- client = Utils.setupTestClient(PortForwardingTest.class);
+ client = CoreTestSupportUtils.setupTestClient(PortForwardingTest.class);
client.start();
}
@@ -262,7 +262,7 @@ public class PortForwardingTest extends BaseTestSupport {
public void testRemoteForwarding() throws Exception {
Session session = createSession();
try {
- int forwardedPort = Utils.getFreePort();
+ int forwardedPort = CoreTestSupportUtils.getFreePort();
session.setPortForwardingR(forwardedPort, TEST_LOCALHOST, echoPort);
waitForForwardingRequest(TcpipForwardHandler.REQUEST, TimeUnit.SECONDS.toMillis(5L));
@@ -293,7 +293,7 @@ public class PortForwardingTest extends BaseTestSupport {
public void testRemoteForwardingSecondTimeInSameSession() throws Exception {
Session session = createSession();
try {
- int forwardedPort = Utils.getFreePort();
+ int forwardedPort = CoreTestSupportUtils.getFreePort();
session.setPortForwardingR(forwardedPort, TEST_LOCALHOST, echoPort);
waitForForwardingRequest(TcpipForwardHandler.REQUEST, TimeUnit.SECONDS.toMillis(5L));
@@ -465,7 +465,7 @@ public class PortForwardingTest extends BaseTestSupport {
public void testLocalForwarding() throws Exception {
Session session = createSession();
try {
- int forwardedPort = Utils.getFreePort();
+ int forwardedPort = CoreTestSupportUtils.getFreePort();
session.setPortForwardingL(forwardedPort, TEST_LOCALHOST, echoPort);
try (Socket s = new Socket(TEST_LOCALHOST, forwardedPort);
@@ -674,7 +674,7 @@ public class PortForwardingTest extends BaseTestSupport {
Session session = createSession();
try {
// 1. Create a Port Forward
- int forwardedPort = Utils.getFreePort();
+ int forwardedPort = CoreTestSupportUtils.getFreePort();
session.setPortForwardingR(forwardedPort, TEST_LOCALHOST, echoPort);
waitForForwardingRequest(TcpipForwardHandler.REQUEST, TimeUnit.SECONDS.toMillis(5L));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java b/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java
deleted file mode 100644
index 0b5ec12..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java
+++ /dev/null
@@ -1,137 +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.future;
-
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-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;
-import org.mockito.Mockito;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class DefaultSshFutureTest extends BaseTestSupport {
- public DefaultSshFutureTest() {
- super();
- }
-
- @Test
- @SuppressWarnings("rawtypes")
- public void testAwaitUninterrupted() {
- DefaultSshFuture future = new DefaultSshFuture(getCurrentTestName(), null);
- Object expected = new Object();
- new Thread() {
- @Override
- public void run() {
- try {
- Thread.sleep(TimeUnit.SECONDS.toMillis(2L));
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- future.setValue(expected);
- }
- }.start();
-
- future.awaitUninterruptibly();
- assertSame("Mismatched signalled value", expected, future.getValue());
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void testNotifyMultipleListeners() {
- DefaultSshFuture future = new DefaultSshFuture(getCurrentTestName(), null);
- AtomicInteger listenerCount = new AtomicInteger(0);
- Object expected = new Object();
- SshFutureListener listener = f -> {
- assertSame("Mismatched future instance", future, f);
- assertSame("Mismatched value object", expected, future.getValue());
- listenerCount.incrementAndGet();
- };
-
- int numListeners = Byte.SIZE;
- for (int index = 0; index < numListeners; index++) {
- future.addListener(listener);
- }
-
- future.setValue(expected);
- assertEquals("Mismatched listeners invocation count", numListeners, listenerCount.get());
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void testListenerInvokedDirectlyAfterResultSet() {
- DefaultSshFuture future = new DefaultSshFuture(getCurrentTestName(), null);
- AtomicInteger listenerCount = new AtomicInteger(0);
- Object expected = new Object();
- SshFutureListener listener = f -> {
- assertSame("Mismatched future instance", future, f);
- assertSame("Mismatched value object", expected, future.getValue());
- listenerCount.incrementAndGet();
- };
- future.setValue(expected);
-
- future.addListener(listener);
- assertEquals("Mismatched number of registered listeners", 0, future.getNumRegisteredListeners());
- assertEquals("Listener not invoked", 1, listenerCount.get());
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void testAddAndRemoveRegisteredListenersBeforeResultSet() {
- DefaultSshFuture future = new DefaultSshFuture(getCurrentTestName(), null);
- SshFutureListener listener = Mockito.mock(SshFutureListener.class);
- for (int index = 1; index <= Byte.SIZE; index++) {
- future.addListener(listener);
- assertEquals("Mismatched number of added listeners", index, future.getNumRegisteredListeners());
- }
-
- for (int index = future.getNumRegisteredListeners() - 1; index >= 0; index--) {
- future.removeListener(listener);
- assertEquals("Mismatched number of remaining listeners", index, future.getNumRegisteredListeners());
- }
- }
-
- @Test
- @SuppressWarnings({ "rawtypes", "unchecked" })
- public void testListenerNotRemovedIfResultSet() {
- DefaultSshFuture future = new DefaultSshFuture(getCurrentTestName(), null);
- AtomicInteger listenerCount = new AtomicInteger(0);
- Object expected = new Object();
- SshFutureListener listener = f -> {
- assertSame("Mismatched future instance", future, f);
- assertSame("Mismatched value object", expected, future.getValue());
- listenerCount.incrementAndGet();
- };
- future.addListener(listener);
- future.setValue(expected);
- assertEquals("Mismatched number of registered listeners", 1, future.getNumRegisteredListeners());
- assertEquals("Listener not invoked", 1, listenerCount.get());
-
- future.removeListener(listener);
- assertEquals("Mismatched number of remaining listeners", 1, future.getNumRegisteredListeners());
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java
deleted file mode 100644
index 1c1bb9f..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.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.common.keyprovider;
-
-import java.security.KeyPair;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.function.Function;
-
-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;
-import org.mockito.Mockito;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class KeyPairProviderTest extends BaseTestSupport {
- public KeyPairProviderTest() {
- super();
- }
-
- @Test
- public void testEmptyKeyProvider() {
- KeyPairProvider provider = KeyPairProvider.EMPTY_KEYPAIR_PROVIDER;
- assertTrue("Non empty loaded keys", GenericUtils.isEmpty(provider.loadKeys()));
- assertTrue("Non empty key type", GenericUtils.isEmpty(provider.getKeyTypes()));
-
- for (String keyType : new String[]{null, "", getCurrentTestName()}) {
- assertNull("Unexpected key-pair loaded for type='" + keyType + "'", provider.loadKey(keyType));
- }
- }
-
- @Test
- public void testMapToKeyPairProvider() {
- PublicKey pubKey = Mockito.mock(PublicKey.class);
- PrivateKey prvKey = Mockito.mock(PrivateKey.class);
- String[] testKeys = {getCurrentTestName(), getClass().getSimpleName()};
- Map<String, KeyPair> pairsMap = GenericUtils.toSortedMap(
- Arrays.asList(testKeys),
- Function.identity(),
- k -> new KeyPair(pubKey, prvKey),
- String.CASE_INSENSITIVE_ORDER);
-
- KeyPairProvider provider = MappedKeyPairProvider.MAP_TO_KEY_PAIR_PROVIDER.apply(pairsMap);
- assertEquals("Key types", pairsMap.keySet(), provider.getKeyTypes());
- assertEquals("Key pairs", pairsMap.values(), provider.loadKeys());
-
- pairsMap.forEach((keyType, expected) -> {
- KeyPair actual = provider.loadKey(keyType);
- assertSame(keyType, expected, actual);
- });
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java
deleted file mode 100644
index ab9e7ae..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java
+++ /dev/null
@@ -1,166 +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.mac;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.EnumSet;
-import java.util.List;
-import java.util.Random;
-import java.util.Set;
-
-import org.apache.sshd.common.NamedResource;
-import org.apache.sshd.common.mac.BuiltinMacs.ParseResult;
-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;
-import org.mockito.Mockito;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class BuiltinMacsTest extends BaseTestSupport {
- public BuiltinMacsTest() {
- super();
- }
-
- @Test
- public void testFromName() {
- for (BuiltinMacs expected : BuiltinMacs.VALUES) {
- String name = expected.getName();
- BuiltinMacs actual = BuiltinMacs.fromFactoryName(name);
- assertSame(name, expected, actual);
- }
- }
-
- @Test
- public void testAllConstantsCovered() throws Exception {
- Set<BuiltinMacs> avail = EnumSet.noneOf(BuiltinMacs.class);
- Field[] fields = BuiltinMacs.Constants.class.getFields();
- for (Field f : fields) {
- String name = (String) f.get(null);
- BuiltinMacs value = BuiltinMacs.fromFactoryName(name);
- assertNotNull("No match found for " + name, value);
- assertTrue(name + " re-specified", avail.add(value));
- }
-
- assertEquals("Incomplete coverage", BuiltinMacs.VALUES, avail);
- }
-
- @Test
- public void testParseMacsList() {
- List<String> builtin = NamedResource.getNameList(BuiltinMacs.VALUES);
- List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName());
- Random rnd = new Random();
- for (int index = 0; index < (builtin.size() + unknown.size()); index++) {
- Collections.shuffle(builtin, rnd);
- Collections.shuffle(unknown, rnd);
-
- List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size());
- for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) {
- boolean useBuiltin = false;
- if (bIndex < builtin.size()) {
- useBuiltin = uIndex >= unknown.size() || rnd.nextBoolean();
- }
-
- if (useBuiltin) {
- weavedList.add(builtin.get(bIndex));
- bIndex++;
- } else if (uIndex < unknown.size()) {
- weavedList.add(unknown.get(uIndex));
- uIndex++;
- }
- }
-
- String fullList = GenericUtils.join(weavedList, ',');
- ParseResult result = BuiltinMacs.parseMacsList(fullList);
- List<String> parsed = NamedResource.getNameList(result.getParsedFactories());
- List<String> missing = result.getUnsupportedFactories();
-
- // makes sure not only that the contents are the same but also the order
- assertListEquals(fullList + "[parsed]", builtin, parsed);
- assertListEquals(fullList + "[unsupported]", unknown, missing);
- }
- }
-
- @Test
- public void testResolveFactoryOnBuiltinValues() {
- for (MacFactory expected : BuiltinMacs.VALUES) {
- String name = expected.getName();
- MacFactory actual = BuiltinMacs.resolveFactory(name);
- assertSame(name, expected, actual);
- }
- }
-
- @Test
- public void testNotAllowedToRegisterBuiltinFactories() {
- for (MacFactory expected : BuiltinMacs.VALUES) {
- try {
- BuiltinMacs.registerExtension(expected);
- fail("Unexpected success for " + expected.getName());
- } catch (IllegalArgumentException e) {
- // expected - ignored
- }
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNotAllowedToOverrideRegisteredFactories() {
- MacFactory expected = Mockito.mock(MacFactory.class);
- Mockito.when(expected.getName()).thenReturn(getCurrentTestName());
-
- String name = expected.getName();
- try {
- for (int index = 1; index <= Byte.SIZE; index++) {
- BuiltinMacs.registerExtension(expected);
- assertEquals("Unexpected success at attempt #" + index, 1, index);
- }
- } finally {
- BuiltinMacs.unregisterExtension(name);
- }
- }
-
- @Test
- public void testResolveFactoryOnRegisteredExtension() {
- MacFactory expected = Mockito.mock(MacFactory.class);
- Mockito.when(expected.getName()).thenReturn(getCurrentTestName());
-
- String name = expected.getName();
- try {
- assertNull("Extension already registered", BuiltinMacs.resolveFactory(name));
- BuiltinMacs.registerExtension(expected);
-
- MacFactory actual = BuiltinMacs.resolveFactory(name);
- assertSame("Mismatched resolved instance", expected, actual);
- } finally {
- MacFactory actual = BuiltinMacs.unregisterExtension(name);
- assertSame("Mismatched unregistered instance", expected, actual);
- assertNull("Extension not un-registered", BuiltinMacs.resolveFactory(name));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
index 823955b..4d3bfa8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java
@@ -32,10 +32,11 @@ import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.util.GenericUtils;
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.Before;
@@ -115,8 +116,8 @@ public class MacTest extends BaseTestSupport {
public static void setupClientAndServer() throws Exception {
JSchLogger.init();
- sshd = Utils.setupTestServer(MacTest.class);
- sshd.setKeyPairProvider(Utils.createTestHostKeyProvider(MacTest.class));
+ sshd = CoreTestSupportUtils.setupTestServer(MacTest.class);
+ sshd.setKeyPairProvider(CommonTestSupportUtils.createTestHostKeyProvider(MacTest.class));
sshd.start();
port = sshd.getPort();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
deleted file mode 100644
index 4887099..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacVectorsTest.java
+++ /dev/null
@@ -1,311 +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.mac;
-
-import java.nio.charset.StandardCharsets;
-import java.util.AbstractMap.SimpleImmutableEntry;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-
-import org.apache.sshd.common.Factory;
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.ValidateUtils;
-import org.apache.sshd.common.util.buffer.BufferUtils;
-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;
-
-/**
- * @see <A HREF="https://tools.ietf.org/html/rfc4231">RFC 4321</A>
- * @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 MacVectorsTest extends BaseTestSupport {
- private final VectorSeed seed;
- private final Factory<? extends Mac> macFactory;
- private final byte[] expected;
-
- public MacVectorsTest(VectorSeed seed, String factoryName, String expected) {
- this.seed = Objects.requireNonNull(seed, "No seed");
- this.macFactory = ValidateUtils.checkNotNull(BuiltinMacs.fromFactoryName(factoryName), "Unknown MAC: %s", factoryName);
- this.expected = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, expected);
- }
-
- @Parameters(name = "factory={1}, expected={2}, seed={0}")
- public static Collection<Object[]> parameters() {
- List<Object[]> ret = new ArrayList<>();
- for (VectorTestData vector : Collections.unmodifiableList(
- Arrays.asList(
- ///////////////// Test Cases for HMAC-MD5 ///////////////////////
- // see https://tools.ietf.org/html/rfc2202
- new VectorTestData("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", false, "Hi There",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 1
- "9294727a3638bb1c13f48ef8158bfc9d"))),
- new VectorTestData("Jefe", "what do ya want for nothing?",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 2
- "750c783e6ab0b503eaa86e310a5db738"))),
- new VectorTestData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false, repeat("dd", 50), false,
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 3
- "56be34521d144c88dbb8c733f0e8b3f6"))),
- /* TODO see why it fails
- new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 4
- "697eaf0aca3a3aea3a75164746ffaa79"))),
- */
- new VectorTestData("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", false, "Test With Truncation",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 5
- "56461ef2342edc00f9bab995690efd4c"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5_96,
- "56461ef2342edc00f9bab995"))),
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 6
- "6b1ab7fe4bd7bf8f0b62e6ce61b9d0cd"))),
- */
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_MD5, // test case 7
- "6f630fad67cda0ee1fb1f562db3aa53e"))),
- */
- ///////////////// Test Cases for HMAC-SHA-1 ///////////////////////
- // see https://tools.ietf.org/html/rfc2202
- new VectorTestData("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b", false, "Hi There",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 1
- "b617318655057264e28bc0b6fb378c8ef146be00"))),
- new VectorTestData("Jefe", "what do ya want for nothing?",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 2
- "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79"))),
- new VectorTestData("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", false, repeat("dd", 50), false,
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 3
- "125d7342b9ac11cd91a39af48aa17b4f63f175d3"))),
- /* TODO see why it fails
- new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 4
- "4c9007f4026250c6bc8414f9bf50c86c2d7235da"))),
- */
- new VectorTestData("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c", false, "Test With Truncation",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 5
- "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1_96,
- "4c1a03424b55e07fe7f27be1"))),
- /* TODO see why this fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 6
- "aa4ae5e15272d00e95705637ce8a3b55ed402112"))),
- */
-
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 7
- "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1_96,
- "4c1a03424b55e07fe7f27be1"))),
- */
-
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 8
- "aa4ae5e15272d00e95705637ce8a3b55ed402112"))),
- */
-
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 80), false, "Test Using Larger Than Block-Size Key and Larger Than One Block-Size Data",
- Arrays.asList(new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA1, // test case 9
- "e8e99d0f45237d786d6bbaa7965c7808bbff1a91"))),
- */
-
- ///////////////// Test Cases for HMAC-SHA-2 ///////////////////////
- // see https://tools.ietf.org/html/rfc4231
- new VectorTestData(repeat("0b", 20), false, "Hi There",
- // test case 1
- Arrays.asList(
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854"))),
- new VectorTestData("Jefe", "what do ya want for nothing?",
- // test case 2
- Arrays.asList(
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737"))),
- new VectorTestData(repeat("aa", 20), false, repeat("dd", 50), false,
- // test case 3
- Arrays.asList(
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb"))),
- new VectorTestData("0102030405060708090a0b0c0d0e0f10111213141516171819", false, repeat("cd", 50), false,
- // test case 4
- Arrays.asList(
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd"))),
-
- /* TODO see why it fails
- new VectorTestData(repeat("0c", 20), false, "Test With Truncation",
- Arrays.asList( // test case 5
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "a3b6167473100ee06e0c796c2955552b"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "415fad6271580a531d4179bc891d87a6"))),
- */
-
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 131), false, "Test Using Larger Than Block-Size Key - Hash Key First",
- Arrays.asList( // test case 6
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598"))),
- */
-
- /* TODO see why it fails
- new VectorTestData(repeat("aa", 131), false, "This is a test using a larger than block-size"
- + " key and a larger than block-size data."
- + " The key needs to be hashed before being used"
- + " by the HMAC algorithm",
- Arrays.asList( // test case 7
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_256,
- "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2"),
- new SimpleImmutableEntry<>(BuiltinMacs.Constants.HMAC_SHA2_512,
- "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58")))
- */
-
- // mark end
- new VectorTestData("", false, "", false, Collections.emptyList())))) {
- for (Map.Entry<String, String> tc : vector.getResults()) {
- ret.add(new Object[]{vector, tc.getKey(), tc.getValue()});
- }
- }
-
- return ret;
- }
-
- @Test
- public void testStandardVectorMac() throws Exception {
- Mac mac = macFactory.create();
- mac.init(seed.getKey());
- mac.update(seed.getData());
-
- byte[] actual = new byte[mac.getBlockSize()];
- mac.doFinal(actual);
- assertArrayEquals("Mismatched results for actual=" + BufferUtils.toHex(BufferUtils.EMPTY_HEX_SEPARATOR, actual), expected, actual);
- }
-
- private static class VectorSeed {
- private final byte[] key;
- private final String keyString;
- private final byte[] data;
- private final String dataString;
-
- VectorSeed(String key, String data) {
- this.key = key.getBytes(StandardCharsets.UTF_8);
- this.keyString = key;
- this.data = data.getBytes(StandardCharsets.UTF_8);
- this.dataString = data;
- }
-
- VectorSeed(String key, boolean useKeyString, String data) {
- this.key = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, key);
- this.keyString = useKeyString ? new String(this.key, StandardCharsets.UTF_8) : key;
- this.data = data.getBytes(StandardCharsets.UTF_8);
- this.dataString = data;
- }
-
- VectorSeed(String key, boolean useKeyString, String data, boolean useDataString) {
- this.key = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, key);
- this.keyString = useKeyString ? new String(this.key, StandardCharsets.UTF_8) : key;
- this.data = BufferUtils.decodeHex(BufferUtils.EMPTY_HEX_SEPARATOR, data);
- this.dataString = useDataString ? new String(this.data, StandardCharsets.UTF_8) : data;
- }
-
- public byte[] getKey() {
- return key.clone(); // clone to avoid inadvertent change
- }
-
- public String getKeyString() {
- return keyString;
- }
-
- public byte[] getData() {
- return data.clone(); // clone to avoid inadvertent change
- }
-
- public String getDataString() {
- return dataString;
- }
-
- @Override
- public String toString() {
- return "key=" + trimToLength(getKeyString(), 32) + ", data=" + trimToLength(getDataString(), 32);
- }
-
- private static CharSequence trimToLength(CharSequence csq, int maxLen) {
- if (GenericUtils.length(csq) <= maxLen) {
- return csq;
- }
-
- return csq.subSequence(0, maxLen) + "...";
- }
- }
-
- private static class VectorTestData extends VectorSeed {
- private final Collection<Map.Entry<String, String>> results;
-
- VectorTestData(String key, String data, Collection<Map.Entry<String, String>> results) {
- super(key, data);
- this.results = results;
- }
-
- VectorTestData(String key, boolean useKeyString, String data, Collection<Map.Entry<String, String>> results) {
- super(key, useKeyString, data);
- this.results = results;
- }
-
- VectorTestData(String key, boolean useKeyString, String data, boolean useDataString, Collection<Map.Entry<String, String>> results) {
- super(key, useKeyString, data, useDataString);
- this.results = results;
- }
-
- public Collection<Map.Entry<String, String>> getResults() {
- return results;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
deleted file mode 100644
index f3f1634..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/random/RandomFactoryTest.java
+++ /dev/null
@@ -1,83 +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.random;
-
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.apache.sshd.util.test.JUnit4ClassRunnerWithParametersFactory;
-import org.apache.sshd.util.test.NoIoTestCase;
-import org.junit.Assume;
-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 RandomFactoryTest extends BaseTestSupport {
- private final RandomFactory factory;
-
- public RandomFactoryTest(RandomFactory factory) {
- this.factory = factory;
- }
-
- @Parameters(name = "type={0}")
- public static Collection<Object[]> parameters() {
- Collection<RandomFactory> testCases = new LinkedList<>();
- testCases.add(JceRandomFactory.INSTANCE);
- if (SecurityUtils.isBouncyCastleRegistered()) {
- testCases.add(SecurityUtils.getRandomFactory());
- } else {
- System.out.println("Skip BouncyCastleRandomFactory - unsupported");
- }
-
- return parameterize(testCases);
- }
-
- @Test
- public void testRandomFactory() {
- Assume.assumeTrue("Skip unsupported factory: " + factory.getName(), factory.isSupported());
- long t = testRandom(factory.create());
- System.out.println(factory.getName() + " duration: " + t + " " + TimeUnit.MICROSECONDS);
- }
-
- // returns duration in microseconds
- private static long testRandom(Random random) {
- byte[] bytes = new byte[32];
- long l0 = System.nanoTime();
- for (int i = 0; i < 1000; i++) {
- random.fill(bytes, 8, 16);
- }
- long l1 = System.nanoTime();
- return TimeUnit.NANOSECONDS.toMicros(l1 - l0);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
index 83a183e..4c56d14 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java
@@ -406,7 +406,7 @@ public class AbstractSessionTest extends BaseTestSupport {
public static class MySession extends AbstractSession {
public MySession() {
- super(true, org.apache.sshd.util.test.Utils.setupTestServer(AbstractSessionTest.class), new MyIoSession());
+ super(true, org.apache.sshd.util.test.CoreTestSupportUtils.setupTestServer(AbstractSessionTest.class), new MyIoSession());
}
@Override
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java
deleted file mode 100644
index 458abfc..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java
+++ /dev/null
@@ -1,149 +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.signature;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Random;
-
-import org.apache.sshd.common.NamedResource;
-import org.apache.sshd.common.signature.BuiltinSignatures.ParseResult;
-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;
-import org.mockito.Mockito;
-
-/**
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-@FixMethodOrder(MethodSorters.NAME_ASCENDING)
-@Category({ NoIoTestCase.class })
-public class BuiltinSignaturesTest extends BaseTestSupport {
- public BuiltinSignaturesTest() {
- super();
- }
-
- @Test
- public void testFromName() {
- for (BuiltinSignatures expected : BuiltinSignatures.VALUES) {
- String name = expected.getName();
- BuiltinSignatures actual = BuiltinSignatures.fromFactoryName(name);
- assertSame(name, expected, actual);
- }
- }
-
- @Test
- public void testParseSignaturesList() {
- List<String> builtin = NamedResource.getNameList(BuiltinSignatures.VALUES);
- List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName());
- Random rnd = new Random();
- for (int index = 0; index < (builtin.size() + unknown.size()); index++) {
- Collections.shuffle(builtin, rnd);
- Collections.shuffle(unknown, rnd);
-
- List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size());
- for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) {
- boolean useBuiltin = false;
- if (bIndex < builtin.size()) {
- useBuiltin = uIndex >= unknown.size() || rnd.nextBoolean();
- }
-
- if (useBuiltin) {
- weavedList.add(builtin.get(bIndex));
- bIndex++;
- } else if (uIndex < unknown.size()) {
- weavedList.add(unknown.get(uIndex));
- uIndex++;
- }
- }
-
- String fullList = GenericUtils.join(weavedList, ',');
- ParseResult result = BuiltinSignatures.parseSignatureList(fullList);
- List<String> parsed = NamedResource.getNameList(result.getParsedFactories());
- List<String> missing = result.getUnsupportedFactories();
-
- // makes sure not only that the contents are the same but also the order
- assertListEquals(fullList + "[parsed]", builtin, parsed);
- assertListEquals(fullList + "[unsupported]", unknown, missing);
- }
- }
-
- @Test
- public void testResolveFactoryOnBuiltinValues() {
- for (SignatureFactory expected : BuiltinSignatures.VALUES) {
- String name = expected.getName();
- SignatureFactory actual = BuiltinSignatures.resolveFactory(name);
- assertSame(name, expected, actual);
- }
- }
-
- @Test
- public void testNotAllowedToRegisterBuiltinFactories() {
- for (SignatureFactory expected : BuiltinSignatures.VALUES) {
- try {
- BuiltinSignatures.registerExtension(expected);
- fail("Unexpected success for " + expected.getName());
- } catch (IllegalArgumentException e) {
- // expected - ignored
- }
- }
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void testNotAllowedToOverrideRegisteredFactories() {
- SignatureFactory expected = Mockito.mock(SignatureFactory.class);
- Mockito.when(expected.getName()).thenReturn(getCurrentTestName());
-
- String name = expected.getName();
- try {
- for (int index = 1; index <= Byte.SIZE; index++) {
- BuiltinSignatures.registerExtension(expected);
- assertEquals("Unexpected success at attempt #" + index, 1, index);
- }
- } finally {
- BuiltinSignatures.unregisterExtension(name);
- }
- }
-
- @Test
- public void testResolveFactoryOnRegisteredExtension() {
- SignatureFactory expected = Mockito.mock(SignatureFactory.class);
- Mockito.when(expected.getName()).thenReturn(getCurrentTestName());
-
- String name = expected.getName();
- try {
- assertNull("Extension already registered", BuiltinSignatures.resolveFactory(name));
- BuiltinSignatures.registerExtension(expected);
-
- SignatureFactory actual = BuiltinSignatures.resolveFactory(name);
- assertSame("Mismatched resolved instance", expected, actual);
- } finally {
- SignatureFactory actual = BuiltinSignatures.unregisterExtension(name);
- assertSame("Mismatched unregistered instance", expected, actual);
- assertNull("Extension not un-registered", BuiltinSignatures.resolveFactory(name));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureDSATest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureDSATest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureDSATest.java
deleted file mode 100644
index 0998bbd..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureDSATest.java
+++ /dev/null
@@ -1,109 +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.signature;
-
-import java.math.BigInteger;
-import java.security.GeneralSecurityException;
-import java.security.KeyFactory;
-import java.security.spec.DSAPublicKeySpec;
-
-import org.apache.sshd.common.config.keys.KeyUtils;
-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.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 SignatureDSATest extends BaseTestSupport {
- public SignatureDSATest() {
- super();
- }
-
- @Test
- public void testTooShortSignature() throws Exception {
- KeyFactory kf = SecurityUtils.getKeyFactory(KeyUtils.DSS_ALGORITHM);
- SignatureDSA signatureDSA = new SignatureDSA(KeyUtils.DSS_ALGORITHM) {
- @Override
- protected java.security.Signature doInitSignature(String algo, boolean forSigning) throws GeneralSecurityException {
- return java.security.Signature.getInstance(algo);
-
- }
- };
-
- byte[] y = new byte[] {
- 0, -92, 59, 5, 72, 124, 101, 124, -18, 114, 7, 100, 98, -61, 73, -104,
- 120, -98, 54, 118, 17, -62, 91, -110, 29, 98, 50, -101, -41, 99, -116,
- 101, 107, -123, 124, -97, 62, 119, 88, -109, -110, -1, 109, 119, -51,
- 69, -98, -105, 2, -69, -121, -82, -118, 23, -6, 96, -61, -65, 102, -58,
- -74, 32, -104, 116, -6, -35, -83, -10, -88, -68, 106, -112, 72, -2, 35,
- 38, 15, -11, -22, 30, -114, -46, -47, -18, -17, -71, 24, -25, 28, 13, 29,
- -40, 101, 18, 81, 45, -120, -67, -53, -41, 11, 50, -89, -33, 50, 54, -14,
- -91, -35, 12, -42, 13, -84, -19, 100, -3, -85, -18, 74, 99, -49, 64, -49,
- 51, -83, -82, -127, 116, 64 };
- byte[] p = new byte[] {
- 0, -3, 127, 83, -127, 29, 117, 18, 41, 82, -33, 74, -100, 46, -20, -28,
- -25, -10, 17, -73, 82, 60, -17, 68, 0, -61, 30, 63, -128, -74, 81, 38,
- 105, 69, 93, 64, 34, 81, -5, 89, 61, -115, 88, -6, -65, -59, -11, -70,
- 48, -10, -53, -101, 85, 108, -41, -127, 59, -128, 29, 52, 111, -14, 102,
- 96, -73, 107, -103, 80, -91, -92, -97, -97, -24, 4, 123, 16, 34, -62, 79,
- -69, -87, -41, -2, -73, -58, 27, -8, 59, 87, -25, -58, -88, -90, 21, 15, 4,
- -5, -125, -10, -45, -59, 30, -61, 2, 53, 84, 19, 90, 22, -111, 50, -10, 117,
- -13, -82, 43, 97, -41, 42, -17, -14, 34, 3, 25, -99, -47, 72, 1, -57 };
- byte[] q = new byte[] {
- 0, -105, 96, 80, -113, 21, 35, 11, -52, -78, -110, -71, -126, -94, -21,
- -124, 11, -16, 88, 28, -11 };
- byte[] g = new byte[] {
- 0, -9, -31, -96, -123, -42, -101, 61, -34, -53, -68, -85, 92, 54, -72, 87,
- -71, 121, -108, -81, -69, -6, 58, -22, -126, -7, 87, 76, 11, 61, 7, -126,
- 103, 81, 89, 87, -114, -70, -44, 89, 79, -26, 113, 7, 16, -127, -128, -76,
- 73, 22, 113, 35, -24, 76, 40, 22, 19, -73, -49, 9, 50, -116, -56, -90, -31,
- 60, 22, 122, -117, 84, 124, -115, 40, -32, -93, -82, 30, 43, -77, -90, 117,
- -111, 110, -93, 127, 11, -6, 33, 53, 98, -15, -5, 98, 122, 1, 36, 59, -52,
- -92, -15, -66, -88, 81, -112, -119, -88, -125, -33, -31, 90, -27, -97, 6,
- -110, -117, 102, 94, -128, 123, 85, 37, 100, 1, 76, 59, -2, -49, 73, 42 };
-
- BigInteger bigY = new BigInteger(y);
- BigInteger bigP = new BigInteger(p);
- BigInteger bigQ = new BigInteger(q);
- BigInteger bigG = new BigInteger(g);
-
- DSAPublicKeySpec dsaPublicKey = new DSAPublicKeySpec(bigY, bigP, bigQ, bigG);
- signatureDSA.initVerifier(kf.generatePublic(dsaPublicKey));
- byte[] h = new byte[] {
- -4, 111, -103, 111, 72, -106, 105, -19, 81, -123, 84, -13, -40, -53, -3,
- -97, -8, 43, -22, -2, -23, -15, 28, 116, -63, 96, -79, -127, -84, 63, -6, -94 };
- signatureDSA.update(h);
-
- byte[] sig_of_h = new byte[] {
- 0, 0, 0, 7, 115, 115, 104, 45, 100, 115, 115, 0, 0, 0, 40, 0, 79,
- 84, 118, -50, 11, -117, -112, 52, -25, -78, -50, -20, 6, -69, -26,
- 7, 90, -34, -124, 80, 76, -32, -23, -8, 43, 38, -48, -89, -17, -60,
- -1, -78, 112, -88, 14, -39, -78, -98, -80 };
- boolean verified = signatureDSA.verify(sig_of_h);
-
- assertTrue(verified);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureFactoriesTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureFactoriesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureFactoriesTest.java
index 8b2943b..0733967 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureFactoriesTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureFactoriesTest.java
@@ -43,8 +43,8 @@ import org.apache.sshd.common.util.ValidateUtils;
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.Utils;
import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.BeforeClass;
@@ -122,11 +122,11 @@ public class SignatureFactoriesTest extends BaseTestSupport implements OptionalF
@BeforeClass
public static void setupClientAndServer() throws Exception {
- sshd = Utils.setupTestServer(SignatureFactoriesTest.class);
+ sshd = CoreTestSupportUtils.setupTestServer(SignatureFactoriesTest.class);
sshd.start();
port = sshd.getPort();
- client = Utils.setupTestClient(SignatureFactoriesTest.class);
+ client = CoreTestSupportUtils.setupTestClient(SignatureFactoriesTest.class);
client.start();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
deleted file mode 100644
index 6f0cb6e..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignatureRSATest.java
+++ /dev/null
@@ -1,119 +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.signature;
-
-import java.math.BigInteger;
-import java.security.GeneralSecurityException;
-import java.security.KeyFactory;
-import java.security.Provider;
-import java.security.PublicKey;
-import java.security.spec.RSAPublicKeySpec;
-import java.util.Base64;
-import java.util.Map;
-
-import org.apache.sshd.common.Factory;
-import org.apache.sshd.common.config.keys.KeyUtils;
-import org.apache.sshd.common.util.security.SecurityUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-import org.junit.BeforeClass;
-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 SignatureRSATest extends BaseTestSupport {
- private static final Base64.Decoder B64_DECODER = Base64.getDecoder();
- @SuppressWarnings("checkstyle:linelength")
- private static final byte[] TEST_MSG =
- B64_DECODER.decode("AAAAFPHgK1MeV9zNnok3pwNJhCd8SONqMgAAAAlidWlsZHVzZXIAAAAOc3NoLWNvbm5lY3Rpb24AAAAJcHVibGlja2V5AQAAAAdzc2gtcnNhAAABFQAAAAdzc2gtcnNhAAAAASMAAAEBAMs9HO/NH/Now+6fSnESebaG4wzaYQWA1b/q1TGV1wHNtCg9fGFGVSKs0VxKF4cfVyrSLtgLjnlXQTn+Lm7xiYKGbBbsTQWOqEDaBVBsRbAkxIkpuvr6/EBxwrtDbKmSQYTJZVJSD2bZRYjGsR9gpZXPorOOKFd5EPCMHXsqnhp2hidTGH7cK6RuLk7MNnPISsY0Nbx8/ZvikiPROGcoTZ8bzUv4IaLr3veW6epSeQem8tJqhnrpTHhbLU99zf045M0Gsnk/azjjlBM+qrHZ5FNdC1kowJnLtf2Oy/rUQNpkGJtcBPT8xvreV0wLsn9t3hSxzsc0+VkDNTQRlfU+o3M=");
- @SuppressWarnings("checkstyle:linelength")
- private static final byte[] TEST_SIGNATURE =
- B64_DECODER.decode("AAAAB3NzaC1yc2EAAAD/+Ntnf4qfr2J1voDS6I+u3VRjtMn+LdWJsAZfkLDxRkK1rQxP7QAjLdNqpT4CkWHp8dtoTGFlBFt6NieNJCMTA2KSOxJMZKsX7e/lHkh7C+vhQvJ9eLTKWjCxSFUrcM0NvFhmwbRCffwXSHvAKak4wbmofxQMpd+G4jZkNMz5kGpmeICBcNjRLPb7oXzuGr/g4x/3ge5Qaawqrg/gcZr/sKN6SdE8SszgKYO0SB320N4gcUoShVdLYr9uwdJ+kJoobfkUK6Or171JCctP/cu2nM79lDqVnJw/2jOG8OnTc8zRDXAh0RKoR5rOU8cOHm0Ls2MATsFdnyRU5FGUxqZ+");
- private static PublicKey testKey;
-
- public SignatureRSATest() {
- super();
- }
-
- @BeforeClass
- public static void initializeTestKey() throws GeneralSecurityException {
- byte[] exp = B64_DECODER.decode("Iw==");
- @SuppressWarnings("checkstyle:linelength")
- byte[] mod = B64_DECODER.decode("AMs9HO/NH/Now+6fSnESebaG4wzaYQWA1b/q1TGV1wHNtCg9fGFGVSKs0VxKF4cfVyrSLtgLjnlXQTn+Lm7xiYKGbBbsTQWOqEDaBVBsRbAkxIkpuvr6/EBxwrtDbKmSQYTJZVJSD2bZRYjGsR9gpZXPorOOKFd5EPCMHXsqnhp2hidTGH7cK6RuLk7MNnPISsY0Nbx8/ZvikiPROGcoTZ8bzUv4IaLr3veW6epSeQem8tJqhnrpTHhbLU99zf045M0Gsnk/azjjlBM+qrHZ5FNdC1kowJnLtf2Oy/rUQNpkGJtcBPT8xvreV0wLsn9t3hSxzsc0+VkDNTQRlfU+o3M=");
- KeyFactory kf = SecurityUtils.getKeyFactory(KeyUtils.RSA_ALGORITHM);
- testKey = kf.generatePublic(new RSAPublicKeySpec(new BigInteger(mod), new BigInteger(exp)));
- }
-
- @Test // see SSHD-642
- public void testLeadingZeroesBC() throws Throwable {
- testLeadingZeroes(new Factory<SignatureRSA>() {
- @Override
- public SignatureRSA create() {
- return new SignatureRSA() {
- @Override
- protected java.security.Signature doInitSignature(String algo, boolean forSigning) throws GeneralSecurityException {
- assertFalse("Signature not initialized for verification", forSigning);
- java.security.Signature signature = super.doInitSignature(algo, forSigning);
- if (SecurityUtils.isBouncyCastleRegistered()) {
- Provider provider = signature.getProvider();
- String name = provider.getName();
- assertEquals("Mismatched BC provider name", SecurityUtils.BOUNCY_CASTLE, name);
- }
- return signature;
- }
- };
- }
- });
- }
-
- @Test // see SSHD-642
- public void testLeadingZeroesJCE() throws Throwable {
- testLeadingZeroes(() -> new SignatureRSA() {
- @Override
- protected java.security.Signature doInitSignature(String algo, boolean forSigning) throws GeneralSecurityException {
- assertFalse("Signature not initialized for verification", forSigning);
- java.security.Signature signature = java.security.Signature.getInstance(algo);
- Provider provider = signature.getProvider();
- String name = provider.getName();
- assertNotEquals("BC provider used although not required", SecurityUtils.BOUNCY_CASTLE, name);
- return signature;
- }
- });
- }
-
- private void testLeadingZeroes(Factory<? extends SignatureRSA> factory) throws Exception {
- SignatureRSA rsa = factory.create();
- rsa.initVerifier(testKey);
-
- int vSize = rsa.getVerifierSignatureSize();
- assertTrue("Verifier signature size not initialized", vSize > 0);
-
- // make sure padding is required
- Map.Entry<String, byte[]> encoding = rsa.extractEncodedSignature(TEST_SIGNATURE);
- assertNotNull("Signature is not encoded", encoding);
- byte[] data = encoding.getValue();
- assertTrue("Signature data size (" + data.length + ") not below verifier size (" + vSize + ")", data.length < vSize);
-
- rsa.update(TEST_MSG);
- assertTrue("Failed to verify", rsa.verify(TEST_SIGNATURE));
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/signature/SignaturesDevelopment.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignaturesDevelopment.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/SignaturesDevelopment.java
deleted file mode 100644
index 180e997..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/signature/SignaturesDevelopment.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.common.signature;
-
-import java.security.KeyPair;
-import java.security.PrivateKey;
-import java.security.PublicKey;
-
-import org.apache.sshd.common.util.GenericUtils;
-import org.apache.sshd.common.util.buffer.BufferUtils;
-import org.apache.sshd.common.util.security.eddsa.EdDSASecurityProviderUtils;
-import org.apache.sshd.util.test.BaseTestSupport;
-
-/**
- * A "scratch-pad" class for testing signatures related code during development
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class SignaturesDevelopment extends BaseTestSupport {
- public SignaturesDevelopment() {
- super();
- }
-
- public static void testSignatureFactory(
- SignatureFactory factory, KeyPair kp, byte[] data, boolean generateSignature, byte[] signature)
- throws Exception {
- Signature signer = factory.create();
- if (generateSignature) {
- signer.initSigner(kp.getPrivate());
- signer.update(data);
- signature = signer.sign();
- System.out.append('\t').append("Signature: ").println(BufferUtils.toHex(':', signature));
- } else {
- signer.initVerifier(kp.getPublic());
- signer.update(data);
- if (signer.verify(signature)) {
- System.out.append('\t').println("Valid signature");
- } else {
- System.err.append('\t').println("Invalid signature");
- }
- }
- }
-
- //////////////////////////////////////////////////////////////////////////
-
- // args[0]=signatureName, args[1]=publicKey, args[2]=privateKey, args[3]=sign/verify, args[4]=data, args[5]=signature(if verify required)
- public static void main(String[] args) throws Exception {
- SignatureFactory factory = BuiltinSignatures.resolveFactory(args[0]);
- // TODO recover public/private keys according to factory name
- byte[] publicKey = BufferUtils.decodeHex(':', args[1]);
- PublicKey pubKey = EdDSASecurityProviderUtils.generateEDDSAPublicKey(publicKey);
- byte[] privateKey = BufferUtils.decodeHex(':', args[2]);
- PrivateKey prvKey = EdDSASecurityProviderUtils.generateEDDSAPrivateKey(privateKey);
- String op = args[3];
- byte[] data = BufferUtils.decodeHex(':', args[4]);
- byte[] signature = GenericUtils.EMPTY_BYTE_ARRAY;
- if ("verify".equalsIgnoreCase(op)) {
- signature = BufferUtils.decodeHex(':', args[5]);
- }
-
- testSignatureFactory(factory, new KeyPair(pubKey, prvKey), data, "sign".equalsIgnoreCase(op), signature);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
deleted file mode 100644
index 3732f8a..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
+++ /dev/null
@@ -1,149 +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.util;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.EventListener;
-import java.util.List;
-import java.util.Set;
-
-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 EventListenerUtilsTest extends BaseTestSupport {
- public EventListenerUtilsTest() {
- super();
- }
-
- @Test
- public void testProxyWrapper() {
- List<ProxyListenerImpl> impls = new ArrayList<>();
- for (int index = 0; index < Byte.SIZE; index++) {
- impls.add(new ProxyListenerImpl());
- }
-
- ProxyListener listener = EventListenerUtils.proxyWrapper(ProxyListener.class, impls);
- String expStr = getCurrentTestName();
- Number expNum = System.currentTimeMillis();
- listener.callMeWithString(expStr);
- listener.callMeWithNumber(expNum);
-
- for (int index = 0; index < impls.size(); index++) {
- ProxyListenerImpl l = impls.get(index);
- assertSame("Mismatched string at listener #" + index, expStr, l.getStringValue());
- assertSame("Mismatched number at listener #" + index, expNum, l.getNumberValue());
- }
- }
-
- @Test
- public void testListenerInstanceComparatorOnProxy() {
- Comparator<? super EventListener> comparator = EventListenerUtils.LISTENER_INSTANCE_COMPARATOR;
- ProxyListener p1 = EventListenerUtils.proxyWrapper(ProxyListener.class, Collections.singletonList(new ProxyListenerImpl()));
- assertEquals("Mismatched self reference comparison", 0, comparator.compare(p1, p1));
-
- EventListener l = new EventListener() { /* nothing extra */ };
- assertEquals("Mismatched proxy vs. non-proxy result", 1, Integer.signum(comparator.compare(p1, l)));
- assertEquals("Mismatched non-proxy vs. proxy result", -1, Integer.signum(comparator.compare(l, p1)));
-
- ProxyListener p2 = EventListenerUtils.proxyWrapper(ProxyListener.class, Collections.singletonList(new ProxyListenerImpl()));
- int p1vsp2 = Integer.signum(comparator.compare(p1, p2));
- assertNotEquals("Mismatched p1 vs. p2 comparison", 0, p1vsp2);
- assertEquals("Mismatched p2 vs. p1 comparison result", 0 - p1vsp2, Integer.signum(comparator.compare(p2, p1)));
- }
-
- @Test
- public void testListenerInstanceComparatorOnNonProxy() {
- Comparator<? super EventListener> comparator = EventListenerUtils.LISTENER_INSTANCE_COMPARATOR;
- EventListener l1 = new EventListener() { /* nothing extra */ };
- assertEquals("Mismatched self reference comparison", 0, comparator.compare(l1, l1));
-
- EventListener l2 = new EventListener() { /* nothing extra */ };
- int l1vsl2 = Integer.signum(comparator.compare(l1, l2));
- assertNotEquals("Mismatched l1 vs. l2 comparison result", 0, l1vsl2);
- assertEquals("Mismatched l2 vs. l1 comparison result", 0 - l1vsl2, Integer.signum(comparator.compare(l2, l1)));
- }
-
- @Test
- public void testSynchronizedListenersSetOnProxies() {
- ProxyListener p1 = EventListenerUtils.proxyWrapper(ProxyListener.class, Collections.singletonList(new ProxyListenerImpl()));
- Set<ProxyListener> s = EventListenerUtils.synchronizedListenersSet();
- for (int index = 1; index <= Byte.SIZE; index++) {
- boolean modified = s.add(p1);
- assertEquals("Mismatched p1 modification indicator at attempt #" + index, index == 1, modified);
- assertEquals("Mismatched p1 set size at attempt #" + index, 1, s.size());
- }
-
- ProxyListener p2 = EventListenerUtils.proxyWrapper(ProxyListener.class, Collections.singletonList(new ProxyListenerImpl()));
- for (int index = 1; index <= Byte.SIZE; index++) {
- boolean modified = s.add(p2);
- assertEquals("Mismatched p2 modification indicator at attempt #" + index, index == 1, modified);
- assertEquals("Mismatched p2 set size at attempt #" + index, 2, s.size());
- }
-
- assertTrue("Failed to remove p1", s.remove(p1));
- assertEquals("Mismatched post p1-remove size", 1, s.size());
- assertTrue("Failed to remove p2", s.remove(p2));
- assertEquals("Mismatched post p2-remove size", 0, s.size());
- }
-
- interface ProxyListener extends SshdEventListener {
- void callMeWithString(String s);
-
- void callMeWithNumber(Number n);
- }
-
- static class ProxyListenerImpl implements ProxyListener {
- private String strValue;
- private Number numValue;
-
- ProxyListenerImpl() {
- super();
- }
-
- public String getStringValue() {
- return strValue;
- }
-
- @Override
- public void callMeWithString(String s) {
- strValue = s;
- }
-
- public Number getNumberValue() {
- return numValue;
- }
-
- @Override
- public void callMeWithNumber(Number n) {
- numValue = n;
- }
- }
-}