|
| 1 | +package client |
| 2 | + |
| 3 | +import ( |
| 4 | + "strings" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/gnolang/gno/tm2/pkg/commands" |
| 8 | + "github.com/gnolang/gno/tm2/pkg/crypto/keys" |
| 9 | + "github.com/gnolang/gno/tm2/pkg/testutils" |
| 10 | + "github.com/stretchr/testify/assert" |
| 11 | + "github.com/stretchr/testify/require" |
| 12 | +) |
| 13 | + |
| 14 | +func Test_execRotate(t *testing.T) { |
| 15 | + t.Parallel() |
| 16 | + |
| 17 | + // make new test dir |
| 18 | + kbHome, kbCleanUp := testutils.NewTestCaseDir(t) |
| 19 | + defer kbCleanUp() |
| 20 | + |
| 21 | + // initialize test options |
| 22 | + cfg := &RotateCfg{ |
| 23 | + RootCfg: &BaseCfg{ |
| 24 | + BaseOptions: BaseOptions{ |
| 25 | + Home: kbHome, |
| 26 | + InsecurePasswordStdin: true, |
| 27 | + }, |
| 28 | + }, |
| 29 | + } |
| 30 | + |
| 31 | + io := commands.NewTestIO() |
| 32 | + |
| 33 | + // Add test accounts to keybase. |
| 34 | + kb, err := keys.NewKeyBaseFromDir(kbHome) |
| 35 | + assert.NoError(t, err) |
| 36 | + |
| 37 | + keyName := "rotateApp_Key1" |
| 38 | + p1, p2 := "1234", "foobar" |
| 39 | + mnemonic := "equip will roof matter pink blind book anxiety banner elbow sun young" |
| 40 | + |
| 41 | + _, err = kb.CreateAccount(keyName, mnemonic, "", p1, 0, 0) |
| 42 | + assert.NoError(t, err) |
| 43 | + |
| 44 | + { |
| 45 | + // test: Key not found |
| 46 | + args := []string{"blah"} |
| 47 | + io.SetIn(strings.NewReader(p1 + "\n" + p2 + "\n" + p2 + "\n")) |
| 48 | + err = execRotate(cfg, args, io) |
| 49 | + require.Error(t, err) |
| 50 | + require.Equal(t, "Key blah not found", err.Error()) |
| 51 | + } |
| 52 | + |
| 53 | + { |
| 54 | + // test: Wrong password |
| 55 | + args := []string{keyName} |
| 56 | + io.SetIn(strings.NewReader("blah" + "\n" + p2 + "\n" + p2 + "\n")) |
| 57 | + err = execRotate(cfg, args, io) |
| 58 | + require.Error(t, err) |
| 59 | + require.Equal(t, "invalid account password", err.Error()) |
| 60 | + } |
| 61 | + |
| 62 | + { |
| 63 | + // test: New passwords don't match |
| 64 | + args := []string{keyName} |
| 65 | + io.SetIn(strings.NewReader(p1 + "\n" + p2 + "\n" + "blah" + "\n")) |
| 66 | + err = execRotate(cfg, args, io) |
| 67 | + require.Error(t, err) |
| 68 | + require.Equal(t, "unable to parse provided password, passphrases don't match", err.Error()) |
| 69 | + } |
| 70 | + |
| 71 | + { |
| 72 | + // Rotate the password |
| 73 | + args := []string{keyName} |
| 74 | + io.SetIn(strings.NewReader(p1 + "\n" + p2 + "\n" + p2 + "\n")) |
| 75 | + err = execRotate(cfg, args, io) |
| 76 | + require.NoError(t, err) |
| 77 | + } |
| 78 | + |
| 79 | + { |
| 80 | + // test: The old password shouldn't work |
| 81 | + args := []string{keyName} |
| 82 | + io.SetIn(strings.NewReader(p1 + "\n" + p1 + "\n" + p1 + "\n")) |
| 83 | + err = execRotate(cfg, args, io) |
| 84 | + require.Error(t, err) |
| 85 | + require.Equal(t, "invalid account password", err.Error()) |
| 86 | + } |
| 87 | + |
| 88 | + { |
| 89 | + // Updating the new password to itself should work |
| 90 | + args := []string{keyName} |
| 91 | + io.SetIn(strings.NewReader(p2 + "\n" + p2 + "\n" + p2 + "\n")) |
| 92 | + err = execRotate(cfg, args, io) |
| 93 | + require.NoError(t, err) |
| 94 | + } |
| 95 | +} |
1 commit comments
github-actions[bot] commentedon Oct 16, 2024
Possible performance regression was detected for benchmark 'Go Benchmarks'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold
1.20
.BenchmarkBinary/EmptyStruct:encode
973.5
ns/op 96 B/op 2 allocs/op437.5
ns/op 96 B/op 2 allocs/op2.23
BenchmarkBinary/EmptyStruct:encode - ns/op
973.5
ns/op437.5
ns/op2.23
BenchmarkBinary/EmptyStruct:decode
603.7
ns/op 0 B/op 0 allocs/op235.9
ns/op 0 B/op 0 allocs/op2.56
BenchmarkBinary/EmptyStruct:decode - ns/op
603.7
ns/op235.9
ns/op2.56
BenchmarkBinary/PrimitivesStruct:encode
9551
ns/op 1724 B/op 60 allocs/op5812
ns/op 1724 B/op 60 allocs/op1.64
BenchmarkBinary/PrimitivesStruct:encode - ns/op
9551
ns/op5812
ns/op1.64
BenchmarkBinary/PrimitivesStruct:decode
6162
ns/op 137 B/op 7 allocs/op3725
ns/op 137 B/op 7 allocs/op1.65
BenchmarkBinary/PrimitivesStruct:decode - ns/op
6162
ns/op3725
ns/op1.65
BenchmarkBinary/ShortArraysStruct:encode
1657
ns/op 192 B/op 4 allocs/op925
ns/op 192 B/op 4 allocs/op1.79
BenchmarkBinary/ShortArraysStruct:encode - ns/op
1657
ns/op925
ns/op1.79
BenchmarkBinary/ShortArraysStruct:decode
780.5
ns/op 0 B/op 0 allocs/op345.7
ns/op 0 B/op 0 allocs/op2.26
BenchmarkBinary/ShortArraysStruct:decode - ns/op
780.5
ns/op345.7
ns/op2.26
BenchmarkBinary/ArraysStruct:decode
16861
ns/op 790 B/op 40 allocs/op13560
ns/op 789 B/op 40 allocs/op1.24
BenchmarkBinary/ArraysStruct:decode - ns/op
16861
ns/op13560
ns/op1.24
BenchmarkBinary/PointersStruct:encode
10715
ns/op 1702 B/op 59 allocs/op6700
ns/op 1702 B/op 59 allocs/op1.60
BenchmarkBinary/PointersStruct:encode - ns/op
10715
ns/op6700
ns/op1.60
BenchmarkBinary/PointersStruct:decode
9221
ns/op 286 B/op 26 allocs/op5647
ns/op 286 B/op 26 allocs/op1.63
BenchmarkBinary/PointersStruct:decode - ns/op
9221
ns/op5647
ns/op1.63
BenchmarkBinary/EmbeddedSt1:encode
10518
ns/op 2037 B/op 65 allocs/op6554
ns/op 2037 B/op 65 allocs/op1.60
BenchmarkBinary/EmbeddedSt1:encode - ns/op
10518
ns/op6554
ns/op1.60
BenchmarkBinary/EmbeddedSt1:decode
6814
ns/op 300 B/op 8 allocs/op4122
ns/op 300 B/op 8 allocs/op1.65
BenchmarkBinary/EmbeddedSt1:decode - ns/op
6814
ns/op4122
ns/op1.65
BenchmarkBinary/AminoMarshalerStruct1:encode
5083
ns/op 512 B/op 16 allocs/op3233
ns/op 512 B/op 16 allocs/op1.57
BenchmarkBinary/AminoMarshalerStruct1:encode - ns/op
5083
ns/op3233
ns/op1.57
BenchmarkBinary/AminoMarshalerStruct1:decode
4548
ns/op 200 B/op 8 allocs/op2837
ns/op 200 B/op 8 allocs/op1.60
BenchmarkBinary/AminoMarshalerStruct1:decode - ns/op
4548
ns/op2837
ns/op1.60
BenchmarkBinary/AminoMarshalerStruct2:encode
9953
ns/op 1783 B/op 53 allocs/op7202
ns/op 1783 B/op 53 allocs/op1.38
BenchmarkBinary/AminoMarshalerStruct2:encode - ns/op
9953
ns/op7202
ns/op1.38
BenchmarkBinary/AminoMarshalerStruct2:decode
9557
ns/op 832 B/op 31 allocs/op6478
ns/op 832 B/op 31 allocs/op1.48
BenchmarkBinary/AminoMarshalerStruct2:decode - ns/op
9557
ns/op6478
ns/op1.48
BenchmarkBinary/AminoMarshalerStruct3:encode
4462
ns/op 352 B/op 12 allocs/op2730
ns/op 352 B/op 12 allocs/op1.63
BenchmarkBinary/AminoMarshalerStruct3:encode - ns/op
4462
ns/op2730
ns/op1.63
BenchmarkBinary/AminoMarshalerStruct3:decode
4209
ns/op 200 B/op 8 allocs/op2582
ns/op 200 B/op 8 allocs/op1.63
BenchmarkBinary/AminoMarshalerStruct3:decode - ns/op
4209
ns/op2582
ns/op1.63
BenchmarkBinary/AminoMarshalerInt4:encode
4801
ns/op 464 B/op 14 allocs/op2975
ns/op 464 B/op 14 allocs/op1.61
BenchmarkBinary/AminoMarshalerInt4:encode - ns/op
4801
ns/op2975
ns/op1.61
BenchmarkBinary/AminoMarshalerInt4:decode
4323
ns/op 200 B/op 8 allocs/op2644
ns/op 200 B/op 8 allocs/op1.64
BenchmarkBinary/AminoMarshalerInt4:decode - ns/op
4323
ns/op2644
ns/op1.64
BenchmarkBinary/AminoMarshalerInt5:encode
5244
ns/op 399 B/op 15 allocs/op3319
ns/op 399 B/op 15 allocs/op1.58
BenchmarkBinary/AminoMarshalerInt5:encode - ns/op
5244
ns/op3319
ns/op1.58
BenchmarkBinary/AminoMarshalerInt5:decode
4488
ns/op 231 B/op 10 allocs/op2793
ns/op 231 B/op 10 allocs/op1.61
BenchmarkBinary/AminoMarshalerInt5:decode - ns/op
4488
ns/op2793
ns/op1.61
BenchmarkBinary/AminoMarshalerStruct6:encode
8097
ns/op 904 B/op 29 allocs/op5417
ns/op 904 B/op 29 allocs/op1.49
BenchmarkBinary/AminoMarshalerStruct6:encode - ns/op
8097
ns/op5417
ns/op1.49
BenchmarkBinary/AminoMarshalerStruct6:decode
7949
ns/op 464 B/op 20 allocs/op5172
ns/op 464 B/op 20 allocs/op1.54
BenchmarkBinary/AminoMarshalerStruct6:decode - ns/op
7949
ns/op5172
ns/op1.54
BenchmarkBinary/AminoMarshalerStruct7:encode
7525
ns/op 696 B/op 24 allocs/op4803
ns/op 696 B/op 24 allocs/op1.57
BenchmarkBinary/AminoMarshalerStruct7:encode - ns/op
7525
ns/op4803
ns/op1.57
BenchmarkBinary/AminoMarshalerStruct7:decode
7702
ns/op 432 B/op 20 allocs/op4932
ns/op 432 B/op 20 allocs/op1.56
BenchmarkBinary/AminoMarshalerStruct7:decode - ns/op
7702
ns/op4932
ns/op1.56
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
69383730
ns/op 5130 B/op 9 allocs/op34774626
ns/op 5126 B/op 9 allocs/op2.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
69383730
ns/op34774626
ns/op2.00
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
138711293
ns/op 5139 B/op 9 allocs/op34774626
ns/op 5126 B/op 9 allocs/op3.99
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
138711293
ns/op34774626
ns/op3.99
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
277473245
ns/op 5158 B/op 9 allocs/op34774626
ns/op 5126 B/op 9 allocs/op7.98
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
277473245
ns/op34774626
ns/op7.98
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
554764352
ns/op 5196 B/op 10 allocs/op34774626
ns/op 5126 B/op 9 allocs/op15.95
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
554764352
ns/op34774626
ns/op15.95
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
1109290083
ns/op 5736 B/op 15 allocs/op34774626
ns/op 5126 B/op 9 allocs/op31.90
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
1109290083
ns/op34774626
ns/op31.90
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - allocs/op
15
allocs/op9
allocs/op1.67
BenchmarkBcryptGenerateFromPassword/benchmark-security-param
2219536939
ns/op 5528 B/op 13 allocs/op34774626
ns/op 5126 B/op 9 allocs/op63.83
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - ns/op
2219536939
ns/op34774626
ns/op63.83
BenchmarkBcryptGenerateFromPassword/benchmark-security-param - allocs/op
13
allocs/op9
allocs/op1.44
BenchmarkSigning
97445
ns/op 1856 B/op 36 allocs/op31111
ns/op 64 B/op 1 allocs/op3.13
BenchmarkSigning - ns/op
97445
ns/op31111
ns/op3.13
BenchmarkSigning - B/op
1856
B/op64
B/op29
BenchmarkSigning - allocs/op
36
allocs/op1
allocs/op36
BenchmarkSigning
99627
ns/op 1856 B/op 36 allocs/op31111
ns/op 64 B/op 1 allocs/op3.20
BenchmarkSigning - ns/op
99627
ns/op31111
ns/op3.20
BenchmarkSigning - B/op
1856
B/op64
B/op29
BenchmarkSigning - allocs/op
36
allocs/op1
allocs/op36
BenchmarkVerification
188069
ns/op 864 B/op 19 allocs/op73474
ns/op 0 B/op 0 allocs/op2.56
BenchmarkVerification - ns/op
188069
ns/op73474
ns/op2.56
BenchmarkVerification - B/op
864
B/op0
B/op+∞
BenchmarkVerification - allocs/op
19
allocs/op0
allocs/op+∞
BenchmarkVerification
193971
ns/op 864 B/op 19 allocs/op73474
ns/op 0 B/op 0 allocs/op2.64
BenchmarkVerification - ns/op
193971
ns/op73474
ns/op2.64
BenchmarkVerification - B/op
864
B/op0
B/op+∞
BenchmarkVerification - allocs/op
19
allocs/op0
allocs/op+∞
BenchmarkRandomBytes/random
88.89
ns/op 16 B/op 1 allocs/op46.88
ns/op 4 B/op 1 allocs/op1.90
BenchmarkRandomBytes/random - ns/op
88.89
ns/op46.88
ns/op1.90
BenchmarkRandomBytes/random - B/op
16
B/op4
B/op4
BenchmarkRandomBytes/random
135.1
ns/op 32 B/op 1 allocs/op46.88
ns/op 4 B/op 1 allocs/op2.88
BenchmarkRandomBytes/random - ns/op
135.1
ns/op46.88
ns/op2.88
BenchmarkRandomBytes/random - B/op
32
B/op4
B/op8
BenchmarkRandomBytes/random
331.3
ns/op 112 B/op 1 allocs/op46.88
ns/op 4 B/op 1 allocs/op7.07
BenchmarkRandomBytes/random - ns/op
331.3
ns/op46.88
ns/op7.07
BenchmarkRandomBytes/random - B/op
112
B/op4
B/op28
BenchmarkRandomBytes/random
2824
ns/op 1024 B/op 1 allocs/op46.88
ns/op 4 B/op 1 allocs/op60.24
BenchmarkRandomBytes/random - ns/op
2824
ns/op46.88
ns/op60.24
BenchmarkRandomBytes/random - B/op
1024
B/op4
B/op256
BenchmarkSmall/boltdb-1000-100-16-40/update
1402634
ns/op 46555 B/op 401 allocs/op843765
ns/op 36903 B/op 364 allocs/op1.66
BenchmarkSmall/boltdb-1000-100-16-40/update - ns/op
1402634
ns/op843765
ns/op1.66
BenchmarkSmall/boltdb-1000-100-16-40/update - B/op
46555
B/op36903
B/op1.26
BenchmarkSmall/goleveldb-1000-100-16-40/block
13746210
ns/op 4406203 B/op 46898 allocs/op11334793
ns/op 3288144 B/op 35620 allocs/op1.21
BenchmarkSmall/goleveldb-1000-100-16-40/block - ns/op
13746210
ns/op11334793
ns/op1.21
BenchmarkSmall/goleveldb-1000-100-16-40/block - B/op
4406203
B/op3288144
B/op1.34
BenchmarkSmall/goleveldb-1000-100-16-40/block - allocs/op
46898
allocs/op35620
allocs/op1.32
BenchmarkSmall/memdb-1000-100-16-40/block
20737727
ns/op 9069661 B/op 165088 allocs/op15591488
ns/op 6576384 B/op 116691 allocs/op1.33
BenchmarkSmall/memdb-1000-100-16-40/block - ns/op
20737727
ns/op15591488
ns/op1.33
BenchmarkSmall/memdb-1000-100-16-40/block - B/op
9069661
B/op6576384
B/op1.38
BenchmarkSmall/memdb-1000-100-16-40/block - allocs/op
165088
allocs/op116691
allocs/op1.41
BenchmarkMedium/boltdb-100000-100-16-40/update
6673256
ns/op 129759 B/op 1013 allocs/op4814868
ns/op 95463 B/op 810 allocs/op1.39
BenchmarkMedium/boltdb-100000-100-16-40/update - ns/op
6673256
ns/op4814868
ns/op1.39
BenchmarkMedium/boltdb-100000-100-16-40/update - B/op
129759
B/op95463
B/op1.36
BenchmarkMedium/boltdb-100000-100-16-40/update - allocs/op
1013
allocs/op810
allocs/op1.25
BenchmarkMedium/memdb-100000-100-16-40/update
1369540
ns/op 373984 B/op 7409 allocs/op1059697
ns/op 257418 B/op 4965 allocs/op1.29
BenchmarkMedium/memdb-100000-100-16-40/update - ns/op
1369540
ns/op1059697
ns/op1.29
BenchmarkMedium/memdb-100000-100-16-40/update - B/op
373984
B/op257418
B/op1.45
BenchmarkMedium/memdb-100000-100-16-40/update - allocs/op
7409
allocs/op4965
allocs/op1.49
BenchmarkLevelDBBatchSizes/goleveldb-100000-400-16-40/update - B/op
48984
B/op39205
B/op1.25
BenchmarkLevelDBBatchSizes/goleveldb-100000-400-16-40/update - allocs/op
592
allocs/op455
allocs/op1.30
BenchmarkHash/ripemd160
3956
ns/op 25 B/op 1 allocs/op1019
ns/op 25 B/op 1 allocs/op3.88
BenchmarkHash/ripemd160 - ns/op
3956
ns/op1019
ns/op3.88
BenchmarkHash/sha2-256
1773
ns/op 33 B/op 1 allocs/op506.9
ns/op 33 B/op 1 allocs/op3.50
BenchmarkHash/sha2-256 - ns/op
1773
ns/op506.9
ns/op3.50
BenchmarkHash/sha3-256
2077
ns/op 33 B/op 1 allocs/op763.6
ns/op 33 B/op 1 allocs/op2.72
BenchmarkHash/sha3-256 - ns/op
2077
ns/op763.6
ns/op2.72
BenchmarkSwitchBroadcast
17373
ns/op 1760 B/op 53 allocs/op11733
ns/op 1762 B/op 53 allocs/op1.48
BenchmarkSwitchBroadcast - ns/op
17373
ns/op11733
ns/op1.48
BenchmarkReadSecretConnection
3349
ns/op 0 B/op 0 allocs/op2777
ns/op 0 B/op 0 allocs/op1.21
BenchmarkReadSecretConnection - ns/op
3349
ns/op2777
ns/op1.21
BenchmarkCacheStoreIterator50000 - allocs/op
5247
allocs/op4313
allocs/op1.22
This comment was automatically generated by workflow using github-action-benchmark.
CC: @ajnavarro @thehowl @zivkovicmilos