mirror of
https://github.com/empayre/fleet.git
synced 2024-11-06 17:05:18 +00:00
12b79d5e46
Part of #10213 this will be used to do various validations in the provided bootstrap package.
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)
|
|
}
|
|
}
|
|
}
|