Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.cookie.CookiePolicy;
Expand Down Expand Up @@ -333,7 +334,7 @@ protected static boolean checkIfServerIsRunning() {
GetMethod request = null;
boolean isRunning = true;
try {
request = httpGet("/");
request = httpGet("/version");
isRunning = request.getStatusCode() == 200;
} catch (IOException e) {
LOG.error("AbstractTestRestApi.checkIfServerIsRunning() fails .. ZeppelinServer is not running");
Expand Down Expand Up @@ -427,8 +428,14 @@ private static String getCookie(String user, String password) throws IOException
httpClient.executeMethod(postMethod);
LOG.info("{} - {}", postMethod.getStatusCode(), postMethod.getStatusText());
Pattern pattern = Pattern.compile("JSESSIONID=([a-zA-Z0-9-]*)");
java.util.regex.Matcher matcher = pattern.matcher(postMethod.getResponseHeaders("Set-Cookie")[0].toString());
return matcher.find()? matcher.group(1) : StringUtils.EMPTY;
Header[] setCookieHeaders = postMethod.getResponseHeaders("Set-Cookie");
for (Header setCookie : setCookieHeaders) {
java.util.regex.Matcher matcher = pattern.matcher(setCookie.toString());
if (matcher.find()) {
return matcher.group(1);
}
}
return StringUtils.EMPTY;
}

protected static boolean userAndPasswordAreNotBlank(String user, String pwd) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SecurityRestApiTest extends AbstractTestRestApi {

@BeforeClass
public static void init() throws Exception {
AbstractTestRestApi.startUpWithAuthenticationEnable();;
AbstractTestRestApi.startUpWithAuthenticationEnable();
}

@AfterClass
Expand All @@ -50,21 +50,21 @@ public static void destroy() throws Exception {

@Test
public void testTicket() throws IOException {
GetMethod get = httpGet("/security/ticket");
GetMethod get = httpGet("/security/ticket", "admin", "password1");
get.addRequestHeader("Origin", "http://localhost");
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
new TypeToken<Map<String, Object>>(){}.getType());
Map<String, String> body = (Map<String, String>) resp.get("body");
collector.checkThat("Paramater principal", body.get("principal"),
CoreMatchers.equalTo("anonymous"));
CoreMatchers.equalTo("admin"));
collector.checkThat("Paramater ticket", body.get("ticket"),
CoreMatchers.equalTo("anonymous"));
CoreMatchers.not("anonymous"));
get.releaseConnection();
}

@Test
public void testGetUserList() throws IOException {
GetMethod get = httpGet("/security/userlist/admi");
GetMethod get = httpGet("/security/userlist/admi", "admin", "password1");
get.addRequestHeader("Origin", "http://localhost");
Map<String, Object> resp = gson.fromJson(get.getResponseBodyAsString(),
new TypeToken<Map<String, Object>>(){}.getType());
Expand All @@ -75,7 +75,7 @@ public void testGetUserList() throws IOException {
CoreMatchers.equalTo(true));
get.releaseConnection();

GetMethod notUser = httpGet("/security/userlist/randomString");
GetMethod notUser = httpGet("/security/userlist/randomString", "admin", "password1");
notUser.addRequestHeader("Origin", "http://localhost");
Map<String, Object> notUserResp = gson.fromJson(notUser.getResponseBodyAsString(),
new TypeToken<Map<String, Object>>(){}.getType());
Expand All @@ -85,6 +85,5 @@ public void testGetUserList() throws IOException {

notUser.releaseConnection();
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class DirAccessTest extends AbstractTestRestApi {
public void testDirAccessForbidden() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "false");
AbstractTestRestApi.startUpWithAuthenticationEnable();
AbstractTestRestApi.startUp();
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);
Expand All @@ -43,7 +43,7 @@ public void testDirAccessForbidden() throws Exception {
public void testDirAccessOk() throws Exception {
synchronized (this) {
System.setProperty(ZeppelinConfiguration.ConfVars.ZEPPELIN_SERVER_DEFAULT_DIR_ALLOWED.getVarName(), "true");
AbstractTestRestApi.startUpWithAuthenticationEnable();
AbstractTestRestApi.startUp();
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new GetMethod(getUrlToTest() + "/app/");
httpClient.executeMethod(getMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1159,7 +1159,7 @@ public void testPublicPrivateNewNote() throws IOException, SchedulerException {
assertEquals(notebookAuthorization.getOwners(notePublic.getId()).size(), 1);
assertEquals(notebookAuthorization.getReaders(notePublic.getId()).size(), 0);
assertEquals(notebookAuthorization.getWriters(notePublic.getId()).size(), 0);

// case of private note
System.setProperty(ConfVars.ZEPPELIN_NOTEBOOK_PUBLIC.getVarName(), "false");
ZeppelinConfiguration conf2 = ZeppelinConfiguration.create();
Expand All @@ -1181,8 +1181,7 @@ public void testPublicPrivateNewNote() throws IOException, SchedulerException {
notes2 = notebook.getAllNotes(user2);
assertEquals(notes1.size(), 2);
assertEquals(notes2.size(), 1);
assertEquals(notes1.get(1).getId(), notePrivate.getId());


// user1 have all rights
assertEquals(notebookAuthorization.getOwners(notePrivate.getId()).size(), 1);
assertEquals(notebookAuthorization.getReaders(notePrivate.getId()).size(), 1);
Expand Down