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

Fix #550: Fixed merging array-type attributes when only one of the tw… #551

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public User merge(User other) {
Object rhsValue = otherAttrs.getValue(key);
// accumulate
if (lhsValue == null) {
attrs.put(key, rhsValue instanceof JsonArray ? new JsonArray().add(rhsValue) : rhsValue);
attrs.put(key, rhsValue instanceof JsonArray ? new JsonArray().addAll((JsonArray) rhsValue) : rhsValue);
} else if (lhsValue instanceof JsonArray) {
if (rhsValue instanceof JsonArray) {
((JsonArray) lhsValue).addAll((JsonArray) rhsValue);
Expand Down
22 changes: 22 additions & 0 deletions vertx-auth-common/src/test/java/io/vertx/ext/auth/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,27 @@ public void testMerge() {
// expectation
assertEquals("B", userA.principal().getString("access_token"));
assertEquals(new JsonArray().add("read").add("write"), userA.attributes().getJsonArray("roles"));

// or 1st is array and 2nd is null

userA = User.create(new JsonObject().put("access_token", "A"), new JsonObject().put("roles", new JsonArray().add("read")));
userB = User.create(new JsonObject().put("access_token", "B"));

userA.merge(userB);

// expectation
assertEquals("B", userA.principal().getString("access_token"));
assertEquals(new JsonArray().add("read"), userA.attributes().getJsonArray("roles"));

// or 1st is null and 2nd is array

userA = User.create(new JsonObject().put("access_token", "A"));
userB = User.create(new JsonObject().put("access_token", "B"), new JsonObject().put("roles", new JsonArray().add("write")));

userA.merge(userB);

// expectation
assertEquals("B", userA.principal().getString("access_token"));
assertEquals(new JsonArray().add("write"), userA.attributes().getJsonArray("roles"));
}
}