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

BBS Integration tests #696

Merged
merged 31 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
b360750
added bbs integration test
dylan-smith Oct 24, 2022
c68349c
fix arg name, add secrets to CI yml
dylan-smith Oct 24, 2022
f05bf52
change SshPort to int
dylan-smith Oct 24, 2022
6fa6bf8
remove unused variable
dylan-smith Oct 24, 2022
2b2a80a
fix tests
dylan-smith Oct 24, 2022
5d943f0
add extra test logging
dylan-smith Oct 25, 2022
77c2aa4
dotnet format
dylan-smith Oct 25, 2022
4a19d22
adding logging to powershell script run too
dylan-smith Oct 25, 2022
802301d
added troubleshooting to CI
dylan-smith Oct 25, 2022
f6846ea
changed dir
dylan-smith Oct 25, 2022
29dd7e0
turn off troubleshooting in CI
dylan-smith Oct 25, 2022
a66ab21
reverted process stdout capture
dylan-smith Oct 25, 2022
b41632f
accidentally deleted some test output
dylan-smith Oct 25, 2022
132e2b5
fix ssh key path
dylan-smith Oct 25, 2022
999612c
chmod on pem file
dylan-smith Oct 25, 2022
4c6e509
fixed problem with SSH key
dylan-smith Oct 27, 2022
fd68600
dotnet format
dylan-smith Oct 27, 2022
7140946
Merge branch 'main' into dylan-smith/bbs-integration-tests
dylan-smith Oct 27, 2022
f053ceb
update repo names
dylan-smith Oct 28, 2022
ac746ca
Merge branch 'dylan-smith/bbs-integration-tests' of https://github.co…
dylan-smith Oct 28, 2022
1f134b0
Merge branch 'main' into dylan-smith/bbs-integration-tests
dylan-smith Oct 28, 2022
8049589
fix compile error after merge
dylan-smith Oct 28, 2022
f44b867
trying to fix disposable problems
dylan-smith Oct 31, 2022
ab3375c
removed unnecessary field
dylan-smith Oct 31, 2022
dc6bf40
remove commented out code
dylan-smith Oct 31, 2022
4204c8d
cleaned up CI yml
dylan-smith Oct 31, 2022
10f26c0
simplified rsa 256 signature and doesnt break other key formats
dylan-smith Nov 1, 2022
fadfb72
Merge branch 'dylan-smith/bbs-integration-tests' of https://github.co…
dylan-smith Nov 1, 2022
fa58d87
fix null reference codeql warning
dylan-smith Nov 1, 2022
879d0d3
make field readonly
dylan-smith Nov 1, 2022
50942a4
fix typo
dylan-smith Nov 1, 2022
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
Prev Previous commit
Next Next commit
trying to fix disposable problems
  • Loading branch information
dylan-smith committed Oct 31, 2022
commit f44b867f779d4f0ae90bc3ac0bb475e8f98b7c38
15 changes: 0 additions & 15 deletions src/bbs2gh/RsaSha256Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,10 @@ protected virtual void Dispose(bool disposing)
_isDisposed = true;
}
}

~RsaSha256DigitalSignature()
{
Dispose(false);
}
}

public static class RsaSha256Util
{
public static void SetupConnection(ConnectionInfo connection)
{
if (connection is null)
{
throw new ArgumentNullException(nameof(connection));
}

connection.HostKeyAlgorithms["rsa-sha2-256"] = data => new KeyHostAlgorithm("rsa-sha2-256", new RsaKey(), data);
}

public static RsaWithSha256SignatureKey ConvertToKeyWithSha256Signature(PrivateKeyFile keyFile)
{
return keyFile?.HostKey is not KeyHostAlgorithm oldKeyHostAlgorithm
Expand Down
28 changes: 20 additions & 8 deletions src/bbs2gh/Services/BbsSshArchiveDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.IO;
using System.Threading.Tasks;
using Renci.SshNet;
using Renci.SshNet.Security;

namespace OctoshiftCLI.BbsToGithub.Services;

Expand All @@ -10,6 +11,10 @@ public sealed class BbsSshArchiveDownloader : IBbsArchiveDownloader, IDisposable
private const int DOWNLOAD_PROGRESS_REPORT_INTERVAL_IN_SECONDS = 10;

private readonly ISftpClient _sftpClient;
private readonly RsaKey _rsaKey = new RsaKey();
private readonly ConnectionInfo _sftpConnection;
private readonly PrivateKeyFile _pkRsa;
private readonly PrivateKeyAuthenticationMethod _authenticationMethodRsa;
private readonly OctoLogger _log;
private readonly FileSystemProvider _fileSystemProvider;
private readonly object _mutex = new();
Expand All @@ -18,14 +23,15 @@ public sealed class BbsSshArchiveDownloader : IBbsArchiveDownloader, IDisposable
#pragma warning disable CA2000 // Incorrectly flagged as a not-disposing error
public BbsSshArchiveDownloader(OctoLogger log, FileSystemProvider fileSystemProvider, string host, string sshUser, string privateKeyFileFullPath, int sshPort = 22)
{
var pkRsa = new PrivateKeyFile(privateKeyFileFullPath);
var newKey = RsaSha256Util.ConvertToKeyWithSha256Signature(pkRsa);
RsaSha256Util.UpdatePrivateKeyFile(pkRsa, newKey);
var authenticationMethodRsa = new PrivateKeyAuthenticationMethod(sshUser, pkRsa);
var conn = new ConnectionInfo(host, sshPort, sshUser, authenticationMethodRsa);
RsaSha256Util.SetupConnection(conn);
_pkRsa = new PrivateKeyFile(privateKeyFileFullPath);
var newKey = RsaSha256Util.ConvertToKeyWithSha256Signature(_pkRsa);
RsaSha256Util.UpdatePrivateKeyFile(_pkRsa, newKey);
_authenticationMethodRsa = new PrivateKeyAuthenticationMethod(sshUser, _pkRsa);
_sftpConnection = new ConnectionInfo(host, sshPort, sshUser, _authenticationMethodRsa);
_sftpConnection.HostKeyAlgorithms["rsa-sha2-256"] = data => new KeyHostAlgorithm("rsa-sha2-256", _rsaKey, data);

_sftpClient = new SftpClient(_sftpConnection);

_sftpClient = new SftpClient(conn);

_log = log;
_fileSystemProvider = fileSystemProvider;
Expand Down Expand Up @@ -122,5 +128,11 @@ private string GetLogFriendlySize(ulong size)
};
}

public void Dispose() => (_sftpClient as IDisposable)?.Dispose();
public void Dispose()
{
(_sftpClient as IDisposable)?.Dispose();
(_rsaKey as IDisposable)?.Dispose();
(_pkRsa as IDisposable)?.Dispose();
(_authenticationMethodRsa as IDisposable)?.Dispose();
}
}