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(
NegotiatorAttributes(
sendRawXML,
() => this,
() => _connectionSettings,
_sendEvent,
getNegotiatorById,

View File

@ -1,5 +1,6 @@
import 'package:meta/meta.dart';
import 'package:moxlib/moxlib.dart';
import 'package:moxxmpp/src/connection.dart';
import 'package:moxxmpp/src/errors.dart';
import 'package:moxxmpp/src/events.dart';
import 'package:moxxmpp/src/jid.dart';
@ -28,6 +29,7 @@ abstract class NegotiatorError extends XmppError {}
class NegotiatorAttributes {
const NegotiatorAttributes(
this.sendNonza,
this.getConnection,
this.getConnectionSettings,
this.sendEvent,
this.getNegotiatorById,
@ -46,7 +48,10 @@ class NegotiatorAttributes {
/// Returns the connection settings.
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;
/// Returns the negotiator with id id of the connection or null.

View File

@ -30,10 +30,13 @@ class ResourceBindingNegotiator extends XmppFeatureNegotiatorBase {
if (sm != null) {
return super.matchesFeature(features) &&
!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

View File

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