test: Fix test failures

This commit is contained in:
PapaTutuWawa 2022-07-28 22:49:54 +02:00
parent 3bb273a88b
commit e08a175798
4 changed files with 48 additions and 59 deletions

View File

@ -7,7 +7,6 @@ import 'package:moxxyv2/xmpp/reconnect.dart';
import 'package:moxxyv2/xmpp/roster.dart';
import 'package:moxxyv2/xmpp/settings.dart';
import 'package:moxxyv2/xmpp/stringxml.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/cachemanager.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/xep_0030.dart';
import 'package:test/test.dart';
@ -75,7 +74,6 @@ void main() {
RosterManager(),
DiscoManager(),
PingManager(),
DiscoCacheManager(),
])
..setConnectionSettings(
ConnectionSettings(

View File

@ -1,4 +1,5 @@
import 'package:cryptography/cryptography.dart';
import 'package:moxxyv2/xmpp/jid.dart';
import 'package:moxxyv2/xmpp/stringxml.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0004.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/helpers.dart';
@ -7,21 +8,22 @@ import 'package:test/test.dart';
void main() {
test('Test XEP example', () async {
const data = DiscoInfo(
features: [
final data = DiscoInfo(
[
'http://jabber.org/protocol/caps',
'http://jabber.org/protocol/disco#info',
'http://jabber.org/protocol/disco#items',
'http://jabber.org/protocol/muc'
],
identities: [
[
Identity(
category: 'client',
type: 'pc',
name: 'Exodus 0.9.1',
)
],
extendedInfo: [],
[],
JID.fromString('some@user.local/test'),
);
final hash = await calculateCapabilityHash(data, Sha1());
@ -31,7 +33,13 @@ void main() {
test('Test complex generation example', () async {
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>";
final data = DiscoInfo(
identities: [
[
'http://jabber.org/protocol/caps',
'http://jabber.org/protocol/disco#info',
'http://jabber.org/protocol/disco#items',
'http://jabber.org/protocol/muc'
],
[
const Identity(
category: 'client',
type: 'pc',
@ -45,13 +53,8 @@ void main() {
lang: 'el',
),
],
features: [
'http://jabber.org/protocol/caps',
'http://jabber.org/protocol/disco#info',
'http://jabber.org/protocol/disco#items',
'http://jabber.org/protocol/muc'
],
extendedInfo: [ parseDataForm(XMLNode.fromString(extDiscoDataString)) ],
[ parseDataForm(XMLNode.fromString(extDiscoDataString)) ],
JID.fromString('some@user.local/test'),
);
final hash = await calculateCapabilityHash(data, Sha1());
@ -118,8 +121,8 @@ void main() {
});
test('Test Conversations hash computation', () async {
const data = DiscoInfo(
features: [
final data = DiscoInfo(
[
'eu.siacs.conversations.axolotl.devicelist+notify',
'http://jabber.org/protocol/caps',
'http://jabber.org/protocol/chatstates',
@ -151,14 +154,15 @@ void main() {
'urn:xmpp:receipts',
'urn:xmpp:time'
],
identities: [
[
Identity(
category: 'client',
type: 'phone',
name: 'Conversations',
)
],
extendedInfo: [],
[],
JID.fromString('user@server.local/test'),
);
final hash = await calculateCapabilityHash(data, Sha1());

View File

@ -14,7 +14,6 @@ import 'package:moxxyv2/xmpp/roster.dart';
import 'package:moxxyv2/xmpp/settings.dart';
import 'package:moxxyv2/xmpp/stanza.dart';
import 'package:moxxyv2/xmpp/stringxml.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/cachemanager.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/xep_0030.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0198/negotiator.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0198/state.dart';
@ -322,10 +321,8 @@ void main() {
PresenceManager(),
RosterManager(),
DiscoManager(),
DiscoCacheManager(),
PingManager(),
StreamManagementManager(),
DiscoCacheManager(),
]);
conn.registerFeatureNegotiators(
[
@ -336,14 +333,14 @@ void main() {
);
await conn.connect();
await Future.delayed(const Duration(seconds: 3), () {
expect(fakeSocket.getState(), 5);
expect(conn.getConnectionState(), XmppConnectionState.connected);
expect(
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
true,
);
});
await Future.delayed(const Duration(seconds: 3));
expect(fakeSocket.getState(), 6);
expect(conn.getConnectionState(), XmppConnectionState.connected);
expect(
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
true,
);
});
test('Test a failed stream resumption', () async {
@ -416,10 +413,8 @@ void main() {
PresenceManager(),
RosterManager(),
DiscoManager(),
DiscoCacheManager(),
PingManager(),
StreamManagementManager(),
DiscoCacheManager(),
]);
conn.registerFeatureNegotiators(
[
@ -439,7 +434,7 @@ void main() {
await conn.connect();
await Future.delayed(const Duration(seconds: 3), () {
expect(fakeSocket.getState(), 6);
expect(fakeSocket.getState(), 7);
expect(conn.getConnectionState(), XmppConnectionState.connected);
expect(
conn.getManagerById<StreamManagementManager>(smManager)!.isStreamManagementEnabled(),
@ -509,10 +504,8 @@ void main() {
PresenceManager(),
RosterManager(),
DiscoManager(),
DiscoCacheManager(),
PingManager(),
StreamManagementManager(),
DiscoCacheManager(),
]);
conn.registerFeatureNegotiators(
[
@ -532,7 +525,7 @@ void main() {
await conn.connect(lastResource: 'abc123');
await Future.delayed(const Duration(seconds: 3), () {
expect(fakeSocket.getState(), 4);
expect(fakeSocket.getState(), 6);
expect(conn.getConnectionState(), XmppConnectionState.connected);
final sm = conn.getManagerById<StreamManagementManager>(smManager)!;
expect(sm.isStreamManagementEnabled(), true);

View File

@ -15,7 +15,6 @@ import 'package:moxxyv2/xmpp/roster.dart';
import 'package:moxxyv2/xmpp/settings.dart';
import 'package:moxxyv2/xmpp/stanza.dart';
import 'package:moxxyv2/xmpp/stringxml.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/cachemanager.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0030/xep_0030.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0198/negotiator.dart';
import 'package:moxxyv2/xmpp/xeps/xep_0198/xep_0198.dart';
@ -147,13 +146,11 @@ void main() {
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
RosterManager(),
DiscoManager(),
DiscoCacheManager(),
PingManager(),
StreamManagementManager(),
DiscoCacheManager(),
PresenceManager(),
RosterManager(),
DiscoManager(),
PingManager(),
StreamManagementManager(),
]);
conn.registerFeatureNegotiators(
[
@ -166,7 +163,7 @@ void main() {
await conn.connect();
await Future.delayed(const Duration(seconds: 3), () {
expect(fakeSocket.getState(), /*5*/ 4);
expect(fakeSocket.getState(), /*6*/ 5);
});
});
@ -207,7 +204,6 @@ void main() {
RosterManager(),
DiscoManager(),
PingManager(),
DiscoCacheManager(),
]);
conn.registerFeatureNegotiators([
SaslPlainNegotiator()
@ -258,11 +254,10 @@ void main() {
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
RosterManager(),
DiscoManager(),
PingManager(),
DiscoCacheManager(),
PresenceManager(),
RosterManager(),
DiscoManager(),
PingManager(),
]);
conn.registerFeatureNegotiators([
SaslPlainNegotiator()
@ -308,17 +303,16 @@ void main() {
);
final XmppConnection conn = XmppConnection(TestingReconnectionPolicy(), socket: fakeSocket);
conn.setConnectionSettings(ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: false,
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: false,
),);
conn.registerManagers([
PresenceManager(),
RosterManager(),
DiscoManager(),
PingManager(),
DiscoCacheManager(),
PresenceManager(),
RosterManager(),
DiscoManager(),
PingManager(),
]);
conn.registerFeatureNegotiators([
SaslPlainNegotiator(),