#1105 Add user test case
This commit is contained in:
parent
3e312e7537
commit
02fea89f49
@ -16,7 +16,6 @@
|
|||||||
package com.alibaba.nacos.core.code;
|
package com.alibaba.nacos.core.code;
|
||||||
|
|
||||||
|
|
||||||
import com.alibaba.nacos.core.utils.Loggers;
|
|
||||||
import org.apache.commons.lang3.ArrayUtils;
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.reflections.Reflections;
|
import org.reflections.Reflections;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
@ -35,14 +35,18 @@ public class User_ITCase extends HttpClient4Test {
|
|||||||
@LocalServerPort
|
@LocalServerPort
|
||||||
private int port;
|
private int port;
|
||||||
|
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
String url = String.format("http://localhost:%d/", port);
|
String url = String.format("http://localhost:%d/", port);
|
||||||
this.base = new URL(url);
|
this.base = new URL(url);
|
||||||
|
login();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public String login() {
|
public void login() {
|
||||||
ResponseEntity<String> response = request("/nacos/v1/ns/auth/users/login",
|
ResponseEntity<String> response = request("/nacos/v1/ns/auth/users/login",
|
||||||
Params.newParams()
|
Params.newParams()
|
||||||
.appendParam("username", "username1")
|
.appendParam("username", "username1")
|
||||||
@ -54,14 +58,12 @@ public class User_ITCase extends HttpClient4Test {
|
|||||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
||||||
JSONObject json = JSON.parseObject(response.getBody());
|
JSONObject json = JSON.parseObject(response.getBody());
|
||||||
Assert.assertTrue(json.containsKey("accessToken"));
|
Assert.assertTrue(json.containsKey("accessToken"));
|
||||||
return json.getString("accessToken");
|
accessToken = json.getString("accessToken");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createUpdateDeleteUser() {
|
public void createUpdateDeleteUser() {
|
||||||
|
|
||||||
String accessToken = login();
|
|
||||||
|
|
||||||
// Create a user:
|
// Create a user:
|
||||||
ResponseEntity<String> response = request("/nacos/v1/ns/auth/users",
|
ResponseEntity<String> response = request("/nacos/v1/ns/auth/users",
|
||||||
Params.newParams()
|
Params.newParams()
|
||||||
@ -85,7 +87,7 @@ public class User_ITCase extends HttpClient4Test {
|
|||||||
|
|
||||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
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);
|
||||||
Assert.assertNotNull(userPage.getPageItems());
|
Assert.assertNotNull(userPage.getPageItems());
|
||||||
@ -122,7 +124,7 @@ public class User_ITCase extends HttpClient4Test {
|
|||||||
.done(),
|
.done(),
|
||||||
String.class);
|
String.class);
|
||||||
|
|
||||||
userPage = JSON.parseObject(response.getBody(), new TypeReference<>());
|
userPage = JSON.parseObject(response.getBody(), new TypeReference<Page<User>>(){});
|
||||||
|
|
||||||
Assert.assertNotNull(userPage);
|
Assert.assertNotNull(userPage);
|
||||||
Assert.assertNotNull(userPage.getPageItems());
|
Assert.assertNotNull(userPage.getPageItems());
|
||||||
@ -160,7 +162,7 @@ public class User_ITCase extends HttpClient4Test {
|
|||||||
|
|
||||||
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
|
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);
|
||||||
Assert.assertNotNull(userPage.getPageItems());
|
Assert.assertNotNull(userPage.getPageItems());
|
||||||
|
@ -18,3 +18,18 @@ server.tomcat.accesslog.enabled=false
|
|||||||
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
|
||||||
# default current work dir
|
# default current work dir
|
||||||
server.tomcat.basedir=
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user