internal Host(string name, IProxyService proxyService, IHostConfigurationManager hostConfigurationManager, IUrlManipulationService urlManipulationService) { _configurationManager = hostConfigurationManager; _urlManipulation = urlManipulationService; _proxyService = proxyService; _settings = _configurationManager.GetOptions(name); ValidateSettings(_settings); }
public void OauthClient_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNull(h.OAuth.OauthClientId); }
public void NetworkNull_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNull(h.NetworkCredentials); }
public void Name_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNull(h.Name); }
public void local_auth_is_not_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNotNull(h.OAuth.LocalUserCreation); }
public void local_auth_is_not_enabled() { HostConfiguration h = new HostConfiguration(); Assert.IsFalse(h.OAuth.LocalUserCreation.Enabled); }
public void oauth_cookie() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.OAuth.CookieName.Equals("CS-SDK-User", StringComparison.CurrentCultureIgnoreCase)); }
public void anonymous_user() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.OAuth.AnonymousUsername.Equals("Anonymous", StringComparison.CurrentCultureIgnoreCase)); }
public void default_language() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.OAuth.DefaultLanguageKey.Equals("en-us", StringComparison.CurrentCultureIgnoreCase)); }
public void sso_sync_cookie() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.SSO.SynchronizationCookieName.Equals("EvolutionSync", StringComparison.CurrentCultureIgnoreCase)); }
public void Url_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNull(h.CommunityServerUrl); }
public void sso_is_not_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNotNull(h.SSO); }
public void sso_is_not_enabled() { HostConfiguration h = new HostConfiguration(); Assert.IsFalse(h.SSO.Enabled); }
public void Oauth_is_not_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNotNull(h.OAuth); }
public void oauth_callback() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.OAuth.OauthCallbackUrl.Equals("~/oauth.ashx", StringComparison.CurrentCultureIgnoreCase)); }
public void Id_null() { HostConfiguration h = new HostConfiguration(); Assert.IsNull(h.Id); }
private HostConfiguration Read(string name) { var configData = GetConfigData(); if (string.IsNullOrEmpty(configData)) throw new ConfigurationErrorsException("Invalid configuration data"); HostConfiguration config = new HostConfiguration(); XDocument doc = XDocument.Parse(configData); var hostNode = doc.Root.Elements("host").Where(e => e.Attribute("name").Value == name).FirstOrDefault(); if(hostNode == null) throw new ConfigurationErrorsException("No host has been defined in confiuration with the name '" + name + "'"); if (hostNode.Attribute("id") != null) config.Id = Guid.Parse(hostNode.Attribute("id").Value); if (hostNode.Attribute("name") != null) config.Name = hostNode.Attribute("name").Value; if (hostNode.Attribute("communityServerUrl") != null) config.CommunityServerUrl = hostNode.Attribute("communityServerUrl").Value; string networkUser = null; string networkPassword = null; string networkDomain = null; if (hostNode.Attribute("networkUsername") != null) networkUser = hostNode.Attribute("networkUsername").Value; if (hostNode.Attribute("networkPassword") != null) networkPassword = hostNode.Attribute("networkPassword").Value; if (hostNode.Attribute("networkDomain") != null) networkDomain = hostNode.Attribute("networkDomain").Value; if (!string.IsNullOrWhiteSpace(networkUser) && !string.IsNullOrWhiteSpace(networkPassword)) { config.NetworkCredentials = new NetworkCredential(networkUser,networkPassword); if (!string.IsNullOrWhiteSpace(networkDomain)) config.NetworkCredentials.Domain = networkDomain; } var proxyNode = hostNode.Element("remoteProxy"); if (proxyNode != null) { if (proxyNode.Attribute("enabled") != null) config.Proxy.Enabled = bool.Parse(proxyNode.Attribute("enabled").Value); if (proxyNode.Attribute("callbackUrl") != null) config.Proxy.CallbackUrl = proxyNode.Attribute("callbackUrl").Value; } var sso = hostNode.Element("sso"); if (sso != null) { if (sso.Attribute("enabled") != null) config.SSO.Enabled = bool.Parse(sso.Attribute("enabled").Value); if (sso.Attribute("synchronizationCookieName") != null) config.SSO.SynchronizationCookieName = sso.Attribute("synchronizationCookieName").Value; } var oauthNode = hostNode.Element("oauth"); if (oauthNode != null) { if (oauthNode.Attribute("clientId") != null) config.OAuth.OauthClientId = oauthNode.Attribute("clientId").Value; if (oauthNode.Attribute("clientSecret") != null) config.OAuth.OauthSecret = oauthNode.Attribute("clientSecret").Value; if (oauthNode.Attribute("callbackUrl") != null) config.OAuth.OauthCallbackUrl = oauthNode.Attribute("callbackUrl").Value; if (oauthNode.Attribute("cookieName") != null) config.OAuth.CookieName = oauthNode.Attribute("cookieName").Value; if (oauthNode.Attribute("defaultLanguage") != null) config.OAuth.DefaultLanguageKey = oauthNode.Attribute("defaultLanguage").Value; if (oauthNode.Attribute("anonymousUsername") != null) config.OAuth.AnonymousUsername = oauthNode.Attribute("anonymousUsername").Value; var localAuth = oauthNode.Element("localAuthentication"); if (localAuth != null) { if (localAuth.Attribute("enabled") != null) config.OAuth.LocalUserCreation.Enabled = bool.Parse(localAuth.Attribute("enabled").Value); if (localAuth.Attribute("membershipAdministrationUsername") != null) config.OAuth.LocalUserCreation.MembershipAdministrationUserName = localAuth.Attribute("membershipAdministrationUsername").Value; } } return config; }
public void local_auth_admin_user() { HostConfiguration h = new HostConfiguration(); Assert.IsTrue(h.OAuth.LocalUserCreation.MembershipAdministrationUserName.Equals("admin",StringComparison.CurrentCultureIgnoreCase)); }
/// <summary> /// Checks for valid host settings as read by the configuration file /// </summary> /// <param name="settings"></param> private void ValidateSettings(HostConfiguration settings) { if (String.IsNullOrEmpty(settings.OAuth.OauthCallbackUrl)) throw new ConfigurationErrorsException("OauthCallbackUrl must be specified"); if (String.IsNullOrEmpty(settings.CommunityServerUrl)) throw new ConfigurationErrorsException("CommunityRootUrl must be specified"); if (String.IsNullOrEmpty(settings.OAuth.OauthClientId)) throw new ConfigurationErrorsException("OauthClientId must be specified"); if (String.IsNullOrEmpty(settings.OAuth.OauthSecret)) throw new ConfigurationErrorsException("OauthSecret must be specified"); if (String.IsNullOrEmpty(settings.OAuth.CookieName)) throw new ConfigurationErrorsException("CookieName must be specified"); if (settings.OAuth.LocalUserCreation.Enabled) { if (String.IsNullOrEmpty(settings.OAuth.LocalUserCreation.MembershipAdministrationUserName)) throw new ConfigurationErrorsException("MembershipAdministrationUserName must be specified when UseLocalAuthentication is true"); } if (settings.OAuth.LocalUserCreation.Enabled && settings.SSO.Enabled) { if (String.IsNullOrEmpty(settings.SSO.SynchronizationCookieName)) throw new ConfigurationErrorsException("SynchronizationCookieName must be specified when EnableSSO is true"); } }
public void Setup() { var fileMock = new Mock<IConfigurationFile>(); fileMock.Setup(m => m.GetConfigurationData()).Returns(() => _data); var manager = new HostConfigurationManager(new Mock<IRestCache>().Object, fileMock.Object); _config = manager.GetOptions("site"); }