78 lines
2.7 KiB
C#
78 lines
2.7 KiB
C#
|
|
using System.Linq.Expressions;
|
||
|
|
using System.Net;
|
||
|
|
using System.Net.Http.Json;
|
||
|
|
using NUnit.Framework;
|
||
|
|
using Umbraco.Cms.Api.Management.Controllers.User;
|
||
|
|
using Umbraco.Cms.Api.Management.ViewModels;
|
||
|
|
using Umbraco.Cms.Api.Management.ViewModels.User;
|
||
|
|
using Umbraco.Cms.Core;
|
||
|
|
using Umbraco.Cms.Core.Models;
|
||
|
|
using Umbraco.Cms.Core.Services;
|
||
|
|
|
||
|
|
namespace Umbraco.Cms.Tests.Integration.ManagementApi.User;
|
||
|
|
|
||
|
|
public class CreateInitialPasswordUserControllerTests : ManagementApiUserGroupTestBase<CreateInitialPasswordUserController>
|
||
|
|
{
|
||
|
|
private IUserGroupService UserGroupService => GetRequiredService<IUserGroupService>();
|
||
|
|
|
||
|
|
private IUserService UserService => GetRequiredService<IUserService>();
|
||
|
|
|
||
|
|
private Guid _userKey;
|
||
|
|
|
||
|
|
[SetUp]
|
||
|
|
public async Task SetUp()
|
||
|
|
{
|
||
|
|
var adminUserGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias);
|
||
|
|
|
||
|
|
var stringKey = Guid.NewGuid();
|
||
|
|
var model = new UserCreateModel()
|
||
|
|
{
|
||
|
|
Email = stringKey + "@test.com",
|
||
|
|
UserName = stringKey + "@test.com",
|
||
|
|
Name = stringKey.ToString(),
|
||
|
|
UserGroupKeys = new HashSet<Guid> { adminUserGroup.Key },
|
||
|
|
};
|
||
|
|
var response = await UserService.CreateAsync(Constants.Security.SuperUserKey, model);
|
||
|
|
_userKey = response.Result.CreatedUser.Key;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override Expression<Func<CreateInitialPasswordUserController, object>> MethodSelector => x => x.CreateInitialPassword(CancellationToken.None, null);
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel EditorUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel SensitiveDataUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel TranslatorUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel WriterUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
|
||
|
|
{
|
||
|
|
ExpectedStatusCode = HttpStatusCode.BadRequest
|
||
|
|
};
|
||
|
|
|
||
|
|
protected override async Task<HttpResponseMessage> ClientRequest()
|
||
|
|
{
|
||
|
|
CreateInitialPasswordUserRequestModel createInitialPasswordUserRequest = new() { User = new ReferenceByIdModel(_userKey), Password = "password", Token = "test" };
|
||
|
|
|
||
|
|
return await Client.PostAsync(Url, JsonContent.Create(createInitialPasswordUserRequest));
|
||
|
|
}
|
||
|
|
}
|