[
https://issues.apache.org/jira/browse/DRILL-7203?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17047631#comment-17047631
]
ASF GitHub Bot commented on DRILL-7203:
---------------------------------------
arina-ielchiieva commented on pull request #1994: DRILL-7203: Accept
impersonation userName as form field & fix back button for query page
URL: https://github.com/apache/drill/pull/1994#discussion_r385699931
##########
File path:
exec/java-exec/src/test/java/org/apache/drill/exec/server/rest/TestQueryWrapper.java
##########
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.server.rest;
+
+import io.netty.channel.DefaultChannelPromise;
+import io.netty.channel.local.LocalAddress;
+import org.apache.drill.common.exceptions.UserException;
+import org.apache.drill.exec.ExecConstants;
+import org.apache.drill.exec.proto.UserBitShared;
+import org.apache.drill.exec.proto.helper.QueryIdHelper;
+import org.apache.drill.exec.rpc.user.UserSession;
+import org.apache.drill.exec.server.Drillbit;
+import org.apache.drill.exec.server.options.SystemOptionManager;
+import org.apache.drill.exec.server.rest.auth.DrillUserPrincipal;
+import org.apache.drill.exec.store.sys.PersistentStore;
+import org.apache.drill.exec.work.WorkManager;
+import org.apache.drill.exec.work.foreman.Foreman;
+import org.apache.drill.test.ClusterFixture;
+import org.apache.drill.test.ClusterTest;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.junit.Test;
+
+import java.io.IOException;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.fail;
+
+public class TestQueryWrapper extends ClusterTest {
+
+ private static DrillRestServer server;
+ private static WorkManager workManager;
+ private static WebServer webServer;
+
+ private void setupServer() throws IOException {
+ setupServer(false);
+ }
+
+ private void setupServer(boolean impersonationEnabled) {
+ cluster = ClusterFixture.bareBuilder(dirTestWatcher)
+ .clusterSize(1)
+ .configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true)
+ .configProperty(ExecConstants.IMPERSONATION_ENABLED,
impersonationEnabled)
+ .build();
+ Drillbit drillbit = cluster.drillbit();
+ workManager = drillbit.getManager();
+ webServer = drillbit.getWebServer();
+ final ServletContextHandler servletContextHandler = new
ServletContextHandler(ServletContextHandler.SESSIONS);
+ servletContextHandler.setContextPath("/");
+ server = new DrillRestServer(workManager,
servletContextHandler.getServletContext(), drillbit);
+ }
+
+ private QueryWrapper.QueryResult run(String sql) throws Exception {
+ return runWithUserName(sql, null);
+ }
+
+ private QueryWrapper.QueryResult runWithUserName(String sql, String
userName) throws Exception {
+ if (cluster == null) {
+ setupServer();
+ }
+
+ SystemOptionManager systemOptions =
cluster.drillbit().getContext().getOptionManager();
+ DrillUserPrincipal principal = new
DrillUserPrincipal.AnonDrillUserPrincipal();
+ WebSessionResources webSessionResources = new WebSessionResources(
+ cluster.drillbit().getContext().getAllocator(),
+ new LocalAddress("test"),
+ UserSession.Builder.newBuilder()
+ .withOptionManager(systemOptions)
+
.withCredentials(UserBitShared.UserCredentials.newBuilder().setUserName(principal.getName()).build())
+ .build(),
+ new DefaultChannelPromise(null));
+ WebUserConnection connection = new
WebUserConnection.AnonWebUserConnection(webSessionResources);
+ QueryWrapper q = new QueryWrapper(sql, "SQL", null, userName);
+ return q.run(workManager, connection);
+ }
+
+
+ @Test
+ public void testShowSchemas() throws Exception {
+ QueryWrapper.QueryResult result = run("SHOW SCHEMAS");
+ assertEquals("COMPLETED", result.queryState);
+ assertNotEquals(0, result.rows.size());
+ assertEquals(1, result.columns.size());
+ assertEquals(result.columns.iterator().next(), "SCHEMA_NAME");
+ }
+
+ @Test
+ public void testImpersonation() throws Exception {
+ setupServer(true);
+ QueryWrapper.QueryResult result = runWithUserName("SELECT CATALOG_NAME,
SCHEMA_NAME FROM information_schema.SCHEMATA", "alfred");
+ final PersistentStore<UserBitShared.QueryProfile> profiles =
workManager.getContext().getProfileStoreContext().getCompletedProfileStore();
+ UserBitShared.QueryId id =
QueryIdHelper.getQueryIdFromString(result.getQueryId());
+ Foreman f = workManager.getBee().getForemanForQueryId(id);
+ UserBitShared.QueryProfile queryProfile =
f.getQueryManager().getQueryProfile();
+ assertEquals("alfred", queryProfile.getUser());
+ }
+
+ @Test
+ public void testImpersonationDisabled() throws Exception {
+ setupServer(false);
+ try {
+ runWithUserName("SHOW SCHEMAS", "alfred");
+ fail("Should have thrown exception");
+ } catch (UserException e) {
+ assertThat(e.getMessage(), containsString("User impersonation is not
enabled"));
+ }
+ }
+
+ @Test
+ public void testImpersonationEnabledButUserNameNotProvided() throws
Exception {
+ setupServer(true);
+ QueryWrapper.QueryResult result = runWithUserName("SELECT CATALOG_NAME,
SCHEMA_NAME FROM information_schema.SCHEMATA", null);
+ final PersistentStore<UserBitShared.QueryProfile> profiles =
workManager.getContext().getProfileStoreContext().getCompletedProfileStore();
Review comment:
Profiles are never used, please remove.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Back button for failed query does not return on Query page
> -----------------------------------------------------------
>
> Key: DRILL-7203
> URL: https://issues.apache.org/jira/browse/DRILL-7203
> Project: Apache Drill
> Issue Type: Bug
> Affects Versions: 1.16.0
> Reporter: Arina Ielchiieva
> Assignee: Dobes Vandermeer
> Priority: Major
> Attachments: back_button.JPG
>
>
> Back button for failed query returns on previous page before Query page but
> not on the Query page.
> Steps:
> 1. go to Logs page
> 2. go to Query page
> 3. execute query with incorrect syntax (ex: xxxxx)
> 4. error message will be displayed, Back button will be in left corner
> (screenshot attached)
> 5. press Back button
> 6. user is redirected to Logs page
--
This message was sent by Atlassian Jira
(v8.3.4#803005)