From 7437d8e30ba2f5c320cdcac1e9de6f604084cf44 Mon Sep 17 00:00:00 2001 From: "Sean G. Wright" Date: Sat, 10 Feb 2024 15:11:56 -0500 Subject: [PATCH 1/4] refactor(Web): settings configuration for local/CI builds disable recaptcha server validation in CI --- .../Infrastructure/CaptchaValidator.cs | 17 ++++-- .../appsettings.CI.json | 23 ++++++++ .../appsettings.Development.json | 26 ++++----- .../appsettings.json | 54 ------------------- .../appsettings.qa.json | 6 --- .../appsettings.uat.json | 17 ------ 6 files changed, 46 insertions(+), 97 deletions(-) delete mode 100644 src/Kentico.Community.Portal.Web/appsettings.qa.json delete mode 100644 src/Kentico.Community.Portal.Web/appsettings.uat.json diff --git a/src/Kentico.Community.Portal.Web/Infrastructure/CaptchaValidator.cs b/src/Kentico.Community.Portal.Web/Infrastructure/CaptchaValidator.cs index 88efb476..7039746e 100644 --- a/src/Kentico.Community.Portal.Web/Infrastructure/CaptchaValidator.cs +++ b/src/Kentico.Community.Portal.Web/Infrastructure/CaptchaValidator.cs @@ -16,6 +16,11 @@ public CaptchaValidator(IOptions options, IHttpClientFactory public async Task ValidateCaptcha(ICaptchaClientResponse clientResponse) { + if (settings.IsValidationDisabled) + { + return new() { IsSuccess = true }; + } + string secret = settings.SecretKey; var client = httpClientFactory.CreateClient(); string requestURL = string.Format( @@ -33,20 +38,20 @@ public async Task ValidateCaptcha(ICaptchaClientRespons if (response is null) { - return new CaptchaValidationResult { IsSuccess = false, ErrorMessage = "Could not validate captcha" }; + return new() { IsSuccess = false, ErrorMessage = "Could not validate captcha" }; } if (response.Score < settings.ScoreThredhold) { - return new CaptchaValidationResult { IsSuccess = false, ErrorMessage = "Invalid captcha score" }; + return new() { IsSuccess = false, ErrorMessage = "Invalid captcha score" }; } if (!response.IsSuccess) { - return new CaptchaValidationResult { IsSuccess = false, ErrorMessage = response.ErrorMessages.FirstOrDefault() ?? "Captcha failed" }; + return new() { IsSuccess = false, ErrorMessage = response.ErrorMessages.FirstOrDefault() ?? "Captcha failed" }; } - return new CaptchaValidationResult { IsSuccess = true }; + return new() { IsSuccess = true }; } public class CaptchaResponse @@ -74,6 +79,10 @@ public class CaptchaValidationResult public class ReCaptchaSettings { + /// + /// Used to disable server-side captcha validation in specific scenarios (ex: CI) + /// + public bool IsValidationDisabled { get; set; } public string SiteKey { get; set; } = ""; public string SecretKey { get; set; } = ""; public double ScoreThredhold { get; set; } diff --git a/src/Kentico.Community.Portal.Web/appsettings.CI.json b/src/Kentico.Community.Portal.Web/appsettings.CI.json index 5294e9e3..1346f1b2 100644 --- a/src/Kentico.Community.Portal.Web/appsettings.CI.json +++ b/src/Kentico.Community.Portal.Web/appsettings.CI.json @@ -1,5 +1,28 @@ { "ConnectionStrings": { "CMSConnectionString": "Data Source=localhost;Initial Catalog=Kentico.Community;User Id=sa;Password=Pass@12345;Persist Security Info=False;Connect Timeout=10;Encrypt=False;Current Language=English;TrustServerCertificate=True;" + }, + + "CMSSendGrid": { + "ApiKey": "" + }, + + "Kentico.Xperience.Lucene.Custom": { + "WebCrawlerBaseUrl": "https://localhost:45039" + }, + + "ReCaptcha": { + "SiteKey": "6LfJIt0ZAAAAADy4LwyLOjqH0Fynf85tX5o9HF-5", + "SecretKey": "test-secret", + "ScoreThreshold": 0, + "IsValidationDisabled": true + }, + + "Cache": { + "Query": { + "IsEnabled": true, + "IsSlidingExpiration": false, + "CacheItemDuration": 1 + } } } diff --git a/src/Kentico.Community.Portal.Web/appsettings.Development.json b/src/Kentico.Community.Portal.Web/appsettings.Development.json index dffd236f..a19ad7ba 100644 --- a/src/Kentico.Community.Portal.Web/appsettings.Development.json +++ b/src/Kentico.Community.Portal.Web/appsettings.Development.json @@ -4,8 +4,7 @@ "Default": "Information", "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information", - "System.Net.Http.HttpClient": "Warning", - "Vite.AspNetCore.Services.ViteManifest": "Warning" + "System.Net.Http.HttpClient": "Warning" }, "KenticoEventLog": { "LogLevel": { @@ -14,24 +13,11 @@ } } }, - "AllowedHosts": "*", - "MicrosoftDynamics": { - "Url": "", - "SupportCasesDirectory": "SupportCases", - "ProcessedCasesDirectory": "Processed" - }, - - "GoogleTagManager": { - "Code": "GTM-KXPK66G" - }, - - "xperience.lucene": { + "Kentico.Xperience.Lucene.Custom": { "WebCrawlerBaseUrl": "https://localhost:45039/" }, - "DefaultSenderAddress": "no-reply@localhost:45039", - "SmtpOptions": { "Server": { "Host": "localhost", @@ -39,6 +25,14 @@ } }, + "Cache": { + "Query": { + "IsEnabled": true, + "IsSlidingExpiration": false, + "CacheItemDuration": 1 + } + }, + "Vite": { "Base": "dist/", "Server": { diff --git a/src/Kentico.Community.Portal.Web/appsettings.json b/src/Kentico.Community.Portal.Web/appsettings.json index 496873ce..1f801b38 100644 --- a/src/Kentico.Community.Portal.Web/appsettings.json +++ b/src/Kentico.Community.Portal.Web/appsettings.json @@ -14,60 +14,6 @@ }, "AllowedHosts": "*", - "ConnectionStrings": { - "CMSConnectionString": "" - }, - - "CMSHashStringSalt": "", - - "xperience.lucene": { - "WebCrawlerBaseUrl": "https://community.kentico.com/" - }, - - "MicrosoftDynamics": { - "Url": "", - "SupportCasesDirectory": "SupportCases", - "ProcessedCasesDirectory": "Processed" - }, - - "GoogleTagManager": { - "Code": "" - }, - - "ReCaptcha": { - "SiteKey": "test-key", - "SecretKey": "test-secret", - "ScoreThreshold": 0.5 - }, - - "CMSSendGrid": { - "ApiKey": "" - }, - - "Cache": { - "Query": { - "IsEnabled": true, - "IsSlidingExpiration": false, - "CacheItemDuration": 5 - } - }, - - "DefaultSenderAddress": "no-reply@community.kentico.com", - - "CMSAdminSettings": { - "Authentication": { - "Identity": { - "AzureAD": { - "Domain": "", - "TenantId": "", - "ClientId": "", - "Instance": "https://login.microsoftonline.com/", - "CallbackPath": "/admin-oidc" - } - } - } - }, - "Vite": { "Base": "dist/", "Manifest": "manifest.json" diff --git a/src/Kentico.Community.Portal.Web/appsettings.qa.json b/src/Kentico.Community.Portal.Web/appsettings.qa.json deleted file mode 100644 index d684187c..00000000 --- a/src/Kentico.Community.Portal.Web/appsettings.qa.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "xperience.lucene": { - "WebCrawlerBaseUrl": "" - }, - "DefaultSenderAddress": "no-reply@" -} diff --git a/src/Kentico.Community.Portal.Web/appsettings.uat.json b/src/Kentico.Community.Portal.Web/appsettings.uat.json deleted file mode 100644 index 1dc1a46b..00000000 --- a/src/Kentico.Community.Portal.Web/appsettings.uat.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "MicrosoftDynamics": { - "Url": "", - "SupportCasesDirectory": "SupportCases", - "ProcessedCasesDirectory": "Processed" - }, - - "GoogleTagManager": { - "Code": "" - }, - - "xperience.lucene": { - "WebCrawlerBaseUrl": "" - }, - - "DefaultSenderAddress": "no-reply@" -} From 293d26b36235f72892752ccf9b9534f2c0414285 Mon Sep 17 00:00:00 2001 From: "Sean G. Wright" Date: Sat, 10 Feb 2024 15:13:38 -0500 Subject: [PATCH 2/4] build(github): specify commit hash for 3rd party action --- .github/workflows/ci.yml | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9439b353..eb770070 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,17 +1,6 @@ name: "CI: Build and Test" on: - # Disabled for now since the deploy.yml also does a build and almost all updates come through PRs - # We don't need to duplicate the build once a PR merges - # push: - # branches: [main] - # paths: - # - "**.cs" - # - "**.csproj" - # - "**.props" - # - "**.targets" - # - "**.sln" - # - "**.ps1" pull_request: branches: [main] paths: @@ -94,7 +83,7 @@ jobs: -DestinationPath "./database" - name: Install a SQL Server suite of tools (SQLEngine, SQLPackage) - uses: potatoqualitee/mssqlsuite@v1.7 + uses: potatoqualitee/mssqlsuite@9a0136e208df60b8ecb62909f076bc34854fa55a # set as a commit hash for security - v1.7 with: install: sqlpackage, sqlengine sa-password: Pass@12345 From ea09fe69b8036c1af6022b1d7db23b14b2bb8ecd Mon Sep 17 00:00:00 2001 From: "Sean G. Wright" Date: Sat, 10 Feb 2024 15:19:19 -0500 Subject: [PATCH 3/4] build(Web): populate CI configuration file to pass tests --- .../appsettings.CI.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Kentico.Community.Portal.Web/appsettings.CI.json b/src/Kentico.Community.Portal.Web/appsettings.CI.json index 1346f1b2..21422212 100644 --- a/src/Kentico.Community.Portal.Web/appsettings.CI.json +++ b/src/Kentico.Community.Portal.Web/appsettings.CI.json @@ -3,6 +3,22 @@ "CMSConnectionString": "Data Source=localhost;Initial Catalog=Kentico.Community;User Id=sa;Password=Pass@12345;Persist Security Info=False;Connect Timeout=10;Encrypt=False;Current Language=English;TrustServerCertificate=True;" }, + "CMSHashStringSalt": "hash-string-salt", + + "CMSAdminSettings": { + "Authentication": { + "Identity": { + "AzureAD": { + "Domain": "ci-domain.onmicrosoft.com", + "TenantId": "ci-tenant-id", + "ClientId": "ci-client-id", + "Instance": "https://login.microsoftonline.com/", + "CallbackPath": "/admin-oidc" + } + } + } + }, + "CMSSendGrid": { "ApiKey": "" }, From bfb1e5615561fc68444fc9c1009bd3cf57b81b5d Mon Sep 17 00:00:00 2001 From: "Sean G. Wright" Date: Sat, 10 Feb 2024 15:22:06 -0500 Subject: [PATCH 4/4] build(Web): populate Development configuration file to enable local env --- .../appsettings.Development.json | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/Kentico.Community.Portal.Web/appsettings.Development.json b/src/Kentico.Community.Portal.Web/appsettings.Development.json index a19ad7ba..dbead615 100644 --- a/src/Kentico.Community.Portal.Web/appsettings.Development.json +++ b/src/Kentico.Community.Portal.Web/appsettings.Development.json @@ -14,6 +14,22 @@ } }, + "CMSHashStringSalt": "hash-string-salt", + + "CMSAdminSettings": { + "Authentication": { + "Identity": { + "AzureAD": { + "Domain": "ci-domain.onmicrosoft.com", + "TenantId": "ci-tenant-id", + "ClientId": "ci-client-id", + "Instance": "https://login.microsoftonline.com/", + "CallbackPath": "/admin-oidc" + } + } + } + }, + "Kentico.Xperience.Lucene.Custom": { "WebCrawlerBaseUrl": "https://localhost:45039/" },