public void SubdomainStatsMapperShouldMapCorrectly() { SubdomainStats domainStats = new SubdomainStats("ncsc.gov.uk", "testProvider", "digital.ncsc.gov.uk", 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 22); SubdomainStatsDto result = _subdomainStatsMapper.Map(domainStats, "testAlias", "testMarkdown"); Assert.That(result.Domain, Is.EqualTo("ncsc.gov.uk")); Assert.That(result.Provider, Is.EqualTo("testProvider")); Assert.That(result.Subdomain, Is.EqualTo("digital.ncsc.gov.uk")); Assert.That(result.SpfPassDkimPassNone, Is.EqualTo(0)); Assert.That(result.SpfPassDkimFailNone, Is.EqualTo(1)); Assert.That(result.SpfFailDkimPassNone, Is.EqualTo(2)); Assert.That(result.SpfFailDkimFailNone, Is.EqualTo(3)); Assert.That(result.SpfPassDkimPassQuarantine, Is.EqualTo(4)); Assert.That(result.SpfPassDkimFailQuarantine, Is.EqualTo(5)); Assert.That(result.SpfFailDkimPassQuarantine, Is.EqualTo(6)); Assert.That(result.SpfFailDkimFailQuarantine, Is.EqualTo(7)); Assert.That(result.SpfPassDkimPassReject, Is.EqualTo(8)); Assert.That(result.SpfPassDkimFailReject, Is.EqualTo(9)); Assert.That(result.SpfFailDkimPassReject, Is.EqualTo(10)); Assert.That(result.SpfFailDkimFailReject, Is.EqualTo(11)); Assert.That(result.TotalEmails, Is.EqualTo(20)); Assert.That(result.FailSpfTotal, Is.EqualTo(21)); Assert.That(result.FailDkimTotal, Is.EqualTo(22)); Assert.That(result.ProviderAlias, Is.EqualTo("testAlias")); Assert.That(result.ProviderMarkdown, Is.EqualTo("testMarkdown")); }
public SubdomainStatsDto Map(SubdomainStats subdomainStats, string providerAlias, string providerMarkdown) { return(new SubdomainStatsDto( subdomainStats.Domain, subdomainStats.Provider, subdomainStats.Subdomain, subdomainStats.SpfPassDkimPassNone, subdomainStats.SpfPassDkimFailNone, subdomainStats.SpfFailDkimPassNone, subdomainStats.SpfFailDkimFailNone, subdomainStats.SpfPassDkimPassQuarantine, subdomainStats.SpfPassDkimFailQuarantine, subdomainStats.SpfFailDkimPassQuarantine, subdomainStats.SpfFailDkimFailQuarantine, subdomainStats.SpfPassDkimPassReject, subdomainStats.SpfPassDkimFailReject, subdomainStats.SpfFailDkimPassReject, subdomainStats.SpfFailDkimFailReject, subdomainStats.TotalEmails, subdomainStats.FailSpfTotal, subdomainStats.FailDkimTotal, providerAlias, providerMarkdown)); }
public async Task <SubdomainStatsResult> GetSubdomainStats(string domain, string provider, DateTime startDate, DateTime endDate, int page, int pageSize, string categoryFilter = null) { var sqlBuilder = new SqlBuilder() .AddAggregateReportDefaults() .AddCategoryFilter(categoryFilter); string connectionString = await _connectionInfoAsync.GetConnectionStringAsync(); MySqlParameter[] parameters = { new MySqlParameter("domain", domain), new MySqlParameter("provider", provider), new MySqlParameter("startDate", startDate.ToString("yyyy-MM-dd")), new MySqlParameter("endDate", endDate.ToString("yyyy-MM-dd")), new MySqlParameter("offset", (page - 1) * pageSize), new MySqlParameter("pageSize", pageSize), }; SubdomainStats domainStats = null; string selectSingleProviderStatsCommandText = sqlBuilder.Build(AggregateReportDaoV2.SelectSingleProviderStats); using (var reader = await MySqlHelper.ExecuteReaderAsync(connectionString, selectSingleProviderStatsCommandText, parameters)) { while (await reader.ReadAsync()) { domainStats = CreateSubdomainStats(reader); break; } } List <SubdomainStats> subdomainStats = new List <SubdomainStats>(); string selectSubdomainStatsCommandText = sqlBuilder.Build(AggregateReportDaoV2.SelectSubdomainStats); using (var reader = await MySqlHelper.ExecuteReaderAsync(connectionString, selectSubdomainStatsCommandText, parameters)) { while (await reader.ReadAsync()) { subdomainStats.Add(CreateSubdomainStats(reader)); } } string selectSubdomainCountCommandText = sqlBuilder.Build(AggregateReportDaoV2.SelectSubdomainCount); object subdomainCount = await MySqlHelper.ExecuteScalarAsync(connectionString, selectSubdomainCountCommandText, parameters); return(new SubdomainStatsResult(domainStats, subdomainStats, ParseInt(subdomainCount))); }
public async Task CheckGetSubdomainStatsDtoReturnsSubdomainStatsDto() { string domain = "ncsc.gov.uk"; string subdomain = "digital.ncsc.gov.uk"; int totalCount = 20; string provider = "testProvider"; string alias = "testAlias"; string markdown = "testMarkdown"; A.CallTo(() => _providerDetailsProvider.GetProviderAliasIn(alias)) .Returns(provider); A.CallTo(() => _providerDetailsProvider.GetProviderAliasOut(provider)) .Returns(alias); A.CallTo(() => _providerDetailsProvider.GetProviderMarkdown(provider)) .Returns(markdown); SubdomainStats domainStats = new SubdomainStats(domain, provider, subdomain, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 22); SubdomainStatsResult subdomainStatsResult = new SubdomainStatsResult(domainStats, new List <SubdomainStats>() { domainStats }, totalCount); A.CallTo(() => _aggregateReportApiDao.GetSubdomainStats(domain, provider, A <DateTime> ._, A <DateTime> ._, A <int> ._, A <int> ._, null)) .Returns(Task.FromResult(subdomainStatsResult)); SubdomainStatsDto subdomainStatsDto = new SubdomainStatsDto(domain, provider, subdomain, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 20, 21, 22, alias, markdown); A.CallTo(() => _subdomainStatsMapper.Map(domainStats, alias, markdown)) .Returns(subdomainStatsDto); SubdomainStatsDtoResult subdomainStatsDtoResults = await _aggregateReportService.GetSubdomainStatsDto(domain, alias, DateTime.MinValue, DateTime.MaxValue, 0, 0); Assert.AreSame(subdomainStatsDto, subdomainStatsDtoResults.DomainStatsDto); Assert.AreSame(subdomainStatsDto, subdomainStatsDtoResults.SubdomainStatsDto[0]); Assert.AreEqual(totalCount, subdomainStatsDtoResults.TotalCount); }
protected override void OnActionExecuting(ActionExecutingContext filterContext) { accountHostname = Request.Headers["Host"]; #if DEBUG if (accountHostname == "local") { filterContext.Result = new RedirectResult(GeneralConstants.HTTP_HOST + Request.Url.PathAndQuery); return; } #else if (accountHostname == null || accountHostname == "tradelr.com" || accountHostname == "98.126.29.28") { filterContext.Result = new RedirectResult(GeneralConstants.HTTP_HOST + Request.Url.PathAndQuery); return; } #endif ////////////////////// subdomain check /////////////////////////////// #if DEBUG if (accountHostname.EndsWith("localhost")) #else if (accountHostname.EndsWith("tradelr.com")) #endif { ////////////// handles case for subdomains string[] host = accountHostname.Split('.'); string hostSegment = ""; // not on a subdomain if (!Utility.IsOnSubdomain(host, out hostSegment)) { return; } MASTERdomain = db.GetSubDomain(hostSegment); // ensure that incoming host name matches x.tradelr.com. // this is to handle www.x.tradelr.com returning www.tradelr.com if (MASTERdomain != null) { #if DEBUG var validHost = string.Format("{0}.localhost", hostSegment); #else var validHost = string.Format("{0}.tradelr.com", hostSegment); #endif if (validHost != accountHostname) { filterContext.Result = new RedirectResult(string.Format("{0}://{1}", Request.Url.Scheme, validHost)); return; } } } else { ////////////////// handles case for custom subdomains MASTERdomain = db.GetCustomHostname(accountHostname); } if (MASTERdomain == null) { // subdomain does not exist filterContext.RequestContext.HttpContext.Response.StatusCode = HttpStatusCode.NotFound.ToInt(); filterContext.Result = new RedirectResult(GeneralConstants.HTTP_HOST); return; } /////////// SUBDOMAIN EXISTS accountLimits = MASTERdomain.accountType.ToEnum<AccountPlanType>().ToAccountLimit(); accountSubdomainName = MASTERdomain.name; subdomainid = MASTERdomain.id; stats = MASTERdomain.ToSubdomainStats(); IsStoreEnabled = MASTERdomain.IsStoreEnabled(); baseviewmodel.storeEnabled = IsStoreEnabled; subdomainFlags = (SubdomainFlags) MASTERdomain.flags; if ((MASTERdomain.flags & (int)SubdomainFlags.OFFLINE_ENABLED) != 0) { var browsertype = Request.Browser.Type.ToLower(); if (browsertype.Contains("safari") || browsertype.Contains("chrome")) { baseviewmodel.manifestFile = "manifest=\"/manifest\""; } } baseviewmodel.orgName = MASTERdomain.organisation.name; baseviewmodel.shopUrl = accountHostname; /////////////////////// session check /////////////////////////////// token = Request.RequestContext.HttpContext.Items["token"] as TradelrSecurityToken; if (token == null) { GetAuthCookie(); } if (token != null) { Request.RequestContext.HttpContext.Items["token"] = token; sessionid = token.UserID; var usr = db.GetUserById(sessionid.Value, subdomainid.Value); if (usr != null) { baseviewmodel.notifications = usr.ToNotification(MASTERdomain.trialExpired).ToJson(); } role = token.UserRole.ToEnum<UserRole>(); baseviewmodel.role = role; permission = token.Permission.ToEnum<UserPermission>(); baseviewmodel.permission = permission; } base.OnActionExecuting(filterContext); }