@@ -4,15 +4,25 @@ import type { OpenClawConfig } from "openclaw/plugin-sdk/setup";
44import { describe , expect , it } from "vitest" ;
55import { lineSetupAdapter , patchLineAccountConfig } from "./setup-core.js" ;
66
7- type LineChannelConfig = { channelAccessToken ?: string } ;
7+ type LineChannelConfig = {
8+ channelAccessToken ?: string ;
9+ channelSecret ?: string ;
10+ tokenFile ?: string ;
11+ secretFile ?: string ;
12+ } ;
813
9- function appliedLineConfig ( input : Record < string , unknown > ) : LineChannelConfig {
10- const cfg = lineSetupAdapter . applyAccountConfig ( {
11- cfg : { } as OpenClawConfig ,
12- accountId : "default" ,
13- input,
14- } ) ;
15- return ( cfg . channels ?. line ?? { } ) as LineChannelConfig ;
14+ function applyLineSetup (
15+ input : Record < string , unknown > ,
16+ cfg : OpenClawConfig = { } as OpenClawConfig ,
17+ ) : OpenClawConfig {
18+ return lineSetupAdapter . applyAccountConfig ( { cfg, accountId : "default" , input } ) ;
19+ }
20+
21+ function appliedLineConfig (
22+ input : Record < string , unknown > ,
23+ cfg ?: OpenClawConfig ,
24+ ) : LineChannelConfig {
25+ return ( applyLineSetup ( input , cfg ) . channels ?. line ?? { } ) as LineChannelConfig ;
1626}
1727
1828describe ( "line setup token alias" , ( ) => {
@@ -85,3 +95,47 @@ describe("LINE scoped setup config", () => {
8595 } ) ;
8696 } ) ;
8797} ) ;
98+
99+ describe ( "LINE credential rotation" , ( ) => {
100+ // The inline value wins over its file at resolution time, so a rotation that
101+ // leaves it behind silently keeps using the credential it was meant to replace.
102+ const inlineFirst = ( ) =>
103+ applyLineSetup ( { channelAccessToken : "inline-token" , channelSecret : "inline-secret" } ) ;
104+
105+ it ( "retires an inline credential when its file replaces it" , ( ) => {
106+ const rotated = appliedLineConfig (
107+ { tokenFile : "/run/secrets/line-token" , secretFile : "/run/secrets/line-secret" } ,
108+ inlineFirst ( ) ,
109+ ) ;
110+
111+ expect ( rotated . tokenFile ) . toBe ( "/run/secrets/line-token" ) ;
112+ expect ( rotated . secretFile ) . toBe ( "/run/secrets/line-secret" ) ;
113+ expect ( rotated . channelAccessToken ) . toBeUndefined ( ) ;
114+ expect ( rotated . channelSecret ) . toBeUndefined ( ) ;
115+ } ) ;
116+
117+ it ( "retires a credential file when an inline value replaces it" , ( ) => {
118+ const fromFiles = applyLineSetup ( {
119+ tokenFile : "/run/secrets/line-token" ,
120+ secretFile : "/run/secrets/line-secret" ,
121+ } ) ;
122+
123+ const rotated = appliedLineConfig (
124+ { channelAccessToken : "inline-token" , channelSecret : "inline-secret" } ,
125+ fromFiles ,
126+ ) ;
127+
128+ expect ( rotated . channelAccessToken ) . toBe ( "inline-token" ) ;
129+ expect ( rotated . channelSecret ) . toBe ( "inline-secret" ) ;
130+ expect ( rotated . tokenFile ) . toBeUndefined ( ) ;
131+ expect ( rotated . secretFile ) . toBeUndefined ( ) ;
132+ } ) ;
133+
134+ it ( "leaves the credential that was not replaced alone" , ( ) => {
135+ const rotated = appliedLineConfig ( { tokenFile : "/run/secrets/line-token" } , inlineFirst ( ) ) ;
136+
137+ expect ( rotated . tokenFile ) . toBe ( "/run/secrets/line-token" ) ;
138+ expect ( rotated . channelSecret ) . toBe ( "inline-secret" ) ;
139+ expect ( rotated . channelAccessToken ) . toBeUndefined ( ) ;
140+ } ) ;
141+ } ) ;
0 commit comments