fix(core): Prevent resource binding if we already have a resource

This commit is contained in:
PapaTutuWawa 2023-04-01 12:38:18 +02:00
parent f460e5ebe9
commit 63b7abd6f9
4 changed files with 37 additions and 3 deletions

View File

@ -270,6 +270,7 @@ class XmppConnection {
negotiator.register( negotiator.register(
NegotiatorAttributes( NegotiatorAttributes(
sendRawXML, sendRawXML,
() => this,
() => _connectionSettings, () => _connectionSettings,
_sendEvent, _sendEvent,
getNegotiatorById, getNegotiatorById,

View File

@ -1,5 +1,6 @@
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart'; import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/connection.dart';
import 'package:moxxmpp/src/errors.dart'; import 'package:moxxmpp/src/errors.dart';
import 'package:moxxmpp/src/events.dart'; import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
@ -28,6 +29,7 @@ abstract class NegotiatorError extends XmppError {}
class NegotiatorAttributes { class NegotiatorAttributes {
const NegotiatorAttributes( const NegotiatorAttributes(
this.sendNonza, this.sendNonza,
this.getConnection,
this.getConnectionSettings, this.getConnectionSettings,
this.sendEvent, this.sendEvent,
this.getNegotiatorById, this.getNegotiatorById,
@ -46,7 +48,10 @@ class NegotiatorAttributes {
/// Returns the connection settings. /// Returns the connection settings.
final ConnectionSettings Function() getConnectionSettings; final ConnectionSettings Function() getConnectionSettings;
/// Send an event event to the connection's event bus /// Returns the connection object.
final XmppConnection Function() getConnection;
/// Send an event event to the connection's event bus.
final Future<void> Function(XmppEvent event) sendEvent; final Future<void> Function(XmppEvent event) sendEvent;
/// Returns the negotiator with id id of the connection or null. /// Returns the negotiator with id id of the connection or null.

View File

@ -30,10 +30,13 @@ class ResourceBindingNegotiator extends XmppFeatureNegotiatorBase {
if (sm != null) { if (sm != null) {
return super.matchesFeature(features) && return super.matchesFeature(features) &&
!sm.streamResumed && !sm.streamResumed &&
attributes.isAuthenticated(); attributes.isAuthenticated() &&
attributes.getConnection().resource.isEmpty;
} }
return super.matchesFeature(features) && attributes.isAuthenticated(); return super.matchesFeature(features) &&
attributes.isAuthenticated() &&
attributes.getConnection().resource.isEmpty;
} }
@override @override

View File

@ -46,6 +46,11 @@ void main() {
)..register( )..register(
NegotiatorAttributes( NegotiatorAttributes(
(XMLNode _, {String? redact}) {}, (XMLNode _, {String? redact}) {},
() => XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
fakeSocket,
),
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
@ -142,6 +147,11 @@ void main() {
)..register( )..register(
NegotiatorAttributes( NegotiatorAttributes(
(XMLNode n, {String? redact}) => lastMessage = n.innerText(), (XMLNode n, {String? redact}) => lastMessage = n.innerText(),
() => XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
StubTCPSocket([]),
),
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
@ -193,6 +203,11 @@ void main() {
)..register( )..register(
NegotiatorAttributes( NegotiatorAttributes(
(XMLNode _, {String? redact}) {}, (XMLNode _, {String? redact}) {},
() => XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
StubTCPSocket([]),
),
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
@ -234,6 +249,11 @@ void main() {
)..register( )..register(
NegotiatorAttributes( NegotiatorAttributes(
(XMLNode _, {String? redact}) {}, (XMLNode _, {String? redact}) {},
() => XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
StubTCPSocket([]),
),
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
@ -278,6 +298,11 @@ void main() {
)..register( )..register(
NegotiatorAttributes( NegotiatorAttributes(
(XMLNode _, {String? redact}) {}, (XMLNode _, {String? redact}) {},
() => XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
StubTCPSocket([]),
),
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',