Skip to content

Commit 3202f09

Browse files
committed
Make sure you enabled status is considered when creating a user
Closes #16
1 parent c44dc56 commit 3202f09

File tree

2 files changed

+45
-13
lines changed

2 files changed

+45
-13
lines changed

src/main/xar-resources/modules/security.xqm

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,21 @@ function sec:create-user($username as xs:string, $user-data as map(xs:string, it
152152
:)
153153
let $_ := sm:create-account($username, util:uuid(), $primary-group, ($primary-group, array:flatten($user-data?groups)))
154154
let $_ := sm:passwd-hash($username, $user-data?password)
155-
return
155+
let $_ :=
156156
if (not(empty($user-data?metadata)))
157157
then
158-
(
159-
let $_ := array:for-each($user-data?metadata, function($attribute as map(xs:string, xs:string)) {
160-
sm:set-account-metadata($username, $attribute?key, $attribute?value)
161-
})
162-
return ()
163-
,
164-
true()
165-
)
166-
else
167-
true()
158+
let $_ := array:for-each($user-data?metadata, function($attribute as map(xs:string, xs:string)) {
159+
sm:set-account-metadata($username, $attribute?key, $attribute?value)
160+
})
161+
return ()
162+
else()
163+
let $_ :=
164+
if (not(empty($user-data?enabled)))
165+
then
166+
sm:set-account-enabled($username, $user-data?enabled)
167+
else()
168+
return
169+
true()
168170
else
169171
false()
170172
};

src/test/java/com/fusiondb/studio/api/UserIT.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,40 @@
2929
import static io.restassured.http.ContentType.JSON;
3030
import static org.apache.http.HttpStatus.*;
3131
import static org.junit.jupiter.api.Assertions.assertFalse;
32+
import static org.junit.jupiter.api.Assertions.assertTrue;
3233

3334
public class UserIT {
3435

3536
@Test
3637
public void createUser() {
37-
createUser("123");
38+
final String userId = "123";
39+
40+
createUser(userId);
41+
42+
// get user
43+
final ExtractableResponse<Response> userResponse = getUser(userId);
44+
45+
// check they are enabled
46+
assertTrue(userResponse.jsonPath().getBoolean("enabled"));
3847
}
3948

4049
@Test
41-
public void disableUser() {
50+
public void createUserDisabled() {
4251
final String userId = "456";
4352

53+
createUser(userId, true);
54+
55+
// get user
56+
final ExtractableResponse<Response> userResponse = getUser(userId);
57+
58+
// check they are disabled
59+
assertFalse(userResponse.jsonPath().getBoolean("enabled"));
60+
}
61+
62+
@Test
63+
public void disableUser() {
64+
final String userId = "789";
65+
4466
// 1. create the user
4567
createUser(userId);
4668

@@ -78,6 +100,10 @@ private ExtractableResponse<Response> getUser(final String userId) {
78100
}
79101

80102
private void createUser(final String userId) {
103+
createUser(userId,false);
104+
}
105+
106+
private void createUser(final String userId, final boolean disabled) {
81107
final Map<String, Object> requestBody = mapOf(
82108
Tuple("userName", "user" + userId),
83109
Tuple("password", "user" + userId),
@@ -93,6 +119,10 @@ private void createUser(final String userId) {
93119
))
94120
);
95121

122+
if (disabled) {
123+
requestBody.put("enabled", false);
124+
}
125+
96126
given().
97127
auth().preemptive().basic(DEFAULT_ADMIN_USERNAME, DEFAULT_ADMIN_PASSWORD).
98128
contentType(JSON).

0 commit comments

Comments
 (0)