check / check (push) Waiting to run
Loading a manifest checked only the outer message's version, so an inner message of version 0 or a later version loaded as if it were version one, although docs/FORMAT.md requires VERSION_ONE in both. deserializeInner now refuses any other inner version with the same error as an unknown outer version. Two existing tests built inner messages with no version and expected them to load; they now write version one. Model: opus-5-5
55 lines
1.7 KiB
Go
55 lines
1.7 KiB
Go
//nolint:testpackage // white-box tests exercise unexported internals
|
|
package mfer
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"uuid"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
// An inner message whose version is not VERSION_ONE, whether version 0 or a
|
|
// later one, is refused with the same error as an outer message's.
|
|
func TestDeserializeRefusesUnknownInnerVersion(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
for _, version := range []MFFile_Version{MFFile_VERSION_NONE, MFFile_VERSION_ONE + 1} {
|
|
t.Run(version.String(), func(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
id := uuid.NewV4()
|
|
inner, err := proto.Marshal(&MFFile{Version: version, Uuid: id[:]})
|
|
require.NoError(t, err)
|
|
|
|
_, err = NewManifestFromReader(bytes.NewReader(wrapInner(t, id, inner)))
|
|
require.ErrorIs(t, err, errUnknownVersion)
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestReadAtMost gives readAtMost exactly its maximum, which it must
|
|
// return whole, and twice its maximum, which it must refuse after reading
|
|
// one byte past the maximum, and no more. NewManifestFromReader reads
|
|
// through it with MaxManifestSize; the test uses 64 KiB, since reading
|
|
// MaxManifestSize under the race detector takes gigabytes of memory.
|
|
func TestReadAtMost(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
const maxSize = 64 << 10
|
|
|
|
dat, err := readAtMost(bytes.NewReader(make([]byte, maxSize)), maxSize)
|
|
require.NoError(t, err)
|
|
assert.Len(t, dat, maxSize)
|
|
|
|
input := bytes.NewReader(make([]byte, 2*maxSize))
|
|
|
|
_, err = readAtMost(input, maxSize)
|
|
require.ErrorIs(t, err, errManifestTooLarge)
|
|
require.EqualError(t, err,
|
|
"manifest exceeds maximum allowed size of 65536 bytes")
|
|
assert.Equal(t, maxSize-1, input.Len(), "bytes left unread")
|
|
}
|