-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7340 from thunderbird/account_setup_email_validation
Use `EmailAddressParser` for validating email address in account setup
- Loading branch information
Showing
4 changed files
with
134 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,69 @@ class ValidateEmailAddressTest { | |
.isInstanceOf<ValidateEmailAddressError.EmptyEmailAddress>() | ||
} | ||
|
||
@Test | ||
fun `should fail when email address is using unnecessary quoting in local part`() { | ||
val result = testSubject.execute("\"local-part\"@domain.example") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.NotAllowed>() | ||
} | ||
|
||
@Test | ||
fun `should fail when email address requires quoted local part`() { | ||
val result = testSubject.execute("\"local part\"@domain.example") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.NotAllowed>() | ||
} | ||
|
||
@Test | ||
fun `should fail when local part is empty`() { | ||
val result = testSubject.execute("\"\"@domain.example") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.NotAllowed>() | ||
} | ||
|
||
@Test | ||
fun `should fail when domain part contains IPv4 literal`() { | ||
val result = testSubject.execute("user@[255.0.100.23]") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.NotAllowed>() | ||
} | ||
|
||
@Test | ||
fun `should fail when domain part contains IPv6 literal`() { | ||
val result = testSubject.execute("user@[IPv6:2001:0db8:0000:0000:0000:ff00:0042:8329]") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.NotAllowed>() | ||
} | ||
|
||
@Test | ||
fun `should fail when local part contains non-ASCII character`() { | ||
val result = testSubject.execute("tö[email protected]") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.InvalidOrNotSupported>() | ||
} | ||
|
||
@Test | ||
fun `should fail when domain contains non-ASCII character`() { | ||
val result = testSubject.execute("test@dömain.example") | ||
|
||
assertThat(result).isInstanceOf<ValidationResult.Failure>() | ||
.prop(ValidationResult.Failure::error) | ||
.isInstanceOf<ValidateEmailAddressError.InvalidOrNotSupported>() | ||
} | ||
|
||
@Test | ||
fun `should fail when email address is invalid`() { | ||
val result = testSubject.execute("test") | ||
|