droboticflow/internal/testsupport/query_replica_lab_test.go

28 lines
872 B
Go

package testsupport
import "testing"
func TestQueryReplicaTargetRejectsUnapprovedConnections(t *testing.T) {
const allowed = "mongodb://127.0.0.1:27229/?directConnection=true&replicaSet=query-lab-rs"
for _, tc := range []struct{ uri, enabled string }{
{allowed, ""},
{"mongodb://10.189.16.4:27017", "1"},
{"mongodb://127.0.0.1:27018", "1"},
{allowed + "&authSource=admin", "1"},
} {
if validateQueryReplicaTarget(tc.uri, tc.enabled) == nil {
t.Fatal("accepted a connection outside the owned synthetic tunnel")
}
}
if err := validateQueryReplicaTarget(allowed, "1"); err != nil {
t.Fatal(err)
}
}
func TestQueryReplicaTargetDefaultsToLocalLab(t *testing.T) {
t.Setenv("QUERY_REPLICA_TEST_TARGET_URI", "")
if got := QueryReplicaTargetURI(t); got != "mongodb://127.0.0.1:27129/?replicaSet=query-read-rs" {
t.Fatal("default target changed")
}
}