Compare commits
No commits in common. "9cb6346c4d94d8b878330d42af0f9c45e5ce772d" and "b53c62b40ccf99dd8df845da0b1c3b1cd46d40b1" have entirely different histories.
9cb6346c4d
...
b53c62b40c
@ -117,19 +117,19 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||||||
allowPlainAuth: true,
|
allowPlainAuth: true,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
final result = await connection.connect(waitUntilLogin: true);
|
final result = await connection.connectAwaitable();
|
||||||
setState(() {
|
setState(() {
|
||||||
connected = result.isType<bool>() && result.get<bool>();
|
connected = result.success;
|
||||||
loading = false;
|
loading = false;
|
||||||
});
|
});
|
||||||
if (result.isType<XmppConnectionError>()) {
|
if (result.error != null) {
|
||||||
logger.severe(result.get<XmppConnectionError>());
|
logger.severe(result.error);
|
||||||
if (context.mounted) {
|
if (context.mounted) {
|
||||||
showDialog(
|
showDialog(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (_) => AlertDialog(
|
builder: (_) => AlertDialog(
|
||||||
title: const Text('Error'),
|
title: const Text('Error'),
|
||||||
content: Text(result.get<XmppConnectionError>().toString()),
|
content: Text(result.error.toString()),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
useGoogleAPIs = false;
|
useGoogleAPIs = false;
|
||||||
useGoogleTVAddOns = false;
|
useGoogleTVAddOns = false;
|
||||||
};
|
};
|
||||||
pinnedJDK = pkgs.jdk17;
|
pinnedJDK = pkgs.jdk;
|
||||||
|
|
||||||
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
|
pythonEnv = pkgs.python3.withPackages (ps: with ps; [
|
||||||
pyyaml
|
pyyaml
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
## 0.3.0
|
|
||||||
|
|
||||||
- **BREAKING**: Removed `connectAwaitable` and merged it with `connect`.
|
|
||||||
|
|
||||||
## 0.1.6+1
|
## 0.1.6+1
|
||||||
|
|
||||||
- **FIX**: Fix LMC not working.
|
- **FIX**: Fix LMC not working.
|
||||||
|
@ -4,7 +4,6 @@ import 'package:meta/meta.dart';
|
|||||||
import 'package:moxlib/moxlib.dart';
|
import 'package:moxlib/moxlib.dart';
|
||||||
import 'package:moxxmpp/src/awaiter.dart';
|
import 'package:moxxmpp/src/awaiter.dart';
|
||||||
import 'package:moxxmpp/src/buffer.dart';
|
import 'package:moxxmpp/src/buffer.dart';
|
||||||
import 'package:moxxmpp/src/connection_errors.dart';
|
|
||||||
import 'package:moxxmpp/src/connectivity.dart';
|
import 'package:moxxmpp/src/connectivity.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';
|
||||||
@ -25,7 +24,6 @@ import 'package:moxxmpp/src/settings.dart';
|
|||||||
import 'package:moxxmpp/src/socket.dart';
|
import 'package:moxxmpp/src/socket.dart';
|
||||||
import 'package:moxxmpp/src/stanza.dart';
|
import 'package:moxxmpp/src/stanza.dart';
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
import 'package:moxxmpp/src/stringxml.dart';
|
||||||
import 'package:moxxmpp/src/types/result.dart';
|
|
||||||
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
import 'package:moxxmpp/src/xeps/xep_0030/xep_0030.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart';
|
import 'package:moxxmpp/src/xeps/xep_0198/negotiator.dart';
|
||||||
import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart';
|
import 'package:moxxmpp/src/xeps/xep_0198/xep_0198.dart';
|
||||||
@ -77,6 +75,21 @@ class StreamHeaderNonza extends XMLNode {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The result of an awaited connection.
|
||||||
|
class XmppConnectionResult {
|
||||||
|
const XmppConnectionResult(
|
||||||
|
this.success, {
|
||||||
|
this.error,
|
||||||
|
});
|
||||||
|
|
||||||
|
/// True if the connection was successful. False if it failed for any reason.
|
||||||
|
final bool success;
|
||||||
|
|
||||||
|
// If a connection attempt fails, i.e. success is false, then this indicates the
|
||||||
|
// reason the connection failed.
|
||||||
|
final XmppError? error;
|
||||||
|
}
|
||||||
|
|
||||||
/// This class is a connection to the server.
|
/// This class is a connection to the server.
|
||||||
class XmppConnection {
|
class XmppConnection {
|
||||||
XmppConnection(
|
XmppConnection(
|
||||||
@ -167,7 +180,7 @@ class XmppConnection {
|
|||||||
|
|
||||||
/// Completers for certain actions
|
/// Completers for certain actions
|
||||||
// ignore: use_late_for_private_fields_and_variables
|
// ignore: use_late_for_private_fields_and_variables
|
||||||
Completer<Result<bool, XmppConnectionError>>? _connectionCompleter;
|
Completer<XmppConnectionResult>? _connectionCompleter;
|
||||||
|
|
||||||
/// Negotiators
|
/// Negotiators
|
||||||
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators = {};
|
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators = {};
|
||||||
@ -185,9 +198,6 @@ class XmppConnection {
|
|||||||
bool _isConnectionRunning = false;
|
bool _isConnectionRunning = false;
|
||||||
final Lock _connectionRunningLock = Lock();
|
final Lock _connectionRunningLock = Lock();
|
||||||
|
|
||||||
/// Flag indicating whether reconnection should be enabled after a successful connection.
|
|
||||||
bool _enableReconnectOnSuccess = false;
|
|
||||||
|
|
||||||
/// Enters the critical section for accessing [XmppConnection._isConnectionRunning]
|
/// Enters the critical section for accessing [XmppConnection._isConnectionRunning]
|
||||||
/// and does the following:
|
/// and does the following:
|
||||||
/// - if _isConnectionRunning is false, set it to true and return false.
|
/// - if _isConnectionRunning is false, set it to true and return false.
|
||||||
@ -394,10 +404,9 @@ class XmppConnection {
|
|||||||
state: XmppConnectionState.error,
|
state: XmppConnectionState.error,
|
||||||
);
|
);
|
||||||
_connectionCompleter?.complete(
|
_connectionCompleter?.complete(
|
||||||
Result(
|
XmppConnectionResult(
|
||||||
StreamFailureError(
|
false,
|
||||||
error,
|
error: error,
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
_connectionCompleter = null;
|
_connectionCompleter = null;
|
||||||
@ -418,14 +427,7 @@ class XmppConnection {
|
|||||||
|
|
||||||
// The error is recoverable
|
// The error is recoverable
|
||||||
await _setConnectionState(XmppConnectionState.notConnected);
|
await _setConnectionState(XmppConnectionState.notConnected);
|
||||||
|
await _reconnectionPolicy.onFailure();
|
||||||
if (await _reconnectionPolicy.getShouldReconnect()) {
|
|
||||||
await _reconnectionPolicy.onFailure();
|
|
||||||
} else {
|
|
||||||
_log.info(
|
|
||||||
'Not passing connection failure to reconnection policy as it indicates that we should not reconnect',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Called whenever the socket creates an event
|
/// Called whenever the socket creates an event
|
||||||
@ -857,13 +859,8 @@ class XmppConnection {
|
|||||||
await _resetIsConnectionRunning();
|
await _resetIsConnectionRunning();
|
||||||
await _setConnectionState(XmppConnectionState.connected);
|
await _setConnectionState(XmppConnectionState.connected);
|
||||||
|
|
||||||
// Enable reconnections
|
|
||||||
if (_enableReconnectOnSuccess) {
|
|
||||||
await _reconnectionPolicy.setShouldReconnect(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Resolve the connection completion future
|
// Resolve the connection completion future
|
||||||
_connectionCompleter?.complete(const Result(true));
|
_connectionCompleter?.complete(const XmppConnectionResult(true));
|
||||||
_connectionCompleter = null;
|
_connectionCompleter = null;
|
||||||
|
|
||||||
// Tell consumers of the event stream that we're done with stream feature
|
// Tell consumers of the event stream that we're done with stream feature
|
||||||
@ -1115,30 +1112,47 @@ class XmppConnection {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<bool, XmppConnectionError>> _connectImpl({
|
/// Like [connect] but the Future resolves when the resource binding is either done or
|
||||||
|
/// SASL has failed.
|
||||||
|
Future<XmppConnectionResult> connectAwaitable({
|
||||||
String? lastResource,
|
String? lastResource,
|
||||||
bool waitForConnection = false,
|
bool waitForConnection = false,
|
||||||
bool shouldReconnect = true,
|
|
||||||
bool waitUntilLogin = false,
|
|
||||||
bool enableReconnectOnSuccess = true,
|
|
||||||
}) async {
|
}) async {
|
||||||
_runPreConnectionAssertions();
|
_runPreConnectionAssertions();
|
||||||
await _resetIsConnectionRunning();
|
await _resetIsConnectionRunning();
|
||||||
|
_connectionCompleter = Completer();
|
||||||
|
_log.finest('Calling connect() from connectAwaitable');
|
||||||
|
await connect(
|
||||||
|
lastResource: lastResource,
|
||||||
|
waitForConnection: waitForConnection,
|
||||||
|
shouldReconnect: false,
|
||||||
|
);
|
||||||
|
return _connectionCompleter!.future;
|
||||||
|
}
|
||||||
|
|
||||||
if (waitUntilLogin) {
|
/// Start the connection process using the provided connection settings.
|
||||||
_log.finest('Setting up completer for awaiting completed login');
|
Future<void> connect({
|
||||||
_connectionCompleter = Completer();
|
String? lastResource,
|
||||||
|
bool waitForConnection = false,
|
||||||
|
bool shouldReconnect = true,
|
||||||
|
}) async {
|
||||||
|
if (_connectionState != XmppConnectionState.notConnected &&
|
||||||
|
_connectionState != XmppConnectionState.error) {
|
||||||
|
_log.fine(
|
||||||
|
'Cancelling this connection attempt as one appears to be already running.',
|
||||||
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_runPreConnectionAssertions();
|
||||||
|
await _resetIsConnectionRunning();
|
||||||
|
|
||||||
if (lastResource != null) {
|
if (lastResource != null) {
|
||||||
setResource(lastResource);
|
setResource(lastResource);
|
||||||
}
|
}
|
||||||
|
|
||||||
_enableReconnectOnSuccess = enableReconnectOnSuccess;
|
|
||||||
if (shouldReconnect) {
|
if (shouldReconnect) {
|
||||||
await _reconnectionPolicy.setShouldReconnect(true);
|
await _reconnectionPolicy.setShouldReconnect(true);
|
||||||
} else {
|
|
||||||
await _reconnectionPolicy.setShouldReconnect(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
await _reconnectionPolicy.reset();
|
await _reconnectionPolicy.reset();
|
||||||
@ -1168,8 +1182,6 @@ class XmppConnection {
|
|||||||
);
|
);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
await handleError(NoConnectionError());
|
await handleError(NoConnectionError());
|
||||||
|
|
||||||
return Result(NoConnectionPossibleError());
|
|
||||||
} else {
|
} else {
|
||||||
await _reconnectionPolicy.onSuccess();
|
await _reconnectionPolicy.onSuccess();
|
||||||
_log.fine('Preparing the internal state for a connection attempt');
|
_log.fine('Preparing the internal state for a connection attempt');
|
||||||
@ -1178,67 +1190,6 @@ class XmppConnection {
|
|||||||
_updateRoutingState(RoutingState.negotiating);
|
_updateRoutingState(RoutingState.negotiating);
|
||||||
_isAuthenticated = false;
|
_isAuthenticated = false;
|
||||||
_sendStreamHeader();
|
_sendStreamHeader();
|
||||||
|
|
||||||
if (waitUntilLogin) {
|
|
||||||
return _connectionCompleter!.future;
|
|
||||||
} else {
|
|
||||||
return const Result(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Start the connection process using the provided connection settings.
|
|
||||||
///
|
|
||||||
/// If [lastResource] is set, then its value is used as the connection's resource.
|
|
||||||
/// Useful for stream resumption.
|
|
||||||
///
|
|
||||||
/// [shouldReconnect] indicates whether the reconnection attempts should be
|
|
||||||
/// automatically performed after a fatal failure of any kind occurs.
|
|
||||||
///
|
|
||||||
/// [waitForConnection] indicates whether the connection should wait for the "go"
|
|
||||||
/// signal from a registered connectivity manager.
|
|
||||||
///
|
|
||||||
/// If [waitUntilLogin] is set to true, the future will resolve when either
|
|
||||||
/// the connection has been successfully established (authentication included) or
|
|
||||||
/// a failure occured. If set to false, then the future will immediately resolve
|
|
||||||
/// to true.
|
|
||||||
///
|
|
||||||
/// [enableReconnectOnSuccess] indicates that automatic reconnection is to be
|
|
||||||
/// enabled once the connection has been successfully established.
|
|
||||||
Future<Result<bool, XmppConnectionError>> connect({
|
|
||||||
String? lastResource,
|
|
||||||
bool? shouldReconnect,
|
|
||||||
bool waitForConnection = false,
|
|
||||||
bool waitUntilLogin = false,
|
|
||||||
bool enableReconnectOnSuccess = true,
|
|
||||||
}) async {
|
|
||||||
if (_connectionState != XmppConnectionState.notConnected &&
|
|
||||||
_connectionState != XmppConnectionState.error) {
|
|
||||||
_log.fine(
|
|
||||||
'Cancelling this connection attempt as one appears to be already running.',
|
|
||||||
);
|
|
||||||
return Future.value(
|
|
||||||
Result(
|
|
||||||
ConnectionAlreadyRunningError(),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
final result = _connectImpl(
|
|
||||||
lastResource: lastResource,
|
|
||||||
shouldReconnect: shouldReconnect ?? !waitUntilLogin,
|
|
||||||
waitForConnection: waitForConnection,
|
|
||||||
waitUntilLogin: waitUntilLogin,
|
|
||||||
enableReconnectOnSuccess: enableReconnectOnSuccess,
|
|
||||||
);
|
|
||||||
if (waitUntilLogin) {
|
|
||||||
return result;
|
|
||||||
} else {
|
|
||||||
return Future.value(
|
|
||||||
const Result(
|
|
||||||
true,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import 'package:moxxmpp/src/errors.dart';
|
|
||||||
import 'package:moxxmpp/src/negotiators/negotiator.dart';
|
|
||||||
|
|
||||||
/// The reason a call to `XmppConnection.connect` failed.
|
|
||||||
abstract class XmppConnectionError {}
|
|
||||||
|
|
||||||
/// Returned by `XmppConnection.connect` when a connection is already active.
|
|
||||||
class ConnectionAlreadyRunningError extends XmppConnectionError {}
|
|
||||||
|
|
||||||
/// Returned by `XmppConnection.connect` when a negotiator returned an unrecoverable
|
|
||||||
/// error. Only returned when waitUntilLogin is true.
|
|
||||||
class NegotiatorReturnedError extends XmppConnectionError {
|
|
||||||
NegotiatorReturnedError(this.error);
|
|
||||||
|
|
||||||
/// The error returned by the negotiator.
|
|
||||||
final NegotiatorError error;
|
|
||||||
}
|
|
||||||
|
|
||||||
class StreamFailureError extends XmppConnectionError {
|
|
||||||
StreamFailureError(this.error);
|
|
||||||
|
|
||||||
/// The error that causes a connection failure.
|
|
||||||
final XmppError error;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returned by `XmppConnection.connect` when no connection could
|
|
||||||
/// be established.
|
|
||||||
class NoConnectionPossibleError extends XmppConnectionError {}
|
|
@ -1,5 +1,3 @@
|
|||||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
|
||||||
import 'package:meta/meta.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';
|
||||||
import 'package:moxxmpp/src/managers/base.dart';
|
import 'package:moxxmpp/src/managers/base.dart';
|
||||||
@ -132,10 +130,7 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO(PapaTutuWawa): This should return a Result<T> in case we cannot proceed
|
Future<PubSubPublishOptions> _preprocessPublishOptions(
|
||||||
// with the requested configuration.
|
|
||||||
@visibleForTesting
|
|
||||||
Future<PubSubPublishOptions> preprocessPublishOptions(
|
|
||||||
String jid,
|
String jid,
|
||||||
String node,
|
String node,
|
||||||
PubSubPublishOptions options,
|
PubSubPublishOptions options,
|
||||||
@ -290,7 +285,7 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
}) async {
|
}) async {
|
||||||
PubSubPublishOptions? pubOptions;
|
PubSubPublishOptions? pubOptions;
|
||||||
if (options != null) {
|
if (options != null) {
|
||||||
pubOptions = await preprocessPublishOptions(jid, node, options);
|
pubOptions = await _preprocessPublishOptions(jid, node, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await getAttributes().sendStanza(
|
final result = await getAttributes().sendStanza(
|
||||||
@ -315,11 +310,14 @@ class PubSubManager extends XmppManagerBase {
|
|||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
if (pubOptions != null)
|
...options != null
|
||||||
XMLNode(
|
? [
|
||||||
tag: 'publish-options',
|
XMLNode(
|
||||||
children: [pubOptions.toXml()],
|
tag: 'publish-options',
|
||||||
),
|
children: [options.toXml()],
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: [],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
name: moxxmpp
|
name: moxxmpp
|
||||||
description: A pure-Dart XMPP library
|
description: A pure-Dart XMPP library
|
||||||
version: 0.3.0
|
version: 0.2.0
|
||||||
homepage: https://codeberg.org/moxxy/moxxmpp
|
homepage: https://codeberg.org/moxxy/moxxmpp
|
||||||
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
publish_to: https://git.polynom.me/api/packages/Moxxy/pub
|
||||||
|
|
||||||
|
@ -5,8 +5,6 @@ void initLogger() {
|
|||||||
Logger.root.level = Level.ALL;
|
Logger.root.level = Level.ALL;
|
||||||
Logger.root.onRecord.listen((record) {
|
Logger.root.onRecord.listen((record) {
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print(
|
print('[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}');
|
||||||
'[${record.level.name}] (${record.loggerName}) ${record.time}: ${record.message}',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,70 +0,0 @@
|
|||||||
import 'dart:async';
|
|
||||||
import 'package:moxxmpp/src/connection.dart';
|
|
||||||
import 'package:moxxmpp/src/connectivity.dart';
|
|
||||||
import 'package:moxxmpp/src/jid.dart';
|
|
||||||
import 'package:moxxmpp/src/managers/attributes.dart';
|
|
||||||
import 'package:moxxmpp/src/managers/base.dart';
|
|
||||||
import 'package:moxxmpp/src/reconnect.dart';
|
|
||||||
import 'package:moxxmpp/src/settings.dart';
|
|
||||||
import 'package:moxxmpp/src/socket.dart';
|
|
||||||
import 'package:moxxmpp/src/stringxml.dart';
|
|
||||||
|
|
||||||
import '../helpers/xmpp.dart';
|
|
||||||
|
|
||||||
/// This class allows registering managers for easier testing.
|
|
||||||
class TestingManagerHolder {
|
|
||||||
TestingManagerHolder({
|
|
||||||
BaseSocketWrapper? socket,
|
|
||||||
}) : _socket = socket ?? StubTCPSocket([]);
|
|
||||||
|
|
||||||
final BaseSocketWrapper _socket;
|
|
||||||
|
|
||||||
final Map<String, XmppManagerBase> _managers = {};
|
|
||||||
|
|
||||||
static final JID jid = JID.fromString('testuser@example.org/abc123');
|
|
||||||
static final ConnectionSettings settings = ConnectionSettings(
|
|
||||||
jid: jid,
|
|
||||||
password: 'abc123',
|
|
||||||
useDirectTLS: true,
|
|
||||||
allowPlainAuth: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
Future<XMLNode> _sendStanza(
|
|
||||||
stanza, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
return XMLNode.fromString('<iq />');
|
|
||||||
}
|
|
||||||
|
|
||||||
T? _getManagerById<T extends XmppManagerBase>(String id) {
|
|
||||||
return _managers[id] as T?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> register(XmppManagerBase manager) async {
|
|
||||||
manager.register(
|
|
||||||
XmppManagerAttributes(
|
|
||||||
sendStanza: _sendStanza,
|
|
||||||
getConnection: () => XmppConnection(
|
|
||||||
TestingReconnectionPolicy(),
|
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
_socket,
|
|
||||||
),
|
|
||||||
getConnectionSettings: () => settings,
|
|
||||||
sendNonza: (_) {},
|
|
||||||
sendEvent: (_) {},
|
|
||||||
getSocket: () => _socket,
|
|
||||||
isFeatureSupported: (_) => false,
|
|
||||||
getNegotiatorById: getNegotiatorNullStub,
|
|
||||||
getFullJID: () => jid,
|
|
||||||
getManagerById: _getManagerById,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
await manager.postRegisterCallback();
|
|
||||||
_managers[manager.id] = manager;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +1,28 @@
|
|||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
|
|
||||||
bool compareXMLNodes(
|
bool compareXMLNodes(XMLNode actual, XMLNode expectation, { bool ignoreId = true}) {
|
||||||
XMLNode actual,
|
|
||||||
XMLNode expectation, {
|
|
||||||
bool ignoreId = true,
|
|
||||||
}) {
|
|
||||||
// Compare attributes
|
// Compare attributes
|
||||||
if (expectation.tag != actual.tag) return false;
|
if (expectation.tag != actual.tag) return false;
|
||||||
|
|
||||||
final attributesEqual = expectation.attributes.keys.every((key) {
|
final attributesEqual = expectation.attributes.keys.every((key) {
|
||||||
// Ignore the stanza ID
|
// Ignore the stanza ID
|
||||||
if (key == 'id' && ignoreId) return true;
|
if (key == 'id' && ignoreId) return true;
|
||||||
|
|
||||||
return actual.attributes[key] == expectation.attributes[key];
|
return actual.attributes[key] == expectation.attributes[key];
|
||||||
});
|
});
|
||||||
if (!attributesEqual) return false;
|
if (!attributesEqual) return false;
|
||||||
|
|
||||||
final actualAttributeLength = !ignoreId
|
final actualAttributeLength = !ignoreId ? actual.attributes.length : (
|
||||||
? actual.attributes.length
|
actual.attributes.containsKey('id') ? actual.attributes.length - 1 : actual.attributes.length
|
||||||
: (actual.attributes.containsKey('id')
|
);
|
||||||
? actual.attributes.length - 1
|
final expectedAttributeLength = !ignoreId ? expectation.attributes.length : (
|
||||||
: actual.attributes.length);
|
expectation.attributes.containsKey('id') ? expectation.attributes.length - 1 : expectation.attributes.length
|
||||||
final expectedAttributeLength = !ignoreId
|
);
|
||||||
? expectation.attributes.length
|
|
||||||
: (expectation.attributes.containsKey('id')
|
|
||||||
? expectation.attributes.length - 1
|
|
||||||
: expectation.attributes.length);
|
|
||||||
if (actualAttributeLength != expectedAttributeLength) return false;
|
if (actualAttributeLength != expectedAttributeLength) return false;
|
||||||
|
|
||||||
if (expectation.innerText() != '' &&
|
if (expectation.innerText() != '' && actual.innerText() != expectation.innerText()) return false;
|
||||||
actual.innerText() != expectation.innerText()) return false;
|
|
||||||
|
|
||||||
return expectation.children.every((childe) {
|
return expectation.children.every((childe) {
|
||||||
return actual.children.any((childa) => compareXMLNodes(childa, childe));
|
return actual.children.any((childa) => compareXMLNodes(childa, childe));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:convert';
|
|
||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
@ -14,8 +13,8 @@ T? getManagerNullStub<T extends XmppManagerBase>(String id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
abstract class ExpectationBase {
|
abstract class ExpectationBase {
|
||||||
ExpectationBase(this.expectation, this.response);
|
|
||||||
|
|
||||||
|
ExpectationBase(this.expectation, this.response);
|
||||||
final String expectation;
|
final String expectation;
|
||||||
final String response;
|
final String response;
|
||||||
|
|
||||||
@ -25,105 +24,36 @@ abstract class ExpectationBase {
|
|||||||
|
|
||||||
/// Literally compare the input with the expectation
|
/// Literally compare the input with the expectation
|
||||||
class StringExpectation extends ExpectationBase {
|
class StringExpectation extends ExpectationBase {
|
||||||
StringExpectation(super.expectation, super.response);
|
StringExpectation(String expectation, String response) : super(expectation, response);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool matches(String input) => input == expectation;
|
bool matches(String input) => input == expectation;
|
||||||
}
|
}
|
||||||
|
|
||||||
///
|
///
|
||||||
class StanzaExpectation extends ExpectationBase {
|
class StanzaExpectation extends ExpectationBase {
|
||||||
StanzaExpectation(
|
StanzaExpectation(String expectation, String response, {this.ignoreId = false, this.adjustId = false }) : super(expectation, response);
|
||||||
super.expectation,
|
|
||||||
super.response, {
|
|
||||||
this.ignoreId = false,
|
|
||||||
this.adjustId = false,
|
|
||||||
});
|
|
||||||
final bool ignoreId;
|
final bool ignoreId;
|
||||||
final bool adjustId;
|
final bool adjustId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool matches(String input) {
|
bool matches(String input) {
|
||||||
final ex = XMLNode.fromString(expectation);
|
final ex = XMLNode.fromString(expectation);
|
||||||
final recv = XMLNode.fromString(input);
|
final recv = XMLNode.fromString(expectation);
|
||||||
|
|
||||||
return compareXMLNodes(recv, ex, ignoreId: ignoreId);
|
return compareXMLNodes(recv, ex, ignoreId: ignoreId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use [settings] to build the beginning of a play that can be used with StubTCPSocket. [settings]'s allowPlainAuth must
|
class StubTCPSocket extends BaseSocketWrapper { // Request -> Response(s)
|
||||||
/// be set to true.
|
|
||||||
List<ExpectationBase> buildAuthenticatedPlay(ConnectionSettings settings) {
|
|
||||||
assert(settings.allowPlainAuth, 'SASL PLAIN must be allowed');
|
|
||||||
|
|
||||||
final plain = base64.encode(
|
|
||||||
utf8.encode('\u0000${settings.jid.local}\u0000${settings.password}'),
|
|
||||||
);
|
|
||||||
return [
|
|
||||||
StringExpectation(
|
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='${settings.jid.domain}' xml:lang='en'>",
|
|
||||||
'''
|
|
||||||
<stream:stream
|
|
||||||
xmlns="jabber:client"
|
|
||||||
version="1.0"
|
|
||||||
xmlns:stream="http://etherx.jabber.org/streams"
|
|
||||||
from="${settings.jid.domain}"
|
|
||||||
xml:lang="en">
|
|
||||||
<stream:features xmlns="http://etherx.jabber.org/streams">
|
|
||||||
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
|
|
||||||
<mechanism>PLAIN</mechanism>
|
|
||||||
</mechanisms>
|
|
||||||
</stream:features>''',
|
|
||||||
),
|
|
||||||
StringExpectation(
|
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>$plain</auth>",
|
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
|
||||||
),
|
|
||||||
StringExpectation(
|
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='${settings.jid.domain}' xml:lang='en'>",
|
|
||||||
'''
|
|
||||||
<stream:stream
|
|
||||||
xmlns="jabber:client"
|
|
||||||
version="1.0"
|
|
||||||
xmlns:stream="http://etherx.jabber.org/streams"
|
|
||||||
from="test.server"
|
|
||||||
xml:lang="en">
|
|
||||||
<stream:features xmlns="http://etherx.jabber.org/streams">
|
|
||||||
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
|
|
||||||
<required/>
|
|
||||||
</bind>
|
|
||||||
</stream:features>
|
|
||||||
''',
|
|
||||||
),
|
|
||||||
StanzaExpectation(
|
|
||||||
'<iq xmlns="jabber:client" type="set" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq>',
|
|
||||||
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>${settings.jid.toBare()}/MU29eEZn</jid></bind></iq>',
|
|
||||||
ignoreId: true,
|
|
||||||
),
|
|
||||||
StanzaExpectation(
|
|
||||||
"<presence xmlns='jabber:client' from='${settings.jid.toBare()}/MU29eEZn'><show>chat</show></presence>",
|
|
||||||
'',
|
|
||||||
),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
class StubTCPSocket extends BaseSocketWrapper {
|
|
||||||
// Request -> Response(s)
|
|
||||||
StubTCPSocket(this._play);
|
|
||||||
|
|
||||||
StubTCPSocket.authenticated(
|
|
||||||
ConnectionSettings settings,
|
|
||||||
List<ExpectationBase> play,
|
|
||||||
) : _play = [
|
|
||||||
...buildAuthenticatedPlay(settings),
|
|
||||||
...play,
|
|
||||||
];
|
|
||||||
|
|
||||||
|
StubTCPSocket({ required List<ExpectationBase> play })
|
||||||
|
: _play = play,
|
||||||
|
_dataStream = StreamController<String>.broadcast(),
|
||||||
|
_eventStream = StreamController<XmppSocketEvent>.broadcast();
|
||||||
int _state = 0;
|
int _state = 0;
|
||||||
final StreamController<String> _dataStream =
|
final StreamController<String> _dataStream;
|
||||||
StreamController<String>.broadcast();
|
final StreamController<XmppSocketEvent> _eventStream;
|
||||||
final StreamController<XmppSocketEvent> _eventStream =
|
|
||||||
StreamController<XmppSocketEvent>.broadcast();
|
|
||||||
final List<ExpectationBase> _play;
|
final List<ExpectationBase> _play;
|
||||||
String? lastId;
|
String? lastId;
|
||||||
|
|
||||||
@ -132,26 +62,24 @@ class StubTCPSocket extends BaseSocketWrapper {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> secure(String domain) async => true;
|
Future<bool> secure(String domain) async => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<bool> connect(String domain, {String? host, int? port}) async => true;
|
Future<bool> connect(String domain, { String? host, int? port }) async => true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Stream<String> getDataStream() => _dataStream.stream.asBroadcastStream();
|
Stream<String> getDataStream() => _dataStream.stream.asBroadcastStream();
|
||||||
@override
|
@override
|
||||||
Stream<XmppSocketEvent> getEventStream() =>
|
Stream<XmppSocketEvent> getEventStream() => _eventStream.stream.asBroadcastStream();
|
||||||
_eventStream.stream.asBroadcastStream();
|
|
||||||
|
|
||||||
/// Let the "connection" receive [data].
|
/// Let the "connection" receive [data].
|
||||||
void injectRawXml(String data) {
|
void injectRawXml(String data) {
|
||||||
// ignore: avoid_print
|
|
||||||
print('<== $data');
|
print('<== $data');
|
||||||
_dataStream.add(data);
|
_dataStream.add(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void write(Object? object, {String? redact}) {
|
void write(Object? object, { String? redact }) {
|
||||||
var str = object! as String;
|
var str = object as String;
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print('==> $str');
|
print('==> $str');
|
||||||
|
|
||||||
@ -162,7 +90,7 @@ class StubTCPSocket extends BaseSocketWrapper {
|
|||||||
|
|
||||||
final expectation = _play[_state];
|
final expectation = _play[_state];
|
||||||
|
|
||||||
// TODO(Unknown): Implement an XML matcher
|
// TODO: Implement an XML matcher
|
||||||
if (str.startsWith("<?xml version='1.0'?>")) {
|
if (str.startsWith("<?xml version='1.0'?>")) {
|
||||||
str = str.substring(21);
|
str = str.substring(21);
|
||||||
}
|
}
|
||||||
@ -171,11 +99,9 @@ class StubTCPSocket extends BaseSocketWrapper {
|
|||||||
str = str.substring(0, str.length - 16);
|
str = str.substring(0, str.length - 16);
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(
|
if (!expectation.matches(str)) {
|
||||||
expectation.matches(str),
|
expect(true, false, reason: 'Expected ${expectation.expectation}, got $str');
|
||||||
true,
|
}
|
||||||
reason: 'Expected ${expectation.expectation}, got $str',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Make sure to only progress if everything passed so far
|
// Make sure to only progress if everything passed so far
|
||||||
_state++;
|
_state++;
|
||||||
@ -183,24 +109,23 @@ class StubTCPSocket extends BaseSocketWrapper {
|
|||||||
var response = expectation.response;
|
var response = expectation.response;
|
||||||
if (expectation is StanzaExpectation) {
|
if (expectation is StanzaExpectation) {
|
||||||
final inputNode = XMLNode.fromString(str);
|
final inputNode = XMLNode.fromString(str);
|
||||||
lastId = inputNode.attributes['id'] as String?;
|
lastId = inputNode.attributes['id'];
|
||||||
|
|
||||||
if (expectation.adjustId) {
|
if (expectation.adjustId) {
|
||||||
final outputNode = XMLNode.fromString(response);
|
final outputNode = XMLNode.fromString(response);
|
||||||
|
|
||||||
outputNode.attributes['id'] = inputNode.attributes['id'];
|
outputNode.attributes['id'] = inputNode.attributes['id']!;
|
||||||
response = outputNode.toXml();
|
response = outputNode.toXml();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ignore: avoid_print
|
print("<== $response");
|
||||||
print('<== $response');
|
|
||||||
_dataStream.add(response);
|
_dataStream.add(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void close() {}
|
void close() {}
|
||||||
|
|
||||||
int getState() => _state;
|
int getState() => _state;
|
||||||
void resetState() => _state = 0;
|
void resetState() => _state = 0;
|
||||||
|
|
||||||
|
@ -29,52 +29,4 @@ void main() {
|
|||||||
expect(compareXMLNodes(node1.firstTag('body')!, XMLNode.fromString('<body>Hallo</body>')), true);
|
expect(compareXMLNodes(node1.firstTag('body')!, XMLNode.fromString('<body>Hallo</body>')), true);
|
||||||
expect(compareXMLNodes(node1.firstTagByXmlns('a')!, XMLNode.fromString('<a xmlns="a" />')), true);
|
expect(compareXMLNodes(node1.firstTagByXmlns('a')!, XMLNode.fromString('<a xmlns="a" />')), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test compareXMLNodes', () {
|
|
||||||
final node1 = XMLNode.fromString('''
|
|
||||||
<iq type='set' id='0327c373-2e34-46bd-ab7f-1274a6f7095f' to='pubsub.server.example.org' from='testuser@example.org/MU29eEZn' xmlns='jabber:client'>
|
|
||||||
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
||||||
<publish node='princely_musings'>
|
|
||||||
<item id='current'>
|
|
||||||
<test-item />
|
|
||||||
</item>
|
|
||||||
</publish>
|
|
||||||
<publish-options >
|
|
||||||
<x xmlns='jabber:x:data' type='submit'>
|
|
||||||
<field var='FORM_TYPE' type='hidden'>
|
|
||||||
<value>http://jabber.org/protocol/pubsub#publish-options</value>
|
|
||||||
</field>
|
|
||||||
<field var='pubsub#max_items'>
|
|
||||||
<value>max</value>
|
|
||||||
</field>
|
|
||||||
</x>
|
|
||||||
</publish-options>
|
|
||||||
</pubsub>
|
|
||||||
</iq>
|
|
||||||
''',
|
|
||||||
);
|
|
||||||
final node2 = XMLNode.fromString('''
|
|
||||||
<iq type="set" to="pubsub.server.example.org" id="a">
|
|
||||||
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
||||||
<publish node='princely_musings'>
|
|
||||||
<item id="current">
|
|
||||||
<test-item />
|
|
||||||
</item>
|
|
||||||
</publish>
|
|
||||||
<publish-options>
|
|
||||||
<x xmlns='jabber:x:data' type='submit'>
|
|
||||||
<field var='FORM_TYPE' type='hidden'>
|
|
||||||
<value>http://jabber.org/protocol/pubsub#publish-options</value>
|
|
||||||
</field>
|
|
||||||
<field var='pubsub#max_items'>
|
|
||||||
<value>1</value>
|
|
||||||
</field>
|
|
||||||
</x>
|
|
||||||
</publish-options>
|
|
||||||
</pubsub>
|
|
||||||
</iq>
|
|
||||||
''');
|
|
||||||
|
|
||||||
expect(compareXMLNodes(node1, node2, ignoreId: true), false);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
@ -2,23 +2,121 @@ import 'package:moxxmpp/moxxmpp.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
import '../helpers/logging.dart';
|
import '../helpers/logging.dart';
|
||||||
import '../helpers/manager.dart';
|
|
||||||
import '../helpers/xmpp.dart';
|
import '../helpers/xmpp.dart';
|
||||||
|
|
||||||
class StubbedDiscoManager extends DiscoManager {
|
class StubbedDiscoManager extends DiscoManager {
|
||||||
StubbedDiscoManager(this._itemError) : super([]);
|
StubbedDiscoManager() : super([]);
|
||||||
|
|
||||||
final bool _itemError;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(String entity, { String? node, bool shouldEncrypt = true }) async {
|
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(String entity, { String? node, bool shouldEncrypt = true }) async {
|
||||||
final result = DiscoInfo.fromQuery(
|
final result = DiscoInfo.fromQuery(
|
||||||
XMLNode.fromString(
|
XMLNode.fromString(
|
||||||
'''
|
'''<query xmlns='http://jabber.org/protocol/disco#info'>
|
||||||
<query xmlns='http://jabber.org/protocol/disco#info'>
|
<identity category='account' type='registered'/>
|
||||||
<identity category='pubsub' type='service' />
|
<identity type='service' category='pubsub' name='PubSub acs-clustered'/>
|
||||||
<feature var="http://jabber.org/protocol/pubsub" />
|
<feature var='http://jabber.org/protocol/pubsub#retrieve-default'/>
|
||||||
<feature var="http://jabber.org/protocol/pubsub#multi-items" />
|
<feature var='http://jabber.org/protocol/pubsub#purge-nodes'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#subscribe'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#member-affiliation'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#subscription-notifications'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#create-nodes'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#outcast-affiliation'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#get-pending'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#presence-notifications'/>
|
||||||
|
<feature var='urn:xmpp:ping'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#delete-nodes'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#config-node'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#retrieve-items'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#access-whitelist'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#access-presence'/>
|
||||||
|
<feature var='http://jabber.org/protocol/disco#items'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#meta-data'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#multi-items'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#item-ids'/>
|
||||||
|
<feature var='urn:xmpp:mam:1'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#instant-nodes'/>
|
||||||
|
<feature var='urn:xmpp:mam:2'/>
|
||||||
|
<feature var='urn:xmpp:mam:2#extended'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#modify-affiliations'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#multi-collection'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#persistent-items'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#create-and-configure'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#publisher-affiliation'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#access-open'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#retrieve-affiliations'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#access-authorize'/>
|
||||||
|
<feature var='jabber:iq:version'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#retract-items'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#manage-subscriptions'/>
|
||||||
|
<feature var='http://jabber.org/protocol/commands'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#auto-subscribe'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#publish-options'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#access-roster'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#publish'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#collections'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#retrieve-subscriptions'/>
|
||||||
|
<feature var='http://jabber.org/protocol/disco#info'/>
|
||||||
|
<x type='result' xmlns='jabber:x:data'>
|
||||||
|
<field type='hidden' var='FORM_TYPE'>
|
||||||
|
<value>http://jabber.org/network/serverinfo</value>
|
||||||
|
</field>
|
||||||
|
<field type='list-multi' var='abuse-addresses'>
|
||||||
|
<value>mailto:support@tigase.net</value>
|
||||||
|
<value>xmpp:tigase@mix.tigase.im</value>
|
||||||
|
<value>xmpp:tigase@muc.tigase.org</value>
|
||||||
|
<value>https://tigase.net/technical-support</value>
|
||||||
|
</field>
|
||||||
|
</x>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#auto-create'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#auto-subscribe'/>
|
||||||
|
<feature var='urn:xmpp:mix:pam:2'/>
|
||||||
|
<feature var='urn:xmpp:carbons:2'/>
|
||||||
|
<feature var='urn:xmpp:carbons:rules:0'/>
|
||||||
|
<feature var='jabber:iq:auth'/>
|
||||||
|
<feature var='vcard-temp'/>
|
||||||
|
<feature var='http://jabber.org/protocol/amp'/>
|
||||||
|
<feature var='msgoffline'/>
|
||||||
|
<feature var='http://jabber.org/protocol/disco#info'/>
|
||||||
|
<feature var='http://jabber.org/protocol/disco#items'/>
|
||||||
|
<feature var='urn:xmpp:blocking'/>
|
||||||
|
<feature var='urn:xmpp:reporting:0'/>
|
||||||
|
<feature var='urn:xmpp:reporting:abuse:0'/>
|
||||||
|
<feature var='urn:xmpp:reporting:spam:0'/>
|
||||||
|
<feature var='urn:xmpp:reporting:1'/>
|
||||||
|
<feature var='urn:xmpp:ping'/>
|
||||||
|
<feature var='urn:ietf:params:xml:ns:xmpp-sasl'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#owner'/>
|
||||||
|
<feature var='http://jabber.org/protocol/pubsub#publish'/>
|
||||||
|
<identity type='pep' category='pubsub'/>
|
||||||
|
<feature var='urn:xmpp:pep-vcard-conversion:0'/>
|
||||||
|
<feature var='urn:xmpp:bookmarks-conversion:0'/>
|
||||||
|
<feature var='urn:xmpp:archive:auto'/>
|
||||||
|
<feature var='urn:xmpp:archive:manage'/>
|
||||||
|
<feature var='urn:xmpp:push:0'/>
|
||||||
|
<feature var='tigase:push:away:0'/>
|
||||||
|
<feature var='tigase:push:encrypt:0'/>
|
||||||
|
<feature var='tigase:push:encrypt:aes-128-gcm'/>
|
||||||
|
<feature var='tigase:push:filter:ignore-unknown:0'/>
|
||||||
|
<feature var='tigase:push:filter:groupchat:0'/>
|
||||||
|
<feature var='tigase:push:filter:muted:0'/>
|
||||||
|
<feature var='tigase:push:priority:0'/>
|
||||||
|
<feature var='tigase:push:jingle:0'/>
|
||||||
|
<feature var='jabber:iq:roster'/>
|
||||||
|
<feature var='jabber:iq:roster-dynamic'/>
|
||||||
|
<feature var='urn:xmpp:mam:1'/>
|
||||||
|
<feature var='urn:xmpp:mam:2'/>
|
||||||
|
<feature var='urn:xmpp:mam:2#extended'/>
|
||||||
|
<feature var='urn:xmpp:mix:pam:2#archive'/>
|
||||||
|
<feature var='jabber:iq:version'/>
|
||||||
|
<feature var='urn:xmpp:time'/>
|
||||||
|
<feature var='jabber:iq:privacy'/>
|
||||||
|
<feature var='urn:ietf:params:xml:ns:xmpp-bind'/>
|
||||||
|
<feature var='urn:xmpp:extdisco:2'/>
|
||||||
|
<feature var='http://jabber.org/protocol/commands'/>
|
||||||
|
<feature var='urn:ietf:params:xml:ns:vcard-4.0'/>
|
||||||
|
<feature var='jabber:iq:private'/>
|
||||||
|
<feature var='urn:ietf:params:xml:ns:xmpp-session'/>
|
||||||
</query>'''
|
</query>'''
|
||||||
),
|
),
|
||||||
JID.fromString('pubsub.server.example.org'),
|
JID.fromString('pubsub.server.example.org'),
|
||||||
@ -26,156 +124,49 @@ class StubbedDiscoManager extends DiscoManager {
|
|||||||
|
|
||||||
return Result(result);
|
return Result(result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
T? getDiscoManagerStub<T extends XmppManagerBase>(String id) {
|
||||||
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(String entity, {String? node, bool shouldEncrypt = true}) async {
|
return StubbedDiscoManager() as T;
|
||||||
if (_itemError) {
|
|
||||||
return Result(
|
|
||||||
UnknownDiscoError(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return const Result<DiscoError, List<DiscoItem>>(
|
|
||||||
<DiscoItem>[],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
initLogger();
|
initLogger();
|
||||||
|
|
||||||
test('Test pre-processing with pubsub#max_items when the server does not support it (1/2)', () async {
|
|
||||||
final manager = PubSubManager();
|
|
||||||
final TestingManagerHolder tm = TestingManagerHolder();
|
|
||||||
await tm.register(StubbedDiscoManager(false));
|
|
||||||
await tm.register(manager);
|
|
||||||
|
|
||||||
final result = await manager.preprocessPublishOptions(
|
|
||||||
'pubsub.server.example.org',
|
|
||||||
'urn:xmpp:omemo:2:bundles',
|
|
||||||
const PubSubPublishOptions(maxItems: 'max'),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.maxItems, '1');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Test pre-processing with pubsub#max_items when the server does not support it (2/2)', () async {
|
|
||||||
final manager = PubSubManager();
|
|
||||||
final TestingManagerHolder tm = TestingManagerHolder();
|
|
||||||
await tm.register(StubbedDiscoManager(true));
|
|
||||||
await tm.register(manager);
|
|
||||||
|
|
||||||
final result = await manager.preprocessPublishOptions(
|
|
||||||
'pubsub.server.example.org',
|
|
||||||
'urn:xmpp:omemo:2:bundles',
|
|
||||||
const PubSubPublishOptions(maxItems: 'max'),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.maxItems, '1');
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Test publishing with pubsub#max_items when the server does not support it', () async {
|
test('Test publishing with pubsub#max_items when the server does not support it', () async {
|
||||||
final socket = StubTCPSocket.authenticated(
|
XMLNode? sent;
|
||||||
TestingManagerHolder.settings,
|
final manager = PubSubManager();
|
||||||
[
|
manager.register(
|
||||||
StanzaExpectation(
|
XmppManagerAttributes(
|
||||||
'''
|
sendStanza: (stanza, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async {
|
||||||
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
|
sent = stanza;
|
||||||
<query xmlns="http://jabber.org/protocol/disco#info" />
|
|
||||||
</iq>
|
return XMLNode.fromString('<iq />');
|
||||||
''',
|
},
|
||||||
'''
|
sendNonza: (_) {},
|
||||||
<iq type="result" from="pubsub.server.example.org" id="a" xmlns="jabber:client">
|
sendEvent: (_) {},
|
||||||
<query xmlns="http://jabber.org/protocol/disco#info">
|
getManagerById: getDiscoManagerStub,
|
||||||
<identity category='pubsub' type='service' />
|
getConnectionSettings: () => ConnectionSettings(
|
||||||
<feature var="http://jabber.org/protocol/pubsub" />
|
jid: JID.fromString('hallo@example.server'),
|
||||||
<feature var="http://jabber.org/protocol/pubsub#multi-items" />
|
password: 'password',
|
||||||
</query>
|
useDirectTLS: true,
|
||||||
</iq>
|
allowPlainAuth: false,
|
||||||
''',
|
|
||||||
ignoreId: true,
|
|
||||||
adjustId: true,
|
|
||||||
),
|
),
|
||||||
StanzaExpectation(
|
isFeatureSupported: (_) => false,
|
||||||
'''
|
getFullJID: () => JID.fromString('hallo@example.server/uwu'),
|
||||||
<iq type="get" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
|
getSocket: () => StubTCPSocket(play: []),
|
||||||
<query xmlns="http://jabber.org/protocol/disco#items" node="princely_musings" />
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
|
||||||
</iq>
|
getNegotiatorById: getNegotiatorNullStub,
|
||||||
''',
|
),
|
||||||
'''
|
|
||||||
<iq type="result" from="pubsub.server.example.org" id="a" xmlns="jabber:client">
|
|
||||||
<query xmlns="http://jabber.org/protocol/disco#items" node="princely_musings" />
|
|
||||||
</iq>
|
|
||||||
''',
|
|
||||||
ignoreId: true,
|
|
||||||
adjustId: true,
|
|
||||||
),
|
|
||||||
StanzaExpectation(
|
|
||||||
'''
|
|
||||||
<iq type="set" to="pubsub.server.example.org" id="a" from="testuser@example.org/MU29eEZn" xmlns="jabber:client">
|
|
||||||
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
||||||
<publish node='princely_musings'>
|
|
||||||
<item id="current">
|
|
||||||
<test-item />
|
|
||||||
</item>
|
|
||||||
</publish>
|
|
||||||
<publish-options>
|
|
||||||
<x xmlns='jabber:x:data' type='submit'>
|
|
||||||
<field var='FORM_TYPE' type='hidden'>
|
|
||||||
<value>http://jabber.org/protocol/pubsub#publish-options</value>
|
|
||||||
</field>
|
|
||||||
<field var='pubsub#max_items'>
|
|
||||||
<value>1</value>
|
|
||||||
</field>
|
|
||||||
</x>
|
|
||||||
</publish-options>
|
|
||||||
</pubsub>
|
|
||||||
</iq>''',
|
|
||||||
'''
|
|
||||||
<iq type="result" from="pubsub.server.example.org" id="a" xmlns="jabber:client">
|
|
||||||
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
|
||||||
<publish node='princely_musings'>
|
|
||||||
<item id='current'/>
|
|
||||||
</publish>
|
|
||||||
</pubsub>
|
|
||||||
</iq>''',
|
|
||||||
ignoreId: true,
|
|
||||||
adjustId: true,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
);
|
||||||
|
|
||||||
final connection = XmppConnection(
|
final result = await manager.preprocessPublishOptions(
|
||||||
TestingReconnectionPolicy(),
|
'pubsub.server.example.org',
|
||||||
AlwaysConnectedConnectivityManager(),
|
'example:node',
|
||||||
socket,
|
PubSubPublishOptions(
|
||||||
);
|
maxItems: 'max',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await connection.registerManagers([
|
|
||||||
PubSubManager(),
|
|
||||||
DiscoManager([]),
|
|
||||||
PresenceManager(),
|
|
||||||
MessageManager(),
|
|
||||||
RosterManager(TestingRosterStateManager(null, [])),
|
|
||||||
PingManager(),
|
|
||||||
]);
|
|
||||||
connection..registerFeatureNegotiators([
|
|
||||||
SaslPlainNegotiator(),
|
|
||||||
ResourceBindingNegotiator(),
|
|
||||||
])
|
|
||||||
..setConnectionSettings(TestingManagerHolder.settings);
|
|
||||||
await connection.connect(
|
|
||||||
waitUntilLogin: true,
|
|
||||||
);
|
|
||||||
|
|
||||||
final item = XMLNode(tag: "test-item");
|
|
||||||
final result = await connection.getManagerById<PubSubManager>(pubsubManager)!.publish(
|
|
||||||
'pubsub.server.example.org',
|
|
||||||
'princely_musings',
|
|
||||||
item,
|
|
||||||
id: 'current',
|
|
||||||
options: const PubSubPublishOptions(maxItems: 'max'),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.isType<bool>(), true);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user