mirror of
https://github.com/Chewbaccalakis/rfid-database.git
synced 2026-09-10 00:11:56 -07:00
Add Next.js app with SQLite/Drizzle storage for sites and LF/HF tag dumps, multi-user Auth.js (credentials + optional OIDC), personal API tokens in Settings, versioned /api/v1 for UI and future CLI use, MCT/Proxmark/JSON import-export, PWA offline shell, Vitest tests, and GitHub Actions CI. Co-authored-by: Cursor Agent <[email protected]>
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { parseMct, parseImport } from "@/lib/rfid/parsers";
|
|
import { exportTag } from "@/lib/rfid/exporters";
|
|
import { mifareClassicDumpSchema } from "@/lib/validation/rfid";
|
|
|
|
const sampleMct = `+UID: 04A1B2C3
|
|
+Sector: 0
|
|
04A1B2C304A1B2C304A1B2C304A1B2C3
|
|
00000000000000000000000000000000
|
|
00000000000000000000000000000000
|
|
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
|
+Sector: 1
|
|
00000000000000000000000000000000
|
|
00000000000000000000000000000000
|
|
00000000000000000000000000000000
|
|
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
|
`;
|
|
|
|
describe("MCT parser/exporter", () => {
|
|
it("parses MCT dumps", () => {
|
|
const tag = parseMct(sampleMct);
|
|
expect(tag.uid).toBe("04A1B2C3");
|
|
expect(tag.protocol).toBe("MIFARE_CLASSIC_1K");
|
|
expect(mifareClassicDumpSchema.safeParse(tag.dumpData).success).toBe(true);
|
|
});
|
|
|
|
it("round-trips via export mct", () => {
|
|
const tag = parseMct(sampleMct);
|
|
const exported = exportTag(
|
|
{
|
|
id: "00000000-0000-4000-8000-000000000001",
|
|
label: "test",
|
|
frequency: tag.frequency,
|
|
protocol: tag.protocol,
|
|
uid: tag.uid,
|
|
dumpData: tag.dumpData,
|
|
keys: null,
|
|
notes: null,
|
|
},
|
|
"mct"
|
|
);
|
|
const again = parseImport(exported.body, "test.mct");
|
|
expect(again.uid).toBe(tag.uid);
|
|
expect(again.protocol).toBe(tag.protocol);
|
|
});
|
|
|
|
it("parses canonical JSON", () => {
|
|
const json = JSON.stringify({
|
|
label: "Dock",
|
|
frequency: "HF",
|
|
protocol: "MIFARE_CLASSIC_1K",
|
|
uid: "04:A1:B2:C3",
|
|
dumpData: {
|
|
size: "1K",
|
|
sectors: [{ index: 0, blocks: ["AABBCCDDEEFF00112233445566778899"] }],
|
|
},
|
|
});
|
|
const tag = parseImport(json, "x.json");
|
|
expect(tag.uid).toBe("04A1B2C3");
|
|
expect(tag.label).toBe("Dock");
|
|
});
|
|
});
|