Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore invalid key files in keystore directory. #4700

Merged
merged 4 commits into from
Feb 15, 2018

Conversation

matrushka
Copy link
Contributor

Modified keystore to ignore invalid key files inside the keystore directory to address #4681

  • Has calls the validateName function before checking if we have the file
  • List filters the returned list of file names by validateName.

@matrushka matrushka force-pushed the ignore_invalid_key_files branch 4 times, most recently from 407ec27 to 3d097c5 Compare February 14, 2018 11:32
Copy link
Member

@magik6k magik6k left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI wants go fmt ./....

1 thing, then LGTM

if err != nil {
t.Fatal(err)
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defer os.RemoveAll(tdir)

@@ -146,6 +147,7 @@ func TestKeystoreBasics(t *testing.T) {

func TestInvalidKeyFiles(t *testing.T) {
tdir, err := ioutil.TempDir("", "keystore-test")
defer os.RemoveAll(tdir)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be after the error check.

@matrushka matrushka force-pushed the ignore_invalid_key_files branch 2 times, most recently from 326f1c3 to fbe955d Compare February 14, 2018 14:15
@matrushka
Copy link
Contributor Author

matrushka commented Feb 14, 2018

@magik6k by the way the formatting error was in a file I haven't touched at all. Also running go fmt ./... had no effect on that file as well (it's fuse/ipns/ipns_test.go https://ci.ipfs.team/blue/organizations/jenkins/go-ipfs/detail/PR-4700/5/pipeline/).

@magik6k
Copy link
Member

magik6k commented Feb 14, 2018

Oh, for some reason un-fmt'ed code got merged to master, pushed a fix in #4701

Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of small things, otherwise, LGTM.

return nil, err
}

var list []string
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to preallocate list := make([]string, 0, len(dirs)).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd leave out the capacity param since we don't know if all the dirs are gonna make it to the list.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Over allocating slightly is better than under allocating, in general (especially when we only over allocate in an error case). Probably not that much of an issue here as this function isn't frequently called but I know it'll continue to bug me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done 👍

}
}

return list, err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning the error here is a bit confusing. It should always be nil (the go idiom is to just return list, nil).


for _, name := range dirs {
err := validateName(name)
if err == nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably log the error. You'll need to import the logger and construct it at the top of the file:

import (
  // ...
  logging "gx/ipfs/QmRb5jh8z2E8hMGN2tkvs1yHynUanqnZ3UeKwgN1i9P1F8/go-log"
)

var log = logging.Logger("keystore")

// ...

@Stebalien
Copy link
Member

LGTM. Thanks! Mind rebasing to make the tests pass?

…ectory.

* Has calls the validateName function before checking if we have the file
* List filters the returned list of file names by validateName.

License: MIT
Signed-off-by: matrushka <barisgumustas@gmail.com>
License: MIT
Signed-off-by: matrushka <barisgumustas@gmail.com>
…ments.

License: MIT
Signed-off-by: matrushka <barisgumustas@gmail.com>
License: MIT
Signed-off-by: matrushka <barisgumustas@gmail.com>
@whyrusleeping whyrusleeping merged commit 476ad38 into ipfs:master Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants