-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- For the checkboxes below you must check each one to indicate that you either did the relevant task, or considered it and decided there was nothing that needed doing --> Stood up a BBS server in our shared Azure Subscription (e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com). It's running the latest version of BBS (8.5.0) and Ubuntu 22.04. Manually created 2 projects and 2 repos in BBS (in the future we may automate this like we have for ADO/GH), and added a new integration test to migrate BBS->GH. Included asserts to check if the GH repo exists and is initialized. The default SSH cert that Azure generates didn't seem to work when using Ubuntu 22.04 (didn't work with our SSH.Net nuget library, but did work when directly using SSH in a terminal). I found a [workaround in an issue](sshnet/SSH.NET#825 (comment)) from the SSH.Net repo that I applied in this PR. I don't fully understand exactly what it's doing, but it looks like it's updating the signature on the key in-memory before using it. Whatever it's doing, it makes keys that previously didn't work now work. So it seems like a good thing to me. Closes #553 Future work: - automate the creation of BBS test data (like we do for ADO/GH) - Include downloading the migration logs (and asserting that they exist) - Add BBS windows server (once we support SMB) - Add AWS - Add another BBS server with the oldest version we support (5.14 I think) Checklist - [x] Did you write/update appropriate tests - [x] Release notes updated (if appropriate) - [x] Appropriate logging output - [x] Issue linked - [x] Docs updated (or issue created) <!-- For docs we should review the docs at: https://docs.github.com/en/early-access/github/migrating-with-github-enterprise-importer and the README.md in this repo If a doc update is required based on the changes in this PR, it is sufficient to create an issue and link to it here. The doc update can be made later/separately. The process to update the docs can be found here: https://github.com/github/docs-early-access#opening-prs The markdown files are here: https://github.com/github/docs-early-access/tree/main/content/github/migrating-with-github-enterprise-importer -->
- Loading branch information
1 parent
f6c1950
commit b4a33bb
Showing
7 changed files
with
256 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Azure.Storage.Blobs; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
|
||
namespace OctoshiftCLI.IntegrationTests; | ||
|
||
[Collection("Integration Tests")] | ||
public sealed class BbsToGithub : IDisposable | ||
{ | ||
private const string BBS_URL = "http://e2e-bbs-8-5-0-linux-2204.eastus.cloudapp.azure.com:7990"; | ||
private const string SSH_KEY_FILE = "ssh_key.pem"; | ||
|
||
private readonly ITestOutputHelper _output; | ||
private readonly TestHelper _targetHelper; | ||
private readonly TestHelper _sourceHelper; | ||
private readonly HttpClient _versionClient; | ||
private readonly HttpClient _targetGithubHttpClient; | ||
private readonly GithubClient _targetGithubClient; | ||
private readonly GithubApi _targetGithubApi; | ||
private readonly HttpClient _sourceBbsHttpClient; | ||
private readonly BbsClient _sourceBbsClient; | ||
private readonly BbsApi _sourceBbsApi; | ||
private readonly BlobServiceClient _blobServiceClient; | ||
private readonly Dictionary<string, string> _tokens; | ||
private readonly DateTime _startTime; | ||
|
||
public BbsToGithub(ITestOutputHelper output) | ||
{ | ||
_startTime = DateTime.Now; | ||
_output = output; | ||
|
||
var logger = new OctoLogger(_ => { }, x => _output.WriteLine(x), _ => { }, _ => { }); | ||
|
||
var sourceBbsUsername = Environment.GetEnvironmentVariable("BBS_USERNAME"); | ||
var sourceBbsPassword = Environment.GetEnvironmentVariable("BBS_PASSWORD"); | ||
var targetGithubToken = Environment.GetEnvironmentVariable("GHEC_PAT"); | ||
var azureStorageConnectionString = Environment.GetEnvironmentVariable($"AZURE_STORAGE_CONNECTION_STRING_{TestHelper.GetOsName().ToUpper()}"); | ||
var sshKey = Environment.GetEnvironmentVariable("SSH_KEY"); | ||
_tokens = new Dictionary<string, string> | ||
{ | ||
["BBS_USERNAME"] = sourceBbsUsername, | ||
["BBS_PASSWORD"] = sourceBbsPassword, | ||
["GH_PAT"] = targetGithubToken, | ||
["AZURE_STORAGE_CONNECTION_STRING"] = azureStorageConnectionString | ||
}; | ||
|
||
File.WriteAllText(Path.Join(TestHelper.GetOsDistPath(), SSH_KEY_FILE), sshKey); | ||
|
||
_versionClient = new HttpClient(); | ||
|
||
_sourceBbsHttpClient = new HttpClient(); | ||
_sourceBbsClient = new BbsClient(logger, _sourceBbsHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), sourceBbsUsername, sourceBbsPassword); | ||
_sourceBbsApi = new BbsApi(_sourceBbsClient, BBS_URL, logger); | ||
|
||
_targetGithubHttpClient = new HttpClient(); | ||
_targetGithubClient = new GithubClient(logger, _targetGithubHttpClient, new VersionChecker(_versionClient, logger), new RetryPolicy(logger), new DateTimeProvider(), targetGithubToken); | ||
_targetGithubApi = new GithubApi(_targetGithubClient, "https://api.github.com", new RetryPolicy(logger)); | ||
|
||
_blobServiceClient = new BlobServiceClient(azureStorageConnectionString); | ||
|
||
_sourceHelper = new TestHelper(_output, _sourceBbsApi, _sourceBbsClient, BBS_URL); | ||
_targetHelper = new TestHelper(_output, _targetGithubApi, _targetGithubClient, _blobServiceClient); | ||
} | ||
|
||
[Fact] | ||
public async Task Basic() | ||
{ | ||
var githubTargetOrg = $"e2e-testing-{TestHelper.GetOsName()}"; | ||
const string repo1 = "EEL-repo-1"; | ||
const string repo2 = "EEL-repo-2"; | ||
|
||
await _targetHelper.ResetBlobContainers(); | ||
|
||
// TODO: Reset BBS test environment | ||
await _targetHelper.ResetGithubTestEnvironment(githubTargetOrg); | ||
|
||
// TODO: Generate BBS test data | ||
|
||
await _targetHelper.RunBbsCliMigration( | ||
$"generate-script --github-org {githubTargetOrg} --bbs-server-url {BBS_URL} --ssh-user octoshift --ssh-private-key {SSH_KEY_FILE}", _tokens); | ||
|
||
_targetHelper.AssertNoErrorInLogs(_startTime); | ||
|
||
await _targetHelper.AssertGithubRepoExists(githubTargetOrg, repo1); | ||
await _targetHelper.AssertGithubRepoExists(githubTargetOrg, repo2); | ||
await _targetHelper.AssertGithubRepoInitialized(githubTargetOrg, repo1); | ||
await _targetHelper.AssertGithubRepoInitialized(githubTargetOrg, repo2); | ||
|
||
// TODO: Assert migration logs are downloaded | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_sourceBbsHttpClient?.Dispose(); | ||
_targetGithubHttpClient?.Dispose(); | ||
_versionClient?.Dispose(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using Renci.SshNet.Common; | ||
using Renci.SshNet.Security; | ||
using Renci.SshNet.Security.Cryptography; | ||
using Renci.SshNet.Security.Cryptography.Ciphers; | ||
|
||
namespace OctoshiftCLI.BbsToGithub; | ||
|
||
// workaround for RSA keys on Ubuntu 22.04 | ||
// https://github.com/sshnet/SSH.NET/issues/825#issuecomment-1139440419 | ||
|
||
public class RsaWithSha256SignatureKey : RsaKey | ||
{ | ||
public RsaWithSha256SignatureKey(BigInteger modulus, BigInteger exponent, BigInteger d, BigInteger p, BigInteger q, | ||
BigInteger inverseQ) : base(modulus, exponent, d, p, q, inverseQ) | ||
{ | ||
} | ||
|
||
private RsaSha256DigitalSignature _digitalSignature; | ||
|
||
protected override DigitalSignature DigitalSignature | ||
{ | ||
get | ||
{ | ||
_digitalSignature ??= new RsaSha256DigitalSignature(this); | ||
|
||
return _digitalSignature; | ||
} | ||
} | ||
|
||
public override string ToString() => "rsa-sha2-256"; | ||
} | ||
|
||
public class RsaSha256DigitalSignature : CipherDigitalSignature, IDisposable | ||
{ | ||
private HashAlgorithm _hash; | ||
|
||
public RsaSha256DigitalSignature(RsaWithSha256SignatureKey rsaKey) | ||
// custom OID | ||
: base(new ObjectIdentifier(2, 16, 840, 1, 101, 3, 4, 2, 1), new RsaCipher(rsaKey)) | ||
{ | ||
// custom | ||
_hash = SHA256.Create(); | ||
} | ||
|
||
protected override byte[] Hash(byte[] input) => _hash.ComputeHash(input); | ||
|
||
private bool _isDisposed; | ||
|
||
public void Dispose() | ||
{ | ||
Dispose(true); | ||
GC.SuppressFinalize(this); | ||
} | ||
|
||
protected virtual void Dispose(bool disposing) | ||
{ | ||
if (_isDisposed) | ||
{ | ||
return; | ||
} | ||
|
||
if (disposing) | ||
{ | ||
var hash = _hash; | ||
if (hash != null) | ||
{ | ||
hash.Dispose(); | ||
_hash = null; | ||
} | ||
|
||
_isDisposed = true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters