natural commented on a change in pull request #3495: NIFI-5973 Adds 
ShellUserGroupProvider
URL: https://github.com/apache/nifi/pull/3495#discussion_r291352470
 
 

 ##########
 File path: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-shell-authorizer/src/test/java/org/apache/nifi/authorization/ShellUserGroupProviderIT.java
 ##########
 @@ -0,0 +1,215 @@
+/*
+ * 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.nifi.authorization;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+import static org.mockito.Mockito.mock;
+
+import org.junit.rules.TemporaryFolder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.utility.MountableFile;
+
+import org.apache.nifi.authorization.util.ShellRunner;
+
+
+public class ShellUserGroupProviderIT extends ShellUserGroupProviderBase {
+    private static final Logger logger = 
LoggerFactory.getLogger(ShellUserGroupProviderIT.class);
+
+    private final static String ALPINE_IMAGE = "natural/alpine-sshd:latest";
+    private final static String CENTOS_IMAGE = "natural/centos-sshd:latest";
+    private final static String DEBIAN_IMAGE = "natural/debian-sshd:latest";
+    private final static String UBUNTU_IMAGE = "natural/ubuntu-sshd:latest";
+    private final static List<String> TEST_CONTAINER_IMAGES =
+        Arrays.asList(
+                      ALPINE_IMAGE,
+                      CENTOS_IMAGE,
+                      DEBIAN_IMAGE,
+                      UBUNTU_IMAGE
+                      );
+
+    private final static String CONTAINER_SSH_AUTH_KEYS = 
"/root/.ssh/authorized_keys";
+    private final static Integer CONTAINER_SSH_PORT = 22;
+
+    private static String sshPrivKeyFile;
+    private static String sshPubKeyFile;
+
+    private AuthorizerConfigurationContext authContext;
+    private ShellUserGroupProvider localProvider;
+    private UserGroupProviderInitializationContext initContext;
+
+    @ClassRule
+    static public TemporaryFolder tempFolder = new TemporaryFolder();
+
+    @Before
+    public void setup() throws IOException {
+        authContext = mock(AuthorizerConfigurationContext.class);
+        initContext = mock(UserGroupProviderInitializationContext.class);
+
+        localProvider = new ShellUserGroupProvider();
+        try {
+            localProvider.initialize(initContext);
+            localProvider.onConfigured(authContext);
+        } catch (final Exception exc) {
+            systemCheckFailed = true;
+            logger.error("setup() exception: " + exc + "; tests cannot run on 
this system.");
+            return;
+        }
+    }
+
+    @BeforeClass
+    public static void setupOnce() throws IOException {
+        sshPrivKeyFile = tempFolder.getRoot().getAbsolutePath() + "/id_rsa";
+        sshPubKeyFile = sshPrivKeyFile + ".pub";
+
+        try {
+            // NB: this command is a bit perplexing: it works without prompt 
from the shell, but hangs
+            // here without the pipe from `yes`:
+            ShellRunner.runShell("yes | ssh-keygen -C '' -N '' -t rsa -f " + 
sshPrivKeyFile);
+        } catch (final IOException ioexc) {
+            systemCheckFailed = true;
+            logger.error("setupOnce() exception: " + ioexc + "; tests cannot 
run on this system.");
+            return;
+        }
+
+        // Fix the file permissions to abide by the ssh client
+        // requirements:
+        Arrays.asList(sshPrivKeyFile, sshPubKeyFile).forEach(name -> {
+                final File f = new File(name);
+                assertTrue(f.setReadable(false, false));
+                assertTrue(f.setReadable(true));
+            });
+    }
+
+    @Test
+    public void testGetUsers() {
 
 Review comment:
   Renamed the test methods to be more descriptive, and added a small javadoc 
to each.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to