test: Fix negotiator test
This commit is contained in:
parent
a37cf62f70
commit
30b77c9808
@ -1,11 +1,17 @@
|
|||||||
import "package:test/test.dart";
|
import "package:test/test.dart";
|
||||||
import "package:moxxyv2/xmpp/stringxml.dart";
|
import "package:moxxyv2/xmpp/stringxml.dart";
|
||||||
import "package:moxxyv2/xmpp/connection.dart";
|
import "package:moxxyv2/xmpp/connection.dart";
|
||||||
|
import "package:moxxyv2/xmpp/jid.dart";
|
||||||
import "package:moxxyv2/xmpp/reconnect.dart";
|
import "package:moxxyv2/xmpp/reconnect.dart";
|
||||||
import "package:moxxyv2/xmpp/presence.dart";
|
import "package:moxxyv2/xmpp/presence.dart";
|
||||||
|
import "package:moxxyv2/xmpp/ping.dart";
|
||||||
|
import "package:moxxyv2/xmpp/roster.dart";
|
||||||
|
import "package:moxxyv2/xmpp/settings.dart";
|
||||||
import "package:moxxyv2/xmpp/negotiators/negotiator.dart";
|
import "package:moxxyv2/xmpp/negotiators/negotiator.dart";
|
||||||
|
import "package:moxxyv2/xmpp/xeps/xep_0030/xep_0030.dart";
|
||||||
|
|
||||||
import "helpers/logging.dart";
|
import "helpers/logging.dart";
|
||||||
|
import "helpers/xmpp.dart";
|
||||||
|
|
||||||
const exampleXmlns1 = "im:moxxy:example1";
|
const exampleXmlns1 = "im:moxxy:example1";
|
||||||
const exampleNamespace1 = "im.moxxy.test.example1";
|
const exampleNamespace1 = "im.moxxy.test.example1";
|
||||||
@ -19,6 +25,7 @@ class StubNegotiator1 extends XmppFeatureNegotiatorBase {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Future<void> negotiate(XMLNode nonza) async {
|
Future<void> negotiate(XMLNode nonza) async {
|
||||||
|
called = true;
|
||||||
state = NegotiatorState.done;
|
state = NegotiatorState.done;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -38,14 +45,70 @@ class StubNegotiator2 extends XmppFeatureNegotiatorBase {
|
|||||||
void main() {
|
void main() {
|
||||||
initLogger();
|
initLogger();
|
||||||
|
|
||||||
final connection = XmppConnection(TestingReconnectionPolicy())
|
final stubSocket = StubTCPSocket(
|
||||||
|
play: [
|
||||||
|
Expectation(
|
||||||
|
XMLNode(
|
||||||
|
tag: "stream:stream",
|
||||||
|
attributes: {
|
||||||
|
"xmlns": "jabber:client",
|
||||||
|
"version": "1.0",
|
||||||
|
"xmlns:stream": "http://etherx.jabber.org/streams",
|
||||||
|
"to": "test.server",
|
||||||
|
"xml:lang": "en"
|
||||||
|
},
|
||||||
|
closeTag: false
|
||||||
|
),
|
||||||
|
XMLNode(
|
||||||
|
tag: "stream:stream",
|
||||||
|
attributes: {
|
||||||
|
"xmlns": "jabber:client",
|
||||||
|
"version": "1.0",
|
||||||
|
"xmlns:stream": "http://etherx.jabber.org/streams",
|
||||||
|
"from": "test.server",
|
||||||
|
"xml:lang": "en"
|
||||||
|
},
|
||||||
|
closeTag: false,
|
||||||
|
children: [
|
||||||
|
XMLNode.xmlns(
|
||||||
|
tag: "stream:features",
|
||||||
|
xmlns: "http://etherx.jabber.org/streams",
|
||||||
|
children: [
|
||||||
|
XMLNode.xmlns(
|
||||||
|
tag: "example1",
|
||||||
|
xmlns: exampleXmlns1,
|
||||||
|
),
|
||||||
|
XMLNode.xmlns(
|
||||||
|
tag: "example2",
|
||||||
|
xmlns: exampleXmlns2,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
|
),
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
final connection = XmppConnection(TestingReconnectionPolicy(), socket: stubSocket)
|
||||||
..registerFeatureNegotiators([
|
..registerFeatureNegotiators([
|
||||||
StubNegotiator1(),
|
StubNegotiator1(),
|
||||||
StubNegotiator2(),
|
StubNegotiator2(),
|
||||||
])
|
])
|
||||||
..registerManagers([
|
..registerManagers([
|
||||||
PresenceManager(),
|
PresenceManager(),
|
||||||
]);
|
RosterManager(),
|
||||||
|
DiscoManager(),
|
||||||
|
PingManager(),
|
||||||
|
])
|
||||||
|
..setConnectionSettings(
|
||||||
|
ConnectionSettings(
|
||||||
|
jid: JID.fromString("user@test.server"),
|
||||||
|
password: "abc123",
|
||||||
|
useDirectTLS: true,
|
||||||
|
allowPlainAuth: false,
|
||||||
|
)
|
||||||
|
);
|
||||||
final features = [
|
final features = [
|
||||||
XMLNode.xmlns(tag: "example1", xmlns: exampleXmlns1),
|
XMLNode.xmlns(tag: "example1", xmlns: exampleXmlns1),
|
||||||
XMLNode.xmlns(tag: "example2", xmlns: exampleXmlns2),
|
XMLNode.xmlns(tag: "example2", xmlns: exampleXmlns2),
|
||||||
@ -56,13 +119,12 @@ void main() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test("Test negotiating features with no stream restarts", () async {
|
test("Test negotiating features with no stream restarts", () async {
|
||||||
// TODO: Use a simple connection setup to test this
|
await connection.connect();
|
||||||
final streamFeatures = XMLNode(tag: "stream:features", children: features);
|
await Future.delayed(const Duration(seconds: 3), () {
|
||||||
await connection.handleXmlStream(streamFeatures);
|
final negotiator1 = connection.getNegotiatorById(exampleNamespace1) as StubNegotiator1?;
|
||||||
|
final negotiator2 = connection.getNegotiatorById(exampleNamespace2) as StubNegotiator2?;
|
||||||
final negotiator1 = connection.getNegotiatorById(exampleNamespace1) as StubNegotiator1?;
|
expect(negotiator1?.called, true);
|
||||||
final negotiator2 = connection.getNegotiatorById(exampleNamespace2) as StubNegotiator2?;
|
expect(negotiator2?.called, true);
|
||||||
expect(negotiator1?.called, true);
|
});
|
||||||
expect(negotiator2?.called, true);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user