Skip to content

Commit

Permalink
fix: #234 (#237)
Browse files Browse the repository at this point in the history
* fix: #234

* fix: #235 (#238)

* fix: #236 (#239)
  • Loading branch information
asabya authored Aug 22, 2022
1 parent d6cedef commit 5cfab47
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 11 deletions.
8 changes: 8 additions & 0 deletions pkg/account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,14 @@ func (a *Account) Authorise(password string) bool {
a.logger.Errorf(errBlankPassword.Error())
return false
}

/*
TODO this is just a temporary fix, in future when mnemonic logic will be removed,
we have to remove Authorise logic or come up with something to check password validity
*/
if a.wallet.seed != nil {
return true
}
plainMnemonic, err := a.wallet.decryptMnemonic(password)
if err != nil {
return false
Expand Down
16 changes: 9 additions & 7 deletions pkg/collection/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,13 +318,15 @@ func (d *Document) DeleteDocumentDB(dbName string) error {
// delete the document db from the DB file
delete(docTables, dbName)

if len(docTables) > 0 {
// store the rest of the document db
err = d.storeDocumentDBSchemas(docTables)
if err != nil { // skipcq: TCV-001
d.logger.Errorf("deleting document db: ", err.Error())
return err
}
if len(docTables) == 0 {
docTables = map[string]DBSchema{}
}

// store the rest of the document db
err = d.storeDocumentDBSchemas(docTables)
if err != nil { // skipcq: TCV-001
d.logger.Errorf("deleting document db: ", err.Error())
return err
}

d.logger.Info("deleted document db: ", dbName)
Expand Down
21 changes: 21 additions & 0 deletions pkg/collection/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,16 @@ func TestDocumentStore(t *testing.T) {

// check if other two db exists
checkIfDBsExists(t, []string{"docdb_1_1", "docdb_1_3"}, docStore)
err = docStore.DeleteDocumentDB("docdb_1_1")
if err != nil {
t.Fatal(err)
}
err = docStore.DeleteDocumentDB("docdb_1_3")
if err != nil {
t.Fatal(err)
}
checkIfDBNotExists(t, "docdb_1_1", docStore)
checkIfDBNotExists(t, "docdb_1_3", docStore)
})

t.Run("create_document_db_with_multiple_indexes", func(t *testing.T) {
Expand Down Expand Up @@ -864,6 +874,17 @@ func checkIfDBsExists(t *testing.T, dbNames []string, docStore *collection.Docum
}
}

func checkIfDBNotExists(t *testing.T, tableName string, docStore *collection.Document) {
t.Helper()
tables, err := docStore.LoadDocumentDBSchemas()
if err != nil {
t.Fatal(err)
}
if _, found := tables[tableName]; found {
t.Fatalf("document db found")
}
}

func loadSchemaAndCheckSimpleIndexCount(t *testing.T, docStore *collection.Document, dbName string, count int) collection.DBSchema {
t.Helper()
tables, err := docStore.LoadDocumentDBSchemas()
Expand Down
1 change: 0 additions & 1 deletion pkg/dfs/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func (d *API) DeletePod(podName, passphrase, sessionId string) error {
// remove from the login session
ui.RemovePodName(podName)
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ func (u *Users) LoginUserV2(userName, passPhrase string, client blockstore.Clien
// load encrypted private key
fd := feed.New(accountInfo, client, u.logger)
key, err := u.downloadPortableAccount(utils.Address(address), userName, passPhrase, fd)
if err != nil { // skipcq: TCV-001
return nil, "", "", err
if err != nil {
return nil, "", "", ErrInvalidPassword
}

// decrypt and remove pad from private ley
Expand Down
5 changes: 5 additions & 0 deletions pkg/user/login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func TestLogin(t *testing.T) {
t.Fatal(err)
}

_, _, _, err = userObject.LoginUserV2("7e4567e7cb003804992eef11fd5c757275a4c", "wrong_password", mockClient, "")
if !errors.Is(err, user.ErrInvalidPassword) {
t.Fatal(err)
}

// addUserAndSessionToMap user again
ui1, _, _, err := userObject.LoginUserV2("7e4567e7cb003804992eef11fd5c757275a4c", "password1", mockClient, "")
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/user/portable_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func (*Users) uploadPortableAccount(accountInfo *account.Info, username, passwor
func (*Users) downloadPortableAccount(address utils.Address, username, password string, fd *feed.API) ([]byte, error) {
topic := utils.HashString(AuthVersion + username + password)
_, data, err := fd.GetFeedDataFromTopic(topic, address)
if err != nil { // skipcq: TCV-001
if err != nil {
return nil, err
}
return data, nil
Expand Down

0 comments on commit 5cfab47

Please sign in to comment.