Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
19 changes: 19 additions & 0 deletions GitIntegration.Test/Hosting/AzureDevOpsProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,25 @@
StringAssert.Contains(exception.Message, "..");
}

[TestMethod]
public async Task ThrowsWhenARepositoryNameIsWhitespaceOnlyAsync()
{
// Path.GetFileName(" ") returns " " unchanged — there is no separator to strip, so the
// leaf is exactly the whitespace-only input. GitRepositoryName itself rejects a
// whitespace-only value ([HasNonWhitespaceContent]), so LocalPath is held to the same rule:
// a name the semantic type would refuse is not a name this mapping can turn into a directory
// either.
using FakeHttpMessageHandler handler = new FakeHttpMessageHandler()
.Respond(HttpStatusCode.OK, SingleRepositoryResponse(" "), ("Content-Type", "application/json"));
AzureDevOpsProvider provider = new() { Owner = "contoso".As<GitProviderOwner>(), Handler = handler };

GitHostingRequestException exception = await Assert.ThrowsExactlyAsync<GitHostingRequestException>(
async () => await provider.GetRepositoriesAsync(TestContext.CancellationTokenSource.Token).ConfigureAwait(false))

Check warning on line 182 in GitIntegration.Test/Hosting/AzureDevOpsProviderTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'TestContext.CancellationToken' instead of 'TestContext.CancellationTokenSource.Token'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_GitIntegration&issues=AaA3eGHtAgjWB_r7V56O&open=AaA3eGHtAgjWB_r7V56O&pullRequest=81
.ConfigureAwait(false);

StringAssert.Contains(exception.Message, "cannot be represented as a local directory");

Check warning on line 185 in GitIntegration.Test/Hosting/AzureDevOpsProviderTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.Contains' instead of 'StringAssert.Contains'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_GitIntegration&issues=AaA3eGHtAgjWB_r7V56N&open=AaA3eGHtAgjWB_r7V56N&pullRequest=81
}

[TestMethod]
public async Task ThrowsWhenARepositoryNameIsMissingAsync()
{
Expand Down
19 changes: 19 additions & 0 deletions GitIntegration.Test/Hosting/GitHubProviderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,25 @@
StringAssert.Contains(exception.Message, "..");
}

[TestMethod]
public async Task ThrowsWhenARepositoryNameIsWhitespaceOnlyAsync()
{
// Path.GetFileName(" ") returns " " unchanged — there is no separator to strip, so the
// leaf is exactly the whitespace-only input. GitRepositoryName itself rejects a
// whitespace-only value ([HasNonWhitespaceContent]), so LocalPath is held to the same rule:
// a name the semantic type would refuse is not a name this mapping can turn into a directory
// either.
using FakeHttpMessageHandler handler = new FakeHttpMessageHandler()
.Respond(HttpStatusCode.OK, SingleRepositoryArray(" "), ("Content-Type", "application/json"));
GitHubProvider provider = new() { Owner = "contoso".As<GitProviderOwner>(), Handler = handler };

GitHostingRequestException exception = await Assert.ThrowsExactlyAsync<GitHostingRequestException>(
async () => await provider.GetRepositoriesAsync(TestContext.CancellationTokenSource.Token).ConfigureAwait(false))

Check warning on line 184 in GitIntegration.Test/Hosting/GitHubProviderTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'TestContext.CancellationToken' instead of 'TestContext.CancellationTokenSource.Token'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_GitIntegration&issues=AaA3eGJrAgjWB_r7V56Q&open=AaA3eGJrAgjWB_r7V56Q&pullRequest=81
.ConfigureAwait(false);

StringAssert.Contains(exception.Message, "cannot be represented as a local directory");

Check warning on line 187 in GitIntegration.Test/Hosting/GitHubProviderTests.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use 'Assert.Contains' instead of 'StringAssert.Contains'

See more on https://sonarcloud.io/project/issues?id=ktsu-dev_GitIntegration&issues=AaA3eGJrAgjWB_r7V56P&open=AaA3eGJrAgjWB_r7V56P&pullRequest=81
}

[TestMethod]
public async Task MapsAnOpenPullRequestToOpenAsync()
{
Expand Down
6 changes: 3 additions & 3 deletions GitIntegration/GitProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,14 +241,14 @@ internal HostingCredential ResolveCredential() =>
/// derived leaf segment of <paramref name="repositoryName"/>.
/// </returns>
/// <exception cref="GitHostingRequestException">
/// <paramref name="repositoryName"/> is <see langword="null"/>, empty, or a name from which no
/// directory segment can be derived.
/// <paramref name="repositoryName"/> is <see langword="null"/>, empty, consists only of
/// whitespace, or is a name from which no directory segment can otherwise be derived.
/// </exception>
internal static AbsoluteDirectoryPath ToLocalRepositoryPath(string? repositoryName, GitProviderName providerName)
{
string leaf = Path.GetFileName(repositoryName ?? string.Empty);

if (string.IsNullOrEmpty(leaf) || leaf is "." or "..")
if (string.IsNullOrWhiteSpace(leaf) || leaf is "." or "..")
{
throw new GitHostingRequestException(
$"{providerName} reported a repository name '{repositoryName}' that cannot be represented as a local directory.");
Expand Down