Skip to content

Commit 7f1cdf8

Browse files
andr317cnhudinh0309Zeegaan
authored
Auhorization: Cherrypicked integration tests from V15 (#20492)
* V15 QA Added the authorization integration tests (#18419) * Added authorization integration tests * Removed unnecessary tests and update tests for preview controller * Updated to use the newest changes from v15/dev and added an override for the AuthenticateClientAsync to use the userGroupKey * Updated CompatibilitySuppressions to include changes from integration tests * Updated pipelines * Skips managementApi tests * Only run necessary tests * Added new schema per fixture to reduce test setup time * Fixed failing tests * Updated test setup * Updated test * Added suppression * Fixed failing tests * Updated addOnTeardown methods to protected * Added method for clearing the host * Added teardown * Updated model usage * Added a lot of cleanup for memory leak issues when running tests * Added CompatibilitySuppressions.xml * Updated tests * Cleaned up * Adjusted base classes * Updated pipeline * Updated CompatibilitySuppressions.xml * Updated test logging * Fixed reponse * Updated condition to skip tests * Updated tests, not done * Reworked test to expect correct responses with correct setup * Updated tests * More updates to tests * Updated tests * Cleaned up tests * Updated setup * Cleaned up tests to match setup * Cleaned up setup * Removed suppression * Fixed tests * Move order of checks * Fix naming * Formatting * Dispose of host * Keep track of if we're disposed * Compat suppression * Dont dispose * Fix failing tests * removed unused virtual * Updated CompatibilitySuppressions.xml --------- Co-authored-by: Andreas Zerbst <[email protected]> Co-authored-by: Zeegaan <[email protected]> Co-authored-by: Nikolaj Geisle <[email protected]> # Conflicts: # tests/Umbraco.Tests.Integration/CompatibilitySuppressions.xml # tests/Umbraco.Tests.Integration/ManagementApi/ManagementApiTest.cs # tests/Umbraco.Tests.Integration/ManagementApi/Policies/AllCultureControllerTests.cs # tests/Umbraco.Tests.Integration/ManagementApi/Policies/CreateDocumentTests.cs # tests/Umbraco.Tests.Integration/ManagementApi/Policies/UpdateDocumentTests.cs # tests/Umbraco.Tests.Integration/ManagementApi/Preview/EndPreviewTests.cs # tests/Umbraco.Tests.Integration/ManagementApi/Preview/EnterPreviewTests.cs # tests/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs * Updated test * Updates * Removed unnessecary test --------- Co-authored-by: Nhu Dinh <[email protected]> Co-authored-by: Zeegaan <[email protected]> Co-authored-by: Nikolaj Geisle <[email protected]>
1 parent 37b239b commit 7f1cdf8

File tree

244 files changed

+13977
-680
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

244 files changed

+13977
-680
lines changed

build/azure-pipelines.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ stages:
313313
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
314314
LinuxPart3Of3:
315315
vmImage: "ubuntu-latest"
316-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
317-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
316+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace. So this will run all tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace
317+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
318318
macOSPart1Of3:
319319
vmImage: "macOS-latest"
320320
# Filter tests that are part of the Umbraco.Infrastructure namespace but not part of the Umbraco.Infrastructure.Service namespace
@@ -325,8 +325,8 @@ stages:
325325
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
326326
macOSPart3Of3:
327327
vmImage: "macOS-latest"
328-
# Filter tests that are not part of the Umbraco.Infrastructure namespace.
329-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
328+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace. So this will run all tests that are not part of the Umbraco.Infrastructure and the ManagementApi namespace
329+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
330330
pool:
331331
vmImage: $(vmImage)
332332
variables:
@@ -389,8 +389,8 @@ stages:
389389
vmImage: "windows-latest"
390390
Tests__Database__DatabaseType: LocalDb
391391
Tests__Database__SQLServerMasterConnectionString: N/A
392-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
393-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
392+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace. So this will run all tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace
393+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
394394
LinuxPart1Of3:
395395
vmImage: "ubuntu-latest"
396396
SA_PASSWORD: UmbracoIntegration123!
@@ -410,8 +410,8 @@ stages:
410410
SA_PASSWORD: UmbracoIntegration123!
411411
Tests__Database__DatabaseType: SqlServer
412412
Tests__Database__SQLServerMasterConnectionString: "Server=(local);User Id=sa;Password=$(SA_PASSWORD);TrustServerCertificate=True"
413-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
414-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
413+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace. So this will run all tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace
414+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
415415
pool:
416416
vmImage: $(vmImage)
417417
steps:

build/nightly-E2E-test-pipelines.yml

Lines changed: 43 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,39 @@ stages:
123123
matrix:
124124
# Windows:
125125
# vmImage: 'windows-latest'
126-
# We split the tests into 3 parts for each OS to reduce the time it takes to run them on the pipeline
127-
LinuxPart1Of3:
126+
# We split the tests into 4 parts for each OS to reduce the time it takes to run them on the pipeline
127+
LinuxPart1Of4:
128128
vmImage: "ubuntu-latest"
129129
# Filter tests that are part of the Umbraco.Infrastructure namespace but not part of the Umbraco.Infrastructure.Service namespace
130130
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure) & (FullyQualifiedName!~Umbraco.Infrastructure.Service)"
131-
LinuxPart2Of3:
131+
LinuxPart2Of4:
132132
vmImage: "ubuntu-latest"
133133
# Filter tests that are part of the Umbraco.Infrastructure.Service namespace
134134
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
135-
LinuxPart3Of3:
135+
LinuxPart3Of4:
136136
vmImage: "ubuntu-latest"
137-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
138-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
139-
macOSPart1Of3:
137+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
138+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
139+
LinuxPart4Of4:
140+
vmImage: "ubuntu-latest"
141+
# Filter tests that are part of the ManagementApi namespace
142+
testFilter: "(FullyQualifiedName~ManagementApi)"
143+
macOSPart1Of4:
140144
vmImage: "macOS-latest"
141145
# Filter tests that are part of the Umbraco.Infrastructure namespace but not part of the Umbraco.Infrastructure.Service namespace
142146
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure) & (FullyQualifiedName!~Umbraco.Infrastructure.Service)"
143-
macOSPart2Of3:
147+
macOSPart2Of4:
144148
vmImage: "macOS-latest"
145149
# Filter tests that are part of the Umbraco.Infrastructure.Service namespace
146150
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
147-
macOSPart3Of3:
151+
macOSPart3Of4:
152+
vmImage: "macOS-latest"
153+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace.
154+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
155+
macOSPart4Of4:
148156
vmImage: "macOS-latest"
149-
# Filter tests that are not part of the Umbraco.Infrastructure namespace.
150-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
157+
# Filter tests that are part of the ManagementApi namespace.
158+
testFilter: "(FullyQualifiedName~ManagementApi)"
151159
pool:
152160
vmImage: $(vmImage)
153161
variables:
@@ -187,43 +195,55 @@ stages:
187195
SA_PASSWORD: UmbracoAcceptance123!
188196
strategy:
189197
matrix:
190-
# We split the tests into 3 parts for each OS to reduce the time it takes to run them on the pipeline
191-
WindowsPart1Of3:
198+
# We split the tests into 4 parts for each OS to reduce the time it takes to run them on the pipeline
199+
WindowsPart1Of4:
192200
vmImage: "windows-latest"
193201
Tests__Database__DatabaseType: LocalDb
194202
Tests__Database__SQLServerMasterConnectionString: N/A
195203
# Filter tests that are part of the Umbraco.Infrastructure namespace but not part of the Umbraco.Infrastructure.Service namespace
196204
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure) & (FullyQualifiedName!~Umbraco.Infrastructure.Service)"
197-
WindowsPart2Of3:
205+
WindowsPart2Of4:
198206
vmImage: "windows-latest"
199207
Tests__Database__DatabaseType: LocalDb
200208
Tests__Database__SQLServerMasterConnectionString: N/A
201209
# Filter tests that are part of the Umbraco.Infrastructure.Service namespace
202210
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
203-
WindowsPart3Of3:
211+
WindowsPart3Of4:
204212
vmImage: "windows-latest"
205213
Tests__Database__DatabaseType: LocalDb
206214
Tests__Database__SQLServerMasterConnectionString: N/A
207-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
208-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
209-
LinuxPart1Of3:
215+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace.
216+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
217+
WindowsPart4Of4:
218+
vmImage: "windows-latest"
219+
Tests__Database__DatabaseType: LocalDb
220+
Tests__Database__SQLServerMasterConnectionString: N/A
221+
# Filter tests that are part of the ManagementApi namespace.
222+
testFilter: "(FullyQualifiedName~ManagementApi)"
223+
LinuxPart1Of4:
210224
vmImage: "ubuntu-latest"
211225
Tests__Database__DatabaseType: SqlServer
212226
Tests__Database__SQLServerMasterConnectionString: "Server=(local);User Id=sa;Password=$(SA_PASSWORD);Encrypt=True;TrustServerCertificate=True"
213227
# Filter tests that are part of the Umbraco.Infrastructure namespace but not part of the Umbraco.Infrastructure.Service namespace
214228
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure) & (FullyQualifiedName!~Umbraco.Infrastructure.Service)"
215-
LinuxPart2Of3:
229+
LinuxPart2Of4:
216230
vmImage: "ubuntu-latest"
217231
Tests__Database__DatabaseType: SqlServer
218232
Tests__Database__SQLServerMasterConnectionString: "Server=(local);User Id=sa;Password=$(SA_PASSWORD);Encrypt=True;TrustServerCertificate=True"
219233
# Filter tests that are part of the Umbraco.Infrastructure.Service namespace
220234
testFilter: "(FullyQualifiedName~Umbraco.Infrastructure.Service)"
221-
LinuxPart3Of3:
235+
LinuxPart3Of4:
236+
vmImage: "ubuntu-latest"
237+
Tests__Database__DatabaseType: SqlServer
238+
Tests__Database__SQLServerMasterConnectionString: "Server=(local);User Id=sa;Password=$(SA_PASSWORD);Encrypt=True;TrustServerCertificate=True"
239+
# Filter tests that are not part of the Umbraco.Infrastructure and ManagementApi namespace.
240+
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure) & (FullyQualifiedName!~ManagementApi)"
241+
LinuxPart4Of4:
222242
vmImage: "ubuntu-latest"
223243
Tests__Database__DatabaseType: SqlServer
224244
Tests__Database__SQLServerMasterConnectionString: "Server=(local);User Id=sa;Password=$(SA_PASSWORD);Encrypt=True;TrustServerCertificate=True"
225-
# Filter tests that are not part of the Umbraco.Infrastructure namespace. So this will run all tests that are not part of the Umbraco.Infrastructure namespace
226-
testFilter: "(FullyQualifiedName!~Umbraco.Infrastructure)"
245+
# Filter tests that are part of the ManagementApi namespace.
246+
testFilter: "(FullyQualifiedName~ManagementApi)"
227247
pool:
228248
vmImage: $(vmImage)
229249
steps:
@@ -485,7 +505,7 @@ stages:
485505
jobs:
486506
- job:
487507
displayName: E2E Tests with Different App settings (SQL Server)
488-
condition: ${{ or(eq(parameters.differentAppSettingsAcceptanceTests, true), eq(parameters.skipDefaultConfigAcceptanceTests, true)) }}
508+
condition: ${{ eq(parameters.differentAppSettingsAcceptanceTests, true) }}
489509
timeoutInMinutes: 180
490510
variables:
491511
SA_PASSWORD: UmbracoAcceptance123!
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System.Linq.Expressions;
2+
using System.Net;
3+
using NUnit.Framework;
4+
using Umbraco.Cms.Api.Management.Controllers.Culture;
5+
using Umbraco.Cms.Core;
6+
using Umbraco.Cms.Core.Services;
7+
using Umbraco.Cms.Tests.Common.Builders;
8+
using Umbraco.Cms.Tests.Common.Builders.Extensions;
9+
10+
namespace Umbraco.Cms.Tests.Integration.ManagementApi.Culture;
11+
12+
public class AllCultureControllerTests : ManagementApiUserGroupTestBase<AllCultureController>
13+
{
14+
ILanguageService LanguageService => GetRequiredService<ILanguageService>();
15+
16+
[SetUp]
17+
public async Task Setup()
18+
{
19+
var langDa = new LanguageBuilder()
20+
.WithCultureInfo("da-DK")
21+
.Build();
22+
await LanguageService.CreateAsync(langDa, Constants.Security.SuperUserKey);
23+
}
24+
25+
protected override Expression<Func<AllCultureController, object>> MethodSelector =>
26+
x => x.GetAll(CancellationToken.None, 0, 100);
27+
28+
protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
29+
{
30+
ExpectedStatusCode = HttpStatusCode.OK
31+
};
32+
33+
protected override UserGroupAssertionModel EditorUserGroupAssertionModel => new()
34+
{
35+
ExpectedStatusCode = HttpStatusCode.OK
36+
};
37+
38+
protected override UserGroupAssertionModel SensitiveDataUserGroupAssertionModel => new()
39+
{
40+
ExpectedStatusCode = HttpStatusCode.OK
41+
};
42+
43+
protected override UserGroupAssertionModel TranslatorUserGroupAssertionModel => new()
44+
{
45+
ExpectedStatusCode = HttpStatusCode.OK
46+
};
47+
48+
protected override UserGroupAssertionModel WriterUserGroupAssertionModel => new()
49+
{
50+
ExpectedStatusCode = HttpStatusCode.OK
51+
};
52+
53+
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
54+
{
55+
ExpectedStatusCode = HttpStatusCode.Unauthorized
56+
};
57+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
using System.Linq.Expressions;
2+
using System.Net;
3+
using NUnit.Framework;
4+
using Umbraco.Cms.Api.Management.Controllers.DataType;
5+
using Umbraco.Cms.Core;
6+
using Umbraco.Cms.Core.Models;
7+
using Umbraco.Cms.Core.Services;
8+
using Umbraco.Cms.Tests.Common.Builders;
9+
using Umbraco.Cms.Tests.Common.Builders.Extensions;
10+
11+
namespace Umbraco.Cms.Tests.Integration.ManagementApi.DataType;
12+
13+
public class ByKeyDataTypeControllerTests : ManagementApiUserGroupTestBase<ByKeyDataTypeController>
14+
{
15+
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
16+
17+
private Guid _dataTypeKey;
18+
19+
[SetUp]
20+
public async Task Setup()
21+
{
22+
var dataType = new DataTypeBuilder()
23+
.WithId(0)
24+
.WithName("Custom list view")
25+
.WithDatabaseType(ValueStorageType.Nvarchar)
26+
.AddEditor()
27+
.WithAlias(Constants.PropertyEditors.Aliases.ListView)
28+
.Done()
29+
.Build();
30+
var response = await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey);
31+
32+
_dataTypeKey = response.Result.Key;
33+
}
34+
35+
protected override Expression<Func<ByKeyDataTypeController, object>> MethodSelector =>
36+
x => x.ByKey(CancellationToken.None, _dataTypeKey);
37+
38+
protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
39+
{
40+
ExpectedStatusCode = HttpStatusCode.OK
41+
};
42+
43+
protected override UserGroupAssertionModel EditorUserGroupAssertionModel => new()
44+
{
45+
ExpectedStatusCode = HttpStatusCode.OK
46+
};
47+
48+
protected override UserGroupAssertionModel SensitiveDataUserGroupAssertionModel => new()
49+
{
50+
ExpectedStatusCode = HttpStatusCode.Forbidden
51+
};
52+
53+
protected override UserGroupAssertionModel TranslatorUserGroupAssertionModel => new()
54+
{
55+
ExpectedStatusCode = HttpStatusCode.Forbidden
56+
};
57+
58+
protected override UserGroupAssertionModel WriterUserGroupAssertionModel => new()
59+
{
60+
ExpectedStatusCode = HttpStatusCode.OK
61+
};
62+
63+
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
64+
{
65+
ExpectedStatusCode = HttpStatusCode.Unauthorized
66+
};
67+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
using System.Linq.Expressions;
2+
using System.Net;
3+
using System.Net.Http.Json;
4+
using NUnit.Framework;
5+
using Umbraco.Cms.Api.Management.Controllers.DataType;
6+
using Umbraco.Cms.Api.Management.ViewModels;
7+
using Umbraco.Cms.Api.Management.ViewModels.DataType;
8+
using Umbraco.Cms.Core;
9+
using Umbraco.Cms.Core.Models;
10+
using Umbraco.Cms.Core.Services;
11+
using Umbraco.Cms.Tests.Common.Builders;
12+
using Umbraco.Cms.Tests.Common.Builders.Extensions;
13+
14+
namespace Umbraco.Cms.Tests.Integration.ManagementApi.DataType;
15+
16+
public class CopyDataTypeControllerTests : ManagementApiUserGroupTestBase<CopyDataTypeController>
17+
{
18+
private IDataTypeContainerService DataTypeContainerService => GetRequiredService<IDataTypeContainerService>();
19+
20+
private IDataTypeService DataTypeService => GetRequiredService<IDataTypeService>();
21+
22+
private Guid _dataTypeKey;
23+
private Guid _folderKey;
24+
25+
[SetUp]
26+
public async Task Setup()
27+
{
28+
// Folder
29+
var responseFolder = await DataTypeContainerService.CreateAsync(Guid.NewGuid(), "TestFolder", Constants.System.RootKey, Constants.Security.SuperUserKey);
30+
_folderKey = responseFolder.Result.Key;
31+
32+
// Datatype
33+
var dataType = new DataTypeBuilder()
34+
.WithId(0)
35+
.WithName("Custom list view")
36+
.WithDatabaseType(ValueStorageType.Nvarchar)
37+
.AddEditor()
38+
.WithAlias(Constants.PropertyEditors.Aliases.ListView)
39+
.Done()
40+
.Build();
41+
var responseDataType = await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey);
42+
43+
_dataTypeKey = responseDataType.Result.Key;
44+
}
45+
46+
protected override Expression<Func<CopyDataTypeController, object>> MethodSelector =>
47+
x => x.Copy(CancellationToken.None, _dataTypeKey, null);
48+
49+
protected override UserGroupAssertionModel AdminUserGroupAssertionModel => new()
50+
{
51+
ExpectedStatusCode = HttpStatusCode.Created
52+
};
53+
54+
protected override UserGroupAssertionModel EditorUserGroupAssertionModel => new()
55+
{
56+
ExpectedStatusCode = HttpStatusCode.Forbidden
57+
};
58+
59+
protected override UserGroupAssertionModel SensitiveDataUserGroupAssertionModel => new()
60+
{
61+
ExpectedStatusCode = HttpStatusCode.Forbidden
62+
};
63+
64+
protected override UserGroupAssertionModel TranslatorUserGroupAssertionModel => new()
65+
{
66+
ExpectedStatusCode = HttpStatusCode.Forbidden
67+
};
68+
69+
protected override UserGroupAssertionModel WriterUserGroupAssertionModel => new()
70+
{
71+
ExpectedStatusCode = HttpStatusCode.Forbidden
72+
};
73+
74+
protected override UserGroupAssertionModel UnauthorizedUserGroupAssertionModel => new()
75+
{
76+
ExpectedStatusCode = HttpStatusCode.Unauthorized
77+
};
78+
79+
protected override async Task<HttpResponseMessage> ClientRequest()
80+
{
81+
CopyDataTypeRequestModel copyDataTypeRequestModel = new() { Target = new ReferenceByIdModel(_folderKey) };
82+
83+
return await Client.PostAsync(Url, JsonContent.Create(copyDataTypeRequestModel));
84+
}
85+
}

0 commit comments

Comments
 (0)