diff --git a/core/core.go b/core/core.go index cac0634..2a5ab3c 100644 --- a/core/core.go +++ b/core/core.go @@ -259,22 +259,27 @@ func Summary(jsonIn []byte) ([]byte, error) { // Purge processes a delegation purge request. func Purge(jsonIn []byte) ([]byte, error) { var s PurgeRequest - if err := json.Unmarshal(jsonIn, &s); err != nil { + var err error + + defer func() { + if err != nil { + log.Printf("core.purge failed: user=%s %v", s.Name, err) + } else { + log.Printf("core.purge success: user=%s", s.Name) + } + }() + + if err = json.Unmarshal(jsonIn, &s); err != nil { return jsonStatusError(err) } if records.NumRecords() == 0 { - return jsonStatusError(errors.New("Vault is not created yet")) - } - - // Validate the Name and Password as valid and admin - if err := validateUser(s.Name, s.Password, true); err != nil { - log.Printf("failed to validate %s as admin for purge request: %s", s.Name, err) + err = errors.New("vault has not been created") return jsonStatusError(err) } - if err := records.DeleteNonAdmin(); err != nil { - log.Printf("failed to purge non-admin delegates: %s", err) + // Validate the Name and Password as valid and admin + if err = validateUser(s.Name, s.Password, true); err != nil { return jsonStatusError(err) } diff --git a/core/core_test.go b/core/core_test.go index 9522305..e665d18 100644 --- a/core/core_test.go +++ b/core/core_test.go @@ -163,6 +163,10 @@ func TestSummary(t *testing.T) { } var s1 SummaryData + delegations := cache.GetSummary() + if len(delegations) == 0 { + t.Fatal("no delegations active") + } // check for summary of initialized vault without non-admin members after purge respJson, err = Purge(createJson) @@ -201,8 +205,13 @@ func TestSummary(t *testing.T) { } _, ok = s1.All["Bob"] - if ok { - t.Fatalf("Error in summary of account, record not purged") + if !ok { + t.Fatal("Bob was removed from the list of users") + } + + delegations = cache.GetSummary() + if len(delegations) != 0 { + t.Fatalf("purge failed to clear delegations (%d delegations remain)", len(delegations)) } } diff --git a/passvault/passvault.go b/passvault/passvault.go index f71c545..9990e9e 100644 --- a/passvault/passvault.go +++ b/passvault/passvault.go @@ -434,16 +434,6 @@ func (records *Records) DeleteRecord(name string) error { return errors.New("Record missing") } -// DeleteNonAdmin removes all record without admin status. -func (records *Records) DeleteNonAdmin() error { - for name, pr := range records.Passwords { - if !pr.IsAdmin() { - delete(records.Passwords, name) - } - } - return records.WriteRecordsToDisk() -} - // RevokeRecord removes admin status from a record. func (records *Records) RevokeRecord(name string) error { if rec, ok := records.GetRecord(name); ok {