Compare commits

...

3 Commits

Author SHA1 Message Date
308f7d93f5 chore(example): Update the example 2023-03-18 14:59:47 +01:00
de85bf848d fix(core): Fix crash when no negotiator matches
Fixes #30.

Also removes the `allowPlainAuth` attribute of `ConnectionSettings` as
users who want to disable SASL PLAIN can just not register the
negotiator or extend it.
2023-03-18 14:54:39 +01:00
7a6bf468bc test(xep): Add a test for parsing sticker packs 2023-03-16 22:04:25 +01:00
17 changed files with 366 additions and 69 deletions

View File

@ -110,11 +110,6 @@ class _MyHomePageState extends State<MyHomePage> {
jid: JID.fromString(jidController.text),
password: passwordController.text,
useDirectTLS: true,
// If `allowPlainAuth` is `false`, connecting to some
// servers will cause apps to hang, and never connect.
// The hang is a bug that will be fixed, so when it is,
// allowPlainAuth should be set to false.
allowPlainAuth: true,
),
);
final result = await connection.connect(waitUntilLogin: true);
@ -122,14 +117,14 @@ class _MyHomePageState extends State<MyHomePage> {
connected = result.isType<bool>() && result.get<bool>();
loading = false;
});
if (result.isType<XmppConnectionError>()) {
logger.severe(result.get<XmppConnectionError>());
if (result.isType<XmppError>()) {
logger.severe(result.get<XmppError>());
if (context.mounted) {
showDialog(
context: context,
builder: (_) => AlertDialog(
title: const Text('Error'),
content: Text(result.get<XmppConnectionError>().toString()),
content: Text(result.get<XmppError>().toString()),
),
);
}

View File

@ -1,6 +1,7 @@
## 0.3.0
- **BREAKING**: Removed `connectAwaitable` and merged it with `connect`.
- **BREAKING**: Removed `allowPlainAuth` from `ConnectionSettings`. If you don't want to use SASL PLAIN, don't register the negotiator. If you want to only conditionally use SASL PLAIN, extend the `SaslPlainNegotiator` and override its `matchesFeature` method to only call the super method when SASL PLAIN should be used.
## 0.1.6+1

View File

@ -1,6 +1,7 @@
library moxxmpp;
export 'package:moxxmpp/src/connection.dart';
export 'package:moxxmpp/src/connection_errors.dart';
export 'package:moxxmpp/src/connectivity.dart';
export 'package:moxxmpp/src/errors.dart';
export 'package:moxxmpp/src/events.dart';

View File

@ -395,9 +395,7 @@ class XmppConnection {
);
_connectionCompleter?.complete(
Result(
StreamFailureError(
error,
),
error,
),
);
_connectionCompleter = null;
@ -875,7 +873,7 @@ class XmppConnection {
}
Future<void> _executeCurrentNegotiator(XMLNode nonza) async {
// If we don't have a negotiator get one
// If we don't have a negotiator, get one
_currentNegotiator ??= getNextNegotiator(_streamFeatures);
if (_currentNegotiator == null &&
_isMandatoryNegotiationDone(_streamFeatures) &&
@ -886,6 +884,25 @@ class XmppConnection {
return;
}
// If we don't have a next negotiator, we have to bail
if (_currentNegotiator == null &&
!_isMandatoryNegotiationDone(_streamFeatures) &&
!_isNegotiationPossible(_streamFeatures)) {
// We failed before authenticating
if (!_isAuthenticated) {
_log.severe('No negotiator could be picked while unauthenticated');
await _resetIsConnectionRunning();
await handleError(NoMatchingAuthenticationMechanismAvailableError());
return;
} else {
_log.severe(
'No negotiator could be picked while negotiations are not done');
await _resetIsConnectionRunning();
await handleError(NoAuthenticatorAvailableError());
return;
}
}
final result = await _currentNegotiator!.negotiate(nonza);
if (result.isType<NegotiatorError>()) {
_log.severe('Negotiator returned an error');

View File

@ -2,16 +2,22 @@ import 'package:moxxmpp/src/errors.dart';
import 'package:moxxmpp/src/negotiators/negotiator.dart';
/// The reason a call to `XmppConnection.connect` failed.
abstract class XmppConnectionError {}
abstract class XmppConnectionError extends XmppError {}
/// Returned by `XmppConnection.connect` when a connection is already active.
class ConnectionAlreadyRunningError extends XmppConnectionError {}
class ConnectionAlreadyRunningError extends XmppConnectionError {
@override
bool isRecoverable() => true;
}
/// Returned by `XmppConnection.connect` when a negotiator returned an unrecoverable
/// error. Only returned when waitUntilLogin is true.
class NegotiatorReturnedError extends XmppConnectionError {
NegotiatorReturnedError(this.error);
@override
bool isRecoverable() => error.isRecoverable();
/// The error returned by the negotiator.
final NegotiatorError error;
}
@ -19,10 +25,30 @@ class NegotiatorReturnedError extends XmppConnectionError {
class StreamFailureError extends XmppConnectionError {
StreamFailureError(this.error);
@override
bool isRecoverable() => error.isRecoverable();
/// The error that causes a connection failure.
final XmppError error;
}
/// Returned by `XmppConnection.connect` when no connection could
/// be established.
class NoConnectionPossibleError extends XmppConnectionError {}
class NoConnectionPossibleError extends XmppConnectionError {
@override
bool isRecoverable() => true;
}
/// Returned if no matching authentication mechanism has been presented
class NoMatchingAuthenticationMechanismAvailableError
extends XmppConnectionError {
@override
bool isRecoverable() => false;
}
/// Returned if no negotiator was picked, even though negotiations are not done
/// yet.
class NoAuthenticatorAvailableError extends XmppConnectionError {
@override
bool isRecoverable() => false;
}

View File

@ -28,8 +28,6 @@ class SaslPlainNegotiator extends SaslNegotiator {
@override
bool matchesFeature(List<XMLNode> features) {
if (!attributes.getConnectionSettings().allowPlainAuth) return false;
if (super.matchesFeature(features)) {
if (!attributes.getSocket().isSecure()) {
_log.warning(

View File

@ -5,10 +5,8 @@ class ConnectionSettings {
required this.jid,
required this.password,
required this.useDirectTLS,
required this.allowPlainAuth,
});
final JID jid;
final String password;
final bool useDirectTLS;
final bool allowPlainAuth;
}

View File

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

View File

@ -51,11 +51,8 @@ class StanzaExpectation extends ExpectationBase {
}
}
/// Use [settings] to build the beginning of a play that can be used with StubTCPSocket. [settings]'s allowPlainAuth must
/// be set to true.
List<ExpectationBase> buildAuthenticatedPlay(ConnectionSettings settings) {
assert(settings.allowPlainAuth, 'SASL PLAIN must be allowed');
final plain = base64.encode(
utf8.encode('\u0000${settings.jid.local}\u0000${settings.password}'),
);

View File

@ -36,7 +36,7 @@ void main() {
initLogger();
final stubSocket = StubTCPSocket(
play: [
[
StringExpectation(
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='test.server' xml:lang='en'>",
'''
@ -74,7 +74,6 @@ void main() {
jid: JID.fromString('user@test.server'),
password: 'abc123',
useDirectTLS: true,
allowPlainAuth: false,
),
);
final features = [

View File

@ -36,13 +36,13 @@ final scramSha256StreamFeatures = XMLNode(
);
void main() {
final fakeSocket = StubTCPSocket(play: []);
final fakeSocket = StubTCPSocket([]);
test('Test SASL SCRAM-SHA-1', () async {
final negotiator = SaslScramNegotiator(0, 'n=user,r=fyko+d2lbbFgONRv9qkxdawL', 'fyko+d2lbbFgONRv9qkxdawL', ScramHashType.sha1);
negotiator.register(
NegotiatorAttributes(
(XMLNode _, {String? redact}) {},
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true, allowPlainAuth: true),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
(_) async {},
getNegotiatorNullStub,
getManagerNullStub,
@ -106,7 +106,7 @@ void main() {
negotiator.register(
NegotiatorAttributes(
(XMLNode n, {String? redact}) => lastMessage = n.innerText(),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true, allowPlainAuth: true),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
(_) async {},
getNegotiatorNullStub,
getManagerNullStub,
@ -138,7 +138,7 @@ void main() {
negotiator.register(
NegotiatorAttributes(
(XMLNode _, {String? redact}) {},
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true, allowPlainAuth: true),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
(_) async {},
getNegotiatorNullStub,
getManagerNullStub,
@ -160,7 +160,7 @@ void main() {
negotiator.register(
NegotiatorAttributes(
(XMLNode _, {String? redact}) {},
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true, allowPlainAuth: true),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
(_) async {},
getNegotiatorNullStub,
getManagerNullStub,
@ -186,7 +186,7 @@ void main() {
negotiator.register(
NegotiatorAttributes(
(XMLNode _, {String? redact}) {},
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true, allowPlainAuth: true),
() => ConnectionSettings(jid: JID.fromString('user@server'), password: 'pencil', useDirectTLS: true),
(_) async {},
getNegotiatorNullStub,
getManagerNullStub,

View File

@ -10,7 +10,7 @@ void main() {
test('Test having multiple disco requests for the same JID', () 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'>",
'''
@ -78,7 +78,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),

View File

@ -29,12 +29,11 @@ XmppManagerAttributes mkAttributes(void Function(Stanza) callback) {
jid: JID.fromString('hallo@example.server'),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('hallo@example.server/uwu'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
getNegotiatorById: getNegotiatorNullStub,
);
}
@ -180,7 +179,7 @@ void main() {
test('Test counting incoming stanzas for which handlers end early', () 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'>",
'''
@ -242,7 +241,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
final sm = StreamManagementManager();
conn.registerManagers([
@ -297,7 +295,7 @@ void main() {
test('Test counting incoming stanzas that are awaited', () 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'>",
'''
@ -369,7 +367,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
final sm = StreamManagementManager();
conn.registerManagers([
@ -467,7 +464,7 @@ void main() {
group('Test the negotiator', () {
test('Test successful stream enablement', () 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'>",
'''
@ -529,7 +526,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
@ -559,7 +555,7 @@ void main() {
test('Test a failed stream resumption', () 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'>",
'''
@ -625,7 +621,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
@ -664,7 +659,7 @@ void main() {
test('Test a successful stream resumption', () 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'>",
'''
@ -721,7 +716,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),

View File

@ -17,12 +17,11 @@ void main() {
jid: JID.fromString('bob@xmpp.example'),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('bob@xmpp.example/uwu'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
getNegotiatorById: getNegotiatorNullStub,
);
final manager = CarbonsManager();

View File

@ -43,14 +43,13 @@ void main() {
jid: JID.fromString('some.user@example.server'),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
getManagerById: getManagerNullStub,
getNegotiatorById: getUnsupportedCSINegotiator,
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
),
);
@ -72,14 +71,13 @@ void main() {
jid: JID.fromString('some.user@example.server'),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
getManagerById: getManagerNullStub,
getNegotiatorById: getSupportedCSINegotiator,
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
),
);

View File

@ -0,0 +1,228 @@
import 'package:test/test.dart';
import 'package:moxxmpp/moxxmpp.dart';
void main() {
test('Test parsing a large sticker pack', () {
// Example sticker pack based on the "miho" sticker pack by Movim
final rawPack = XMLNode.fromString('''
<pack xmlns='urn:xmpp:stickers:0'>
<name>Miho</name>
<summary>XMPP-chan.</summary>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho no:</desc>
<name>no.png</name>
<size>32088</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>LmIVPPPfOfmf8JLCCi0UFbjzILuRhJlkgzeN/nKIrm8=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/fd759226e3ec153956f3e941b81ed820614792a6.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho good:</desc>
<name>good.png</name>
<size>35529</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>Yu8qycCh5e3ZjZGTL5jadHAzni8ufvI+9Y7sKXjFLfE=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/100bdb0e14c557b87ad4d253018b71eb65b80725.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho think:</desc>
<name>think.png</name>
<size>36045</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>imQS2JiFO6S0e49p090ZVMDUhMK00LNWvRIpZJCF3wE=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/fc0f48df75138fa0f3aec605629226b8ac57c639.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho sorry:</desc>
<name>sorry.png</name>
<size>29542</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>ypwf+tCDjfHYRWNccIM0mh48IwP9YO/xieCZ5EwIUoY=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/f038ef01f098cae73a727618c0fbf9adf3e96ef6.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho confused:</desc>
<name>confused.png</name>
<size>35965</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>Za809qdsDuCrDsPxpPAlTrEY4c10Wiap4IXtb+F+dEo=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/eb7d0dd12b283017edee25243c3edacd62033ed0.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho sparkle:</desc>
<name>sparkle.png</name>
<size>35965</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>PaNrKyVZtSrqf/qLcf3K6h5u9l90h+P803hDU/yrh9M=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/e599dca3de182a821ef2e92234fb2bfca04a325e.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho glad:</desc>
<name>glad.png</name>
<size>55894</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>EeNaIsEp026KJL/OGCluO0lMuFBcqN/FACUBF52lDDc=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/580999b6110e859e336229913a73ec0ae640ef06.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho shock:</desc>
<name>shock.png</name>
<size>34478</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>nvoMdblXUoJonvGeMJUgmCOAww17mwNgaQInT1vmi2s=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/c42fc57e5234c4d19a2455178eff2b30bced20ef.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho stare:</desc>
<name>stare.png</name>
<size>34574</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>VDhOMXWPeLL64rhJ/SBTz/Remt7AWhxb0HzdPYc48tY=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/c069c6deff735fab3e4416ca354594a64a79ae40.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho happy:</desc>
<name>happy.png</name>
<size>32984</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>P5AvAPByh8n0hOCamrN4YCc9oA7XwdGvSbBHMJf8RBg=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/ae0ba6cdae25fbe512dc53c7e0413d706a9410f8.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho angry:</desc>
<name>angry.png</name>
<size>37862</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>m/NrSawqkK0qdO6fi6HPiagsizqBJMZWoIhS0g2O3m0=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/a3366676e1aea97dd9425fe7cc45a6ed86288f2e.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho speechless:</desc>
<name>speechless.png</name>
<size>30721</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>tIxqUrkiXWHRWUC4/Pk/rO/B0EuwyQq8GkawxE/NsF8=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/777e80a69ccc9c9938457844f9723f4debac0653.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho laugh:</desc>
<name>laugh.png</name>
<size>36209</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>MqH3vXkXJn1k3nZ6YBAT2di6ZhXVxk/StVbgX/nI9/0=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/6bbee3f5bcaeecbaa9fac68ba1aa4656e10a158d.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho surprise:</desc>
<name>surprise.png</name>
<size>34655</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>3CsvFu1vZNpLVLgHDPPQJ8w9Dm4Hd3VPpuKZn7+wcXc=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/34a406c2212522d7e6b60e888665267b16fc37ba.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho sad:</desc>
<name>sad.png</name>
<size>32655</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>12pOZSdygnaaaXeDDAN6995LXdLfalKXTRrVbnBxjE0=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/3142d1222d82d9f2dbe48d284c8f189660f418c3.png' />
</sources>
</item>
<item>
<file xmlns='urn:xmpp:file:metadata:0'>
<media-type>image/png</media-type>
<desc>:miho blush:</desc>
<name>blush.png</name>
<size>30476</size>
<dimensions>400x400</dimensions>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>Q8wdGYxHvO5EmMEEqWbwESr99hiKfLlK/LPp4yL8UgY=</hash>
</file>
<sources xmlns='urn:xmpp:sfs:0'>
<url-data xmlns='http://jabber.org/protocol/url-data' target='https://github.com/movim/movim/raw/master/public/stickers/miho/04214b0b967163915432d5406adec8c4017e093b.png' />
</sources>
</item>
<hash xmlns='urn:xmpp:hashes:2' algo='sha-256'>Epasa8DHHzFrE4zd+xaNpVb4jbu4s74XtioExNjQzZ0=</hash>
</pack>''');
final pack = StickerPack.fromXML(
'Epasa8DHHzFrE4zd+xaNpVb4jbu4s74XtioExNjQzZ0=',
rawPack,
);
expect(pack.stickers.length, 16);
});
}

View File

@ -18,14 +18,13 @@ Future<bool> testRosterManager(String bareJid, String resource, String stanzaStr
jid: JID.fromString(bareJid),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
getManagerById: getManagerNullStub,
getNegotiatorById: getNegotiatorNullStub,
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('$bareJid/$resource'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
),);
final stanza = Stanza.fromXMLNode(XMLNode.fromString(stanzaString));
@ -41,7 +40,7 @@ void main() {
test('Test a successful login attempt with no SM', () 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'>",
'''
@ -121,12 +120,12 @@ void main() {
final XmppConnection conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
fakeSocket);
fakeSocket,
);
conn.setConnectionSettings(ConnectionSettings(
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
@ -153,7 +152,7 @@ void main() {
test('Test a failed SASL auth', () 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'>",
'''
@ -185,7 +184,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
@ -212,7 +210,7 @@ void main() {
test('Test another failed SASL auth', () 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'>",
'''
@ -244,7 +242,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: true,
),);
conn.registerManagers([
PresenceManager(),
@ -300,7 +297,6 @@ void main() {
jid: JID.fromString('polynomdivision@test.server'),
password: 'aaaa',
useDirectTLS: true,
allowPlainAuth: false,
),);
conn.registerManagers([
PresenceManager('http://moxxmpp.example'),
@ -333,14 +329,13 @@ void main() {
jid: JID.fromString('some.user@example.server'),
password: 'password',
useDirectTLS: true,
allowPlainAuth: false,
),
getManagerById: getManagerNullStub,
getNegotiatorById: getNegotiatorNullStub,
isFeatureSupported: (_) => false,
getFullJID: () => JID.fromString('some.user@example.server/aaaaa'),
getSocket: () => StubTCPSocket(play: []),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket(play: [])),
getSocket: () => StubTCPSocket([]),
getConnection: () => XmppConnection(TestingReconnectionPolicy(), AlwaysConnectedConnectivityManager(), StubTCPSocket([])),
),);
// NOTE: Based on https://gultsch.de/gajim_roster_push_and_message_interception.html
@ -365,4 +360,57 @@ void main() {
expect(result2, true, reason: 'Roster pushes should be accepted if the bare JIDs are the same');
});
});
test('Test failing due to the server only allowing SASL PLAIN', () async {
final fakeSocket = StubTCPSocket(
[
StringExpectation(
"<stream:stream xmlns='jabber:client' version='1.0' xmlns:stream='http://etherx.jabber.org/streams' to='example.org' 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>''',
),
],
);
final conn = XmppConnection(
TestingReconnectionPolicy(),
AlwaysConnectedConnectivityManager(),
fakeSocket,
);
conn.registerManagers([
PresenceManager(),
RosterManager(TestingRosterStateManager('', [])),
DiscoManager([]),
PingManager(),
]);
conn.registerFeatureNegotiators(
[
// SaslPlainNegotiator(),
ResourceBindingNegotiator(),
]
);
conn.setConnectionSettings(
ConnectionSettings(
jid: JID.fromString('testuser@example.org'),
password: 'abc123',
useDirectTLS: false,
),
);
final result = await conn.connect(
waitUntilLogin: true,
);
expect(result.isType<NoMatchingAuthenticationMechanismAvailableError>(), true);
});
}