Skip to content

Commit

Permalink
If the configured port is the default port, we should treat it the sa…
Browse files Browse the repository at this point in the history
…me as if no port was configured
  • Loading branch information
olabini committed Sep 7, 2021
1 parent 2a0a678 commit 67220a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 4 additions & 1 deletion config/connection_policy.go
Expand Up @@ -71,6 +71,9 @@ var buildDialerFor = func(p *ConnectionPolicy, conf *Account, verifier ourtls.Ve
return p.buildDialerFor(conf, verifier)
}

// DefaultXMPPPort is the default port which XMPP clients should use for connecting to XMPP servers
const DefaultXMPPPort = 5222

func (p *ConnectionPolicy) buildDialerFor(conf *Account, verifier ourtls.Verifier) (interfaces.Dialer, error) {
//Account is a bare JID
jidParts := strings.SplitN(conf.Account, "@", 2)
Expand Down Expand Up @@ -138,7 +141,7 @@ func (p *ConnectionPolicy) buildDialerFor(conf *Account, verifier ourtls.Verifie
customServerAddress = true
}

if conf.Port > 0 {
if conf.Port > 0 && conf.Port != DefaultXMPPPort {
port = strconv.Itoa(conf.Port)
customServerAddress = true
}
Expand Down
13 changes: 13 additions & 0 deletions config/connection_policy_test.go
Expand Up @@ -128,6 +128,19 @@ func (s *ConnectionPolicySuite) Test_buildDialerFor_UsesACustomPortEvenIfNoCusto
c.Assert(dialer.ServerAddress(), Equals, "coy.im:5236")
}

func (s *ConnectionPolicySuite) Test_buildDialerFor_UsesNoCustomPortIfItsTheDefault(c *C) {
policy := ConnectionPolicy{DialerFactory: xmpp.DialerFactory, torState: mockTorState("", false)}

dialer, err := policy.buildDialerFor(&Account{
Account: "coyim@coy.im",
Port: 5222,
}, nil)

c.Assert(err, IsNil)
c.Assert(dialer.ServerAddress(), Equals, "")
c.Assert(dialer.GetServer(), Equals, "coy.im:5222")
}

func (s *ConnectionPolicySuite) Test_buildDialerFor_FailsIfItCantDoProxyCreation(c *C) {
policy := ConnectionPolicy{DialerFactory: xmpp.DialerFactory, torState: mockTorState("", false)}

Expand Down

0 comments on commit 67220a0

Please sign in to comment.