From 02fea89f49d071da8d9e9bffb740ab52a16f6d05 Mon Sep 17 00:00:00 2001 From: nkorange Date: Mon, 6 Jan 2020 16:23:00 +0800 Subject: [PATCH] #1105 Add user test case --- .../nacos/core/code/ControllerMethodsCache.java | 1 - .../nacos/test/core/auth/User_ITCase.java | 16 +++++++++------- test/src/test/resources/application.properties | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java b/core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java index b74d5968e..97dc9bfca 100644 --- a/core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java +++ b/core/src/main/java/com/alibaba/nacos/core/code/ControllerMethodsCache.java @@ -16,7 +16,6 @@ package com.alibaba.nacos.core.code; -import com.alibaba.nacos.core.utils.Loggers; import org.apache.commons.lang3.ArrayUtils; import org.reflections.Reflections; import org.springframework.stereotype.Component; diff --git a/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java b/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java index 43fc22cfb..4b5ba37a1 100644 --- a/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java +++ b/test/src/test/java/com/alibaba/nacos/test/core/auth/User_ITCase.java @@ -35,14 +35,18 @@ public class User_ITCase extends HttpClient4Test { @LocalServerPort private int port; + private String accessToken; + @Before public void init() throws Exception { String url = String.format("http://localhost:%d/", port); this.base = new URL(url); + login(); } + @Test - public String login() { + public void login() { ResponseEntity response = request("/nacos/v1/ns/auth/users/login", Params.newParams() .appendParam("username", "username1") @@ -54,14 +58,12 @@ public class User_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); JSONObject json = JSON.parseObject(response.getBody()); Assert.assertTrue(json.containsKey("accessToken")); - return json.getString("accessToken"); + accessToken = json.getString("accessToken"); } @Test public void createUpdateDeleteUser() { - String accessToken = login(); - // Create a user: ResponseEntity response = request("/nacos/v1/ns/auth/users", Params.newParams() @@ -85,7 +87,7 @@ public class User_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - Page userPage = JSON.parseObject(response.getBody(), new TypeReference<>()); + Page userPage = JSON.parseObject(response.getBody(), new TypeReference>(){}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); @@ -122,7 +124,7 @@ public class User_ITCase extends HttpClient4Test { .done(), String.class); - userPage = JSON.parseObject(response.getBody(), new TypeReference<>()); + userPage = JSON.parseObject(response.getBody(), new TypeReference>(){}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); @@ -160,7 +162,7 @@ public class User_ITCase extends HttpClient4Test { Assert.assertTrue(response.getStatusCode().is2xxSuccessful()); - userPage = JSON.parseObject(response.getBody(), new TypeReference<>()); + userPage = JSON.parseObject(response.getBody(), new TypeReference>(){}); Assert.assertNotNull(userPage); Assert.assertNotNull(userPage.getPageItems()); diff --git a/test/src/test/resources/application.properties b/test/src/test/resources/application.properties index b611435ea..adb20a5e3 100644 --- a/test/src/test/resources/application.properties +++ b/test/src/test/resources/application.properties @@ -18,3 +18,18 @@ server.tomcat.accesslog.enabled=false server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D # default current work dir server.tomcat.basedir= + +### The ignore urls of auth, is deprecated in 1.2.0: +nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** + +### The auth system to use, currently only 'nacos' is supported: +nacos.core.auth.system.type=nacos + +### If turn on auth system: +nacos.core.auth.enabled=false + +### The token expiration in seconds: +nacos.core.auth.default.token.expire.seconds=18000 + +### The default token: +nacos.core.auth.default.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789