Skip to content

Commit 139f016

Browse files
author
gauffininteractive
committed
* Added guards against reporting clients with incorrectly configured clocks when receiving new reports
* The global dashboard can now handle/ignore future dates
1 parent 147951d commit 139f016

File tree

8 files changed

+56
-6
lines changed

8 files changed

+56
-6
lines changed

src/Server/OneTrueError.Api/Web/Overview/Queries/GetOverviewApplicationResult.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ protected GetOverviewApplicationResult()
6969
public void AddValue(DateTime date, int value)
7070
{
7171
if (value < 0) throw new ArgumentOutOfRangeException("value");
72+
73+
//future date = malconfigured reporting clients.
74+
if (!_index.ContainsKey(date))
75+
return;
76+
7277
var indexPos = _index[date];
7378
Values[indexPos] = value;
7479
}

src/Server/OneTrueError.App.Tests/OneTrueError.App.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<Compile Include="ObjectExtensions.cs" />
112112
<Compile Include="Properties\AssemblyInfo.cs" />
113113
<Compile Include="ReposExtensions.cs" />
114+
<Compile Include="Web\Overview\Queries\GetOverviewApplicationResultTests.cs" />
114115
</ItemGroup>
115116
<ItemGroup />
116117
<ItemGroup>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using FluentAssertions;
7+
using OneTrueError.Api.Web.Overview.Queries;
8+
using Xunit;
9+
10+
namespace OneTrueError.App.Tests.Web.Overview.Queries
11+
{
12+
public class GetOverviewApplicationResultTests
13+
{
14+
15+
[Fact]
16+
public void ignore_future_dates_to_allow_malconfigured_clients()
17+
{
18+
19+
var sut = new GetOverviewApplicationResult("Label", DateTime.Today.AddDays(-30), 30);
20+
sut.AddValue(DateTime.Today.AddDays(1), 10);
21+
22+
}
23+
24+
[Fact]
25+
public void should_allow_dates_within_the_given_interval()
26+
{
27+
28+
var sut = new GetOverviewApplicationResult("hello", DateTime.Today.AddDays(-30), 31);
29+
sut.AddValue(DateTime.Today, 10);
30+
31+
sut.Values[sut.Values.Length - 1].Should().Be(10);
32+
}
33+
}
34+
}

src/Server/OneTrueError.SqlServer/Web/Overview/GetOverviewHandler.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ private string ApplicationIds
4949

5050
public async Task<GetOverviewResult> ExecuteAsync(GetOverview query)
5151
{
52+
if (query.NumberOfDays == 0)
53+
query.NumberOfDays = 30;
5254
var labels = CreateTimeLabels(query);
5355

5456
if (!ClaimsPrincipal.Current.FindAll(x => x.Type == OneTrueClaims.Application).Any())
@@ -61,8 +63,6 @@ public async Task<GetOverviewResult> ExecuteAsync(GetOverview query)
6163
};
6264
}
6365

64-
if (query.NumberOfDays == 0)
65-
query.NumberOfDays = 30;
6666
if (query.NumberOfDays == 1)
6767
return await GetTodaysOverviewAsync(query);
6868

@@ -76,7 +76,8 @@ public async Task<GetOverviewResult> ExecuteAsync(GetOverview query)
7676
(
7777
select Incidents.ApplicationId , cast(Incidents.CreatedAtUtc as date) as Date, count(Incidents.Id) as Count
7878
from Incidents
79-
where Incidents.CreatedAtUtc >= @minDate
79+
where Incidents.CreatedAtUtc >= @minDate
80+
AND Incidents.CreatedAtUtc <= GetUtcDate()
8081
AND Incidents.ApplicationId in ({ApplicationIds})
8182
group by Incidents.ApplicationId, cast(Incidents.CreatedAtUtc as date)
8283
) cte
@@ -139,6 +140,7 @@ private async Task GetStatSummary(GetOverview query, GetOverviewResult result)
139140
{
140141
cmd.CommandText = string.Format(@"select count(id) from incidents
141142
where CreatedAtUtc >= @minDate
143+
AND CreatedAtUtc <= GetUtcDate()
142144
AND Incidents.ApplicationId IN ({0})
143145
AND Incidents.IgnoreReports = 0
144146
AND Incidents.IsSolved = 0;
@@ -149,12 +151,14 @@ AND ApplicationId IN ({0})
149151
150152
select count(distinct emailaddress) from IncidentFeedback
151153
where CreatedAtUtc >= @minDate
154+
AND CreatedAtUtc <= GetUtcDate()
152155
AND ApplicationId IN ({0})
153156
AND emailaddress is not null
154157
AND DATALENGTH(emailaddress) > 0;
155158
156159
select count(*) from IncidentFeedback
157160
where CreatedAtUtc >= @minDate
161+
AND CreatedAtUtc <= GetUtcDate()
158162
AND ApplicationId IN ({0})
159163
AND Description is not null
160164
AND DATALENGTH(Description) > 0;", ApplicationIds);
@@ -208,6 +212,7 @@ private async Task<GetOverviewResult> GetTodaysOverviewAsync(GetOverview query)
208212
select Incidents.ApplicationId , DATEPART(HOUR, Incidents.CreatedAtUtc) as Date, count(Incidents.Id) as Count
209213
from Incidents
210214
where Incidents.CreatedAtUtc >= @minDate
215+
AND CreatedAtUtc <= GetUtcDate()
211216
AND Incidents.ApplicationId IN ({0})
212217
group by Incidents.ApplicationId, DATEPART(HOUR, Incidents.CreatedAtUtc)
213218
) cte

src/Server/OneTrueError.Web/Areas/Receiver/Helpers/SaveReportHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public async Task BuildReportAsync(string appKey, string signatureProvidedByTheC
5959
}
6060

6161
var report = DeserializeBody(reportBody);
62+
63+
//fix malconfigured clients
64+
if (report.CreatedAtUtc > DateTime.UtcNow)
65+
report.CreatedAtUtc = DateTime.UtcNow;
66+
6267
var internalDto = new ReceivedReportDTO
6368
{
6469
ApplicationId = application.Id,

src/Server/OneTrueError.Web/Content/ote_bootstrap.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ th { padding: 0; }
414414
@font-face {
415415
font-family: 'Glyphicons Halflings';
416416
src: url('fonts/glyphicons-halflings-regular.eot');
417-
src: url('fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('fonts/glyphicons-halflings-regular.woff') format('woff'), url('fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
417+
src: url('fonts/glyphicons-halflings-regular.eot?#iefix') format('embedded-opentype'), url('../fonts/glyphicons-halflings-regular.woff2') format('woff2'), url('fonts/glyphicons-halflings-regular.woff') format('woff'), url('fonts/glyphicons-halflings-regular.ttf') format('truetype'), url('fonts/glyphicons-halflings-regular.svg#glyphicons_halflingsregular') format('svg');
418418
}
419419

420420
.glyphicon {

src/Server/OneTrueError.Web/ViewModels/Incident/CloseViewModel.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Server/OneTrueError.Web/ViewModels/Incident/CloseViewModel.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)