Skip to content

Commit 4d85fd3

Browse files
authored
Merge pull request #1780 from felixfontein/lint
Lint
2 parents f6bc6df + df8432b commit 4d85fd3

7 files changed

Lines changed: 16 additions & 30 deletions

File tree

age/keysource_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -521,8 +521,9 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
521521
t.Setenv(SopsAgeKeyEnv, mockEncryptedIdentity)
522522
//blocks calling gpg-agent
523523
os.Unsetenv("XDG_RUNTIME_DIR")
524-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
524+
testOnlyAgePassword = mockIdentityPassphrase
525525
got, err := key.Decrypt()
526+
testOnlyAgePassword = ""
526527

527528
assert.NoError(t, err)
528529
assert.EqualValues(t, mockEncryptedKeyPlain, got)
@@ -540,9 +541,11 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
540541
t.Setenv(SopsAgeKeyFileEnv, keyPath)
541542
//blocks calling gpg-agent
542543
os.Unsetenv("XDG_RUNTIME_DIR")
543-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
544+
testOnlyAgePassword = mockIdentityPassphrase
544545

545546
got, err := key.Decrypt()
547+
testOnlyAgePassword = ""
548+
546549
assert.NoError(t, err)
547550
assert.EqualValues(t, mockEncryptedKeyPlain, got)
548551
})
@@ -552,9 +555,11 @@ func TestMasterKey_Identities_Passphrase(t *testing.T) {
552555
t.Setenv(SopsAgeKeyEnv, mockEncryptedIdentity)
553556
//blocks calling gpg-agent
554557
os.Unsetenv("XDG_RUNTIME_DIR")
555-
t.Setenv(SopsAgePasswordEnv, mockIdentityPassphrase)
558+
testOnlyAgePassword = mockIdentityPassphrase
556559

557560
got, err := key.Decrypt()
561+
testOnlyAgePassword = ""
562+
558563
assert.Error(t, err)
559564
assert.ErrorContains(t, err, "failed to create reader for decrypting sops data key with age")
560565
assert.Nil(t, got)

age/tui.go

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ import (
2222
"golang.org/x/term"
2323
)
2424

25-
const (
26-
SopsAgePasswordEnv = "SOPS_AGE_PASSWORD"
27-
)
25+
var testOnlyAgePassword string
2826

2927
func printf(format string, v ...interface{}) {
3028
log.Printf("age: "+format, v...)
@@ -34,20 +32,6 @@ func warningf(format string, v ...interface{}) {
3432
log.Printf("age: warning: "+format, v...)
3533
}
3634

37-
// If testOnlyPanicInsteadOfExit is true, exit will set testOnlyDidExit and
38-
// panic instead of calling os.Exit. This way, the wrapper in TestMain can
39-
// recover the panic and return the exit code only if it was originated in exit.
40-
var testOnlyPanicInsteadOfExit bool
41-
var testOnlyDidExit bool
42-
43-
func exit(code int) {
44-
if testOnlyPanicInsteadOfExit {
45-
testOnlyDidExit = true
46-
panic(code)
47-
}
48-
os.Exit(code)
49-
}
50-
5135
// clearLine clears the current line on the terminal, or opens a new line if
5236
// terminal escape codes don't work.
5337
func clearLine(out io.Writer) {
@@ -96,9 +80,8 @@ func withTerminal(f func(in, out *os.File) error) error {
9680
// readSecret reads a value from the terminal with no echo. The prompt is ephemeral.
9781
func readSecret(prompt string) (s []byte, err error) {
9882
if testing.Testing() {
99-
password := os.Getenv(SopsAgePasswordEnv)
100-
if password != "" {
101-
return []byte(password), nil
83+
if testOnlyAgePassword != "" {
84+
return []byte(testOnlyAgePassword), nil
10285
}
10386
}
10487

azkv/keysource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func NewMasterKeyFromURL(url string) (*MasterKey, error) {
7979
url = strings.TrimSpace(url)
8080
re := regexp.MustCompile("^(https://[^/]+)/keys/([^/]+)/([^/]+)$")
8181
parts := re.FindStringSubmatch(url)
82-
if parts == nil || len(parts) < 3 {
82+
if len(parts) < 3 {
8383
return nil, fmt.Errorf("could not parse %q into a valid Azure Key Vault MasterKey", url)
8484
}
8585
return NewMasterKey(parts[1], parts[2], parts[3]), nil

cmd/sops/common/common.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func GetKMSKeyWithEncryptionCtx(tree *sops.Tree) (keyGroupIndex int, keyIndex in
222222
for n, k := range kg {
223223
kmsKey, ok := k.(*kms.MasterKey)
224224
if ok {
225-
if kmsKey.EncryptionContext != nil && len(kmsKey.EncryptionContext) >= 2 {
225+
if len(kmsKey.EncryptionContext) >= 2 {
226226
duplicateValues := map[string]int{}
227227
for _, v := range kmsKey.EncryptionContext {
228228
duplicateValues[*v] = duplicateValues[*v] + 1

cmd/sops/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2150,7 +2150,7 @@ func keyservices(c *cli.Context) (svcs []keyservice.KeyServiceClient) {
21502150
"address",
21512151
fmt.Sprintf("%s://%s", url.Scheme, addr),
21522152
).Infof("Connecting to key service")
2153-
conn, err := grpc.Dial(addr, opts...)
2153+
conn, err := grpc.NewClient(addr, opts...)
21542154
if err != nil {
21552155
log.Fatalf("failed to listen: %v", err)
21562156
}
@@ -2283,7 +2283,7 @@ func keyGroups(c *cli.Context, file string) ([]sops.KeyGroup, error) {
22832283
if err != nil {
22842284
errMsg = fmt.Sprintf("%s: %s", errMsg, err)
22852285
}
2286-
return nil, fmt.Errorf(errMsg)
2286+
return nil, fmt.Errorf("%s", errMsg)
22872287
}
22882288
return conf.KeyGroups, err
22892289
}

gcpkms/keysource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func newGRPCServer(port string) *grpc.ClientConn {
159159
}
160160
go serv.Serve(lis)
161161

162-
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
162+
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
163163
if err != nil {
164164
log.Fatal(err)
165165
}

shamir/shamir.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"crypto/subtle"
1616
"fmt"
1717
mathrand "math/rand"
18-
"time"
1918
)
2019

2120
const (
@@ -190,7 +189,6 @@ func Split(secret []byte, parts, threshold int) ([][]byte, error) {
190189
// a non-cryptographically secure source of randomness is used.
191190
// As far as I know the x coordinates do not need to be random.
192191

193-
mathrand.Seed(time.Now().UnixNano())
194192
xCoordinates := mathrand.Perm(255)
195193

196194
// Allocate the output array, initialize the final byte

0 commit comments

Comments
 (0)