mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-06 13:43:09 -06:00
Merge branch 'main' into s7evink/migrate
This commit is contained in:
commit
4b4d4a0eb5
|
|
@ -102,8 +102,7 @@ type userInteractiveFlow struct {
|
||||||
// the user already has a valid access token, but we want to double-check
|
// the user already has a valid access token, but we want to double-check
|
||||||
// that it isn't stolen by re-authenticating them.
|
// that it isn't stolen by re-authenticating them.
|
||||||
type UserInteractive struct {
|
type UserInteractive struct {
|
||||||
Completed []string
|
Flows []userInteractiveFlow
|
||||||
Flows []userInteractiveFlow
|
|
||||||
// Map of login type to implementation
|
// Map of login type to implementation
|
||||||
Types map[string]Type
|
Types map[string]Type
|
||||||
// Map of session ID to completed login types, will need to be extended in future
|
// Map of session ID to completed login types, will need to be extended in future
|
||||||
|
|
@ -116,7 +115,6 @@ func NewUserInteractive(userAccountAPI api.UserLoginAPI, cfg *config.ClientAPI)
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
}
|
}
|
||||||
return &UserInteractive{
|
return &UserInteractive{
|
||||||
Completed: []string{},
|
|
||||||
Flows: []userInteractiveFlow{
|
Flows: []userInteractiveFlow{
|
||||||
{
|
{
|
||||||
Stages: []string{typePassword.Name()},
|
Stages: []string{typePassword.Name()},
|
||||||
|
|
@ -140,7 +138,6 @@ func (u *UserInteractive) IsSingleStageFlow(authType string) bool {
|
||||||
|
|
||||||
func (u *UserInteractive) AddCompletedStage(sessionID, authType string) {
|
func (u *UserInteractive) AddCompletedStage(sessionID, authType string) {
|
||||||
// TODO: Handle multi-stage flows
|
// TODO: Handle multi-stage flows
|
||||||
u.Completed = append(u.Completed, authType)
|
|
||||||
delete(u.Sessions, sessionID)
|
delete(u.Sessions, sessionID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,7 +154,7 @@ func (u *UserInteractive) Challenge(sessionID string) *util.JSONResponse {
|
||||||
return &util.JSONResponse{
|
return &util.JSONResponse{
|
||||||
Code: 401,
|
Code: 401,
|
||||||
JSON: Challenge{
|
JSON: Challenge{
|
||||||
Completed: u.Completed,
|
Completed: u.Sessions[sessionID],
|
||||||
Flows: u.Flows,
|
Flows: u.Flows,
|
||||||
Session: sessionID,
|
Session: sessionID,
|
||||||
Params: make(map[string]interface{}),
|
Params: make(map[string]interface{}),
|
||||||
|
|
|
||||||
|
|
@ -187,3 +187,38 @@ func TestUserInteractivePasswordBadLogin(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestUserInteractive_AddCompletedStage(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
sessionID string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "first user",
|
||||||
|
sessionID: util.RandomString(8),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "second user",
|
||||||
|
sessionID: util.RandomString(8),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "third user",
|
||||||
|
sessionID: util.RandomString(8),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
u := setup()
|
||||||
|
ctx := context.Background()
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
_, resp := u.Verify(ctx, []byte("{}"), nil)
|
||||||
|
challenge, ok := resp.JSON.(Challenge)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected a Challenge, got %T", resp.JSON)
|
||||||
|
}
|
||||||
|
if len(challenge.Completed) > 0 {
|
||||||
|
t.Fatalf("expected 0 completed stages, got %d", len(challenge.Completed))
|
||||||
|
}
|
||||||
|
u.AddCompletedStage(tt.sessionID, "")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -55,60 +55,62 @@ var servers = map[string]*server{
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// Set up the server key API for each "server" that we
|
// Set up the server key API for each "server" that we
|
||||||
// will use in our tests.
|
// will use in our tests.
|
||||||
for _, s := range servers {
|
os.Exit(func() int {
|
||||||
// Generate a new key.
|
for _, s := range servers {
|
||||||
_, testPriv, err := ed25519.GenerateKey(nil)
|
// Generate a new key.
|
||||||
if err != nil {
|
_, testPriv, err := ed25519.GenerateKey(nil)
|
||||||
panic("can't generate identity key: " + err.Error())
|
if err != nil {
|
||||||
|
panic("can't generate identity key: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a new cache but don't enable prometheus!
|
||||||
|
s.cache, err = caching.NewInMemoryLRUCache(false)
|
||||||
|
if err != nil {
|
||||||
|
panic("can't create cache: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a temporary directory for JetStream.
|
||||||
|
d, err := ioutil.TempDir("./", "jetstream*")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(d)
|
||||||
|
|
||||||
|
// Draw up just enough Dendrite config for the server key
|
||||||
|
// API to work.
|
||||||
|
cfg := &config.Dendrite{}
|
||||||
|
cfg.Defaults(true)
|
||||||
|
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
|
||||||
|
cfg.Global.PrivateKey = testPriv
|
||||||
|
cfg.Global.JetStream.InMemory = true
|
||||||
|
cfg.Global.JetStream.TopicPrefix = string(s.name[:1])
|
||||||
|
cfg.Global.JetStream.StoragePath = config.Path(d)
|
||||||
|
cfg.Global.KeyID = serverKeyID
|
||||||
|
cfg.Global.KeyValidityPeriod = s.validity
|
||||||
|
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
||||||
|
s.config = &cfg.FederationAPI
|
||||||
|
|
||||||
|
// Create a transport which redirects federation requests to
|
||||||
|
// the mock round tripper. Since we're not *really* listening for
|
||||||
|
// federation requests then this will return the key instead.
|
||||||
|
transport := &http.Transport{}
|
||||||
|
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
||||||
|
|
||||||
|
// Create the federation client.
|
||||||
|
s.fedclient = gomatrixserverlib.NewFederationClient(
|
||||||
|
s.config.Matrix.ServerName, serverKeyID, testPriv,
|
||||||
|
gomatrixserverlib.WithTransport(transport),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Finally, build the server key APIs.
|
||||||
|
sbase := base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
|
||||||
|
s.api = NewInternalAPI(sbase, s.fedclient, nil, s.cache, nil, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new cache but don't enable prometheus!
|
// Now that we have built our server key APIs, start the
|
||||||
s.cache, err = caching.NewInMemoryLRUCache(false)
|
// rest of the tests.
|
||||||
if err != nil {
|
return m.Run()
|
||||||
panic("can't create cache: " + err.Error())
|
}())
|
||||||
}
|
|
||||||
|
|
||||||
// Create a temporary directory for JetStream.
|
|
||||||
d, err := ioutil.TempDir("./", "jetstream*")
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
defer os.RemoveAll(d)
|
|
||||||
|
|
||||||
// Draw up just enough Dendrite config for the server key
|
|
||||||
// API to work.
|
|
||||||
cfg := &config.Dendrite{}
|
|
||||||
cfg.Defaults(true)
|
|
||||||
cfg.Global.ServerName = gomatrixserverlib.ServerName(s.name)
|
|
||||||
cfg.Global.PrivateKey = testPriv
|
|
||||||
cfg.Global.JetStream.InMemory = true
|
|
||||||
cfg.Global.JetStream.TopicPrefix = string(s.name[:1])
|
|
||||||
cfg.Global.JetStream.StoragePath = config.Path(d)
|
|
||||||
cfg.Global.KeyID = serverKeyID
|
|
||||||
cfg.Global.KeyValidityPeriod = s.validity
|
|
||||||
cfg.FederationAPI.Database.ConnectionString = config.DataSource("file::memory:")
|
|
||||||
s.config = &cfg.FederationAPI
|
|
||||||
|
|
||||||
// Create a transport which redirects federation requests to
|
|
||||||
// the mock round tripper. Since we're not *really* listening for
|
|
||||||
// federation requests then this will return the key instead.
|
|
||||||
transport := &http.Transport{}
|
|
||||||
transport.RegisterProtocol("matrix", &MockRoundTripper{})
|
|
||||||
|
|
||||||
// Create the federation client.
|
|
||||||
s.fedclient = gomatrixserverlib.NewFederationClient(
|
|
||||||
s.config.Matrix.ServerName, serverKeyID, testPriv,
|
|
||||||
gomatrixserverlib.WithTransport(transport),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Finally, build the server key APIs.
|
|
||||||
sbase := base.NewBaseDendrite(cfg, "Monolith", base.DisableMetrics)
|
|
||||||
s.api = NewInternalAPI(sbase, s.fedclient, nil, s.cache, nil, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Now that we have built our server key APIs, start the
|
|
||||||
// rest of the tests.
|
|
||||||
os.Exit(m.Run())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type MockRoundTripper struct{}
|
type MockRoundTripper struct{}
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,8 @@ func (r *FederationInternalAPI) performJoinUsingServer(
|
||||||
if content == nil {
|
if content == nil {
|
||||||
content = map[string]interface{}{}
|
content = map[string]interface{}{}
|
||||||
}
|
}
|
||||||
content["membership"] = "join"
|
_ = json.Unmarshal(respMakeJoin.JoinEvent.Content, &content)
|
||||||
|
content["membership"] = gomatrixserverlib.Join
|
||||||
if err = respMakeJoin.JoinEvent.SetContent(content); err != nil {
|
if err = respMakeJoin.JoinEvent.SetContent(content); err != nil {
|
||||||
return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err)
|
return fmt.Errorf("respMakeJoin.JoinEvent.SetContent: %w", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -30,7 +30,7 @@ require (
|
||||||
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
github.com/matrix-org/dugong v0.0.0-20210921133753-66e6b1c67e2e
|
||||||
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
|
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20220513103617-eee8fd528433
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20220523164922-dfd9bd7c03fb
|
||||||
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48
|
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48
|
||||||
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
github.com/matrix-org/util v0.0.0-20200807132607-55161520e1d4
|
||||||
github.com/mattn/go-sqlite3 v1.14.10
|
github.com/mattn/go-sqlite3 v1.14.10
|
||||||
|
|
|
||||||
4
go.sum
4
go.sum
|
|
@ -795,8 +795,8 @@ github.com/matrix-org/go-sqlite3-js v0.0.0-20220419092513-28aa791a1c91/go.mod h1
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
github.com/matrix-org/gomatrix v0.0.0-20190528120928-7df988a63f26/go.mod h1:3fxX6gUjWyI/2Bt7J1OLhpCzOfO/bB3AiX0cJtEKud0=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
|
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16 h1:ZtO5uywdd5dLDCud4r0r55eP4j9FuUNpl60Gmntcop4=
|
||||||
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
github.com/matrix-org/gomatrix v0.0.0-20210324163249-be2af5ef2e16/go.mod h1:/gBX06Kw0exX1HrwmoBibFA98yBk/jxKpGVeyQbff+s=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20220513103617-eee8fd528433 h1:nwAlThHGPI2EAAJklXvgMcdhXF6ZiHp60+fmaYMoaDA=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20220523164922-dfd9bd7c03fb h1:MRhaR1IKYdizM2vECOcJlleExLEwy4KAvQ6v73QQRnA=
|
||||||
github.com/matrix-org/gomatrixserverlib v0.0.0-20220513103617-eee8fd528433/go.mod h1:V5eO8rn/C3rcxig37A/BCeKerLFS+9Avg/77FIeTZ48=
|
github.com/matrix-org/gomatrixserverlib v0.0.0-20220523164922-dfd9bd7c03fb/go.mod h1:V5eO8rn/C3rcxig37A/BCeKerLFS+9Avg/77FIeTZ48=
|
||||||
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48 h1:W0sjjC6yjskHX4mb0nk3p0fXAlbU5bAFUFeEtlrPASE=
|
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48 h1:W0sjjC6yjskHX4mb0nk3p0fXAlbU5bAFUFeEtlrPASE=
|
||||||
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48/go.mod h1:ulJzsVOTssIVp1j/m5eI//4VpAGDkMt5NrRuAVX7wpc=
|
github.com/matrix-org/pinecone v0.0.0-20220408153826-2999ea29ed48/go.mod h1:ulJzsVOTssIVp1j/m5eI//4VpAGDkMt5NrRuAVX7wpc=
|
||||||
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7/go.mod h1:vVQlW/emklohkZnOPwD3LrZUBqdfsbiyO3p1lNV8F6U=
|
github.com/matrix-org/util v0.0.0-20190711121626-527ce5ddefc7/go.mod h1:vVQlW/emklohkZnOPwD3LrZUBqdfsbiyO3p1lNV8F6U=
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue