feat: add getUser and getUsers endpoints
Feishin calls getUser during login to determine roles and folder access.
This commit is contained in:
1 parent
656020f5c1
commit
43e726628e
4 files changed
+104
-2
No files matched your search
@@ -114,6 +114,41 @@ class SystemRoutesTest {
|
||||
assertEquals(42, status["count"]!!.jsonPrimitive.int)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getUser returns roles and folder ids with admin restrictions`() = testApplication {
|
||||
setupApp()
|
||||
|
||||
val own = parse(client.get("/rest/getUser?${credentials()}&username=alice").bodyAsText())
|
||||
val alice = own["user"]!!.jsonObject
|
||||
assertEquals("alice", alice.string("username"))
|
||||
assertEquals("true", alice["adminRole"]!!.jsonPrimitive.content)
|
||||
assertEquals("true", alice["downloadRole"]!!.jsonPrimitive.content)
|
||||
assertEquals(listOf(1), alice["folder"]!!.jsonArray.map { it.jsonPrimitive.int })
|
||||
|
||||
val other = parse(client.get("/rest/getUser?${credentials()}&username=bob").bodyAsText())
|
||||
assertEquals("bob", other["user"]!!.jsonObject.string("username"))
|
||||
|
||||
val forbidden = parse(client.get("/rest/getUser?${credentials(user = "bob")}&username=alice").bodyAsText())
|
||||
assertEquals("failed", forbidden.string("status"))
|
||||
assertEquals(50, forbidden["error"]!!.jsonObject["code"]!!.jsonPrimitive.int)
|
||||
|
||||
val missing = parse(client.get("/rest/getUser?${credentials()}").bodyAsText())
|
||||
assertEquals(10, missing["error"]!!.jsonObject["code"]!!.jsonPrimitive.int)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `getUsers is admin only`() = testApplication {
|
||||
setupApp()
|
||||
|
||||
val admin = parse(client.get("/rest/getUsers?${credentials()}").bodyAsText())
|
||||
val names = admin["users"]!!.jsonObject["user"]!!.jsonArray
|
||||
.map { it.jsonObject.string("username") }
|
||||
assertEquals(setOf("alice", "bob"), names.toSet())
|
||||
|
||||
val regular = parse(client.get("/rest/getUsers?${credentials(user = "bob")}").bodyAsText())
|
||||
assertEquals(50, regular["error"]!!.jsonObject["code"]!!.jsonPrimitive.int)
|
||||
}
|
||||
|
||||
private fun ApplicationTestBuilder.setupApp(
|
||||
startScan: () -> Boolean = { false },
|
||||
scanStatus: () -> ScanStatus = { ScanStatus(false, 0) },
|
||||
|
||||
Reference in new issue
Block a user