diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 10:15:56 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 10:15:56 +0300 |
| commit | 7374be02a89cad4d0df4460a98b42764d191ad92 (patch) | |
| tree | 880889fffc6681925536d354cba206a52cb22175 /internal/cli/cli_test.go | |
| parent | c053f1e04ffb0fb89743cc7bc5154efaf6e8a0bf (diff) | |
task 13: upload API keys in SQLite, Bearer auth, create-client-key CLI
- Add internal/authkeys with SHA-256 hashed tokens and KeyCount gate
- PUT /upload/{host}/{kind} for uptimed files; auth when any key exists
- Daemon -auth-db and Config.AuthDB; plain HTTP unchanged
- CLI: goprecords --create-client-key HOSTNAME (-stats-dir|-auth-db)
Made-with: Cursor
Diffstat (limited to 'internal/cli/cli_test.go')
| -rw-r--r-- | internal/cli/cli_test.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/internal/cli/cli_test.go b/internal/cli/cli_test.go index 9fa20e5..ff7b046 100644 --- a/internal/cli/cli_test.go +++ b/internal/cli/cli_test.go @@ -147,3 +147,30 @@ func TestStableSubcommandsStillRecognized(t *testing.T) { } } } + +func TestCreateClientKeyRequiresHostname(t *testing.T) { + err := Execute([]string{"--create-client-key"}) + if err == nil || !strings.Contains(err.Error(), "hostname") { + t.Fatalf("expected hostname error, got %v", err) + } +} + +func TestCreateClientKeyRequiresStatsOrAuthDB(t *testing.T) { + err := Execute([]string{"--create-client-key", "h1"}) + if err == nil || !strings.Contains(err.Error(), "stats-dir") { + t.Fatalf("expected stats-dir/auth-db error, got %v", err) + } +} + +func TestCreateClientKeyWritesToken(t *testing.T) { + dir := t.TempDir() + out := captureStdout(t, func() { + if err := Execute([]string{"--create-client-key", "mybox", "-stats-dir", dir}); err != nil { + t.Fatal(err) + } + }) + tok := strings.TrimSpace(out) + if len(tok) < 20 { + t.Fatalf("token too short %q", tok) + } +} |
