Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/rdmp 19 more codescanning #1828

Draft
wants to merge 30 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
bc7d517
attempt fix
JFriel May 16, 2024
a31c368
add null checking
JFriel May 16, 2024
888d930
Merge branch 'develop' of https://github.com/HicServices/RDMP into ta…
JFriel May 16, 2024
839a70c
tidy up
JFriel May 16, 2024
abaf6d4
fix typos
JFriel May 16, 2024
1762a31
fix some codeql
JFriel May 16, 2024
d54b628
Merge branch 'task/RDMP-184-investigate-slow-start' of https://github…
JFriel May 16, 2024
3a3246b
update codeql
JFriel May 16, 2024
88ac08b
fix dot
JFriel May 16, 2024
a5186d8
additional codeql
JFriel May 16, 2024
cb8ce70
codeql fixes
JFriel May 16, 2024
a571e22
more codeql
JFriel May 16, 2024
31f8e53
Merge branch 'develop' of https://github.com/HicServices/RDMP into ta…
JFriel May 21, 2024
0bbc96b
misc updates
JFriel May 21, 2024
74ce236
misc updates
JFriel May 21, 2024
74cf9eb
few tidy ups
JFriel May 21, 2024
f2a9167
more
JFriel May 24, 2024
86842c0
more codeql
JFriel May 24, 2024
4968ef5
fix build
JFriel May 24, 2024
fa1b2cc
more exceptions
JFriel May 24, 2024
17cfa06
code ql updates
JFriel May 24, 2024
eb8967b
more rules
JFriel May 27, 2024
683af04
Merge branch 'develop' of https://github.com/HicServices/RDMP into ta…
JFriel May 27, 2024
7d3574c
minor updates
JFriel May 27, 2024
34cd10a
Update codeql.yml
JFriel May 27, 2024
44e1762
updates
JFriel May 27, 2024
5e15471
fix rule
JFriel May 27, 2024
01202a1
Merge branch 'task/RDMP-19-more-codescanning' of https://github.com/H…
JFriel May 27, 2024
bc9860f
minor updates
JFriel May 28, 2024
ed2c02e
more ignore
JFriel May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 33 additions & 1 deletion .github/configs/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,39 @@ paths-ignore:
- "**/obj/**"
- "**/bin/**"
- "**/*.Designer.cs"
- "*.g.cs"

query-filters:
- exclude:
id: cs/catch-of-all-exceptions
id: cs/catch-of-all-exceptions
- exclude:
id: cs/useless-assignment-to-local
- exclude:
id: cs/local-not-disposed
- exclude:
id: cs/missed-readonly-modifier
- exclude:
id: cs/dereferenced-value-may-be-null
- exclude:
id: cs/string-concatenation-in-loop
- exclude:
id: cs/useless-cast-to-self
- exclude:
id: cs/useless-upcast
- exclude:
id: cs/class-missing-equals
- exclude:
id: cs/reference-equality-with-object
- exclude:
id: cs/virtual-call-in-constructor
- exclude:
id: cs/linq/missed-where
- exclude:
id: cs/linq/missed-select
- exclude:
id: cs/nested-if-statements
- exclude:
id: cs/missed-ternary-operator
- exclude:
id: cs/call-to-gc

1 change: 0 additions & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
languages: ${{ matrix.language }}
queries: +security-and-quality
config-file: ./.github/configs/codeql.yml

- name: Build
run: dotnet build

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ public void Close()

public override string ToString() => Tab.TabText;

public override bool Equals(object obj) =>
obj is TabNavigation navigation &&
EqualityComparer<DockContent>.Default.Equals(Tab, navigation.Tab);
public override bool Equals(object obj) => obj.GetType() == typeof(TabNavigation) && EqualityComparer<DockContent>.Default.Equals(Tab, ((TabNavigation)obj).Tab);

public override int GetHashCode()
{
Expand Down
26 changes: 12 additions & 14 deletions Rdmp.Core.Tests/Curation/Integration/CommitInProgressTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,24 @@ public void CommitInProgress_TestCancellation()
Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.NoChanges),
"We just created this Catalogue, how can db copy be different?!");

var start = new CommitInProgress(RepositoryLocator, new CommitInProgressSettings(c)
using (var start = new CommitInProgress(RepositoryLocator, new CommitInProgressSettings(c)
{
UseTransactions = true
});

// there is a CommitInProgress on c so db should not have
c.Name = "abadaba";
c.IsDeprecated = true;

Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.DatabaseCopyDifferent),
"We have local changes");
}))
{
// there is a CommitInProgress on c so db should not have
c.Name = "abadaba";
c.IsDeprecated = true;

c.SaveToDatabase();
Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.DatabaseCopyDifferent),
"We have local changes");

Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.NoChanges),
"Should be saved inside the transaction");
c.SaveToDatabase();

// abandon the commit
start.Dispose();
Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.NoChanges),
"Should be saved inside the transaction");

}
Assert.That(c.HasLocalChanges().Evaluation, Is.EqualTo(ChangeDescription.DatabaseCopyDifferent),
"With transaction rolled back the Catalogue should now no longer match db state - i.e. be unsaved");

Expand Down
10 changes: 10 additions & 0 deletions Rdmp.Core.Tests/Curation/Integration/LookupTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public void CreateLookup_linkWithSelfThrowsException()
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -89,6 +90,7 @@ public void CreateLookup_linkWithSelfThrowsException()
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -97,6 +99,7 @@ public void CreateLookup_linkWithSelfThrowsException()
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -105,6 +108,7 @@ public void CreateLookup_linkWithSelfThrowsException()
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}
}

Expand All @@ -114,6 +118,7 @@ public void CreateLookup_linkWithSelfThrowsException()
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}
}

Expand Down Expand Up @@ -162,6 +167,7 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo)
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -170,6 +176,7 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo)
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -178,6 +185,7 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo)
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -186,6 +194,7 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo)
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}

try
Expand All @@ -194,6 +203,7 @@ public void CreateLookup_linkWithOtherTable(bool memoryRepo)
}
catch (Exception)
{
Console.WriteLine("Unable To Delete child");
}
}
}
Expand Down
59 changes: 32 additions & 27 deletions Rdmp.Core.Tests/Curation/Unit/AggregateConfigurationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,52 @@ internal class AggregateConfigurationTests : UnitTests
[Test]
public void TestStripZeroSeries_EmptyTable()
{
var dt = new DataTable();
dt.Columns.Add("col1");
dt.Columns.Add("col2");
using (var dt = new DataTable())

UserSettings.IncludeZeroSeriesInGraphs = false;
{
dt.Columns.Add("col1");
dt.Columns.Add("col2");

UserSettings.IncludeZeroSeriesInGraphs = false;

// empty tables should not get nuked
AggregateConfiguration.AdjustGraphDataTable(dt);
Assert.That(dt.Columns, Has.Count.EqualTo(2));
// empty tables should not get nuked
AggregateConfiguration.AdjustGraphDataTable(dt);
Assert.That(dt.Columns, Has.Count.EqualTo(2));
}

dt.Dispose();
}


