config.ClearToken creates a config file when none exists (not a no-op) #595

Closed
opened 2026-08-07 19:40:08 +00:00 by the.auditor · 1 comment
Owner

ClearToken in internal/tpagectl/config/config.go is documented as "a no-op when no config file is present", but resolveConfig always returns the default user config path when no file is found, so the path == "" guard never triggers. ClearToken therefore creates a config file (defaults + empty server.token) at the default path even when none existed.

TestClearTokenNoFile passes for the wrong reason: it checks the working directory for .tpagectl.yaml, but the file is written to the real user config dir (os.UserConfigDir()), which also pollutes the developer's config during go test.

Track whether a config file was actually read (e.g. a hadFile flag returned by resolveConfig) and return early when there is none.

See #588

`ClearToken` in `internal/tpagectl/config/config.go` is documented as "a no-op when no config file is present", but `resolveConfig` always returns the default user config path when no file is found, so the `path == ""` guard never triggers. `ClearToken` therefore creates a config file (defaults + empty `server.token`) at the default path even when none existed. `TestClearTokenNoFile` passes for the wrong reason: it checks the working directory for `.tpagectl.yaml`, but the file is written to the real user config dir (`os.UserConfigDir()`), which also pollutes the developer's config during `go test`. Track whether a config file was actually read (e.g. a `hadFile` flag returned by `resolveConfig`) and return early when there is none. See https://git.lan.thwap.org/thwap/thwap-pagesd/pulls/588
Owner

Fixed in #634: config.ClearToken returns early (via os.Stat) when no config file exists, so token set no longer creates an empty config file.

Fixed in #634: `config.ClearToken` returns early (via `os.Stat`) when no config file exists, so `token set` no longer creates an empty config file.
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
thwap/thwap-pagesd#595
No description provided.