From 4e07c1f82bead0401f55dace2b34a86171ea48ab Mon Sep 17 00:00:00 2001 From: Paulo Lopes Date: Thu, 8 Oct 2020 15:57:10 +0200 Subject: [PATCH] Ensure that token based auth uses the same User object layout Signed-off-by: Paulo Lopes --- .../io/vertx/ext/web/handler/AuthHandlerTestBase.java | 4 ++-- .../io/vertx/ext/web/handler/EventbusBridgeTest.java | 3 ++- .../io/vertx/ext/web/handler/JWTAuthHandlerTest.java | 2 +- .../ext/web/handler/MultiAuthorizationHandlerTest.java | 10 +++++----- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/vertx-web/src/test/java/io/vertx/ext/web/handler/AuthHandlerTestBase.java b/vertx-web/src/test/java/io/vertx/ext/web/handler/AuthHandlerTestBase.java index 322caddab9..491cf7b3db 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/handler/AuthHandlerTestBase.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/handler/AuthHandlerTestBase.java @@ -18,8 +18,8 @@ import io.vertx.core.Vertx; import io.vertx.core.http.HttpMethod; -import io.vertx.core.json.JsonObject; import io.vertx.ext.auth.authentication.AuthenticationProvider; +import io.vertx.ext.auth.authentication.UsernamePasswordCredentials; import io.vertx.ext.auth.authorization.Authorization; import io.vertx.ext.auth.authorization.AuthorizationProvider; import io.vertx.ext.auth.authorization.PermissionBasedAuthorization; @@ -77,7 +77,7 @@ protected void testAuthorization(String username, boolean fail, Authorization au router.route().handler(rc -> { // we need to be logged in if (rc.user() == null) { - JsonObject authInfo = new JsonObject().put("username", username).put("password", "delicious:sausages"); + UsernamePasswordCredentials authInfo = new UsernamePasswordCredentials(username, "delicious:sausages"); authNProvider.authenticate(authInfo, res -> { if (res.succeeded()) { rc.setUser(res.result()); diff --git a/vertx-web/src/test/java/io/vertx/ext/web/handler/EventbusBridgeTest.java b/vertx-web/src/test/java/io/vertx/ext/web/handler/EventbusBridgeTest.java index 03d94df007..773493c91d 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/handler/EventbusBridgeTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/handler/EventbusBridgeTest.java @@ -23,6 +23,7 @@ import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; import io.vertx.ext.auth.authentication.AuthenticationProvider; +import io.vertx.ext.auth.authentication.UsernamePasswordCredentials; import io.vertx.ext.auth.properties.PropertyFileAuthentication; import io.vertx.ext.auth.properties.PropertyFileAuthorization; import io.vertx.ext.bridge.BridgeEventType; @@ -1093,7 +1094,7 @@ private void addLoginHandler(Router router, AuthenticationProvider authProvider) router.route("/eventbus/*").handler(rc -> { // we need to be logged in if (rc.user() == null) { - JsonObject authInfo = new JsonObject().put("username", "tim").put("password", "delicious:sausages"); + UsernamePasswordCredentials authInfo = new UsernamePasswordCredentials("tim", "delicious:sausages"); HttpServerRequest request = rc.request(); request.pause(); authProvider.authenticate(authInfo, res -> { diff --git a/vertx-web/src/test/java/io/vertx/ext/web/handler/JWTAuthHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/handler/JWTAuthHandlerTest.java index 024546bf05..1ff9e76e68 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/handler/JWTAuthHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/handler/JWTAuthHandlerTest.java @@ -49,7 +49,7 @@ public void testLogin() throws Exception { Handler handler = rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome to the protected resource!"); }; diff --git a/vertx-web/src/test/java/io/vertx/ext/web/handler/MultiAuthorizationHandlerTest.java b/vertx-web/src/test/java/io/vertx/ext/web/handler/MultiAuthorizationHandlerTest.java index 864c6ceda7..8fd9895393 100644 --- a/vertx-web/src/test/java/io/vertx/ext/web/handler/MultiAuthorizationHandlerTest.java +++ b/vertx-web/src/test/java/io/vertx/ext/web/handler/MultiAuthorizationHandlerTest.java @@ -44,7 +44,7 @@ public void testJWTAuthenticationNoAuthorization() throws Exception { router.route("/protected/page1").handler(rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome"); }); @@ -67,7 +67,7 @@ public void testJWTAuthenticationWithAuthorization1() throws Exception { router.route("/protected/page1").handler(rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome"); }); @@ -94,7 +94,7 @@ public void testJWTAuthenticationWithAuthorization2() throws Exception { router.route("/protected/page1").handler(rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome"); }); @@ -123,7 +123,7 @@ public void testJWTAuthenticationWithAuthorization3() throws Exception { router.route("/protected/page1").handler(rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome"); }); @@ -152,7 +152,7 @@ public void testJWTAuthenticationWithAuthorization4() throws Exception { router.route("/protected/page1").handler(rc -> { assertNotNull(rc.user()); - assertEquals("paulo", rc.user().principal().getString("sub")); + assertEquals("paulo", rc.user().attributes().getJsonObject("accessToken").getString("sub")); rc.response().end("Welcome"); });