mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-28 15:01:17 -07:00
Enhancement: handle OMV v8 auth response (#6886)
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
Docker CI / Docker Build & Push (push) Has been cancelled
Lint / Linting Checks (push) Has been cancelled
Tests / vitest (4) (push) Has been cancelled
Release Drafter / Update Release Draft (push) Has been cancelled
Release Drafter / Auto Label PR (push) Has been cancelled
Tests / vitest (1) (push) Has been cancelled
Tests / vitest (2) (push) Has been cancelled
Tests / vitest (3) (push) Has been cancelled
This commit is contained in:
@@ -73,7 +73,7 @@ async function tryLogin(widget) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const json = JSON.parse(resp.data.toString());
|
const json = JSON.parse(resp.data.toString());
|
||||||
if (json.response.authenticated !== true) {
|
if (json.response.authenticated !== true && json.response.status !== "authenticated") {
|
||||||
logger.error("Login error in OpenMediaVault. Data: %s", resp.data);
|
logger.error("Login error in OpenMediaVault. Data: %s", resp.data);
|
||||||
resp.status = 401;
|
resp.status = 401;
|
||||||
return [false, resp];
|
return [false, resp];
|
||||||
|
|||||||
@@ -145,6 +145,39 @@ describe("widgets/openmediavault/proxy", () => {
|
|||||||
expect(res.body).toEqual(Buffer.from(JSON.stringify({ response: { ok: true } })));
|
expect(res.body).toEqual(Buffer.from(JSON.stringify({ response: { ok: true } })));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("accepts the OpenMediaVault 8 authenticated status after login", async () => {
|
||||||
|
getServiceWidget.mockResolvedValue({
|
||||||
|
type: "openmediavault",
|
||||||
|
url: "http://omv",
|
||||||
|
username: "u",
|
||||||
|
password: "p",
|
||||||
|
method: "foo.bar",
|
||||||
|
});
|
||||||
|
|
||||||
|
httpProxy
|
||||||
|
// initial rpc unauthorized
|
||||||
|
.mockResolvedValueOnce([401, "application/json", Buffer.from(JSON.stringify({ response: {} })), {}])
|
||||||
|
// OMV 8 login rpc
|
||||||
|
.mockResolvedValueOnce([
|
||||||
|
200,
|
||||||
|
"application/json",
|
||||||
|
Buffer.from(JSON.stringify({ response: { status: "authenticated" } })),
|
||||||
|
{ "set-cookie": ["sid=1"] },
|
||||||
|
])
|
||||||
|
// retry rpc
|
||||||
|
.mockResolvedValueOnce([200, "application/json", Buffer.from(JSON.stringify({ response: { ok: true } })), {}]);
|
||||||
|
|
||||||
|
const req = { query: { group: "g", service: "svc", index: "0" } };
|
||||||
|
const res = createMockRes();
|
||||||
|
|
||||||
|
await openmediavaultProxyHandler(req, res);
|
||||||
|
|
||||||
|
expect(cookieJar.addCookieToJar).toHaveBeenCalled();
|
||||||
|
expect(httpProxy).toHaveBeenCalledTimes(3);
|
||||||
|
expect(res.statusCode).toBe(200);
|
||||||
|
expect(res.body).toEqual(Buffer.from(JSON.stringify({ response: { ok: true } })));
|
||||||
|
});
|
||||||
|
|
||||||
it("returns after a failed login attempt (non-200 response)", async () => {
|
it("returns after a failed login attempt (non-200 response)", async () => {
|
||||||
getServiceWidget.mockResolvedValue({
|
getServiceWidget.mockResolvedValue({
|
||||||
type: "openmediavault",
|
type: "openmediavault",
|
||||||
|
|||||||
Reference in New Issue
Block a user