Compare commits
No commits in common. "e1e492832e4733443d0c36e3c958b131457fd80c" and "308f7d93f5cfc5c5b46e9eeb4bdb20c9ae02ea5e" have entirely different histories.
e1e492832e
...
308f7d93f5
2
.gitlint
2
.gitlint
@ -7,7 +7,7 @@ line-length=72
|
|||||||
[title-trailing-punctuation]
|
[title-trailing-punctuation]
|
||||||
[title-hard-tab]
|
[title-hard-tab]
|
||||||
[title-match-regex]
|
[title-match-regex]
|
||||||
regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core|example)+(,(meta|tests|style|docs|xep|core|example))*\)|release): [A-Z0-9].*$
|
regex=^((feat|fix|chore|refactor|docs|release|test)\((meta|tests|style|docs|xep|core)+(,(meta|tests|style|docs|xep|core))*\)|release): [A-Z0-9].*$
|
||||||
|
|
||||||
|
|
||||||
[body-trailing-whitespace]
|
[body-trailing-whitespace]
|
||||||
|
@ -11,3 +11,5 @@ analyzer:
|
|||||||
exclude:
|
exclude:
|
||||||
- "**/*.g.dart"
|
- "**/*.g.dart"
|
||||||
- "**/*.freezed.dart"
|
- "**/*.freezed.dart"
|
||||||
|
- "test/"
|
||||||
|
- "integration_test/"
|
||||||
|
@ -167,7 +167,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, XmppError>>? _connectionCompleter;
|
Completer<Result<bool, XmppConnectionError>>? _connectionCompleter;
|
||||||
|
|
||||||
/// Negotiators
|
/// Negotiators
|
||||||
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators = {};
|
final Map<String, XmppFeatureNegotiatorBase> _featureNegotiators = {};
|
||||||
@ -896,8 +896,7 @@ class XmppConnection {
|
|||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
_log.severe(
|
_log.severe(
|
||||||
'No negotiator could be picked while negotiations are not done',
|
'No negotiator could be picked while negotiations are not done');
|
||||||
);
|
|
||||||
await _resetIsConnectionRunning();
|
await _resetIsConnectionRunning();
|
||||||
await handleError(NoAuthenticatorAvailableError());
|
await handleError(NoAuthenticatorAvailableError());
|
||||||
return;
|
return;
|
||||||
@ -1133,7 +1132,7 @@ class XmppConnection {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Result<bool, XmppError>> _connectImpl({
|
Future<Result<bool, XmppConnectionError>> _connectImpl({
|
||||||
String? lastResource,
|
String? lastResource,
|
||||||
bool waitForConnection = false,
|
bool waitForConnection = false,
|
||||||
bool shouldReconnect = true,
|
bool shouldReconnect = true,
|
||||||
@ -1223,7 +1222,7 @@ class XmppConnection {
|
|||||||
///
|
///
|
||||||
/// [enableReconnectOnSuccess] indicates that automatic reconnection is to be
|
/// [enableReconnectOnSuccess] indicates that automatic reconnection is to be
|
||||||
/// enabled once the connection has been successfully established.
|
/// enabled once the connection has been successfully established.
|
||||||
Future<Result<bool, XmppError>> connect({
|
Future<Result<bool, XmppConnectionError>> connect({
|
||||||
String? lastResource,
|
String? lastResource,
|
||||||
bool? shouldReconnect,
|
bool? shouldReconnect,
|
||||||
bool waitForConnection = false,
|
bool waitForConnection = false,
|
||||||
|
@ -4,28 +4,13 @@ import 'package:test/test.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
test('Test the async queue', () async {
|
test('Test the async queue', () async {
|
||||||
final queue = AsyncQueue();
|
final queue = AsyncQueue();
|
||||||
var future1Finish = 0;
|
int future1Finish = 0;
|
||||||
var future2Finish = 0;
|
int future2Finish = 0;
|
||||||
var future3Finish = 0;
|
int future3Finish = 0;
|
||||||
|
|
||||||
await queue.addJob(
|
await queue.addJob(() => Future<void>.delayed(const Duration(seconds: 3), () => future1Finish = DateTime.now().millisecondsSinceEpoch));
|
||||||
() => Future<void>.delayed(
|
await queue.addJob(() => Future<void>.delayed(const Duration(seconds: 3), () => future2Finish = DateTime.now().millisecondsSinceEpoch));
|
||||||
const Duration(seconds: 3),
|
await queue.addJob(() => Future<void>.delayed(const Duration(seconds: 3), () => future3Finish = DateTime.now().millisecondsSinceEpoch));
|
||||||
() => future1Finish = DateTime.now().millisecondsSinceEpoch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await queue.addJob(
|
|
||||||
() => Future<void>.delayed(
|
|
||||||
const Duration(seconds: 3),
|
|
||||||
() => future2Finish = DateTime.now().millisecondsSinceEpoch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
await queue.addJob(
|
|
||||||
() => Future<void>.delayed(
|
|
||||||
const Duration(seconds: 3),
|
|
||||||
() => future3Finish = DateTime.now().millisecondsSinceEpoch,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 12));
|
await Future<void>.delayed(const Duration(seconds: 12));
|
||||||
|
|
||||||
|
@ -3,38 +3,28 @@ import 'package:moxxmpp/src/awaiter.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const bareJid = JID('moxxmpp', 'server3.example', '');
|
final bareJid = JID('moxxmpp', 'server3.example', '');
|
||||||
|
|
||||||
test('Test awaiting an awaited stanza with a from attribute', () async {
|
test('Test awaiting an awaited stanza with a from attribute', () async {
|
||||||
final awaiter = StanzaAwaiter();
|
final awaiter = StanzaAwaiter();
|
||||||
|
|
||||||
// "Send" a stanza
|
// "Send" a stanza
|
||||||
final future = await awaiter.addPending(
|
final future = await awaiter.addPending('user1@server.example', 'abc123', 'iq');
|
||||||
'user1@server.example',
|
|
||||||
'abc123',
|
|
||||||
'iq',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Receive the wrong answer
|
// Receive the wrong answer
|
||||||
final result1 = await awaiter.onData(
|
final result1 = await awaiter.onData(
|
||||||
XMLNode.fromString(
|
XMLNode.fromString('<iq from="user3@server.example" id="abc123" type="result" />'),
|
||||||
'<iq from="user3@server.example" id="abc123" type="result" />',
|
|
||||||
),
|
|
||||||
bareJid,
|
bareJid,
|
||||||
);
|
);
|
||||||
expect(result1, false);
|
expect(result1, false);
|
||||||
final result2 = await awaiter.onData(
|
final result2 = await awaiter.onData(
|
||||||
XMLNode.fromString(
|
XMLNode.fromString('<iq from="user1@server.example" id="lol" type="result" />'),
|
||||||
'<iq from="user1@server.example" id="lol" type="result" />',
|
|
||||||
),
|
|
||||||
bareJid,
|
bareJid,
|
||||||
);
|
);
|
||||||
expect(result2, false);
|
expect(result2, false);
|
||||||
|
|
||||||
// Receive the correct answer
|
// Receive the correct answer
|
||||||
final stanza = XMLNode.fromString(
|
final stanza = XMLNode.fromString('<iq from="user1@server.example" id="abc123" type="result" />');
|
||||||
'<iq from="user1@server.example" id="abc123" type="result" />',
|
|
||||||
);
|
|
||||||
final result3 = await awaiter.onData(
|
final result3 = await awaiter.onData(
|
||||||
stanza,
|
stanza,
|
||||||
bareJid,
|
bareJid,
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Parse a full JID', () {
|
test('Parse a full JID', () {
|
||||||
final jid = JID.fromString('test@server/abc');
|
final jid = JID.fromString('test@server/abc');
|
||||||
@ -30,41 +29,23 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Equality', () {
|
test('Equality', () {
|
||||||
expect(
|
expect(JID.fromString('hallo@welt/abc') == JID('hallo', 'welt', 'abc'), true);
|
||||||
JID.fromString('hallo@welt/abc') == const JID('hallo', 'welt', 'abc'),
|
expect(JID.fromString('hallo@welt') == JID('hallo', 'welt', 'a'), false);
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
JID.fromString('hallo@welt') == const JID('hallo', 'welt', 'a'),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Dot suffix at domain part', () {
|
test('Dot suffix at domain part', () {
|
||||||
expect(
|
expect(JID.fromString('hallo@welt.example.') == JID('hallo', 'welt.example', ''), true);
|
||||||
JID.fromString('hallo@welt.example.') ==
|
expect(JID.fromString('hallo@welt.example./test') == JID('hallo', 'welt.example', 'test'), true);
|
||||||
const JID('hallo', 'welt.example', ''),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
JID.fromString('hallo@welt.example./test') ==
|
|
||||||
const JID('hallo', 'welt.example', 'test'),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Parse resource with a slash', () {
|
test('Parse resource with a slash', () {
|
||||||
expect(
|
expect(JID.fromString('hallo@welt.example./test/welt') == JID('hallo', 'welt.example', 'test/welt'), true);
|
||||||
JID.fromString('hallo@welt.example./test/welt') ==
|
|
||||||
const JID('hallo', 'welt.example', 'test/welt'),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bareCompare', () {
|
test('bareCompare', () {
|
||||||
const jid1 = JID('hallo', 'welt', 'lol');
|
final jid1 = JID('hallo', 'welt', 'lol');
|
||||||
const jid2 = JID('hallo', 'welt', '');
|
final jid2 = JID('hallo', 'welt', '');
|
||||||
const jid3 = JID('hallo', 'earth', 'true');
|
final jid3 = JID('hallo', 'earth', 'true');
|
||||||
|
|
||||||
expect(jid1.bareCompare(jid2), true);
|
expect(jid1.bareCompare(jid2), true);
|
||||||
expect(jid2.bareCompare(jid1), true);
|
expect(jid2.bareCompare(jid1), true);
|
||||||
|
@ -9,32 +9,24 @@ const exampleXmlns2 = 'im:moxxmpp:example2';
|
|||||||
const exampleNamespace2 = 'im.moxxmpp.test.example2';
|
const exampleNamespace2 = 'im.moxxmpp.test.example2';
|
||||||
|
|
||||||
class StubNegotiator1 extends XmppFeatureNegotiatorBase {
|
class StubNegotiator1 extends XmppFeatureNegotiatorBase {
|
||||||
StubNegotiator1()
|
StubNegotiator1() : called = false, super(1, false, exampleXmlns1, exampleNamespace1);
|
||||||
: called = false,
|
|
||||||
super(1, false, exampleXmlns1, exampleNamespace1);
|
|
||||||
|
|
||||||
bool called;
|
bool called;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<NegotiatorState, NegotiatorError>> negotiate(
|
Future<Result<NegotiatorState, NegotiatorError>> negotiate(XMLNode nonza) async {
|
||||||
XMLNode nonza,
|
|
||||||
) async {
|
|
||||||
called = true;
|
called = true;
|
||||||
return const Result(NegotiatorState.done);
|
return const Result(NegotiatorState.done);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class StubNegotiator2 extends XmppFeatureNegotiatorBase {
|
class StubNegotiator2 extends XmppFeatureNegotiatorBase {
|
||||||
StubNegotiator2()
|
StubNegotiator2() : called = false, super(10, false, exampleXmlns2, exampleNamespace2);
|
||||||
: called = false,
|
|
||||||
super(10, false, exampleXmlns2, exampleNamespace2);
|
|
||||||
|
|
||||||
bool called;
|
bool called;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<NegotiatorState, NegotiatorError>> negotiate(
|
Future<Result<NegotiatorState, NegotiatorError>> negotiate(XMLNode nonza) async {
|
||||||
XMLNode nonza,
|
|
||||||
) async {
|
|
||||||
called = true;
|
called = true;
|
||||||
return const Result(NegotiatorState.done);
|
return const Result(NegotiatorState.done);
|
||||||
}
|
}
|
||||||
@ -66,8 +58,7 @@ void main() {
|
|||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
stubSocket,
|
stubSocket,
|
||||||
)
|
)..registerFeatureNegotiators([
|
||||||
..registerFeatureNegotiators([
|
|
||||||
StubNegotiator1(),
|
StubNegotiator1(),
|
||||||
StubNegotiator2(),
|
StubNegotiator2(),
|
||||||
])
|
])
|
||||||
@ -97,10 +88,8 @@ void main() {
|
|||||||
test('Test negotiating features with no stream restarts', () async {
|
test('Test negotiating features with no stream restarts', () async {
|
||||||
await connection.connect();
|
await connection.connect();
|
||||||
await Future.delayed(const Duration(seconds: 3), () {
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
final negotiator1 =
|
final negotiator1 = connection.getNegotiatorById<StubNegotiator1>(exampleNamespace1);
|
||||||
connection.getNegotiatorById<StubNegotiator1>(exampleNamespace1);
|
final negotiator2 = connection.getNegotiatorById<StubNegotiator2>(exampleNamespace2);
|
||||||
final negotiator2 =
|
|
||||||
connection.getNegotiatorById<StubNegotiator2>(exampleNamespace2);
|
|
||||||
expect(negotiator1?.called, true);
|
expect(negotiator1?.called, true);
|
||||||
expect(negotiator2?.called, true);
|
expect(negotiator2?.called, true);
|
||||||
});
|
});
|
||||||
|
@ -3,11 +3,12 @@ import 'package:test/test.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Test receiving a roster push', () async {
|
test('Test receiving a roster push', () async {
|
||||||
final rs = TestingRosterStateManager(null, [])..register((_) {});
|
final rs = TestingRosterStateManager(null, []);
|
||||||
|
rs.register((_) {});
|
||||||
|
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushResult(
|
RosterPushResult(
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
@ -16,10 +17,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
rs
|
rs.getRosterItems().indexWhere((item) => item.jid == 'testuser@server.example') != -1,
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser@server.example') !=
|
|
||||||
-1,
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(rs.loadCount, 1);
|
expect(rs.loadCount, 1);
|
||||||
@ -28,7 +26,7 @@ void main() {
|
|||||||
// Receive another roster push
|
// Receive another roster push
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushResult(
|
RosterPushResult(
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'to',
|
subscription: 'to',
|
||||||
),
|
),
|
||||||
@ -37,10 +35,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
rs
|
rs.getRosterItems().indexWhere((item) => item.jid == 'testuser2@server2.example') != -1,
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser2@server2.example') !=
|
|
||||||
-1,
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(rs.loadCount, 1);
|
expect(rs.loadCount, 1);
|
||||||
@ -49,7 +44,7 @@ void main() {
|
|||||||
// Remove one of the items
|
// Remove one of the items
|
||||||
await rs.handleRosterPush(
|
await rs.handleRosterPush(
|
||||||
RosterPushResult(
|
RosterPushResult(
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'remove',
|
subscription: 'remove',
|
||||||
),
|
),
|
||||||
@ -58,17 +53,11 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
rs
|
rs.getRosterItems().indexWhere((item) => item.jid == 'testuser2@server2.example') == -1,
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser2@server2.example') ==
|
|
||||||
-1,
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
rs
|
rs.getRosterItems().indexWhere((item) => item.jid == 'testuser@server.example') != 1,
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser@server.example') !=
|
|
||||||
1,
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
expect(rs.loadCount, 1);
|
expect(rs.loadCount, 1);
|
||||||
@ -76,21 +65,22 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test a roster fetch', () async {
|
test('Test a roster fetch', () async {
|
||||||
final rs = TestingRosterStateManager(null, [])..register((_) {});
|
final rs = TestingRosterStateManager(null, []);
|
||||||
|
rs.register((_) {});
|
||||||
|
|
||||||
// Fetch the roster
|
// Fetch the roster
|
||||||
await rs.handleRosterFetch(
|
await rs.handleRosterFetch(
|
||||||
RosterRequestResult(
|
RosterRequestResult(
|
||||||
[
|
[
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'to',
|
subscription: 'to',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser3@server3.example',
|
jid: 'testuser3@server3.example',
|
||||||
subscription: 'from',
|
subscription: 'from',
|
||||||
),
|
),
|
||||||
@ -101,66 +91,48 @@ void main() {
|
|||||||
|
|
||||||
expect(rs.loadCount, 1);
|
expect(rs.loadCount, 1);
|
||||||
expect(rs.getRosterItems().length, 3);
|
expect(rs.getRosterItems().length, 3);
|
||||||
expect(
|
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser@server.example') != -1, true);
|
||||||
rs
|
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser2@server2.example') != -1, true);
|
||||||
.getRosterItems()
|
expect(rs.getRosterItems().indexWhere((item) => item.jid == 'testuser3@server3.example') != -1, true);
|
||||||
.indexWhere((item) => item.jid == 'testuser@server.example') !=
|
|
||||||
-1,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
rs
|
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser2@server2.example') !=
|
|
||||||
-1,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
rs
|
|
||||||
.getRosterItems()
|
|
||||||
.indexWhere((item) => item.jid == 'testuser3@server3.example') !=
|
|
||||||
-1,
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test a roster fetch if we already have a roster', () async {
|
test('Test a roster fetch if we already have a roster', () async {
|
||||||
XmppEvent? event;
|
XmppEvent? event;
|
||||||
final rs = TestingRosterStateManager('aaaaa', [
|
final rs = TestingRosterStateManager('aaaaa', [
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'to',
|
subscription: 'to',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser3@server3.example',
|
jid: 'testuser3@server3.example',
|
||||||
subscription: 'from',
|
subscription: 'from',
|
||||||
),
|
),
|
||||||
])
|
]);
|
||||||
..register((e) {
|
rs.register((_event) {
|
||||||
event = e;
|
event = _event;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fetch the roster
|
// Fetch the roster
|
||||||
await rs.handleRosterFetch(
|
await rs.handleRosterFetch(
|
||||||
RosterRequestResult(
|
RosterRequestResult(
|
||||||
[
|
[
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser@server.example',
|
jid: 'testuser@server.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser2@server2.example',
|
jid: 'testuser2@server2.example',
|
||||||
subscription: 'to',
|
subscription: 'to',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser3@server3.example',
|
jid: 'testuser3@server3.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
const XmppRosterItem(
|
XmppRosterItem(
|
||||||
jid: 'testuser4@server4.example',
|
jid: 'testuser4@server4.example',
|
||||||
subscription: 'both',
|
subscription: 'both',
|
||||||
),
|
),
|
||||||
@ -170,7 +142,7 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(event is RosterUpdatedEvent, true);
|
expect(event is RosterUpdatedEvent, true);
|
||||||
final updateEvent = event! as RosterUpdatedEvent;
|
final updateEvent = event as RosterUpdatedEvent;
|
||||||
|
|
||||||
expect(updateEvent.added.length, 1);
|
expect(updateEvent.added.length, 1);
|
||||||
expect(updateEvent.added.first.jid, 'testuser4@server4.example');
|
expect(updateEvent.added.first.jid, 'testuser4@server4.example');
|
||||||
|
@ -1,30 +1,27 @@
|
|||||||
import 'package:moxxmpp/src/negotiators/sasl/kv.dart';
|
import 'package:moxxmpp/src/negotiators/sasl/kv.dart';
|
||||||
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Test the Key-Value parser', () {
|
test('Test the Key-Value parser', () {
|
||||||
final result1 = parseKeyValue('n,,n=user,r=fyko+d2lbbFgONRv9qkxdawL');
|
final result1 = parseKeyValue('n,,n=user,r=fyko+d2lbbFgONRv9qkxdawL');
|
||||||
expect(result1.length, 2);
|
expect(result1.length, 2);
|
||||||
expect(result1['n'], 'user');
|
expect(result1['n']!, 'user');
|
||||||
expect(result1['r'], 'fyko+d2lbbFgONRv9qkxdawL');
|
expect(result1['r']!, 'fyko+d2lbbFgONRv9qkxdawL');
|
||||||
|
|
||||||
final result2 = parseKeyValue(
|
final result2 = parseKeyValue('r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096');
|
||||||
'r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096',
|
|
||||||
);
|
|
||||||
expect(result2.length, 3);
|
expect(result2.length, 3);
|
||||||
expect(result2['r'], 'fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j');
|
expect(result2['r']!, 'fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j');
|
||||||
expect(result2['s'], 'QSXCR+Q6sek8bf92');
|
expect(result2['s']!, 'QSXCR+Q6sek8bf92');
|
||||||
expect(result2['i'], '4096');
|
expect(result2['i']!, '4096');
|
||||||
});
|
});
|
||||||
|
|
||||||
test("Test the Key-Value parser with '=' as a value", () {
|
test("Test the Key-Value parser with '=' as a value", () {
|
||||||
final result = parseKeyValue(
|
final result = parseKeyValue('c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=,o=123');
|
||||||
'c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=,o=123',
|
|
||||||
);
|
|
||||||
expect(result.length, 4);
|
expect(result.length, 4);
|
||||||
expect(result['c'], 'biws');
|
expect(result['c']!, 'biws');
|
||||||
expect(result['r'], 'fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j');
|
expect(result['r']!, 'fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j');
|
||||||
expect(result['p'], 'v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=');
|
expect(result['p']!, 'v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=');
|
||||||
expect(result['o'], '123');
|
expect(result['o']!, '123');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -38,19 +38,11 @@ final scramSha256StreamFeatures = XMLNode(
|
|||||||
void main() {
|
void main() {
|
||||||
final fakeSocket = StubTCPSocket([]);
|
final fakeSocket = StubTCPSocket([]);
|
||||||
test('Test SASL SCRAM-SHA-1', () async {
|
test('Test SASL SCRAM-SHA-1', () async {
|
||||||
final negotiator = SaslScramNegotiator(
|
final negotiator = SaslScramNegotiator(0, 'n=user,r=fyko+d2lbbFgONRv9qkxdawL', 'fyko+d2lbbFgONRv9qkxdawL', ScramHashType.sha1);
|
||||||
0,
|
negotiator.register(
|
||||||
'n=user,r=fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
'fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
ScramHashType.sha1,
|
|
||||||
)..register(
|
|
||||||
NegotiatorAttributes(
|
NegotiatorAttributes(
|
||||||
(XMLNode _, {String? redact}) {},
|
(XMLNode _, {String? redact}) {},
|
||||||
() => ConnectionSettings(
|
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
|
||||||
jid: JID.fromString('user@server'),
|
|
||||||
password: 'pencil',
|
|
||||||
useDirectTLS: true,
|
|
||||||
),
|
|
||||||
(_) async {},
|
(_) async {},
|
||||||
getNegotiatorNullStub,
|
getNegotiatorNullStub,
|
||||||
getManagerNullStub,
|
getManagerNullStub,
|
||||||
@ -61,53 +53,37 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(await negotiator.calculateSaltedPassword('QSXCR+Q6sek8bf92', 4096)),
|
||||||
await negotiator.calculateSaltedPassword('QSXCR+Q6sek8bf92', 4096),
|
|
||||||
),
|
|
||||||
'1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d',
|
'1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d',
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(
|
||||||
await negotiator.calculateClientKey(
|
await negotiator.calculateClientKey(HEX.decode('1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d')),
|
||||||
HEX.decode('1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'e234c47bf6c36696dd6d852b99aaa2ba26555728',
|
'e234c47bf6c36696dd6d852b99aaa2ba26555728',
|
||||||
);
|
);
|
||||||
const authMessage =
|
const authMessage = 'n=user,r=fyko+d2lbbFgONRv9qkxdawL,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096,c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j';
|
||||||
'n=user,r=fyko+d2lbbFgONRv9qkxdawL,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,s=QSXCR+Q6sek8bf92,i=4096,c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j';
|
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(
|
||||||
await negotiator.calculateClientSignature(
|
await negotiator.calculateClientSignature(authMessage, HEX.decode('e9d94660c39d65c38fbad91c358f14da0eef2bd6')),
|
||||||
authMessage,
|
|
||||||
HEX.decode('e9d94660c39d65c38fbad91c358f14da0eef2bd6'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'5d7138c486b0bfabdf49e3e2da8bd6e5c79db613',
|
'5d7138c486b0bfabdf49e3e2da8bd6e5c79db613',
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(
|
||||||
negotiator.calculateClientProof(
|
negotiator.calculateClientProof(HEX.decode('e234c47bf6c36696dd6d852b99aaa2ba26555728'), HEX.decode('5d7138c486b0bfabdf49e3e2da8bd6e5c79db613')),
|
||||||
HEX.decode('e234c47bf6c36696dd6d852b99aaa2ba26555728'),
|
|
||||||
HEX.decode('5d7138c486b0bfabdf49e3e2da8bd6e5c79db613'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'bf45fcbf7073d93d022466c94321745fe1c8e13b',
|
'bf45fcbf7073d93d022466c94321745fe1c8e13b',
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(
|
||||||
await negotiator.calculateServerSignature(
|
await negotiator.calculateServerSignature(authMessage, HEX.decode('0fe09258b3ac852ba502cc62ba903eaacdbf7d31')),
|
||||||
authMessage,
|
|
||||||
HEX.decode('0fe09258b3ac852ba502cc62ba903eaacdbf7d31'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'ae617da6a57c4bbb2e0286568dae1d251905b0a4',
|
'ae617da6a57c4bbb2e0286568dae1d251905b0a4',
|
||||||
);
|
);
|
||||||
expect(
|
expect(
|
||||||
HEX.encode(
|
HEX.encode(
|
||||||
await negotiator.calculateServerKey(
|
await negotiator.calculateServerKey(HEX.decode('1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d')),
|
||||||
HEX.decode('1d96ee3a529b5a5f9e47c01f229a2cb8a6e15f7d'),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
'0fe09258b3ac852ba502cc62ba903eaacdbf7d31',
|
'0fe09258b3ac852ba502cc62ba903eaacdbf7d31',
|
||||||
);
|
);
|
||||||
@ -121,29 +97,16 @@ void main() {
|
|||||||
'bf45fcbf7073d93d022466c94321745fe1c8e13b',
|
'bf45fcbf7073d93d022466c94321745fe1c8e13b',
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(await negotiator.calculateChallengeResponse('cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng=='), 'c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=');
|
||||||
await negotiator.calculateChallengeResponse(
|
|
||||||
'cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==',
|
|
||||||
),
|
|
||||||
'c=biws,r=fyko+d2lbbFgONRv9qkxdawL3rfcNHYJY1ZVvWVs7j,p=v0X8v3Bz2T0CJGbJQyF0X+HI4Ts=',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test SASL SCRAM-SHA-256', () async {
|
test('Test SASL SCRAM-SHA-256', () async {
|
||||||
String? lastMessage;
|
String? lastMessage;
|
||||||
final negotiator = SaslScramNegotiator(
|
final negotiator = SaslScramNegotiator(0, 'n=user,r=rOprNGfwEbeRWgbNEkqO', 'rOprNGfwEbeRWgbNEkqO', ScramHashType.sha256);
|
||||||
0,
|
negotiator.register(
|
||||||
'n=user,r=rOprNGfwEbeRWgbNEkqO',
|
|
||||||
'rOprNGfwEbeRWgbNEkqO',
|
|
||||||
ScramHashType.sha256,
|
|
||||||
)..register(
|
|
||||||
NegotiatorAttributes(
|
NegotiatorAttributes(
|
||||||
(XMLNode n, {String? redact}) => lastMessage = n.innerText(),
|
(XMLNode n, {String? redact}) => lastMessage = n.innerText(),
|
||||||
() => ConnectionSettings(
|
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
|
||||||
jid: JID.fromString('user@server'),
|
|
||||||
password: 'pencil',
|
|
||||||
useDirectTLS: true,
|
|
||||||
),
|
|
||||||
(_) async {},
|
(_) async {},
|
||||||
getNegotiatorNullStub,
|
getNegotiatorNullStub,
|
||||||
getManagerNullStub,
|
getManagerNullStub,
|
||||||
@ -159,39 +122,23 @@ void main() {
|
|||||||
'n,,n=user,r=rOprNGfwEbeRWgbNEkqO',
|
'n,,n=user,r=rOprNGfwEbeRWgbNEkqO',
|
||||||
);
|
);
|
||||||
|
|
||||||
await negotiator.negotiate(
|
await negotiator.negotiate(XMLNode.fromString("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1yT3ByTkdmd0ViZVJXZ2JORWtxTyVodllEcFdVYTJSYVRDQWZ1eEZJbGopaE5sRiRrMCxzPVcyMlphSjBTTlk3c29Fc1VFamI2Z1E9PSxpPTQwOTY=</challenge>"));
|
||||||
XMLNode.fromString(
|
|
||||||
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1yT3ByTkdmd0ViZVJXZ2JORWtxTyVodllEcFdVYTJSYVRDQWZ1eEZJbGopaE5sRiRrMCxzPVcyMlphSjBTTlk3c29Fc1VFamI2Z1E9PSxpPTQwOTY=</challenge>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(
|
expect(
|
||||||
utf8.decode(base64Decode(lastMessage!)),
|
utf8.decode(base64Decode(lastMessage!)),
|
||||||
r'c=biws,r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF$k0,p=dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=',
|
'c=biws,r=rOprNGfwEbeRWgbNEkqO%hvYDpWUa2RaTCAfuxFIlj)hNlF\$k0,p=dHzbZapWIk4jUhN+Ute9ytag9zjfMHgsqmmiz7AndVQ=',
|
||||||
);
|
);
|
||||||
|
|
||||||
final result = await negotiator.negotiate(
|
final result = await negotiator.negotiate(XMLNode.fromString("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj02cnJpVFJCaTIzV3BSUi93dHVwK21NaFVaVW4vZEI1bkxUSlJzamw5NUc0PQ==</success>"));
|
||||||
XMLNode.fromString(
|
|
||||||
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj02cnJpVFJCaTIzV3BSUi93dHVwK21NaFVaVW4vZEI1bkxUSlJzamw5NUc0PQ==</success>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.get<NegotiatorState>(), NegotiatorState.done);
|
expect(result.get<NegotiatorState>(), NegotiatorState.done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test a positive server signature check', () async {
|
test('Test a positive server signature check', () async {
|
||||||
final negotiator = SaslScramNegotiator(
|
final negotiator = SaslScramNegotiator(0, 'n=user,r=fyko+d2lbbFgONRv9qkxdawL', 'fyko+d2lbbFgONRv9qkxdawL', ScramHashType.sha1);
|
||||||
0,
|
negotiator.register(
|
||||||
'n=user,r=fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
'fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
ScramHashType.sha1,
|
|
||||||
)..register(
|
|
||||||
NegotiatorAttributes(
|
NegotiatorAttributes(
|
||||||
(XMLNode _, {String? redact}) {},
|
(XMLNode _, {String? redact}) {},
|
||||||
() => ConnectionSettings(
|
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
|
||||||
jid: JID.fromString('user@server'),
|
|
||||||
password: 'pencil',
|
|
||||||
useDirectTLS: true,
|
|
||||||
),
|
|
||||||
(_) async {},
|
(_) async {},
|
||||||
getNegotiatorNullStub,
|
getNegotiatorNullStub,
|
||||||
getManagerNullStub,
|
getManagerNullStub,
|
||||||
@ -202,34 +149,18 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await negotiator.negotiate(scramSha1StreamFeatures);
|
await negotiator.negotiate(scramSha1StreamFeatures);
|
||||||
await negotiator.negotiate(
|
await negotiator.negotiate(XMLNode.fromString("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>"));
|
||||||
XMLNode.fromString(
|
final result = await negotiator.negotiate(XMLNode.fromString("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>"));
|
||||||
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final result = await negotiator.negotiate(
|
|
||||||
XMLNode.fromString(
|
|
||||||
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(result.get<NegotiatorState>(), NegotiatorState.done);
|
expect(result.get<NegotiatorState>(), NegotiatorState.done);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test a negative server signature check', () async {
|
test('Test a negative server signature check', () async {
|
||||||
final negotiator = SaslScramNegotiator(
|
final negotiator = SaslScramNegotiator(0, 'n=user,r=fyko+d2lbbFgONRv9qkxdawL', 'fyko+d2lbbFgONRv9qkxdawL', ScramHashType.sha1);
|
||||||
0,
|
negotiator.register(
|
||||||
'n=user,r=fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
'fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
ScramHashType.sha1,
|
|
||||||
)..register(
|
|
||||||
NegotiatorAttributes(
|
NegotiatorAttributes(
|
||||||
(XMLNode _, {String? redact}) {},
|
(XMLNode _, {String? redact}) {},
|
||||||
() => ConnectionSettings(
|
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
|
||||||
jid: JID.fromString('user@server'),
|
|
||||||
password: 'pencil',
|
|
||||||
useDirectTLS: true,
|
|
||||||
),
|
|
||||||
(_) async {},
|
(_) async {},
|
||||||
getNegotiatorNullStub,
|
getNegotiatorNullStub,
|
||||||
getManagerNullStub,
|
getManagerNullStub,
|
||||||
@ -239,38 +170,23 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
var result = await negotiator.negotiate(scramSha1StreamFeatures);
|
var result;
|
||||||
|
result = await negotiator.negotiate(scramSha1StreamFeatures);
|
||||||
expect(result.isType<NegotiatorState>(), true);
|
expect(result.isType<NegotiatorState>(), true);
|
||||||
|
|
||||||
result = await negotiator.negotiate(
|
result = await negotiator.negotiate(XMLNode.fromString("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>"));
|
||||||
XMLNode.fromString(
|
|
||||||
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(result.isType<NegotiatorState>(), true);
|
expect(result.isType<NegotiatorState>(), true);
|
||||||
|
|
||||||
result = await negotiator.negotiate(
|
result = await negotiator.negotiate(XMLNode.fromString("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1zbUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>"));
|
||||||
XMLNode.fromString(
|
|
||||||
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1zbUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(result.isType<NegotiatorError>(), true);
|
expect(result.isType<NegotiatorError>(), true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test a resetting the SCRAM negotiator', () async {
|
test('Test a resetting the SCRAM negotiator', () async {
|
||||||
final negotiator = SaslScramNegotiator(
|
final negotiator = SaslScramNegotiator(0, 'n=user,r=fyko+d2lbbFgONRv9qkxdawL', 'fyko+d2lbbFgONRv9qkxdawL', ScramHashType.sha1);
|
||||||
0,
|
negotiator.register(
|
||||||
'n=user,r=fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
'fyko+d2lbbFgONRv9qkxdawL',
|
|
||||||
ScramHashType.sha1,
|
|
||||||
)..register(
|
|
||||||
NegotiatorAttributes(
|
NegotiatorAttributes(
|
||||||
(XMLNode _, {String? redact}) {},
|
(XMLNode _, {String? redact}) {},
|
||||||
() => ConnectionSettings(
|
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
|
||||||
jid: JID.fromString('user@server'),
|
|
||||||
password: 'pencil',
|
|
||||||
useDirectTLS: true,
|
|
||||||
),
|
|
||||||
(_) async {},
|
(_) async {},
|
||||||
getNegotiatorNullStub,
|
getNegotiatorNullStub,
|
||||||
getManagerNullStub,
|
getManagerNullStub,
|
||||||
@ -281,31 +197,15 @@ void main() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
await negotiator.negotiate(scramSha1StreamFeatures);
|
await negotiator.negotiate(scramSha1StreamFeatures);
|
||||||
await negotiator.negotiate(
|
await negotiator.negotiate(XMLNode.fromString("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>"));
|
||||||
XMLNode.fromString(
|
final result1 = await negotiator.negotiate(XMLNode.fromString("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>"));
|
||||||
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final result1 = await negotiator.negotiate(
|
|
||||||
XMLNode.fromString(
|
|
||||||
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(result1.get<NegotiatorState>(), NegotiatorState.done);
|
expect(result1.get<NegotiatorState>(), NegotiatorState.done);
|
||||||
|
|
||||||
// Reset and try again
|
// Reset and try again
|
||||||
negotiator.reset();
|
negotiator.reset();
|
||||||
await negotiator.negotiate(scramSha1StreamFeatures);
|
await negotiator.negotiate(scramSha1StreamFeatures);
|
||||||
await negotiator.negotiate(
|
await negotiator.negotiate(XMLNode.fromString("<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>"));
|
||||||
XMLNode.fromString(
|
final result2 = await negotiator.negotiate(XMLNode.fromString("<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>"));
|
||||||
"<challenge xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>cj1meWtvK2QybGJiRmdPTlJ2OXFreGRhd0wzcmZjTkhZSlkxWlZ2V1ZzN2oscz1RU1hDUitRNnNlazhiZjkyLGk9NDA5Ng==</challenge>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
final result2 = await negotiator.negotiate(
|
|
||||||
XMLNode.fromString(
|
|
||||||
"<success xmlns='urn:ietf:params:xml:ns:xmpp-sasl'>dj1ybUY5cHFWOFM3c3VBb1pXamE0ZEpSa0ZzS1E9</success>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(result2.get<NegotiatorState>(), NegotiatorState.done);
|
expect(result2.get<NegotiatorState>(), NegotiatorState.done);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,23 +1,16 @@
|
|||||||
import 'package:moxxmpp/moxxmpp.dart';
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
final stanza1 = Stanza.iq(
|
final stanza1 = Stanza.iq(children: [
|
||||||
children: [XMLNode.xmlns(tag: 'tag', xmlns: 'owo')],
|
XMLNode.xmlns(tag: 'tag', xmlns: 'owo')
|
||||||
);
|
],);
|
||||||
final stanza2 = Stanza.message(
|
final stanza2 = Stanza.message(children: [
|
||||||
children: [XMLNode.xmlns(tag: 'some-other-tag', xmlns: 'owo')],
|
XMLNode.xmlns(tag: 'some-other-tag', xmlns: 'owo')
|
||||||
);
|
],);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('match all', () {
|
test('match all', () {
|
||||||
final handler = StanzaHandler(
|
final handler = StanzaHandler(callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza));
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(handler.matches(Stanza.iq()), true);
|
expect(handler.matches(Stanza.iq()), true);
|
||||||
expect(handler.matches(Stanza.message()), true);
|
expect(handler.matches(Stanza.message()), true);
|
||||||
@ -27,12 +20,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('xmlns matching', () {
|
test('xmlns matching', () {
|
||||||
final handler = StanzaHandler(
|
final handler = StanzaHandler(
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza),
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
tagXmlns: 'owo',
|
tagXmlns: 'owo',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -44,18 +32,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('stanzaTag matching', () {
|
test('stanzaTag matching', () {
|
||||||
var run = false;
|
var run = false;
|
||||||
final handler = StanzaHandler(
|
final handler = StanzaHandler(callback: (stanza, _) async {
|
||||||
callback: (stanza, _) async {
|
|
||||||
run = true;
|
run = true;
|
||||||
return StanzaHandlerData(
|
return StanzaHandlerData(true, false, null, stanza);
|
||||||
true,
|
}, stanzaTag: 'iq',);
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
stanzaTag: 'iq',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(handler.matches(Stanza.iq()), true);
|
expect(handler.matches(Stanza.iq()), true);
|
||||||
expect(handler.matches(Stanza.message()), false);
|
expect(handler.matches(Stanza.message()), false);
|
||||||
@ -63,25 +43,12 @@ void main() {
|
|||||||
expect(handler.matches(stanza1), true);
|
expect(handler.matches(stanza1), true);
|
||||||
expect(handler.matches(stanza2), false);
|
expect(handler.matches(stanza2), false);
|
||||||
|
|
||||||
handler.callback(
|
handler.callback(stanza2, StanzaHandlerData(false, false, null, stanza2));
|
||||||
stanza2,
|
|
||||||
StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza2,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
expect(run, true);
|
expect(run, true);
|
||||||
});
|
});
|
||||||
test('tagName matching', () {
|
test('tagName matching', () {
|
||||||
final handler = StanzaHandler(
|
final handler = StanzaHandler(
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza),
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
tagName: 'tag',
|
tagName: 'tag',
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -93,12 +60,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('combined matching', () {
|
test('combined matching', () {
|
||||||
final handler = StanzaHandler(
|
final handler = StanzaHandler(
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza),
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
tagName: 'tag',
|
tagName: 'tag',
|
||||||
stanzaTag: 'iq',
|
stanzaTag: 'iq',
|
||||||
tagXmlns: 'owo',
|
tagXmlns: 'owo',
|
||||||
@ -113,36 +75,12 @@ void main() {
|
|||||||
|
|
||||||
test('sorting', () {
|
test('sorting', () {
|
||||||
final handlerList = [
|
final handlerList = [
|
||||||
StanzaHandler(
|
StanzaHandler(callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza), tagName: '1', priority: 100),
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
StanzaHandler(callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza), tagName: '2'),
|
||||||
true,
|
StanzaHandler(callback: (stanza, _) async => StanzaHandlerData(true, false, null, stanza), tagName: '3', priority: 50)
|
||||||
false,
|
];
|
||||||
null,
|
|
||||||
stanza,
|
handlerList.sort(stanzaHandlerSortComparator);
|
||||||
),
|
|
||||||
tagName: '1',
|
|
||||||
priority: 100,
|
|
||||||
),
|
|
||||||
StanzaHandler(
|
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
tagName: '2',
|
|
||||||
),
|
|
||||||
StanzaHandler(
|
|
||||||
callback: (stanza, _) async => StanzaHandlerData(
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
tagName: '3',
|
|
||||||
priority: 50,
|
|
||||||
)
|
|
||||||
]..sort(stanzaHandlerSortComparator);
|
|
||||||
|
|
||||||
expect(handlerList[0].tagName, '1');
|
expect(handlerList[0].tagName, '1');
|
||||||
expect(handlerList[1].tagName, '3');
|
expect(handlerList[1].tagName, '3');
|
||||||
|
@ -5,79 +5,33 @@ import 'helpers/xml.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Test stringxml', () {
|
test('Test stringxml', () {
|
||||||
final child = XMLNode(tag: 'uwu', attributes: {'strength': 10});
|
final child = XMLNode(tag: 'uwu', attributes: { 'strength': 10 });
|
||||||
final stanza =
|
final stanza = XMLNode.xmlns(tag: 'uwu-meter', xmlns: 'uwu', children: [ child ]);
|
||||||
XMLNode.xmlns(tag: 'uwu-meter', xmlns: 'uwu', children: [child]);
|
expect(XMLNode(tag: 'iq', attributes: {'xmlns': 'uwu'}).toXml(), "<iq xmlns='uwu' />");
|
||||||
expect(
|
expect(XMLNode.xmlns(tag: 'iq', xmlns: 'uwu', attributes: {'how': 'uwu'}).toXml(), "<iq xmlns='uwu' how='uwu' />");
|
||||||
XMLNode(tag: 'iq', attributes: {'xmlns': 'uwu'}).toXml(),
|
expect(stanza.toXml(), "<uwu-meter xmlns='uwu'><uwu strength=10 /></uwu-meter>");
|
||||||
"<iq xmlns='uwu' />",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
XMLNode.xmlns(tag: 'iq', xmlns: 'uwu', attributes: {'how': 'uwu'})
|
|
||||||
.toXml(),
|
|
||||||
"<iq xmlns='uwu' how='uwu' />",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
stanza.toXml(),
|
|
||||||
"<uwu-meter xmlns='uwu'><uwu strength=10 /></uwu-meter>",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
expect(StreamHeaderNonza('uwu.server').toXml(), "<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='uwu.server' xml:lang='en'>");
|
||||||
StreamHeaderNonza('uwu.server').toXml(),
|
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='uwu.server' xml:lang='en'>",
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
expect(XMLNode(tag: 'text', attributes: {}, text: 'hallo').toXml(), '<text>hallo</text>');
|
||||||
XMLNode(tag: 'text', attributes: {}, text: 'hallo').toXml(),
|
expect(XMLNode(tag: 'text', attributes: { 'world': 'no' }, text: 'hallo').toXml(), "<text world='no'>hallo</text>");
|
||||||
'<text>hallo</text>',
|
expect(XMLNode(tag: 'text', attributes: {}, text: 'hallo').toXml(), '<text>hallo</text>');
|
||||||
);
|
expect(XMLNode(tag: 'text', attributes: {}, text: 'test').innerText(), 'test');
|
||||||
expect(
|
|
||||||
XMLNode(tag: 'text', attributes: {'world': 'no'}, text: 'hallo').toXml(),
|
|
||||||
"<text world='no'>hallo</text>",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
XMLNode(tag: 'text', attributes: {}, text: 'hallo').toXml(),
|
|
||||||
'<text>hallo</text>',
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
XMLNode(tag: 'text', attributes: {}, text: 'test').innerText(),
|
|
||||||
'test',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test XmlElement', () {
|
test('Test XmlElement', () {
|
||||||
expect(
|
expect(XMLNode.fromXmlElement(XmlDocument.parse("<root owo='uwu' />").firstElementChild!).toXml(), "<root owo='uwu' />");
|
||||||
XMLNode.fromXmlElement(
|
|
||||||
XmlDocument.parse("<root owo='uwu' />").firstElementChild!,
|
|
||||||
).toXml(),
|
|
||||||
"<root owo='uwu' />",
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test the find functions', () {
|
test('Test the find functions', () {
|
||||||
final node1 = XMLNode.fromString(
|
final node1 = XMLNode.fromString('<message><a xmlns="a" /><body>Hallo</body></message>');
|
||||||
'<message><a xmlns="a" /><body>Hallo</body></message>',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(
|
expect(compareXMLNodes(node1.firstTag('body')!, XMLNode.fromString('<body>Hallo</body>')), true);
|
||||||
compareXMLNodes(
|
expect(compareXMLNodes(node1.firstTagByXmlns('a')!, XMLNode.fromString('<a xmlns="a" />')), true);
|
||||||
node1.firstTag('body')!,
|
|
||||||
XMLNode.fromString('<body>Hallo</body>'),
|
|
||||||
),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
compareXMLNodes(
|
|
||||||
node1.firstTagByXmlns('a')!,
|
|
||||||
XMLNode.fromString('<a xmlns="a" />'),
|
|
||||||
),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test compareXMLNodes', () {
|
test('Test compareXMLNodes', () {
|
||||||
final node1 = XMLNode.fromString(
|
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'>
|
<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'>
|
<pubsub xmlns='http://jabber.org/protocol/pubsub'>
|
||||||
<publish node='princely_musings'>
|
<publish node='princely_musings'>
|
||||||
@ -121,12 +75,6 @@ void main() {
|
|||||||
</iq>
|
</iq>
|
||||||
''');
|
''');
|
||||||
|
|
||||||
expect(
|
expect(compareXMLNodes(node1, node2, ignoreId: true), false);
|
||||||
compareXMLNodes(
|
|
||||||
node1,
|
|
||||||
node2,
|
|
||||||
),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,27 @@
|
|||||||
import 'package:moxxmpp/src/util/wait.dart';
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
import 'package:moxxmpp/src/util/wait.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Test adding and resolving', () async {
|
test('Test adding and resolving', () async {
|
||||||
// ID -> Milliseconds since epoch
|
// ID -> Milliseconds since epoch
|
||||||
final tracker = WaitForTracker<int, int>();
|
final tracker = WaitForTracker<int, int>();
|
||||||
|
|
||||||
var r2 = 0;
|
int r2 = 0;
|
||||||
var r3 = 0;
|
int r3 = 0;
|
||||||
|
|
||||||
// Queue some jobs
|
// Queue some jobs
|
||||||
final r1 = await tracker.waitFor(0);
|
final r1 = await tracker.waitFor(0);
|
||||||
expect(r1, null);
|
expect(r1, null);
|
||||||
|
|
||||||
// ignore: unawaited_futures
|
tracker
|
||||||
tracker.waitFor(0).then((result) async {
|
.waitFor(0)
|
||||||
|
.then((result) async {
|
||||||
expect(result != null, true);
|
expect(result != null, true);
|
||||||
r2 = await result!;
|
r2 = await result!;
|
||||||
});
|
});
|
||||||
|
tracker
|
||||||
// ignore: unawaited_futures
|
.waitFor(0)
|
||||||
tracker.waitFor(0).then((result) async {
|
.then((result) async {
|
||||||
expect(result != null, true);
|
expect(result != null, true);
|
||||||
r3 = await result!;
|
r3 = await result!;
|
||||||
});
|
});
|
||||||
|
@ -3,15 +3,11 @@ import 'package:test/test.dart';
|
|||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Parsing', () {
|
test('Parsing', () {
|
||||||
const testData =
|
const testData = "<x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='ip_version' type='text-multi' ><value>ipv4</value><value>ipv6</value></field><field var='os'><value>Mac</value></field><field var='os_version'><value>10.5.1</value></field><field var='software'><value>Psi</value></field><field var='software_version'><value>0.11</value></field></x>";
|
||||||
"<x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='ip_version' type='text-multi' ><value>ipv4</value><value>ipv6</value></field><field var='os'><value>Mac</value></field><field var='os_version'><value>10.5.1</value></field><field var='software'><value>Psi</value></field><field var='software_version'><value>0.11</value></field></x>";
|
|
||||||
|
|
||||||
final form = parseDataForm(XMLNode.fromString(testData));
|
final form = parseDataForm(XMLNode.fromString(testData));
|
||||||
expect(
|
expect(form.getFieldByVar('FORM_TYPE')?.values.first, 'urn:xmpp:dataforms:softwareinfo');
|
||||||
form.getFieldByVar('FORM_TYPE')?.values.first,
|
expect(form.getFieldByVar('ip_version')?.values, [ 'ipv4', 'ipv6' ]);
|
||||||
'urn:xmpp:dataforms:softwareinfo',
|
|
||||||
);
|
|
||||||
expect(form.getFieldByVar('ip_version')?.values, ['ipv4', 'ipv6']);
|
|
||||||
expect(form.getFieldByVar('os')?.values.first, 'Mac');
|
expect(form.getFieldByVar('os')?.values.first, 'Mac');
|
||||||
expect(form.getFieldByVar('os_version')?.values.first, '10.5.1');
|
expect(form.getFieldByVar('os_version')?.values.first, '10.5.1');
|
||||||
expect(form.getFieldByVar('software')?.values.first, 'Psi');
|
expect(form.getFieldByVar('software')?.values.first, 'Psi');
|
||||||
|
@ -28,7 +28,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -64,54 +64,53 @@ void main() {
|
|||||||
"<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' from='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
|
"<iq type='get' id='ec325efc-9924-4c48-93f8-ed34a2b0e5fc' to='romeo@montague.lit/orchard' from='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
|
||||||
'',
|
'',
|
||||||
ignoreId: true,
|
ignoreId: true,
|
||||||
|
adjustId: false,
|
||||||
),
|
),
|
||||||
|
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager(null, [])),
|
RosterManager(TestingRosterStateManager(null, [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
SaslScramNegotiator(10, '', '', ScramHashType.sha512),
|
SaslScramNegotiator(10, '', '', ScramHashType.sha512),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final disco = conn.getManagerById<DiscoManager>(discoManager)!;
|
final disco = conn.getManagerById<DiscoManager>(discoManager)!;
|
||||||
|
|
||||||
await conn.connect();
|
await conn.connect();
|
||||||
await Future<void>.delayed(const Duration(seconds: 3));
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
|
||||||
final jid = JID.fromString('romeo@montague.lit/orchard');
|
final jid = JID.fromString('romeo@montague.lit/orchard');
|
||||||
final result1 = disco.discoInfoQuery(jid.toString());
|
final result1 = disco.discoInfoQuery(jid.toString());
|
||||||
final result2 = disco.discoInfoQuery(jid.toString());
|
final result2 = disco.discoInfoQuery(jid.toString());
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 1));
|
await Future.delayed(const Duration(seconds: 1));
|
||||||
expect(
|
expect(
|
||||||
disco.infoTracker
|
disco.infoTracker.getRunningTasks(DiscoCacheKey(jid.toString(), null)).length,
|
||||||
.getRunningTasks(DiscoCacheKey(jid.toString(), null))
|
|
||||||
.length,
|
|
||||||
1,
|
1,
|
||||||
);
|
);
|
||||||
fakeSocket.injectRawXml(
|
fakeSocket.injectRawXml("<iq type='result' id='${fakeSocket.lastId!}' from='romeo@montague.lit/orchard' to='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>");
|
||||||
"<iq type='result' id='${fakeSocket.lastId!}' from='romeo@montague.lit/orchard' to='polynomdivision@test.server/MU29eEZn' xmlns='jabber:client'><query xmlns='http://jabber.org/protocol/disco#info' /></iq>",
|
|
||||||
);
|
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
|
|
||||||
expect(fakeSocket.getState(), 6);
|
expect(fakeSocket.getState(), 6);
|
||||||
expect(await result1, await result2);
|
expect(await result1, await result2);
|
||||||
|
@ -11,18 +11,16 @@ class StubbedDiscoManager extends DiscoManager {
|
|||||||
final bool _itemError;
|
final bool _itemError;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(
|
Future<Result<DiscoError, DiscoInfo>> discoInfoQuery(String entity, { String? node, bool shouldEncrypt = true }) async {
|
||||||
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='pubsub' type='service' />
|
<identity category='pubsub' type='service' />
|
||||||
<feature var="http://jabber.org/protocol/pubsub" />
|
<feature var="http://jabber.org/protocol/pubsub" />
|
||||||
<feature var="http://jabber.org/protocol/pubsub#multi-items" />
|
<feature var="http://jabber.org/protocol/pubsub#multi-items" />
|
||||||
</query>'''),
|
</query>'''
|
||||||
|
),
|
||||||
JID.fromString('pubsub.server.example.org'),
|
JID.fromString('pubsub.server.example.org'),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -30,11 +28,7 @@ class StubbedDiscoManager extends DiscoManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(
|
Future<Result<DiscoError, List<DiscoItem>>> discoItemsQuery(String entity, {String? node, bool shouldEncrypt = true}) async {
|
||||||
String entity, {
|
|
||||||
String? node,
|
|
||||||
bool shouldEncrypt = true,
|
|
||||||
}) async {
|
|
||||||
if (_itemError) {
|
if (_itemError) {
|
||||||
return Result(
|
return Result(
|
||||||
UnknownDiscoError(),
|
UnknownDiscoError(),
|
||||||
@ -49,11 +43,9 @@ class StubbedDiscoManager extends DiscoManager {
|
|||||||
void main() {
|
void main() {
|
||||||
initLogger();
|
initLogger();
|
||||||
|
|
||||||
test(
|
test('Test pre-processing with pubsub#max_items when the server does not support it (1/2)', () async {
|
||||||
'Test pre-processing with pubsub#max_items when the server does not support it (1/2)',
|
|
||||||
() async {
|
|
||||||
final manager = PubSubManager();
|
final manager = PubSubManager();
|
||||||
final tm = TestingManagerHolder();
|
final TestingManagerHolder tm = TestingManagerHolder();
|
||||||
await tm.register(StubbedDiscoManager(false));
|
await tm.register(StubbedDiscoManager(false));
|
||||||
await tm.register(manager);
|
await tm.register(manager);
|
||||||
|
|
||||||
@ -66,11 +58,9 @@ void main() {
|
|||||||
expect(result.maxItems, '1');
|
expect(result.maxItems, '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('Test pre-processing with pubsub#max_items when the server does not support it (2/2)', () async {
|
||||||
'Test pre-processing with pubsub#max_items when the server does not support it (2/2)',
|
|
||||||
() async {
|
|
||||||
final manager = PubSubManager();
|
final manager = PubSubManager();
|
||||||
final tm = TestingManagerHolder();
|
final TestingManagerHolder tm = TestingManagerHolder();
|
||||||
await tm.register(StubbedDiscoManager(true));
|
await tm.register(StubbedDiscoManager(true));
|
||||||
await tm.register(manager);
|
await tm.register(manager);
|
||||||
|
|
||||||
@ -83,9 +73,7 @@ void main() {
|
|||||||
expect(result.maxItems, '1');
|
expect(result.maxItems, '1');
|
||||||
});
|
});
|
||||||
|
|
||||||
test(
|
test('Test publishing with pubsub#max_items when the server does not support it', () async {
|
||||||
'Test publishing with pubsub#max_items when the server does not support it',
|
|
||||||
() async {
|
|
||||||
final socket = StubTCPSocket.authenticated(
|
final socket = StubTCPSocket.authenticated(
|
||||||
TestingManagerHolder.settings,
|
TestingManagerHolder.settings,
|
||||||
[
|
[
|
||||||
@ -170,8 +158,7 @@ void main() {
|
|||||||
RosterManager(TestingRosterStateManager(null, [])),
|
RosterManager(TestingRosterStateManager(null, [])),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
]);
|
]);
|
||||||
connection
|
connection..registerFeatureNegotiators([
|
||||||
..registerFeatureNegotiators([
|
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
])
|
])
|
||||||
@ -180,9 +167,8 @@ void main() {
|
|||||||
waitUntilLogin: true,
|
waitUntilLogin: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
final item = XMLNode(tag: 'test-item');
|
final item = XMLNode(tag: "test-item");
|
||||||
final result =
|
final result = await connection.getManagerById<PubSubManager>(pubsubManager)!.publish(
|
||||||
await connection.getManagerById<PubSubManager>(pubsubManager)!.publish(
|
|
||||||
'pubsub.server.example.org',
|
'pubsub.server.example.org',
|
||||||
'princely_musings',
|
'princely_musings',
|
||||||
item,
|
item,
|
||||||
|
@ -5,20 +5,20 @@ import 'package:test/test.dart';
|
|||||||
void main() {
|
void main() {
|
||||||
test('Test XEP example', () async {
|
test('Test XEP example', () async {
|
||||||
final data = DiscoInfo(
|
final data = DiscoInfo(
|
||||||
const [
|
[
|
||||||
'http://jabber.org/protocol/caps',
|
'http://jabber.org/protocol/caps',
|
||||||
'http://jabber.org/protocol/disco#info',
|
'http://jabber.org/protocol/disco#info',
|
||||||
'http://jabber.org/protocol/disco#items',
|
'http://jabber.org/protocol/disco#items',
|
||||||
'http://jabber.org/protocol/muc'
|
'http://jabber.org/protocol/muc'
|
||||||
],
|
],
|
||||||
const [
|
[
|
||||||
Identity(
|
Identity(
|
||||||
category: 'client',
|
category: 'client',
|
||||||
type: 'pc',
|
type: 'pc',
|
||||||
name: 'Exodus 0.9.1',
|
name: 'Exodus 0.9.1',
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
const [],
|
[],
|
||||||
null,
|
null,
|
||||||
JID.fromString('some@user.local/test'),
|
JID.fromString('some@user.local/test'),
|
||||||
);
|
);
|
||||||
@ -28,30 +28,29 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test complex generation example', () async {
|
test('Test complex generation example', () async {
|
||||||
const extDiscoDataString =
|
const extDiscoDataString = "<x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='ip_version' type='text-multi' ><value>ipv4</value><value>ipv6</value></field><field var='os'><value>Mac</value></field><field var='os_version'><value>10.5.1</value></field><field var='software'><value>Psi</value></field><field var='software_version'><value>0.11</value></field></x>";
|
||||||
"<x xmlns='jabber:x:data' type='result'><field var='FORM_TYPE' type='hidden'><value>urn:xmpp:dataforms:softwareinfo</value></field><field var='ip_version' type='text-multi' ><value>ipv4</value><value>ipv6</value></field><field var='os'><value>Mac</value></field><field var='os_version'><value>10.5.1</value></field><field var='software'><value>Psi</value></field><field var='software_version'><value>0.11</value></field></x>";
|
|
||||||
final data = DiscoInfo(
|
final data = DiscoInfo(
|
||||||
const [
|
[
|
||||||
'http://jabber.org/protocol/caps',
|
'http://jabber.org/protocol/caps',
|
||||||
'http://jabber.org/protocol/disco#info',
|
'http://jabber.org/protocol/disco#info',
|
||||||
'http://jabber.org/protocol/disco#items',
|
'http://jabber.org/protocol/disco#items',
|
||||||
'http://jabber.org/protocol/muc'
|
'http://jabber.org/protocol/muc'
|
||||||
],
|
],
|
||||||
const [
|
[
|
||||||
Identity(
|
const Identity(
|
||||||
category: 'client',
|
category: 'client',
|
||||||
type: 'pc',
|
type: 'pc',
|
||||||
name: 'Psi 0.11',
|
name: 'Psi 0.11',
|
||||||
lang: 'en',
|
lang: 'en',
|
||||||
),
|
),
|
||||||
Identity(
|
const Identity(
|
||||||
category: 'client',
|
category: 'client',
|
||||||
type: 'pc',
|
type: 'pc',
|
||||||
name: 'Ψ 0.11',
|
name: 'Ψ 0.11',
|
||||||
lang: 'el',
|
lang: 'el',
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
[parseDataForm(XMLNode.fromString(extDiscoDataString))],
|
[ parseDataForm(XMLNode.fromString(extDiscoDataString)) ],
|
||||||
null,
|
null,
|
||||||
JID.fromString('some@user.local/test'),
|
JID.fromString('some@user.local/test'),
|
||||||
);
|
);
|
||||||
@ -61,7 +60,7 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test Gajim capability hash computation', () async {
|
test('Test Gajim capability hash computation', () async {
|
||||||
// TODO(Unknown): This one fails
|
// TODO: This one fails
|
||||||
/*
|
/*
|
||||||
final data = DiscoInfo(
|
final data = DiscoInfo(
|
||||||
features: [
|
features: [
|
||||||
@ -121,7 +120,7 @@ void main() {
|
|||||||
|
|
||||||
test('Test Conversations hash computation', () async {
|
test('Test Conversations hash computation', () async {
|
||||||
final data = DiscoInfo(
|
final data = DiscoInfo(
|
||||||
const [
|
[
|
||||||
'eu.siacs.conversations.axolotl.devicelist+notify',
|
'eu.siacs.conversations.axolotl.devicelist+notify',
|
||||||
'http://jabber.org/protocol/caps',
|
'http://jabber.org/protocol/caps',
|
||||||
'http://jabber.org/protocol/chatstates',
|
'http://jabber.org/protocol/chatstates',
|
||||||
@ -153,14 +152,14 @@ void main() {
|
|||||||
'urn:xmpp:receipts',
|
'urn:xmpp:receipts',
|
||||||
'urn:xmpp:time'
|
'urn:xmpp:time'
|
||||||
],
|
],
|
||||||
const [
|
[
|
||||||
Identity(
|
Identity(
|
||||||
category: 'client',
|
category: 'client',
|
||||||
type: 'phone',
|
type: 'phone',
|
||||||
name: 'Conversations',
|
name: 'Conversations',
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
const [],
|
[],
|
||||||
null,
|
null,
|
||||||
JID.fromString('user@server.local/test'),
|
JID.fromString('user@server.local/test'),
|
||||||
);
|
);
|
||||||
|
@ -3,54 +3,21 @@ import 'package:test/test.dart';
|
|||||||
import '../helpers/logging.dart';
|
import '../helpers/logging.dart';
|
||||||
import '../helpers/xmpp.dart';
|
import '../helpers/xmpp.dart';
|
||||||
|
|
||||||
Future<void> runIncomingStanzaHandlers(
|
Future<void> runIncomingStanzaHandlers(StreamManagementManager man, Stanza stanza) async {
|
||||||
StreamManagementManager man,
|
|
||||||
Stanza stanza,
|
|
||||||
) async {
|
|
||||||
for (final handler in man.getIncomingPreStanzaHandlers()) {
|
for (final handler in man.getIncomingPreStanzaHandlers()) {
|
||||||
if (handler.matches(stanza)) {
|
if (handler.matches(stanza)) await handler.callback(stanza, StanzaHandlerData(false, false, null, stanza));
|
||||||
await handler.callback(
|
|
||||||
stanza,
|
|
||||||
StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> runOutgoingStanzaHandlers(
|
Future<void> runOutgoingStanzaHandlers(StreamManagementManager man, Stanza stanza) async {
|
||||||
StreamManagementManager man,
|
|
||||||
Stanza stanza,
|
|
||||||
) async {
|
|
||||||
for (final handler in man.getOutgoingPostStanzaHandlers()) {
|
for (final handler in man.getOutgoingPostStanzaHandlers()) {
|
||||||
if (handler.matches(stanza)) {
|
if (handler.matches(stanza)) await handler.callback(stanza, StanzaHandlerData(false, false, null, stanza));
|
||||||
await handler.callback(
|
|
||||||
stanza,
|
|
||||||
StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
|
XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
|
||||||
return XmppManagerAttributes(
|
return XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (stanza, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async {
|
||||||
stanza, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
callback(stanza);
|
callback(stanza);
|
||||||
|
|
||||||
return Stanza.message();
|
return Stanza.message();
|
||||||
@ -66,22 +33,12 @@ XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('hallo@example.server/uwu'),
|
getFullJID: () => JID.fromString('hallo@example.server/uwu'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
|
||||||
getNegotiatorById: getNegotiatorNullStub,
|
getNegotiatorById: getNegotiatorNullStub,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
XMLNode mkAck(int h) => XMLNode.xmlns(
|
XMLNode mkAck(int h) => XMLNode.xmlns(tag: 'a', xmlns: 'urn:xmpp:sm:3', attributes: { 'h': h.toString() });
|
||||||
tag: 'a',
|
|
||||||
xmlns: 'urn:xmpp:sm:3',
|
|
||||||
attributes: {
|
|
||||||
'h': h.toString(),
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
initLogger();
|
initLogger();
|
||||||
@ -93,7 +50,8 @@ void main() {
|
|||||||
|
|
||||||
test('Test stream with SM enablement', () async {
|
test('Test stream with SM enablement', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
// [...]
|
// [...]
|
||||||
// <enable /> // <enabled />
|
// <enable /> // <enabled />
|
||||||
@ -119,10 +77,10 @@ void main() {
|
|||||||
group('Acking', () {
|
group('Acking', () {
|
||||||
test('Test completely clearing the queue', () async {
|
test('Test completely clearing the queue', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
await manager
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -135,11 +93,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('Test partially clearing the queue', () async {
|
test('Test partially clearing the queue', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
await manager.onXmppEvent(
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -152,11 +109,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('Send an ack with h > c2s', () async {
|
test('Send an ack with h > c2s', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
await manager.onXmppEvent(
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -170,11 +126,10 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('Send an ack with h < c2s', () async {
|
test('Send an ack with h < c2s', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
await manager.onXmppEvent(
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -191,10 +146,9 @@ void main() {
|
|||||||
group('Counting acks', () {
|
group('Counting acks', () {
|
||||||
test('Sending all pending acks at once', () async {
|
test('Sending all pending acks at once', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
await manager.onXmppEvent(
|
manager.register(attributes);
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
);
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -208,10 +162,9 @@ void main() {
|
|||||||
});
|
});
|
||||||
test('Sending partial pending acks at once', () async {
|
test('Sending partial pending acks at once', () async {
|
||||||
final attributes = mkAttributes((_) {});
|
final attributes = mkAttributes((_) {});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
await manager.onXmppEvent(
|
manager.register(attributes);
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
);
|
|
||||||
|
|
||||||
// Send a stanza 5 times
|
// Send a stanza 5 times
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -224,9 +177,9 @@ void main() {
|
|||||||
expect(await manager.getPendingAcks(), 2);
|
expect(await manager.getPendingAcks(), 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test counting incoming stanzas for which handlers end early',
|
test('Test counting incoming stanzas for which handlers end early', () async {
|
||||||
() async {
|
final fakeSocket = StubTCPSocket(
|
||||||
final fakeSocket = StubTCPSocket([
|
[
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
'''
|
'''
|
||||||
@ -244,7 +197,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -276,21 +229,21 @@ void main() {
|
|||||||
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
||||||
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
||||||
),
|
),
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
|
||||||
final sm = StreamManagementManager();
|
final sm = StreamManagementManager();
|
||||||
await conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
@ -299,21 +252,20 @@ void main() {
|
|||||||
CarbonsManager()..forceEnable(),
|
CarbonsManager()..forceEnable(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
|
|
||||||
await conn.connect(
|
|
||||||
waitUntilLogin: true,
|
|
||||||
);
|
);
|
||||||
expect(fakeSocket.getState(), 5);
|
|
||||||
|
await conn.connect();
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
expect(fakeSocket.getState(), 6);
|
||||||
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
||||||
expect(
|
expect(
|
||||||
conn
|
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
|
||||||
.getManagerById<StreamManagementManager>(smManager)!
|
|
||||||
.isStreamManagementEnabled(),
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -337,12 +289,13 @@ void main() {
|
|||||||
</message>
|
</message>
|
||||||
''');
|
''');
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2));
|
||||||
expect(sm.state.s2c, 1);
|
expect(sm.state.s2c, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test counting incoming stanzas that are awaited', () async {
|
test('Test counting incoming stanzas that are awaited', () async {
|
||||||
final fakeSocket = StubTCPSocket([
|
final fakeSocket = StubTCPSocket(
|
||||||
|
[
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
'''
|
'''
|
||||||
@ -360,7 +313,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -392,54 +345,53 @@ void main() {
|
|||||||
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
||||||
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
||||||
),
|
),
|
||||||
// StringExpectation(
|
StringExpectation(
|
||||||
// "<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show></presence>",
|
"<presence xmlns='jabber:client' from='polynomdivision@test.server/MU29eEZn'><show>chat</show><c xmlns='http://jabber.org/protocol/caps' hash='sha-1' node='http://moxxmpp.example' ver='3QvQ2RAy45XBDhArjxy/vEWMl+E=' /></presence>",
|
||||||
// '<iq type="result" />',
|
'<iq type="result" />',
|
||||||
// ),
|
),
|
||||||
StanzaExpectation(
|
StanzaExpectation(
|
||||||
"<iq to='user@example.com' type='get' id='a' xmlns='jabber:client' />",
|
"<iq to='user@example.com' type='get' id='a' xmlns='jabber:client' />",
|
||||||
"<iq from='user@example.com' type='result' id='a' />",
|
"<iq from='user@example.com' type='result' id='a' />",
|
||||||
ignoreId: true,
|
ignoreId: true,
|
||||||
adjustId: true,
|
adjustId: true,
|
||||||
),
|
),
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
|
||||||
final sm = StreamManagementManager();
|
final sm = StreamManagementManager();
|
||||||
await conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
sm,
|
sm,
|
||||||
CarbonsManager()..forceEnable(),
|
CarbonsManager()..forceEnable(),
|
||||||
//EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
|
|
||||||
await conn.connect(
|
|
||||||
waitUntilLogin: true,
|
|
||||||
);
|
);
|
||||||
expect(fakeSocket.getState(), 5);
|
|
||||||
|
await conn.connect();
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
expect(fakeSocket.getState(), 6);
|
||||||
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
||||||
expect(
|
expect(
|
||||||
conn
|
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
|
||||||
.getManagerById<StreamManagementManager>(smManager)!
|
|
||||||
.isStreamManagementEnabled(),
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -452,7 +404,7 @@ void main() {
|
|||||||
addFrom: StanzaFromType.none,
|
addFrom: StanzaFromType.none,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(sm.state.s2c, /*2*/ 1);
|
expect(sm.state.s2c, 2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -462,11 +414,10 @@ void main() {
|
|||||||
final attributes = mkAttributes((_) {
|
final attributes = mkAttributes((_) {
|
||||||
stanzaCount++;
|
stanzaCount++;
|
||||||
});
|
});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
await manager.onXmppEvent(
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
|
||||||
);
|
|
||||||
|
|
||||||
// Send 5 stanzas
|
// Send 5 stanzas
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -489,13 +440,12 @@ void main() {
|
|||||||
final attributes = mkAttributes((_) {
|
final attributes = mkAttributes((_) {
|
||||||
stanzaCount++;
|
stanzaCount++;
|
||||||
});
|
});
|
||||||
final manager = StreamManagementManager()..register(attributes);
|
final manager = StreamManagementManager();
|
||||||
|
manager.register(attributes);
|
||||||
|
|
||||||
// [ ... ]
|
// [ ... ]
|
||||||
await manager.onXmppEvent(
|
await manager.onXmppEvent(StreamManagementEnabledEvent(resource: 'hallo'));
|
||||||
StreamManagementEnabledEvent(resource: 'hallo'),
|
manager.setState(manager.state.copyWith(c2s: 150, s2c: 70));
|
||||||
);
|
|
||||||
await manager.setState(manager.state.copyWith(c2s: 150, s2c: 70));
|
|
||||||
|
|
||||||
// Send some stanzas but don't ack them
|
// Send some stanzas but don't ack them
|
||||||
for (var i = 0; i < 5; i++) {
|
for (var i = 0; i < 5; i++) {
|
||||||
@ -513,7 +463,8 @@ void main() {
|
|||||||
|
|
||||||
group('Test the negotiator', () {
|
group('Test the negotiator', () {
|
||||||
test('Test successful stream enablement', () async {
|
test('Test successful stream enablement', () async {
|
||||||
final fakeSocket = StubTCPSocket([
|
final fakeSocket = StubTCPSocket(
|
||||||
|
[
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
'''
|
'''
|
||||||
@ -531,7 +482,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -557,54 +508,54 @@ void main() {
|
|||||||
StanzaExpectation(
|
StanzaExpectation(
|
||||||
'<iq xmlns="jabber:client" type="set" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq>',
|
'<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>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
||||||
ignoreId: true,
|
ignoreId: true
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
||||||
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
|
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />'
|
||||||
)
|
)
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
|
|
||||||
await conn.connect(
|
|
||||||
waitUntilLogin: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(fakeSocket.getState(), 5);
|
await conn.connect();
|
||||||
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
|
|
||||||
|
expect(fakeSocket.getState(), 6);
|
||||||
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
||||||
expect(
|
expect(
|
||||||
conn
|
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
|
||||||
.getManagerById<StreamManagementManager>(smManager)!
|
|
||||||
.isStreamManagementEnabled(),
|
|
||||||
true,
|
true,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Test a failed stream resumption', () async {
|
test('Test a failed stream resumption', () async {
|
||||||
final fakeSocket = StubTCPSocket([
|
final fakeSocket = StubTCPSocket(
|
||||||
|
[
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
'''
|
'''
|
||||||
@ -622,7 +573,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -652,38 +603,41 @@ void main() {
|
|||||||
StanzaExpectation(
|
StanzaExpectation(
|
||||||
'<iq xmlns="jabber:client" type="set" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq>',
|
'<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>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
||||||
ignoreId: true,
|
ignoreId: true
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
||||||
'<enabled xmlns="urn:xmpp:sm:3" id="id-2" resume="true" />',
|
'<enabled xmlns="urn:xmpp:sm:3" id="id-2" resume="true" />'
|
||||||
)
|
)
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
await conn.getManagerById<StreamManagementManager>(smManager)!.setState(
|
);
|
||||||
|
conn.getManagerById<StreamManagementManager>(smManager)!
|
||||||
|
.setState(
|
||||||
StreamManagementState(
|
StreamManagementState(
|
||||||
10,
|
10,
|
||||||
10,
|
10,
|
||||||
@ -691,10 +645,9 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
await conn.connect(
|
await conn.connect();
|
||||||
waitUntilLogin: true,
|
await Future.delayed(const Duration(seconds: 3));
|
||||||
);
|
expect(fakeSocket.getState(), 7);
|
||||||
expect(fakeSocket.getState(), 6);
|
|
||||||
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
||||||
expect(
|
expect(
|
||||||
conn
|
conn
|
||||||
@ -705,7 +658,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test a successful stream resumption', () async {
|
test('Test a successful stream resumption', () async {
|
||||||
final fakeSocket = StubTCPSocket([
|
final fakeSocket = StubTCPSocket(
|
||||||
|
[
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
'''
|
'''
|
||||||
@ -723,7 +677,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -750,32 +704,35 @@ void main() {
|
|||||||
"<resume xmlns='urn:xmpp:sm:3' previd='id-1' h='10' />",
|
"<resume xmlns='urn:xmpp:sm:3' previd='id-1' h='10' />",
|
||||||
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
|
"<resumed xmlns='urn:xmpp:sm:3' h='id-1' h='12' />",
|
||||||
),
|
),
|
||||||
]);
|
]
|
||||||
|
);
|
||||||
|
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
await conn.getManagerById<StreamManagementManager>(smManager)!.setState(
|
);
|
||||||
|
conn.getManagerById<StreamManagementManager>(smManager)!
|
||||||
|
.setState(
|
||||||
StreamManagementState(
|
StreamManagementState(
|
||||||
10,
|
10,
|
||||||
10,
|
10,
|
||||||
@ -783,15 +740,14 @@ void main() {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
await conn.connect(
|
await conn.connect(lastResource: 'abc123');
|
||||||
lastResource: 'abc123',
|
await Future.delayed(const Duration(seconds: 3), () async {
|
||||||
waitUntilLogin: true,
|
expect(fakeSocket.getState(), 5);
|
||||||
);
|
|
||||||
expect(fakeSocket.getState(), 4);
|
|
||||||
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
expect(await conn.getConnectionState(), XmppConnectionState.connected);
|
||||||
final sm = conn.getManagerById<StreamManagementManager>(smManager)!;
|
final sm = conn.getManagerById<StreamManagementManager>(smManager)!;
|
||||||
expect(sm.isStreamManagementEnabled(), true);
|
expect(sm.isStreamManagementEnabled(), true);
|
||||||
expect(sm.streamResumed, true);
|
expect(sm.streamResumed, true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,12 @@ import 'package:test/test.dart';
|
|||||||
import '../helpers/xmpp.dart';
|
import '../helpers/xmpp.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test("Test if we're vulnerable against CVE-2020-26547 style vulnerabilities",
|
test("Test if we're vulnerable against CVE-2020-26547 style vulnerabilities", () async {
|
||||||
() async {
|
|
||||||
final attributes = XmppManagerAttributes(
|
final attributes = XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (stanza, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async {
|
||||||
stanza, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async {
|
|
||||||
// ignore: avoid_print
|
// ignore: avoid_print
|
||||||
print('==> ${stanza.toXml()}');
|
print('==> ${stanza.toXml()}');
|
||||||
return XMLNode(tag: 'iq', attributes: {'type': 'result'});
|
return XMLNode(tag: 'iq', attributes: { 'type': 'result' });
|
||||||
},
|
},
|
||||||
sendNonza: (nonza) {},
|
sendNonza: (nonza) {},
|
||||||
sendEvent: (event) {},
|
sendEvent: (event) {},
|
||||||
@ -30,27 +21,15 @@ void main() {
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('bob@xmpp.example/uwu'),
|
getFullJID: () => JID.fromString('bob@xmpp.example/uwu'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
|
||||||
getNegotiatorById: getNegotiatorNullStub,
|
getNegotiatorById: getNegotiatorNullStub,
|
||||||
);
|
);
|
||||||
final manager = CarbonsManager()..register(attributes);
|
final manager = CarbonsManager();
|
||||||
|
manager.register(attributes);
|
||||||
await manager.enableCarbons();
|
await manager.enableCarbons();
|
||||||
|
|
||||||
expect(
|
expect(manager.isCarbonValid(JID.fromString('mallory@evil.example')), false);
|
||||||
manager.isCarbonValid(JID.fromString('mallory@evil.example')),
|
expect(manager.isCarbonValid(JID.fromString('bob@xmpp.example')), true);
|
||||||
false,
|
expect(manager.isCarbonValid(JID.fromString('bob@xmpp.example/abc')), false);
|
||||||
);
|
|
||||||
expect(
|
|
||||||
manager.isCarbonValid(JID.fromString('bob@xmpp.example')),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
manager.isCarbonValid(JID.fromString('bob@xmpp.example/abc')),
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -31,19 +31,10 @@ void main() {
|
|||||||
group('Test the XEP-0352 implementation', () {
|
group('Test the XEP-0352 implementation', () {
|
||||||
test('Test setting the CSI state when CSI is unsupported', () {
|
test('Test setting the CSI state when CSI is unsupported', () {
|
||||||
var nonzaSent = false;
|
var nonzaSent = false;
|
||||||
CSIManager()
|
final csi = CSIManager();
|
||||||
..register(
|
csi.register(
|
||||||
XmppManagerAttributes(
|
XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async => XMLNode(tag: 'hallo'),
|
||||||
_, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async =>
|
|
||||||
XMLNode(tag: 'hallo'),
|
|
||||||
sendEvent: (event) {},
|
sendEvent: (event) {},
|
||||||
sendNonza: (nonza) {
|
sendNonza: (nonza) {
|
||||||
nonzaSent = true;
|
nonzaSent = true;
|
||||||
@ -58,39 +49,23 @@ void main() {
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
)
|
|
||||||
..setActive()
|
csi.setActive();
|
||||||
..setInactive();
|
csi.setInactive();
|
||||||
|
|
||||||
expect(nonzaSent, false, reason: 'Expected that no nonza is sent');
|
expect(nonzaSent, false, reason: 'Expected that no nonza is sent');
|
||||||
});
|
});
|
||||||
test('Test setting the CSI state when CSI is supported', () {
|
test('Test setting the CSI state when CSI is supported', () {
|
||||||
CSIManager()
|
final csi = CSIManager();
|
||||||
..register(
|
csi.register(
|
||||||
XmppManagerAttributes(
|
XmppManagerAttributes(
|
||||||
sendStanza: (
|
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async => XMLNode(tag: 'hallo'),
|
||||||
_, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async =>
|
|
||||||
XMLNode(tag: 'hallo'),
|
|
||||||
sendEvent: (event) {},
|
sendEvent: (event) {},
|
||||||
sendNonza: (nonza) {
|
sendNonza: (nonza) {
|
||||||
expect(
|
expect(nonza.attributes['xmlns'] == csiXmlns, true, reason: "Expected only nonzas with XMLNS '$csiXmlns'");
|
||||||
nonza.attributes['xmlns'] == csiXmlns,
|
|
||||||
true,
|
|
||||||
reason: "Expected only nonzas with XMLNS '$csiXmlns'",
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
getConnectionSettings: () => ConnectionSettings(
|
getConnectionSettings: () => ConnectionSettings(
|
||||||
jid: JID.fromString('some.user@example.server'),
|
jid: JID.fromString('some.user@example.server'),
|
||||||
@ -102,15 +77,12 @@ void main() {
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
),
|
||||||
),
|
);
|
||||||
)
|
|
||||||
..setActive()
|
csi.setActive();
|
||||||
..setInactive();
|
csi.setInactive();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -29,20 +29,26 @@ void main() {
|
|||||||
'Cookie': 'foo=bar; user=romeo',
|
'Cookie': 'foo=bar; user=romeo',
|
||||||
'X-Tracking': 'Base64String=='
|
'X-Tracking': 'Base64String=='
|
||||||
};
|
};
|
||||||
expect(prepareHeaders(headers), {
|
expect(
|
||||||
|
prepareHeaders(headers),
|
||||||
|
{
|
||||||
'Authorization': 'Basic Base64String==',
|
'Authorization': 'Basic Base64String==',
|
||||||
'Cookie': 'foo=bar; user=romeo',
|
'Cookie': 'foo=bar; user=romeo',
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
test('remove newlines', () {
|
test('remove newlines', () {
|
||||||
final headers = {
|
final headers = {
|
||||||
'Authorization': '\n\nBasic Base64String==\n\n',
|
'Authorization': '\n\nBasic Base64String==\n\n',
|
||||||
'\nCookie\r\n': 'foo=bar; user=romeo',
|
'\nCookie\r\n': 'foo=bar; user=romeo',
|
||||||
};
|
};
|
||||||
expect(prepareHeaders(headers), {
|
expect(
|
||||||
|
prepareHeaders(headers),
|
||||||
|
{
|
||||||
'Authorization': 'Basic Base64String==',
|
'Authorization': 'Basic Base64String==',
|
||||||
'Cookie': 'foo=bar; user=romeo',
|
'Cookie': 'foo=bar; user=romeo',
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,7 @@ void main() {
|
|||||||
'''),
|
'''),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(sfs.metadata.hashes['sha3-256'], '2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=');
|
||||||
sfs.metadata.hashes['sha3-256'],
|
expect(sfs.metadata.hashes['id-blake2b256'], '2AfMGH8O7UNPTvUVAM9aK13mpCY=');
|
||||||
'2XarmwTlNxDAMkvymloX3S5+VbylNrJt/l5QyPa+YoU=',
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
sfs.metadata.hashes['id-blake2b256'],
|
|
||||||
'2AfMGH8O7UNPTvUVAM9aK13mpCY=',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:moxxmpp/moxxmpp.dart';
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
import 'package:moxxmpp/moxxmpp.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test('Test parsing a large sticker pack', () {
|
test('Test parsing a large sticker pack', () {
|
||||||
|
@ -10,18 +10,15 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Test building a multiline quote', () {
|
test('Test building a multiline quote', () {
|
||||||
final quote = QuoteData.fromBodies(
|
final quote = QuoteData.fromBodies('Hallo Welt\nHallo Erde', 'How are you?');
|
||||||
'Hallo Welt\nHallo Erde',
|
|
||||||
'How are you?',
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(quote.body, '> Hallo Welt\n> Hallo Erde\nHow are you?');
|
expect(quote.body, '> Hallo Welt\n> Hallo Erde\nHow are you?');
|
||||||
expect(quote.fallbackLength, 26);
|
expect(quote.fallbackLength, 26);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Applying a singleline quote', () {
|
test('Applying a singleline quote', () {
|
||||||
const body = '> Hallo Welt\nHello right back!';
|
final body = '> Hallo Welt\nHello right back!';
|
||||||
const reply = ReplyData(
|
final reply = ReplyData(
|
||||||
to: '',
|
to: '',
|
||||||
id: '',
|
id: '',
|
||||||
start: 0,
|
start: 0,
|
||||||
@ -33,8 +30,8 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test('Applying a multiline quote', () {
|
test('Applying a multiline quote', () {
|
||||||
const body = "> Hallo Welt\n> How are you?\nI'm fine.\nThank you!";
|
final body = "> Hallo Welt\n> How are you?\nI'm fine.\nThank you!";
|
||||||
const reply = ReplyData(
|
final reply = ReplyData(
|
||||||
to: '',
|
to: '',
|
||||||
id: '',
|
id: '',
|
||||||
start: 0,
|
start: 0,
|
||||||
|
@ -10,21 +10,23 @@ void main() {
|
|||||||
final buffer = XmlStreamBuffer();
|
final buffer = XmlStreamBuffer();
|
||||||
final controller = StreamController<String>();
|
final controller = StreamController<String>();
|
||||||
|
|
||||||
unawaited(
|
controller
|
||||||
controller.stream.transform(buffer).forEach((node) {
|
.stream
|
||||||
|
.transform(buffer)
|
||||||
|
.forEach((node) {
|
||||||
if (node.tag == 'childa') {
|
if (node.tag == 'childa') {
|
||||||
childa = true;
|
childa = true;
|
||||||
} else if (node.tag == 'childb') {
|
} else if (node.tag == 'childb') {
|
||||||
childb = true;
|
childb = true;
|
||||||
}
|
}
|
||||||
}),
|
});
|
||||||
);
|
|
||||||
controller.add('<childa /><childb />');
|
controller.add('<childa /><childb />');
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2), () {
|
||||||
expect(childa, true);
|
expect(childa, true);
|
||||||
expect(childb, true);
|
expect(childb, true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
test('Test broken up Xml data', () async {
|
test('Test broken up Xml data', () async {
|
||||||
var childa = false;
|
var childa = false;
|
||||||
var childb = false;
|
var childb = false;
|
||||||
@ -32,23 +34,24 @@ void main() {
|
|||||||
final buffer = XmlStreamBuffer();
|
final buffer = XmlStreamBuffer();
|
||||||
final controller = StreamController<String>();
|
final controller = StreamController<String>();
|
||||||
|
|
||||||
unawaited(
|
controller
|
||||||
controller.stream.transform(buffer).forEach((node) {
|
.stream
|
||||||
|
.transform(buffer)
|
||||||
|
.forEach((node) {
|
||||||
if (node.tag == 'childa') {
|
if (node.tag == 'childa') {
|
||||||
childa = true;
|
childa = true;
|
||||||
} else if (node.tag == 'childb') {
|
} else if (node.tag == 'childb') {
|
||||||
childb = true;
|
childb = true;
|
||||||
}
|
}
|
||||||
}),
|
});
|
||||||
);
|
controller.add('<childa');
|
||||||
controller
|
controller.add(' /><childb />');
|
||||||
..add('<childa')
|
|
||||||
..add(' /><childb />');
|
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2), () {
|
||||||
expect(childa, true);
|
expect(childa, true);
|
||||||
expect(childb, true);
|
expect(childb, true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Test closing the stream', () async {
|
test('Test closing the stream', () async {
|
||||||
var childa = false;
|
var childa = false;
|
||||||
@ -57,22 +60,23 @@ void main() {
|
|||||||
final buffer = XmlStreamBuffer();
|
final buffer = XmlStreamBuffer();
|
||||||
final controller = StreamController<String>();
|
final controller = StreamController<String>();
|
||||||
|
|
||||||
unawaited(
|
controller
|
||||||
controller.stream.transform(buffer).forEach((node) {
|
.stream
|
||||||
|
.transform(buffer)
|
||||||
|
.forEach((node) {
|
||||||
if (node.tag == 'childa') {
|
if (node.tag == 'childa') {
|
||||||
childa = true;
|
childa = true;
|
||||||
} else if (node.tag == 'childb') {
|
} else if (node.tag == 'childb') {
|
||||||
childb = true;
|
childb = true;
|
||||||
}
|
}
|
||||||
}),
|
});
|
||||||
);
|
controller.add('<childa');
|
||||||
controller
|
controller.add(' /><childb />');
|
||||||
..add('<childa')
|
controller.add('</stream:stream>');
|
||||||
..add(' /><childb />')
|
|
||||||
..add('</stream:stream>');
|
|
||||||
|
|
||||||
await Future<void>.delayed(const Duration(seconds: 2));
|
await Future.delayed(const Duration(seconds: 2), () {
|
||||||
expect(childa, true);
|
expect(childa, true);
|
||||||
expect(childb, true);
|
expect(childb, true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,25 +5,11 @@ import 'helpers/logging.dart';
|
|||||||
import 'helpers/xmpp.dart';
|
import 'helpers/xmpp.dart';
|
||||||
|
|
||||||
/// Returns true if the roster manager triggeres an event for a given stanza
|
/// Returns true if the roster manager triggeres an event for a given stanza
|
||||||
Future<bool> testRosterManager(
|
Future<bool> testRosterManager(String bareJid, String resource, String stanzaString) async {
|
||||||
String bareJid,
|
|
||||||
String resource,
|
|
||||||
String stanzaString,
|
|
||||||
) async {
|
|
||||||
var eventTriggered = false;
|
var eventTriggered = false;
|
||||||
final roster = RosterManager(TestingRosterStateManager('', []))
|
final roster = RosterManager(TestingRosterStateManager('', []));
|
||||||
..register(
|
roster.register(XmppManagerAttributes(
|
||||||
XmppManagerAttributes(
|
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async => XMLNode(tag: 'hallo'),
|
||||||
sendStanza: (
|
|
||||||
_, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async =>
|
|
||||||
XMLNode(tag: 'hallo'),
|
|
||||||
sendEvent: (event) {
|
sendEvent: (event) {
|
||||||
eventTriggered = true;
|
eventTriggered = true;
|
||||||
},
|
},
|
||||||
@ -38,27 +24,12 @@ Future<bool> testRosterManager(
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('$bareJid/$resource'),
|
getFullJID: () => JID.fromString('$bareJid/$resource'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
),);
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
final stanza = Stanza.fromXMLNode(XMLNode.fromString(stanzaString));
|
final stanza = Stanza.fromXMLNode(XMLNode.fromString(stanzaString));
|
||||||
for (final handler in roster.getIncomingStanzaHandlers()) {
|
for (final handler in roster.getIncomingStanzaHandlers()) {
|
||||||
if (handler.matches(stanza)) {
|
if (handler.matches(stanza)) await handler.callback(stanza, StanzaHandlerData(false, false, null, stanza));
|
||||||
await handler.callback(
|
|
||||||
stanza,
|
|
||||||
StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
stanza,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return eventTriggered;
|
return eventTriggered;
|
||||||
@ -87,7 +58,7 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
|
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />'
|
||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
|
||||||
@ -115,25 +86,48 @@ void main() {
|
|||||||
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
|
||||||
ignoreId: true,
|
ignoreId: true,
|
||||||
),
|
),
|
||||||
StanzaExpectation(
|
/*
|
||||||
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
|
Expectation(
|
||||||
"<enabled xmlns='urn:xmpp:sm:3' id='some-long-sm-id' resume='true'/>",
|
XMLNode.xmlns(
|
||||||
|
tag: 'presence',
|
||||||
|
xmlns: 'jabber:client',
|
||||||
|
attributes: { 'from': 'polynomdivision@test.server/MU29eEZn' },
|
||||||
|
children: [
|
||||||
|
XMLNode(
|
||||||
|
tag: 'show',
|
||||||
|
text: 'chat',
|
||||||
),
|
),
|
||||||
|
XMLNode.xmlns(
|
||||||
|
tag: 'c',
|
||||||
|
xmlns: 'http://jabber.org/protocol/caps',
|
||||||
|
attributes: {
|
||||||
|
// TODO: Somehow make the test ignore this attribute
|
||||||
|
'ver': 'QRTBC5cg/oYd+UOTYazSQR4zb/I=',
|
||||||
|
'node': 'http://moxxmpp.example',
|
||||||
|
'hash': 'sha-1'
|
||||||
|
},
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
XMLNode(
|
||||||
|
tag: 'presence',
|
||||||
|
),
|
||||||
|
),
|
||||||
|
*/
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
// TODO(Unknown): This test is broken since we query the server and enable carbons
|
// TODO: This test is broken since we query the server and enable carbons
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
@ -141,18 +135,20 @@ void main() {
|
|||||||
StreamManagementManager(),
|
StreamManagementManager(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators(
|
||||||
|
[
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator(),
|
||||||
SaslScramNegotiator(10, '', '', ScramHashType.sha512),
|
SaslScramNegotiator(10, '', '', ScramHashType.sha512),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
StreamManagementNegotiator(),
|
StreamManagementNegotiator(),
|
||||||
]);
|
]
|
||||||
|
|
||||||
await conn.connect(
|
|
||||||
waitUntilLogin: true,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await conn.connect();
|
||||||
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
expect(fakeSocket.getState(), /*6*/ 5);
|
expect(fakeSocket.getState(), /*6*/ 5);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Test a failed SASL auth', () async {
|
test('Test a failed SASL auth', () async {
|
||||||
final fakeSocket = StubTCPSocket(
|
final fakeSocket = StubTCPSocket(
|
||||||
@ -174,23 +170,22 @@ void main() {
|
|||||||
),
|
),
|
||||||
StringExpectation(
|
StringExpectation(
|
||||||
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
'<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized /></failure>',
|
'<failure xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><not-authorized /></failure>'
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
var receivedEvent = false;
|
var receivedEvent = false;
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
@ -198,21 +193,20 @@ void main() {
|
|||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([
|
conn.registerFeatureNegotiators([
|
||||||
SaslPlainNegotiator(),
|
SaslPlainNegotiator()
|
||||||
]);
|
]);
|
||||||
|
|
||||||
conn.asBroadcastStream().listen((event) {
|
conn.asBroadcastStream().listen((event) {
|
||||||
if (event is AuthenticationFailedEvent &&
|
if (event is AuthenticationFailedEvent && event.saslError == 'not-authorized') {
|
||||||
event.saslError == 'not-authorized') {
|
|
||||||
receivedEvent = true;
|
receivedEvent = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await conn.connect(
|
await conn.connect();
|
||||||
waitUntilLogin: true,
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
);
|
|
||||||
expect(receivedEvent, true);
|
expect(receivedEvent, true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
test('Test another failed SASL auth', () async {
|
test('Test another failed SASL auth', () async {
|
||||||
final fakeSocket = StubTCPSocket(
|
final fakeSocket = StubTCPSocket(
|
||||||
@ -239,55 +233,94 @@ void main() {
|
|||||||
],
|
],
|
||||||
);
|
);
|
||||||
var receivedEvent = false;
|
var receivedEvent = false;
|
||||||
final conn = XmppConnection(
|
final XmppConnection conn = XmppConnection(
|
||||||
TestingReconnectionPolicy(),
|
TestingReconnectionPolicy(),
|
||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
)..setConnectionSettings(
|
);
|
||||||
ConnectionSettings(
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
jid: JID.fromString('polynomdivision@test.server'),
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
password: 'aaaa',
|
password: 'aaaa',
|
||||||
useDirectTLS: true,
|
useDirectTLS: true,
|
||||||
),
|
),);
|
||||||
);
|
conn.registerManagers([
|
||||||
await conn.registerManagers([
|
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
EntityCapabilitiesManager('http://moxxmpp.example'),
|
EntityCapabilitiesManager('http://moxxmpp.example'),
|
||||||
]);
|
]);
|
||||||
conn.registerFeatureNegotiators([SaslPlainNegotiator()]);
|
conn.registerFeatureNegotiators([
|
||||||
|
SaslPlainNegotiator()
|
||||||
|
]);
|
||||||
|
|
||||||
conn.asBroadcastStream().listen((event) {
|
conn.asBroadcastStream().listen((event) {
|
||||||
if (event is AuthenticationFailedEvent &&
|
if (event is AuthenticationFailedEvent && event.saslError == 'mechanism-too-weak') {
|
||||||
event.saslError == 'mechanism-too-weak') {
|
|
||||||
receivedEvent = true;
|
receivedEvent = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await conn.connect(
|
await conn.connect();
|
||||||
waitUntilLogin: true,
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
);
|
|
||||||
expect(receivedEvent, true);
|
expect(receivedEvent, true);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/*test('Test choosing SCRAM-SHA-1', () async {
|
||||||
|
final fakeSocket = StubTCPSocket(
|
||||||
|
play: [
|
||||||
|
StringExpectation(
|
||||||
|
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' 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">
|
||||||
|
<mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl">
|
||||||
|
<mechanism>PLAIN</mechanism>
|
||||||
|
<mechanism>SCRAM-SHA-1</mechanism>
|
||||||
|
</mechanisms>
|
||||||
|
</stream:features>''',
|
||||||
|
),
|
||||||
|
// TODO(Unknown): This test is currently broken
|
||||||
|
StringExpectation(
|
||||||
|
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='SCRAM-SHA-1'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
|
||||||
|
"..."
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
final XmppConnection conn = XmppConnection(TestingReconnectionPolicy(), fakeSocket);
|
||||||
|
conn.setConnectionSettings(ConnectionSettings(
|
||||||
|
jid: JID.fromString('polynomdivision@test.server'),
|
||||||
|
password: 'aaaa',
|
||||||
|
useDirectTLS: true,
|
||||||
|
),);
|
||||||
|
conn.registerManagers([
|
||||||
|
PresenceManager('http://moxxmpp.example'),
|
||||||
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
|
DiscoManager(),
|
||||||
|
PingManager(),
|
||||||
|
]);
|
||||||
|
conn.registerFeatureNegotiators([
|
||||||
|
SaslPlainNegotiator(),
|
||||||
|
SaslScramNegotiator(10, '', '', ScramHashType.sha1),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await conn.connect();
|
||||||
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
|
expect(fakeSocket.getState(), 2);
|
||||||
|
});
|
||||||
|
});*/
|
||||||
|
|
||||||
group('Test roster pushes', () {
|
group('Test roster pushes', () {
|
||||||
test('Test for a CVE-2015-8688 style vulnerability', () async {
|
test('Test for a CVE-2015-8688 style vulnerability', () async {
|
||||||
var eventTriggered = false;
|
var eventTriggered = false;
|
||||||
final roster = RosterManager(TestingRosterStateManager('', []))
|
final roster = RosterManager(TestingRosterStateManager('', []));
|
||||||
..register(
|
roster.register(XmppManagerAttributes(
|
||||||
XmppManagerAttributes(
|
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false, bool forceEncryption = false, }) async => XMLNode(tag: 'hallo'),
|
||||||
sendStanza: (
|
|
||||||
_, {
|
|
||||||
StanzaFromType addFrom = StanzaFromType.full,
|
|
||||||
bool addId = true,
|
|
||||||
bool retransmitted = false,
|
|
||||||
bool awaitable = true,
|
|
||||||
bool encrypted = false,
|
|
||||||
bool forceEncryption = false,
|
|
||||||
}) async =>
|
|
||||||
XMLNode(tag: 'hallo'),
|
|
||||||
sendEvent: (event) {
|
sendEvent: (event) {
|
||||||
eventTriggered = true;
|
eventTriggered = true;
|
||||||
},
|
},
|
||||||
@ -302,80 +335,29 @@ void main() {
|
|||||||
isFeatureSupported: (_) => false,
|
isFeatureSupported: (_) => false,
|
||||||
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
|
||||||
getSocket: () => StubTCPSocket([]),
|
getSocket: () => StubTCPSocket([]),
|
||||||
getConnection: () => XmppConnection(
|
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
|
||||||
TestingReconnectionPolicy(),
|
),);
|
||||||
AlwaysConnectedConnectivityManager(),
|
|
||||||
StubTCPSocket([]),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
// NOTE: Based on https://gultsch.de/gajim_roster_push_and_message_interception.html
|
// NOTE: Based on https://gultsch.de/gajim_roster_push_and_message_interception.html
|
||||||
// NOTE: Added a from attribute as a server would add it itself.
|
// NOTE: Added a from attribute as a server would add it itself.
|
||||||
final maliciousStanza = Stanza.fromXMLNode(
|
final maliciousStanza = Stanza.fromXMLNode(XMLNode.fromString("<iq type=\"set\" from=\"eve@siacs.eu/bbbbb\" to=\"some.user@example.server/aaaaa\"><query xmlns='jabber:iq:roster'><item subscription=\"both\" jid=\"eve@siacs.eu\" name=\"Bob\" /></query></iq>"));
|
||||||
XMLNode.fromString(
|
|
||||||
"<iq type=\"set\" from=\"eve@siacs.eu/bbbbb\" to=\"some.user@example.server/aaaaa\"><query xmlns='jabber:iq:roster'><item subscription=\"both\" jid=\"eve@siacs.eu\" name=\"Bob\" /></query></iq>",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
|
|
||||||
for (final handler in roster.getIncomingStanzaHandlers()) {
|
for (final handler in roster.getIncomingStanzaHandlers()) {
|
||||||
if (handler.matches(maliciousStanza)) {
|
if (handler.matches(maliciousStanza)) await handler.callback(maliciousStanza, StanzaHandlerData(false, false, null, maliciousStanza));
|
||||||
await handler.callback(
|
|
||||||
maliciousStanza,
|
|
||||||
StanzaHandlerData(
|
|
||||||
false,
|
|
||||||
false,
|
|
||||||
null,
|
|
||||||
maliciousStanza,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(
|
expect(eventTriggered, false, reason: 'Was able to inject a malicious roster push');
|
||||||
eventTriggered,
|
|
||||||
false,
|
|
||||||
reason: 'Was able to inject a malicious roster push',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
test('The manager should accept pushes from our bare jid', () async {
|
test('The manager should accept pushes from our bare jid', () async {
|
||||||
final result = await testRosterManager(
|
final result = await testRosterManager('test.user@server.example', 'aaaaa', "<iq from='test.user@server.example' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>");
|
||||||
'test.user@server.example',
|
expect(result, true, reason: 'Roster pushes from our bare JID should be accepted');
|
||||||
'aaaaa',
|
|
||||||
"<iq from='test.user@server.example' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
result,
|
|
||||||
true,
|
|
||||||
reason: 'Roster pushes from our bare JID should be accepted',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
test(
|
test('The manager should accept pushes from a jid that, if the resource is stripped, is our bare jid', () async {
|
||||||
'The manager should accept pushes from a jid that, if the resource is stripped, is our bare jid',
|
final result1 = await testRosterManager('test.user@server.example', 'aaaaa', "<iq from='test.user@server.example/aaaaa' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>");
|
||||||
() async {
|
expect(result1, true, reason: 'Roster pushes should be accepted if the bare JIDs are the same');
|
||||||
final result1 = await testRosterManager(
|
|
||||||
'test.user@server.example',
|
|
||||||
'aaaaa',
|
|
||||||
"<iq from='test.user@server.example/aaaaa' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
result1,
|
|
||||||
true,
|
|
||||||
reason:
|
|
||||||
'Roster pushes should be accepted if the bare JIDs are the same',
|
|
||||||
);
|
|
||||||
|
|
||||||
final result2 = await testRosterManager(
|
final result2 = await testRosterManager('test.user@server.example', 'aaaaa', "<iq from='test.user@server.example/bbbbb' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>");
|
||||||
'test.user@server.example',
|
expect(result2, true, reason: 'Roster pushes should be accepted if the bare JIDs are the same');
|
||||||
'aaaaa',
|
|
||||||
"<iq from='test.user@server.example/bbbbb' type='result' id='82c2aa1e-cac3-4f62-9e1f-bbe6b057daf3' to='test.user@server.example/aaaaa' xmlns='jabber:client'><query ver='64' xmlns='jabber:iq:roster'><item jid='some.other.user@server.example' subscription='to' /></query></iq>",
|
|
||||||
);
|
|
||||||
expect(
|
|
||||||
result2,
|
|
||||||
true,
|
|
||||||
reason:
|
|
||||||
'Roster pushes should be accepted if the bare JIDs are the same',
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -405,18 +387,19 @@ void main() {
|
|||||||
AlwaysConnectedConnectivityManager(),
|
AlwaysConnectedConnectivityManager(),
|
||||||
fakeSocket,
|
fakeSocket,
|
||||||
);
|
);
|
||||||
await conn.registerManagers([
|
conn.registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
RosterManager(TestingRosterStateManager('', [])),
|
RosterManager(TestingRosterStateManager('', [])),
|
||||||
DiscoManager([]),
|
DiscoManager([]),
|
||||||
PingManager(),
|
PingManager(),
|
||||||
]);
|
]);
|
||||||
conn
|
conn.registerFeatureNegotiators(
|
||||||
..registerFeatureNegotiators([
|
[
|
||||||
// SaslPlainNegotiator(),
|
// SaslPlainNegotiator(),
|
||||||
ResourceBindingNegotiator(),
|
ResourceBindingNegotiator(),
|
||||||
])
|
]
|
||||||
..setConnectionSettings(
|
);
|
||||||
|
conn.setConnectionSettings(
|
||||||
ConnectionSettings(
|
ConnectionSettings(
|
||||||
jid: JID.fromString('testuser@example.org'),
|
jid: JID.fromString('testuser@example.org'),
|
||||||
password: 'abc123',
|
password: 'abc123',
|
||||||
@ -428,9 +411,6 @@ void main() {
|
|||||||
waitUntilLogin: true,
|
waitUntilLogin: true,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(
|
expect(result.isType<NoMatchingAuthenticationMechanismAvailableError>(), true);
|
||||||
result.isType<NoMatchingAuthenticationMechanismAvailableError>(),
|
|
||||||
true,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user