Files
WireMock.Net-wiremock/test/WireMock.Net.Tests/WireMockServer.Authentication.cs
Stef Heyenrath 54edf0bebc Add link to TIOBE Index on main page + fix issues (#1137)
* Add TIOBE + include SonarAnalyzer.CSharp

* .

* cp

* Copyright © WireMock.Net

* more fixes

* fix

* xpath

* if (Matchers == null || !Matchers.Any())

* if (Matchers != null)

* ?

* .

* .
2024-07-18 18:06:04 +02:00

66 lines
2.0 KiB
C#

// Copyright © WireMock.Net
using FluentAssertions;
using NFluent;
using WireMock.Matchers;
using WireMock.Owin;
using WireMock.Server;
using Xunit;
namespace WireMock.Net.Tests
{
public class WireMockServerAuthenticationTests
{
[Fact]
public void WireMockServer_Authentication_SetBasicAuthentication()
{
// Assign
var server = WireMockServer.Start();
// Act
server.SetBasicAuthentication("x", "y");
// Assert
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
Check.That(options.AuthenticationMatcher.Name).IsEqualTo("BasicAuthenticationMatcher");
Check.That(options.AuthenticationMatcher.MatchBehaviour).IsEqualTo(MatchBehaviour.AcceptOnMatch);
Check.That(options.AuthenticationMatcher.GetPatterns()).ContainsExactly("^(?i)BASIC eDp5$");
server.Stop();
}
[Fact]
public void WireMockServer_Authentication_SetSetAzureADAuthentication()
{
// Assign
var server = WireMockServer.Start();
// Act
server.SetAzureADAuthentication("x", "y");
// Assert
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
options.AuthenticationMatcher.Name.Should().Be("AzureADAuthenticationMatcher");
options.AuthenticationMatcher.MatchBehaviour.Should().Be(MatchBehaviour.AcceptOnMatch);
server.Stop();
}
[Fact]
public void WireMockServer_Authentication_RemoveAuthentication()
{
// Assign
var server = WireMockServer.Start();
server.SetBasicAuthentication("x", "y");
// Act
server.RemoveAuthentication();
// Assert
var options = server.GetPrivateFieldValue<IWireMockMiddlewareOptions>("_options");
Check.That(options.AuthenticationMatcher).IsNull();
server.Stop();
}
}
}