aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKenny Root <kenny@the-b.org>2011-10-15 11:29:17 -0700
committerKenny Root <kenny@the-b.org>2011-10-15 11:29:17 -0700
commit629f7d6eefd67c3d8a59f5ec0cfc17b823dcd6c3 (patch)
treee594aa153bf3ae8fbd60d59e849e228ecf38c578 /tests
parenta7d16b81f466c32f549f2638f61d9376c65db47f (diff)
downloadconnectbot-629f7d6eefd67c3d8a59f5ec0cfc17b823dcd6c3.tar.gz
connectbot-629f7d6eefd67c3d8a59f5ec0cfc17b823dcd6c3.tar.bz2
connectbot-629f7d6eefd67c3d8a59f5ec0cfc17b823dcd6c3.zip
Add some test coverage for PubkeyUtils
Diffstat (limited to 'tests')
-rw-r--r--tests/src/org/connectbot/util/PubkeyUtilsTest.java62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/src/org/connectbot/util/PubkeyUtilsTest.java b/tests/src/org/connectbot/util/PubkeyUtilsTest.java
new file mode 100644
index 0000000..635b3be
--- /dev/null
+++ b/tests/src/org/connectbot/util/PubkeyUtilsTest.java
@@ -0,0 +1,62 @@
+/*
+ * ConnectBot: simple, powerful, open-source SSH client for Android
+ * Copyright 2007 Kenny Root, Jeffrey Sharkey
+ *
+ * Licensed 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.connectbot.util;
+
+import java.util.Arrays;
+
+import android.test.AndroidTestCase;
+
+/**
+ * @author Kenny Root
+ *
+ */
+public class PubkeyUtilsTest extends AndroidTestCase {
+ public void testEncodeHex_Null_Failure() throws Exception {
+ try {
+ PubkeyUtils.encodeHex(null);
+ fail("Should throw null pointer exception when argument is null");
+ } catch (NullPointerException e) {
+ // success
+ }
+ }
+ public void testEncodeHex_Success() throws Exception {
+ byte[] input = {(byte) 0xFF, 0x00, (byte) 0xA5, 0x5A, 0x12, 0x23};
+ String expected = "ff00a55a1223";
+
+ assertEquals("Encoded hex should match expected",
+ PubkeyUtils.encodeHex(input), expected);
+ }
+
+ public void testSha256_Empty_Success() throws Exception {
+ byte[] empty_hashed = new byte[] {
+ (byte) 0xe3, (byte) 0xb0, (byte) 0xc4, (byte) 0x42,
+ (byte) 0x98, (byte) 0xfc, (byte) 0x1c, (byte) 0x14,
+ (byte) 0x9a, (byte) 0xfb, (byte) 0xf4, (byte) 0xc8,
+ (byte) 0x99, (byte) 0x6f, (byte) 0xb9, (byte) 0x24,
+ (byte) 0x27, (byte) 0xae, (byte) 0x41, (byte) 0xe4,
+ (byte) 0x64, (byte) 0x9b, (byte) 0x93, (byte) 0x4c,
+ (byte) 0xa4, (byte) 0x95, (byte) 0x99, (byte) 0x1b,
+ (byte) 0x78, (byte) 0x52, (byte) 0xb8, (byte) 0x55,
+ };
+
+ final byte[] empty = new byte[] {};
+
+ assertTrue("Empty string should be equal to known test vector",
+ Arrays.equals(empty_hashed, PubkeyUtils.sha256(empty)));
+ }
+}