Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add user-api test #1456

Merged
merged 10 commits into from
Jun 1, 2021
Merged

add user-api test #1456

merged 10 commits into from
Jun 1, 2021

Conversation

coderzc
Copy link
Member

@coderzc coderzc commented May 19, 2021

No description provided.

@codecov
Copy link

codecov bot commented May 19, 2021

Codecov Report

Merging #1456 (4f69663) into master (1ede97c) will increase coverage by 2.25%.
The diff coverage is 25.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #1456      +/-   ##
============================================
+ Coverage     61.80%   64.05%   +2.25%     
- Complexity     5840     5882      +42     
============================================
  Files           381      381              
  Lines         32148    32190      +42     
  Branches       4504     4506       +2     
============================================
+ Hits          19869    20620     +751     
+ Misses        10231     9463     -768     
- Partials       2048     2107      +59     
Impacted Files Coverage Δ
.../com/baidu/hugegraph/auth/ConfigAuthenticator.java 0.00% <0.00%> (ø)
...va/com/baidu/hugegraph/auth/HugeAuthenticator.java 33.70% <ø> (+12.70%) ⬆️
...c/main/java/com/baidu/hugegraph/cmd/InitStore.java 0.00% <0.00%> (ø)
...om/baidu/hugegraph/auth/StandardAuthenticator.java 35.38% <14.28%> (+35.38%) ⬆️
...in/java/com/baidu/hugegraph/core/GraphManager.java 54.59% <50.00%> (+2.50%) ⬆️
...ava/com/baidu/hugegraph/api/profile/GraphsAPI.java 0.00% <0.00%> (-20.76%) ⬇️
.../hugegraph/backend/store/rocksdb/RocksDBStore.java 69.61% <0.00%> (-1.79%) ⬇️
...in/java/com/baidu/hugegraph/StandardHugeGraph.java 68.45% <0.00%> (-0.39%) ⬇️
...a/com/baidu/hugegraph/api/traversers/CountAPI.java 0.00% <0.00%> (ø)
...ugegraph/backend/store/raft/StoreSnapshotFile.java 0.00% <0.00%> (ø)
... and 33 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1ede97c...4f69663. Read the comment docs.

ImmutableMap.of());
assertResponseStatus(200, r);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the empty line

String result = assertResponseStatus(400, r);
String message = assertJsonContains(result, "message");
Assert.assertThat(message, CoreMatchers.containsString(
"Invalid user id:"));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

align

this.client().post(path, user);
}

protected List<Map<String, Object>> getList() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listUsers

Response r3 = client().post(path, "{}");
assertResponseStatus(400, r3);


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove empty line

private static final String path = "graphs/hugegraph/auth/users";

@After
public void clearUser() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

teardown


