Skip to content

Commit 19921cb

Browse files
committed
Add CBOR decoder unit test that accepts tag 55799.
Tag 55799 (self-described CBOR) imparts no special semantics on the item it encloses. The CBOR encoder always encloses its output in this tag so that the prefix 0xd9d9f7 can be used to mechanically distinguish encoded CBOR from encoded JSON, and the decoder must be able to accept any sequence of bytes that the encoder can produce.
1 parent f75d8e9 commit 19921cb

File tree

1 file changed

+18
-0
lines changed
  • staging/src/k8s.io/apimachinery/pkg/runtime/serializer/cbor

1 file changed

+18
-0
lines changed

staging/src/k8s.io/apimachinery/pkg/runtime/serializer/cbor/cbor_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,24 @@ func TestDecode(t *testing.T) {
181181
expectedGVK *schema.GroupVersionKind
182182
assertOnError func(*testing.T, error)
183183
}{
184+
{
185+
name: "self-described cbor tag accepted",
186+
data: []byte("\xd9\xd9\xf7\xa3\x4aapiVersion\x41v\x44kind\x41k\x48metadata\xa1\x44name\x43foo"), // 55799({'apiVersion': 'v', 'kind': 'k', 'metadata': {'name': 'foo'}})
187+
gvk: &schema.GroupVersionKind{},
188+
metaFactory: &defaultMetaFactory{},
189+
typer: stubTyper{gvks: []schema.GroupVersionKind{{Version: "v", Kind: "k"}}},
190+
into: &metav1.PartialObjectMetadata{},
191+
expectedObj: &metav1.PartialObjectMetadata{
192+
TypeMeta: metav1.TypeMeta{APIVersion: "v", Kind: "k"},
193+
ObjectMeta: metav1.ObjectMeta{Name: "foo"},
194+
},
195+
expectedGVK: &schema.GroupVersionKind{Version: "v", Kind: "k"},
196+
assertOnError: func(t *testing.T, err error) {
197+
if err != nil {
198+
t.Errorf("expected nil error, got: %v", err)
199+
}
200+
},
201+
},
184202
{
185203
name: "error determining gvk",
186204
metaFactory: stubMetaFactory{err: errors.New("test")},

0 commit comments

Comments
 (0)