chore(core): Remove useDirectTLS

This commit is contained in:
PapaTutuWawa 2023-04-04 15:52:56 +02:00
parent f6abf3d5b5
commit dc24b3c48a
16 changed files with 2 additions and 204 deletions

View File

@ -28,7 +28,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('component.localhost'), jid: JID.fromString('component.localhost'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
host: '127.0.0.1', host: '127.0.0.1',
port: 8888, port: 8888,
); );

View File

@ -29,7 +29,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@localhost'), jid: JID.fromString('testuser@localhost'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
host: '127.0.0.1', host: '127.0.0.1',
port: 5222, port: 5222,
); );

View File

@ -7,6 +7,8 @@
- **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same - **BREAKING**: Removed `isFeatureSupported` from the manager attributes. The managers now all have a method `isFeatureSupported` that works the same
- The `PresenceManager` is now optional - The `PresenceManager` is now optional
- **BREAKING**: Removed `setConnectionSettings` and `getConnectionSettings`. Just directly acces the `connectionSettings` field. - **BREAKING**: Removed `setConnectionSettings` and `getConnectionSettings`. Just directly acces the `connectionSettings` field.
- Implement XEP-0144 for implementing components
- **BREAKING**: Remove `useDirectTLS` from `ConnectionSettings`
## 0.1.6+1 ## 0.1.6+1

View File

@ -4,7 +4,6 @@ class ConnectionSettings {
ConnectionSettings({ ConnectionSettings({
required this.jid, required this.jid,
required this.password, required this.password,
required this.useDirectTLS,
this.host, this.host,
this.port, this.port,
}); });
@ -15,9 +14,6 @@ class ConnectionSettings {
/// The password to use during authentication. /// The password to use during authentication.
final String password; final String password;
/// Directly use TLS while connecting. Only effective if [host] and [port] are null.
final bool useDirectTLS;
/// The host to connect to. Skips DNS resolution if specified. /// The host to connect to. Skips DNS resolution if specified.
final String? host; final String? host;

View File

@ -34,7 +34,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('component.example.org'), jid: JID.fromString('component.example.org'),
password: 'abc123', password: 'abc123',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),

View File

@ -26,7 +26,6 @@ class TestingManagerHolder {
static final ConnectionSettings settings = ConnectionSettings( static final ConnectionSettings settings = ConnectionSettings(
jid: jid, jid: jid,
password: 'abc123', password: 'abc123',
useDirectTLS: true,
); );
Future<XMLNode> _sendStanza( Future<XMLNode> _sendStanza(

View File

@ -58,7 +58,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('test'), jid: JID.fromString('test'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
), ),
) )
..registerNegotiator(StubNegotiator1()) ..registerNegotiator(StubNegotiator1())
@ -77,7 +76,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('test'), jid: JID.fromString('test'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
), ),
) )
..registerNegotiator(StubNegotiator1()) ..registerNegotiator(StubNegotiator1())

View File

@ -55,7 +55,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
), ),
(_) async {}, (_) async {},
getNegotiatorNullStub, getNegotiatorNullStub,
@ -157,7 +156,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
), ),
(_) async {}, (_) async {},
getNegotiatorNullStub, getNegotiatorNullStub,
@ -214,7 +212,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
), ),
(_) async {}, (_) async {},
getNegotiatorNullStub, getNegotiatorNullStub,
@ -261,7 +258,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
), ),
(_) async {}, (_) async {},
getNegotiatorNullStub, getNegotiatorNullStub,
@ -311,7 +307,6 @@ void main() {
() => ConnectionSettings( () => ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
), ),
(_) async {}, (_) async {},
getNegotiatorNullStub, getNegotiatorNullStub,

View File

@ -75,7 +75,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),

View File

