Fix server key API test

This commit is contained in:
Neil Alexander 2020-06-16 12:20:33 +01:00
parent 5e609796c9
commit 20bf0ed242

View file

@ -13,6 +13,7 @@ import (
"testing" "testing"
"time" "time"
"github.com/matrix-org/dendrite/federationapi/routing"
"github.com/matrix-org/dendrite/internal/caching" "github.com/matrix-org/dendrite/internal/caching"
"github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/internal/config"
"github.com/matrix-org/dendrite/serverkeyapi/api" "github.com/matrix-org/dendrite/serverkeyapi/api"
@ -72,7 +73,8 @@ func TestMain(m *testing.M) {
s.config.SetDefaults() s.config.SetDefaults()
s.config.Matrix.ServerName = gomatrixserverlib.ServerName(s.name) s.config.Matrix.ServerName = gomatrixserverlib.ServerName(s.name)
s.config.Matrix.PrivateKey = testPriv s.config.Matrix.PrivateKey = testPriv
s.config.Matrix.KeyID = "ed25519:test" s.config.Matrix.KeyID = serverKeyID
s.config.Matrix.KeyValidityPeriod = s.validity
s.config.Database.ServerKey = config.DataSource("file::memory:") s.config.Database.ServerKey = config.DataSource("file::memory:")
// Create a transport which redirects federation requests to // Create a transport which redirects federation requests to
@ -83,7 +85,7 @@ func TestMain(m *testing.M) {
// Create the federation client. // Create the federation client.
s.fedclient = gomatrixserverlib.NewFederationClientWithTransport( s.fedclient = gomatrixserverlib.NewFederationClientWithTransport(
s.config.Matrix.ServerName, "ed25519:test", testPriv, transport, s.config.Matrix.ServerName, serverKeyID, testPriv, transport,
) )
// Finally, build the server key APIs. // Finally, build the server key APIs.
@ -112,15 +114,9 @@ func (m *MockRoundTripper) RoundTrip(req *http.Request) (res *http.Response, err
return nil, fmt.Errorf("unexpected request path: %s", req.URL.Path) return nil, fmt.Errorf("unexpected request path: %s", req.URL.Path)
} }
// Query the local keys for the server in question. // Get the keys and JSON-ify them.
request := &api.QueryLocalKeysRequest{} keys := routing.LocalKeys(s.config)
response := &api.QueryLocalKeysResponse{} body, err := json.MarshalIndent(keys.JSON, "", " ")
if err = s.api.QueryLocalKeys(context.Background(), request, response); err != nil {
return nil, err
}
// Make a nice JSON response out of it.
body, err := json.MarshalIndent(response.ServerKeys, "", " ")
if err != nil { if err != nil {
return nil, err return nil, err
} }