From 9427334a1d1bedaac67c805544b52dd29f41beca Mon Sep 17 00:00:00 2001 From: Simon Li Date: Thu, 8 Sep 2022 11:18:52 +0200 Subject: [PATCH 1/4] NH-2558 Fixed various bugs from Local Sonarqube scan --- .../TestUddi/Program.cs | 2 +- src/dk.gov.oiosi.configuration/CacheConfig.cs | 4 +- .../DefaultDocumentTypes.cs | 12 +- src/dk.gov.oiosi/addressing/Identifier.cs | 5 + .../communication/handlers/email/Inbox.cs | 15 +- .../communication/listener/Listener.cs | 6 +- src/dk.gov.oiosi/uddi/UddiLookupKey.cs | 2 +- .../xml/schematron/SchematronValidator.cs | 150 ++++++++++-------- test/dk.gov.oiosi.test.integration/App.config | 14 +- .../AutomaticPasswordFiller/Program.cs | 2 +- 10 files changed, 117 insertions(+), 95 deletions(-) diff --git a/samples/dk.gov.oiosi.samples.TestUddi/TestUddi/Program.cs b/samples/dk.gov.oiosi.samples.TestUddi/TestUddi/Program.cs index 84df2a32..28a358de 100644 --- a/samples/dk.gov.oiosi.samples.TestUddi/TestUddi/Program.cs +++ b/samples/dk.gov.oiosi.samples.TestUddi/TestUddi/Program.cs @@ -11,7 +11,7 @@ namespace dk.gov.oiosi.samples.TestUddi { static void Main(string[] args) { - new Program(); + Program program = new Program(); } diff --git a/src/dk.gov.oiosi.configuration/CacheConfig.cs b/src/dk.gov.oiosi.configuration/CacheConfig.cs index b7c954a4..e3baf333 100644 --- a/src/dk.gov.oiosi.configuration/CacheConfig.cs +++ b/src/dk.gov.oiosi.configuration/CacheConfig.cs @@ -115,9 +115,9 @@ namespace dk.gov.oiosi.configuration } if (schematronStoreCache == null) { - throw new NullArgumentException("schematromStoreCache"); + throw new NullArgumentException("schematronStoreCache"); } - if (schematronStoreCache == null) + if (schemaStoreCache == null) { throw new NullArgumentException("schemaStoreCache"); } diff --git a/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs b/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs index a12bd956..53d17af3 100644 --- a/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs +++ b/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs @@ -115,16 +115,8 @@ namespace dk.gov.oiosi.raspProfile { DocumentTypeConfig documentType = documentTypeConfigDelegate(); DocumentTypeCollectionConfig configuration = ConfigurationHandler.GetConfigurationSection(); - if (configuration.ContainsDocumentTypeByValue(documentType)) - { - // already added - //Debug.Fail("already added"); - configuration.AddDocumentType(documentType); - } - else - { - configuration.AddDocumentType(documentType); - } + configuration.AddDocumentType(documentType); + } /// diff --git a/src/dk.gov.oiosi/addressing/Identifier.cs b/src/dk.gov.oiosi/addressing/Identifier.cs index f8070010..0d4eb6b1 100644 --- a/src/dk.gov.oiosi/addressing/Identifier.cs +++ b/src/dk.gov.oiosi/addressing/Identifier.cs @@ -216,6 +216,11 @@ namespace dk.gov.oiosi.addressing { return this.GetAsString().GetHashCode(); } + public override bool Equals(object obj) + { + return this.GetAsString().Equals(obj); + } + public override string ToString() { return this.GetAsString(); diff --git a/src/dk.gov.oiosi/communication/handlers/email/Inbox.cs b/src/dk.gov.oiosi/communication/handlers/email/Inbox.cs index b903f969..a5330d29 100644 --- a/src/dk.gov.oiosi/communication/handlers/email/Inbox.cs +++ b/src/dk.gov.oiosi/communication/handlers/email/Inbox.cs @@ -192,13 +192,14 @@ namespace dk.gov.oiosi.communication.handlers.email { logging.WCFLogger.Write(TraceEventType.Verbose, "Beginning to receive incoming mails on '" + this._serverConfiguration.ServerAddress + "' as user '" + this._serverConfiguration.UserName + "'"); SetState(InboxState.Starting); - try { - _asyncResult = _asyncReceive.BeginInvoke(null, null); - OnStartPolling.WaitOne(); - } - catch { - SetState(InboxState.Faulted); - } + try { + _asyncResult = _asyncReceive.BeginInvoke(null, null); + OnStartPolling.WaitOne(); + _asyncReceive.EndInvoke(_asyncResult); + } + catch { + SetState(InboxState.Faulted); + } } diff --git a/src/dk.gov.oiosi/communication/listener/Listener.cs b/src/dk.gov.oiosi/communication/listener/Listener.cs index 71119911..b80e08fe 100644 --- a/src/dk.gov.oiosi/communication/listener/Listener.cs +++ b/src/dk.gov.oiosi/communication/listener/Listener.cs @@ -337,14 +337,14 @@ namespace dk.gov.oiosi.communication.listener { /// protected void OverrideConfig(){ if (pListenerIdentity != null) { - - + + // Override certificate // TOOD: what is going on here? why only override the servicehost cridentials one time ? if (pListenerIdentity.ListenerCertificate != null && pServiceHost != null) { pServiceHost.Credentials.ServiceCertificate.Certificate = pListenerIdentity.ListenerCertificate.Certificate; } - else { + else if (pServiceHost != null) { pListenerIdentity.ListenerCertificate = new OcesX509Certificate(pServiceHost.Credentials.ServiceCertificate.Certificate); } diff --git a/src/dk.gov.oiosi/uddi/UddiLookupKey.cs b/src/dk.gov.oiosi/uddi/UddiLookupKey.cs index 1d258712..d1028e48 100644 --- a/src/dk.gov.oiosi/uddi/UddiLookupKey.cs +++ b/src/dk.gov.oiosi/uddi/UddiLookupKey.cs @@ -8,7 +8,7 @@ namespace dk.gov.oiosi.uddi { public class UddiLookupKey { - private Identifier identifier; + private readonly Identifier identifier; private UddiId serviceId; private Uri endpoint; private string profileConformanceClaim; diff --git a/src/dk.gov.oiosi/xml/schematron/SchematronValidator.cs b/src/dk.gov.oiosi/xml/schematron/SchematronValidator.cs index 9185760d..8d196499 100644 --- a/src/dk.gov.oiosi/xml/schematron/SchematronValidator.cs +++ b/src/dk.gov.oiosi/xml/schematron/SchematronValidator.cs @@ -181,46 +181,52 @@ namespace dk.gov.oiosi.xml.schematron { using (MemoryStream schematronResultMemoryStream = new MemoryStream()) { - using (MemoryStream xmlSchematronStylesheetMemoryStream = compiledXslt.Stream) - { - xmlSchematronStylesheetMemoryStream.Flush();//Adjust this if you want read your data - xmlSchematronStylesheetMemoryStream.Position = 0; + if (compiledXslt != null) + { + using (MemoryStream xmlSchematronStylesheetMemoryStream = compiledXslt.Stream) + { + xmlSchematronStylesheetMemoryStream.Flush();//Adjust this if you want read your data + xmlSchematronStylesheetMemoryStream.Position = 0; - Processor processor = new Processor(); - XsltCompiler compiler = processor.NewXsltCompiler(); - Serializer serializer = processor.NewSerializer(); + Processor processor = new Processor(); + XsltCompiler compiler = processor.NewXsltCompiler(); + Serializer serializer = processor.NewSerializer(); - try - { - XsltTransformer saxonTransformer = compiler.Compile(xmlSchematronStylesheetMemoryStream).Load(); + try + { + XsltTransformer saxonTransformer = compiler.Compile(xmlSchematronStylesheetMemoryStream).Load(); - // Load the XML document. Input to the build method is the document. - XdmNode docXdmNode = processor.NewDocumentBuilder().Build(xmlDocument); + // Load the XML document. Input to the build method is the document. + XdmNode docXdmNode = processor.NewDocumentBuilder().Build(xmlDocument); - // Set the root node of the source document to be the initial - // context node - saxonTransformer.InitialContextNode = docXdmNode; + // Set the root node of the source document to be the initial + // context node + saxonTransformer.InitialContextNode = docXdmNode; - // Init. the result object - serializer.SetOutputProperty(Serializer.INDENT, "yes"); - serializer.SetOutputProperty(Serializer.ENCODING, Encoding.UTF8.BodyName); + // Init. the result object + serializer.SetOutputProperty(Serializer.INDENT, "yes"); + serializer.SetOutputProperty(Serializer.ENCODING, Encoding.UTF8.BodyName); - serializer.SetOutputStream(schematronResultMemoryStream); + serializer.SetOutputStream(schematronResultMemoryStream); - // Run the transformation with result object as input param. - saxonTransformer.Run(serializer); - } - catch (Exception) - { - // easy debugging - throw; - } - finally - { - // close/dispose - serializer.Close(); + // Run the transformation with result object as input param. + saxonTransformer.Run(serializer); + } + catch (Exception) + { + // easy debugging + throw; + } + finally + { + // close/dispose + serializer.Close(); + } } - } + } else + { + throw new Exception("compiledXslt is null."); + } // convert the schematronResultMemoryStream, into a xmlDocument schematronResultMemoryStream.Position = 0; @@ -424,54 +430,60 @@ namespace dk.gov.oiosi.xml.schematron { using (MemoryStream schematronResultMemoryStream = new MemoryStream()) { - using (MemoryStream xmlSchematronStylesheetMemoryStream = compiledXslt.Stream) + if (compiledXslt != null) { - xmlSchematronStylesheetMemoryStream.Flush();//Adjust this if you want read your data - xmlSchematronStylesheetMemoryStream.Position = 0; + using (MemoryStream xmlSchematronStylesheetMemoryStream = compiledXslt.Stream) + { + xmlSchematronStylesheetMemoryStream.Flush();//Adjust this if you want read your data + xmlSchematronStylesheetMemoryStream.Position = 0; - Processor processor = new Processor(); - XsltCompiler compiler = processor.NewXsltCompiler(); - Uri uri = new Uri("file://" + compiledXslt.FileInfo.Directory.FullName); - - compiler.BaseUri = uri; - Serializer serializer = processor.NewSerializer(); + Processor processor = new Processor(); + XsltCompiler compiler = processor.NewXsltCompiler(); + Uri uri = new Uri("file://" + compiledXslt.FileInfo.Directory.FullName); - try - { - XsltTransformer saxonTransformer = compiler.Compile(xmlSchematronStylesheetMemoryStream).Load(); + compiler.BaseUri = uri; + Serializer serializer = processor.NewSerializer(); - // Load the XML document. Input to the build method is the document. - DocumentBuilder docBuilder = processor.NewDocumentBuilder(); - if (docBuilder.BaseUri == null) + try { - docBuilder.BaseUri = uri; - } + XsltTransformer saxonTransformer = compiler.Compile(xmlSchematronStylesheetMemoryStream).Load(); - XdmNode docXdmNode = docBuilder.Build(documentAsString.ToStream()); + // Load the XML document. Input to the build method is the document. + DocumentBuilder docBuilder = processor.NewDocumentBuilder(); + if (docBuilder.BaseUri == null) + { + docBuilder.BaseUri = uri; + } - // Set the root node of the source document to be the initial - // context node - saxonTransformer.InitialContextNode = docXdmNode; + XdmNode docXdmNode = docBuilder.Build(documentAsString.ToStream()); - // Init. the result object - serializer.SetOutputProperty(Serializer.INDENT, "yes"); - serializer.SetOutputProperty(Serializer.ENCODING, Encoding.UTF8.BodyName); + // Set the root node of the source document to be the initial + // context node + saxonTransformer.InitialContextNode = docXdmNode; - serializer.SetOutputStream(schematronResultMemoryStream); + // Init. the result object + serializer.SetOutputProperty(Serializer.INDENT, "yes"); + serializer.SetOutputProperty(Serializer.ENCODING, Encoding.UTF8.BodyName); - // Run the transformation with result object as input param. - saxonTransformer.Run(serializer); - } - catch (Exception) - { - // easy debugging - throw; - } - finally - { - // close/dispose - serializer.Close(); + serializer.SetOutputStream(schematronResultMemoryStream); + + // Run the transformation with result object as input param. + saxonTransformer.Run(serializer); + } + catch (Exception) + { + // easy debugging + throw; + } + finally + { + // close/dispose + serializer.Close(); + } } + } else + { + throw new Exception("compiledXslt is null."); } // convert the schematronResultMemoryStream, into a xmlDocument diff --git a/test/dk.gov.oiosi.test.integration/App.config b/test/dk.gov.oiosi.test.integration/App.config index d035bec7..d0e91daf 100644 --- a/test/dk.gov.oiosi.test.integration/App.config +++ b/test/dk.gov.oiosi.test.integration/App.config @@ -31,6 +31,7 @@ --> +
+ + + + + diff --git a/tool/AutomaticPasswordFiller/AutomaticPasswordFiller/Program.cs b/tool/AutomaticPasswordFiller/AutomaticPasswordFiller/Program.cs index 16d0899e..9029d80e 100644 --- a/tool/AutomaticPasswordFiller/AutomaticPasswordFiller/Program.cs +++ b/tool/AutomaticPasswordFiller/AutomaticPasswordFiller/Program.cs @@ -17,7 +17,7 @@ namespace dk.gov.oiosi.tool.AutomaticPasswordFiller throw new Exception("Require two parameter. First is the keepRunning file, and the second must be the password!"); } - new Program(args[0], args[1]); + Program program = new Program(args[0], args[1]); } public Program(string file, string password) -- GitLab From de9d07b317583dc9faf78eb2b92b4f014f7e7950 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 12 Sep 2022 09:38:28 +0200 Subject: [PATCH 2/4] NH-2558 Reverted some changed made in the App.config to test old and currently redundant integration test --- test/dk.gov.oiosi.test.integration/App.config | 171 +++++++++--------- 1 file changed, 81 insertions(+), 90 deletions(-) diff --git a/test/dk.gov.oiosi.test.integration/App.config b/test/dk.gov.oiosi.test.integration/App.config index d0e91daf..dafd9bf1 100644 --- a/test/dk.gov.oiosi.test.integration/App.config +++ b/test/dk.gov.oiosi.test.integration/App.config @@ -30,11 +30,10 @@ */ --> - -
- + + - - - + - - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - + + + + + + + + + + -- GitLab From a23ef050b9d3be3b5d9ac4ca86b4a4708c4029a8 Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 12 Sep 2022 09:43:02 +0200 Subject: [PATCH 3/4] NH-2558 Fixed spacing in app.config file changes --- test/dk.gov.oiosi.test.integration/App.config | 161 +++++++++--------- 1 file changed, 79 insertions(+), 82 deletions(-) diff --git a/test/dk.gov.oiosi.test.integration/App.config b/test/dk.gov.oiosi.test.integration/App.config index dafd9bf1..d035bec7 100644 --- a/test/dk.gov.oiosi.test.integration/App.config +++ b/test/dk.gov.oiosi.test.integration/App.config @@ -30,10 +30,10 @@ */ --> - - + + - - - + - - - - - - + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - + + + + + + + + -- GitLab From 535308a7945f31c11b019701c2f4bcb9ce11bb0b Mon Sep 17 00:00:00 2001 From: Simon Li Date: Tue, 13 Sep 2022 12:18:04 +0200 Subject: [PATCH 4/4] NH-2558 Fixed some issues with merge request and reverted a change that would crash local sonarqube scan --- src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs | 12 ++++++++++-- src/dk.gov.oiosi/addressing/Identifier.cs | 8 +++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs b/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs index 53d17af3..a12bd956 100644 --- a/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs +++ b/src/dk.gov.oiosi.raspProfile/DefaultDocumentTypes.cs @@ -115,8 +115,16 @@ namespace dk.gov.oiosi.raspProfile { DocumentTypeConfig documentType = documentTypeConfigDelegate(); DocumentTypeCollectionConfig configuration = ConfigurationHandler.GetConfigurationSection(); - configuration.AddDocumentType(documentType); - + if (configuration.ContainsDocumentTypeByValue(documentType)) + { + // already added + //Debug.Fail("already added"); + configuration.AddDocumentType(documentType); + } + else + { + configuration.AddDocumentType(documentType); + } } /// diff --git a/src/dk.gov.oiosi/addressing/Identifier.cs b/src/dk.gov.oiosi/addressing/Identifier.cs index 0d4eb6b1..d1b69151 100644 --- a/src/dk.gov.oiosi/addressing/Identifier.cs +++ b/src/dk.gov.oiosi/addressing/Identifier.cs @@ -218,7 +218,13 @@ namespace dk.gov.oiosi.addressing { public override bool Equals(object obj) { - return this.GetAsString().Equals(obj); + var ident = obj as Identifier; + if (ident != null) + { + return this.Equals(ident); + } + return false; + } public override string ToString() -- GitLab