Skip to content

Commit

Permalink
Feat #637 [Configuration] Add a fullTrust property to the appsettings (
Browse files Browse the repository at this point in the history
  • Loading branch information
joao4all authored May 22, 2024
1 parent 5ee3c35 commit 307859b
Show file tree
Hide file tree
Showing 15 changed files with 166 additions and 94 deletions.
62 changes: 29 additions & 33 deletions COMET.Web.Common.Tests/Components/IndexComponentTestFixture.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="IndexComponentTestFixture.cs" company="Starion Group S.A.">
// 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -62,14 +61,25 @@ namespace COMET.Web.Common.Tests.Components
[TestFixture]
public class IndexComponentTestFixture
{
private IIndexViewModel viewModel;
private TestContext context;
private Mock<IVersionService> versionService;
private Mock<ISessionService> sessionService;
private Mock<IConfigurationService> serverConnectionService;
private Mock<IAuthenticationService> authenticationService;
private TestAuthorizationContext authorization;
private SourceList<Iteration> sourceList;
private Mock<IRegistrationService> registrationService;

[SetUp]
public void Setup()
{
this.context = new TestContext();
this.versionService = new Mock<IVersionService>();
this.sessionService = new Mock<ISessionService>();
this.serverConnectionService = new Mock<IConfigurationService>();
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<Iteration>();
this.sessionService.Setup(x => x.OpenIterations).Returns(this.sourceList);

Expand All @@ -89,28 +99,18 @@ public void Setup()
this.context.Services.AddSingleton(this.registrationService.Object);
this.context.ConfigureDevExpressBlazor();
this.authorization = this.context.AddTestAuthorization();

var configurationService = new Mock<IStringTableService>();
configurationService.Setup(x => x.GetText(It.IsAny<string>())).Returns("something");
this.context.Services.AddSingleton(configurationService.Object);
}
}

[TearDown]
public void Teardown()
{
this.context.CleanContext();
}

private IIndexViewModel viewModel;
private TestContext context;
private Mock<IVersionService> versionService;
private Mock<ISessionService> sessionService;
private Mock<IConfigurationService> serverConnectionService;
private Mock<IAuthenticationService> authenticationService;
private TestAuthorizationContext authorization;
private SourceList<Iteration> sourceList;
private Mock<IRegistrationService> registrationService;

