-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a new route: GET /admin/config. add data about currently runni…
…ng build
- Loading branch information
Showing
5 changed files
with
90 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { randomBytes } from "crypto"; | ||
import request from "supertest"; | ||
import User from "../../../auth/User.js"; | ||
import UserManager from "../../../auth/UserManager.js"; | ||
import Vfs from "../../../vfs/index.js"; | ||
|
||
|
||
|
||
/** | ||
* Minimal tests as most | ||
*/ | ||
|
||
describe("GET /admin/config", function(){ | ||
let vfs :Vfs, userManager :UserManager, user :User, admin :User; | ||
|
||
this.beforeAll(async function(){ | ||
let locals = await createIntegrationContext(this); | ||
vfs = locals.vfs; | ||
userManager = locals.userManager; | ||
user = await userManager.addUser("bob", "12345678"); | ||
admin = await userManager.addUser("alice", "12345678", true); | ||
}); | ||
|
||
this.afterAll(async function(){ | ||
await cleanIntegrationContext(this); | ||
}); | ||
|
||
it("requires admin access", async function(){ | ||
//Anonymous | ||
await request(this.server).get(`/admin/config`) | ||
.expect(401); | ||
//read-only User | ||
await request(this.server).get(`/admin/config`) | ||
.auth(user.username, "12345678") | ||
.expect(401); | ||
|
||
await request(this.server).get(`/admin/config`) | ||
.auth(admin.username, "12345678") | ||
.expect(200); | ||
}); | ||
|
||
it("can return text/plain env file", async function(){ | ||
await request(this.server).get(`/admin/config`) | ||
.auth(admin.username, "12345678") | ||
.accept("text/plain") | ||
.expect(200) | ||
.expect("Content-Type", "text/plain; charset=utf-8"); | ||
}); | ||
it("can return application/json", async function(){ | ||
await request(this.server).get(`/admin/config`) | ||
.auth(admin.username, "12345678") | ||
.accept("application/json") | ||
.expect(200) | ||
.expect("Content-Type", "application/json; charset=utf-8"); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Request, Response } from "express"; | ||
import { getLocals, getVfs } from "../../../utils/locals.js"; | ||
|
||
|
||
|
||
export default async function handleGetConfig(req :Request, res :Response){ | ||
let {config} = getLocals(req); | ||
res.status(200) | ||
res.format({ | ||
"application/json": ()=>{ | ||
res.send(config); | ||
}, | ||
"text/plain": ()=>{ | ||
res.send(Object.entries(config).map(([key, value])=>{ | ||
return `${key.toUpperCase()}="${value}"` | ||
}).join("\n")); | ||
} | ||
}) | ||
} |
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