|
1 | 1 | // Doctor OAuth sidecar tests cover encrypted sidecar detection and auth repair guidance. |
2 | | -import { createCipheriv } from "node:crypto"; |
3 | 2 | import fs from "node:fs"; |
4 | 3 | import path from "node:path"; |
5 | 4 | import { afterEach, describe, expect, it, vi } from "vitest"; |
|
9 | 8 | type OpenClawTestState, |
10 | 9 | } from "../test-utils/openclaw-test-state.js"; |
11 | 10 | import { maybeRepairLegacyOAuthSidecarProfiles } from "./doctor-auth-oauth-sidecar.js"; |
12 | | -import { testing } from "./doctor-auth-oauth-sidecar.test-support.js"; |
13 | 11 | import type { DoctorPrompter } from "./doctor-prompter.js"; |
14 | 12 |
|
15 | 13 | const states: OpenClawTestState[] = []; |
@@ -54,34 +52,6 @@ function writeLegacyAuthProfiles( |
54 | 52 | return state.writeJson(path.join("agents", agentId, "agent", "auth-profiles.json"), store); |
55 | 53 | } |
56 | 54 |
|
57 | | -function encryptLegacySidecarMaterial(params: { |
58 | | - ref: { source: "openclaw-credentials"; provider: "openai-codex"; id: string }; |
59 | | - profileId: string; |
60 | | - provider: string; |
61 | | - seed: string; |
62 | | - material: Record<string, string>; |
63 | | -}) { |
64 | | - const iv = Buffer.alloc(12, 7); |
65 | | - const cipher = createCipheriv("aes-256-gcm", testing.buildLegacyOAuthSecretKey(params.seed), iv); |
66 | | - cipher.setAAD( |
67 | | - testing.buildLegacyOAuthSecretAad({ |
68 | | - ref: params.ref, |
69 | | - profileId: params.profileId, |
70 | | - provider: params.provider, |
71 | | - }), |
72 | | - ); |
73 | | - const ciphertext = Buffer.concat([ |
74 | | - cipher.update(JSON.stringify(params.material), "utf8"), |
75 | | - cipher.final(), |
76 | | - ]); |
77 | | - return { |
78 | | - algorithm: "aes-256-gcm", |
79 | | - iv: iv.toString("base64url"), |
80 | | - tag: cipher.getAuthTag().toString("base64url"), |
81 | | - ciphertext: ciphertext.toString("base64url"), |
82 | | - }; |
83 | | -} |
84 | | - |
85 | 55 | afterEach(async () => { |
86 | 56 | clearRuntimeAuthProfileStoreSnapshots(); |
87 | 57 | for (const state of states.splice(0)) { |
@@ -126,17 +96,13 @@ describe("maybeRepairLegacyOAuthSidecarProfiles", () => { |
126 | 96 | version: 1, |
127 | 97 | profileId, |
128 | 98 | provider: "openai-codex", |
129 | | - encrypted: encryptLegacySidecarMaterial({ |
130 | | - ref, |
131 | | - profileId, |
132 | | - provider: "openai-codex", |
133 | | - seed, |
134 | | - material: { |
135 | | - access: "access-token", |
136 | | - refresh: "refresh-token", |
137 | | - idToken: "id-token", |
138 | | - }, |
139 | | - }), |
| 99 | + encrypted: { |
| 100 | + algorithm: "aes-256-gcm", |
| 101 | + iv: "BwcHBwcHBwcHBwcH", |
| 102 | + tag: "gSm_Lg58EVO-5wZGQlWHEA", |
| 103 | + ciphertext: |
| 104 | + "4qrZ4-zdgUdttB3gTUNORWdtO4gqLiFgTsilUX3-9RZiN2MLkCDdxQXQ2GfeqN1zi1qb9iURwK0sO0TJZfxO3zULMKNlRgUT", |
| 105 | + }, |
140 | 106 | }, |
141 | 107 | ); |
142 | 108 |
|
@@ -231,16 +197,12 @@ describe("maybeRepairLegacyOAuthSidecarProfiles", () => { |
231 | 197 | version: 1, |
232 | 198 | profileId, |
233 | 199 | provider: "openai-codex", |
234 | | - encrypted: encryptLegacySidecarMaterial({ |
235 | | - ref, |
236 | | - profileId, |
237 | | - provider: "openai-codex", |
238 | | - seed: "right-seed", |
239 | | - material: { |
240 | | - access: "access-token", |
241 | | - refresh: "refresh-token", |
242 | | - }, |
243 | | - }), |
| 200 | + encrypted: { |
| 201 | + algorithm: "aes-256-gcm", |
| 202 | + iv: "BwcHBwcHBwcHBwcH", |
| 203 | + tag: "ZHGhT2cekYFZCOxu8pP0KA", |
| 204 | + ciphertext: "OQPDJez2jSRH4FPxFNNkwEw7PDbClF6Ty6T2l4TLGvr6bdJfhK6VA6ccWwC1xlrR4ENA", |
| 205 | + }, |
244 | 206 | }, |
245 | 207 | ); |
246 | 208 |
|
@@ -450,16 +412,13 @@ describe("maybeRepairLegacyOAuthSidecarProfiles", () => { |
450 | 412 | version: 1, |
451 | 413 | profileId, |
452 | 414 | provider: "openai-codex", |
453 | | - encrypted: encryptLegacySidecarMaterial({ |
454 | | - ref, |
455 | | - profileId, |
456 | | - provider: "openai-codex", |
457 | | - seed, |
458 | | - material: { |
459 | | - access: "shared-access-token", |
460 | | - refresh: "shared-refresh-token", |
461 | | - }, |
462 | | - }), |
| 415 | + encrypted: { |
| 416 | + algorithm: "aes-256-gcm", |
| 417 | + iv: "BwcHBwcHBwcHBwcH", |
| 418 | + tag: "91XpNgcMQ-AVeo7NDnv11Q", |
| 419 | + ciphertext: |
| 420 | + "fVMsIFtJ0LX1ayciusBnyS7KulJU2dCAdkKU4yMLGYTVB-Gq0X_SvUqPTkAX_a1ZBIjGIC6nFH_3HvhWHMIX7Cs", |
| 421 | + }, |
463 | 422 | }, |
464 | 423 | ); |
465 | 424 |
|
|
0 commit comments