2017-06-16 10:52:03 -05:00
|
|
|
// Copyright 2017 Vector Creations Ltd
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestLoadConfigRelative(t *testing.T) {
|
|
|
|
_, err := loadConfig("/my/config/dir", []byte(testConfig),
|
|
|
|
mockReadFile{
|
|
|
|
"/my/config/dir/matrix_key.pem": testKey,
|
|
|
|
"/my/config/dir/tls_cert.pem": testCert,
|
|
|
|
}.readFile,
|
2017-08-16 07:36:41 -05:00
|
|
|
false,
|
2017-06-16 10:52:03 -05:00
|
|
|
)
|
|
|
|
if err != nil {
|
|
|
|
t.Error("failed to load config:", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testConfig = `
|
2022-01-05 11:44:49 -06:00
|
|
|
version: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
global:
|
2017-06-16 10:52:03 -05:00
|
|
|
server_name: localhost
|
|
|
|
private_key: matrix_key.pem
|
2020-08-11 07:21:26 -05:00
|
|
|
key_id: ed25519:auto
|
2020-08-10 08:18:04 -05:00
|
|
|
key_validity_period: 168h0m0s
|
2021-09-10 04:05:31 -05:00
|
|
|
well_known_server_name: "localhost:443"
|
2020-08-11 07:21:26 -05:00
|
|
|
trusted_third_party_id_servers:
|
|
|
|
- matrix.org
|
|
|
|
- vector.im
|
2020-08-10 08:18:04 -05:00
|
|
|
kafka:
|
2020-08-13 06:16:37 -05:00
|
|
|
addresses:
|
|
|
|
- localhost:2181
|
2020-08-11 07:21:26 -05:00
|
|
|
topic_prefix: Dendrite
|
2020-08-10 08:18:04 -05:00
|
|
|
use_naffka: true
|
|
|
|
naffka_database:
|
|
|
|
connection_string: file:naffka.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
metrics:
|
|
|
|
enabled: false
|
|
|
|
basic_auth:
|
|
|
|
username: metrics
|
|
|
|
password: metrics
|
2022-02-18 09:05:03 -06:00
|
|
|
server_notices:
|
|
|
|
local_part: "_server"
|
|
|
|
display_name: "Server alerts"
|
|
|
|
avatar: ""
|
|
|
|
room_name: "Server Alerts"
|
2020-08-10 08:18:04 -05:00
|
|
|
app_service_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7777
|
|
|
|
connect: http://localhost:7777
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:appservice.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
config_files: []
|
|
|
|
client_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7771
|
|
|
|
connect: http://localhost:7771
|
|
|
|
external_api:
|
|
|
|
listen: http://[::]:8071
|
2020-08-11 07:21:26 -05:00
|
|
|
registration_disabled: false
|
2020-08-10 08:18:04 -05:00
|
|
|
registration_shared_secret: ""
|
2020-08-11 07:21:26 -05:00
|
|
|
enable_registration_captcha: false
|
2020-08-10 08:18:04 -05:00
|
|
|
recaptcha_public_key: ""
|
|
|
|
recaptcha_private_key: ""
|
2020-08-11 07:21:26 -05:00
|
|
|
recaptcha_bypass_secret: ""
|
2020-08-10 08:18:04 -05:00
|
|
|
recaptcha_siteverify_api: ""
|
|
|
|
turn:
|
|
|
|
turn_user_lifetime: ""
|
|
|
|
turn_uris: []
|
|
|
|
turn_shared_secret: ""
|
|
|
|
turn_username: ""
|
|
|
|
turn_password: ""
|
|
|
|
current_state_server:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7782
|
|
|
|
connect: http://localhost:7782
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:currentstate.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
edu_server:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7778
|
|
|
|
connect: http://localhost:7778
|
2020-08-10 08:18:04 -05:00
|
|
|
federation_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7772
|
|
|
|
connect: http://localhost:7772
|
|
|
|
external_api:
|
|
|
|
listen: http://[::]:8072
|
2020-08-10 08:18:04 -05:00
|
|
|
federation_certificates: []
|
|
|
|
federation_sender:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7775
|
|
|
|
connect: http://localhost:7775
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
2021-11-24 04:45:23 -06:00
|
|
|
connection_string: file:federationapi.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
2020-08-11 07:21:26 -05:00
|
|
|
send_max_retries: 16
|
|
|
|
disable_tls_validation: false
|
2020-08-10 08:18:04 -05:00
|
|
|
key_server:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7779
|
|
|
|
connect: http://localhost:7779
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:keyserver.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
media_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7774
|
|
|
|
connect: http://localhost:7774
|
|
|
|
external_api:
|
|
|
|
listen: http://[::]:8074
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:mediaapi.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
2020-08-11 07:21:26 -05:00
|
|
|
base_path: ./media_store
|
2020-08-10 08:18:04 -05:00
|
|
|
max_file_size_bytes: 10485760
|
|
|
|
dynamic_thumbnails: false
|
|
|
|
max_thumbnail_generators: 10
|
2020-08-11 07:21:26 -05:00
|
|
|
thumbnail_sizes:
|
|
|
|
- width: 32
|
|
|
|
height: 32
|
|
|
|
method: crop
|
|
|
|
- width: 96
|
|
|
|
height: 96
|
|
|
|
method: crop
|
|
|
|
- width: 640
|
|
|
|
height: 480
|
|
|
|
method: scale
|
2020-08-10 08:18:04 -05:00
|
|
|
room_server:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7770
|
|
|
|
connect: http://localhost:7770
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:roomserver.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
server_key_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7780
|
|
|
|
connect: http://localhost:7780
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:serverkeyapi.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
2020-08-11 07:21:26 -05:00
|
|
|
key_perspectives:
|
|
|
|
- server_name: matrix.org
|
|
|
|
keys:
|
|
|
|
- key_id: ed25519:auto
|
|
|
|
public_key: Noi6WqcDj0QmPxCNQqgezwTlBKrfqehY1u2FyWP9uYw
|
|
|
|
- key_id: ed25519:a_RXGa
|
|
|
|
public_key: l8Hft5qXKn1vfHrg3p4+W8gELQVo8N13JkluMfmn2sQ
|
2020-08-10 08:18:04 -05:00
|
|
|
sync_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7773
|
|
|
|
connect: http://localhost:7773
|
2020-08-10 08:18:04 -05:00
|
|
|
database:
|
|
|
|
connection_string: file:syncapi.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
user_api:
|
2020-08-13 06:16:37 -05:00
|
|
|
internal_api:
|
|
|
|
listen: http://localhost:7781
|
|
|
|
connect: http://localhost:7781
|
2020-08-10 08:18:04 -05:00
|
|
|
account_database:
|
|
|
|
connection_string: file:userapi_accounts.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
|
|
|
device_database:
|
|
|
|
connection_string: file:userapi_devices.db
|
2020-08-11 07:21:26 -05:00
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
2020-08-10 08:18:04 -05:00
|
|
|
conn_max_lifetime: -1
|
2022-03-03 05:40:53 -06:00
|
|
|
pusher_database:
|
|
|
|
connection_string: file:pushserver.db
|
|
|
|
max_open_conns: 100
|
|
|
|
max_idle_conns: 2
|
|
|
|
conn_max_lifetime: -1
|
2020-08-10 08:18:04 -05:00
|
|
|
tracing:
|
|
|
|
enabled: false
|
|
|
|
jaeger:
|
|
|
|
serviceName: ""
|
|
|
|
disabled: false
|
|
|
|
rpc_metrics: false
|
|
|
|
tags: []
|
|
|
|
sampler: null
|
|
|
|
reporter: null
|
|
|
|
headers: null
|
|
|
|
baggage_restrictions: null
|
|
|
|
throttler: null
|
2020-08-11 07:21:26 -05:00
|
|
|
logging:
|
|
|
|
- type: file
|
|
|
|
level: info
|
|
|
|
params:
|
|
|
|
path: /var/log/dendrite
|
2017-06-16 10:52:03 -05:00
|
|
|
`
|
|
|
|
|
|
|
|
type mockReadFile map[string]string
|
|
|
|
|
|
|
|
func (m mockReadFile) readFile(path string) ([]byte, error) {
|
|
|
|
data, ok := m[path]
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("no such file %q", path)
|
|
|
|
}
|
|
|
|
return []byte(data), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadKey(t *testing.T) {
|
2020-09-25 04:58:53 -05:00
|
|
|
keyID, _, err := readKeyPEM("path/to/key", []byte(testKey), true)
|
2017-06-16 10:52:03 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Error("failed to load private key:", err)
|
|
|
|
}
|
|
|
|
wantKeyID := testKeyID
|
|
|
|
if wantKeyID != string(keyID) {
|
|
|
|
t.Errorf("wanted key ID to be %q, got %q", wantKeyID, keyID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const testKeyID = "ed25519:c8NsuQ"
|
|
|
|
|
|
|
|
const testKey = `
|
|
|
|
-----BEGIN MATRIX PRIVATE KEY-----
|
|
|
|
Key-ID: ` + testKeyID + `
|
|
|
|
7KRZiZ2sTyRR8uqqUjRwczuwRXXkUMYIUHq4Mc3t4b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