Search in sources :

Example 6 with QueryError

use of io.trino.client.QueryError in project trino by trinodb.

the class TestUserImpersonationAccessControl method testReadAccessControl.

// On the tpch catalog Alice has allow all permissions, Bob has no permissions, and Charlie has read only permissions.
@Test
public void testReadAccessControl() {
    QueryError aliceQueryError = trySelectQuery("alice");
    assertNull(aliceQueryError);
    QueryError bobQueryError = trySelectQuery("bob");
    assertNotNull(bobQueryError);
    assertEquals(bobQueryError.getErrorType(), "USER_ERROR");
    assertEquals(bobQueryError.getErrorName(), "PERMISSION_DENIED");
    QueryError charlieQueryError = trySelectQuery("charlie");
    assertNull(charlieQueryError);
}
Also used : QueryError(io.trino.client.QueryError) Test(org.testng.annotations.Test)

Example 7 with QueryError

use of io.trino.client.QueryError in project trino by trinodb.

the class TestServer method checkVersionOnError.

private void checkVersionOnError(String query, @Language("RegExp") String proofOfOrigin) {
    QueryResults queryResults = postQuery(request -> request.setBodyGenerator(createStaticBodyGenerator(query, UTF_8))).map(JsonResponse::getValue).filter(result -> result.getError() != null).findFirst().orElseThrow(() -> new RuntimeException("Error expected"));
    assertNull(queryResults.getNextUri());
    QueryError queryError = queryResults.getError();
    String stackTrace = getStackTraceAsString(queryError.getFailureInfo().toException());
    assertThat(stackTrace).containsPattern(proofOfOrigin);
    long versionLines = Splitter.on("\n").splitToStream(stackTrace).filter(line -> line.contains("at io.trino.$gen.Trino_testversion____")).count();
    if (versionLines != 1) {
        fail(format("Expected version embedded in the stacktrace exactly once, but was %s: %s", versionLines, stackTrace));
    }
}
Also used : QueryId(io.trino.spi.QueryId) QueryError(io.trino.client.QueryError) X_FORWARDED_PORT(com.google.common.net.HttpHeaders.X_FORWARDED_PORT) BasicQueryInfo(io.trino.server.BasicQueryInfo) FullJsonResponseHandler.createFullJsonResponseHandler(io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.testng.annotations.Test) Closeables.closeAll(io.airlift.testing.Closeables.closeAll) QueryResults(io.trino.client.QueryResults) URI(java.net.URI) Collector(java.util.stream.Collector) TestingTrinoServer(io.trino.server.testing.TestingTrinoServer) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) Splitter(com.google.common.base.Splitter) X_FORWARDED_PROTO(com.google.common.net.HttpHeaders.X_FORWARDED_PROTO) HttpUriBuilder(io.airlift.http.client.HttpUriBuilder) SEE_OTHER(javax.ws.rs.core.Response.Status.SEE_OTHER) JettyHttpClient(io.airlift.http.client.jetty.JettyHttpClient) Builder.prepareHead(io.airlift.http.client.Request.Builder.prepareHead) QUERY_MAX_MEMORY(io.trino.SystemSessionProperties.QUERY_MAX_MEMORY) ImmutableMap(com.google.common.collect.ImmutableMap) OK(javax.ws.rs.core.Response.Status.OK) MemoryPlugin(io.trino.plugin.memory.MemoryPlugin) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) TestingTrinoClient(io.trino.testing.TestingTrinoClient) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) TestingSession.testSessionBuilder(io.trino.testing.TestingSession.testSessionBuilder) Stream(java.util.stream.Stream) Optional(java.util.Optional) StaticBodyGenerator.createStaticBodyGenerator(io.airlift.http.client.StaticBodyGenerator.createStaticBodyGenerator) JsonCodec(io.airlift.json.JsonCodec) HttpClient(io.airlift.http.client.HttpClient) IntStream(java.util.stream.IntStream) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) Function(java.util.function.Function) CONTENT_TYPE(com.google.common.net.HttpHeaders.CONTENT_TYPE) AbstractSequentialIterator(com.google.common.collect.AbstractSequentialIterator) INCOMPATIBLE_CLIENT(io.trino.spi.StandardErrorCode.INCOMPATIBLE_CLIENT) JsonResponse(io.airlift.http.client.FullJsonResponseHandler.JsonResponse) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) Request(io.airlift.http.client.Request) X_FORWARDED_HOST(com.google.common.net.HttpHeaders.X_FORWARDED_HOST) AfterClass(org.testng.annotations.AfterClass) Builder.preparePost(io.airlift.http.client.Request.Builder.preparePost) Builder.prepareGet(io.airlift.http.client.Request.Builder.prepareGet) Language(org.intellij.lang.annotations.Language) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) HASH_PARTITION_COUNT(io.trino.SystemSessionProperties.HASH_PARTITION_COUNT) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) JsonCodec.jsonCodec(io.airlift.json.JsonCodec.jsonCodec) StatusResponseHandler.createStatusResponseHandler(io.airlift.http.client.StatusResponseHandler.createStatusResponseHandler) JOIN_DISTRIBUTION_TYPE(io.trino.SystemSessionProperties.JOIN_DISTRIBUTION_TYPE) TimeZoneNotSupportedException(io.trino.spi.type.TimeZoneNotSupportedException) StatusResponse(io.airlift.http.client.StatusResponseHandler.StatusResponse) Collections(java.util.Collections) TRINO_HEADERS(io.trino.client.ProtocolHeaders.TRINO_HEADERS) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) QueryError(io.trino.client.QueryError) QueryResults(io.trino.client.QueryResults)

Aggregations

QueryError (io.trino.client.QueryError)7 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 Splitter (com.google.common.base.Splitter)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)2 AbstractSequentialIterator (com.google.common.collect.AbstractSequentialIterator)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Streams (com.google.common.collect.Streams)2 CONTENT_TYPE (com.google.common.net.HttpHeaders.CONTENT_TYPE)2 X_FORWARDED_HOST (com.google.common.net.HttpHeaders.X_FORWARDED_HOST)2 X_FORWARDED_PORT (com.google.common.net.HttpHeaders.X_FORWARDED_PORT)2 X_FORWARDED_PROTO (com.google.common.net.HttpHeaders.X_FORWARDED_PROTO)2 JsonResponse (io.airlift.http.client.FullJsonResponseHandler.JsonResponse)2 FullJsonResponseHandler.createFullJsonResponseHandler (io.airlift.http.client.FullJsonResponseHandler.createFullJsonResponseHandler)2 HttpClient (io.airlift.http.client.HttpClient)2 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)2 Request (io.airlift.http.client.Request)2 Builder.prepareGet (io.airlift.http.client.Request.Builder.prepareGet)2 Builder.prepareHead (io.airlift.http.client.Request.Builder.prepareHead)2