~samwhited/xmpp

008072a4511547af0c1f3b8f7d1c55bc3bd94291 — Sam Whited 5 years ago 3036712
Update SASL to use new mellium.im/sasl API

Add credentials to config (probably temporarily)
3 files changed, 20 insertions(+), 12 deletions(-)

M config.go
M sasl.go
M sasl_test.go
M config.go => config.go +6 -0
@@ 39,6 39,12 @@ type Config struct {

	// XMPP protocol version
	Version internal.Version

	// The authorization identity, username, and password to authenticate with.
	// Identity is used when a user wants to act on behalf of another user. For
	// instance, an admin might want to log in as another user to help them
	// troubleshoot an issue. Normally it is left blank.
	Identity, Username, Password string
}

// NewClientConfig constructs a new client-to-server session configuration with

M sasl.go => sasl.go +12 -10
@@ 87,19 87,21 @@ func SASL(mechanisms ...sasl.Mechanism) StreamFeature {
					return mask, errors.New(`No matching SASL mechanisms found`)
				}

				var client sasl.Negotiator
				// Create the SASL Client
				conf := conn.Config()
				saslconf := sasl.Config{
					RemoteMechanisms: data.([]string),
					Identity:         conf.Identity,
					Username:         conf.Username,
					Password:         conf.Password,
				}
				if tlsconn, ok := conn.rwc.(*tls.Conn); ok {
					client = sasl.NewClient(selected,
						sasl.RemoteMechanisms(data.([]string)...),
						sasl.ConnState(tlsconn.ConnectionState()),
					)
				} else {
					client = sasl.NewClient(selected,
						sasl.RemoteMechanisms(data.([]string)...),
					)
					connstate := tlsconn.ConnectionState()
					saslconf.TLSState = &connstate
				}

				// Create the SASL Client
				client := sasl.NewClient(selected, saslconf)

				more, resp, err := client.Step(nil)
				if err != nil {
					return mask, err

M sasl_test.go => sasl_test.go +2 -2
@@ 26,7 26,7 @@ func TestSASLPanicsNoMechanisms(t *testing.T) {

func TestSASLList(t *testing.T) {
	var b bytes.Buffer
	s := SASL(sasl.Plain("", "user", "pass"), sasl.ScramSha256("", "user", "pass"))
	s := SASL(sasl.Plain, sasl.ScramSha256)
	req, err := s.List(context.Background(), &b)
	switch {
	case err != nil:


@@ 74,7 74,7 @@ func TestSASLList(t *testing.T) {
}

func TestSASLParse(t *testing.T) {
	s := SASL(sasl.Plain("", "", ""))
	s := SASL(sasl.Plain)
	for _, test := range []struct {
		xml   string
		items []string