using System.Collections.Generic; using Shouldly; using Xunit; using ZB.MOM.WW.LmxOpcUa.Host.Configuration; using ZB.MOM.WW.LmxOpcUa.Host.Domain; namespace ZB.MOM.WW.LmxOpcUa.Tests.Authentication { public class UserAuthenticationTests { [Fact] public void ValidCredentials_ReturnsTrue() { var provider = new ConfigUserAuthenticationProvider(new List { new UserCredential { Username = "operator", Password = "op123" } }); provider.ValidateCredentials("operator", "op123").ShouldBeTrue(); } [Fact] public void WrongPassword_ReturnsFalse() { var provider = new ConfigUserAuthenticationProvider(new List { new UserCredential { Username = "operator", Password = "op123" } }); provider.ValidateCredentials("operator", "wrong").ShouldBeFalse(); } [Fact] public void UnknownUsername_ReturnsFalse() { var provider = new ConfigUserAuthenticationProvider(new List { new UserCredential { Username = "operator", Password = "op123" } }); provider.ValidateCredentials("unknown", "op123").ShouldBeFalse(); } [Fact] public void Username_IsCaseInsensitive() { var provider = new ConfigUserAuthenticationProvider(new List { new UserCredential { Username = "Operator", Password = "op123" } }); provider.ValidateCredentials("operator", "op123").ShouldBeTrue(); provider.ValidateCredentials("OPERATOR", "op123").ShouldBeTrue(); } [Fact] public void EmptyUserList_RejectsAll() { var provider = new ConfigUserAuthenticationProvider(new List()); provider.ValidateCredentials("anyone", "anything").ShouldBeFalse(); } [Fact] public void AuthenticationConfiguration_Defaults() { var config = new AuthenticationConfiguration(); config.AllowAnonymous.ShouldBeTrue(); config.AnonymousCanWrite.ShouldBeTrue(); config.Users.ShouldBeEmpty(); } } }