[TestCase(true)]
[TestCase(false)]
public void TestStripZeroSeries_Nulls(bool includeZeroSeries)
{
var dt = new DataTable();
dt.Columns.Add("date");
dt.Columns.Add("col1");
dt.Columns.Add("col2");
using (var dt = new DataTable())
{
dt.Columns.Add("date");
dt.Columns.Add("col1");
dt.Columns.Add("col2");

dt.Rows.Add("2001", 0, 12);
dt.Rows.Add("2002", null, 333);
dt.Rows.Add("2001", 0, 12);
dt.Rows.Add("2002", null, 333);

UserSettings.IncludeZeroSeriesInGraphs = includeZeroSeries;
UserSettings.IncludeZeroSeriesInGraphs = includeZeroSeries;

AggregateConfiguration.AdjustGraphDataTable(dt);
AggregateConfiguration.AdjustGraphDataTable(dt);

if (includeZeroSeries)
{
Assert.That(dt.Columns, Has.Count.EqualTo(3));
}
else
{
// col1 should have been gotten rid of
Assert.That(dt.Columns, Has.Count.EqualTo(2));
dt.Columns.Contains("date");
dt.Columns.Contains("col2");
if (includeZeroSeries)
{
Assert.That(dt.Columns, Has.Count.EqualTo(3));
}
else
{
// col1 should have been gotten rid of
Assert.That(dt.Columns, Has.Count.EqualTo(2));
dt.Columns.Contains("date");
dt.Columns.Contains("col2");
}
}

dt.Dispose();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,36 @@ public void ExtractionDestination_FloatRounding(bool lotsOfDecimalPlaces)
{
var dest = new ExecuteDatasetExtractionFlatFileDestination();

var dt = new DataTable();
dt.Columns.Add("Floats", typeof(decimal));
using (var dt = new DataTable())
{

dt.Rows.Add(Math.PI);
dt.Columns.Add("Floats", typeof(decimal));

var lm = new LogManager(new DiscoveredServer(UnitTestLoggingConnectionString));
lm.CreateNewLoggingTaskIfNotExists("ExtractionDestination_FloatRounding");
dt.Rows.Add(Math.PI);

var dli = lm.CreateDataLoadInfo("ExtractionDestination_FloatRounding",
nameof(ExecuteDatasetExtractionFlatFileDestinationTests), "test", "", true);
var lm = new LogManager(new DiscoveredServer(UnitTestLoggingConnectionString));
lm.CreateNewLoggingTaskIfNotExists("ExtractionDestination_FloatRounding");

if (_request.QueryBuilder == null) _request.GenerateQueryBuilder();
dest.RoundFloatsTo = lotsOfDecimalPlaces ? 10 : 2;
var dli = lm.CreateDataLoadInfo("ExtractionDestination_FloatRounding",
nameof(ExecuteDatasetExtractionFlatFileDestinationTests), "test", "", true);

dest.PreInitialize(_request, ThrowImmediatelyDataLoadEventListener.Quiet);
dest.PreInitialize(_project, ThrowImmediatelyDataLoadEventListener.Quiet);
dest.PreInitialize((DataLoadInfo)dli, ThrowImmediatelyDataLoadEventListener.Quiet);
if (_request.QueryBuilder == null) _request.GenerateQueryBuilder();
dest.RoundFloatsTo = lotsOfDecimalPlaces ? 10 : 2;

dest.ProcessPipelineData(dt, ThrowImmediatelyDataLoadEventListener.Quiet, new GracefulCancellationToken());
dest.Dispose(ThrowImmediatelyDataLoadEventListener.Quiet, null);
dest.PreInitialize(_request, ThrowImmediatelyDataLoadEventListener.Quiet);
dest.PreInitialize(_project, ThrowImmediatelyDataLoadEventListener.Quiet);
dest.PreInitialize((DataLoadInfo)dli, ThrowImmediatelyDataLoadEventListener.Quiet);

Assert.That(dest.OutputFile, Is.Not.Null);
FileAssert.Exists(dest.OutputFile);
dest.ProcessPipelineData(dt, ThrowImmediatelyDataLoadEventListener.Quiet, new GracefulCancellationToken());
dest.Dispose(ThrowImmediatelyDataLoadEventListener.Quiet, null);

Assert.That(
File.ReadAllText(dest.OutputFile), Is.EqualTo(lotsOfDecimalPlaces
? $"Floats{Environment.NewLine}3.1415926536{Environment.NewLine}"
: $"Floats{Environment.NewLine}3.14{Environment.NewLine}"));
Assert.That(dest.OutputFile, Is.Not.Null);
FileAssert.Exists(dest.OutputFile);

dt.Dispose();
Assert.That(
File.ReadAllText(dest.OutputFile), Is.EqualTo(lotsOfDecimalPlaces
? $"Floats{Environment.NewLine}3.1415926536{Environment.NewLine}"
: $"Floats{Environment.NewLine}3.14{Environment.NewLine}"));
}
}
}
Loading
Loading