tests: Fix tests

This commit is contained in:
PapaTutuWawa 2023-01-07 18:40:36 +01:00
parent 67446285c1
commit 473f8e4bb6
4 changed files with 22 additions and 15 deletions

View File

@ -1,5 +1,6 @@
import 'dart:async'; import 'dart:async';
import 'package:moxxmpp/src/jid.dart'; import 'package:moxxmpp/src/jid.dart';
import 'package:moxxmpp/src/managers/attributes.dart';
import 'package:moxxmpp/src/managers/base.dart'; import 'package:moxxmpp/src/managers/base.dart';
import 'package:moxxmpp/src/managers/data.dart'; import 'package:moxxmpp/src/managers/data.dart';
import 'package:moxxmpp/src/managers/handlers.dart'; import 'package:moxxmpp/src/managers/handlers.dart';
@ -66,11 +67,17 @@ class RosterFeatureNegotiator extends XmppFeatureNegotiatorBase {
/// This manager requires a RosterFeatureNegotiator to be registered. /// This manager requires a RosterFeatureNegotiator to be registered.
class RosterManager extends XmppManagerBase { class RosterManager extends XmppManagerBase {
RosterManager(this._stateManager) : super() { RosterManager(this._stateManager) : super();
_stateManager.register(getAttributes().sendEvent);
} /// The class managing the entire roster state.
final BaseRosterStateManager _stateManager; final BaseRosterStateManager _stateManager;
@override
void register(XmppManagerAttributes attributes) {
super.register(attributes);
_stateManager.register(attributes.sendEvent);
}
@override @override
String getId() => rosterManager; String getId() => rosterManager;

View File

@ -61,7 +61,7 @@ void main() {
]) ])
..registerManagers([ ..registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
]) ])

View File

@ -243,7 +243,7 @@ void main() {
final sm = StreamManagementManager(); final sm = StreamManagementManager();
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
sm, sm,
@ -365,7 +365,7 @@ void main() {
final sm = StreamManagementManager(); final sm = StreamManagementManager();
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
sm, sm,
@ -519,7 +519,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
StreamManagementManager(), StreamManagementManager(),
@ -611,7 +611,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
StreamManagementManager(), StreamManagementManager(),
@ -703,7 +703,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
StreamManagementManager(), StreamManagementManager(),

View File

@ -7,7 +7,7 @@ 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(String bareJid, String resource, String stanzaString) async { Future<bool> testRosterManager(String bareJid, String resource, String stanzaString) async {
var eventTriggered = false; var eventTriggered = false;
final roster = RosterManager(); final roster = RosterManager(TestingRosterStateManager('', []));
roster.register(XmppManagerAttributes( roster.register(XmppManagerAttributes(
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false }) async => XMLNode(tag: 'hallo'), sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false }) async => XMLNode(tag: 'hallo'),
sendEvent: (event) { sendEvent: (event) {
@ -127,7 +127,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
StreamManagementManager(), StreamManagementManager(),
@ -181,7 +181,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
]); ]);
@ -235,7 +235,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
]); ]);
@ -290,7 +290,7 @@ void main() {
),); ),);
conn.registerManagers([ conn.registerManagers([
PresenceManager('http://moxxmpp.example'), PresenceManager('http://moxxmpp.example'),
RosterManager(), RosterManager(TestingRosterStateManager('', [])),
DiscoManager(), DiscoManager(),
PingManager(), PingManager(),
]); ]);
@ -308,7 +308,7 @@ void main() {
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(); final roster = RosterManager(TestingRosterStateManager('', []));
roster.register(XmppManagerAttributes( roster.register(XmppManagerAttributes(
sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false }) async => XMLNode(tag: 'hallo'), sendStanza: (_, { StanzaFromType addFrom = StanzaFromType.full, bool addId = true, bool retransmitted = false, bool awaitable = true, bool encrypted = false }) async => XMLNode(tag: 'hallo'),
sendEvent: (event) { sendEvent: (event) {