mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-12-24 06:59:40 -05:00
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
|
/*
|
||
|
Copyright (c) Edgeless Systems GmbH
|
||
|
|
||
|
SPDX-License-Identifier: AGPL-3.0-only
|
||
|
*/
|
||
|
package router
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/assert"
|
||
|
)
|
||
|
|
||
|
func TestValidateContentMD5(t *testing.T) {
|
||
|
tests := map[string]struct {
|
||
|
contentMD5 string
|
||
|
body []byte
|
||
|
expectedErrMsg string
|
||
|
}{
|
||
|
"empty content-md5": {
|
||
|
contentMD5: "",
|
||
|
body: []byte("hello, world"),
|
||
|
},
|
||
|
// https://datatracker.ietf.org/doc/html/rfc1864#section-2
|
||
|
"valid content-md5": {
|
||
|
contentMD5: "Q2hlY2sgSW50ZWdyaXR5IQ==",
|
||
|
body: []byte("Check Integrity!"),
|
||
|
},
|
||
|
"invalid content-md5": {
|
||
|
contentMD5: "invalid base64",
|
||
|
body: []byte("hello, world"),
|
||
|
expectedErrMsg: "decoding base64",
|
||
|
},
|
||
|
}
|
||
|
|
||
|
// Iterate over the test cases
|
||
|
for name, tc := range tests {
|
||
|
t.Run(name, func(t *testing.T) {
|
||
|
// Call the validateContentMD5 function
|
||
|
err := validateContentMD5(tc.contentMD5, tc.body)
|
||
|
|
||
|
// Check the result against the expected value
|
||
|
if tc.expectedErrMsg != "" {
|
||
|
assert.ErrorContains(t, err, tc.expectedErrMsg)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|