forked from NoeFabris/opencode-antigravity-auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfingerprint.test.ts
More file actions
170 lines (143 loc) · 6.14 KB
/
Copy pathfingerprint.test.ts
File metadata and controls
170 lines (143 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import { describe, expect, it, vi, beforeEach } from "vitest";
import {
generateFingerprint,
collectCurrentFingerprint,
updateFingerprintVersion,
buildFingerprintHeaders,
getSessionFingerprint,
regenerateSessionFingerprint,
type Fingerprint,
} from "./fingerprint";
// ─── generateFingerprint ──────────────────────────────────────────────────────
describe("generateFingerprint", () => {
it("returns an object with all required Fingerprint fields", () => {
const fp = generateFingerprint();
expect(fp).toHaveProperty("deviceId");
expect(fp).toHaveProperty("sessionToken");
expect(fp).toHaveProperty("userAgent");
expect(fp).toHaveProperty("apiClient");
expect(fp).toHaveProperty("clientMetadata");
expect(fp).toHaveProperty("createdAt");
});
it("deviceId is a valid UUID", () => {
const fp = generateFingerprint();
expect(fp.deviceId).toMatch(
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,
);
});
it("sessionToken is a hex string of 32 chars", () => {
const fp = generateFingerprint();
expect(fp.sessionToken).toMatch(/^[0-9a-f]{32}$/);
});
it("clientMetadata.pluginType is GEMINI", () => {
const fp = generateFingerprint();
expect(fp.clientMetadata.pluginType).toBe("GEMINI");
});
it("clientMetadata.platform is WINDOWS or MACOS", () => {
const fp = generateFingerprint();
expect(["WINDOWS", "MACOS"]).toContain(fp.clientMetadata.platform);
});
it("clientMetadata.ideType is ANTIGRAVITY", () => {
const fp = generateFingerprint();
expect(fp.clientMetadata.ideType).toBe("ANTIGRAVITY");
});
it("userAgent contains antigravity/ prefix", () => {
const fp = generateFingerprint();
expect(fp.userAgent).toMatch(/^antigravity\//);
});
it("createdAt is a recent timestamp", () => {
const before = Date.now();
const fp = generateFingerprint();
const after = Date.now();
expect(fp.createdAt).toBeGreaterThanOrEqual(before);
expect(fp.createdAt).toBeLessThanOrEqual(after);
});
it("each call produces a different deviceId", () => {
const ids = new Set(Array.from({ length: 10 }, () => generateFingerprint().deviceId));
expect(ids.size).toBe(10);
});
});
// ─── collectCurrentFingerprint ────────────────────────────────────────────────
describe("collectCurrentFingerprint", () => {
it("returns a valid Fingerprint shape", () => {
const fp = collectCurrentFingerprint();
expect(fp.deviceId).toBeTruthy();
expect(fp.sessionToken).toBeTruthy();
expect(fp.userAgent).toBeTruthy();
expect(fp.clientMetadata.pluginType).toBe("GEMINI");
});
it("ideType is always ANTIGRAVITY", () => {
const fp = collectCurrentFingerprint();
expect(fp.clientMetadata.ideType).toBe("ANTIGRAVITY");
});
it("platform is WINDOWS or MACOS", () => {
const fp = collectCurrentFingerprint();
expect(["WINDOWS", "MACOS"]).toContain(fp.clientMetadata.platform);
});
});
// ─── updateFingerprintVersion ─────────────────────────────────────────────────
describe("updateFingerprintVersion", () => {
function makeFp(userAgent: string): Fingerprint {
return {
deviceId: "d",
sessionToken: "s",
userAgent,
apiClient: "a",
clientMetadata: { ideType: "ANTIGRAVITY", platform: "MACOS", pluginType: "GEMINI" },
createdAt: Date.now(),
};
}
it("returns false when version matches current", () => {
const fp = makeFp("antigravity/1.18.3 darwin/arm64");
// We don't know current version, but if already correct it returns false
const result = updateFingerprintVersion(fp);
// Either false (same) or true (updated) — just verify no throw
expect(typeof result).toBe("boolean");
});
it("updates userAgent when version differs and returns true", () => {
const fp = makeFp("antigravity/0.0.1 darwin/arm64");
const updated = updateFingerprintVersion(fp);
expect(updated).toBe(true);
expect(fp.userAgent).not.toContain("0.0.1");
expect(fp.userAgent).toMatch(/^antigravity\//);
});
it("preserves everything after the version in userAgent", () => {
const fp = makeFp("antigravity/0.0.1 darwin/arm64");
updateFingerprintVersion(fp);
expect(fp.userAgent).toContain("darwin/arm64");
});
it("does not modify userAgent when it has no version prefix", () => {
const fp = makeFp("some-other-agent/1.0");
const updated = updateFingerprintVersion(fp);
expect(updated).toBe(false);
expect(fp.userAgent).toBe("some-other-agent/1.0");
});
});
// ─── buildFingerprintHeaders ──────────────────────────────────────────────────
describe("buildFingerprintHeaders", () => {
it("returns empty object for null fingerprint", () => {
expect(buildFingerprintHeaders(null)).toEqual({});
});
it("returns User-Agent header from fingerprint", () => {
const fp = generateFingerprint();
const headers = buildFingerprintHeaders(fp);
expect(headers["User-Agent"]).toBe(fp.userAgent);
});
});
// ─── session fingerprint ──────────────────────────────────────────────────────
describe("getSessionFingerprint / regenerateSessionFingerprint", () => {
it("getSessionFingerprint returns the same object on repeated calls", () => {
const a = getSessionFingerprint();
const b = getSessionFingerprint();
expect(a).toBe(b);
});
it("regenerateSessionFingerprint returns a new object", () => {
const before = getSessionFingerprint();
const next = regenerateSessionFingerprint();
expect(next).not.toBe(before);
});
it("after regeneration, getSessionFingerprint returns the new fingerprint", () => {
const next = regenerateSessionFingerprint();
expect(getSessionFingerprint()).toBe(next);
});
});