90 lines
4.8 KiB
C#
90 lines
4.8 KiB
C#
using Microsoft.AspNetCore.Server.IntegrationTesting;
|
|
using Microsoft.AspNetCore.Server.IntegrationTesting.xunit;
|
|
using Microsoft.AspNetCore.Testing.xunit;
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
|
using Microsoft.Extensions.Logging;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Net.Http;
|
|
using System.Threading.Tasks;
|
|
using Xunit;
|
|
using Xunit.Abstractions;
|
|
|
|
namespace E2ETests
|
|
{
|
|
public class NtlmAuthenticationTests : LoggedTest
|
|
{
|
|
public NtlmAuthenticationTests(ITestOutputHelper output) : base(output)
|
|
{
|
|
}
|
|
|
|
[ConditionalTheory, Trait("E2Etests", "E2Etests")]
|
|
[OSSkipCondition(OperatingSystems.Linux)]
|
|
[OSSkipCondition(OperatingSystems.MacOSX)]
|
|
[InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable)]
|
|
[InlineData(ServerType.WebListener, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone,
|
|
Skip = "https://github.com/aspnet/MusicStore/issues/761")]
|
|
[InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Portable)]
|
|
[InlineData(ServerType.IISExpress, RuntimeFlavor.CoreClr, RuntimeArchitecture.x64, ApplicationType.Standalone,
|
|
Skip = "https://github.com/aspnet/MusicStore/issues/761")]
|
|
public async Task NtlmAuthenticationTest(ServerType serverType, RuntimeFlavor runtimeFlavor, RuntimeArchitecture architecture, ApplicationType applicationType)
|
|
{
|
|
var testName = $"NtlmAuthentication_{serverType}_{runtimeFlavor}_{architecture}_{applicationType}";
|
|
using (StartLog(out var loggerFactory, testName))
|
|
{
|
|
var logger = loggerFactory.CreateLogger("NtlmAuthenticationTest");
|
|
var musicStoreDbName = DbUtils.GetUniqueName();
|
|
|
|
var deploymentParameters = new DeploymentParameters(Helpers.GetApplicationPath(applicationType), serverType, runtimeFlavor, architecture)
|
|
{
|
|
PublishApplicationBeforeDeployment = true,
|
|
PreservePublishedApplicationForDebugging = Helpers.PreservePublishedApplicationForDebugging,
|
|
TargetFramework = runtimeFlavor == RuntimeFlavor.Clr ? "net46" : "netcoreapp2.0",
|
|
Configuration = Helpers.GetCurrentBuildConfiguration(),
|
|
ApplicationType = applicationType,
|
|
EnvironmentName = "NtlmAuthentication", //Will pick the Start class named 'StartupNtlmAuthentication'
|
|
ServerConfigTemplateContent = (serverType == ServerType.IISExpress) ? File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "NtlmAuthentation.config")) : null,
|
|
SiteName = "MusicStoreNtlmAuthentication", //This is configured in the NtlmAuthentication.config
|
|
UserAdditionalCleanup = parameters =>
|
|
{
|
|
DbUtils.DropDatabase(musicStoreDbName, logger);
|
|
}
|
|
};
|
|
|
|
// Override the connection strings using environment based configuration
|
|
deploymentParameters.EnvironmentVariables
|
|
.Add(new KeyValuePair<string, string>(
|
|
MusicStoreConfig.ConnectionStringKey,
|
|
DbUtils.CreateConnectionString(musicStoreDbName)));
|
|
|
|
using (var deployer = ApplicationDeployerFactory.Create(deploymentParameters, loggerFactory))
|
|
{
|
|
var deploymentResult = await deployer.DeployAsync();
|
|
var httpClientHandler = new HttpClientHandler() { UseDefaultCredentials = true };
|
|
var httpClient = deploymentResult.CreateHttpClient(httpClientHandler);
|
|
|
|
// Request to base address and check if various parts of the body are rendered & measure the cold startup time.
|
|
var response = await RetryHelper.RetryRequest(async () =>
|
|
{
|
|
return await httpClient.GetAsync(string.Empty);
|
|
}, logger: logger, cancellationToken: deploymentResult.HostShutdownToken);
|
|
|
|
Assert.False(response == null, "Response object is null because the client could not " +
|
|
"connect to the server after multiple retries");
|
|
|
|
var validator = new Validator(httpClient, httpClientHandler, logger, deploymentResult);
|
|
|
|
logger.LogInformation("Verifying home page");
|
|
await validator.VerifyNtlmHomePage(response);
|
|
|
|
logger.LogInformation("Verifying access to store with permissions");
|
|
await validator.AccessStoreWithPermissions();
|
|
|
|
logger.LogInformation("Variation completed successfully.");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|