From b31432cf458b7fa613b788397145dd2c95ff10ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Walkiewicz?= Date: Wed, 8 Dec 2021 09:26:06 +0100 Subject: [PATCH] Assert additional fields from identity --- .../java/io/trino/server/security/TestResourceSecurity.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/core/trino-main/src/test/java/io/trino/server/security/TestResourceSecurity.java b/core/trino-main/src/test/java/io/trino/server/security/TestResourceSecurity.java index 55ce3f382052..7bca8ed8f7b5 100644 --- a/core/trino-main/src/test/java/io/trino/server/security/TestResourceSecurity.java +++ b/core/trino-main/src/test/java/io/trino/server/security/TestResourceSecurity.java @@ -293,18 +293,19 @@ public void testPasswordAuthenticatorUserMapping() // Normally this would result in an impersonation check to the X-Trino-User, but the password // authenticator has a hack to clear X-Trino-User in this case. Request request = new Request.Builder() - .url(getLocation(httpServerInfo.getHttpsUri(), "/username")) + .url(getLocation(httpServerInfo.getHttpsUri(), "/identity")) .addHeader("Authorization", Credentials.basic(TEST_USER_LOGIN, TEST_PASSWORD)) .addHeader("X-Trino-User", TEST_USER_LOGIN) .build(); try (Response response = client.newCall(request).execute()) { assertEquals(response.code(), SC_OK); assertEquals(response.header("user"), TEST_USER); + assertEquals(response.header("principal"), TEST_USER_LOGIN); } } } - @javax.ws.rs.Path("/username") + @javax.ws.rs.Path("/identity") public static class TestResource { private final HttpRequestSessionContextFactory sessionContextFactory; @@ -322,6 +323,7 @@ public javax.ws.rs.core.Response echoToken(@Context HttpServletRequest servletRe Identity identity = sessionContextFactory.extractAuthorizedIdentity(servletRequest, httpHeaders, Optional.empty()); return javax.ws.rs.core.Response.ok() .header("user", identity.getUser()) + .header("principal", identity.getPrincipal().map(Principal::getName).orElse(null)) .build(); } }