Skip to content

Commit 5c81a70

Browse files
authored
Merge branch 'main' into hs/msc4155-invite-filtering
2 parents 684b12c + b95569e commit 5c81a70

5 files changed

Lines changed: 192 additions & 60 deletions

File tree

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ type Complement struct {
106106
// disable this behaviour being added later, once this has stablised.
107107
EnableDirtyRuns bool
108108

109+
// The IP that is used to connect to the running homeserver from the host.
110+
//
111+
// For Complement tests, this is always configured as `127.0.0.1` but can be
112+
// overridden by homerunner to allow binding to a different IP address
113+
// (`HOMERUNNER_HS_PORTBINDING_IP`).
114+
//
115+
// This field is used for the host-accessible homeserver URLs (as the hostname)
116+
// so clients in your tests can access the homeserver.
109117
HSPortBindingIP string
110118

111119
// Name: COMPLEMENT_POST_TEST_SCRIPT

go.mod

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
module github.com/matrix-org/complement
22

3-
go 1.23
3+
go 1.23.0
44

5-
toolchain go1.23.9
5+
toolchain go1.24.3
66

77
require (
88
github.com/docker/docker v28.0.4+incompatible
@@ -14,7 +14,7 @@ require (
1414
github.com/sirupsen/logrus v1.9.3
1515
github.com/tidwall/gjson v1.18.0
1616
github.com/tidwall/sjson v1.2.5
17-
golang.org/x/crypto v0.32.0
17+
golang.org/x/crypto v0.36.0
1818
golang.org/x/exp v0.0.0-20230905200255-921286631fa9
1919
gonum.org/v1/plot v0.11.0
2020
)
@@ -36,7 +36,6 @@ require (
3636
github.com/gogo/protobuf v1.3.2 // indirect
3737
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
3838
github.com/moby/docker-image-spec v1.3.1 // indirect
39-
github.com/moby/sys/atomicwriter v0.1.0 // indirect
4039
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 // indirect
4140
github.com/morikuni/aec v1.0.0 // indirect
4241
github.com/opencontainers/go-digest v1.0.0 // indirect
@@ -51,9 +50,9 @@ require (
5150
go.opentelemetry.io/otel/sdk v1.30.0 // indirect
5251
go.opentelemetry.io/otel/trace v1.30.0 // indirect
5352
golang.org/x/image v0.18.0 // indirect
54-
golang.org/x/net v0.33.0 // indirect
55-
golang.org/x/sys v0.29.0 // indirect
56-
golang.org/x/text v0.21.0 // indirect
53+
golang.org/x/net v0.38.0 // indirect
54+
golang.org/x/sys v0.31.0 // indirect
55+
golang.org/x/text v0.23.0 // indirect
5756
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
5857
gotest.tools/v3 v3.0.3 // indirect
5958
)

go.sum

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2222
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2323
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
2424
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
25-
github.com/docker/docker v27.5.1+incompatible h1:4PYU5dnBYqRQi0294d1FBECqT9ECWeQAIfE8q4YnPY8=
26-
github.com/docker/docker v27.5.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
2725
github.com/docker/docker v28.0.4+incompatible h1:JNNkBctYKurkw6FrHfKqY0nKIDf5nrbxjVBtS+cdcok=
2826
github.com/docker/docker v28.0.4+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
29-
github.com/docker/docker v28.1.1+incompatible h1:49M11BFLsVO1gxY9UX9p/zwkE/rswggs8AdFmXQw51I=
30-
github.com/docker/docker v28.1.1+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
3127
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
3228
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
3329
github.com/docker/go-units v0.4.0 h1:3uh0PgVws3nIA0Q+MwDC8yjEPf9zjRfZZWXZYDct3Tw=
@@ -81,10 +77,6 @@ github.com/miekg/dns v1.1.50 h1:DQUfb9uc6smULcREF09Uc+/Gd46YWqJd5DbpPE9xkcA=
8177
github.com/miekg/dns v1.1.50/go.mod h1:e3IlAVfNqAllflbibAZEWOXOQ+Ynzk/dDozDxY7XnME=
8278
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
8379
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
84-
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
85-
github.com/moby/sys/atomicwriter v0.1.0/go.mod h1:Ul8oqv2ZMNHOceF643P6FKPXeCmYtlQMvpizfsSoaWs=
86-
github.com/moby/sys/sequential v0.6.0 h1:qrx7XFUd/5DxtqcoH1h438hF5TmOvzC/lspjy7zgvCU=
87-
github.com/moby/sys/sequential v0.6.0/go.mod h1:uyv8EUTrca5PnDsdMGXhZe6CCe8U/UiTWd+lL+7b/Ko=
8880
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297 h1:yH0SvLzcbZxcJXho2yh7CqdENGMQe73Cw3woZBpPli0=
8981
github.com/moby/term v0.0.0-20210610120745-9d4ed1856297/go.mod h1:vgPCkQMyxTZ7IDy8SXRufE172gr8+K/JE/7hHFxHW3A=
9082
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
@@ -143,8 +135,8 @@ go.opentelemetry.io/proto/otlp v1.3.1/go.mod h1:0X1WI4de4ZsLrrJNLAQbFeLCm3T7yBkR
143135
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
144136
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
145137
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
146-
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
147-
golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc=
138+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
139+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
148140
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 h1:GoHiUyI/Tp2nVkLI2mCxVkOjsbSXD66ic0XW0js0R9g=
149141
golang.org/x/exp v0.0.0-20230905200255-921286631fa9/go.mod h1:S2oDrQGGwySpoQPVqRShND87VCbxmc6bL1Yd2oYrm6k=
150142
golang.org/x/image v0.0.0-20190910094157-69e4b8554b2a/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
@@ -165,13 +157,13 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
165157
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
166158
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
167159
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
168-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
169-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
160+
golang.org/x/net v0.38.0 h1:vRMAPTMaeGqVhG5QyLJHqNDwecKTomGeqbnfZyKlBI8=
161+
golang.org/x/net v0.38.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
170162
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
171163
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
172164
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
173-
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
174-
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
165+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
166+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
175167
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
176168
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
177169
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -181,13 +173,13 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
181173
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
182174
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
183175
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
184-
golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU=
185-
golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
176+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
177+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
186178
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
187179
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
188180
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
189-
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
190-
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
181+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
182+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
191183
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac h1:7zkz7BUtwNFFqcowJ+RIgu2MaV/MapERkDIy+mwPyjs=
192184
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
193185
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

internal/docker/builder.go

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ func (d *Builder) construct(bprint b.Blueprint) (errs []error) {
343343
Pause: true,
344344
Reference: "localhost/complement:" + res.contextStr,
345345
Changes: toChanges(labels),
346+
347+
// Podman's compatibility API returns a 500 if the POST request has an empty body, so we give it an empty
348+
// Config to chew on.
349+
Config: &container.Config{},
346350
})
347351
if err != nil {
348352
d.log("%s : failed to ContainerCommit: %s\n", res.contextStr, err)
@@ -539,27 +543,59 @@ func printPortBindingsOfAllComplementContainers(docker *client.Client, contextSt
539543
log.Printf("=============== %s : END ALL COMPLEMENT DOCKER PORT BINDINGS ===============\n\n\n", contextStr)
540544
}
541545

542-
func endpoints(p nat.PortMap, csPort, ssPort int) (baseURL, fedBaseURL string, err error) {
543-
csapiPort := fmt.Sprintf("%d/tcp", csPort)
544-
csapiPortInfo, ok := p[nat.Port(csapiPort)]
545-
if !ok {
546-
return "", "", fmt.Errorf("port %s not exposed - exposed ports: %v", csapiPort, p)
546+
// endpoints transforms the homeserver ports into the base URL and federation base URL.
547+
func endpoints(p nat.PortMap, hsPortBindingIP string, csPort, ssPort int) (baseURL, fedBaseURL string, err error) {
548+
csapiPortBinding, err := findPortBinding(p, hsPortBindingIP, csPort)
549+
if err != nil {
550+
return "", "", fmt.Errorf("Problem finding CS API port: %s", err)
547551
}
548-
if len(csapiPortInfo) == 0 {
549-
return "", "", fmt.Errorf("port %s exposed with not mapped port: %+v", csapiPort, p)
552+
baseURL = fmt.Sprintf("http://"+csapiPortBinding.HostIP+":%s", csapiPortBinding.HostPort)
553+
554+
ssapiPortBinding, err := findPortBinding(p, hsPortBindingIP, ssPort)
555+
if err != nil {
556+
return "", "", fmt.Errorf("Problem finding SS API port: %s", err)
550557
}
551-
baseURL = fmt.Sprintf("http://"+csapiPortInfo[0].HostIP+":%s", csapiPortInfo[0].HostPort)
558+
fedBaseURL = fmt.Sprintf("https://"+ssapiPortBinding.HostIP+":%s", ssapiPortBinding.HostPort)
559+
return
560+
}
552561

553-
ssapiPort := fmt.Sprintf("%d/tcp", ssPort)
554-
ssapiPortInfo, ok := p[nat.Port(ssapiPort)]
562+
// findPortBinding finds a matching port binding for the given host/port in the `nat.PortMap`.
563+
//
564+
// This function will return the first port binding that matches the given host IP. If a
565+
// `0.0.0.0` binding is found, we will assume that it is listening on all interfaces,
566+
// including the `hsPortBindingIP`, and return a binding with the `hsPortBindingIP` as
567+
// the host IP.
568+
func findPortBinding(p nat.PortMap, hsPortBindingIP string, port int) (portBinding nat.PortBinding, err error) {
569+
portString := fmt.Sprintf("%d/tcp", port)
570+
portBindings, ok := p[nat.Port(portString)]
555571
if !ok {
556-
return "", "", fmt.Errorf("port %s not exposed - exposed ports: %v", ssapiPort, p)
557-
}
558-
if len(ssapiPortInfo) == 0 {
559-
return "", "", fmt.Errorf("port %s exposed with not mapped port: %+v", ssapiPort, p)
572+
return nat.PortBinding{}, fmt.Errorf("port %s not exposed - exposed ports: %v", portString, p)
573+
}
574+
if len(portBindings) == 0 {
575+
return nat.PortBinding{}, fmt.Errorf("port %s exposed with not mapped port: %+v", portString, p)
576+
}
577+
578+
for _, pb := range portBindings {
579+
if pb.HostIP == hsPortBindingIP {
580+
return pb, nil
581+
} else if pb.HostIP == "0.0.0.0" {
582+
// `0.0.0.0` means "all interfaces", so we can assume that this will be listening
583+
// for connections from `hsPortBindingIP` as well.
584+
return nat.PortBinding{
585+
HostIP: hsPortBindingIP,
586+
HostPort: pb.HostPort,
587+
}, nil
588+
} else if pb.HostIP == "" && hsPortBindingIP == "127.0.0.1" {
589+
// `HostIP` can be empty in certain environments (observed with podman v4.3.1). We
590+
// will assume this is only a binding for `127.0.0.1`.
591+
return nat.PortBinding{
592+
HostIP: hsPortBindingIP,
593+
HostPort: pb.HostPort,
594+
}, nil
595+
}
560596
}
561-
fedBaseURL = fmt.Sprintf("https://"+csapiPortInfo[0].HostIP+":%s", ssapiPortInfo[0].HostPort)
562-
return
597+
598+
return nat.PortBinding{}, fmt.Errorf("unable to find matching port binding for %s %s: %+v", hsPortBindingIP, portString, p)
563599
}
564600

565601
type result struct {

0 commit comments

Comments
 (0)