[Test]
public void VerifyIndexPageAuthorized()
{
Expand Down Expand Up @@ -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<IndexComponent>(parameters =>
{
parameters.Add(p => p.Redirect, url);
parameters.Add(p => p.FullTrustCheckboxVisible, true);
});
var renderer = this.context.RenderComponent<IndexComponent>(parameters => { parameters.Add(p => p.Redirect, url); });

var login = renderer.FindComponent<Login>();
Assert.That(login.Instance.ViewModel.AuthenticationDto.SourceAddress, Is.EqualTo(targetServer));
Expand Down
10 changes: 8 additions & 2 deletions COMET.Web.Common.Tests/Components/LoginTestFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +60,14 @@ public void Setup()
{
this.authenticationService = new Mock<IAuthenticationService>();
this.serverConnectionService = new Mock<IConfigurationService>();
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);
Expand Down
2 changes: 1 addition & 1 deletion COMET.Web.Common/Components/IndexComponent.razor
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div id="unauthorized-notice" class="text-align-center font-weight-bold">Connect and Open a Model.</div>
<div class="m-top-10px color-title">
<h5 class="color-title font-weight-bold">Connect</h5>
<Login RequestedServer="@this.requestedServer" FullTrustCheckboxVisible="@this.FullTrustCheckboxVisible"/>
<Login RequestedServer="@this.requestedServer"/>
</div>
</div>
</div>
Expand Down
6 changes: 0 additions & 6 deletions COMET.Web.Common/Components/IndexComponent.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,6 @@ public partial class IndexComponent
[Parameter]
public string Redirect { get; set; }

/// <summary>
/// The condition to check if the full trust checkbox should be visible or not
/// </summary>
[Parameter]
public bool FullTrustCheckboxVisible { get; set; }

/// <summary>
/// The <see cref="NavigationManager" />
/// </summary>
Expand Down
6 changes: 4 additions & 2 deletions COMET.Web.Common/Components/Login.razor
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
// limitations under the License.
------------------------------------------------------------------------------->
@namespace COMET.Web.Common.Components
@using COMET.Web.Common.Enumerations
@inherits DisposableComponent

<EditForm Context="editFormContext" Model="@(this.ViewModel.AuthenticationDto)" OnValidSubmit="this.ExecuteLogin">
<DataAnnotationsValidator/>
<DxFormLayout CaptionPosition="CaptionPosition.Vertical">
@if (string.IsNullOrEmpty(this.ViewModel.ServerConnectionService.ServerConfiguration.ServerAddress))
@if (string.IsNullOrEmpty(this.ServerConfiguration.ServerAddress))
{
<DxFormLayoutItem Caption="Source Address:" ColSpanLg="12">
<Template>
Expand Down Expand Up @@ -61,12 +62,13 @@
</Template>
</DxFormLayoutItem>

@if (this.FullTrustCheckboxVisible)
@if (this.ServerConfiguration.FullTrustConfiguration?.IsVisible == true || this.ServerConfiguration.FullTrustConfiguration?.IsTrusted == FullTrustTrustedKind.UserDefined)
{
<DxFormLayoutItem Caption="@(this.FullTrustLabel)" BeginRow="true" ColSpanLg="12" CaptionPosition="CaptionPosition.Horizontal">
<Template>
<DxCheckBox Id="fulltrust"
@bind-Checked="@(this.ViewModel.AuthenticationDto.FullTrust)"
Enabled="@(this.ServerConfiguration.FullTrustConfiguration?.IsTrusted == FullTrustTrustedKind.UserDefined)"
Attributes="@(new Dictionary<string, object> { ["title"] = "Checking this option will allow connecting to servers with self signed certificates" })" />
</Template>
</DxFormLayoutItem>
Expand Down
14 changes: 7 additions & 7 deletions COMET.Web.Common/Components/Login.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -64,13 +65,7 @@ public partial class Login
/// The label for the full trust checkbox field
/// </summary>
[Parameter]
public string FullTrustLabel { get; set; } = "FullTrust:";

/// <summary>
/// The condition to check if the full trust checkbox should be visible or not
/// </summary>
[Parameter]
public bool FullTrustCheckboxVisible { get; set; } = false;
public string FullTrustLabel { get; set; } = "Full Trust:";

/// <summary>
/// The text of the login button
Expand All @@ -92,6 +87,11 @@ public partial class Login
/// </summary>
public Dictionary<string, bool> FieldsFocusedStatus { get; private set; }

/// <summary>
/// Gets the server configuration
/// </summary>
private ServerConfiguration ServerConfiguration => this.ViewModel.ServerConnectionService.ServerConfiguration;

/// <summary>
/// Method invoked when the component is ready to start, having received its
/// initial parameters from its parent in the render tree.
Expand Down
47 changes: 47 additions & 0 deletions COMET.Web.Common/Enumerations/FullTrustTrustedKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FullTrustTrustedKind.cs" company="Starion Group S.A.">
// 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Enumerations
{
/// <summary>
/// An enumeration that defines possible values for the full trust trusted configuration
/// </summary>
public enum FullTrustTrustedKind
{
/// <summary>
/// The kind selected for when the configuration should be full trust
/// </summary>
FullTrust,

/// <summary>
/// The kind selected for when the configuration should be no trust
/// </summary>
NoTrust,

/// <summary>
/// The kind selected for when the configuration should be user defined
/// </summary>
UserDefined
}
}
44 changes: 44 additions & 0 deletions COMET.Web.Common/Model/Configuration/FullTrustConfiguration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="FullTrustConfiguration.cs" company="Starion Group S.A.">
// 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 <http://www.gnu.org/licenses/>.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

namespace COMET.Web.Common.Model.Configuration
{
using COMET.Web.Common.Enumerations;

/// <summary>
/// Holds all of the configuration related to the FullTrust feature
/// </summary>
public class FullTrustConfiguration
{
/// <summary>
/// Verifies if the full trust option should be visible
/// </summary>
public bool IsVisible { get; set; } = false;

/// <summary>
/// Verifies the kind of trust the full trust feature has
/// </summary>
public FullTrustTrustedKind IsTrusted { get; set; } = FullTrustTrustedKind.UserDefined;
}
}
5 changes: 5 additions & 0 deletions COMET.Web.Common/Model/Configuration/ServerConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ public class ServerConfiguration
/// </summary>
public BookInputConfiguration BookInputConfiguration { get; set; }

/// <summary>
/// The configuration values for the FullTrust feature
/// </summary>
public FullTrustConfiguration FullTrustConfiguration { get; set; }

/// <summary>
/// Gets or sets the <see cref="EngineeringModelRdlFilter"/>. If not filters are specified all the available models are shown
/// </summary>
Expand Down
17 changes: 15 additions & 2 deletions COMET.Web.Common/ViewModels/Components/LoginViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,6 +62,7 @@ public LoginViewModel(IAuthenticationService authenticationService, IConfigurati
{
this.ServerConnectionService = serverConnectionService;
this.authenticationService = authenticationService;
this.ResetAuthenticationDto();
}

/// <summary>
Expand Down Expand Up @@ -89,7 +91,7 @@ public Result AuthenticationResult
/// <summary>
/// The <see cref="AuthenticationDto" /> used for perfoming a login
/// </summary>
public AuthenticationDto AuthenticationDto { get; private set; } = new();
public AuthenticationDto AuthenticationDto { get; private set; }

/// <summary>
/// Attempt to login to a COMET Server
Expand All @@ -108,10 +110,21 @@ public async Task ExecuteLogin()

if (this.AuthenticationResult.IsSuccess)
{
this.AuthenticationDto = new AuthenticationDto();
this.ResetAuthenticationDto();
}

this.IsLoading = false;
}

/// <summary>
/// Resets the <see cref="AuthenticationDto"/> property to a new object with the default parameters
/// </summary>
private void ResetAuthenticationDto()
{
this.AuthenticationDto = new AuthenticationDto()
{
FullTrust = this.ServerConnectionService.ServerConfiguration?.FullTrustConfiguration?.IsTrusted == FullTrustTrustedKind.FullTrust
};
}
}
}
Loading

0 comments on commit 307859b

Please sign in to comment.