Skip to content

Commit

Permalink
[decrypt_test] Fix windows test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jbygdell committed Dec 18, 2023
1 parent 0f54827 commit 08458f4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions decrypt/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"os"
"path/filepath"
"runtime"
"testing"

createKey "github.com/NBISweden/sda-cli/create_key"
Expand Down Expand Up @@ -97,8 +98,12 @@ func (suite *DecryptTests) Testdecrypt() {
assert.NoError(suite.T(), err)

// Test decrypting a non-existent file
msg := "no such file or directory"
if runtime.GOOS == "windows" {
msg = "open somekey: The system cannot find the file specified."
}
err = decryptFile(filepath.Join(suite.tempDir, "non-existent"), "output_file", *privateKey)
assert.ErrorContains(suite.T(), err, "no such file or directory")
assert.ErrorContains(suite.T(), err, msg)

// Test decryption with malformed key
fakeKey := [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
Expand Down Expand Up @@ -131,7 +136,7 @@ func (suite *DecryptTests) TestDecrypt() {
encryptArgs := []string{"encrypt", "-key", fmt.Sprintf("%s.pub.pem", testKeyFile), suite.testFile.Name()}
assert.NoError(suite.T(), encrypt.Encrypt(encryptArgs), "encrypting file for testing failed")
assert.NoError(suite.T(), os.Chdir(cwd))
assert.NoError(suite.T(), os.Remove(suite.testFile.Name()))
assert.NoError(suite.T(), os.Rename(suite.testFile.Name(), filepath.Join(suite.tempDir, "fuu")))

os.Setenv("C4GH_PASSWORD", "")
os.Args = []string{"decrypt", "-key", fmt.Sprintf("%s.sec.pem", testKeyFile), fmt.Sprintf("%s.c4gh", suite.testFile.Name())}
Expand Down

0 comments on commit 08458f4

Please sign in to comment.