Skip to content

Commit

Permalink
chore: enable gosec linter (#4161)
Browse files Browse the repository at this point in the history
* gosec

* gosec

* secure use of tar files

* fix lint issues

* fix tests

---------

Co-authored-by: Danilo Pantani <[email protected]>
  • Loading branch information
faddat and Pantani committed Aug 5, 2024
1 parent 3152cf5 commit b0828f2
Show file tree
Hide file tree
Showing 31 changed files with 123 additions and 85 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ linters:
- godot
- gofumpt
- revive
- gosec
- gosimple
- govet
- grouper
Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/account_export.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func accountExportHandler(cmd *cobra.Command, args []string) error {
return err
}

if err := os.WriteFile(path, []byte(armored), 0o644); err != nil {
if err := os.WriteFile(path, []byte(armored), 0o600); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion ignite/cmd/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func toolsMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, app
return err
}

return os.WriteFile(toolsFilename, buf.Bytes(), 0o644)
return os.WriteFile(toolsFilename, buf.Bytes(), 0o600)
}

func bufMigrationPreRunHandler(cmd *cobra.Command, session *cliui.Session, appPath, protoDir string) error {
Expand Down
2 changes: 1 addition & 1 deletion ignite/internal/analytics/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func checkDNT() (anonIdentity, error) {
return i, err
}

return i, os.WriteFile(identityPath, data, 0o700)
return i, os.WriteFile(identityPath, data, 0o600)
}

