You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ignite.apache.org by "petrov-mg (via GitHub)" <gi...@apache.org> on 2023/03/14 20:44:20 UTC

[GitHub] [ignite] petrov-mg opened a new pull request, #10595: IGNITE-19030 .Net: Added authorization of compute tasks.

petrov-mg opened a new pull request, #10595:
URL: https://github.com/apache/ignite/pull/10595

   Thank you for submitting the pull request to the Apache Ignite.
   
   In order to streamline the review of the contribution 
   we ask you to ensure the following steps have been taken:
   
   ### The Contribution Checklist
   - [ ] There is a single JIRA ticket related to the pull request. 
   - [ ] The web-link to the pull request is attached to the JIRA ticket.
   - [ ] The JIRA ticket has the _Patch Available_ state.
   - [ ] The pull request body describes changes that have been made. 
   The description explains _WHAT_ and _WHY_ was made instead of _HOW_.
   - [ ] The pull request title is treated as the final commit message. 
   The following pattern must be used: `IGNITE-XXXX Change summary` where `XXXX` - number of JIRA issue.
   - [ ] A reviewer has been mentioned through the JIRA comments 
   (see [the Maintainers list](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute#HowtoContribute-ReviewProcessandMaintainers)) 
   - [ ] The pull request has been checked by the Teamcity Bot and 
   the `green visa` attached to the JIRA ticket (see [TC.Bot: Check PR](https://mtcga.gridgain.com/prs.html))
   
   ### Notes
   - [How to Contribute](https://cwiki.apache.org/confluence/display/IGNITE/How+to+Contribute)
   - [Coding abbreviation rules](https://cwiki.apache.org/confluence/display/IGNITE/Abbreviation+Rules)
   - [Coding Guidelines](https://cwiki.apache.org/confluence/display/IGNITE/Coding+Guidelines)
   - [Apache Ignite Teamcity Bot](https://cwiki.apache.org/confluence/display/IGNITE/Apache+Ignite+Teamcity+Bot)
   
   If you need any help, please email dev@ignite.apache.org or ask anу advice on http://asf.slack.com _#ignite_ channel.
   


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1141029078


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+            };
+
+            _grid = Ignition.Start(cfg);
+
+            _grid.CreateCache<object, object>(CacheName);
+        }
+
+        /// <summary/>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary/>
+        [Test]
+        public void TestComputeSecurityExecutePermission()
+        {
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task, null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<object, int, int>(task.GetType(), null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<int, int>(task.GetType()));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType()).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().Call(func));
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(CacheName, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(new[] { CacheName }, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func, ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables, new TestReducer()));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer()).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer(), ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, ct).GetResult());
+
+            CheckCallable((callable, ct) => _grid.GetCompute().Broadcast(callable));
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable).GetResult());
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Broadcast(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0, ct).GetResult());
+
+            CheckAction((action, ct) => _grid.GetCompute().Broadcast(action));
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().Run(action));
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(CacheName, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(new[] { CacheName }, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action, ct).Wait());
+
+            CheckActions((actions, ct) => _grid.GetCompute().Run(actions));
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions).Wait());
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions, ct).Wait());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }, new TestReducer()));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer()).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer(), ct).GetResult());
+        }
+        
+        /// <summary/>
+        [Test]
+        public void TestComputeTaskSecurityCancelPermission()
+        {
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct));
+        }
+
+        /// <summary/> 
+        private void CheckFunction(Action<IComputeFunc<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedFunction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenFunction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallable(Action<IComputeFunc<int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedCallable(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenCallable(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallables(Action<IEnumerable<IComputeFunc<int>>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedCallable() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeFunc<int>[] { new ExecuteAllowedCallable(), new ExecuteForbiddenCallable() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckAction(Action<IComputeAction, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedAction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenAction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckActions(Action<IEnumerable<IComputeAction>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedAction() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeAction[] { new ExecuteAllowedAction(), new ExecuteForbiddenAction() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckTask(Action<IComputeTask<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedTask(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenTask(), token));
+        }
+        
+        /// <summary/> 
+        private void CheckTaskCancel(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CheckTaskCancelSucceeded(executor);
+            CheckTaskCancelFailed(executor);
+        }
+        
+        /// <summary/>
+        private void CheckTaskCancelFailed(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+           CancelledJobCounter = 0;
+           ExecutedJobCounter = 0;
+           
+           JobStartedLatch = new CountdownEvent(1);
+           JobUnblockedLatch = new CountdownEvent(1);
+
+           using var cts = new CancellationTokenSource();
+
+           var fut = executor.Invoke(new ExecuteAllowedTask(), cts.Token);
+
+           JobStartedLatch.Wait(5000);
+
+           AssertAuthorizationException(() => cts.Cancel());
+           
+           Assert.False(fut.IsCanceled);
+           
+           JobUnblockedLatch.Signal();
+           
+           Assert.AreEqual(0, CancelledJobCounter);
+           TestUtils.WaitForTrueCondition(() => 1 == ExecutedJobCounter); 
+        }
+
+        /// <summary/>
+        private void CheckTaskCancelSucceeded(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CancelledJobCounter = 0;
+            ExecutedJobCounter = 0;
+            
+            JobStartedLatch = new CountdownEvent(1);
+            JobUnblockedLatch = new CountdownEvent(1);
+
+            using var cts = new CancellationTokenSource();
+
+            var fut = executor.Invoke(new ExecuteCancelAllowedTask(), cts.Token);
+
+            JobStartedLatch.Wait(5000);
+
+            cts.Cancel();
+            
+            TestUtils.WaitForTrueCondition(() => fut.IsCanceled);
+            
+            JobUnblockedLatch.Signal();
+            
+            Assert.AreEqual(1, CancelledJobCounter);
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionSucceeded(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+
+            action(cts.Token);
+
+            Assert.AreEqual(1, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionFailed(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+            
+            var token = cts.Token;
+            
+            AssertAuthorizationException(() => action(token));
+
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void AssertAuthorizationException(Action action)
+        {
+            Exception ex = null;
+
+            try
+            {
+                action();
+            }
+            catch (AggregateException aggregateException)
+            {
+                ex = aggregateException.GetBaseException();
+            }
+            catch (Exception exception)
+            {
+                ex = exception;
+            }

Review Comment:
   Fixed.



##########
modules/platforms/cpp/core-test/src/compute_security_test.cpp:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/chrono.hpp>
+
+#include <ignite/ignition.h>
+#include <ignite/test_utils.h>
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cluster;
+using namespace ignite::compute;
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+using namespace ignite_test;
+
+using namespace boost::unit_test;
+
+// Currently we cannot validate exceptions produced by non "affinity" compute methods
+// see https://issues.apache.org/jira/browse/IGNITE-19055
+#define CHECK_COMPUTE_FAILED(doCompute)                                                                 \
+{                                                                                                       \
+    int32_t errCode = -1;                                                                               \
+                                                                                                        \
+    try {                                                                                               \
+        doCompute;                                                                                      \
+    }                                                                                                   \
+    catch (IgniteError& err) {                                                                          \
+        errCode = err.GetCode();                                                                        \
+                                                                                                        \
+        if (errCode == IgniteError::IGNITE_ERR_GENERIC) {                                               \
+            BOOST_ASSERT(std::string(err.GetText()).find("Authorization failed") != std::string::npos); \
+        }                                                                                               \
+    }                                                                                                   \
+                                                                                                        \
+    BOOST_ASSERT(errCode != -1);                                                                        \
+}                                                                                                       \
+
+/** */
+struct ComputeSecurityTestSuiteFixture {
+    /** */
+    Ignite node;
+
+    /** */
+    ComputeSecurityTestSuiteFixture() : node(StartNode("compute-security.xml", "test-node")) {
+        // No-op.
+    }
+
+    /** */
+    ~ComputeSecurityTestSuiteFixture()
+    {
+        Ignition::StopAll(true);
+    }
+};
+
+struct AbstractCallable : ComputeFunc<int> {
+    virtual int Call() {
+        return 42;
+    }
+};
+
+/** */
+struct AllowedCallable : AbstractCallable { };
+
+/** */
+struct ForbiddenCallable : AbstractCallable { };
+
+/** */
+struct AbstractRunnable : ComputeFunc<void> {
+    virtual void Call() {
+        // No-op.
+    }
+};
+
+/** */
+struct AllowedRunnable : AbstractRunnable { };
+
+/** */
+struct ForbiddenRunnable : AbstractRunnable { };
+
+namespace ignite {
+    namespace binary {
+        template<>
+        struct BinaryType<AllowedCallable> : BinaryTypeDefaultAll<AllowedCallable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "AllowedCallable";
+            }
+
+            static void Write(BinaryWriter&, const AllowedCallable&) {}
+
+            static void Read(BinaryReader&, AllowedCallable&) {}
+        };
+
+        template<>
+        struct BinaryType<ForbiddenCallable> : BinaryTypeDefaultAll<ForbiddenCallable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "ForbiddenCallable";
+            }
+
+            static void Write(BinaryWriter&, const ForbiddenCallable&) {}
+
+            static void Read(BinaryReader&, ForbiddenCallable&) {}
+        };
+
+        template<>
+        struct BinaryType<AllowedRunnable> : BinaryTypeDefaultAll<AllowedRunnable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "AllowedRunnable";
+            }
+
+            static void Write(BinaryWriter&, const AllowedRunnable&) {}
+
+            static void Read(BinaryReader&, AllowedRunnable&) {}
+        };
+
+        template<>
+        struct BinaryType<ForbiddenRunnable> : BinaryTypeDefaultAll<ForbiddenRunnable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "ForbiddenRunnable";
+            }
+
+            static void Write(BinaryWriter&, const ForbiddenRunnable&) {}
+
+            static void Read(BinaryReader&, ForbiddenRunnable&) {}
+        };
+    }
+}
+
+BOOST_FIXTURE_TEST_SUITE(ComputeSecurityTestSuite, ComputeSecurityTestSuiteFixture)
+
+    BOOST_AUTO_TEST_CASE(TestComputeSecurity) {
+        Compute compute = node.GetCompute();
+
+
+        BOOST_ASSERT(42 == compute.Call<int>(AllowedCallable()));

Review Comment:
   Fixed.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1139868346


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+                JvmClasspath = TestUtils.CreateTestClasspath()

Review Comment:
   Fixed.



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on PR #10595:
URL: https://github.com/apache/ignite/pull/10595#issuecomment-1473300989

   @ptupitsyn @isapego I would sincerely appreciate it if you could take a look at my changes.


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1139868073


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest

Review Comment:
   Fixed.



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration

Review Comment:
   Fixed.
   



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1141030168


##########
modules/platforms/cpp/core-test/src/compute_security_test.cpp:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/chrono.hpp>
+
+#include <ignite/ignition.h>
+#include <ignite/test_utils.h>
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cluster;
+using namespace ignite::compute;
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+using namespace ignite_test;
+
+using namespace boost::unit_test;
+
+// Currently we cannot validate exceptions produced by non "affinity" compute methods
+// see https://issues.apache.org/jira/browse/IGNITE-19055
+#define CHECK_COMPUTE_FAILED(doCompute)                                                                 \
+{                                                                                                       \
+    int32_t errCode = -1;                                                                               \
+                                                                                                        \
+    try {                                                                                               \
+        doCompute;                                                                                      \
+    }                                                                                                   \
+    catch (IgniteError& err) {                                                                          \
+        errCode = err.GetCode();                                                                        \
+                                                                                                        \
+        if (errCode == IgniteError::IGNITE_ERR_GENERIC) {                                               \
+            BOOST_ASSERT(std::string(err.GetText()).find("Authorization failed") != std::string::npos); \
+        }                                                                                               \
+    }                                                                                                   \
+                                                                                                        \
+    BOOST_ASSERT(errCode != -1);                                                                        \
+}                                                                                                       \

Review Comment:
   I had a problem to check the security error message in case authoriation fails. 
   Here is description of the problem i'm stuck with - https://issues.apache.org/jira/browse/IGNITE-19055
   
   I refactored the tests according to your suggestion. But all security exception message checks are now skipped. I think we can add them when IGNITE-19055 is resolved. 



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg merged pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg merged PR #10595:
URL: https://github.com/apache/ignite/pull/10595


-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] ptupitsyn commented on a diff in pull request #10595: IGNITE-19030 .NET: Add authorization of Compute tasks

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1136537747


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration

Review Comment:
   ```suggestion
               var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
   ```



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest

Review Comment:
   Please rename the file to match the class name.



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecuritymisionsTest.cs:
##########
@@ -0,0 +1,450 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+                JvmClasspath = TestUtils.CreateTestClasspath()

Review Comment:
   ```suggestion
   ```



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] isapego commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "isapego (via GitHub)" <gi...@apache.org>.
isapego commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1141000670


##########
modules/platforms/cpp/core-test/src/compute_security_test.cpp:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/chrono.hpp>
+
+#include <ignite/ignition.h>
+#include <ignite/test_utils.h>
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cluster;
+using namespace ignite::compute;
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+using namespace ignite_test;
+
+using namespace boost::unit_test;
+
+// Currently we cannot validate exceptions produced by non "affinity" compute methods
+// see https://issues.apache.org/jira/browse/IGNITE-19055
+#define CHECK_COMPUTE_FAILED(doCompute)                                                                 \
+{                                                                                                       \
+    int32_t errCode = -1;                                                                               \
+                                                                                                        \
+    try {                                                                                               \
+        doCompute;                                                                                      \
+    }                                                                                                   \
+    catch (IgniteError& err) {                                                                          \
+        errCode = err.GetCode();                                                                        \
+                                                                                                        \
+        if (errCode == IgniteError::IGNITE_ERR_GENERIC) {                                               \
+            BOOST_ASSERT(std::string(err.GetText()).find("Authorization failed") != std::string::npos); \
+        }                                                                                               \
+    }                                                                                                   \
+                                                                                                        \
+    BOOST_ASSERT(errCode != -1);                                                                        \
+}                                                                                                       \

Review Comment:
   Why won't you use `BOOST_CHECK_EXCEPTION`?



##########
modules/platforms/cpp/core-test/src/compute_security_test.cpp:
##########
@@ -0,0 +1,187 @@
+/*
+ * 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.
+ */
+
+#include <boost/test/unit_test.hpp>
+#include <boost/chrono.hpp>
+
+#include <ignite/ignition.h>
+#include <ignite/test_utils.h>
+
+using namespace ignite;
+using namespace ignite::cache;
+using namespace ignite::cluster;
+using namespace ignite::compute;
+using namespace ignite::common::concurrent;
+using namespace ignite::impl;
+using namespace ignite_test;
+
+using namespace boost::unit_test;
+
+// Currently we cannot validate exceptions produced by non "affinity" compute methods
+// see https://issues.apache.org/jira/browse/IGNITE-19055
+#define CHECK_COMPUTE_FAILED(doCompute)                                                                 \
+{                                                                                                       \
+    int32_t errCode = -1;                                                                               \
+                                                                                                        \
+    try {                                                                                               \
+        doCompute;                                                                                      \
+    }                                                                                                   \
+    catch (IgniteError& err) {                                                                          \
+        errCode = err.GetCode();                                                                        \
+                                                                                                        \
+        if (errCode == IgniteError::IGNITE_ERR_GENERIC) {                                               \
+            BOOST_ASSERT(std::string(err.GetText()).find("Authorization failed") != std::string::npos); \
+        }                                                                                               \
+    }                                                                                                   \
+                                                                                                        \
+    BOOST_ASSERT(errCode != -1);                                                                        \
+}                                                                                                       \
+
+/** */
+struct ComputeSecurityTestSuiteFixture {
+    /** */
+    Ignite node;
+
+    /** */
+    ComputeSecurityTestSuiteFixture() : node(StartNode("compute-security.xml", "test-node")) {
+        // No-op.
+    }
+
+    /** */
+    ~ComputeSecurityTestSuiteFixture()
+    {
+        Ignition::StopAll(true);
+    }
+};
+
+struct AbstractCallable : ComputeFunc<int> {
+    virtual int Call() {
+        return 42;
+    }
+};
+
+/** */
+struct AllowedCallable : AbstractCallable { };
+
+/** */
+struct ForbiddenCallable : AbstractCallable { };
+
+/** */
+struct AbstractRunnable : ComputeFunc<void> {
+    virtual void Call() {
+        // No-op.
+    }
+};
+
+/** */
+struct AllowedRunnable : AbstractRunnable { };
+
+/** */
+struct ForbiddenRunnable : AbstractRunnable { };
+
+namespace ignite {
+    namespace binary {
+        template<>
+        struct BinaryType<AllowedCallable> : BinaryTypeDefaultAll<AllowedCallable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "AllowedCallable";
+            }
+
+            static void Write(BinaryWriter&, const AllowedCallable&) {}
+
+            static void Read(BinaryReader&, AllowedCallable&) {}
+        };
+
+        template<>
+        struct BinaryType<ForbiddenCallable> : BinaryTypeDefaultAll<ForbiddenCallable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "ForbiddenCallable";
+            }
+
+            static void Write(BinaryWriter&, const ForbiddenCallable&) {}
+
+            static void Read(BinaryReader&, ForbiddenCallable&) {}
+        };
+
+        template<>
+        struct BinaryType<AllowedRunnable> : BinaryTypeDefaultAll<AllowedRunnable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "AllowedRunnable";
+            }
+
+            static void Write(BinaryWriter&, const AllowedRunnable&) {}
+
+            static void Read(BinaryReader&, AllowedRunnable&) {}
+        };
+
+        template<>
+        struct BinaryType<ForbiddenRunnable> : BinaryTypeDefaultAll<ForbiddenRunnable> {
+            static void GetTypeName(std::string &dst) {
+                dst = "ForbiddenRunnable";
+            }
+
+            static void Write(BinaryWriter&, const ForbiddenRunnable&) {}
+
+            static void Read(BinaryReader&, ForbiddenRunnable&) {}
+        };
+    }
+}
+
+BOOST_FIXTURE_TEST_SUITE(ComputeSecurityTestSuite, ComputeSecurityTestSuiteFixture)
+
+    BOOST_AUTO_TEST_CASE(TestComputeSecurity) {
+        Compute compute = node.GetCompute();
+
+
+        BOOST_ASSERT(42 == compute.Call<int>(AllowedCallable()));

Review Comment:
   Here and in other places:
   ```suggestion
           BOOST_CHECK_EQUAL(42, compute.Call<int>(AllowedCallable()));
   ```



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] ptupitsyn commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "ptupitsyn (via GitHub)" <gi...@apache.org>.
ptupitsyn commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1140380536


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 

