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

User/lemccomb/fileread #94

Merged
merged 18 commits into from
Jul 15, 2024
Merged

User/lemccomb/fileread #94

merged 18 commits into from
Jul 15, 2024

Conversation

lemccomb
Copy link
Contributor

@lemccomb lemccomb commented Jul 11, 2024

  1. Makes CoseSignTool and CoseHandler more resilient to sign and validate requests on files that may not have been fully written yet or fully disposed.
  2. Forces full dispose of streams at the end of sign and validate operations.
  3. Implements a simple logger to write to console, trace, or other target.

CoseHandler/Extensions/FileInfoExtensions.cs Dismissed Show dismissed Hide dismissed
// Act
// Start the file writes then start the loading tasks before the writes complete.
// Both tasks should wait for the writes to complete before loading the content.
Task t1 = Task.Run(() => WriteTextFileSlowly(outPath1, text));

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to t1 is useless, since its value is never read.
byte[] bytes = f1.GetBytesResilient();
bytes.Length.Should().BeGreaterThan(38);

var t2 = Task.Run(() => WriteTextFileSlowly(outPath2, text));

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to t2 is useless, since its value is never read.

// Act
// Start the file write. The loading task should time out before the first character is written.
var writeTask1 = Task.Run(() => WriteTextFileWithDelay(outPath, text, 10));

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to writeTask1 is useless, since its value is never read.
CoseHandler/CoseHandler.cs Dismissed Show dismissed Hide dismissed
CoseSign1/Extensions/StreamExtensions.cs Dismissed Show dismissed Hide dismissed
CoseHandler/CoseHandler.cs Dismissed Show dismissed Hide dismissed
CoseHandler/CoseHandler.cs Dismissed Show dismissed Hide dismissed
CoseHandler/CoseHandler.cs Dismissed Show dismissed Hide dismissed
Comment on lines 78 to 82
catch (Exception ex)
{
// Assert
ex.Should().BeOfType<IOException>("The file was still empty.");
}

Check notice

Code scanning / CodeQL

Generic catch clause Note test

Generic catch clause.
// Assert
Assert.Fail("The file should have thrown an IOException because it was still empty.");
}
catch (IOException) { }

Check notice

Code scanning / CodeQL

Poor error handling: empty catch block Note test

Poor error handling: empty catch block.
{
// Arrange
string text = "This is some text being written slowly."; // 39 chars
byte[] textBytes = Encoding.UTF8.GetBytes(text);

Check warning

Code scanning / CodeQL

Useless assignment to local variable Warning test

This assignment to textBytes is useless, since its value is never read.
CoseSign1/Extensions/StreamExtensions.cs Dismissed Show dismissed Hide dismissed
(DateTime.Now - startTime).TotalSeconds >= maxWaitTimeInSeconds;

private static double SecondsSince(DateTime startTime)
=> Math.Round((double)(DateTime.Now - startTime).TotalSeconds, 2);

Check warning

Code scanning / CodeQL

Cast to same type Warning

This cast is redundant because the expression already has type Double.
byte[] bytes = Encoding.UTF8.GetBytes("This is some text that will be written to a file eventually.");
FileInfo f = new(Path.GetTempFileName());
f.Refresh();
var cts = new CancellationTokenSource();

Check warning

Code scanning / CodeQL

Missing Dispose call on local IDisposable Warning test

Disposable 'CancellationTokenSource' is created but not disposed.
@lemccomb lemccomb merged commit 5f37ce2 into main Jul 15, 2024
10 checks passed
@lemccomb lemccomb deleted the user/lemccomb/fileread branch July 15, 2024 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants