Repository: zeppelin Updated Branches: refs/heads/master 340b326d4 -> 73426b4ef
[ZEPPELIN-2846] Add selenium test case for AnyOfRolesAuthorizationFilter ### What is this PR for? This is to test the new feature that was brought in with ZEPPELIN-2825 (org.apache.zeppelin.utils.AnyOfRolesAuthorizationFilter) ### What type of PR is it? [Improvement] ### What is the Jira issue? * [ZEPPELIN-2846](https://issues.apache.org/jira/browse/ZEPPELIN-2846) ### How should this be tested? CI should be green ### Questions: * Does the licenses files need update? N/A * Is there breaking changes for older versions? N/A * Does this needs documentation? N/A Author: Prabhjyot Singh <[email protected]> Closes #2524 from prabhjyotsingh/ZEPPELIN-2846 and squashes the following commits: e2a7ad548 [Prabhjyot Singh] add selenium test case for AnyOfRolesAuthorizationFilter Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/73426b4e Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/73426b4e Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/73426b4e Branch: refs/heads/master Commit: 73426b4ef410db67020ead7e6e6421ec71bed5c2 Parents: 340b326 Author: Prabhjyot Singh <[email protected]> Authored: Thu Aug 10 16:27:28 2017 -0700 Committer: Prabhjyot Singh <[email protected]> Committed: Wed Aug 16 12:12:37 2017 -0700 ---------------------------------------------------------------------- .../org/apache/zeppelin/AbstractZeppelinIT.java | 1 + .../zeppelin/integration/AuthenticationIT.java | 62 +++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/zeppelin/blob/73426b4e/zeppelin-server/src/test/java/org/apache/zeppelin/AbstractZeppelinIT.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/AbstractZeppelinIT.java b/zeppelin-server/src/test/java/org/apache/zeppelin/AbstractZeppelinIT.java index 475be50..6f537fd 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/AbstractZeppelinIT.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/AbstractZeppelinIT.java @@ -40,6 +40,7 @@ abstract public class AbstractZeppelinIT { protected static WebDriver driver; protected final static Logger LOG = LoggerFactory.getLogger(AbstractZeppelinIT.class); + protected static final long MIN_IMPLICIT_WAIT = 5; protected static final long MAX_IMPLICIT_WAIT = 30; protected static final long MAX_BROWSER_TIMEOUT_SEC = 30; protected static final long MAX_PARAGRAPH_TIMEOUT_SEC = 120; http://git-wip-us.apache.org/repos/asf/zeppelin/blob/73426b4e/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java ---------------------------------------------------------------------- diff --git a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java index f87bff2..38fe574 100644 --- a/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java +++ b/zeppelin-server/src/test/java/org/apache/zeppelin/integration/AuthenticationIT.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.List; - import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.zeppelin.AbstractZeppelinIT; @@ -38,6 +37,7 @@ import org.junit.Test; import org.junit.rules.ErrorCollector; import org.openqa.selenium.By; import org.openqa.selenium.Keys; +import org.openqa.selenium.TimeoutException; import org.openqa.selenium.WebElement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -63,12 +63,14 @@ public class AuthenticationIT extends AbstractZeppelinIT { "securityManager.sessionManager = $sessionManager\n" + "securityManager.sessionManager.globalSessionTimeout = 86400000\n" + "shiro.loginUrl = /api/login\n" + + "anyofroles = org.apache.zeppelin.utils.AnyOfRolesAuthorizationFilter\n" + "[roles]\n" + "admin = *\n" + "hr = *\n" + "finance = *\n" + "[urls]\n" + "/api/version = anon\n" + + "/api/interpreter/** = authc, anyofroles[admin, finance]\n" + "/** = authc"; static String originalShiro = ""; @@ -183,6 +185,62 @@ public class AuthenticationIT extends AbstractZeppelinIT { } @Test + public void testAnyOfRoles() throws Exception { + if (!endToEndTestEnabled()) { + return; + } + try { + AuthenticationIT authenticationIT = new AuthenticationIT(); + authenticationIT.authenticationUser("admin", "password1"); + + pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"), + MAX_BROWSER_TIMEOUT_SEC).click(); + clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]")); + + collector.checkThat("Check is user has permission to view this page", true, + CoreMatchers.equalTo(pollingWait(By.xpath( + "//div[@id='main']/div/div[2]"), + MIN_IMPLICIT_WAIT).isDisplayed()) + ); + + authenticationIT.logoutUser("admin"); + + authenticationIT.authenticationUser("finance1", "finance1"); + + pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"), + MAX_BROWSER_TIMEOUT_SEC).click(); + clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]")); + + collector.checkThat("Check is user has permission to view this page", true, + CoreMatchers.equalTo(pollingWait(By.xpath( + "//div[@id='main']/div/div[2]"), + MIN_IMPLICIT_WAIT).isDisplayed()) + ); + + authenticationIT.logoutUser("finance1"); + + authenticationIT.authenticationUser("hr1", "hr1"); + + pollingWait(By.xpath("//div/button[contains(@class, 'nav-btn dropdown-toggle ng-scope')]"), + MAX_BROWSER_TIMEOUT_SEC).click(); + clickAndWait(By.xpath("//li/a[contains(@href, '#/interpreter')]")); + + try { + collector.checkThat("Check is user has permission to view this page", + true, CoreMatchers.equalTo( + pollingWait(By.xpath("//li[contains(@class, 'ng-toast__message')]//span/span"), + MIN_IMPLICIT_WAIT).isDisplayed())); + } catch (TimeoutException e) { + throw new Exception("Expected ngToast not found", e); + } + authenticationIT.logoutUser("hr1"); + + } catch (Exception e) { + handleException("Exception in AuthenticationIT while testAnyOfRoles ", e); + } + } + + @Test public void testGroupPermission() throws Exception { if (!endToEndTestEnabled()) { return; @@ -254,7 +312,7 @@ public class AuthenticationIT extends AbstractZeppelinIT { } catch (Exception e) { - handleException("Exception in ParagraphActionsIT while testGroupPermission ", e); + handleException("Exception in AuthenticationIT while testGroupPermission ", e); } }