func getIsCI() bool {
Expand Down
16 changes: 8 additions & 8 deletions ignite/internal/plugin/testdata/execute_fail/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-sdk v0.50.7 // indirect
github.com/cosmos/cosmos-sdk v0.50.8 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.16.0 // indirect
Expand Down Expand Up @@ -81,17 +81,17 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
16 changes: 8 additions & 8 deletions ignite/internal/plugin/testdata/execute_ok/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ require (
github.com/cockroachdb/logtags v0.0.0-20230118201751-21c54148d20b // indirect
github.com/cockroachdb/redact v1.1.5 // indirect
github.com/cosmos/btcutil v1.0.5 // indirect
github.com/cosmos/cosmos-sdk v0.50.7 // indirect
github.com/cosmos/cosmos-sdk v0.50.8 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/color v1.16.0 // indirect
Expand Down Expand Up @@ -81,17 +81,17 @@ require (
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
go.etcd.io/bbolt v1.3.9 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240515191416-fc5f0ca64291 // indirect
google.golang.org/grpc v1.64.0 // indirect
google.golang.org/grpc v1.64.1 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
8 changes: 4 additions & 4 deletions ignite/internal/tools/gen-config-doc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ require (
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
4 changes: 4 additions & 0 deletions ignite/internal/tools/gen-config-doc/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ golang.org/x/net v0.0.0-20221002022538-bcab6841153b/go.mod h1:YDH+HFinaLZZlnHAfS
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -220,19 +221,22 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand Down
12 changes: 6 additions & 6 deletions ignite/internal/tools/gen-mig-diffs/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@ require (
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/term v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/tools v0.21.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/term v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
6 changes: 6 additions & 0 deletions ignite/internal/tools/gen-mig-diffs/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ golang.org/x/crypto v0.3.1-0.20221117191849-2c476679df9a/go.mod h1:hebNnKkNXi2Uz
golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU=
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
Expand All @@ -247,6 +248,7 @@ golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
golang.org/x/net v0.26.0/go.mod h1:5YKkiSynbBIh3p6iOc/vibscux0x38BZDkn8sCUPxHE=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -278,6 +280,7 @@ golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
Expand All @@ -286,6 +289,7 @@ golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.20.0 h1:VnkxpohqXaOBYJtBmEppKUG6mXpi+4O6purfc2+sMhw=
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -295,6 +299,7 @@ golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
Expand All @@ -303,6 +308,7 @@ golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.21.0 h1:qc0xYgIbsSDt9EyWz05J5wfa7LOVW0YTLOXrqdLAWIw=
golang.org/x/tools v0.21.0/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
25 changes: 9 additions & 16 deletions ignite/pkg/availableport/availableport.go
Original file line number Diff line number Diff line change
@@ -1,28 +1,21 @@
package availableport

import (
"crypto/rand"
"fmt"
"math/rand"
"math/big"
"net"
"time"

"github.com/ignite/cli/v29/ignite/pkg/errors"
)

type availablePortOptions struct {
randomizer *rand.Rand
minPort uint
maxPort uint
minPort uint
maxPort uint
}

type Options func(o *availablePortOptions)

func WithRandomizer(r *rand.Rand) Options {
return func(o *availablePortOptions) {
o.randomizer = r
}
}

func WithMaxPort(maxPort uint) Options {
return func(o *availablePortOptions) {
o.maxPort = maxPort
Expand All @@ -41,9 +34,8 @@ func WithMinPort(minPort uint) Options {
func Find(n uint, options ...Options) (ports []uint, err error) {
// Defining them before so we can set a value depending on the AvailablePortOptions
opts := availablePortOptions{
minPort: 44000,
maxPort: 55000,
randomizer: rand.New(rand.NewSource(time.Now().UnixNano())),
minPort: 44000,
maxPort: 55000,
}

for _, apply := range options {
Expand All @@ -64,8 +56,9 @@ func Find(n uint, options ...Options) (ports []uint, err error) {
for len(registered) < int(n) {
// Greater or equal to min and lower than max
totalPorts := opts.maxPort - opts.minPort + 1
randomPort := opts.randomizer.Intn(int(totalPorts))
port := uint(randomPort) + opts.minPort

randomPort, _ := rand.Int(rand.Reader, big.NewInt(int64(totalPorts)))
port := uint(randomPort.Uint64()) + opts.minPort

conn, err := net.Dial("tcp", fmt.Sprintf(":%d", port))
// if there is an error, this might mean that no one is listening from this port
Expand Down
2 changes: 0 additions & 2 deletions ignite/pkg/availableport/availableport_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package availableport_test

import (
"math/rand"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -51,7 +50,6 @@ func TestFind(t *testing.T) {
name: "with randomizer",
n: 100,
options: []availableport.Options{
availableport.WithRandomizer(rand.New(rand.NewSource(2023))),
availableport.WithMinPort(100),
availableport.WithMaxPort(200),
},
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/chaincmd/runner/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (r Runner) Export(ctx context.Context, exportedFile string) error {
}

// Save the new state
return os.WriteFile(exportedFile, exportedState, 0o644)
return os.WriteFile(exportedFile, exportedState, 0o600)
}

// EventSelector is used to query events.
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/checksum/checksum.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Sum(dirPath, outPath string) error {
}
}

return os.WriteFile(outPath, b.Bytes(), 0o666)
return os.WriteFile(outPath, b.Bytes(), 0o600)
}

// Binary returns SHA256 hash of executable file, file is searched by name in PATH.
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cmdrunner/cmdrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ func (r *Runner) newCommand(step *step.Step) Executor {
}

// Initialize command
command := exec.Command(step.Exec.Command, step.Exec.Args...)
command := exec.Command(step.Exec.Command, step.Exec.Args...) //nolint:gosec
command.Stdout = stdout
command.Stderr = stderr
command.Dir = dir
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosgen/generate_openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (g *generator) generateOpenAPISpec(ctx context.Context) error {

if !errors.Is(err, cache.ErrorNotFound) {
specPath := filepath.Join(dir, specFilename)
if err := os.WriteFile(specPath, existingSpec, 0o644); err != nil {
if err := os.WriteFile(specPath, existingSpec, 0o600); err != nil {
return err
}
return conf.AddSpec(name, specPath, true)
Expand Down
2 changes: 1 addition & 1 deletion ignite/pkg/cosmosgen/sta.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ return createCustomOperationId(method, route, moduleName);
// generateRouteNameFile generates the `route-name.eta` file.
func generateRouteNameFile(outPath string) error {
outTemplate := filepath.Join(outPath, "route-name.eta")
return os.WriteFile(outTemplate, []byte(routeNameTemplate), 0o644)
return os.WriteFile(outTemplate, []byte(routeNameTemplate), 0o600)
}
10 changes: 5 additions & 5 deletions ignite/pkg/dircache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,39 @@ func Test_cacheKey(t *testing.T) {
args: args{
src: wd,
},
want: "78f544d2184b8076ac527ba4728822de1a7fc77bf2d6a77e44d0193cb63ed26e",
want: "4cf0539ac24f8ebc9ee17b81d0ea880e55d2ba98a4e355affe3c3f8a0cdb01ee",
},
{
name: "one key",
args: args{
src: wd,
keys: []string{"test"},
},
want: "5701099a1fcc67cd8b694295fbdecf537edcc8733bcc3adae0bdd7e65e28c8e5",
want: "dc7b4e68b7b9d827b3833845202818a11a1105542a3551052c012d815a64e7ae",
},
{
name: "two keys",
args: args{
src: wd,
keys: []string{"test1", "test2"},
},
want: "6299c9bd405a1c073fa711006f8aadf6420cf522ef446e36fc01586354726095",
want: "a017b975dd0a30efc7fbc515af9b3c37657c20a509fd5771111d4c0e43d373b0",
},
{
name: "duplicated keys",
args: args{
src: wd,
keys: []string{"test", "test"},
},
want: "b9eb1b01931deccc44a354ab5aeb52337a465e5559069eb35b71ea0cbfe3c87f",
want: "26ce20a6c4563963fd646121948cd62137a143317c970a52a3ec8ed9979c868d",
},
{
name: "many keys",
args: args{
src: wd,
keys: []string{"test1", "test2", "test3", "test4", "test5", "test6", "test6"},
},
want: "bbe74cfd33ba4d1244e8d0ea3e430081d06ed55be12c7772d345d3117a4dfc90",
want: "f9cd1468363ff902bdd5a93c9c7c43c83c9074796486306a7da046a082314121",
},
{
name: "invalid source",
Expand Down
4 changes: 2 additions & 2 deletions ignite/pkg/dirchange/dirchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package dirchange

import (
"bytes"
"crypto/md5"
"crypto/sha256"
"os"
"path/filepath"

Expand Down Expand Up @@ -60,7 +60,7 @@ func HasDirChecksumChanged(checksumCache cache.Cache[[]byte], cacheKey string, w
// ChecksumFromPaths computes the md5 checksum from the provided paths.
// Relative paths to the workdir are used. If workdir is empty, string paths are absolute.
func ChecksumFromPaths(workdir string, paths ...string) ([]byte, error) {
hash := md5.New()
hash := sha256.New()

// Can't compute hash if no file present
noFile := true
Expand Down
Loading

0 comments on commit b0828f2

Please sign in to comment.