Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase headers type validation coverage #89

Merged
merged 2 commits into from
Jul 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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