Skip to content

Commit

Permalink
Fix(auth) Fix bug #1515 PLAIN and LOGIN always returning failure if "…
Browse files Browse the repository at this point in the history
…allow any" turned off. (#1551)
  • Loading branch information
rnwood committed Sep 5, 2024
1 parent 0651589 commit be8816f
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ await Assert.ThrowsAsync<BadBase64Exception>(async () =>
await processor.ProcessResponse("rob blah");
});

[Fact]
public void ValidateCredentials_Correct()
{
var creds = new LoginAuthenticationCredentials("a", "b");
bool result = creds.ValidateResponse("b");

Assert.True(result);
}

[Fact]
public void ValidateCredentials_Incorrect()
{
var creds = new LoginAuthenticationCredentials("a", "b");
bool result = creds.ValidateResponse("c");

Assert.False(result);
}

/// <summary>
/// </summary>
/// <param name="mocks">The mocks<see cref="TestMocks" /></param>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the.NET Foundation under one or more agreements.
// The.NET Foundation licenses this file to you under the MIT license.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Rnwood.SmtpServer.Extensions.Auth;
using Xunit;

namespace Rnwood.SmtpServer.Tests.Extensions.Auth
{
public class PlainMechanismProcessorTests
{

[Fact]
public void ValidateCredentials_Correct()
{
var creds = new PlainAuthenticationCredentials("a", "b");
bool result = creds.ValidateResponse("b");

Assert.True(result);
}

[Fact]
public void ValidateCredentials_Incorrect()
{
var creds = new PlainAuthenticationCredentials("a", "b");
bool result = creds.ValidateResponse("c");

Assert.False(result);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Rnwood.SmtpServer.Extensions.Auth;
/// <summary>
/// Defines the <see cref="UsernameAndPasswordAuthenticationCredentials" />.
/// </summary>
public abstract class UsernameAndPasswordAuthenticationCredentials : IAuthenticationCredentials
public abstract class UsernameAndPasswordAuthenticationCredentials : IAuthenticationCredentials, IAuthenticationCredentialsCanValidateWithPassword
{
/// <summary>
/// Initializes a new instance of the <see cref="UsernameAndPasswordAuthenticationCredentials" /> class.
Expand All @@ -33,4 +33,9 @@ protected UsernameAndPasswordAuthenticationCredentials(string username, string p

/// <inheritdoc />
public string Type { get => "USERNAME_PASSWORD"; }

/// <inheritdoc/>
public bool ValidateResponse(string password) {
return string.Equals(Password, password);
}
}
3 changes: 3 additions & 0 deletions smtpserver/Rnwood.SmtpServer/Rnwood.SmtpServer.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit be8816f

Please sign in to comment.