From 307859b739b9dae40d9a33e76f35acc657b648f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rua?= <140734849+joao4all@users.noreply.github.com> Date: Wed, 22 May 2024 11:44:59 +0100 Subject: [PATCH] Feat #637 [Configuration] Add a fullTrust property to the appsettings (#639) --- .../Components/IndexComponentTestFixture.cs | 62 +++++++++---------- .../Components/LoginTestFixture.cs | 10 ++- .../Components/IndexComponent.razor | 2 +- .../Components/IndexComponent.razor.cs | 6 -- COMET.Web.Common/Components/Login.razor | 6 +- COMET.Web.Common/Components/Login.razor.cs | 14 ++--- .../Enumerations/FullTrustTrustedKind.cs | 47 ++++++++++++++ .../Configuration/FullTrustConfiguration.cs | 44 +++++++++++++ .../Configuration/ServerConfiguration.cs | 5 ++ .../ViewModels/Components/LoginViewModel.cs | 17 ++++- COMETwebapp.Tests/Pages/IndexTestFixture.cs | 12 +--- COMETwebapp/Pages/Index.razor | 2 +- COMETwebapp/Pages/Index.razor.cs | 23 ------- COMETwebapp/Utilities/Constants.cs | 5 -- COMETwebapp/appsettings.json | 5 +- 15 files changed, 166 insertions(+), 94 deletions(-) create mode 100644 COMET.Web.Common/Enumerations/FullTrustTrustedKind.cs create mode 100644 COMET.Web.Common/Model/Configuration/FullTrustConfiguration.cs diff --git a/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs b/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs index 7f63da7b..c9130b38 100644 --- a/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs @@ -1,25 +1,24 @@ // -------------------------------------------------------------------------------------------------------------------- // -// Copyright (c) 2023-2024 Starion Group S.A. +// Copyright (c) 2024 Starion Group S.A. // -// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, Nabil Abbar +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua // -// This file is part of CDP4-COMET WEB Community Edition -// The CDP4-COMET WEB Community Edition is the Starion Web Application implementation of ECSS-E-TM-10-25 -// Annex A and Annex C. +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. // -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. // -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. // +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . // // -------------------------------------------------------------------------------------------------------------------- @@ -62,6 +61,16 @@ namespace COMET.Web.Common.Tests.Components [TestFixture] public class IndexComponentTestFixture { + private IIndexViewModel viewModel; + private TestContext context; + private Mock versionService; + private Mock sessionService; + private Mock serverConnectionService; + private Mock authenticationService; + private TestAuthorizationContext authorization; + private SourceList sourceList; + private Mock registrationService; + [SetUp] public void Setup() { @@ -69,7 +78,8 @@ public void Setup() this.versionService = new Mock(); this.sessionService = new Mock(); this.serverConnectionService = new Mock(); - this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration()); + var serverConfiguration = new ServerConfiguration { FullTrustConfiguration = new FullTrustConfiguration() }; + this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(serverConfiguration); this.sourceList = new SourceList(); this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList); @@ -89,11 +99,11 @@ public void Setup() this.context.Services.AddSingleton(this.registrationService.Object); this.context.ConfigureDevExpressBlazor(); this.authorization = this.context.AddTestAuthorization(); - + var configurationService = new Mock(); configurationService.Setup(x => x.GetText(It.IsAny())).Returns("something"); this.context.Services.AddSingleton(configurationService.Object); -} + } [TearDown] public void Teardown() @@ -101,16 +111,6 @@ public void Teardown() this.context.CleanContext(); } - private IIndexViewModel viewModel; - private TestContext context; - private Mock versionService; - private Mock sessionService; - private Mock serverConnectionService; - private Mock authenticationService; - private TestAuthorizationContext authorization; - private SourceList sourceList; - private Mock registrationService; - [Test] public void VerifyIndexPageAuthorized() { @@ -219,11 +219,7 @@ public void VerifyIndexPageWithRedirectionNotAuthorized() const string targetServer = "http://localhost:5000"; var url = QueryHelpers.AddQueryString("ModelDashboard", QueryKeys.ServerKey, targetServer); - var renderer = this.context.RenderComponent(parameters => - { - parameters.Add(p => p.Redirect, url); - parameters.Add(p => p.FullTrustCheckboxVisible, true); - }); + var renderer = this.context.RenderComponent(parameters => { parameters.Add(p => p.Redirect, url); }); var login = renderer.FindComponent(); Assert.That(login.Instance.ViewModel.AuthenticationDto.SourceAddress, Is.EqualTo(targetServer)); diff --git a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs index c3843cd2..c4b6459a 100644 --- a/COMET.Web.Common.Tests/Components/LoginTestFixture.cs +++ b/COMET.Web.Common.Tests/Components/LoginTestFixture.cs @@ -28,7 +28,6 @@ namespace COMET.Web.Common.Tests.Components using Bunit; using COMET.Web.Common.Components; - using COMET.Web.Common.Enumerations; using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.Model.DTO; using COMET.Web.Common.Services.ConfigurationService; @@ -61,7 +60,14 @@ public void Setup() { this.authenticationService = new Mock(); this.serverConnectionService = new Mock(); - this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(new ServerConfiguration { ServerAddress = "http://localhost.com" }); + + var serverConfiguration = new ServerConfiguration + { + ServerAddress = "http://localhost.com", + FullTrustConfiguration = new FullTrustConfiguration() + }; + + this.serverConnectionService.Setup(x => x.ServerConfiguration).Returns(serverConfiguration); this.context = new TestContext(); this.viewModel = new LoginViewModel(this.authenticationService.Object, this.serverConnectionService.Object); this.context.Services.AddSingleton(this.viewModel); diff --git a/COMET.Web.Common/Components/IndexComponent.razor b/COMET.Web.Common/Components/IndexComponent.razor index 9e5be980..22f04eb7 100644 --- a/COMET.Web.Common/Components/IndexComponent.razor +++ b/COMET.Web.Common/Components/IndexComponent.razor @@ -70,7 +70,7 @@
Connect and Open a Model.
Connect
- +
diff --git a/COMET.Web.Common/Components/IndexComponent.razor.cs b/COMET.Web.Common/Components/IndexComponent.razor.cs index 88cf3901..33694aaa 100644 --- a/COMET.Web.Common/Components/IndexComponent.razor.cs +++ b/COMET.Web.Common/Components/IndexComponent.razor.cs @@ -70,12 +70,6 @@ public partial class IndexComponent [Parameter] public string Redirect { get; set; } - /// - /// The condition to check if the full trust checkbox should be visible or not - /// - [Parameter] - public bool FullTrustCheckboxVisible { get; set; } - /// /// The /// diff --git a/COMET.Web.Common/Components/Login.razor b/COMET.Web.Common/Components/Login.razor index 04279a0b..3f9f2fd1 100644 --- a/COMET.Web.Common/Components/Login.razor +++ b/COMET.Web.Common/Components/Login.razor @@ -20,12 +20,13 @@ // limitations under the License. -------------------------------------------------------------------------------> @namespace COMET.Web.Common.Components +@using COMET.Web.Common.Enumerations @inherits DisposableComponent - @if (string.IsNullOrEmpty(this.ViewModel.ServerConnectionService.ServerConfiguration.ServerAddress)) + @if (string.IsNullOrEmpty(this.ServerConfiguration.ServerAddress)) { - @if (this.FullTrustCheckboxVisible) + @if (this.ServerConfiguration.FullTrustConfiguration?.IsVisible == true || this.ServerConfiguration.FullTrustConfiguration?.IsTrusted == FullTrustTrustedKind.UserDefined) { diff --git a/COMET.Web.Common/Components/Login.razor.cs b/COMET.Web.Common/Components/Login.razor.cs index ce34ff5b..573523f2 100644 --- a/COMET.Web.Common/Components/Login.razor.cs +++ b/COMET.Web.Common/Components/Login.razor.cs @@ -25,6 +25,7 @@ namespace COMET.Web.Common.Components { + using COMET.Web.Common.Model.Configuration; using COMET.Web.Common.ViewModels.Components; using Microsoft.AspNetCore.Components; @@ -64,13 +65,7 @@ public partial class Login /// The label for the full trust checkbox field /// [Parameter] - public string FullTrustLabel { get; set; } = "FullTrust:"; - - /// - /// The condition to check if the full trust checkbox should be visible or not - /// - [Parameter] - public bool FullTrustCheckboxVisible { get; set; } = false; + public string FullTrustLabel { get; set; } = "Full Trust:"; /// /// The text of the login button @@ -92,6 +87,11 @@ public partial class Login /// public Dictionary FieldsFocusedStatus { get; private set; } + /// + /// Gets the server configuration + /// + private ServerConfiguration ServerConfiguration => this.ViewModel.ServerConnectionService.ServerConfiguration; + /// /// Method invoked when the component is ready to start, having received its /// initial parameters from its parent in the render tree. diff --git a/COMET.Web.Common/Enumerations/FullTrustTrustedKind.cs b/COMET.Web.Common/Enumerations/FullTrustTrustedKind.cs new file mode 100644 index 00000000..63faf5d6 --- /dev/null +++ b/COMET.Web.Common/Enumerations/FullTrustTrustedKind.cs @@ -0,0 +1,47 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Enumerations +{ + /// + /// An enumeration that defines possible values for the full trust trusted configuration + /// + public enum FullTrustTrustedKind + { + /// + /// The kind selected for when the configuration should be full trust + /// + FullTrust, + + /// + /// The kind selected for when the configuration should be no trust + /// + NoTrust, + + /// + /// The kind selected for when the configuration should be user defined + /// + UserDefined + } +} diff --git a/COMET.Web.Common/Model/Configuration/FullTrustConfiguration.cs b/COMET.Web.Common/Model/Configuration/FullTrustConfiguration.cs new file mode 100644 index 00000000..2c2f5f01 --- /dev/null +++ b/COMET.Web.Common/Model/Configuration/FullTrustConfiguration.cs @@ -0,0 +1,44 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2024 Starion Group S.A. +// +// Authors: Sam Gerené, Alex Vorobiev, Alexander van Delft, Jaime Bernar, Théate Antoine, João Rua +// +// This file is part of COMET WEB Community Edition +// The COMET WEB Community Edition is the Starion Group Web Application implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// +// The COMET WEB Community Edition is free software; you can redistribute it and/or +// modify it under the terms of the GNU Affero General Public +// License as published by the Free Software Foundation; either +// version 3 of the License, or (at your option) any later version. +// +// The COMET WEB Community Edition is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see . +// +// -------------------------------------------------------------------------------------------------------------------- + +namespace COMET.Web.Common.Model.Configuration +{ + using COMET.Web.Common.Enumerations; + + /// + /// Holds all of the configuration related to the FullTrust feature + /// + public class FullTrustConfiguration + { + /// + /// Verifies if the full trust option should be visible + /// + public bool IsVisible { get; set; } = false; + + /// + /// Verifies the kind of trust the full trust feature has + /// + public FullTrustTrustedKind IsTrusted { get; set; } = FullTrustTrustedKind.UserDefined; + } +} diff --git a/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs b/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs index 0d48247b..b732b56f 100644 --- a/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs +++ b/COMET.Web.Common/Model/Configuration/ServerConfiguration.cs @@ -39,6 +39,11 @@ public class ServerConfiguration /// public BookInputConfiguration BookInputConfiguration { get; set; } + /// + /// The configuration values for the FullTrust feature + /// + public FullTrustConfiguration FullTrustConfiguration { get; set; } + /// /// Gets or sets the . If not filters are specified all the available models are shown /// diff --git a/COMET.Web.Common/ViewModels/Components/LoginViewModel.cs b/COMET.Web.Common/ViewModels/Components/LoginViewModel.cs index 498204b3..bdf022af 100644 --- a/COMET.Web.Common/ViewModels/Components/LoginViewModel.cs +++ b/COMET.Web.Common/ViewModels/Components/LoginViewModel.cs @@ -24,6 +24,7 @@ namespace COMET.Web.Common.ViewModels.Components { + using COMET.Web.Common.Enumerations; using COMET.Web.Common.Model.DTO; using COMET.Web.Common.Services.ConfigurationService; using COMET.Web.Common.Services.SessionManagement; @@ -61,6 +62,7 @@ public LoginViewModel(IAuthenticationService authenticationService, IConfigurati { this.ServerConnectionService = serverConnectionService; this.authenticationService = authenticationService; + this.ResetAuthenticationDto(); } /// @@ -89,7 +91,7 @@ public Result AuthenticationResult /// /// The used for perfoming a login /// - public AuthenticationDto AuthenticationDto { get; private set; } = new(); + public AuthenticationDto AuthenticationDto { get; private set; } /// /// Attempt to login to a COMET Server @@ -108,10 +110,21 @@ public async Task ExecuteLogin() if (this.AuthenticationResult.IsSuccess) { - this.AuthenticationDto = new AuthenticationDto(); + this.ResetAuthenticationDto(); } this.IsLoading = false; } + + /// + /// Resets the property to a new object with the default parameters + /// + private void ResetAuthenticationDto() + { + this.AuthenticationDto = new AuthenticationDto() + { + FullTrust = this.ServerConnectionService.ServerConfiguration?.FullTrustConfiguration?.IsTrusted == FullTrustTrustedKind.FullTrust + }; + } } } diff --git a/COMETwebapp.Tests/Pages/IndexTestFixture.cs b/COMETwebapp.Tests/Pages/IndexTestFixture.cs index 06dc2338..a46bf865 100644 --- a/COMETwebapp.Tests/Pages/IndexTestFixture.cs +++ b/COMETwebapp.Tests/Pages/IndexTestFixture.cs @@ -57,7 +57,6 @@ public class IndexTestFixture private Mock viewModel; private TestContext context; private Mock sessionService; - private readonly bool fullTrustValue = true; [SetUp] public void Setup() @@ -72,9 +71,6 @@ public void Setup() this.viewModel = new Mock(); this.viewModel.Setup(x => x.SessionService).Returns(this.sessionService.Object); - var configuration = new Mock(); - configuration.Setup(x => x.GetSection(Constants.FullTrustSelectionEnabledKey).Value).Returns(this.fullTrustValue.ToString()); - var loginViewModel = new Mock(); loginViewModel.Setup(x => x.ServerConnectionService.ServerConfiguration).Returns(new ServerConfiguration()); loginViewModel.Setup(x => x.AuthenticationResult).Returns(new Result()); @@ -83,7 +79,6 @@ public void Setup() this.context.Services.AddSingleton(loginViewModel.Object); this.context.Services.AddSingleton(this.viewModel.Object); this.context.Services.AddSingleton(this.sessionService.Object); - this.context.Services.AddSingleton(configuration.Object); } [TearDown] @@ -97,12 +92,7 @@ public void TearDown() public void VerifyIndexPageNotAuthorized() { var renderer = this.context.RenderComponent(); - - Assert.Multiple(() => - { - Assert.That(() => renderer.FindComponent(), Throws.Nothing); - Assert.That(renderer.Instance.FullTrustCheckboxVisible, Is.EqualTo(this.fullTrustValue)); - }); + Assert.That(() => renderer.FindComponent(), Throws.Nothing); } } } diff --git a/COMETwebapp/Pages/Index.razor b/COMETwebapp/Pages/Index.razor index 1532868f..55fb99d7 100644 --- a/COMETwebapp/Pages/Index.razor +++ b/COMETwebapp/Pages/Index.razor @@ -20,4 +20,4 @@ // along with this program. If not, see http://www.gnu.org/licenses/. -------------------------------------------------------------------------------> @page "/" - + diff --git a/COMETwebapp/Pages/Index.razor.cs b/COMETwebapp/Pages/Index.razor.cs index 20b90173..e5b9e081 100644 --- a/COMETwebapp/Pages/Index.razor.cs +++ b/COMETwebapp/Pages/Index.razor.cs @@ -24,8 +24,6 @@ namespace COMETwebapp.Pages { - using COMETwebapp.Utilities; - using Microsoft.AspNetCore.Components; /// @@ -39,26 +37,5 @@ public partial class Index [Parameter] [SupplyParameterFromQuery] public string Redirect { get; set; } - - /// - /// Gets or sets the - /// - [Inject] - public IConfiguration Configuration { get; set; } - - /// - /// Gets the condition to check if the full trust checkbox should be visible - /// - public bool FullTrustCheckboxVisible { get; private set; } - - /// - /// Method invoked when the component is ready to start, having received its - /// initial parameters from its parent in the render tree. - /// - protected override void OnInitialized() - { - base.OnInitialized(); - this.FullTrustCheckboxVisible = bool.Parse(this.Configuration.GetSection(Constants.FullTrustSelectionEnabledKey).Value!); - } } } diff --git a/COMETwebapp/Utilities/Constants.cs b/COMETwebapp/Utilities/Constants.cs index e1b7cea6..dec6c2f5 100644 --- a/COMETwebapp/Utilities/Constants.cs +++ b/COMETwebapp/Utilities/Constants.cs @@ -33,10 +33,5 @@ public static class Constants /// The name of the configuration key used to retrieve the max upload file size, in megabytes /// public const string MaxUploadFileSizeInMbConfigurationKey = "MaxUploadFileSizeInMb"; - - /// - /// The name of the configuration key used to retrieve the condition to verify if the full trust selection is enabled - /// - public const string FullTrustSelectionEnabledKey = "FullTrustSelectionEnabled"; } } diff --git a/COMETwebapp/appsettings.json b/COMETwebapp/appsettings.json index 060057d0..295df06c 100644 --- a/COMETwebapp/appsettings.json +++ b/COMETwebapp/appsettings.json @@ -2,9 +2,12 @@ "AllowedHosts": "*", "StringTablePath": "wwwroot/DefaultTextConfiguration.json", "MaxUploadFileSizeInMb": 500, - "FullTrustSelectionEnabled": true, "ServerConfiguration": { "ServerAddress": "", + "FullTrustConfiguration": { + "IsVisible": true, + "IsTrusted": "UserDefined" + }, "BookInputConfiguration": { "ShowName": true, "ShowShortName": true