* First attempt at OpenIddict * Making headway and more TODOs * Redo current policies for multiple schemas + clean up auth controller * Fix bad merge * Clean up some more test code * Fix spacing * Include AddAuthentication() in OpenIddict addition * A little more clean-up * Move application creation to its own implementation + prepare for middleware to handle valid callback URL * Enable refresh token flow * Fix bad merge from v11/dev * Support auth for Swagger and Postman in non-production environments + use default login screen for back-office logins * Add workaround to client side login handling so the OAuth return URL is not corrupted before redirection * Add temporary configuration handling for new backoffice * Restructure the code somewhat, move singular responsibility from management API project * Add recurring task for cleaning up old tokens in the DB * Fix bad merge + make auth controller align with the new management API structure * Explicitly handle the new management API path as a backoffice path (NOTE: this is potentially behaviorally breaking!) * Redo handle the new management API requests as backoffice requests, this time in a non-breaking way * Add/update TODOs * Replace NSwag with Swashbuckle and clean up unnecessary client secret workaround * Revert duplication of current auth policies for OpenIddict (as it breaks everything for V11 without the new management APIs) and introduce a dedicated PoC policy setup for OpenIddict. * Fix failing unit tests * A little niceness + export new OpenApi.json and fix path in contract unit test * Redo after merge with v11/dev + filter out unwanted mime types * Remove CreatedResult and NotFoundObjectResult where possible * Custom schema IDs - no more "ViewModel" postfix and make generic lists look less clunky too * A little more explanation for generic schema ID generation * Force Swashbuckle to use enum string names * Update OpenApi.json to match new enum string values * Add clarifying comment about weird looking construct
59 lines
2.1 KiB
C#
59 lines
2.1 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Options;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using NUnit.Framework;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Cms.Core.Hosting;
|
|
using Umbraco.Cms.Tests.Integration.TestServerTest;
|
|
|
|
namespace Umbraco.Cms.Tests.Integration.NewBackoffice;
|
|
|
|
[TestFixture]
|
|
internal sealed class OpenAPIContractTest : UmbracoTestServerTestBase
|
|
{
|
|
private GlobalSettings GlobalSettings => GetRequiredService<IOptions<GlobalSettings>>().Value;
|
|
|
|
private IHostingEnvironment HostingEnvironment => GetRequiredService<IHostingEnvironment>();
|
|
|
|
protected override void CustomTestSetup(IUmbracoBuilder builder)
|
|
{
|
|
builder.AddMvcAndRazor(mvcBuilder =>
|
|
{
|
|
// Adds Umbraco.Cms.ManagementApi
|
|
mvcBuilder.AddApplicationPart(typeof(ManagementApi.Controllers.Install.InstallControllerBase).Assembly);
|
|
});
|
|
|
|
new ManagementApi.ManagementApiComposer().Compose(builder);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Validate_OpenApi_Contract_is_implemented()
|
|
{
|
|
string[] keysToIgnore = { "servers", "x-generator" };
|
|
|
|
var officePath = GlobalSettings.GetBackOfficePath(HostingEnvironment);
|
|
|
|
var urlToContract = $"{officePath}/management/api/openapi.json";
|
|
var swaggerPath = $"{officePath}/swagger/v1/swagger.json";
|
|
var apiContract = JObject.Parse(await Client.GetStringAsync(urlToContract));
|
|
|
|
var generatedJsonString = await Client.GetStringAsync(swaggerPath);
|
|
var mergedContract = JObject.Parse(generatedJsonString);
|
|
var originalGeneratedContract = JObject.Parse(generatedJsonString);
|
|
|
|
mergedContract.Merge(apiContract, new JsonMergeSettings
|
|
{
|
|
MergeArrayHandling = MergeArrayHandling.Merge
|
|
});
|
|
|
|
foreach (var key in keysToIgnore)
|
|
{
|
|
originalGeneratedContract.Remove(key);
|
|
mergedContract.Remove(key);
|
|
}
|
|
|
|
Assert.AreEqual(originalGeneratedContract.ToString(Formatting.Indented), mergedContract.ToString(Formatting.Indented), $"Generated API do not respect the contract.");
|
|
}
|
|
}
|