quak login: do not call an account without SRP attributes missing
check / check (push) Waiting to run
check / check (push) Waiting to run
The Ente server answers /users/srp/attributes with 404 and the code
NOT_FOUND when the account exists but has no SRP attributes, and with
404 and {} when no account has the email. Both were reported as "no
account with this email on the server". Only a 404 whose JSON body has
no code is named that way now.
Model: opus-5-5
This commit is contained in:
1 parent
6e361ace8a
commit
41d3e6f72f
2 files changed
+29
-4
No files matched your search
+6
-4
@@ -123,14 +123,16 @@ export const beginLogin = async (
|
|||||||
{ email },
|
{ email },
|
||||||
));
|
));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// The Ente server answers 404 with a JSON body when no account has the
|
// The Ente server answers 404 with `{}` when no account has the email.
|
||||||
// email. A server address that points somewhere else also answers 404,
|
// It answers 404 with the code NOT_FOUND when the account exists but
|
||||||
// but not with JSON, so that error keeps its bare status.
|
// has no SRP attributes. A server address that points somewhere else
|
||||||
|
// answers 404 without JSON. Those two errors stay as they are.
|
||||||
if (
|
if (
|
||||||
err instanceof ApiError &&
|
err instanceof ApiError &&
|
||||||
err.status === 404 &&
|
err.status === 404 &&
|
||||||
typeof err.body === "object" &&
|
typeof err.body === "object" &&
|
||||||
err.body !== null
|
err.body !== null &&
|
||||||
|
err.code === undefined
|
||||||
) {
|
) {
|
||||||
throw withMessage(err, "no account with this email on the server");
|
throw withMessage(err, "no account with this email on the server");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -410,6 +410,29 @@ describe("beginLogin via SRP", () => {
|
|||||||
expect((err as ApiError).status).toBe(404);
|
expect((err as ApiError).status).toBe(404);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// The Ente server's answer for an account that has no SRP attributes.
|
||||||
|
it("does not call an account with no SRP attributes missing", async () => {
|
||||||
|
const api = new ApiClient({
|
||||||
|
fetch: (async () =>
|
||||||
|
new Response(
|
||||||
|
JSON.stringify({ code: "NOT_FOUND", message: "" }),
|
||||||
|
{
|
||||||
|
status: 404,
|
||||||
|
headers: { "content-type": "application/json" },
|
||||||
|
},
|
||||||
|
)) as typeof globalThis.fetch,
|
||||||
|
});
|
||||||
|
|
||||||
|
const err = await beginLogin(api, TEST_EMAIL, TEST_PASSWORD).catch(
|
||||||
|
(e: unknown) => e,
|
||||||
|
);
|
||||||
|
expect(err).toBeInstanceOf(ApiError);
|
||||||
|
expect((err as ApiError).code).toBe("NOT_FOUND");
|
||||||
|
expect((err as ApiError).message).not.toBe(
|
||||||
|
"no account with this email on the server",
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// A server address that points somewhere other than an Ente server.
|
// A server address that points somewhere other than an Ente server.
|
||||||
it("keeps the bare status of a 404 that is not JSON", async () => {
|
it("keeps the bare status of a 404 that is not JSON", async () => {
|
||||||
const api = new ApiClient({
|
const api = new ApiClient({
|
||||||
|
|||||||
Reference in new issue
Block a user