Skip to content

Commit

Permalink
#1105 Add user test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nkorange committed Jan 6, 2020
1 parent 3e312e7 commit 02fea89
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -54,14 +58,12 @@ public String login() {
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()
Expand All @@ -85,7 +87,7 @@ public void createUpdateDeleteUser() {

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());
Expand Down Expand Up @@ -122,7 +124,7 @@ public void createUpdateDeleteUser() {
.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());
Expand Down Expand Up @@ -160,7 +162,7 @@ public void createUpdateDeleteUser() {

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());
Expand Down
15 changes: 15 additions & 0 deletions test/src/test/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 02fea89

Please sign in to comment.