public IChallengeHandler GetHandler(Challenge c, IReadOnlyDictionary <string, object> initParams) { var h = new IisChallengeHandler(); if (initParams == null) { initParams = new Dictionary <string, object>(); } // Required params if (!initParams.ContainsKey(WEB_SITE_REF.Name)) { throw new KeyNotFoundException($"missing required parameter [{WEB_SITE_REF.Name}]"); } h.WebSiteRef = (string)initParams[WEB_SITE_REF.Name]; // Optional params if (initParams.ContainsKey(OVERRIDE_SITE_ROOT.Name)) { h.OverrideSiteRoot = (string)initParams[OVERRIDE_SITE_ROOT.Name]; } if (initParams.ContainsKey(SKIP_LOCAL_WEB_CONFIG.Name)) { h.SkipLocalWebConfig = (bool)initParams[SKIP_LOCAL_WEB_CONFIG.Name]; } return(h); }
public void TestHandleCreateAndCleanUpFiles() { var r = new Random(); var bn = new byte[10]; var bv = new byte[10]; r.NextBytes(bn); r.NextBytes(bv); var rn = BitConverter.ToString(bn); var rv = BitConverter.ToString(bv); var c = new HttpChallenge(AcmeProtocol.CHALLENGE_TYPE_HTTP, new HttpChallengeAnswer()) { Token = "FOOBAR", FileUrl = $"http://foobar.acmetesting.zyborg.io/utest/{rn}", FilePath = $"utest/{rn}", FileContent = rv, }; var awsParams = new AwsCommonParams(); awsParams.InitParams(_handlerParams); var p = GetProvider(); using (var h = p.GetHandler(c, _handlerParams)) { var sites = IisChallengeHandler.ListHttpWebSites(); Assert.IsNotNull(sites); var site = sites.First(x => x.SiteName == _handlerParams.WebSiteRef); Assert.IsNotNull(site); var fullPath = Environment.ExpandEnvironmentVariables( Path.Combine(site.SiteRoot, c.FilePath)); // Assert test file does not exist Assert.IsFalse(File.Exists(fullPath)); // Create the record... h.Handle(c); // ...and assert it does exist Assert.IsTrue(File.Exists(fullPath)); Assert.AreEqual(c.FileContent, File.ReadAllText(fullPath)); // Clean up the record... h.CleanUp(c); // ...and assert it does not exist once more Assert.IsFalse(File.Exists(fullPath)); } }
public IChallengeHandler GetHandler(Challenge c, IReadOnlyDictionary<string, object> initParams) { var h = new IisChallengeHandler(); if (initParams == null) initParams = new Dictionary<string, object>(); // Required params if (!initParams.ContainsKey(WEB_SITE_REF.Name)) throw new KeyNotFoundException($"missing required parameter [{WEB_SITE_REF.Name}]"); h.WebSiteRef = (string)initParams[WEB_SITE_REF.Name]; // Optional params if (initParams.ContainsKey(OVERRIDE_SITE_ROOT.Name)) h.OverrideSiteRoot = (string)initParams[OVERRIDE_SITE_ROOT.Name]; if (initParams.ContainsKey(SKIP_LOCAL_WEB_CONFIG.Name)) h.SkipLocalWebConfig = (bool)initParams[SKIP_LOCAL_WEB_CONFIG.Name]; return h; }