You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by zj...@apache.org on 2019/12/10 03:56:07 UTC
[zeppelin] branch master updated: [ZEPPELIN-4464] Fix Regression in
InterpreterSetting isUserAuthorized
This is an automated email from the ASF dual-hosted git repository.
zjffdu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new a92aac2 [ZEPPELIN-4464] Fix Regression in InterpreterSetting isUserAuthorized
a92aac2 is described below
commit a92aac23f7458282bf97b6e7ca2e47dfe24f332c
Author: Philipp Dallig <ph...@gmail.com>
AuthorDate: Mon Dec 2 11:59:06 2019 +0100
[ZEPPELIN-4464] Fix Regression in InterpreterSetting isUserAuthorized
### What is this PR for?
With ZEPPELIN-3734 we got a regression in InterpreterSettings.class in isUserAuthorized method.
### What type of PR is it?
Regression Fix
### Todos
*
### What is the Jira issue?
* https://issues.apache.org/jira/browse/ZEPPELIN-4464
### How should this be tested?
* Unit-Tests are added
Author: Philipp Dallig <ph...@gmail.com>
Closes #3531 from Reamer/correctInterpreterPermissions and squashes the following commits:
6c9bd6725 [Philipp Dallig] Fix Regression in InterpreterSetting isUserAuthorized
---
.../zeppelin/interpreter/InterpreterSetting.java | 2 +-
.../interpreter/InterpreterSettingTest.java | 53 ++++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
diff --git a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
index 7a6ce3a..4da96dc 100644
--- a/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
+++ b/zeppelin-zengine/src/main/java/org/apache/zeppelin/interpreter/InterpreterSetting.java
@@ -717,7 +717,7 @@ public class InterpreterSetting {
}
Set<String> intersection = new HashSet<>(userAndRoles);
intersection.retainAll(option.getOwners());
- return intersection.isEmpty();
+ return !intersection.isEmpty();
}
//////////////////////////// IMPORTANT ////////////////////////////////////////////////
diff --git a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
index eb02609..de01959 100644
--- a/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
+++ b/zeppelin-zengine/src/test/java/org/apache/zeppelin/interpreter/InterpreterSettingTest.java
@@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.List;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -465,4 +466,56 @@ public class InterpreterSettingTest {
assertNotNull(checkIntpSetting.getInterpreterInfo("echo"));
assertNotNull(checkIntpSetting.getInterpreterInfo("double_echo"));
}
+
+ @Test
+ public void testIsUserAuthorized() {
+ List<String> userAndRoles = new ArrayList<>();
+ userAndRoles.add("User1");
+ userAndRoles.add("Role1");
+ userAndRoles.add("Role2");
+ List<String> owners;
+ InterpreterSetting interpreterSetting;
+ InterpreterOption interpreterOption;
+
+ // With match
+ owners = new ArrayList<>();
+ owners.add("Role1");
+ interpreterOption = new InterpreterOption();
+ interpreterOption.setUserPermission(true);
+ interpreterOption.owners = owners;
+ interpreterSetting = new InterpreterSetting.Builder()
+ .setId("id")
+ .setName("id")
+ .setGroup("group")
+ .setOption(interpreterOption)
+ .create();
+ assertTrue(interpreterSetting.isUserAuthorized(userAndRoles));
+
+ // Without match
+ owners = new ArrayList<>();
+ owners.add("Role88");
+ interpreterOption = new InterpreterOption();
+ interpreterOption.setUserPermission(true);
+ interpreterOption.owners = owners;
+ interpreterSetting = new InterpreterSetting.Builder()
+ .setId("id")
+ .setName("id")
+ .setGroup("group")
+ .setOption(interpreterOption)
+ .create();
+ assertFalse(interpreterSetting.isUserAuthorized(userAndRoles));
+
+ // Without permissions
+ owners = new ArrayList<>();
+ interpreterOption = new InterpreterOption();
+ interpreterOption.setUserPermission(false);
+ interpreterOption.owners = owners;
+ interpreterSetting = new InterpreterSetting.Builder()
+ .setId("id")
+ .setName("id")
+ .setGroup("group")
+ .setOption(interpreterOption)
+ .create();
+ assertTrue(interpreterSetting.isUserAuthorized(userAndRoles));
+ }
}