feat: release authentication diagnostics 0.2.0
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
importAegisBackup,
|
||||
importAndOtpBackup,
|
||||
importFreeOtpBackup,
|
||||
importTwoFasBackup,
|
||||
} from "../../src/otp/vendor-backups";
|
||||
|
||||
const secret = "JBSWY3DPEHPK3PXP";
|
||||
|
||||
describe("vendor OTP backup importers", () => {
|
||||
it("imports Aegis plaintext entries and skips non-portable token types", () => {
|
||||
const result = importAegisBackup(
|
||||
JSON.stringify({
|
||||
db: {
|
||||
entries: [
|
||||
{
|
||||
type: "totp",
|
||||
name: "alice",
|
||||
issuer: "Example",
|
||||
info: { secret, algo: "SHA1", digits: 6, period: 30 },
|
||||
},
|
||||
{ type: "steam", name: "game", issuer: "Steam", info: { secret } },
|
||||
],
|
||||
},
|
||||
}),
|
||||
);
|
||||
expect(result.profiles[0]).toMatchObject({
|
||||
issuer: "Example",
|
||||
account: "alice",
|
||||
});
|
||||
expect(result.warnings[0]).toMatch(/steam/iu);
|
||||
});
|
||||
|
||||
it("imports 2FAS, andOTP and FreeOTP field layouts", () => {
|
||||
expect(
|
||||
importTwoFasBackup(
|
||||
JSON.stringify({
|
||||
services: [
|
||||
{
|
||||
name: "Example",
|
||||
secret,
|
||||
otp: {
|
||||
account: "alice",
|
||||
issuer: "Issuer",
|
||||
tokenType: "TOTP",
|
||||
algorithm: "SHA1",
|
||||
digits: 6,
|
||||
period: 30,
|
||||
},
|
||||
},
|
||||
],
|
||||
}),
|
||||
).profiles[0],
|
||||
).toMatchObject({ account: "alice", issuer: "Issuer" });
|
||||
expect(
|
||||
importAndOtpBackup(
|
||||
JSON.stringify([
|
||||
{
|
||||
secret,
|
||||
issuer: "Example",
|
||||
label: "bob",
|
||||
type: "TOTP",
|
||||
algorithm: "SHA1",
|
||||
digits: 6,
|
||||
period: 30,
|
||||
},
|
||||
]),
|
||||
).profiles[0]!.account,
|
||||
).toBe("bob");
|
||||
expect(
|
||||
importFreeOtpBackup(
|
||||
JSON.stringify([
|
||||
{
|
||||
secret: [49, 50, 51, 52],
|
||||
issuerExt: "Example",
|
||||
label: "carol",
|
||||
type: "totp",
|
||||
algo: "SHA1",
|
||||
digits: 6,
|
||||
period: 30,
|
||||
},
|
||||
]),
|
||||
).profiles[0]!.account,
|
||||
).toBe("carol");
|
||||
});
|
||||
|
||||
it("refuses encrypted Aegis content instead of guessing", () => {
|
||||
expect(() =>
|
||||
importAegisBackup(JSON.stringify({ db: "ciphertext", header: {} })),
|
||||
).toThrow(/encrypted/iu);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user