Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Authentication implementation #316

Merged
merged 10 commits into from
May 22, 2024
Merged

feat: Authentication implementation #316

merged 10 commits into from
May 22, 2024

Conversation

nikcio
Copy link
Owner

@nikcio nikcio commented May 19, 2024

No description provided.

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 3 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Comment on lines +15 to +53
[InlineData(1, 1, "en-us", false, null, false, "Invalid")]
public async Task ContentAtRootQuery_Snaps_Async(
int page,
int pageSize,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentAtRootSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentAtRootQueries.GetItems,
variables = new
{
page,
pageSize,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentAtRoot_Snaps_{page}_{pageSize}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentAtRootQuery_Snaps_Async has 7 arguments, threshold = 4

Suppress

Comment on lines +24 to +64
[InlineData("default", 1, 1, "en-us", false, null, false, "Invalid")]
public async Task ContentByContentTypeQuery_Snaps_Async(
string contentType,
int page,
int pageSize,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentByContentTypeSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentByContentTypeQueries.GetItems,
variables = new
{
contentType,
page,
pageSize,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentByContentType_Snaps_{contentType}_{page}_{pageSize}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentByContentTypeQuery_Snaps_Async has 8 arguments, threshold = 4

Suppress

@@ -32,13 +37,36 @@ public static IUmbracoBuilder AddUHeadless(this IUmbracoBuilder builder, Action<
var options = new UHeadlessOptions()
{
RequestExecutorBuilder = requestExecutorBuilder,
UmbracoBuilder = builder
UmbracoBuilder = builder,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Complex Method
AddUHeadless has a cyclomatic complexity of 10, threshold = 9

Suppress

@@ -1,8 +1,13 @@
using System.ComponentModel.DataAnnotations;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Getting better: String Heavy Function Arguments
The ratio of strings in function arguments decreases from 42.86% to 40.00%, threshold = 39.0%

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Comment on lines +23 to +59
[InlineData("eadd5be4-456c-4a7d-8c4a-2f7ead9c8ecf", "en-us", false, null, true, "Invalid")] // Doesn't error because null is a vaild response
public async Task ContentByGuidQuery_Snaps_Async(
string key,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentByGuidSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentByGuidQueries.GetItems,
variables = new
{
key,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentByGuid_Snaps_{key}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentByGuidQuery_Snaps_Async has 6 arguments, threshold = 4

Suppress

Comment on lines +23 to +59
[InlineData(1152, "en-us", false, null, true, "Invalid")] // Doesn't error because null is a vaild response
public async Task ContentByIdQuery_Snaps_Async(
int id,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentByIdSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentByIdQueries.GetItems,
variables = new
{
id,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentById_Snaps_{id}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentByIdQuery_Snaps_Async has 6 arguments, threshold = 4

Suppress

Comment on lines +23 to +61
[InlineData("https://site-1.com", "/homepage", null, false, null, true, "Invalid")] // Doesn't error because null is a vaild response
public async Task ContentByRouteQuery_Snaps_Async(
string baseUrl,
string route,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentByRouteSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentByRouteQueries.GetItems,
variables = new
{
baseUrl,
route,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentByRoute_Snaps_{Convert.ToBase64String(Encoding.UTF8.GetBytes(baseUrl))}_{Convert.ToBase64String(Encoding.UTF8.GetBytes(route))}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentByRouteQuery_Snaps_Async has 7 arguments, threshold = 4

Suppress

Comment on lines +23 to +61
[InlineData("normal", null, "en-us", false, null, false, "Invalid")]
public async Task ContentByTagQuery_Snaps_Async(
string tag,
string? tagGroup,
string? culture,
bool? includePreview,
string? segment,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_contentByTagSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = ContentByTagQueries.GetItems,
variables = new
{
tag,
tagGroup,
culture,
includePreview,
segment
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"ContentByTag_Snaps_{tag}_{tagGroup}_{culture}_{includePreview}_{segment}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
ContentByTagQuery_Snaps_Async has 7 arguments, threshold = 4

Suppress

Comment on lines +21 to +57
[InlineData("user1", StringPropertyMatchType.Exact, 1, 1, false, "Invalid")]
public async Task FindMembersByDisplayNameQuery_Snaps_Async(
string displayName,
StringPropertyMatchType matchType,
int page,
int pageSize,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_findMembersByDisplayNameSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = FindMembersByDisplayNameQueries.GetItems,
variables = new
{
displayName,
matchType = TestUtils.GetHotChocolateEnum(matchType.ToString()),
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"FindMembersByDisplayName_Snaps_{displayName}_{matchType}_{page}_{pageSize}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
FindMembersByDisplayNameQuery_Snaps_Async has 6 arguments, threshold = 4

Suppress

Comment on lines +21 to +57
[InlineData("[email protected]", StringPropertyMatchType.Exact, 1, 1, false, "Invalid")]
public async Task FindMembersByEmailQuery_Snaps_Async(
string email,
StringPropertyMatchType matchType,
int page,
int pageSize,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_findMembersByEmailSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = FindMembersByEmailQueries.GetItems,
variables = new
{
email,
matchType = TestUtils.GetHotChocolateEnum(matchType.ToString()),
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"FindMembersByEmail_Snaps_{email}_{matchType}_{page}_{pageSize}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
FindMembersByEmailQuery_Snaps_Async has 6 arguments, threshold = 4

Suppress

Comment on lines +21 to +59
[InlineData("Member group 1", "", StringPropertyMatchType.Exact, 1, 1, false, "Invalid")]
public async Task FindMembersByRoleQuery_Snaps_Async(
string roleName,
string usernameToMatch,
StringPropertyMatchType matchType,
int page,
int pageSize,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_findMembersByRoleSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = FindMembersByRoleQueries.GetItems,
variables = new
{
roleName,
usernameToMatch,
matchType = TestUtils.GetHotChocolateEnum(matchType.ToString()),
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"FindMembersByRole_Snaps_{roleName}_{usernameToMatch}_{matchType}_{page}_{pageSize}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
FindMembersByRoleQuery_Snaps_Async has 7 arguments, threshold = 4

Suppress

Comment on lines +21 to +57
[InlineData("user1", StringPropertyMatchType.Exact, 1, 1, false, "Invalid")]
public async Task FindMembersByUsernameQuery_Snaps_Async(
string username,
StringPropertyMatchType matchType,
int page,
int pageSize,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_findMembersByUsernameSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = FindMembersByUsernameQueries.GetItems,
variables = new
{
username,
matchType = TestUtils.GetHotChocolateEnum(matchType.ToString()),
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"FindMembersByUsername_Snaps_{username}_{matchType}_{page}_{pageSize}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
FindMembersByUsernameQuery_Snaps_Async has 6 arguments, threshold = 4

Suppress

Comment on lines +20 to +54
[InlineData("image", 1, 1, false, "Invalid")]
public async Task MediaByContentTypeQuery_Snaps_Async(
string contentType,
int page,
int pageSize,
bool expectSuccess,
params string[] claims)
{
var snapshotProvider = new SnapshotProvider($"{_mediaByContentTypeSnapshotPath}/Snaps");
HttpClient client = _factory.CreateClient();

JwtToken token = await CreateTokenMutation_Async(client, new TokenClaim() { Name = DefaultClaims.UHeadlessScope, Value = claims }).ConfigureAwait(true);

client.DefaultRequestHeaders.Add(token.Header, token.Prefix + token.Token);

using var request = JsonContent.Create(new
{
query = MediaByContentTypeQueries.GetItems,
variables = new
{
contentType,
page,
pageSize,
}
});

HttpResponseMessage response = await client.PostAsync("/graphql", request).ConfigureAwait(true);

string responseContent = await response.Content.ReadAsStringAsync().ConfigureAwait(true);

string snapshotName = $"MediaByContentType_Snaps_{contentType}_{page}_{pageSize}_{string.Join("-", claims)}";

await snapshotProvider.AssertIsSnapshotEqualAsync(snapshotName, responseContent).ConfigureAwait(true);
Assert.Equal(expectSuccess, response.IsSuccessStatusCode);
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ New issue: Excess Number of Function Arguments
MediaByContentTypeQuery_Snaps_Async has 5 arguments, threshold = 4

Suppress

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

@nikcio nikcio marked this pull request as ready for review May 22, 2024 19:17
Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

Copy link

@codescene-delta-analysis codescene-delta-analysis bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Quality Gates: OK

  • Declining Code Health: 12 findings(s) 🚩
  • Improving Code Health: 1 findings(s) ✅

View detailed results in CodeScene

@nikcio nikcio merged commit b84d02c into contrib May 22, 2024
6 checks passed
@nikcio nikcio deleted the feature/auth branch May 22, 2024 19:51
Copy link

sonarcloud bot commented May 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant