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 2020/04/07 20:48:05 UTC

[mina-sshd] branch master updated: [SSHD-974] Add (ignored) authorized keys test for specific files

This is an automated email from the ASF dual-hosted git repository.

lgoldstein pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mina-sshd.git


The following commit(s) were added to refs/heads/master by this push:
     new 5b7ae15  [SSHD-974] Add (ignored) authorized keys test for specific files
5b7ae15 is described below

commit 5b7ae15d8fac8513f32d968c175f1e01adb80cbf
Author: Lyor Goldstein <lg...@apache.org>
AuthorDate: Sun Mar 29 18:29:40 2020 +0300

    [SSHD-974] Add (ignored) authorized keys test for specific files
---
 .../common/config/keys/AuthorizedKeyEntryTest.java | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java
index cf0c5c4..ccdbf8f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeyEntryTest.java
@@ -19,10 +19,12 @@
 
 package org.apache.sshd.common.config.keys;
 
+import java.io.File;
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.LinkOption;
 import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.security.GeneralSecurityException;
 import java.security.PublicKey;
 import java.util.Collection;
@@ -98,14 +100,20 @@ public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport {
         }
     }
 
-    private void runAuthorizedKeysTests(Collection<AuthorizedKeyEntry> entries) throws Exception {
+    @Test
+    @Ignore("Used to test specific files")
+    public void testSpecificFile() throws Exception {
+        Path path = Paths.get("C:" + File.separator + "Temp", "id_ed25519.pub");
+        testReadAuthorizedKeys(AuthorizedKeyEntry.readAuthorizedKeys(path));
+    }
+
+    private <C extends Collection<AuthorizedKeyEntry>> C runAuthorizedKeysTests(C entries) throws Exception {
         testReadAuthorizedKeys(entries);
         testAuthorizedKeysAuth(entries);
+        return entries;
     }
 
-    private static Collection<AuthorizedKeyEntry> testReadAuthorizedKeys(
-            Collection<AuthorizedKeyEntry> entries)
-                throws Exception {
+    private static <C extends Collection<AuthorizedKeyEntry>> C testReadAuthorizedKeys(C entries) throws Exception {
         assertFalse("No entries read", GenericUtils.isEmpty(entries));
 
         Exception err = null;
@@ -117,8 +125,8 @@ public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport {
                     entry);
             } catch (Exception e) {
                 System.err.append("Failed (").append(e.getClass().getSimpleName()).append(')')
-                        .append(" to resolve key of entry=").append(entry.toString())
-                        .append(": ").println(e.getMessage());
+                    .append(" to resolve key of entry=").append(entry.toString())
+                    .append(": ").println(e.getMessage());
                 err = e;
             }
         }
@@ -138,7 +146,8 @@ public class AuthorizedKeyEntryTest extends AuthorizedKeysTestSupport {
             PublickeyAuthenticator.fromAuthorizedEntries(
                 getCurrentTestName(), null, entries, PublicKeyEntryResolver.FAILING);
         for (PublicKey key : keySet) {
-            assertTrue("Failed to authenticate with key=" + key.getAlgorithm(), auth.authenticate(getCurrentTestName(), key, null));
+            assertTrue("Failed to authenticate with key=" + key.getAlgorithm(),
+                auth.authenticate(getCurrentTestName(), key, null));
         }
 
         return auth;