version_check_test.go 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // Copyright 2020 The go-ethereum Authors
  2. // This file is part of go-ethereum.
  3. //
  4. // go-ethereum is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // go-ethereum is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with go-ethereum. If not, see <http://www.gnu.org/licenses/>.
  16. package main
  17. import (
  18. "encoding/json"
  19. "io/ioutil"
  20. "path/filepath"
  21. "testing"
  22. )
  23. func TestVerification(t *testing.T) {
  24. // Signatures generated with `minisign`
  25. t.Run("minisig", func(t *testing.T) {
  26. // For this test, the pubkey is in testdata/minisign.pub
  27. // (the privkey is `minisign.sec`, if we want to expand this test. Password 'test' )
  28. pub := "RWQkliYstQBOKOdtClfgC3IypIPX6TAmoEi7beZ4gyR3wsaezvqOMWsp"
  29. testVerification(t, pub, "./testdata/vcheck/minisig-sigs/")
  30. })
  31. // Signatures generated with `signify-openbsd`
  32. t.Run("signify-openbsd", func(t *testing.T) {
  33. t.Skip("This currently fails, minisign expects 4 lines of data, signify provides only 2")
  34. // For this test, the pubkey is in testdata/signifykey.pub
  35. // (the privkey is `signifykey.sec`, if we want to expand this test. Password 'test' )
  36. pub := "RWSKLNhZb0KdATtRT7mZC/bybI3t3+Hv/O2i3ye04Dq9fnT9slpZ1a2/"
  37. testVerification(t, pub, "./testdata/vcheck/signify-sigs/")
  38. })
  39. }
  40. func testVerification(t *testing.T, pubkey, sigdir string) {
  41. // Data to verify
  42. data, err := ioutil.ReadFile("./testdata/vcheck/data.json")
  43. if err != nil {
  44. t.Fatal(err)
  45. }
  46. // Signatures, with and without comments, both trusted and untrusted
  47. files, err := ioutil.ReadDir(sigdir)
  48. if err != nil {
  49. t.Fatal(err)
  50. }
  51. for _, f := range files {
  52. sig, err := ioutil.ReadFile(filepath.Join(sigdir, f.Name()))
  53. if err != nil {
  54. t.Fatal(err)
  55. }
  56. err = verifySignature([]string{pubkey}, data, sig)
  57. if err != nil {
  58. t.Fatal(err)
  59. }
  60. }
  61. }
  62. func TestJson(t *testing.T) {
  63. data, _ := ioutil.ReadFile("./testdata/vcheck/data2.json")
  64. var vulns []vulnJson
  65. if err := json.Unmarshal(data, &vulns); err != nil {
  66. t.Fatal(err)
  67. }
  68. if len(vulns) == 0 {
  69. t.Fatal("expected data, got none")
  70. }
  71. if have, want := vulns[0].CVE, "correct"; have != want {
  72. t.Errorf("have %v, want %v", have, want)
  73. }
  74. }