~samwhited/xmpp

ed13a4c4861ee84d693dae5b80cdf1d1674b57d4 — Sam Whited 9 months ago 467e8c4
internal/integration/ejabberd: component support

Signed-off-by: Sam Whited <sam@samwhited.com>
2 files changed, 38 insertions(+), 3 deletions(-)

M internal/integration/ejabberd/config.go
M internal/integration/ejabberd/ejabberd.go
M internal/integration/ejabberd/config.go => internal/integration/ejabberd/config.go +18 -3
@@ 11,9 11,11 @@ import (

// Config contains options that can be written to a Prosody config file.
type Config struct {
	VHosts    []string
	C2SSocket string
	S2SSocket string
	VHosts     []string
	C2SSocket  string
	S2SSocket  string
	CompSocket string
	Component  map[string]string
}

const inetrc = `{lookup,["file","native"]}.


@@ 53,6 55,19 @@ listen:
    module: ejabberd_s2s_in
    max_stanza_size: 524288
{{- end }}
{{- if .CompSocket }}
  -
    port: "unix:{{ $.CompSocket }}"
    ip: "::1"
    access: "all"
    module: ejabberd_service
    max_stanza_size: 524288
    hosts:
{{- range $domain, $secret := .Component }}
      '{{$domain}}':
        password: '{{ $secret }}'
{{- end }}
{{- end }}

s2s_use_starttls: optional


M internal/integration/ejabberd/ejabberd.go => internal/integration/ejabberd/ejabberd.go +20 -0
@@ 186,6 186,26 @@ func ctlFunc(ctx context.Context, args ...string) func(*integration.Cmd) error {
	}
}

// Component adds an external component with the given domain and secret to the
// config file.
func Component(domain, secret string) integration.Option {
	return func(cmd *integration.Cmd) error {
		compListener, err := cmd.ComponentListen("unix", filepath.Join(cmd.ConfigDir(), "comp.socket"))
		if err != nil {
			return err
		}

		cfg := getConfig(cmd)
		cfg.CompSocket = compListener.Addr().(*net.UnixAddr).Name
		if cfg.Component == nil {
			cfg.Component = make(map[string]string)
		}
		cfg.Component[domain] = secret
		cmd.Config = cfg
		return nil
	}
}

// CreateUser returns an option that calls ejabberdctl to create a user.
// It is equivalent to calling:
// Ctl(ctx, "register", "localpart", "domainpart", "password") except that it