protected List<Map<String, Object>> getList() {
Response r = this.client().get(path,
ImmutableMap.of("limit", -1));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define params var

String result = assertResponseStatus(200, r);
Map<String, List<Map<String, Object>>> resultMap = JsonUtil.fromJson(
result,
new TypeReference<Map<String, List<Map<String, Object>>>>() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

define local var

result,
new TypeReference<Map<String, List<Map<String, Object>>>>() {
});
return resultMap.get("users");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonUtil.fromJson().get("users");

@coderzc coderzc force-pushed the user-graph-api-test branch from 9dfd80b to 96edf75 Compare May 19, 2021 08:55
@coderzc coderzc force-pushed the user-graph-api-test branch from 96edf75 to 00b22f6 Compare May 19, 2021 09:02
@javeme javeme changed the title add user test add user-api test May 19, 2021
@@ -5,9 +5,30 @@ set -ev
TRAVIS_DIR=`dirname $0`
VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
SERVER_DIR=hugegraph-$VERSION
CONF=$TRAVIS_DIR/conf/hugegraph.properties
REST_CONF=$TRAVIS_DIR/conf/rest-server.properties
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

REST_SERVER_CONF


mvn package -DskipTests

cp $CONF "${CONF}_bak"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't need to copy bak file

@@ -5,9 +5,30 @@ set -ev
TRAVIS_DIR=`dirname $0`
VERSION=`mvn help:evaluate -Dexpression=project.version -q -DforceStdout`
SERVER_DIR=hugegraph-$VERSION
CONF=$TRAVIS_DIR/conf/hugegraph.properties
REST_CONF=$TRAVIS_DIR/conf/rest-server.properties
GREMLIN_CONF=$TRAVIS_DIR/conf/gremlin-server.yaml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GREMLIN_SERVER_CONF


mv "${CONF}_bak" $CONF
mv "${REST_CONF}_bak" $REST_CONF
mv "${GREMLIN_CONF}_bak" $GREMLIN_CONF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add empty line

@@ -36,9 +36,12 @@
public class UserApiTest extends BaseApiTest {

private static final String path = "graphs/hugegraph/auth/users";
private static final Map<String, Object> NO_LIMIT = ImmutableMap.of("limit",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just define NO_LIMIT = -1;

});
Map<String, List<Map<String, Object>>> resultMap =
JsonUtil.fromJson(result, new TypeReference<Map<String,
List<Map<String, Object>>>>() {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return JsonUtil.fromJson(result, type).get("users");

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it need to cast

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update alignment

@coderzc coderzc force-pushed the user-graph-api-test branch from 1b961e8 to 454d51a Compare May 19, 2021 11:42
@coderzc coderzc force-pushed the user-graph-api-test branch from f16fa55 to d95d5ad Compare May 20, 2021 04:35
});
Map<String, List<Map<String, Object>>> resultMap =
JsonUtil.fromJson(result, new TypeReference<Map<String,
List<Map<String, Object>>>>() {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update alignment


mvn package -DskipTests

sed -i 's/#auth.authenticator=/auth.authenticator=com.baidu.hugegraph.auth.StandardAuthenticator/' $REST_SERVER_CONF
sed -i 's/gremlin.graph=.*/gremlin.graph=com.baidu.hugegraph.auth.HugeFactoryAuthProxy/' $CONF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem no this option

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem no the option named "gremlin.graph"

"\", \"user_email\":\"user1@baidu.com\", " +
"\"user_phone\"123456789\", \"user_avatar\":\"image1" +
"\", \"user_email\":\"user1@baidu.com\"," +
"\"user_phone\":123456789,\"user_avatar\":\"image1" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep string

@@ -93,7 +93,13 @@ public void testClearAndInit() {
assertResponseStatus(200, client().post(path, body));

body = "{"
+ "\"gremlin\":\"hugegraph.initBackend()\","
+ "\"gremlin\":\"import com.baidu.hugegraph.auth.HugeUser;"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't separate clearBackend and initBackend into 2 parts if enabled auth

@coderzc coderzc force-pushed the user-graph-api-test branch from 92fd0eb to 50e926b Compare May 27, 2021 10:27
+ "import com.baidu.hugegraph.util.StringEncoding;"
+ "hugegraph.clearBackend();"
+ "hugegraph.initBackend();"
+ "HugeUser admin = new HugeUser('admin');"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth = hugegraph.authManager();
admin = auth.findUser('admin');
hugegraph.clearBackend();
hugegraph.initBackend();
auth.createUser(admin);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@@ -52,6 +53,8 @@

private static String BASE_URL = "http://127.0.0.1:8080";
private static String GRAPH = "hugegraph";
protected static final String USERNAME = "admin";
protected static final String PASSWORD = "pa";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set private

NO_LIMIT));
String result = assertResponseStatus(200, r);
Map<String, List<Map<String, Object>>> resultMap =
JsonUtil.fromJson(result, new TypeReference<Map<String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

improve align

+ "hugegraph.clearBackend();"
+ "hugegraph.initBackend();"
+ "HugeUser admin = new HugeUser('admin');"
+ "admin.password(StringEncoding.hashPassword('pa'));"
+ "admin.creator('system');"
+ "hugegraph.hugegraph().authManager().createUser(admin);\","
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth.createUser(admin);


mvn package -DskipTests

sed -i 's/#auth.authenticator=/auth.authenticator=com.baidu.hugegraph.auth.StandardAuthenticator/' $REST_SERVER_CONF
sed -i 's/gremlin.graph=.*/gremlin.graph=com.baidu.hugegraph.auth.HugeFactoryAuthProxy/' $CONF
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seem no the option named "gremlin.graph"

@houzhizhen houzhizhen merged commit 461948e into master Jun 1, 2021
@houzhizhen houzhizhen deleted the user-graph-api-test branch June 1, 2021 04:31
jadepeng pushed a commit to jadepeng/hugegraph that referenced this pull request Jun 25, 2021
* add user test
* open auth properties
* fix auth startup of memory backend bug
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants