Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var auditCmd = &cobra.Command{
The log lists the changes made to the project through the API, each with the
token, client and source address that made it: an attempt row before the
change and a result row after it. Count rows sum a minute's refused requests
and requests by legacy project tokens.
and requests by agent and workload tokens.

It reads the active project unless --project names another, and needs
permission to manage the project. A page holds --limit rows, at most 500;
Expand Down
9 changes: 5 additions & 4 deletions cmd/audit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import (
"github.com/valar/cli/api"
)

// Row 1200's token ID is in a format the CLI does not know, so it is shown whole.
const auditPage = `[{"id":1201,"at":"2026-11-21T10:00:01Z","kind":"result","attemptId":1200,"principal":"human::alice","tokenId":"` + ciTokenID +
`","client":"valar-cli/4.9.0","sourceIp":"192.0.2.1","service":"web","operation":"deploys.submit","target":"deployment=7","status":200,"count":0},` +
`{"id":1200,"at":"2026-11-21T10:00:00Z","kind":"attempt","principal":"human::alice","tokenId":"legacy-project","operation":"tokens.create","count":0},` +
`{"id":1190,"at":"2026-11-21T09:59:00Z","kind":"count","principal":"service::acme","operation":"env.patch","status":403,"count":3}]`
`{"id":1200,"at":"2026-11-21T10:00:00Z","kind":"attempt","principal":"human::alice","tokenId":"future-id","operation":"tokens.create","count":0},` +
`{"id":1190,"at":"2026-11-21T09:59:00Z","kind":"count","principal":"service::acme/web","operation":"env.patch","status":403,"count":3}]`

func TestListAudit(t *testing.T) {
for _, tc := range []struct {
Expand All @@ -36,8 +37,8 @@ func TestListAudit(t *testing.T) {
want := []string{
"ID TIME KIND PRINCIPAL TOKEN OPERATION SERVICE TARGET STATUS SOURCE CLIENT",
"1201 <time> result human::alice fedcba98 deploys.submit web deployment=7 200 192.0.2.1 valar-cli/4.9.0",
"1200 <time> attempt human::alice legacy-project tokens.create - - - - -",
"1190 <time> count (3) service::acme - env.patch - - 403 - -",
"1200 <time> attempt human::alice future-id tokens.create - - - - -",
"1190 <time> count (3) service::acme/web - env.patch - - 403 - -",
}
if len(got) != len(want) {
t.Fatalf("table\n got %q\nwant %q", got, want)
Expand Down
3 changes: 2 additions & 1 deletion cmd/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func TestVerifyToken(t *testing.T) {
Name: "ExpiresSoon", Info: `{"name":"alice","projects":[],"token":{"kind":"user","scopes":["all"],"expiresAt":"2026-11-24T12:00:00Z"}}`,
WantWarn: "Warning: your Valar token expires in 3 days, at 2026-11-24 12:00 UTC.",
},
{Name: "NoExpiry", Info: `{"name":"alice","projects":[],"token":{"kind":"legacy-user","scopes":["all"]}}`},
{Name: "NoExpiry", Info: `{"name":"alice","projects":[],"token":{"kind":"user","scopes":["all"]}}`},
{Name: "UnknownKind", Info: `{"name":"alice","projects":[],"token":{"kind":"future-kind","scopes":["all"],"expiresAt":"2027-01-20T12:00:00Z"}}`},
{
Name: "Agent", Info: `{"name":"alice","projects":[],"token":{"kind":"agent","project":"acme","scopes":["read"]}}`,
WantKind: kindNotAllowed, WantErr: "this is an agent token",
Expand Down
13 changes: 4 additions & 9 deletions cmd/token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,6 @@ func TestCreateToken_Refused(t *testing.T) {
map[string]string{"POST /tokens": `{"error":"only tokens minted in the console or with authctl can mint tokens"}`},
kindNotAllowed, "Forbidden: only tokens minted in the console or with authctl can mint tokens",
},
{
"Legacy", http.StatusForbidden,
map[string]string{"POST /tokens": `{"error":"legacy tokens cannot mint tokens; create one in the console or with authctl"}`},
kindNotAllowed, "Forbidden: legacy tokens cannot mint tokens",
},
{"Taken", http.StatusConflict, map[string]string{"POST /tokens": `{"error":"a live token with that name exists"}`}, kindConflict, "a live token with that name exists"},
{"BadBinding", http.StatusBadRequest, map[string]string{"POST /tokens": `{"error":"service is not a service name"}`}, kindInvalid, "service is not a service name"},
} {
Expand Down Expand Up @@ -404,7 +399,7 @@ func TestListTokens(t *testing.T) {
own = `[{"id":"` + rootTokenID + `","kind":"user","name":"laptop","scopes":["all"],"createdAt":"2026-11-01T12:00:00Z","expiresAt":"2027-01-30T12:00:00Z","lastUsed":"2026-11-21T11:59:00Z"},` +
`{"id":"` + ciTokenID + `","kind":"user","name":"ci","project":"acme","scopes":["deploy","read"],"parent":"` + rootTokenID + `","expiresAt":"2027-01-30T12:00:00Z"},` +
`{"id":"` + oldID + `","kind":"user","name":"old","service":"web","project":"acme","scopes":["read"],"expiresAt":"2027-01-30T12:00:00Z","revokedAt":"2026-11-20T12:00:00Z"},` +
`{"id":"` + expiredID + `","kind":"legacy-user","name":"cli","scopes":["all"],"expiresAt":"2026-11-21T11:00:00Z"}]`
`{"id":"` + expiredID + `","kind":"future-kind","name":"cli","scopes":["all"],"expiresAt":"2026-11-21T11:00:00Z"}]`
project = `[{"id":"` + ciTokenID + `","kind":"user","name":"ci","owner":"alice","project":"acme","scopes":["deploy","read"],"parent":"` + rootTokenID + `"}]`
)
routes := map[string]string{"GET /tokens": own, "GET /projects/acme/tokens": project}
Expand All @@ -420,7 +415,7 @@ func TestListTokens(t *testing.T) {
rootTokenID + " laptop user - all - 2 months from now 1 minute ago live",
ciTokenID + " ci user acme deploy,read laptop 2 months from now never live",
oldID + " old user acme/web read - 2 months from now never revoked",
expiredID + " cli legacy-user - all - 1 hour ago never expired",
expiredID + " cli future-kind - all - 1 hour ago never expired",
},
},
{
Expand Down Expand Up @@ -568,11 +563,11 @@ func TestPrintUserInfo(t *testing.T) {
"EarlierGrant",
api.UserInfo{
Name: "alice", Projects: []string{"acme"}, Principal: "human::alice",
Token: &api.Token{ID: rootTokenID, Kind: "legacy-user", Scopes: []string{"all"}},
Token: &api.Token{ID: rootTokenID, Kind: "user", Scopes: []string{"all"}},
},
[]string{
"User: alice", "Principal: human::alice", "Projects: acme", "Token: -", "ID: " + rootTokenID,
"Kind: legacy-user", "Binding: any project", "Scopes: all", "Expires: never",
"Kind: user", "Binding: any project", "Scopes: all", "Expires: never",
},
},
{"NoGrant", api.UserInfo{Name: "alice", Projects: []string{"acme"}}, []string{"User: alice", "Projects: acme"}},
Expand Down