36 lines
1.8 KiB
Go
36 lines
1.8 KiB
Go
package api
|
|
|
|
import (
|
|
"encoding/json"
|
|
"linkport/internal/model"
|
|
"testing"
|
|
)
|
|
|
|
func TestRabbitManagementConfigurationRoundTrip(t *testing.T) {
|
|
f := newFixture(t)
|
|
f.login()
|
|
w := f.request("POST", "/api/v1/targets", map[string]any{"name": "rabbit management", "type": "rabbitmq", "targetHost": "rabbit.internal", "targetPort": 5672, "managementPort": 15671, "managementTLS": true, "accounts": []any{map[string]any{"id": "upstream", "username": "target", "password": "secret"}}}, true)
|
|
requireStatus(t, w, 201)
|
|
var target struct {
|
|
Config model.Target `json:"config"`
|
|
}
|
|
if err := json.Unmarshal(w.Body.Bytes(), &target); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if target.Config.ManagementPort != 15671 || !target.Config.ManagementTLS {
|
|
t.Fatal("management target settings lost")
|
|
}
|
|
w = f.request("POST", "/api/v1/proxies", map[string]any{"name": "rabbit dual port", "type": "rabbitmq", "targetId": target.Config.ID, "targetAccountId": "upstream", "listenHost": "127.0.0.1", "listenPort": 5672, "managementListenPort": 15672, "gatewayAccounts": []any{map[string]any{"id": "reader", "username": "reader", "password": "fixture", "accessMode": "readonly"}}}, true)
|
|
requireStatus(t, w, 201)
|
|
view := readView(t, w)
|
|
if view.Config.ManagementListenPort != 15672 || view.Config.GatewayAccounts[0].AccessMode != "readonly" {
|
|
t.Fatal("gateway management/readonly settings lost")
|
|
}
|
|
saved, err := f.store.Get(view.Config.ID)
|
|
if err != nil || saved.ManagementPort != 15671 || !saved.ManagementTLS {
|
|
t.Fatalf("target settings not resolved: %+v %v", saved, err)
|
|
}
|
|
requireStatus(t, f.request("PUT", "/api/v1/proxies/"+view.Config.ID, map[string]any{"managementPort": 9999}, true), 400)
|
|
requireStatus(t, f.request("PUT", "/api/v1/proxies/"+view.Config.ID, map[string]any{"managementListenPort": 5672}, true), 400)
|
|
}
|