diff --git a/doc/xmlConfigFile.md b/doc/xmlConfigFile.md index a6dcec3..72cc911 100644 --- a/doc/xmlConfigFile.md +++ b/doc/xmlConfigFile.md @@ -159,12 +159,20 @@ For servers requiring authentication some parameters must be specified depending The parameter “unsecureAuth” is only effective when the transfer protocol is HTTP - unencrypted data transfer. This is a security vulnerability because the credentials are send in clear text! For a SSPI authentication this is not relevant because the authentication tokens are encrypted. For target servers using the HTTPS transfer protocol it is necessary, that the CA which issued the server certificate is trusted by the client. This is normally the situation when the server ist located in the Internet. When an organisation is using a self issued CA for the intranet this probably is not the case. In this case it is necessary to import the CA to the Certificate MMC of the Windows client. Have a look to the instructions on this [site](https://msdn.microsoft.com/de-de/library/system.net.credentialcache.defaultcredentials(v=vs.85).aspx). The self issued CA must be imported to the Trusted Root Certification Authorities for the computer. -``` + +By default, the `download` command does not fail the service startup if the operation fails (e.g. `from` is not available). +In order to force the download failure in such case, it is possible to specify the `failOnError` boolean attribute. + +Examples: + +```xml + + - + /// Downloads the requested file and puts it to the specified target. + /// + /// + /// Download failure. FailOnError flag should be processed outside. + /// public void Perform() { WebRequest req = WebRequest.Create(From); @@ -106,6 +123,15 @@ namespace winsw File.Move(To + ".tmp", To); } + /// + /// Produces the XML configuuration entry. + /// + /// XML String for the configuration file + public String toXMLConfig() + { + return ""; + } + private static void CopyStream(Stream i, Stream o) { byte[] buf = new byte[8192]; diff --git a/src/Test/winswTests/DownloadTest.cs b/src/Test/winswTests/DownloadTest.cs new file mode 100644 index 0000000..2160434 --- /dev/null +++ b/src/Test/winswTests/DownloadTest.cs @@ -0,0 +1,56 @@ +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.Text; +using winsw; +using winswTests.Util; + +namespace winswTests +{ + [TestFixture] + class DownloadTest + { + private const string From = "http://www.nosuchhostexists.foo.myorg/foo.xml"; + private const string To = "%BASE%\\foo.xml"; + + /// + /// Ensures that the fail-on-error field is being processed correctly. + /// + [TestCase(true)] + [TestCase(false)] + public void Download_FailOnError(bool failOnError) + { + Download d = new Download(From, To, failOnError); + + var sd = ConfigXmlBuilder.create() + .WithDownload(d) + .ToServiceDescriptor(true); + + var loaded = getSingleEntry(sd); + Assert.That(loaded.From, Is.EqualTo(From)); + Assert.That(loaded.To, Is.EqualTo(To)); + Assert.That(loaded.FailOnError, Is.EqualTo(failOnError), "Unexpected FailOnError value"); + } + + /// + /// Ensures that the fail-on-error field is being processed correctly. + /// + [Test] + public void Download_FailOnError_Undefined() + { + var sd = ConfigXmlBuilder.create() + .WithRawEntry("") + .ToServiceDescriptor(true); + + var loaded = getSingleEntry(sd); + Assert.That(loaded.FailOnError, Is.False); + } + + private Download getSingleEntry(ServiceDescriptor sd) + { + var downloads = sd.Downloads.ToArray(); + Assert.That(downloads.Length, Is.EqualTo(1), "Service Descriptor is expected to have only one entry"); + return downloads[0]; + } + } +} diff --git a/src/Test/winswTests/Util/ConfigXmlBuilder.cs b/src/Test/winswTests/Util/ConfigXmlBuilder.cs index 9fc75f4..bce54fd 100644 --- a/src/Test/winswTests/Util/ConfigXmlBuilder.cs +++ b/src/Test/winswTests/Util/ConfigXmlBuilder.cs @@ -119,5 +119,10 @@ namespace winswTests.Util return this; } + + public ConfigXmlBuilder WithDownload(Download download) + { + return WithRawEntry(download.toXMLConfig()); + } } } diff --git a/src/Test/winswTests/winswTests.csproj b/src/Test/winswTests/winswTests.csproj index 27f3c39..3f82234 100644 --- a/src/Test/winswTests/winswTests.csproj +++ b/src/Test/winswTests/winswTests.csproj @@ -56,6 +56,7 @@ +