You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by GitBox <gi...@apache.org> on 2020/02/05 12:29:09 UTC

[GitHub] [ignite] andrey-kuznetsov commented on a change in pull request #6904: IGNITE-12220

andrey-kuznetsov commented on a change in pull request #6904: IGNITE-12220
URL: https://github.com/apache/ignite/pull/6904#discussion_r375226971
 
 

 ##########
 File path: modules/core/src/test/java/org/apache/ignite/internal/processors/security/rest/handlers/cache/CacheOperationPermissionRestCommandHandlerCheckTest.java
 ##########
 @@ -0,0 +1,442 @@
+/*
+ * 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.ignite.internal.processors.security.rest.handlers.cache;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.DataRegionConfiguration;
+import org.apache.ignite.configuration.DataStorageConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteEx;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.rest.GridRestCommand;
+import org.apache.ignite.internal.processors.rest.GridRestResponse;
+import org.apache.ignite.internal.processors.rest.handlers.GridRestCommandHandler;
+import org.apache.ignite.internal.processors.rest.handlers.cache.GridCacheCommandHandler;
+import org.apache.ignite.internal.processors.rest.request.GridRestCacheRequest;
+import org.apache.ignite.internal.processors.rest.request.GridRestRequest;
+import org.apache.ignite.internal.processors.security.impl.TestSecurityPluginProvider;
+import org.apache.ignite.plugin.security.SecurityPermission;
+import org.apache.ignite.plugin.security.SecurityPermissionSetBuilder;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.plugin.security.SecurityException;
+import org.junit.Test;
+
+import static java.util.Collections.singletonMap;
+import static org.apache.ignite.plugin.security.SecurityPermission.*;
+import static org.apache.ignite.testframework.GridTestUtils.assertThrowsWithCause;
+
+/**
+ * Test CRUD, create and destroy cache permissions with rest commands handler.
+ */
+public class CacheOperationPermissionRestCommandHandlerCheckTest extends GridCommonAbstractTest {
+    /** Empty permission. */
+    private static final SecurityPermission[] EMPTY_PERMS = new SecurityPermission[0];
+
+    /** Cache name for tests. */
+    private static final String CACHE_NAME = "TEST_CACHE";
+
+    /** Forbidden cache. */
+    private static final String FORBIDDEN_CACHE_NAME = "FORBIDDEN_TEST_CACHE";
+
+    /** New cache. */
+    private static final String NEW_TEST_CACHE = "NEW_TEST_CACHE";
+
+    /** Key. */
+    private String key = "key";
+
+    /** Value. */
+    private String val = "value";
+
+    /** New value. */
+    private String newVal = "newValue";
+
+    /** Cache permissions. */
+    private Map<String, SecurityPermission[]> cachePerms = new HashMap<>();
+
+    /** Security permission set. */
+    private Set<SecurityPermission> secPermSet = new HashSet<>();
+
+    /** Default allow all. */
+    private boolean dfltAllowAll;
+
+    /** Handler. */
+    private GridRestCommandHandler hnd;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration() throws Exception {
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(new TcpDiscoveryVmIpFinder(true));
+
+        IgniteConfiguration cfg = super.getConfiguration();
+
+        cfg.setDiscoverySpi(disco);
+
+        SecurityPermissionSetBuilder builder = SecurityPermissionSetBuilder.create();
+
+        builder.defaultAllowAll(dfltAllowAll);
+
+        cachePerms.forEach((builder::appendCachePermissions));
+        secPermSet.forEach(builder::appendSystemPermissions);
+
+        cfg.setDataStorageConfiguration(
+            new DataStorageConfiguration()
+                .setDefaultDataRegionConfiguration(
+                    new DataRegionConfiguration()
+                        .setPersistenceEnabled(true)
+                )
+        )
+            .setAuthenticationEnabled(true)
+            .setPluginProviders(
+                new TestSecurityPluginProvider("login", "password", builder.build(), true));
+
+        return cfg;
+    }
+
+    /** */
+    @Test
+    public void testCacheCreate() throws Exception {
+        cachePerms.putIfAbsent(CACHE_NAME, new SecurityPermission[] {CACHE_CREATE});
+        cachePerms.putIfAbsent(FORBIDDEN_CACHE_NAME, EMPTY_PERMS);
+
+        startGrid(getConfiguration()).cluster().active(true);
+
+        assertTrue(grid().cacheNames().isEmpty());
+
+        cacheCreate(CACHE_NAME);
+
+        assertTrue(grid().cacheNames().contains(CACHE_NAME));
+
+        if (secPermSet.contains(CACHE_CREATE) || cachePermsContains(FORBIDDEN_CACHE_NAME, CACHE_CREATE)) {
 
 Review comment:
   What this condition is for? The state of secPermSet and cachePerms is known at compile time. This relates to some tests below as well.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services