TF-2667 Write unit test for Domain & MailAddress class
This commit is contained in:
@@ -1,33 +1,39 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:core/utils/app_logger.dart';
|
||||||
import 'package:equatable/equatable.dart';
|
import 'package:equatable/equatable.dart';
|
||||||
|
|
||||||
class Domain with EquatableMixin {
|
class Domain with EquatableMixin {
|
||||||
static final RegExp _dashMatcher = RegExp(r"[-_]");
|
static final RegExp _dashMatcher = RegExp(r'[-_]');
|
||||||
static final RegExp _digitMatcher = RegExp(r"[0-9]");
|
static final RegExp _digitMatcher = RegExp(r'\d');
|
||||||
static final RegExp _partCharMatcher = RegExp(r"[a-zA-Z0-9\-._]");
|
static final RegExp _partCharMatcher = RegExp(r'[A-Za-z0-9_\-.]');
|
||||||
|
|
||||||
static final Domain localhost = Domain.of('localhost');
|
static final Domain localhost = Domain.of('localhost');
|
||||||
static const int maximumDomainLength = 253;
|
static const int maximumDomainLength = 253;
|
||||||
|
|
||||||
static String _removeBrackets(String domainName) {
|
static String _removeBrackets(String domainName) {
|
||||||
if (!(domainName.startsWith("[") && domainName.endsWith("]"))) {
|
if (!(domainName.startsWith('[') && domainName.endsWith(']'))) {
|
||||||
return domainName;
|
return domainName;
|
||||||
}
|
}
|
||||||
return domainName.substring(1, domainName.length - 1);
|
return domainName.substring(1, domainName.length - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Domain of(String domain) {
|
static bool _allCharactersMatchRegex(String input, RegExp regex) {
|
||||||
assert(
|
for (int i = 0; i < input.length; i++) {
|
||||||
domain.length <= maximumDomainLength,
|
if (!regex.hasMatch(input[i])) {
|
||||||
'Domain name length should not exceed $maximumDomainLength characters'
|
return false;
|
||||||
);
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
String domainWithoutBrackets = _removeBrackets(domain);
|
static Domain of(String? domain) {
|
||||||
assert(
|
assert(domain != null, 'Domain can not be null');
|
||||||
_partCharMatcher
|
assert(domain!.isNotEmpty, 'Domain can not be empty');
|
||||||
.allMatches(domainWithoutBrackets)
|
assert(domain!.length <= maximumDomainLength, 'Domain name length should not exceed $maximumDomainLength characters');
|
||||||
.every((match) => match.group(0) != null),
|
|
||||||
'Domain parts ASCII chars must be a-z A-Z 0-9 - or _'
|
String domainWithoutBrackets = _removeBrackets(domain!);
|
||||||
);
|
assert(_allCharactersMatchRegex(domainWithoutBrackets, _partCharMatcher), 'Domain parts ASCII chars must be a-z A-Z 0-9 - or _');
|
||||||
|
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
int nextDot = domainWithoutBrackets.indexOf('.');
|
int nextDot = domainWithoutBrackets.indexOf('.');
|
||||||
@@ -42,17 +48,15 @@ class Domain with EquatableMixin {
|
|||||||
}
|
}
|
||||||
_assertValidPart(domainWithoutBrackets, pos, domainWithoutBrackets.length);
|
_assertValidPart(domainWithoutBrackets, pos, domainWithoutBrackets.length);
|
||||||
_assertValidLastPart(domainWithoutBrackets, pos);
|
_assertValidLastPart(domainWithoutBrackets, pos);
|
||||||
|
|
||||||
return Domain._(domainWithoutBrackets);
|
return Domain._(domainWithoutBrackets);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _assertValidPart(String domainPart, int begin, int end) {
|
static void _assertValidPart(String domainPart, int begin, int end) {
|
||||||
assert(begin != end, "Domain part should not be empty");
|
assert(begin != end, "Domain part should not be empty");
|
||||||
assert(!_dashMatcher.hasMatch(domainPart[begin]),
|
assert(!_dashMatcher.hasMatch(domainPart[begin]), "Domain part should not start with '-' or '_'");
|
||||||
"Domain part should not start with '-' or '_'");
|
assert(!_dashMatcher.hasMatch(domainPart[end - 1]), "Domain part should not end with '-' or '_'");
|
||||||
assert(!_dashMatcher.hasMatch(domainPart[end - 1]),
|
assert(end - begin <= 63, "Domain part should not not exceed 63 characters");
|
||||||
"Domain part should not end with '-' or '_'");
|
|
||||||
assert(
|
|
||||||
end - begin <= 63, "Domain part should not not exceed 63 characters");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _assertValidLastPart(String domainPart, int pos) {
|
static void _assertValidLastPart(String domainPart, int pos) {
|
||||||
@@ -63,9 +67,10 @@ class Domain with EquatableMixin {
|
|||||||
|
|
||||||
static bool _validIPAddress(String value) {
|
static bool _validIPAddress(String value) {
|
||||||
try {
|
try {
|
||||||
Uri.parseIPv6Address(value);
|
InternetAddress(value);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
logError('Domain::validIPAddress: Exception = $e');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -73,16 +78,11 @@ class Domain with EquatableMixin {
|
|||||||
final String domainName;
|
final String domainName;
|
||||||
final String normalizedDomainName;
|
final String normalizedDomainName;
|
||||||
|
|
||||||
Domain._(this.domainName)
|
Domain._(this.domainName) : normalizedDomainName = _removeBrackets(domainName.toLowerCase());
|
||||||
: normalizedDomainName = _removeBrackets(domainName.toLowerCase());
|
|
||||||
|
|
||||||
String name() {
|
String name() => domainName;
|
||||||
return domainName;
|
|
||||||
}
|
|
||||||
|
|
||||||
String asString() {
|
String asString() => normalizedDomainName;
|
||||||
return normalizedDomainName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) {
|
bool operator ==(Object other) {
|
||||||
@@ -104,4 +104,4 @@ class Domain with EquatableMixin {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
List<Object?> get props => [domainName];
|
List<Object?> get props => [domainName];
|
||||||
}
|
}
|
||||||
@@ -25,19 +25,15 @@ class MailAddress with EquatableMixin {
|
|||||||
|
|
||||||
MailAddress({required this.localPart, required this.domain});
|
MailAddress({required this.localPart, required this.domain});
|
||||||
|
|
||||||
String asString() {
|
factory MailAddress.validateAddress(String address) {
|
||||||
return '$localPart@${domain.asString()}';
|
log('MailAddress::validate: Address = $address');
|
||||||
}
|
|
||||||
|
|
||||||
String asPrettyString() {
|
|
||||||
return '<${asString()}>';
|
|
||||||
}
|
|
||||||
|
|
||||||
static MailAddress validate(String address) {
|
|
||||||
String localPart;
|
String localPart;
|
||||||
Domain domain;
|
Domain domain;
|
||||||
|
|
||||||
address = address.trim();
|
address = address.trim();
|
||||||
|
if (address.isEmpty) {
|
||||||
|
throw AddressException('Addresses should not be empty');
|
||||||
|
}
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|
||||||
// Test if mail address has source routing information (RFC-821) and get rid of it!!
|
// Test if mail address has source routing information (RFC-821) and get rid of it!!
|
||||||
@@ -96,7 +92,7 @@ class MailAddress with EquatableMixin {
|
|||||||
throw AddressException('No domain found at position ${pos + 1} in "$address"');
|
throw AddressException('No domain found at position ${pos + 1} in "$address"');
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('MailAddress::validate: Exception = $e');
|
logError('MailAddress::validate: Exception = $e');
|
||||||
if (e is AddressException) {
|
if (e is AddressException) {
|
||||||
rethrow;
|
rethrow;
|
||||||
} else {
|
} else {
|
||||||
@@ -114,11 +110,38 @@ class MailAddress with EquatableMixin {
|
|||||||
|
|
||||||
domain = _createDomain(domainSB.toString());
|
domain = _createDomain(domainSB.toString());
|
||||||
|
|
||||||
log('MailAddress::validate: localPart = $localPart | domain = $domain');
|
|
||||||
|
|
||||||
return MailAddress(localPart: localPart, domain: domain);
|
return MailAddress(localPart: localPart, domain: domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
factory MailAddress.validateLocalPartAndDomain({required String localPart, required dynamic domain}) {
|
||||||
|
if (domain is Domain) {
|
||||||
|
return MailAddress.validateAddress('$localPart@${domain.name()}');
|
||||||
|
} else {
|
||||||
|
return MailAddress.validateAddress('$localPart@$domain');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
String asString() {
|
||||||
|
return '$localPart@${domain.asString()}';
|
||||||
|
}
|
||||||
|
|
||||||
|
String asPrettyString() {
|
||||||
|
return '<${asString()}>';
|
||||||
|
}
|
||||||
|
|
||||||
|
Domain getDomain() {
|
||||||
|
return domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getLocalPart() {
|
||||||
|
return localPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return '$localPart@${domain.asString()}';
|
||||||
|
}
|
||||||
|
|
||||||
static bool _haveDoubleDot(String localPart) {
|
static bool _haveDoubleDot(String localPart) {
|
||||||
return localPart.contains('..');
|
return localPart.contains('..');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
import 'package:core/utils/mail/domain.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
test('Domain.of(args) should not be case sensitive', () {
|
||||||
|
expect(Domain.of('Domain'), equals(Domain.of('domain')));
|
||||||
|
});
|
||||||
|
|
||||||
|
group('Domain.of(arg) should throw an AssertionError with a list of invalid domains', () {
|
||||||
|
final listDomainInValid = [
|
||||||
|
'domain\$bad.com',
|
||||||
|
'',
|
||||||
|
'aab..ddd',
|
||||||
|
'aab.cc.1com',
|
||||||
|
'abc.abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcd.com',
|
||||||
|
'domain\$bad.com',
|
||||||
|
'domain/bad.com',
|
||||||
|
'domain\\bad.com',
|
||||||
|
'domain@bad.com',
|
||||||
|
'domain@bad.com',
|
||||||
|
'domain%bad.com',
|
||||||
|
'#domain.com',
|
||||||
|
'bad-.com',
|
||||||
|
'bad_.com',
|
||||||
|
'-bad.com',
|
||||||
|
'bad_.com',
|
||||||
|
'[domain.tld',
|
||||||
|
'domain.tld]',
|
||||||
|
'a[aaa]a',
|
||||||
|
'[aaa]a',
|
||||||
|
'a[aaa]',
|
||||||
|
'[]'
|
||||||
|
];
|
||||||
|
for (var arg in listDomainInValid) {
|
||||||
|
test(arg, () {
|
||||||
|
expect(() => Domain.of(arg), throwsA(const TypeMatcher<AssertionError>()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
group('Domain.of(arg) should not throw any exceptions with the list of valid domains', () {
|
||||||
|
final listDomainValid = [
|
||||||
|
'127.0.0.1',
|
||||||
|
'domain.tld',
|
||||||
|
'do-main.tld',
|
||||||
|
'do_main.tld',
|
||||||
|
'ab.dc.de.fr',
|
||||||
|
'123.456.789.a23',
|
||||||
|
'acv.abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabc.fr',
|
||||||
|
'ab--cv.fr',
|
||||||
|
'ab__cd.fr',
|
||||||
|
'domain',
|
||||||
|
'[domain]',
|
||||||
|
'127.0.0.1'
|
||||||
|
];
|
||||||
|
for (var arg in listDomainValid) {
|
||||||
|
test(arg, () {
|
||||||
|
expect(() => Domain.of(arg), returnsNormally);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Domain.of(args) should remove brackets', () {
|
||||||
|
expect(Domain.of('[domain]'), equals(Domain.of('domain')));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Domain.of(args) should throw AssertionError when args is null', () {
|
||||||
|
expect(() => Domain.of(null), throwsA(const TypeMatcher<AssertionError>()));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Domain.of(args) should allow 253 long domain', () {
|
||||||
|
expect(Domain.of('${'aaaaaaaaa.' * 25}aaa').domainName.length, 253);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Domain.of(args) should throw AssertionError when too long', () {
|
||||||
|
expect(() => Domain.of('a' * 254), throwsA(const TypeMatcher<AssertionError>()));
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -1,20 +1,85 @@
|
|||||||
import 'package:core/domain/exceptions/address_exception.dart';
|
import 'package:core/domain/exceptions/address_exception.dart';
|
||||||
|
import 'package:core/utils/mail/domain.dart';
|
||||||
import 'package:core/utils/mail/mail_address.dart';
|
import 'package:core/utils/mail/mail_address.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('MailAddress test', () {
|
const String GOOD_LOCAL_PART = "\"quoted@local part\"";
|
||||||
test('validate method should be return MailAddress when address valid', () {
|
const String GOOD_QUOTED_LOCAL_PART = "\"quoted@local part\"@james.apache.org";
|
||||||
String validAddress = 'user@example.com';
|
const String GOOD_ADDRESS = "server-dev@james.apache.org";
|
||||||
MailAddress mailAddress = MailAddress.validate(validAddress);
|
final Domain GOOD_DOMAIN = Domain.of("james.apache.org");
|
||||||
|
|
||||||
|
final List<String> goodAddresses = [
|
||||||
|
GOOD_ADDRESS,
|
||||||
|
GOOD_QUOTED_LOCAL_PART,
|
||||||
|
"server-dev@james-apache.org",
|
||||||
|
"server-dev@[127.0.0.1]",
|
||||||
|
"server.dev@james.apache.org",
|
||||||
|
"\\.server-dev@james.apache.org",
|
||||||
|
"Abc@10.42.0.1",
|
||||||
|
"Abc.123@example.com",
|
||||||
|
"user+mailbox/department=shipping@example.com",
|
||||||
|
"user+mailbox@example.com",
|
||||||
|
"\"Abc@def\"@example.com",
|
||||||
|
"\"Fred Bloggs\"@example.com",
|
||||||
|
"\"Joe.\\Blow\"@example.com",
|
||||||
|
"!#\$%&'*+-/=?^_`.{|}~@example.com"
|
||||||
|
];
|
||||||
|
|
||||||
|
final List<String> badAddresses = [
|
||||||
|
"",
|
||||||
|
"server-dev",
|
||||||
|
"server-dev@",
|
||||||
|
"[]",
|
||||||
|
"server-dev@[]",
|
||||||
|
"server-dev@#",
|
||||||
|
"quoted local-part@james.apache.org",
|
||||||
|
"quoted@local-part@james.apache.org",
|
||||||
|
"local-part.@james.apache.org",
|
||||||
|
".local-part@james.apache.org",
|
||||||
|
"local-part@.james.apache.org",
|
||||||
|
"local-part@james.apache.org.",
|
||||||
|
"local-part@james.apache..org",
|
||||||
|
"server-dev@-james.apache.org",
|
||||||
|
"server-dev@james.apache.org-",
|
||||||
|
"server-dev@#james.apache.org",
|
||||||
|
"server-dev@#123james.apache.org",
|
||||||
|
"server-dev@#-123.james.apache.org",
|
||||||
|
"server-dev@james. apache.org",
|
||||||
|
"server-dev@james\\.apache.org",
|
||||||
|
"server-dev@[300.0.0.1]",
|
||||||
|
"server-dev@[127.0.1]",
|
||||||
|
"server-dev@[0127.0.0.1]",
|
||||||
|
"server-dev@[127.0.1.1a]",
|
||||||
|
"server-dev@[127\\.0.1.1]",
|
||||||
|
"server-dev@#123",
|
||||||
|
"server-dev@#123.apache.org",
|
||||||
|
"server-dev@[127.0.1.1.1]",
|
||||||
|
"server-dev@[127.0.1.-1]",
|
||||||
|
"\"a..b\"@domain.com", // jakarta.mail is unable to handle this so we better reject it
|
||||||
|
"server-dev\\.@james.apache.org", // jakarta.mail is unable to handle this so we better reject it
|
||||||
|
"a..b@domain.com",
|
||||||
|
// According to wikipedia these addresses are valid but as jakarta.mail is unable
|
||||||
|
// to work with them we shall rather reject them (note that this is not breaking retro-compatibility)
|
||||||
|
"Loïc.Accentué@voilà.fr8",
|
||||||
|
"pelé@exemple.com",
|
||||||
|
"δοκιμή@παράδειγμα.δοκιμή",
|
||||||
|
"我買@屋企.香港",
|
||||||
|
"二ノ宮@黒川.日本",
|
||||||
|
"медведь@с-балалайкой.рф",
|
||||||
|
"संपर्क@डाटामेल.भारत"
|
||||||
|
];
|
||||||
|
|
||||||
|
group('MailAddress simple test', () {
|
||||||
|
test('MailAddress.validateAddress() should be return MailAddress when address valid', () {
|
||||||
|
MailAddress mailAddress = MailAddress.validateAddress('user@example.com');
|
||||||
expect(mailAddress.localPart, equals('user'));
|
expect(mailAddress.localPart, equals('user'));
|
||||||
expect(mailAddress.domain.name(), equals('example.com'));
|
expect(mailAddress.domain.name(), equals('example.com'));
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate method should be throw AddressException when address missing @', () {
|
test('MailAddress.validateAddress() should be throw AddressException when address missing @', () {
|
||||||
String invalidAddress = 'userexample.com';
|
|
||||||
expect(
|
expect(
|
||||||
() => MailAddress.validate(invalidAddress),
|
() => MailAddress.validateAddress('userexample.com'),
|
||||||
throwsA(isA<AddressException>().having(
|
throwsA(isA<AddressException>().having(
|
||||||
(e) => e.message,
|
(e) => e.message,
|
||||||
'message',
|
'message',
|
||||||
@@ -23,10 +88,9 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate method should be throw AddressException when address empty local-part', () {
|
test('MailAddress.validateAddress() should be throw AddressException when address empty local-part', () {
|
||||||
String invalidAddress = '@example.com';
|
|
||||||
expect(
|
expect(
|
||||||
() => MailAddress.validate(invalidAddress),
|
() => MailAddress.validateAddress('@example.com'),
|
||||||
throwsA(isA<AddressException>().having(
|
throwsA(isA<AddressException>().having(
|
||||||
(e) => e.message,
|
(e) => e.message,
|
||||||
'message',
|
'message',
|
||||||
@@ -35,10 +99,9 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate method should be throw AddressException when address empty domain', () {
|
test('MailAddress.validateAddress() should be throw AddressException when address empty domain', () {
|
||||||
String invalidAddress = 'user@';
|
|
||||||
expect(
|
expect(
|
||||||
() => MailAddress.validate(invalidAddress),
|
() => MailAddress.validateAddress('user@'),
|
||||||
throwsA(isA<AddressException>().having(
|
throwsA(isA<AddressException>().having(
|
||||||
(e) => e.message,
|
(e) => e.message,
|
||||||
'message',
|
'message',
|
||||||
@@ -47,10 +110,9 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('validate method should be throw AddressException when address with a hyphen "-"', () {
|
test('MailAddress.validateAddress() should be throw AddressException when address with a hyphen "-"', () {
|
||||||
String invalidAddress = 'user@-example.com';
|
|
||||||
expect(
|
expect(
|
||||||
() => MailAddress.validate(invalidAddress),
|
() => MailAddress.validateAddress('user@-example.com'),
|
||||||
throwsA(isA<AddressException>().having(
|
throwsA(isA<AddressException>().having(
|
||||||
(e) => e.message,
|
(e) => e.message,
|
||||||
'message',
|
'message',
|
||||||
@@ -59,4 +121,49 @@ void main() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
group('MailAddress advanced test', () {
|
||||||
|
group('MailAddress.validateAddress() should not throw any exceptions with the list of good address', () {
|
||||||
|
for (var arg in goodAddresses) {
|
||||||
|
test(arg, () {
|
||||||
|
expect(() => MailAddress.validateAddress(arg), returnsNormally);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
group('MailAddress.validateAddress() should throw an AddressException with a list of bad address', () {
|
||||||
|
for (var arg in badAddresses) {
|
||||||
|
test(arg, () {
|
||||||
|
expect(() => MailAddress.validateAddress(arg), throwsA(const TypeMatcher<AddressException>()));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.validateLocalPartAndDomain() should not throw any exceptions with good address have LocalPart and Domain', () {
|
||||||
|
expect(() => MailAddress.validateLocalPartAndDomain(localPart: 'local-part', domain: 'domain'), returnsNormally);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.validateLocalPartAndDomain() should throw an AddressException with bad address have LocalPart and Domain', () {
|
||||||
|
expect(() => MailAddress.validateLocalPartAndDomain(localPart: 'local-part', domain: '-domain'), throwsA(const TypeMatcher<AddressException>()));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.validateAddress() should not throw any exceptions with mail address is GOOD_QUOTED_LOCAL_PART', () {
|
||||||
|
expect(() => MailAddress.validateAddress(GOOD_QUOTED_LOCAL_PART), returnsNormally);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.getDomain() should return GOOD_DOMAIN with address is GOOD_ADDRESS', () {
|
||||||
|
final mailAddress = MailAddress.validateAddress(GOOD_ADDRESS);
|
||||||
|
expect(mailAddress.getDomain(), equals(GOOD_DOMAIN));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.getLocalPart() should return GOOD_LOCAL_PART with address is GOOD_QUOTED_LOCAL_PART', () {
|
||||||
|
final mailAddress = MailAddress.validateAddress(GOOD_QUOTED_LOCAL_PART);
|
||||||
|
expect(mailAddress.getLocalPart(), equals(GOOD_LOCAL_PART));
|
||||||
|
});
|
||||||
|
|
||||||
|
test('MailAddress.toString() should return GOOD_ADDRESS with address is GOOD_ADDRESS', () {
|
||||||
|
final mailAddress = MailAddress.validateAddress(GOOD_ADDRESS);
|
||||||
|
expect(mailAddress.toString(), equals(GOOD_ADDRESS));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ class EmailUtils {
|
|||||||
|
|
||||||
static bool isEmailAddressValid(String address) {
|
static bool isEmailAddressValid(String address) {
|
||||||
try {
|
try {
|
||||||
return GetUtils.isEmail(address) && MailAddress.validate(address).asString().isNotEmpty;
|
return GetUtils.isEmail(address) && MailAddress.validateAddress(address).asString().isNotEmpty;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
logError('EmailUtils::isEmailAddressValid: Exception = $e');
|
logError('EmailUtils::isEmailAddressValid: Exception = $e');
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user