mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 14:04:58 +00:00
fix(daemon): normalise whitespace in checkTokenDrift to prevent false-positive warning (#39108)
This commit is contained in:
@@ -118,6 +118,24 @@ describe("checkTokenDrift", () => {
|
|||||||
expect(result).toBeNull();
|
expect(result).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns null when tokens match but service token has trailing newline", () => {
|
||||||
|
const result = checkTokenDrift({ serviceToken: "same-token\n", configToken: "same-token" });
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns null when tokens match but have surrounding whitespace", () => {
|
||||||
|
const result = checkTokenDrift({ serviceToken: " same-token ", configToken: "same-token" });
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns null when both tokens have different whitespace padding", () => {
|
||||||
|
const result = checkTokenDrift({
|
||||||
|
serviceToken: "same-token\r\n",
|
||||||
|
configToken: " same-token ",
|
||||||
|
});
|
||||||
|
expect(result).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
it("detects drift when config has token but service has different token", () => {
|
it("detects drift when config has token but service has different token", () => {
|
||||||
const result = checkTokenDrift({ serviceToken: "old-token", configToken: "new-token" });
|
const result = checkTokenDrift({ serviceToken: "old-token", configToken: "new-token" });
|
||||||
expect(result).not.toBeNull();
|
expect(result).not.toBeNull();
|
||||||
|
|||||||
@@ -362,13 +362,19 @@ export function checkTokenDrift(params: {
|
|||||||
}): ServiceConfigIssue | null {
|
}): ServiceConfigIssue | null {
|
||||||
const { serviceToken, configToken } = params;
|
const { serviceToken, configToken } = params;
|
||||||
|
|
||||||
|
// Normalise both tokens before comparing: service-file parsers (systemd,
|
||||||
|
// launchd) can return values with trailing newlines or whitespace that
|
||||||
|
// cause a false-positive mismatch against the config value.
|
||||||
|
const normService = serviceToken?.trim() || undefined;
|
||||||
|
const normConfig = configToken?.trim() || undefined;
|
||||||
|
|
||||||
// No drift if both are undefined/empty
|
// No drift if both are undefined/empty
|
||||||
if (!serviceToken && !configToken) {
|
if (!normService && !normConfig) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Drift: config has token, service has different or no token
|
// Drift: config has token, service has different or no token
|
||||||
if (configToken && serviceToken !== configToken) {
|
if (normConfig && normService !== normConfig) {
|
||||||
return {
|
return {
|
||||||
code: SERVICE_AUDIT_CODES.gatewayTokenDrift,
|
code: SERVICE_AUDIT_CODES.gatewayTokenDrift,
|
||||||
message:
|
message:
|
||||||
|
|||||||
Reference in New Issue
Block a user