Review Comment:
   Here and below - what's the point of empty summary? For the class, add some description please. Other comments on test code are not required I think.



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+            };
+
+            _grid = Ignition.Start(cfg);
+
+            _grid.CreateCache<object, object>(CacheName);
+        }
+
+        /// <summary/>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary/>
+        [Test]
+        public void TestComputeSecurityExecutePermission()
+        {
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task, null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<object, int, int>(task.GetType(), null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<int, int>(task.GetType()));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType()).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().Call(func));
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(CacheName, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(new[] { CacheName }, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func, ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables, new TestReducer()));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer()).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer(), ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, ct).GetResult());
+
+            CheckCallable((callable, ct) => _grid.GetCompute().Broadcast(callable));
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable).GetResult());
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Broadcast(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0, ct).GetResult());
+
+            CheckAction((action, ct) => _grid.GetCompute().Broadcast(action));
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().Run(action));
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(CacheName, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(new[] { CacheName }, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action, ct).Wait());
+
+            CheckActions((actions, ct) => _grid.GetCompute().Run(actions));
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions).Wait());
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions, ct).Wait());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }, new TestReducer()));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer()).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer(), ct).GetResult());
+        }
+        
+        /// <summary/>
+        [Test]
+        public void TestComputeTaskSecurityCancelPermission()
+        {
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct));
+        }
+
+        /// <summary/> 
+        private void CheckFunction(Action<IComputeFunc<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedFunction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenFunction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallable(Action<IComputeFunc<int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedCallable(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenCallable(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallables(Action<IEnumerable<IComputeFunc<int>>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedCallable() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeFunc<int>[] { new ExecuteAllowedCallable(), new ExecuteForbiddenCallable() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckAction(Action<IComputeAction, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedAction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenAction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckActions(Action<IEnumerable<IComputeAction>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedAction() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeAction[] { new ExecuteAllowedAction(), new ExecuteForbiddenAction() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckTask(Action<IComputeTask<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedTask(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenTask(), token));
+        }
+        
+        /// <summary/> 
+        private void CheckTaskCancel(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CheckTaskCancelSucceeded(executor);
+            CheckTaskCancelFailed(executor);
+        }
+        
+        /// <summary/>
+        private void CheckTaskCancelFailed(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+           CancelledJobCounter = 0;
+           ExecutedJobCounter = 0;
+           
+           JobStartedLatch = new CountdownEvent(1);
+           JobUnblockedLatch = new CountdownEvent(1);
+
+           using var cts = new CancellationTokenSource();
+
+           var fut = executor.Invoke(new ExecuteAllowedTask(), cts.Token);
+
+           JobStartedLatch.Wait(5000);
+
+           AssertAuthorizationException(() => cts.Cancel());
+           
+           Assert.False(fut.IsCanceled);
+           
+           JobUnblockedLatch.Signal();
+           
+           Assert.AreEqual(0, CancelledJobCounter);
+           TestUtils.WaitForTrueCondition(() => 1 == ExecutedJobCounter); 
+        }
+
+        /// <summary/>
+        private void CheckTaskCancelSucceeded(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CancelledJobCounter = 0;
+            ExecutedJobCounter = 0;
+            
+            JobStartedLatch = new CountdownEvent(1);
+            JobUnblockedLatch = new CountdownEvent(1);
+
+            using var cts = new CancellationTokenSource();
+
+            var fut = executor.Invoke(new ExecuteCancelAllowedTask(), cts.Token);
+
+            JobStartedLatch.Wait(5000);
+
+            cts.Cancel();
+            
+            TestUtils.WaitForTrueCondition(() => fut.IsCanceled);
+            
+            JobUnblockedLatch.Signal();
+            
+            Assert.AreEqual(1, CancelledJobCounter);
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionSucceeded(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+
+            action(cts.Token);
+
+            Assert.AreEqual(1, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionFailed(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+            
+            var token = cts.Token;
+            
+            AssertAuthorizationException(() => action(token));
+
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void AssertAuthorizationException(Action action)
+        {
+            Exception ex = null;
+
+            try
+            {
+                action();
+            }
+            catch (AggregateException aggregateException)
+            {
+                ex = aggregateException.GetBaseException();
+            }
+            catch (Exception exception)
+            {
+                ex = exception;
+            }
+            
+            Assert.NotNull(ex);
+            Assert.True(ex.GetBaseException().Message.Contains("Authorization failed"));

Review Comment:
   Let's use `StringAssert.Contains` - more readable and produces better messages in case of failure.



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+            };
+
+            _grid = Ignition.Start(cfg);
+
+            _grid.CreateCache<object, object>(CacheName);
+        }
+
+        /// <summary/>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary/>
+        [Test]
+        public void TestComputeSecurityExecutePermission()
+        {
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task, null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<object, int, int>(task.GetType(), null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<int, int>(task.GetType()));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType()).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().Call(func));
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(CacheName, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(new[] { CacheName }, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func, ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables, new TestReducer()));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer()).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer(), ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, ct).GetResult());
+
+            CheckCallable((callable, ct) => _grid.GetCompute().Broadcast(callable));
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable).GetResult());
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Broadcast(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0, ct).GetResult());
+
+            CheckAction((action, ct) => _grid.GetCompute().Broadcast(action));
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().Run(action));
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(CacheName, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(new[] { CacheName }, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action, ct).Wait());
+
+            CheckActions((actions, ct) => _grid.GetCompute().Run(actions));
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions).Wait());
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions, ct).Wait());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }, new TestReducer()));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer()).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer(), ct).GetResult());
+        }
+        
+        /// <summary/>
+        [Test]
+        public void TestComputeTaskSecurityCancelPermission()
+        {
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct));
+        }
+
+        /// <summary/> 
+        private void CheckFunction(Action<IComputeFunc<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedFunction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenFunction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallable(Action<IComputeFunc<int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedCallable(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenCallable(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallables(Action<IEnumerable<IComputeFunc<int>>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedCallable() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeFunc<int>[] { new ExecuteAllowedCallable(), new ExecuteForbiddenCallable() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckAction(Action<IComputeAction, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedAction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenAction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckActions(Action<IEnumerable<IComputeAction>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedAction() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeAction[] { new ExecuteAllowedAction(), new ExecuteForbiddenAction() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckTask(Action<IComputeTask<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedTask(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenTask(), token));
+        }
+        
+        /// <summary/> 
+        private void CheckTaskCancel(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CheckTaskCancelSucceeded(executor);
+            CheckTaskCancelFailed(executor);
+        }
+        
+        /// <summary/>
+        private void CheckTaskCancelFailed(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+           CancelledJobCounter = 0;
+           ExecutedJobCounter = 0;
+           
+           JobStartedLatch = new CountdownEvent(1);
+           JobUnblockedLatch = new CountdownEvent(1);
+
+           using var cts = new CancellationTokenSource();
+
+           var fut = executor.Invoke(new ExecuteAllowedTask(), cts.Token);
+
+           JobStartedLatch.Wait(5000);
+
+           AssertAuthorizationException(() => cts.Cancel());
+           
+           Assert.False(fut.IsCanceled);
+           
+           JobUnblockedLatch.Signal();
+           
+           Assert.AreEqual(0, CancelledJobCounter);
+           TestUtils.WaitForTrueCondition(() => 1 == ExecutedJobCounter); 
+        }
+
+        /// <summary/>
+        private void CheckTaskCancelSucceeded(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CancelledJobCounter = 0;
+            ExecutedJobCounter = 0;
+            
+            JobStartedLatch = new CountdownEvent(1);
+            JobUnblockedLatch = new CountdownEvent(1);
+
+            using var cts = new CancellationTokenSource();
+
+            var fut = executor.Invoke(new ExecuteCancelAllowedTask(), cts.Token);
+
+            JobStartedLatch.Wait(5000);
+
+            cts.Cancel();
+            
+            TestUtils.WaitForTrueCondition(() => fut.IsCanceled);
+            
+            JobUnblockedLatch.Signal();
+            
+            Assert.AreEqual(1, CancelledJobCounter);
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionSucceeded(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+
+            action(cts.Token);
+
+            Assert.AreEqual(1, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionFailed(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+            
+            var token = cts.Token;
+            
+            AssertAuthorizationException(() => action(token));
+
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void AssertAuthorizationException(Action action)
+        {
+            Exception ex = null;
+
+            try
+            {
+                action();
+            }
+            catch (AggregateException aggregateException)
+            {
+                ex = aggregateException.GetBaseException();
+            }
+            catch (Exception exception)
+            {
+                ex = exception;
+            }

Review Comment:
   ```suggestion
               var ex = Assert.Catch(() => action())
   ```



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [ignite] petrov-mg commented on a diff in pull request #10595: IGNITE-19030 Platforms: Add authorization of Compute tasks

Posted by "petrov-mg (via GitHub)" <gi...@apache.org>.
petrov-mg commented on code in PR #10595:
URL: https://github.com/apache/ignite/pull/10595#discussion_r1141029047


##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 

Review Comment:
   There is no point in them. Just Ignite 2 cargo cult. Removed.
   Added description for the test class. 



##########
modules/platforms/dotnet/Apache.Ignite.Core.Tests/Compute/ComputeSecurityPermissionsTest.cs:
##########
@@ -0,0 +1,449 @@
+/*
+ * 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.
+ */
+
+namespace Apache.Ignite.Core.Tests.Compute
+{
+    using System;
+    using System.Collections.Generic;
+    using System.Linq;
+    using System.Threading;
+    using System.Threading.Tasks;
+    using Apache.Ignite.Core.Cluster;
+    using Apache.Ignite.Core.Compute;
+    using NUnit.Framework;
+    using static AbstractTask.Job;
+    using static ComputeSecurityPermissionsTest;
+
+    /// <summary/> 
+    public class ComputeSecurityPermissionsTest
+    {
+        /// <summary/> 
+        private const string CacheName = "DEFAULT_CACHE_NAME";
+        
+        /// <summary/> 
+        public static int ExecutedJobCounter;
+        
+        /// <summary/> 
+        public static int CancelledJobCounter;
+        
+        /// <summary/> 
+        private IIgnite _grid;
+
+        /// <summary/> 
+        [TestFixtureSetUp]
+        public void FixtureSetUp()
+        {
+            var cfg = new IgniteConfiguration(TestUtils.GetTestConfiguration())
+            {
+                SpringConfigUrl = @"Config/Compute/compute-security.xml",
+            };
+
+            _grid = Ignition.Start(cfg);
+
+            _grid.CreateCache<object, object>(CacheName);
+        }
+
+        /// <summary/>
+        [TestFixtureTearDown]
+        public void FixtureTearDown()
+        {
+            Ignition.StopAll(true);
+        }
+
+        /// <summary/>
+        [Test]
+        public void TestComputeSecurityExecutePermission()
+        {
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task, null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute(task));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<object, int, int>(task.GetType(), null));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct).GetResult());
+
+            CheckTask((task, ct) => _grid.GetCompute().Execute<int, int>(task.GetType()));
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType()).GetResult());
+            CheckTask((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().Call(func));
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().CallAsync(func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(CacheName, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(CacheName, 0, func, ct).GetResult());
+
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCall(new[] { CacheName }, 0, func));
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func).GetResult());
+            CheckCallable((func, ct) => _grid.GetCompute().AffinityCallAsync(new[] { CacheName }, 0, func, ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables, new TestReducer()));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer()).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, new TestReducer(), ct).GetResult());
+
+            CheckCallables((callables, ct) => _grid.GetCompute().Call(callables));
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables).GetResult());
+            CheckCallables((callables, ct) => _grid.GetCompute().CallAsync(callables, ct).GetResult());
+
+            CheckCallable((callable, ct) => _grid.GetCompute().Broadcast(callable));
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable).GetResult());
+            CheckCallable((callable, ct) => _grid.GetCompute().BroadcastAsync(callable, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Broadcast(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().BroadcastAsync(func, 0, ct).GetResult());
+
+            CheckAction((action, ct) => _grid.GetCompute().Broadcast(action));
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().BroadcastAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().Run(action));
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().RunAsync(action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(CacheName, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(CacheName, 0, action, ct).Wait());
+
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRun(new[] { CacheName }, 0, action));
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action).Wait());
+            CheckAction((action, ct) => _grid.GetCompute().AffinityRunAsync(new[] { CacheName }, 0, action, ct).Wait());
+
+            CheckActions((actions, ct) => _grid.GetCompute().Run(actions));
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions).Wait());
+            CheckActions((actions, ct) => _grid.GetCompute().RunAsync(actions, ct).Wait());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, 0));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, 0, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, ct).GetResult());
+
+            CheckFunction((func, ct) => _grid.GetCompute().Apply(func, new[] { 0 }, new TestReducer()));
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer()).GetResult());
+            CheckFunction((func, ct) => _grid.GetCompute().ApplyAsync(func, new[] { 0 }, new TestReducer(), ct).GetResult());
+        }
+        
+        /// <summary/>
+        [Test]
+        public void TestComputeTaskSecurityCancelPermission()
+        {
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync(task, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<object, int, int>(task.GetType(), null, ct));
+            CheckTaskCancel((task, ct) => _grid.GetCompute().ExecuteAsync<int, int>(task.GetType(), ct));
+        }
+
+        /// <summary/> 
+        private void CheckFunction(Action<IComputeFunc<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedFunction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenFunction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallable(Action<IComputeFunc<int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedCallable(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenCallable(), token));
+        }
+
+        /// <summary/> 
+        private void CheckCallables(Action<IEnumerable<IComputeFunc<int>>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedCallable() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeFunc<int>[] { new ExecuteAllowedCallable(), new ExecuteForbiddenCallable() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckAction(Action<IComputeAction, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedAction(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenAction(), token));
+        }
+
+        /// <summary/> 
+        private void CheckActions(Action<IEnumerable<IComputeAction>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new[] { new ExecuteAllowedAction() }, token));
+            CheckExecutionFailed(token =>
+                executor(new IComputeAction[] { new ExecuteAllowedAction(), new ExecuteForbiddenAction() }, token));
+        }
+
+        /// <summary/> 
+        private void CheckTask(Action<IComputeTask<int, int>, CancellationToken> executor)
+        {
+            CheckExecutionSucceeded(token => executor(new ExecuteAllowedTask(), token));
+            CheckExecutionFailed(token => executor(new ExecuteForbiddenTask(), token));
+        }
+        
+        /// <summary/> 
+        private void CheckTaskCancel(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CheckTaskCancelSucceeded(executor);
+            CheckTaskCancelFailed(executor);
+        }
+        
+        /// <summary/>
+        private void CheckTaskCancelFailed(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+           CancelledJobCounter = 0;
+           ExecutedJobCounter = 0;
+           
+           JobStartedLatch = new CountdownEvent(1);
+           JobUnblockedLatch = new CountdownEvent(1);
+
+           using var cts = new CancellationTokenSource();
+
+           var fut = executor.Invoke(new ExecuteAllowedTask(), cts.Token);
+
+           JobStartedLatch.Wait(5000);
+
+           AssertAuthorizationException(() => cts.Cancel());
+           
+           Assert.False(fut.IsCanceled);
+           
+           JobUnblockedLatch.Signal();
+           
+           Assert.AreEqual(0, CancelledJobCounter);
+           TestUtils.WaitForTrueCondition(() => 1 == ExecutedJobCounter); 
+        }
+
+        /// <summary/>
+        private void CheckTaskCancelSucceeded(Func<IComputeTask<int, int>, CancellationToken, Task<int>> executor)
+        {
+            CancelledJobCounter = 0;
+            ExecutedJobCounter = 0;
+            
+            JobStartedLatch = new CountdownEvent(1);
+            JobUnblockedLatch = new CountdownEvent(1);
+
+            using var cts = new CancellationTokenSource();
+
+            var fut = executor.Invoke(new ExecuteCancelAllowedTask(), cts.Token);
+
+            JobStartedLatch.Wait(5000);
+
+            cts.Cancel();
+            
+            TestUtils.WaitForTrueCondition(() => fut.IsCanceled);
+            
+            JobUnblockedLatch.Signal();
+            
+            Assert.AreEqual(1, CancelledJobCounter);
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionSucceeded(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+
+            action(cts.Token);
+
+            Assert.AreEqual(1, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void CheckExecutionFailed(Action<CancellationToken> action)
+        {
+            ExecutedJobCounter = 0;
+
+            using var cts = new CancellationTokenSource();
+            
+            var token = cts.Token;
+            
+            AssertAuthorizationException(() => action(token));
+
+            Assert.AreEqual(0, ExecutedJobCounter);
+        }
+
+        /// <summary/>
+        private void AssertAuthorizationException(Action action)
+        {
+            Exception ex = null;
+
+            try
+            {
+                action();
+            }
+            catch (AggregateException aggregateException)
+            {
+                ex = aggregateException.GetBaseException();
+            }
+            catch (Exception exception)
+            {
+                ex = exception;
+            }
+            
+            Assert.NotNull(ex);
+            Assert.True(ex.GetBaseException().Message.Contains("Authorization failed"));

Review Comment:
   Fixed.
   



-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@ignite.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org