getsops/sops

Failing age tests after setting SOPS_AGE_KEY_FILE env var

rroctavian opened this issue · 0 comments

Issue description

The setup here is an aws ec2 instance with Ubuntu 22.04, amd64 with go1.21.5 and age v1.1.1 installed.

I ran make test after cloning the project with all tests successful. After installing sops from source and setting up age with SOPS_AGE_KEY_FILE, some of the tests in sops/age started complaining. This is with no source code modifications whatsoever.

Is it perhaps better if we temporarily muted/overwritten the SOPS_AGE_KEY_FILE environment variable at test time? The issue seems that a few tests do not expect to find an extra key. (See for example TestMasterKey_loadIdentities/SOPS_AGE_KEY and TestMasterKey_loadIdentities/SOPS_AGE_KEY_multiple attached.)

After removing SOPS_AGE_KEY_FILE env var entry from my .bashrc and rebooting the instance, I am again able to run the tests without any failures.

I look forward to hearing your thoughts on this and suggestions for what might be the best next step, if any at all.

Tests

Below, I replaced the secret keys (mine and the test keys in sops/age/keysource_test.go) as follows:

  • my_local_key for the secret key found in SOPS_AGE_KEY_FILE
  • mockIdentity_key for test key mockIdentity string = "AGE-SECRET-KEY-1G0Q5K9TV4REQ3ZSQRMTMG8NSWQGYT0T7TZ33RAZEE0GZYVZN0APSU24RK7"
  • mockOtherIdentity_key for test key mockOtherIdentity string = "AGE-SECRET-KEY-1432K5YRNSC44GC4986NXMX6GVZ52WTMT9C79CLUVWYY4DKDHD5JSNDP4MC"
--- FAIL: TestMasterKey_Decrypt (0.01s)
    --- FAIL: TestMasterKey_Decrypt/no_identities (0.00s)
        keysource_test.go:198: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:198
                Error:          Error "failed to create reader for decrypting sops data key with age: no identity matched any of the recipients" does not contain "failed to load age identities"
                Test:           TestMasterKey_Decrypt/no_identities
--- FAIL: TestMasterKey_loadIdentities (0.01s)
    --- FAIL: TestMasterKey_loadIdentities/SOPS_AGE_KEY (0.00s)
        keysource_test.go:280: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:280
                Error:          "[AGE-SECRET-KEY-**mockIdentity_key** AGE-SECRET-KEY-**my_local_key**]" should have 1 item(s), but has 2
                Test:           TestMasterKey_loadIdentities/SOPS_AGE_KEY
    --- FAIL: TestMasterKey_loadIdentities/SOPS_AGE_KEY_multiple (0.00s)
        keysource_test.go:293: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:293
                Error:          "[AGE-SECRET-KEY-**mockIdentity_key** AGE-SECRET-KEY-**mockOtherIdentity_key** AGE-SECRET-KEY-**my_local_key**]" should have 2 item(s), but has 3
                Test:           TestMasterKey_loadIdentities/SOPS_AGE_KEY_multiple
    --- FAIL: TestMasterKey_loadIdentities/sops/age/keys.txt (0.00s)
        keysource_test.go:327: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:327
                Error:          "[AGE-SECRET-KEY-**my_local_key** AGE-SECRET-KEY-**mockIdentity_key**]" should have 1 item(s), but has 2
                Test:           TestMasterKey_loadIdentities/sops/age/keys.txt
    --- FAIL: TestMasterKey_loadIdentities/no_identity (0.00s)
        keysource_test.go:335: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:335
                Error:          An error is expected but got nil.
                Test:           TestMasterKey_loadIdentities/no_identity
        keysource_test.go:336: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:336
                Error:          An error is expected but got nil.
                Test:           TestMasterKey_loadIdentities/no_identity
        keysource_test.go:337: 
                Error Trace:    /home/ubuntu/go/src/github.com/getsops/sops/age/keysource_test.go:337
                Error:          Expected nil, but got: age.ParsedIdentities{(*age.X25519Identity)(0xc000182a80)}
                Test:           TestMasterKey_loadIdentities/no_identity
FAIL
coverage: 83.3% of statements
FAIL    github.com/getsops/sops/v3/age  0.068s