fix: store tokens in ~/.config/mcp-publisher/ instead of cwd (#1166)
## Summary Fixes #663 - **Security fix**: `mcp-publisher login` no longer writes `.mcpregistry_github_token` and `.mcpregistry_registry_token` to the current working directory. GitHub tokens are kept in memory during the login→exchange flow and cleared immediately after. - **Token location**: Unified token moved from `~/.mcp_publisher_token` to `~/.config/mcp-publisher/token.json` (dir 0700, file 0600), following the convention used by `gh`, `docker`, and `kubectl`. - **Dead code removed**: `NeedsLogin()` was on the `Provider` interface but never called — removed from interface and all 4 implementations. `forceLogin` field also removed. - **Auth tests added**: 11 new tests for `GitHubATProvider` (package previously had 0 tests). - **Test isolation**: `SetupTestToken` now uses `t.TempDir()` + `t.Setenv("HOME", ...)` instead of writing to real `$HOME`. ### Breaking change Users must re-login after upgrading (`mcp-publisher login <method>`). Existing tokens at `~/.mcp_publisher_token` are not auto-migrated. `logout` cleans up both old and new locations. ## Test plan - [x] `make check` passes (lint, unit tests, integration tests) - [x] `mcp-publisher login none` stores token at `~/.config/mcp-publisher/token.json` - [x] No `.mcpregistry_*` files created in cwd after login (with `--token`, `MCP_GITHUB_TOKEN`, or device flow) - [x] `mcp-publisher publish` reads token from new location - [x] `mcp-publisher validate` reads registry URL from new location - [x] `mcp-publisher logout` cleans up new location, legacy `~/.mcp_publisher_token`, and cwd `.mcpregistry_*` files - [x] `mcp-publisher logout` when not logged in shows "Not logged in" - [x] File permissions: dir 0700, file 0600 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
77bbd41fd3
commit
90baa0528f
1 changed files with 556 additions and 203 deletions
|
|
@ -8,7 +8,6 @@ import (
|
|||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/modelcontextprotocol/registry/cmd/publisher/commands"
|
||||
"github.com/modelcontextprotocol/registry/internal/validators"
|
||||
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
@ -64,14 +63,19 @@ func SetupMockRegistryServer(t *testing.T, publishHandler func(w http.ResponseWr
|
|||
return server
|
||||
}
|
||||
|
||||
// SetupTestToken creates a token file pointing to the test server
|
||||
// SetupTestToken creates a token file pointing to the test server.
|
||||
// It overrides $HOME to a temp directory so tests don't touch real credentials.
|
||||
func SetupTestToken(t *testing.T, registryURL, token string) string {
|
||||
t.Helper()
|
||||
|
||||
homeDir, err := os.UserHomeDir()
|
||||
require.NoError(t, err)
|
||||
// Override $HOME so tokenFilePath() resolves to a temp directory
|
||||
tempHome := t.TempDir()
|
||||
t.Setenv("HOME", tempHome)
|
||||
|
||||
tokenPath := filepath.Join(homeDir, commands.TokenFileName)
|
||||
dir := filepath.Join(tempHome, ".config", "mcp-publisher")
|
||||
require.NoError(t, os.MkdirAll(dir, 0700))
|
||||
|
||||
tokenPath := filepath.Join(dir, "token.json")
|
||||
tokenData := map[string]string{
|
||||
"token": token,
|
||||
"registry": registryURL,
|
||||
|
|
@ -83,10 +87,6 @@ func SetupTestToken(t *testing.T, registryURL, token string) string {
|
|||
err = os.WriteFile(tokenPath, data, 0600)
|
||||
require.NoError(t, err)
|
||||
|
||||
t.Cleanup(func() {
|
||||
_ = os.Remove(tokenPath)
|
||||
})
|
||||
|
||||
return tokenPath
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue