diff --git a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs index 981b0ce5c..a60751adf 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/GenerateScript/GenerateScriptCommandArgsTests.cs @@ -107,5 +107,52 @@ public void UseGithubStorage_And_Aws_Bucket_Name_Throws() .ThrowExactly() .WithMessage("*--use-github-storage flag was provided with an AWS S3 Bucket name*"); } + [Fact] + public void Throws_If_Url_Passed_In_GithubSourceOrg() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetOrg() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "foo", + GithubTargetOrg = "https://github.com/bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_Both_Source_And_Target_Org() + { + var args = new GenerateScriptCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + GhesApiUrl = "https://github.contoso.com" + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("GithubSourceOrg should be an org name, not a URL."); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs index e5508275b..afecc38b4 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateOrg/MigrateOrgCommandArgsTests.cs @@ -30,5 +30,70 @@ public void Source_Pat_Defaults_To_Target_Pat() args.GithubSourcePat.Should().Be(TARGET_PAT); } + [Fact] + public void Throws_If_Url_Passed_In_GithubSourceOrg() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = TARGET_ORG, + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetOrg() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = "https://github.com/foo", + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + + [Fact] + public void Throws_If_Url_Passed_In_Both_Source_And_Target_Org() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + GithubTargetEnterprise = TARGET_ENTERPRISE, + GithubTargetPat = TARGET_PAT, + }; + + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("GithubSourceOrg should be an org name, not a URL."); + } + [Fact] + public void Throws_If_Url_Passed_In_GithubTargetEnterprise() + { + var args = new MigrateOrgCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + GithubTargetEnterprise = "https://github.com/foo", + GithubTargetPat = TARGET_PAT, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetEnterprise should be an enterprise name, not a URL*"); + } } } diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs index ae8b994b4..c2691494f 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandArgsTests.cs @@ -308,5 +308,80 @@ public void MetadataArchiveUrl_With_MetadataArchivePath_Throws() .ThrowExactly() .WithMessage("*--metadata-archive-url and --metadata-archive-path may not be used together*"); } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_GithubSourceOrg() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_GithubTargetOrg() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = "https://github.com/bar", + TargetRepo = TARGET_REPO, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubTargetOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_Both_Source_And_Target_Org() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = "https://github.com/foo", + GithubTargetOrg = "https://github.com/bar", + TargetRepo = TARGET_REPO, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*GithubSourceOrg should be an org name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_SourceRepo() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = "https://github.com/foo", + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*SourceRepo should be a repo name, not a URL*"); + } + [Fact] + public void It_Throws_Error_When_Url_Provided_In_TargetRepo() + { + var args = new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = "https://github.com/bar", + }; + FluentActions.Invoking(() => args.Validate(_mockOctoLogger.Object)) + .Should() + .ThrowExactly() + .WithMessage("*TargetRepo should be a repo name, not a URL*"); + } } } diff --git a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs index 52bfd7f52..7bcb5d2a3 100644 --- a/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs +++ b/src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs @@ -28,6 +28,15 @@ public class GenerateScriptCommandArgs : CommandArgs public override void Validate(OctoLogger log) { + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } if (AwsBucketName.HasValue()) { if (GhesApiUrl.IsNullOrWhiteSpace()) diff --git a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs index 4b9a85ae8..00ffa3a43 100644 --- a/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs +++ b/src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs @@ -1,4 +1,5 @@ -using OctoshiftCLI.Commands; +using System; +using OctoshiftCLI.Commands; using OctoshiftCLI.Extensions; using OctoshiftCLI.Services; @@ -19,6 +20,19 @@ public class MigrateOrgCommandArgs : CommandArgs public override void Validate(OctoLogger log) { + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } + if (GithubTargetEnterprise.HasValue() && Uri.IsWellFormedUriString(GithubTargetEnterprise, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetEnterprise should be an enterprise name, not a URL."); + } if (GithubTargetPat.HasValue() && GithubSourcePat.IsNullOrWhiteSpace()) { GithubSourcePat = GithubTargetPat; diff --git a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs index 58b24171a..57e686322 100644 --- a/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs +++ b/src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs @@ -1,4 +1,5 @@ -using OctoshiftCLI.Commands; +using System; +using OctoshiftCLI.Commands; using OctoshiftCLI.Extensions; using OctoshiftCLI.Services; @@ -96,6 +97,7 @@ public override void Validate(OctoLogger log) { throw new OctoshiftCliException("The --use-github-storage flag was provided with a connection string for an Azure storage account. Archive cannot be uploaded to both locations."); } + ValidateNamesAreNotUrls(); } private void DefaultTargetRepo(OctoLogger log) @@ -115,5 +117,24 @@ private void DefaultSourcePat(OctoLogger log) log?.LogInformation("Since github-target-pat is provided, github-source-pat will also use its value."); } } + private void ValidateNamesAreNotUrls() + { + if (GithubSourceOrg.HasValue() && Uri.IsWellFormedUriString(GithubSourceOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubSourceOrg should be an org name, not a URL."); + } + if (GithubTargetOrg.HasValue() && Uri.IsWellFormedUriString(GithubTargetOrg, UriKind.Absolute)) + { + throw new OctoshiftCliException("GithubTargetOrg should be an org name, not a URL."); + } + if (SourceRepo.HasValue() && Uri.IsWellFormedUriString(SourceRepo, UriKind.Absolute)) + { + throw new OctoshiftCliException("SourceRepo should be a repo name, not a URL."); + } + if (TargetRepo.HasValue() && Uri.IsWellFormedUriString(TargetRepo, UriKind.Absolute)) + { + throw new OctoshiftCliException("TargetRepo should be a repo name, not a URL."); + } + } } }