mirror of
https://github.com/empayre/fleet.git
synced 2024-11-07 01:15:22 +00:00
52 lines
868 B
Go
52 lines
868 B
Go
|
package file
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"errors"
|
||
|
"io"
|
||
|
"os"
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
)
|
||
|
|
||
|
func TestCheckPKGSignature(t *testing.T) {
|
||
|
read := func(name string) []byte {
|
||
|
b, err := os.ReadFile(name)
|
||
|
require.NoError(t, err)
|
||
|
return b
|
||
|
}
|
||
|
testCases := []struct {
|
||
|
in []byte
|
||
|
out error
|
||
|
}{
|
||
|
{in: []byte{}, out: io.EOF},
|
||
|
{
|
||
|
in: read("./testdata/invalid.tar.gz"),
|
||
|
out: ErrInvalidType,
|
||
|
},
|
||
|
{
|
||
|
in: read("./testdata/unsigned.pkg"),
|
||
|
out: ErrNotSigned,
|
||
|
},
|
||
|
{
|
||
|
in: read("./testdata/signed.pkg"),
|
||
|
out: nil,
|
||
|
},
|
||
|
{
|
||
|
out: errors.New("decompressing TOC: unexpected EOF"),
|
||
|
in: read("./testdata/wrong-toc.pkg"),
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, c := range testCases {
|
||
|
r := bytes.NewReader(c.in)
|
||
|
err := CheckPKGSignature(r)
|
||
|
if c.out != nil {
|
||
|
require.ErrorContains(t, err, c.out.Error())
|
||
|
} else {
|
||
|
require.NoError(t, err)
|
||
|
}
|
||
|
}
|
||
|
}
|