Skip to content
Open
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,52 @@ public void UseGithubStorage_And_Aws_Bucket_Name_Throws()
.ThrowExactly<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.WithMessage("GithubSourceOrg should be an org name, not a URL.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.WithMessage("*GithubTargetEnterprise should be an enterprise name, not a URL*");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -308,5 +308,80 @@ public void MetadataArchiveUrl_With_MetadataArchivePath_Throws()
.ThrowExactly<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.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<OctoshiftCliException>()
.WithMessage("*TargetRepo should be a repo name, not a URL*");
}
}
}
9 changes: 9 additions & 0 deletions src/gei/Commands/GenerateScript/GenerateScriptCommandArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
16 changes: 15 additions & 1 deletion src/gei/Commands/MigrateOrg/MigrateOrgCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OctoshiftCLI.Commands;
using System;
using OctoshiftCLI.Commands;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.Services;

Expand All @@ -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;
Expand Down
23 changes: 22 additions & 1 deletion src/gei/Commands/MigrateRepo/MigrateRepoCommandArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using OctoshiftCLI.Commands;
using System;
using OctoshiftCLI.Commands;
using OctoshiftCLI.Extensions;
using OctoshiftCLI.Services;

Expand Down Expand Up @@ -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)
Expand All @@ -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.");
}
}
}
}
Loading