#1105 Add user test case

This commit is contained in:
nkorange 2020-01-06 16:23:00 +08:00
parent 3e312e7537
commit 02fea89f49
3 changed files with 24 additions and 8 deletions

View File

@ -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;

View File

@ -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<String> 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<String> 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<User> userPage = JSON.parseObject(response.getBody(), new TypeReference<>());
Page<User> userPage = JSON.parseObject(response.getBody(), new TypeReference<Page<User>>(){});
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<Page<User>>(){});
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<Page<User>>(){});
Assert.assertNotNull(userPage);
Assert.assertNotNull(userPage.getPageItems());

View File

@ -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