Skip to content

Commit

Permalink
FIX #86 - Fixed an issue where signing keys were not properly resolve…
Browse files Browse the repository at this point in the history
…d for an account user. (#87)
  • Loading branch information
aricart authored May 14, 2019
1 parent 8cebc2d commit e81db7c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
3 changes: 2 additions & 1 deletion cmd/describeuser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,8 @@ func TestDescribeUser_Account(t *testing.T) {

ts.AddAccount(t, "A")
_, pub, kp := CreateAccountKey(t)
_, _, err := ExecuteCmd(createEditAccount(), "--account", "A", "-sk", pub)
_, _, err := ExecuteCmd(createEditAccount(), "--account", "A", "--sk", pub)
require.NoError(t, err)

// signed with default account key
ts.AddUser(t, "A", "aa")
Expand Down
50 changes: 50 additions & 0 deletions cmd/edituser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,53 @@ func Test_EditUser_Src(t *testing.T) {
require.NotNil(t, cc)
require.ElementsMatch(t, strings.Split(cc.Src, ","), []string{"192.0.1.0/8"})
}

func Test_EditUserSK(t *testing.T) {
ts := NewTestStore(t, "O")
t.Log(ts.Dir)

s, p, _ := CreateAccountKey(t)
ts.AddAccount(t, "A")
_, _, err := ExecuteCmd(HoistRootFlags(createEditAccount()), "-a", "A", "--sk", p)
require.NoError(t, err)

ac, err := ts.Store.ReadAccountClaim("A")
require.NoError(t, err)
require.Contains(t, ac.SigningKeys, p)

ts.AddUser(t, "A", "U")
uc, err := ts.Store.ReadUserClaim("A", "U")
require.NoError(t, err)
require.Equal(t, uc.Issuer, ac.Subject)

_, _, err = ExecuteCmd(HoistRootFlags(createEditUserCmd()), "-n", "U", "--allow-pub", "foo", "-K", string(s))
require.NoError(t, err)
uc, err = ts.Store.ReadUserClaim("A", "U")
require.NoError(t, err)
require.Equal(t, uc.Issuer, p)
}

func Test_EditUserAddedWithSK(t *testing.T) {
ts := NewTestStore(t, "O")
t.Log(ts.Dir)

s, p, sk := CreateAccountKey(t)
ts.AddAccount(t, "A")
_, _, err := ExecuteCmd(HoistRootFlags(createEditAccount()), "-a", "A", "--sk", p)
require.NoError(t, err)

ac, err := ts.Store.ReadAccountClaim("A")
require.NoError(t, err)
require.Contains(t, ac.SigningKeys, p)

ts.AddUserWithSigner(t, "A", "U", sk)
uc, err := ts.Store.ReadUserClaim("A", "U")
require.NoError(t, err)
require.Equal(t, uc.Issuer, p)

_, _, err = ExecuteCmd(HoistRootFlags(createEditUserCmd()), "-n", "U", "--allow-pub", "foo", "-K", string(s))
require.NoError(t, err)
uc, err = ts.Store.ReadUserClaim("A", "U")
require.NoError(t, err)
require.Equal(t, uc.Issuer, p)
}
12 changes: 5 additions & 7 deletions cmd/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (s *Store) StoreClaim(data []byte) error {
if err != nil {
return err
}
issuer := gc.Issuer
issuer := uc.Issuer
if uc.IssuerAccount != "" {
issuer = uc.IssuerAccount
}
Expand All @@ -299,15 +299,13 @@ func (s *Store) StoreClaim(data []byte) error {
}
for _, i := range infos {
if i.IsDir() {
c, err := s.LoadClaim(Accounts, i.Name(), JwtName(i.Name()))
c, err := s.ReadAccountClaim(i.Name())
if err != nil {
return err
}
if c != nil {
if c.Subject == issuer {
account = i.Name()
break
}
if c != nil && c.DidSign(uc) {
account = i.Name()
break
}
}
}
Expand Down

0 comments on commit e81db7c

Please sign in to comment.