mirror of
https://github.com/Chewbaccalakis/rfid-database.git
synced 2026-09-10 00:11:56 -07:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
924b889f76 | ||
|
|
4593052348 | ||
|
|
d07bf72e23 | ||
|
|
3331944773 |
@@ -7,7 +7,6 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
check:
|
check:
|
||||||
name: lint-typecheck-test-build
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -19,14 +18,3 @@ jobs:
|
|||||||
- run: npm run lint
|
- run: npm run lint
|
||||||
- run: npm run typecheck
|
- run: npm run typecheck
|
||||||
- run: npm test
|
- run: npm test
|
||||||
- run: npm run build
|
|
||||||
env:
|
|
||||||
AUTH_SECRET: ci-build-secret-at-least-32-characters
|
|
||||||
|
|
||||||
docker:
|
|
||||||
name: docker-build
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
- name: Build production image
|
|
||||||
run: docker build -t rfid-database:ci .
|
|
||||||
|
|||||||
@@ -80,13 +80,9 @@ curl -sH "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" \
|
|||||||
npm test
|
npm test
|
||||||
npm run lint
|
npm run lint
|
||||||
npm run typecheck
|
npm run typecheck
|
||||||
npm run build
|
|
||||||
```
|
```
|
||||||
|
|
||||||
GitHub Actions runs on every pull request and push to `main`:
|
GitHub Actions runs lint, typecheck, and tests on every pull request and push to `main`.
|
||||||
|
|
||||||
1. **lint / typecheck / test / Next.js build**
|
|
||||||
2. **`docker build`** — catches Dockerfile parse/build failures (the class of break that conflict markers previously caused)
|
|
||||||
|
|
||||||
## Docker
|
## Docker
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,6 @@ import { GET as getTags, POST as postTag } from "@/app/api/v1/tags/route";
|
|||||||
import { PUT as putByUid } from "@/app/api/v1/tags/by-uid/[uid]/route";
|
import { PUT as putByUid } from "@/app/api/v1/tags/by-uid/[uid]/route";
|
||||||
import { GET as getExport } from "@/app/api/v1/tags/[id]/export/route";
|
import { GET as getExport } from "@/app/api/v1/tags/[id]/export/route";
|
||||||
import { GET as listTokens, POST as createToken } from "@/app/api/v1/tokens/route";
|
import { GET as listTokens, POST as createToken } from "@/app/api/v1/tokens/route";
|
||||||
import { DELETE as deleteToken } from "@/app/api/v1/tokens/[id]/route";
|
|
||||||
import { GET as search } from "@/app/api/v1/search/route";
|
|
||||||
import { GET as getBackup, POST as postBackup } from "@/app/api/v1/backup/route";
|
|
||||||
import { POST as importTag } from "@/app/api/v1/tags/import/route";
|
|
||||||
import { NextRequest } from "next/server";
|
import { NextRequest } from "next/server";
|
||||||
|
|
||||||
function req(url: string, init?: ConstructorParameters<typeof NextRequest>[1]) {
|
function req(url: string, init?: ConstructorParameters<typeof NextRequest>[1]) {
|
||||||
@@ -193,81 +189,9 @@ describe("API v1 integration", () => {
|
|||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
const revoked = await deleteToken(
|
|
||||||
req(`http://localhost/api/v1/tokens/${data.id}`, {
|
|
||||||
method: "DELETE",
|
|
||||||
headers: auth,
|
|
||||||
}),
|
|
||||||
{ params: Promise.resolve({ id: data.id }) }
|
|
||||||
);
|
|
||||||
expect(revoked.status).toBe(200);
|
|
||||||
|
|
||||||
const db = getDb();
|
const db = getDb();
|
||||||
const user = db.select().from(users).where(eq(users.id, userId)).get();
|
const user = db.select().from(users).where(eq(users.id, userId)).get();
|
||||||
expect(user?.email).toBe("[email protected]");
|
expect(user?.email).toBe("[email protected]");
|
||||||
expect(db.select().from(sites).all().length).toBeGreaterThanOrEqual(0);
|
expect(db.select().from(sites).all().length).toBeGreaterThanOrEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("searches, imports MCT, and backs up", async () => {
|
|
||||||
const auth = { Authorization: `Bearer ${bearer}` };
|
|
||||||
|
|
||||||
const siteRes = await postSite(
|
|
||||||
req("http://localhost/api/v1/sites", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { ...auth, "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ code: "C", name: "Lab" }),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const site = await siteRes.json();
|
|
||||||
|
|
||||||
const mct = `+UID: AABBCCDD
|
|
||||||
+Sector: 0
|
|
||||||
AABBCCDD00112233445566778899AABB
|
|
||||||
00000000000000000000000000000000
|
|
||||||
00000000000000000000000000000000
|
|
||||||
FFFFFFFFFFFFFF078069FFFFFFFFFFFF
|
|
||||||
`;
|
|
||||||
|
|
||||||
const imported = await importTag(
|
|
||||||
req("http://localhost/api/v1/tags/import", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { ...auth, "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({
|
|
||||||
siteId: site.id,
|
|
||||||
label: "Imported fob",
|
|
||||||
content: mct,
|
|
||||||
filename: "sample.mct",
|
|
||||||
}),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
expect(imported.status).toBe(201);
|
|
||||||
const tag = await imported.json();
|
|
||||||
expect(tag.uid).toBe("AABBCCDD");
|
|
||||||
|
|
||||||
const searchRes = await search(
|
|
||||||
req("http://localhost/api/v1/search?q=Imported", { headers: auth })
|
|
||||||
);
|
|
||||||
expect(searchRes.status).toBe(200);
|
|
||||||
const found = await searchRes.json();
|
|
||||||
expect(found.tags.some((t: { label: string }) => t.label === "Imported fob")).toBe(
|
|
||||||
true
|
|
||||||
);
|
|
||||||
|
|
||||||
const backupRes = await getBackup(
|
|
||||||
req("http://localhost/api/v1/backup", { headers: auth })
|
|
||||||
);
|
|
||||||
expect(backupRes.status).toBe(200);
|
|
||||||
const backup = await backupRes.json();
|
|
||||||
expect(backup.sites.length).toBeGreaterThanOrEqual(1);
|
|
||||||
expect(backup.tags.length).toBeGreaterThanOrEqual(1);
|
|
||||||
|
|
||||||
const restore = await postBackup(
|
|
||||||
req("http://localhost/api/v1/backup", {
|
|
||||||
method: "POST",
|
|
||||||
headers: { ...auth, "Content-Type": "application/json" },
|
|
||||||
body: JSON.stringify({ ...backup, mode: "merge" }),
|
|
||||||
})
|
|
||||||
);
|
|
||||||
expect(restore.status).toBe(200);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import { exportTag } from "@/lib/rfid/exporters";
|
|
||||||
import {
|
|
||||||
dumpDataSchema,
|
|
||||||
mifareClassicDumpSchema,
|
|
||||||
siteCreateSchema,
|
|
||||||
tagCreateSchema,
|
|
||||||
} from "@/lib/validation/rfid";
|
|
||||||
|
|
||||||
const classicDump = {
|
|
||||||
size: "1K" as const,
|
|
||||||
sectors: [
|
|
||||||
{
|
|
||||||
index: 0,
|
|
||||||
blocks: [
|
|
||||||
"04A1B2C304A1B2C304A1B2C304A1B2C3",
|
|
||||||
"00000000000000000000000000000000",
|
|
||||||
"00000000000000000000000000000000",
|
|
||||||
"FFFFFFFFFFFFFF078069FFFFFFFFFFFF",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const sampleTag = {
|
|
||||||
id: "00000000-0000-4000-8000-000000000001",
|
|
||||||
label: "Dock fob",
|
|
||||||
frequency: "HF",
|
|
||||||
protocol: "MIFARE_CLASSIC_1K",
|
|
||||||
uid: "04A1B2C3",
|
|
||||||
dumpData: classicDump,
|
|
||||||
keys: { A: ["FFFFFFFFFFFF"], B: [] },
|
|
||||||
notes: null as string | null,
|
|
||||||
};
|
|
||||||
|
|
||||||
describe("exporters", () => {
|
|
||||||
it("exports canonical JSON", () => {
|
|
||||||
const out = exportTag(sampleTag, "json");
|
|
||||||
expect(out.contentType).toBe("application/json");
|
|
||||||
const parsed = JSON.parse(out.body);
|
|
||||||
expect(parsed.uid).toBe("04A1B2C3");
|
|
||||||
expect(parsed.dumpData.size).toBe("1K");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("exports proxmark JSON with blocks", () => {
|
|
||||||
const out = exportTag(sampleTag, "proxmark");
|
|
||||||
const parsed = JSON.parse(out.body);
|
|
||||||
expect(parsed.FileType).toBe("mfcard");
|
|
||||||
expect(parsed.blocks).toHaveLength(4);
|
|
||||||
expect(parsed.Card.UID).toBe("04A1B2C3");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("exports MCT text", () => {
|
|
||||||
const out = exportTag(sampleTag, "mct");
|
|
||||||
expect(out.body).toContain("+UID: 04A1B2C3");
|
|
||||||
expect(out.body).toContain("+Sector: 0");
|
|
||||||
});
|
|
||||||
|
|
||||||
it("exports hex listing", () => {
|
|
||||||
const out = exportTag(sampleTag, "hex");
|
|
||||||
expect(out.body).toContain("# UID 04A1B2C3");
|
|
||||||
expect(out.body).toContain("S0B0");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe("validation schemas", () => {
|
|
||||||
it("accepts valid classic dump", () => {
|
|
||||||
expect(mifareClassicDumpSchema.safeParse(classicDump).success).toBe(true);
|
|
||||||
expect(dumpDataSchema.safeParse(classicDump).success).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("rejects invalid site codes", () => {
|
|
||||||
expect(
|
|
||||||
siteCreateSchema.safeParse({ name: "Lab", code: "bad code!" }).success
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("accepts valid tag create payload", () => {
|
|
||||||
const parsed = tagCreateSchema.safeParse({
|
|
||||||
siteId: "00000000-0000-4000-8000-000000000099",
|
|
||||||
label: "Dock",
|
|
||||||
frequency: "HF",
|
|
||||||
protocol: "MIFARE_CLASSIC_1K",
|
|
||||||
uid: "04:A1:B2:C3",
|
|
||||||
dumpData: classicDump,
|
|
||||||
keys: { A: ["FFFFFFFFFFFF"] },
|
|
||||||
});
|
|
||||||
expect(parsed.success).toBe(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user