versia-go/pkg/versia/crypto/federation_headers_test.go

33 lines
855 B
Go
Raw Normal View History

2024-08-22 23:03:38 +02:00
package versiacrypto
2024-08-15 19:22:17 +02:00
import (
"net/http"
2024-08-15 19:22:17 +02:00
"net/url"
"testing"
2024-09-02 15:46:32 +02:00
"github.com/stretchr/testify/assert"
2024-08-15 19:22:17 +02:00
)
func TestFederationHeaders_String(t *testing.T) {
one := SignatureData{
RequestMethod: "POST",
Nonce: "1234567890",
URL: &url.URL{Scheme: "https", Host: "bob.com", Path: "/users/bob", RawQuery: "z=foo&a=bar"},
2024-09-02 15:46:32 +02:00
Digest: SHA256([]byte("hello")),
2024-08-15 19:22:17 +02:00
}
assert.Equal(t, "post /users/bob?z=foo&a=bar 1234567890 LPJNul+wow4m6DsqxbninhsWHlwfp0JecwQzYpOLmCQ=", one.String())
}
func TestFederationHeaders_Headers(t *testing.T) {
headers, err := ExtractFederationHeaders(http.Header{
"X-Signed-By": []string{"instance"},
"X-Nonce": []string{"11"},
"X-Signature": []string{"Cg=="},
})
assert.NoError(t, err)
assert.Nil(t, headers.SignedBy, "the SignedBy field should be nil when the signer is the instance")
}