Skip to content

Commit

Permalink
Fail authentication instead of closing connection when try to authori…
Browse files Browse the repository at this point in the history
…ze with empty user name or password. (cosullivan#65)
  • Loading branch information
mumitroller authored and cosullivan committed May 29, 2018
1 parent 89edf00 commit 58555f1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
29 changes: 29 additions & 0 deletions Src/SmtpServer.Tests/SmtpServerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,35 @@ public void CanAuthenticateUser()
}
}

[Theory]
[InlineData("", "" )]
[InlineData("user", "" )]
[InlineData("", "password")]
public void CanFailAuthenticationEmptyUserOrPassword(string user, string password)
{
// arrange
string actualUser = null;
string actualPassword = null;
var userAuthenticator = new DelegatingUserAuthenticator((u, p) =>
{
actualUser = u;
actualPassword = p;

return false;
});

using (CreateServer(options => options.AllowUnsecureAuthentication().UserAuthenticator(userAuthenticator)))
{
// act and assert
Assert.Throws<MailKit.Security.AuthenticationException>(() => MailClient.Send(user: user, password: password));

// assert
Assert.Equal(0, MessageStore.Messages.Count);
Assert.Equal(user, actualUser);
Assert.Equal(password, actualPassword);
}
}

[Fact]
public void CanReceiveBccInMessageTransaction()
{
Expand Down
2 changes: 1 addition & 1 deletion Src/SmtpServer/Protocol/AuthCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async Task<string> ReadBase64EncodedLineAsync(INetworkClient client, Cancellatio
{
var text = await client.ReadLineAsync(Encoding.ASCII, cancellationToken).ReturnOnAnyThread();

return Encoding.UTF8.GetString(Convert.FromBase64String(text));
return Encoding.UTF8.GetString(Convert.FromBase64String(text ?? ""));
}

/// <summary>
Expand Down

0 comments on commit 58555f1

Please sign in to comment.