add Name to auth.Account as a user friendly alias (#1992)

* add Name to auth.Account as a user friendly alias
This commit is contained in:
Dominic Wong
2020-09-10 14:49:51 +01:00
committed by GitHub
parent 04d2aa4696
commit 601b223cfb
6 changed files with 58 additions and 5 deletions

View File

@@ -44,8 +44,9 @@ func TestInspect(t *testing.T) {
md := map[string]string{"foo": "bar"}
scopes := []string{"admin"}
subject := "test"
name := "testname"
acc := &auth.Account{ID: subject, Scopes: scopes, Metadata: md}
acc := &auth.Account{ID: subject, Scopes: scopes, Metadata: md, Name: name}
tok, err := j.Generate(acc)
if err != nil {
t.Fatalf("Generate returned %v error, expected nil", err)
@@ -64,6 +65,9 @@ func TestInspect(t *testing.T) {
if len(tok2.Metadata) != len(md) {
t.Errorf("Inspect returned %v as the token metadata, expected %v", tok2.Metadata, md)
}
if tok2.Name != name {
t.Errorf("Inspect returned %v as the token name, expected %v", tok2.Name, name)
}
})
t.Run("Expired token", func(t *testing.T) {
@@ -84,4 +88,19 @@ func TestInspect(t *testing.T) {
}
})
t.Run("Default name", func(t *testing.T) {
tok, err := j.Generate(&auth.Account{ID: "test"})
if err != nil {
t.Fatalf("Generate returned %v error, expected nil", err)
}
tok2, err := j.Inspect(tok.Token)
if err != nil {
t.Fatalf("Inspect returned %v error, expected nil", err)
}
if tok2.Name != "test" {
t.Fatalf("Inspect returned %v as the token name, expected test", tok2.Name)
}
})
}