http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/GenericUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/GenericUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/GenericUtilsTest.java deleted file mode 100644 index a83b9de..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/GenericUtilsTest.java +++ /dev/null @@ -1,173 +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.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.NoSuchElementException; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class GenericUtilsTest extends BaseTestSupport { - public GenericUtilsTest() { - super(); - } - - @Test - public void testSplitAndJoin() { - List<String> expected = Collections.unmodifiableList( - Arrays.asList(getClass().getPackage().getName().replace('.', '/'), getClass().getSimpleName(), getCurrentTestName())); - - // NOTE: we also test characters that have meaning in String.split(...) as regex ones - for (char ch : new char[]{',', '.', '*', '?'}) { - String sep = String.valueOf(ch); - String s = GenericUtils.join(expected, sep); - String[] actual = GenericUtils.split(s, ch); - assertEquals("Mismatched split length for separator=" + sep, expected.size(), GenericUtils.length((Object[]) actual)); - - for (int index = 0; index < actual.length; index++) { - String e = expected.get(index); - String a = actual[index]; - if (!e.endsWith(a)) { - fail("Mismatched value at index=" + index + " for separator=" + sep + ": expected=" + e + ", actual=" + a); - } - } - } - } - - @Test - public void testStripQuotes() { - String expected = getCurrentTestName(); - assertSame("Unexpected un-quoted stripping", expected, GenericUtils.stripQuotes(expected)); - - StringBuilder sb = new StringBuilder(2 + expected.length()).append('|').append(expected).append('|'); - for (int index = 0; index < GenericUtils.QUOTES.length(); index++) { - char delim = GenericUtils.QUOTES.charAt(index); - sb.setCharAt(0, delim); - sb.setCharAt(sb.length() - 1, delim); - - CharSequence actual = GenericUtils.stripQuotes(sb); - assertEquals("Mismatched result for delim (" + delim + ")", expected, actual.toString()); - } - } - - @Test - public void testStripOnlyFirstLayerQuotes() { - StringBuilder sb = new StringBuilder().append("||").append(getCurrentTestName()).append("||"); - char[] delims = {'\'', '"', '"', '\''}; - for (int index = 0; index < delims.length; index += 2) { - char topDelim = delims[index]; - char innerDelim = delims[index + 1]; - sb.setCharAt(0, topDelim); - sb.setCharAt(1, innerDelim); - sb.setCharAt(sb.length() - 2, innerDelim); - sb.setCharAt(sb.length() - 1, topDelim); - - CharSequence expected = sb.subSequence(1, sb.length() - 1); - CharSequence actual = GenericUtils.stripQuotes(sb); - assertEquals("Mismatched result for delim (" + topDelim + "/" + innerDelim + ")", expected.toString(), actual.toString()); - } - } - - @Test - public void testStripDelimiters() { - String expected = getCurrentTestName(); - final char delim = '|'; - assertSame("Unexpected un-delimited stripping", expected, GenericUtils.stripDelimiters(expected, delim)); - - CharSequence actual = GenericUtils.stripDelimiters( - new StringBuilder(2 + expected.length()).append(delim).append(expected).append(delim), delim); - assertEquals("Mismatched stripped values", expected, actual.toString()); - } - - @Test - public void testStripDelimitersOnlyIfOnBothEnds() { - final char delim = '$'; - StringBuilder expected = new StringBuilder().append(delim).append(getCurrentTestName()).append(delim); - for (int index : new int[]{0, expected.length() - 1}) { - // restore original delimiters - expected.setCharAt(0, delim); - expected.setCharAt(expected.length() - 1, delim); - // trash one end - expected.setCharAt(index, (char) (delim + 1)); - - assertSame("Mismatched result for delim at index=" + index, expected, GenericUtils.stripDelimiters(expected, delim)); - } - } - - @Test - public void testAccumulateExceptionOnNullValues() { - assertNull("Unexpected null/null result", GenericUtils.accumulateException(null, null)); - - Throwable expected = new NoSuchMethodException(getClass().getName() + "#" + getCurrentTestName()); - assertSame("Mismatched null/extra result", expected, GenericUtils.accumulateException(null, expected)); - assertSame("Mismatched current/null result", expected, GenericUtils.accumulateException(expected, null)); - } - - @Test - public void testAccumulateExceptionOnExistingCurrent() { - RuntimeException[] expected = new RuntimeException[]{ - new IllegalArgumentException(getCurrentTestName()), - new ClassCastException(getClass().getName()), - new NoSuchElementException(getClass().getPackage().getName()) - }; - RuntimeException current = new UnsupportedOperationException("top"); - for (RuntimeException extra : expected) { - RuntimeException actual = GenericUtils.accumulateException(current, extra); - assertSame("Mismatched returned actual exception", current, actual); - } - - Throwable[] actual = current.getSuppressed(); - assertArrayEquals("Suppressed", expected, actual); - } - - @Test - public void testNullOrEmptyCharArrayComparison() { - char[][] values = new char[][]{null, GenericUtils.EMPTY_CHAR_ARRAY}; - for (char[] c1 : values) { - for (char[] c2 : values) { - assertEquals(((c1 == null) ? "null" : "empty") + " vs. " + ((c2 == null) ? "null" : "empty"), 0, GenericUtils.compare(c1, c2)); - } - } - } - - @Test - public void testCharArrayComparison() { - String s1 = getClass().getSimpleName(); - char[] c1 = s1.toCharArray(); - assertEquals("Same value equality", 0, GenericUtils.compare(c1, s1.toCharArray())); - - String s2 = getCurrentTestName(); - char[] c2 = s2.toCharArray(); - assertEquals("s1 vs. s2", Integer.signum(s1.compareTo(s2)), Integer.signum(GenericUtils.compare(c1, c2))); - assertEquals("s2 vs. s1", Integer.signum(s2.compareTo(s1)), Integer.signum(GenericUtils.compare(c2, c1))); - } -}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/Int2IntFunctionTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/Int2IntFunctionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/Int2IntFunctionTest.java deleted file mode 100644 index 941190b..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/Int2IntFunctionTest.java +++ /dev/null @@ -1,154 +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.Random; -import java.util.function.IntUnaryOperator; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class Int2IntFunctionTest extends BaseTestSupport { - public Int2IntFunctionTest() { - super(); - } - - @Test - public void testAdd() { - int factor = Byte.SIZE; - IntUnaryOperator func = Int2IntFunction.add(factor); - for (int index = 1, sum = 0; index <= Byte.SIZE; index++) { - sum = func.applyAsInt(sum); - assertEquals(factor * index, sum); - } - } - - @Test - public void testAddIdentity() { - IntUnaryOperator func = Int2IntFunction.add(0); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int expected = rnd.nextInt(); - int actual = func.applyAsInt(expected); - assertEquals(expected, actual); - } - } - - @Test - public void testSub() { - int factor = Byte.SIZE; - IntUnaryOperator func = Int2IntFunction.sub(factor); - for (int index = 1, sum = 0; index <= Byte.SIZE; index++) { - sum = func.applyAsInt(sum); - assertEquals(factor * index * -1, sum); - } - } - - @Test - public void testSubIdentity() { - IntUnaryOperator func = Int2IntFunction.sub(0); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int expected = rnd.nextInt(); - int actual = func.applyAsInt(expected); - assertEquals(expected, actual); - } - } - - @Test - public void testMul() { - int factor = 2; - IntUnaryOperator func = Int2IntFunction.mul(factor); - for (int index = 1, mul = 1, expected = factor; index <= Byte.SIZE; index++, expected *= factor) { - mul = func.applyAsInt(mul); - assertEquals(expected, mul); - } - } - - @Test - public void testMulIdentity() { - IntUnaryOperator func = Int2IntFunction.mul(1); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int expected = rnd.nextInt(); - int actual = func.applyAsInt(expected); - assertEquals(expected, actual); - } - } - - @Test - public void testMulZero() { - IntUnaryOperator func = Int2IntFunction.mul(0); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int value = rnd.nextInt(); - int actual = func.applyAsInt(value); - assertEquals(Integer.toString(value), 0, actual); - } - } - - @Test - public void testConstant() { - int expected = 377347; - IntUnaryOperator func = Int2IntFunction.constant(expected); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int value = rnd.nextInt(); - int actual = func.applyAsInt(value); - assertEquals(Integer.toString(value), expected, actual); - } - } - - @Test - public void testDiv() { - int factor = 2; - IntUnaryOperator func = Int2IntFunction.div(factor); - for (int index = 1, quot = 65536, expected = quot / factor; index <= Byte.SIZE; index++, expected /= factor) { - quot = func.applyAsInt(quot); - assertEquals(expected, quot); - } - } - - @Test - public void testDivIdentity() { - IntUnaryOperator func = Int2IntFunction.div(1); - Random rnd = new Random(System.nanoTime()); - for (int index = 1; index <= Byte.SIZE; index++) { - int expected = rnd.nextInt(); - int actual = func.applyAsInt(expected); - assertEquals(expected, actual); - } - } - - @Test(expected = IllegalArgumentException.class) - public void testDivZeroFactor() { - IntUnaryOperator func = Int2IntFunction.div(0); - fail("Unexpected success: " + func); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java deleted file mode 100644 index 8109b55..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/NumberUtilsTest.java +++ /dev/null @@ -1,77 +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 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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class NumberUtilsTest extends BaseTestSupport { - public NumberUtilsTest() { - super(); - } - - @Test - public void testPowersOf2List() { - assertEquals("Mismatched values size for " + NumberUtils.POWERS_OF_TWO, Long.SIZE, GenericUtils.size(NumberUtils.POWERS_OF_TWO)); - long expected = 1L; - for (int index = 0; index < Long.SIZE; index++, expected <<= 1) { - Long actual = NumberUtils.POWERS_OF_TWO.get(index); - assertEquals("Mismatched value at index=" + index, Long.toHexString(expected), Long.toHexString(actual)); - } - } - - @Test - public void testNextPowerOf2() { - for (Long v : NumberUtils.POWERS_OF_TWO) { - long expected = v; - if (expected > 2L) { - assertEquals("Mismatched lower bound value", expected, NumberUtils.getNextPowerOf2(expected - 1L)); - } - - if (expected > 0L) { // avoid the negative value - assertEquals("Mismatched exact value", expected, NumberUtils.getNextPowerOf2(expected)); - } - } - } - - @Test - public void testToInteger() { - assertNull("Unexpected null value", NumberUtils.toInteger(null)); - for (Number n : new Number[]{ - Byte.valueOf(Byte.MAX_VALUE), Short.valueOf(Short.MIN_VALUE), - Integer.valueOf(Short.MAX_VALUE), Long.valueOf(82007160L)}) { - Integer i = NumberUtils.toInteger(n); - if (n instanceof Integer) { - assertSame("Unexpected conversion", n, i); - } else { - assertEquals("Mismatched values", n.intValue(), i.intValue()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/OsUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/OsUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/OsUtilsTest.java deleted file mode 100644 index 62081af..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/OsUtilsTest.java +++ /dev/null @@ -1,135 +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.Objects; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class OsUtilsTest extends BaseTestSupport { - public OsUtilsTest() { - super(); - } - - @Test - public void testSetOsTypeByProperty() { - try { - for (String osType : new String[]{"Some-Windows", "Some-Linux"}) { - OsUtils.setWin32(null); // force re-detection - - try { - boolean expected = osType.contains("Windows"); - System.setProperty(OsUtils.OS_TYPE_OVERRIDE_PROP, osType); - boolean actual = OsUtils.isWin32(); - assertEquals(osType, expected, actual); - } finally { - System.clearProperty(OsUtils.OS_TYPE_OVERRIDE_PROP); - } - } - } finally { - OsUtils.setWin32(null); // force re-detection - } - } - - @Test - public void testSetOsTypeProgrammatically() { - try { - for (boolean expected : new boolean[]{true, false}) { - OsUtils.setWin32(expected); // force value - assertEquals("Mismatched detection value", expected, OsUtils.isWin32()); - } - } finally { - OsUtils.setWin32(null); // force re-detection - } - } - - @Test - public void testSetCurrentUserByProperty() { - try { - for (String expected : new String[]{getClass().getSimpleName(), getCurrentTestName()}) { - OsUtils.setCurrentUser(null); // force re-detection - - try { - System.setProperty(OsUtils.CURRENT_USER_OVERRIDE_PROP, expected); - String actual = OsUtils.getCurrentUser(); - assertEquals("Mismatched reported current user", expected, actual); - } finally { - System.clearProperty(OsUtils.CURRENT_USER_OVERRIDE_PROP); - } - } - } finally { - OsUtils.setCurrentUser(null); // force re-detection - } - } - - @Test - public void testSetCurrentUserProgrammatically() { - try { - for (String expected : new String[]{getClass().getSimpleName(), getCurrentTestName()}) { - OsUtils.setCurrentUser(expected); // force value - assertEquals("Mismatched detection value", expected, OsUtils.getCurrentUser()); - } - } finally { - OsUtils.setCurrentUser(null); // force re-detection - } - } - - @Test - public void testSetJavaVersionByProperty() { - try { - for (String value : new String[]{"7.3.6_5", "37.77.34_7-" + getCurrentTestName()}) { - OsUtils.setJavaVersion(null); // force re-detection - - try { - System.setProperty(OsUtils.JAVA_VERSION_OVERRIDE_PROP, value); - String expected = value.replace('_', '.'); - String actual = Objects.toString(OsUtils.getJavaVersion(), null); - assertTrue("Mismatched reported version value: " + actual, expected.startsWith(actual)); - } finally { - System.clearProperty(OsUtils.JAVA_VERSION_OVERRIDE_PROP); - } - } - } finally { - OsUtils.setJavaVersion(null); // force re-detection - } - } - - @Test - public void testSetJavaVersionProgrammatically() { - try { - for (VersionInfo expected : new VersionInfo[]{VersionInfo.parse("7.3.6.5"), VersionInfo.parse("37.77.34.7")}) { - OsUtils.setJavaVersion(expected); // force value - assertEquals("Mismatched detection value", expected, OsUtils.getJavaVersion()); - } - } finally { - OsUtils.setJavaVersion(null); // force re-detection - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java deleted file mode 100644 index c4e521c..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/SecurityUtilsTest.java +++ /dev/null @@ -1,232 +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.io.IOException; -import java.nio.file.Path; -import java.security.GeneralSecurityException; -import java.security.KeyPair; -import java.security.PrivateKey; -import java.security.PublicKey; -import java.security.interfaces.DSAPrivateKey; -import java.security.interfaces.DSAPublicKey; -import java.security.interfaces.ECPrivateKey; -import java.security.interfaces.ECPublicKey; -import java.security.interfaces.RSAPrivateKey; -import java.security.interfaces.RSAPublicKey; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import org.apache.sshd.common.cipher.BuiltinCiphers; -import org.apache.sshd.common.cipher.ECCurves; -import org.apache.sshd.common.config.keys.FilePasswordProvider; -import org.apache.sshd.common.config.keys.KeyUtils; -import org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader; -import org.apache.sshd.common.keyprovider.AbstractResourceKeyPairProvider; -import org.apache.sshd.common.keyprovider.ClassLoadableResourceKeyPairProvider; -import org.apache.sshd.common.keyprovider.FileKeyPairProvider; -import org.apache.sshd.common.util.security.SecurityProviderRegistrar; -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.AfterClass; -import org.junit.Assume; -import org.junit.BeforeClass; -import org.junit.FixMethodOrder; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -@SuppressWarnings("checkstyle:MethodCount") -public class SecurityUtilsTest extends BaseTestSupport { - public static final String BC_NAMED_USAGE_PROP = - SecurityProviderRegistrar.CONFIG_PROP_BASE - + "." + SecurityUtils.BOUNCY_CASTLE - + "." + SecurityProviderRegistrar.NAMED_PROVIDER_PROPERTY; - - private static final String DEFAULT_PASSWORD = "super secret passphrase"; - private static final FilePasswordProvider TEST_PASSWORD_PROVIDER = file -> DEFAULT_PASSWORD; - - public SecurityUtilsTest() { - super(); - } - - // NOTE: Using the BouncyCastle provider instead of the name does not work as expected so we take no chances - @BeforeClass - public static void useNamedBouncyCastleProvider() { - System.setProperty(BC_NAMED_USAGE_PROP, Boolean.TRUE.toString()); - } - - @AfterClass - public static void unsetBouncyCastleProviderUsagePreference() { - System.clearProperty(BC_NAMED_USAGE_PROP); - } - - @Test - public void testLoadEncryptedDESPrivateKey() throws Exception { - testLoadEncryptedRSAPrivateKey("DES-EDE3"); - } - - @Test - public void testLoadEncryptedAESPrivateKey() { - for (BuiltinCiphers c : new BuiltinCiphers[]{ - BuiltinCiphers.aes128cbc, BuiltinCiphers.aes192cbc, BuiltinCiphers.aes256cbc - }) { - if (!c.isSupported()) { - System.out.println("Skip unsupported encryption scheme: " + c.getName()); - continue; - } - - try { - testLoadEncryptedRSAPrivateKey("AES-" + c.getKeySize()); - } catch (Exception e) { - fail("Failed (" + e.getClass().getSimpleName() + " to load key for " + c.getName() + ": " + e.getMessage()); - } - } - } - - private KeyPair testLoadEncryptedRSAPrivateKey(String algorithm) throws IOException, GeneralSecurityException { - return testLoadRSAPrivateKey(DEFAULT_PASSWORD.replace(' ', '-') + "-RSA-" + algorithm.toUpperCase() + "-key"); - } - - @Test - public void testLoadUnencryptedRSAPrivateKey() throws Exception { - testLoadRSAPrivateKey(getClass().getSimpleName() + "-RSA-KeyPair"); - } - - @Test - public void testLoadUnencryptedDSSPrivateKey() throws Exception { - testLoadDSSPrivateKey(getClass().getSimpleName() + "-DSA-KeyPair"); - } - - private KeyPair testLoadDSSPrivateKey(String name) throws Exception { - return testLoadPrivateKey(name, DSAPublicKey.class, DSAPrivateKey.class); - } - - @Test - public void testLoadUnencryptedECPrivateKey() throws Exception { - Assume.assumeTrue("EC not supported", SecurityUtils.isECCSupported()); - for (ECCurves c : ECCurves.VALUES) { - if (!c.isSupported()) { - System.out.println("Skip unsupported curve: " + c.getName()); - continue; - } - - testLoadECPrivateKey(getClass().getSimpleName() + "-EC-" + c.getKeySize() + "-KeyPair"); - } - } - - private KeyPair testLoadECPrivateKey(String name) throws IOException, GeneralSecurityException { - return testLoadPrivateKey(name, ECPublicKey.class, ECPrivateKey.class); - } - - private KeyPair testLoadRSAPrivateKey(String name) throws IOException, GeneralSecurityException { - return testLoadPrivateKey(name, RSAPublicKey.class, RSAPrivateKey.class); - } - - private KeyPair testLoadPrivateKey(String name, Class<? extends PublicKey> pubType, Class<? extends PrivateKey> prvType) - throws IOException, GeneralSecurityException { - Path folder = getTestResourcesFolder(); - Path file = folder.resolve(name); - KeyPair kpFile = testLoadPrivateKeyFile(file, pubType, prvType); - if (SecurityUtils.isBouncyCastleRegistered()) { - KeyPairResourceLoader bcLoader = SecurityUtils.getBouncycastleKeyPairResourceParser(); - Collection<KeyPair> kpList = bcLoader.loadKeyPairs(file, TEST_PASSWORD_PROVIDER); - assertEquals(name + ": Mismatched loaded BouncyCastle keys count", 1, GenericUtils.size(kpList)); - - KeyPair kpBC = kpList.iterator().next(); - assertTrue(name + ": Mismatched BouncyCastle vs. file values", KeyUtils.compareKeyPairs(kpFile, kpBC)); - } - - Class<?> clazz = getClass(); - Package pkg = clazz.getPackage(); - KeyPair kpResource = testLoadPrivateKeyResource(pkg.getName().replace('.', '/') + "/" + name, pubType, prvType); - assertTrue(name + ": Mismatched key file vs. resource values", KeyUtils.compareKeyPairs(kpFile, kpResource)); - return kpResource; - } - - private static KeyPair testLoadPrivateKeyResource(String name, Class<? extends PublicKey> pubType, Class<? extends PrivateKey> prvType) { - return testLoadPrivateKey(name, new ClassLoadableResourceKeyPairProvider(name), pubType, prvType); - } - - private static KeyPair testLoadPrivateKeyFile(Path file, Class<? extends PublicKey> pubType, Class<? extends PrivateKey> prvType) { - return testLoadPrivateKey(file.toString(), new FileKeyPairProvider(file), pubType, prvType); - } - - private static KeyPair testLoadPrivateKey(String resourceKey, AbstractResourceKeyPairProvider<?> provider, - Class<? extends PublicKey> pubType, Class<? extends PrivateKey> prvType) { - provider.setPasswordFinder(TEST_PASSWORD_PROVIDER); - Iterable<KeyPair> iterator = provider.loadKeys(); - List<KeyPair> pairs = new ArrayList<>(); - for (KeyPair kp : iterator) { - pairs.add(kp); - } - - assertEquals("Mismatched loaded pairs count for " + resourceKey, 1, pairs.size()); - - KeyPair kp = pairs.get(0); - PublicKey pub = kp.getPublic(); - assertNotNull("No public key extracted", pub); - assertTrue("Not an " + pubType.getSimpleName() + " public key for " + resourceKey, pubType.isAssignableFrom(pub.getClass())); - - PrivateKey prv = kp.getPrivate(); - assertNotNull("No private key extracted", prv); - assertTrue("Not an " + prvType.getSimpleName() + " private key for " + resourceKey, prvType.isAssignableFrom(prv.getClass())); - - return kp; - } - - @Test - public void testSetMaxDHGroupExchangeKeySizeByProperty() { - try { - for (int expected = SecurityUtils.MIN_DHGEX_KEY_SIZE; expected <= SecurityUtils.MAX_DHGEX_KEY_SIZE; expected += 1024) { - SecurityUtils.setMaxDHGroupExchangeKeySize(0); // force detection - try { - System.setProperty(SecurityUtils.MAX_DHGEX_KEY_SIZE_PROP, Integer.toString(expected)); - assertTrue("DH group not supported for key size=" + expected, SecurityUtils.isDHGroupExchangeSupported()); - assertEquals("Mismatched values", expected, SecurityUtils.getMaxDHGroupExchangeKeySize()); - } finally { - System.clearProperty(SecurityUtils.MAX_DHGEX_KEY_SIZE_PROP); - } - } - } finally { - SecurityUtils.setMaxDHGroupExchangeKeySize(0); // force detection - } - } - - @Test - public void testSetMaxDHGroupExchangeKeySizeProgrammatically() { - try { - for (int expected = SecurityUtils.MIN_DHGEX_KEY_SIZE; expected <= SecurityUtils.MAX_DHGEX_KEY_SIZE; expected += 1024) { - SecurityUtils.setMaxDHGroupExchangeKeySize(expected); - assertTrue("DH group not supported for key size=" + expected, SecurityUtils.isDHGroupExchangeSupported()); - assertEquals("Mismatched values", expected, SecurityUtils.getMaxDHGroupExchangeKeySize()); - } - } finally { - SecurityUtils.setMaxDHGroupExchangeKeySize(0); // force detection - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java deleted file mode 100644 index e13fa9b..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/SelectorUtilsTest.java +++ /dev/null @@ -1,147 +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.io.File; -import java.util.Random; - -import org.apache.sshd.util.test.BaseTestSupport; -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.runners.MethodSorters; - -/** - * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class SelectorUtilsTest extends BaseTestSupport { - public SelectorUtilsTest() { - super(); - } - - @Test - public void testApplyLinuxSeparatorSlashifyRules() { - testApplySlashifyRules('/'); - } - - @Test - public void testApplyWindowsSeparatorSlashifyRules() { - testApplySlashifyRules('\\'); - } - - private void testApplySlashifyRules(char slash) { - for (String expected : new String[]{ - null, "", getCurrentTestName(), - getClass().getSimpleName() + Character.toString(slash) + getCurrentTestName(), - Character.toString(slash) + getClass().getSimpleName(), - Character.toString(slash) + getClass().getSimpleName() + Character.toString(slash) + getCurrentTestName() - }) { - String actual = SelectorUtils.applySlashifyRules(expected, slash); - assertSame("Mismatched results for '" + expected + "'", expected, actual); - } - - String[] comps = {getClass().getSimpleName(), getCurrentTestName()}; - Random rnd = new Random(System.nanoTime()); - StringBuilder sb = new StringBuilder(Byte.MAX_VALUE); - for (int index = 0; index < Long.SIZE; index++) { - if (sb.length() > 0) { - sb.setLength(0); // start from scratch - } - - boolean prepend = rnd.nextBoolean(); - if (prepend) { - slashify(sb, rnd, slash); - } - - sb.append(comps[0]); - for (int j = 1; j < comps.length; j++) { - slashify(sb, rnd, slash); - sb.append(comps[j]); - } - - boolean append = rnd.nextBoolean(); - if (append) { - slashify(sb, rnd, slash); - } - - String path = sb.toString(); - sb.setLength(0); - if (prepend) { - sb.append(slash); - } - - sb.append(comps[0]); - for (int j = 1; j < comps.length; j++) { - sb.append(slash).append(comps[j]); - } - - if (append) { - sb.append(slash).append('.'); - } - - String expected = sb.toString(); - String actual = SelectorUtils.applySlashifyRules(path, slash); - assertEquals("Mismatched results for path=" + path, expected, actual); - } - } - - private static int slashify(StringBuilder sb, Random rnd, char slash) { - int slashes = 1 /* at least one slash */ + rnd.nextInt(Byte.SIZE); - for (int k = 0; k < slashes; k++) { - sb.append(slash); - } - - return slashes; - } - - @Test - public void testTranslateToFileSystemPath() { - String path = getClass().getPackage().getName().replace('.', File.separatorChar) - + File.separator + getClass().getSimpleName() - + File.separator + getCurrentTestName(); - for (String expected : new String[] {null, "", path}) { - String actual = SelectorUtils.translateToFileSystemPath(expected, File.separator, File.separator); - assertSame("Mismatched instance for translated result", expected, actual); - } - - for (String fsSeparator : new String[] {String.valueOf('.'), "##"}) { - String expected = path.replace(File.separator, fsSeparator); - String actual = SelectorUtils.translateToFileSystemPath(path, File.separator, fsSeparator); - assertEquals("Mismatched translation result for separator='" + fsSeparator + "'", expected, actual); - - actual = SelectorUtils.translateToFileSystemPath(actual, fsSeparator, File.separator); - assertEquals("Mismatched translation revert for separator='" + fsSeparator + "'", path, actual); - } - } - - @Test - public void testAbsoluteWindowsPathTranslation() { - Assume.assumeTrue("Not tested on Windows", OsUtils.isWin32()); - String expected = detectTargetFolder().toString(); - for (String prefix : new String[]{"", "/"}) { - String actual = SelectorUtils.translateToLocalPath(prefix + expected.replace('/', File.separatorChar)); - assertEquals("Mismatched result for prefix='" + prefix + "'", expected, actual); - } - } - -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/ThreadUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/ThreadUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/ThreadUtilsTest.java deleted file mode 100644 index 50fda34..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/ThreadUtilsTest.java +++ /dev/null @@ -1,72 +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.Collection; - -import org.apache.sshd.common.util.threads.CloseableExecutorService; -import org.apache.sshd.common.util.threads.ThreadUtils; -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class ThreadUtilsTest extends BaseTestSupport { - public ThreadUtilsTest() { - super(); - } - - @Test - public void testProtectExecutorServiceShutdown() { - for (boolean shutdownOnExit : new boolean[]{true, false}) { - assertNull("Unexpected instance for shutdown=" + shutdownOnExit, ThreadUtils.protectExecutorServiceShutdown(null, shutdownOnExit)); - } - - CloseableExecutorService service = ThreadUtils.newSingleThreadExecutor("pool"); - try { - assertSame("Unexpected wrapped instance", service, ThreadUtils.protectExecutorServiceShutdown(service, true)); - - CloseableExecutorService wrapped = ThreadUtils.protectExecutorServiceShutdown(service, false); - try { - assertNotSame("No wrapping occurred", service, wrapped); - - wrapped.shutdown(); - assertTrue("Wrapped service not shutdown", wrapped.isShutdown()); - assertFalse("Protected service is shutdown", service.isShutdown()); - - Collection<?> running = wrapped.shutdownNow(); - assertTrue("Non-empty runners list", running.isEmpty()); - assertTrue("Wrapped service not shutdownNow", wrapped.isShutdown()); - assertFalse("Protected service is shutdownNow", service.isShutdown()); - } finally { - wrapped.shutdownNow(); // just in case - } - } finally { - service.shutdownNow(); // just in case... - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/ValidateUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/ValidateUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/ValidateUtilsTest.java deleted file mode 100644 index 80c2e7f..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/ValidateUtilsTest.java +++ /dev/null @@ -1,44 +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 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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class ValidateUtilsTest extends BaseTestSupport { - public ValidateUtilsTest() { - super(); - } - - @Test(expected = IllegalArgumentException.class) - public void checkNotNull() { - ValidateUtils.checkNotNull(getClass(), getCurrentTestName()); - ValidateUtils.checkNotNull(null, getCurrentTestName()); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/VersionInfoTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/VersionInfoTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/VersionInfoTest.java deleted file mode 100644 index 3b742a9..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/VersionInfoTest.java +++ /dev/null @@ -1,52 +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 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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class VersionInfoTest extends BaseTestSupport { - public VersionInfoTest() { - super(); - } - - @Test - public void testLessThan4Components() { - VersionInfo expected = new VersionInfo(73, 65); - VersionInfo actual = VersionInfo.parse(NumberUtils.join('.', expected.getMajorVersion(), expected.getMinorVersion())); - assertEquals("Mismatched result", expected, actual); - } - - @Test - public void testMoreThan4Components() { - VersionInfo expected = new VersionInfo(7, 3, 6, 5); - VersionInfo actual = VersionInfo.parse(expected.toString() + ".3.7.7.7.3.4.7"); - assertEquals("Mismatched result", expected, actual); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java deleted file mode 100644 index be3f796..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java +++ /dev/null @@ -1,103 +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.buffer; - -import java.io.ByteArrayOutputStream; -import java.io.DataOutputStream; -import java.nio.charset.StandardCharsets; - -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; - -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class BufferTest extends BaseTestSupport { - public BufferTest() { - super(); - } - - @Test - public void testGetLong() throws Exception { - long expected = 1234567890123456789L; - - try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) { - try (DataOutputStream ds = new DataOutputStream(stream)) { - ds.writeLong(expected); - } - - Buffer buffer = new ByteArrayBuffer(stream.toByteArray()); - assertEquals("Mismatched recovered value", expected, buffer.getLong()); - } - } - - @Test - public void testPutCharsWithNullOrEmptyValue() { - Buffer buffer = new ByteArrayBuffer(Integer.SIZE); - for (char[] chars : new char[][]{null, GenericUtils.EMPTY_CHAR_ARRAY}) { - buffer.putChars(chars); - - String value = buffer.getString(); - assertEquals("Mismatched value for " + ((chars == null) ? "null" : "empty") + " characters", "", value); - } - } - - @Test - public void testPutCharsOnNonEmptyValue() { - String expected = getCurrentTestName(); - Buffer buffer = new ByteArrayBuffer(expected.length() + Byte.SIZE); - buffer.putChars(expected.toCharArray()); - - String actual = buffer.getString(); - assertEquals("Mismatched recovered values", expected, actual); - } - - @Test - public void testPutAndWipeChars() { - String expected = getCurrentTestName(); - char[] chars = expected.toCharArray(); - Buffer buffer = new ByteArrayBuffer(chars.length + Byte.SIZE); - buffer.putAndWipeChars(chars); - - String actual = buffer.getString(); - assertEquals("Mismatched recovered values", expected, actual); - - for (int index = 0; index < chars.length; index++) { - assertEquals("Character not wiped at index=" + index, 0, chars[index]); - } - } - - @Test - public void testPutAndWipeBytes() { - String expected = getCurrentTestName(); - byte[] bytes = expected.getBytes(StandardCharsets.UTF_8); - Buffer buffer = new ByteArrayBuffer(bytes.length + Byte.SIZE); - buffer.putAndWipeBytes(bytes); - String actual = buffer.getString(); - assertEquals("Mismatched recovered values", expected, actual); - - for (int index = 0; index < bytes.length; index++) { - assertEquals("Value not wiped at index=" + index, 0, bytes[index]); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java deleted file mode 100644 index b106bc6..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java +++ /dev/null @@ -1,73 +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.buffer; - -import java.nio.charset.StandardCharsets; -import java.util.Random; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class BufferUtilsTest extends BaseTestSupport { - public BufferUtilsTest() { - super(); - } - - @Test - public void testHexEncodeDecode() { - String expValue = getClass().getName() + "#" + getCurrentTestName(); - byte[] expData = expValue.getBytes(StandardCharsets.UTF_8); - for (char sep : new char[]{BufferUtils.EMPTY_HEX_SEPARATOR, ':'}) { - String hexData = BufferUtils.toHex(sep, expData); - byte[] actData = BufferUtils.decodeHex(sep, hexData); - String actValue = new String(actData, StandardCharsets.UTF_8); - String sepName = (BufferUtils.EMPTY_HEX_SEPARATOR == sep) ? "EMPTY" : Character.toString(sep); - outputDebugMessage("Decode(sep=%s) expected=%s, actual=%s", sepName, expValue, actValue); - assertArrayEquals("Mismatched result for sep='" + sepName + "'", expData, actData); - } - } - - @Test - public void testGetCompactClone() { - byte[] expected = getCurrentTestName().getBytes(StandardCharsets.UTF_8); - final int testOffset = Byte.SIZE / 2; - byte[] data = new byte[expected.length + 2 * testOffset]; - Random rnd = new Random(System.nanoTime()); - rnd.nextBytes(data); - System.arraycopy(expected, 0, data, testOffset, expected.length); - - Buffer buf = ByteArrayBuffer.getCompactClone(data, testOffset, expected.length); - assertEquals("Mismatched cloned buffer read position", 0, buf.rpos()); - assertEquals("Mismatched cloned buffer available size", expected.length, buf.available()); - - byte[] actual = buf.array(); - assertNotSame("Original data not cloned", data, actual); - assertArrayEquals("Mismatched cloned contents", expected, actual); - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/closeable/CloseableUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/closeable/CloseableUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/closeable/CloseableUtilsTest.java deleted file mode 100644 index 8a6cb18..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/closeable/CloseableUtilsTest.java +++ /dev/null @@ -1,163 +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.closeable; - -import java.io.IOException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.sshd.common.Closeable; -import org.apache.sshd.common.future.CloseFuture; -import org.apache.sshd.common.future.DefaultCloseFuture; -import org.apache.sshd.common.future.SshFutureListener; -import org.apache.sshd.common.util.threads.ThreadUtils; -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class CloseableUtilsTest extends BaseTestSupport { - public CloseableUtilsTest() { - super(); - } - - @Test - public void testCloseImmediateNotCalledIfAlreadyClosed() throws IOException { - Closeable closeable = new IoBaseCloseable() { - @Override - public CloseFuture close(boolean immediately) { - fail("Unexpected call to close(" + immediately + ")"); - return null; - } - - @Override - public void addCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to addCloseFutureListener"); - } - - @Override - public void removeCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to removeCloseFutureListener"); - } - - @Override - public boolean isClosed() { - return true; - } - - @Override - public boolean isClosing() { - return false; - } - }; - closeable.close(); - } - - @Test - public void testCloseImmediateNotCalledIfIsClosing() throws IOException { - Closeable closeable = new IoBaseCloseable() { - @Override - public CloseFuture close(boolean immediately) { - fail("Unexpected call to close(" + immediately + ")"); - return null; - } - - @Override - public void addCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to addCloseFutureListener"); - } - - @Override - public void removeCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to removeCloseFutureListener"); - } - - @Override - public boolean isClosed() { - return false; - } - - @Override - public boolean isClosing() { - return true; - } - }; - closeable.close(); - } - - @Test - public void testCloseImmediateCalledAndWait() throws Exception { - DefaultCloseFuture future = new DefaultCloseFuture(this, this); - AtomicInteger callsCount = new AtomicInteger(0); - Closeable closeable = new IoBaseCloseable() { - @Override - public CloseFuture close(boolean immediately) { - assertTrue("Closure is not immediate", immediately); - assertEquals("Multiple close immediate calls", 1, callsCount.incrementAndGet()); - return future; - } - - @Override - public void addCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to addCloseFutureListener"); - } - - @Override - public void removeCloseFutureListener(SshFutureListener<CloseFuture> listener) { - fail("Unexpected call to removeCloseFutureListener"); - } - - @Override - public boolean isClosed() { - return false; - } - - @Override - public boolean isClosing() { - return false; - } - }; - - ExecutorService service = ThreadUtils.newSingleThreadExecutor(getCurrentTestName()); - try { - Future<?> task = service.submit((Runnable) () -> { - try { - closeable.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - }); - future.setClosed(); // signal close complete - task.get(5L, TimeUnit.SECONDS); // make sure #await call terminated - assertEquals("Close immediate not called", 1, callsCount.get()); - } finally { - service.shutdownNow(); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java deleted file mode 100644 index 24f18e3..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java +++ /dev/null @@ -1,120 +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.io; - -import java.io.IOException; -import java.io.InputStream; - -import org.apache.sshd.common.util.buffer.BufferUtils; -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class EmptyInputStreamTest extends BaseTestSupport { - public EmptyInputStreamTest() { - super(); - } - - @Test - public void testEmptyInputStream() throws IOException { - try (EmptyInputStream in = new EmptyInputStream()) { - testEmptyInputStream(in, false); - } - } - - @Test - public void testCloseableEmptyInputStream() throws IOException { - try (EmptyInputStream in = new CloseableEmptyInputStream()) { - testEmptyInputStream(in, true); - } - } - - private void testEmptyInputStream(InputStream in, boolean failAfterClose) throws IOException { - testEmptyInputStream("open", in, false); - in.close(); - testEmptyInputStream("closed", in, failAfterClose); - } - - private void testEmptyInputStream(String message, InputStream in, boolean errorExpected) { - assertFalse(message + ": unexpected markSupported()", in.markSupported()); - try { - in.mark(Long.SIZE); - fail(message + ": unexpected mark success"); - } catch (UnsupportedOperationException e) { - // expected - } - - try { - int len = in.available(); - assertFalse(message + ": Unexpected success in available(): " + len, errorExpected); - assertEquals(message + ": Mismatched available() result", 0, len); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on available(): " + e.getMessage(), errorExpected); - } - - try { - int data = in.read(); - assertFalse(message + ": Unexpected success in read(): " + data, errorExpected); - assertEquals(message + ": Mismatched read() result", -1, data); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on read(): " + e.getMessage(), errorExpected); - } - - byte[] bytes = new byte[Byte.SIZE]; - try { - int len = in.read(bytes); - assertFalse(message + ": Unexpected success in read([]): " + BufferUtils.toHex(':', bytes), errorExpected); - assertEquals(message + ": Mismatched read([]) result", -1, len); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on read([]): " + e.getMessage(), errorExpected); - } - - try { - int len = in.read(bytes, 0, bytes.length); - assertFalse(message + ": Unexpected success in read([],int,int): " + BufferUtils.toHex(':', bytes), errorExpected); - assertEquals(message + ": Mismatched read([],int,int) result", -1, len); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on read([],int,int): " + e.getMessage(), errorExpected); - } - - try { - long len = in.skip(Byte.MAX_VALUE); - assertFalse(message + ": Unexpected success in skip(): " + len, errorExpected); - assertEquals(message + ": Mismatched skip() result", 0L, len); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on skip(): " + e.getMessage(), errorExpected); - } - - try { - in.reset(); - assertFalse(message + ": Unexpected success in reset()", errorExpected); - } catch (IOException e) { - assertTrue(message + ": Unexpected error on reset(): " + e.getMessage(), errorExpected); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/IoUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/IoUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/IoUtilsTest.java deleted file mode 100644 index 6d7a8fa..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/IoUtilsTest.java +++ /dev/null @@ -1,61 +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.io; - -import java.nio.file.LinkOption; - -import org.apache.sshd.common.util.NumberUtils; -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class IoUtilsTest extends BaseTestSupport { - public IoUtilsTest() { - super(); - } - - @Test - public void testFollowLinks() { - assertTrue("Null ?", IoUtils.followLinks((LinkOption[]) null)); - assertTrue("Empty ?", IoUtils.followLinks(IoUtils.EMPTY_LINK_OPTIONS)); - assertFalse("No-follow ?", IoUtils.followLinks(IoUtils.getLinkOptions(false))); - } - - @Test - public void testGetEOLBytes() { - byte[] expected = IoUtils.getEOLBytes(); - assertTrue("Empty bytes", NumberUtils.length(expected) > 0); - - for (int index = 1; index < Byte.SIZE; index++) { - byte[] actual = IoUtils.getEOLBytes(); - assertNotSame("Same bytes received at iteration " + index, expected, actual); - assertArrayEquals("Mismatched bytes at iteration " + index, expected, actual); - } - } - -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java deleted file mode 100644 index 0f179b8..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/LimitInputStreamTest.java +++ /dev/null @@ -1,118 +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.io; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class LimitInputStreamTest extends BaseTestSupport { - public LimitInputStreamTest() { - super(); - } - - @Test - public void testReadLimit() throws IOException { - Path targetPath = detectTargetFolder(); - Path rootFolder = assertHierarchyTargetFolderExists(targetPath.resolve(getClass().getSimpleName())); - Path inputFile = rootFolder.resolve(getCurrentTestName() + ".bin"); - byte[] data = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8); - Files.write(inputFile, data); - - try (InputStream in = Files.newInputStream(inputFile)) { - int maxLen = data.length / 2; - byte[] expected = new byte[maxLen]; - System.arraycopy(data, 0, expected, 0, expected.length); - - byte[] actual = new byte[expected.length]; - try (LimitInputStream limited = new LimitInputStream(in, expected.length)) { - assertTrue("Limited stream not marked as open", limited.isOpen()); - assertEquals("Mismatched initial available data size", expected.length, limited.available()); - - int readLen = limited.read(actual); - assertEquals("Incomplete actual data read", actual.length, readLen); - assertArrayEquals("Mismatched read data", expected, actual); - assertEquals("Mismatched remaining available data size", 0, limited.available()); - - readLen = limited.read(); - assertTrue("Unexpected success to read one more byte: " + readLen, readLen < 0); - - readLen = limited.read(actual); - assertTrue("Unexpected success to read extra buffer: " + readLen, readLen < 0); - - limited.close(); - assertFalse("Limited stream still marked as open", limited.isOpen()); - - try { - readLen = limited.read(); - fail("Unexpected one byte read success after close"); - } catch (IOException e) { - // expected - } - - try { - readLen = limited.read(actual); - fail("Unexpected buffer read success after close: " + readLen); - } catch (IOException e) { - // expected - } - - try { - readLen = limited.read(actual); - fail("Unexpected buffer read success after close: " + readLen); - } catch (IOException e) { - // expected - } - - try { - readLen = (int) limited.skip(Byte.SIZE); - fail("Unexpected skip success after close: " + readLen); - } catch (IOException e) { - // expected - } - - try { - readLen = limited.available(); - fail("Unexpected available success after close: " + readLen); - } catch (IOException e) { - // expected - } - } - - // make sure underlying stream not closed - int readLen = in.read(actual); - assertEquals("Incomplete extra data read", Math.min(actual.length, data.length - expected.length), readLen); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java deleted file mode 100644 index 70c548b..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/ModifiableFileWatcherTest.java +++ /dev/null @@ -1,82 +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.io; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.attribute.PosixFilePermission; -import java.util.Collection; -import java.util.Date; -import java.util.Map; - -import org.apache.sshd.common.util.GenericUtils; -import org.apache.sshd.common.util.OsUtils; -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class ModifiableFileWatcherTest extends BaseTestSupport { - public ModifiableFileWatcherTest() { - super(); - } - - @Test // see SSHD-606 - public void testValidateStrictConfigFilePermissions() throws IOException { - Path file = getTempTargetRelativeFile(getClass().getSimpleName(), getCurrentTestName()); - outputDebugMessage("%s deletion result=%s", file, Files.deleteIfExists(file)); - assertNull("Unexpected violation for non-existent file: " + file, ModifiableFileWatcher.validateStrictConfigFilePermissions(file)); - - assertHierarchyTargetFolderExists(file.getParent()); - try (OutputStream output = Files.newOutputStream(file)) { - output.write((getClass().getName() + "#" + getCurrentTestName() + "@" + new Date(System.currentTimeMillis())).getBytes(StandardCharsets.UTF_8)); - } - - Collection<PosixFilePermission> perms = IoUtils.getPermissions(file); - if (GenericUtils.isEmpty(perms)) { - assertNull("Unexpected violation for no permissions file: " + file, ModifiableFileWatcher.validateStrictConfigFilePermissions(file)); - } else if (OsUtils.isUNIX()) { - Map.Entry<String, Object> violation = null; - for (PosixFilePermission p : ModifiableFileWatcher.STRICTLY_PROHIBITED_FILE_PERMISSION) { - if (perms.contains(p)) { - violation = ModifiableFileWatcher.validateStrictConfigFilePermissions(file); - assertNotNull("Unexpected success for permission=" + p + " of file " + file + " permissions=" + perms, violation); - break; - } - } - - if (violation == null) { // we do not expected a failure if no permissions have been violated - assertNull("Unexpected UNIX violation for file " + file + " permissions=" + perms, ModifiableFileWatcher.validateStrictConfigFilePermissions(file)); - } - } else { - assertNull("Unexpected Windows violation for file " + file + " permissions=" + perms, ModifiableFileWatcher.validateStrictConfigFilePermissions(file)); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseInputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseInputStreamTest.java deleted file mode 100644 index 2990fa6..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseInputStreamTest.java +++ /dev/null @@ -1,89 +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.io; - -import java.io.IOException; -import java.io.InputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Date; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class NoCloseInputStreamTest extends BaseTestSupport { - public NoCloseInputStreamTest() { - super(); - } - - @Test - public void testCanKeepReadingAfterClose() throws IOException { - byte[] expected = (getClass().getName() + "#" + getCurrentTestName() + "@" + new Date()).getBytes(StandardCharsets.UTF_8); - Path dir = createTempClassFolder(); - Path file = Files.write(dir.resolve(getCurrentTestName() + ".txt"), expected); - try (InputStream fileStream = Files.newInputStream(file); - InputStream shielded = new NoCloseInputStream(fileStream)) { - int index = 0; - - for (; index < (expected.length / 2); index++) { - shielded.close(); - - int readValue = shielded.read(); - if (readValue == -1) { - fail("Premature EOF after shield read of " + index + " bytes"); - } - - byte expValue = expected[index]; - byte actValue = (byte) (readValue & 0xFF); - if (expValue != actValue) { - fail("Mismatched shielded read value after " + index + " bytes"); - } - } - - for (; index < expected.length; index++) { - int readValue = fileStream.read(); - if (readValue == -1) { - fail("Premature EOF after original read of " + index + " bytes"); - } - byte expValue = expected[index]; - byte actValue = (byte) (readValue & 0xFF); - if (expValue != actValue) { - fail("Mismatched original read value after " + index + " bytes"); - } - } - - int readValue = shielded.read(); - assertEquals("Shielded EOF not signalled", -1, readValue); - - readValue = fileStream.read(); - assertEquals("Original EOF not signalled", -1, readValue); - } - } -} http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/10de190e/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseOutputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseOutputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseOutputStreamTest.java deleted file mode 100644 index fc211c3..0000000 --- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/NoCloseOutputStreamTest.java +++ /dev/null @@ -1,69 +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.io; - -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.Date; - -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:[email protected]">Apache MINA SSHD Project</a> - */ -@FixMethodOrder(MethodSorters.NAME_ASCENDING) -@Category({ NoIoTestCase.class }) -public class NoCloseOutputStreamTest extends BaseTestSupport { - public NoCloseOutputStreamTest() { - super(); - } - - @Test - public void testCanKeepWritingAfterClose() throws IOException { - Path dir = createTempClassFolder(); - Path file = dir.resolve(getCurrentTestName() + ".txt"); - Files.deleteIfExists(file); - - String expectedOutput = getClass().getName() + "#" + getCurrentTestName() + "@" + new Date(); - byte[] expected = expectedOutput.getBytes(StandardCharsets.UTF_8); - try (OutputStream fileStream = Files.newOutputStream(file); - OutputStream shielded = new NoCloseOutputStream(fileStream)) { - int index = 0; - for (; index < (expected.length / 2); index++) { - shielded.close(); - shielded.write(expected[index] & 0xFF); - } - - fileStream.write(expected, index, expected.length - index); - } - - byte[] actual = Files.readAllBytes(file); - String actualOutput = new String(actual, StandardCharsets.UTF_8); - assertEquals(expectedOutput, actualOutput); - } -}