@ -61,7 +61,6 @@ XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString('hallo@example.server'), jid: JID.fromString('hallo@example.server'),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getFullJID: () => JID.fromString('hallo@example.server/uwu'), getFullJID: () => JID.fromString('hallo@example.server/uwu'),
getSocket: () => StubTCPSocket([]), getSocket: () => StubTCPSocket([]),
@ -286,7 +285,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
final sm = StreamManagementManager(); final sm = StreamManagementManager();
await conn.registerManagers([ await conn.registerManagers([
@ -410,166 +408,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
);
final sm = StreamManagementManager();
await conn.registerManagers([
PresenceManager(),
RosterManager(TestingRosterStateManager('', [])),
DiscoManager([]),
sm,
CarbonsManager()..forceEnable(),
//EntityCapabilitiesManager('http://moxxmpp.example'),
]);
await conn.registerFeatureNegotiators([
SaslPlainNegotiator(),
ResourceBindingNegotiator(),
StreamManagementNegotiator(),
]);
await conn.connect(
waitUntilLogin: true,
);
expect(fakeSocket.getState(), 6);
expect(await conn.getConnectionState(), XmppConnectionState.connected);
expect(
conn
.getManagerById<StreamManagementManager>(smManager)!
.isStreamManagementEnabled(),
true,
);
// Await an iq
await conn.sendStanza(
Stanza.iq(
to: 'user@example.com',
type: 'get',
),
addFrom: StanzaFromType.none,
);
expect(sm.state.s2c, 2);
});
});
group('Stream resumption', () {
test('Stanza retransmission', () async {
var stanzaCount = 0;
final attributes = mkAttributes((_) {
stanzaCount++;
});
final manager = StreamManagementManager()..register(attributes);
await manager.onXmppEvent(
StreamManagementEnabledEvent(resource: 'hallo'),
);
// Send 5 stanzas
for (var i = 0; i < 5; i++) {
await runOutgoingStanzaHandlers(manager, stanza);
}
// Only ack 3
// <a h='3' />
await manager.runNonzaHandlers(mkAck(3));
expect(manager.getUnackedStanzas().length, 2);
// Lose connection
// [ Reconnect ]
await manager.onXmppEvent(StreamResumedEvent(h: 3));
expect(stanzaCount, 2);
});
test('Resumption with prior state', () async {
var stanzaCount = 0;
final attributes = mkAttributes((_) {
stanzaCount++;
});
final manager = StreamManagementManager()..register(attributes);
// [ ... ]
await manager.onXmppEvent(
StreamManagementEnabledEvent(resource: 'hallo'),
);
await manager.setState(manager.state.copyWith(c2s: 150, s2c: 70));
// Send some stanzas but don't ack them
for (var i = 0; i < 5; i++) {
await runOutgoingStanzaHandlers(manager, stanza);
}
expect(manager.getUnackedStanzas().length, 5);
// Lose connection
// [ Reconnect ]
await manager.onXmppEvent(StreamResumedEvent(h: 150));
expect(manager.getUnackedStanzas().length, 0);
expect(stanzaCount, 5);
});
});
group('Test the negotiator', () {
test('Test successful stream enablement', () async {
final fakeSocket = StubTCPSocket([
StringExpectation(
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' from='polynomdivision@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>
</mechanisms>
</stream:features>''',
),
StringExpectation(
"<auth xmlns='urn:ietf:params:xml:ns:xmpp-sasl' mechanism='PLAIN'>AHBvbHlub21kaXZpc2lvbgBhYWFh</auth>",
'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl" />',
),
StringExpectation(
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' from='polynomdivision@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">
<bind xmlns="urn:ietf:params:xml:ns:xmpp-bind">
<required/>
</bind>
<session xmlns="urn:ietf:params:xml:ns:xmpp-session">
<optional/>
</session>
<csi xmlns="urn:xmpp:csi:0"/>
<sm xmlns="urn:xmpp:sm:3"/>
</stream:features>
''',
),
StanzaExpectation(
'<iq xmlns="jabber:client" type="set" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq>',
'<iq xmlns="jabber:client" type="result" id="a"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>polynomdivision@test.server/MU29eEZn</jid></bind></iq>',
ignoreId: true,
),
StringExpectation(
"<enable xmlns='urn:xmpp:sm:3' resume='true' />",
'<enabled xmlns="urn:xmpp:sm:3" id="some-long-sm-id" resume="true" />',
)
]);
final conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
ClientToServerNegotiator(),
fakeSocket,
)..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -662,7 +500,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -752,7 +589,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -839,7 +675,6 @@ void main() {
..connectionSettings = ConnectionSettings( ..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([
@ -937,7 +772,6 @@ void main() {
..connectionSettings = ConnectionSettings( ..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([
@ -1039,7 +873,6 @@ void main() {
..connectionSettings = ConnectionSettings( ..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([

View File

@ -28,7 +28,6 @@ void main() {
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString('bob@xmpp.example'), jid: JID.fromString('bob@xmpp.example'),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getFullJID: () => JID.fromString('bob@xmpp.example/uwu'), getFullJID: () => JID.fromString('bob@xmpp.example/uwu'),
getSocket: () => StubTCPSocket([]), getSocket: () => StubTCPSocket([]),
@ -110,7 +109,6 @@ void main() {
..connectionSettings = ConnectionSettings( ..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
) )
..setResource('test-resource', triggerEvent: false); ..setResource('test-resource', triggerEvent: false);
await conn.registerManagers([ await conn.registerManagers([

View File

@ -54,7 +54,6 @@ void main() {
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString('some.user@example.server'), jid: JID.fromString('some.user@example.server'),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getManagerById: getManagerNullStub, getManagerById: getManagerNullStub,
getNegotiatorById: getUnsupportedCSINegotiator, getNegotiatorById: getUnsupportedCSINegotiator,
@ -98,7 +97,6 @@ void main() {
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString('some.user@example.server'), jid: JID.fromString('some.user@example.server'),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getManagerById: getManagerNullStub, getManagerById: getManagerNullStub,
getNegotiatorById: getSupportedCSINegotiator, getNegotiatorById: getSupportedCSINegotiator,
@ -174,7 +172,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
final csi = CSIManager(); final csi = CSIManager();
await csi.setInactive(sendNonza: false); await csi.setInactive(sendNonza: false);

View File

@ -49,7 +49,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -121,7 +120,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),

View File

@ -106,7 +106,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -185,7 +184,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -263,7 +261,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('user@server'), jid: JID.fromString('user@server'),
password: 'pencil', password: 'pencil',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -349,7 +346,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -433,7 +429,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),

View File

@ -112,7 +112,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),
@ -226,7 +225,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),

View File

@ -31,7 +31,6 @@ Future<bool> testRosterManager(
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString(bareJid), jid: JID.fromString(bareJid),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getManagerById: getManagerNullStub, getManagerById: getManagerNullStub,
getNegotiatorById: getNegotiatorNullStub, getNegotiatorById: getNegotiatorNullStub,
@ -130,7 +129,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -186,7 +184,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -244,7 +241,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'), jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa', password: 'aaaa',
useDirectTLS: true,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -290,7 +286,6 @@ void main() {
getConnectionSettings: () => ConnectionSettings( getConnectionSettings: () => ConnectionSettings(
jid: JID.fromString('some.user@example.server'), jid: JID.fromString('some.user@example.server'),
password: 'password', password: 'password',
useDirectTLS: true,
), ),
getManagerById: getManagerNullStub, getManagerById: getManagerNullStub,
getNegotiatorById: getNegotiatorNullStub, getNegotiatorById: getNegotiatorNullStub,
@ -403,7 +398,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@example.org'), jid: JID.fromString('testuser@example.org'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
); );
await conn.registerManagers([ await conn.registerManagers([
PresenceManager(), PresenceManager(),
@ -497,7 +491,6 @@ void main() {
)..connectionSettings = ConnectionSettings( )..connectionSettings = ConnectionSettings(
jid: JID.fromString('testuser@example.org'), jid: JID.fromString('testuser@example.org'),
password: 'abc123', password: 'abc123',
useDirectTLS: false,
); );
await conn.registerManagers([ await conn.registerManagers([
RosterManager(TestingRosterStateManager('', [])), RosterManager(TestingRosterStateManager('', [])),