-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Only allow System Administrators to create users (#3022)
- Loading branch information
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -296,6 +296,27 @@ class UsersADME2ESpec | |
} | ||
|
||
"given a custom Iri" should { | ||
"given no credentials in the request when creating a user it must be forbidden" in { | ||
val validUserCreationRequest: String = | ||
s"""{ | ||
| "id": "$customUserIri", | ||
| "username": "userWithCustomIri", | ||
| "email": "[email protected]", | ||
| "givenName": "a user", | ||
| "familyName": "with a custom Iri", | ||
| "password": "test", | ||
| "status": true, | ||
| "lang": "en", | ||
| "systemAdmin": false | ||
|}""".stripMargin | ||
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, validUserCreationRequest) | ||
) | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
response.status should be(StatusCodes.Forbidden) | ||
} | ||
|
||
"create a user with the provided custom IRI" in { | ||
val createUserWithCustomIriRequest: String = | ||
s"""{ | ||
|
@@ -323,7 +344,7 @@ class UsersADME2ESpec | |
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, createUserWithCustomIriRequest) | ||
) | ||
) ~> addRootUserCredentials() | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
|
||
response.status should be(StatusCodes.OK) | ||
|
@@ -359,7 +380,10 @@ class UsersADME2ESpec | |
| "systemAdmin": false | ||
|}""".stripMargin | ||
|
||
val request = Post(baseApiUrl + s"/admin/users", HttpEntity(ContentTypes.`application/json`, params)) | ||
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, params) | ||
) ~> addRootUserCredentials() | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
response.status should be(StatusCodes.BadRequest) | ||
|
||
|
@@ -389,7 +413,7 @@ class UsersADME2ESpec | |
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, createUserWithApostropheRequest) | ||
) | ||
) ~> addRootUserCredentials() | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
|
||
response.status should be(StatusCodes.OK) | ||
|
@@ -463,7 +487,11 @@ class UsersADME2ESpec | |
text = createUserRequest | ||
) | ||
) | ||
val request = Post(baseApiUrl + s"/admin/users", HttpEntity(ContentTypes.`application/json`, createUserRequest)) | ||
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, createUserRequest) | ||
) ~> addRootUserCredentials() | ||
|
||
val response: HttpResponse = singleAwaitingRequest(request) | ||
|
||
response.status should be(StatusCodes.OK) | ||
|
@@ -513,7 +541,10 @@ class UsersADME2ESpec | |
text = createUserRequest | ||
) | ||
) | ||
val request = Post(baseApiUrl + s"/admin/users", HttpEntity(ContentTypes.`application/json`, createUserRequest)) | ||
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, createUserRequest) | ||
) ~> addRootUserCredentials() | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
|
||
response.status should be(StatusCodes.BadRequest) | ||
|
@@ -553,7 +584,10 @@ class UsersADME2ESpec | |
text = createUserRequest | ||
) | ||
) | ||
val request = Post(baseApiUrl + s"/admin/users", HttpEntity(ContentTypes.`application/json`, createUserRequest)) | ||
val request = Post( | ||
baseApiUrl + s"/admin/users", | ||
HttpEntity(ContentTypes.`application/json`, createUserRequest) | ||
) ~> addRootUserCredentials() | ||
val response: HttpResponse = singleAwaitingRequest(request) | ||
|
||
response.status should be(StatusCodes.BadRequest) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters