mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-08-02 14:12:47 +00:00
Implement server notices (#2180)
* Add server_notices config * Disallow rejecting "server notice" invites * Update config * Slightly refactor sendEvent and CreateRoom so it can be reused * Implement unspecced server notices * Validate the request * Set the user api when starting * Rename function/variables * Update comments * Update config * Set the avatar on account creation * Update test * Only create the account when starting Only add routes if sever notices are enabled * Use reserver username Check that we actually got roomData * Add check for admin account Enable server notices for CI Return same values as Synapse * Add custom error for rejecting server notice invite * Move building an invite to it's own function, for reusability * Don't create new rooms, use the existing one (follow Synapse behavior) Co-authored-by: kegsay <kegan@matrix.org>
This commit is contained in:
parent
dbded87525
commit
002429c9e2
18 changed files with 689 additions and 82 deletions
83
clientapi/routing/server_notices_test.go
Normal file
83
clientapi/routing/server_notices_test.go
Normal file
|
@ -0,0 +1,83 @@
|
|||
package routing
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_sendServerNoticeRequest_validate(t *testing.T) {
|
||||
type fields struct {
|
||||
UserID string `json:"user_id,omitempty"`
|
||||
Content struct {
|
||||
MsgType string `json:"msgtype,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
} `json:"content,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
StateKey string `json:"state_key,omitempty"`
|
||||
}
|
||||
|
||||
content := struct {
|
||||
MsgType string `json:"msgtype,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
}{
|
||||
MsgType: "m.text",
|
||||
Body: "Hello world!",
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
wantOk bool
|
||||
}{
|
||||
{
|
||||
name: "empty request",
|
||||
fields: fields{},
|
||||
},
|
||||
{
|
||||
name: "msgtype empty",
|
||||
fields: fields{
|
||||
UserID: "@alice:localhost",
|
||||
Content: struct {
|
||||
MsgType string `json:"msgtype,omitempty"`
|
||||
Body string `json:"body,omitempty"`
|
||||
}{
|
||||
Body: "Hello world!",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "msg body empty",
|
||||
fields: fields{
|
||||
UserID: "@alice:localhost",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "statekey empty",
|
||||
fields: fields{
|
||||
UserID: "@alice:localhost",
|
||||
Content: content,
|
||||
},
|
||||
wantOk: true,
|
||||
},
|
||||
{
|
||||
name: "type empty",
|
||||
fields: fields{
|
||||
UserID: "@alice:localhost",
|
||||
Content: content,
|
||||
},
|
||||
wantOk: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
r := sendServerNoticeRequest{
|
||||
UserID: tt.fields.UserID,
|
||||
Content: tt.fields.Content,
|
||||
Type: tt.fields.Type,
|
||||
StateKey: tt.fields.StateKey,
|
||||
}
|
||||
if gotOk := r.valid(); gotOk != tt.wantOk {
|
||||
t.Errorf("valid() = %v, want %v", gotOk, tt.wantOk)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue