Skip to content

Commit

Permalink
Merge pull request #89 from qmuntal/headers
Browse files Browse the repository at this point in the history
Increase headers type validation coverage
  • Loading branch information
SteveLasker committed Jul 11, 2022
2 parents 33ff2e9 + aea9b6b commit ebba05d
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,34 @@ func TestProtectedHeader_MarshalCBOR(t *testing.T) {
},
wantErr: true,
},
{
name: "content type is string",
h: ProtectedHeader{
HeaderLabelContentType: []byte("foo"),
},
wantErr: true,
},
{
name: "content type is negative int8",
h: ProtectedHeader{
HeaderLabelContentType: int8(-1),
},
wantErr: true,
},
{
name: "content type is negative int16",
h: ProtectedHeader{
HeaderLabelContentType: int16(-1),
},
wantErr: true,
},
{
name: "content type is negative int32",
h: ProtectedHeader{
HeaderLabelContentType: int32(-1),
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -800,7 +828,7 @@ func TestHeaders_MarshalUnprotected(t *testing.T) {
HeaderLabelAlgorithm: AlgorithmES256,
},
Unprotected: UnprotectedHeader{
HeaderLabelContentType: 42,
HeaderLabelContentType: uint8(42),
},
},
want: []byte{0xa1, 0x03, 0x18, 0x2a},
Expand Down Expand Up @@ -866,7 +894,7 @@ func TestHeaders_UnmarshalFromRaw(t *testing.T) {
},
RawUnprotected: []byte{0xa1, 0x04, 0x18, 0x2a},
Unprotected: UnprotectedHeader{
HeaderLabelContentType: 42,
HeaderLabelContentType: int8(42),
},
},
},
Expand All @@ -879,7 +907,7 @@ func TestHeaders_UnmarshalFromRaw(t *testing.T) {
},
RawUnprotected: []byte{0xa1, 0x03, 0x18, 0x2a},
Unprotected: UnprotectedHeader{
HeaderLabelContentType: 43,
HeaderLabelContentType: int16(43),
},
},
want: Headers{
Expand Down

0 comments on commit ebba05d

Please sign in to comment.