From 594f5c75354d33d14a5510ff701db43bed3515a7 Mon Sep 17 00:00:00 2001 From: samatrhea Date: Sun, 17 Dec 2023 11:59:33 +0100 Subject: [PATCH] [Add] logging statement to AuthenticationPluginInjector; fixes #155 [Improve] coverage of AuthenticationPluginInjector --- ...AuthenticationPluginInjectorTestFixture.cs | 65 +++++++++++++++++++ .../AuthenticationPluginInjector.cs | 5 ++ 2 files changed, 70 insertions(+) create mode 100644 CometServer.Tests/Authorization/AuthenticationPluginInjectorTestFixture.cs diff --git a/CometServer.Tests/Authorization/AuthenticationPluginInjectorTestFixture.cs b/CometServer.Tests/Authorization/AuthenticationPluginInjectorTestFixture.cs new file mode 100644 index 00000000..2fdcbd04 --- /dev/null +++ b/CometServer.Tests/Authorization/AuthenticationPluginInjectorTestFixture.cs @@ -0,0 +1,65 @@ +// -------------------------------------------------------------------------------------------------------------------- +// +// Copyright (c) 2015-2023 RHEA System S.A. +// +// Author: Sam Gerené, Alex Vorobiev, Alexander van Delft, Nathanael Smiechowski, Antoine Théate +// +// This file is part of CDP4-COMET Webservices Community Edition. +// The CDP4-COMET Web Services Community Edition is the RHEA implementation of ECSS-E-TM-10-25 Annex A and Annex C. +// This is an auto-generated class. Any manual changes to this file will be overwritten! +// +// The CDP4-COMET Web Services 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 CDP4-COMET Web Services 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 +// Lesser 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 CometServer.Tests.Authorization +{ + using CometServer.Authentication; + + using Microsoft.Extensions.Logging; + + using Moq; + + using NUnit.Framework; + using System.IO; + + /// + /// Test fixture for the class + /// + [TestFixture] + public class AuthenticationPluginInjectorTestFixture + { + private Mock> logger; + + [SetUp] + public void SetUp() + { + this.logger = new Mock>(); + + // create Authentication directory for testing purposes + var path = Path.Combine(TestContext.CurrentContext.TestDirectory, "Authentication"); + Directory.CreateDirectory(path); + } + + [Test] + public void Verify_that_the_AuthenticationPluginInjector_can_be_constructed() + { + var authenticationPluginInjector = new AuthenticationPluginInjector(this.logger.Object); + + Assert.That(authenticationPluginInjector.Plugins, Is.Empty); + + Assert.That(authenticationPluginInjector.Connectors, Is.Empty); + } + } +} diff --git a/CometServer/Authentication/AuthenticationPluginInjector.cs b/CometServer/Authentication/AuthenticationPluginInjector.cs index f4d5f670..690ea6ef 100644 --- a/CometServer/Authentication/AuthenticationPluginInjector.cs +++ b/CometServer/Authentication/AuthenticationPluginInjector.cs @@ -60,6 +60,11 @@ public AuthenticationPluginInjector(ILogger logger this.logger = logger; this.Plugins = this.LoadPlugins().ToList(); + + foreach (var authenticatorConnector in this.Plugins.SelectMany(authenticatorPlugin => authenticatorPlugin.Connectors)) + { + logger.LogInformation(authenticatorConnector.IsUp ? "The {name} is loaded and is Up" : "The {name} is loaded and is Down", authenticatorConnector.Name); + } } ///