Skip to content

Commit

Permalink
Add tests for the IsCrypt4ghFile() function
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtamm committed Aug 6, 2024
1 parent 5097d81 commit 6d3dc37
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions storage/crypt4gh/decrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"crypto/rand"
"encoding/binary"
"io"
"os"
"path"
"testing"

"golang.org/x/crypto/blake2b"
Expand All @@ -22,6 +24,24 @@ Third line
// Holds the key-pair for encrypting/decrypting the content
var c4gh, _ = KeyPairFromFiles("testdata/key.pub", "testdata/key.plain.sec", nil)

// Verifies the IsCrypt4ghFile() function.
func TestIsCrypt4ghFile(t *testing.T) {
tempDir := t.TempDir()
correctFile := path.Join(tempDir, "correct.c4gh")

if err := os.WriteFile(correctFile, encryptContent(0, -1).Bytes(), 0600); err != nil {
t.Error("Failed to create a test-file")
}

if !IsCrypt4ghFile(correctFile) {
t.Error("Failed to recognise the correct Crypt4gh file as valid")
}

if IsCrypt4ghFile(path.Join(tempDir, "unknown.c4gh")) {
t.Error("Failed to recognise a non-existent Crypt4gh file as invalid")
}
}

// Encrypts test-data in memory (as it would be in a Crypt4gh file) and then decrypts the content.
// No edit-list used.
func TestDecryptFullText(t *testing.T) {
Expand Down

0 comments on commit 6d3dc37

Please sign in to comment.