-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsynocrypto_decrypter_test.go
More file actions
52 lines (44 loc) · 1.39 KB
/
synocrypto_decrypter_test.go
File metadata and controls
52 lines (44 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package synocrypto
import (
"bytes"
"fmt"
"io/ioutil"
"testing"
"github.com/maxlaverse/synocrypto/testdata"
"github.com/stretchr/testify/assert"
)
func TestDecryptingFiles(t *testing.T) {
testCases := []struct {
givenFilepath string
givenPassword string
givenPrivateKey string
expectedMetadata string
}{
{"testdata/Mark.Twain-Tom.Sawyer.txt", testdata.FixturePassword, "", "24bde34ecb5632ac6637325e8a334a9c"},
{"testdata/Mark.Twain-Tom.Sawyer.txt", "", testdata.FixturePrivateKey, "24bde34ecb5632ac6637325e8a334a9c"},
}
for _, tc := range testCases {
t.Run("", func(t *testing.T) {
inputData, err := ioutil.ReadFile(fmt.Sprintf("%s.enc", tc.givenFilepath))
if !assert.NoError(t, err) {
t.Fatal("unable to read file used for testing")
}
expectedOutputData, err := ioutil.ReadFile(tc.givenFilepath)
if !assert.NoError(t, err) {
t.Fatal("unable to read file used for testing")
}
opts := DecrypterOptions{
Password: tc.givenPassword,
PrivateKey: []byte(tc.givenPrivateKey),
}
var outputDecrypted bytes.Buffer
d := NewDecrypter(opts)
err = d.Decrypt(bytes.NewReader(inputData), &outputDecrypted)
assert.NoError(t, err)
assert.Equal(t, expectedOutputData, outputDecrypted.Bytes())
metadata, err := d.Metadata(bytes.NewReader(inputData))
assert.NoError(t, err)
assert.Equal(t, tc.expectedMetadata, metadata["file_md5"])
})
}
}