Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
Additional docker auth error mesage (#97)
Browse files Browse the repository at this point in the history
* one more auth error message to check
* Add unit test for new error message check
  • Loading branch information
dwhathaway authored Nov 2, 2022
1 parent 6e80c1a commit fb0bd8f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/Valet.UnitTests/Services/DockerServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,40 @@ public void UpdateImageAsync_InvalidCredentialsProvided_ThrowsUnauthorized()
_processService.VerifyAll();
}

[Test]
public void UpdateImageAsync_Unauthenticated_ThrowsUnauthorized()
{
// Arrange
var image = "valet-customers/valet-cli";
var server = "ghcr.io";
var version = "latest";

_processService.Setup(handler =>
handler.RunAndCaptureAsync(
"docker",
$"pull {server}/{image}:{version} --quiet",
It.IsAny<string?>(),
It.IsAny<IEnumerable<(string, string)>?>(),
It.IsAny<bool>(),
null
)
).ReturnsAsync(("", $"Error response from daemon: Head \"https://{server}/v2/valet-customers/valet-cli/manifests/latest\": unauthorized", 1));

// Act/Assert
Assert.ThrowsAsync<Exception>(() => _dockerService.UpdateImageAsync(
image,
server,
version,
null,
null
),
@"You are not authorized to access Valet yet. Please ensure you've completed the following:
- Requested access to Valet and received onboarding instructions via email.
- Accepted all of the repository invites sent after being onboarded.
- The GitHub personal access token used above contains the 'read:packages' scope.");
_processService.VerifyAll();
}

[Test]
public void UpdateImageAsync_InvalidCredentialsProvided_ThrowsUnknownError()
{
Expand Down
13 changes: 9 additions & 4 deletions src/Valet/Services/DockerService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,17 @@ private async Task DockerPullAsync(string image, string server, string version)
if (exitCode != 0)
{
string message = standardError.Trim();
string? errorMessage = message == "Error response from daemon: denied"
? @"You are not authorized to access Valet yet. Please ensure you've completed the following:
string errorMessage = $"There was an error pulling the {image}:{version} image from the {server} docker repository.\nError: {message}";

if (message == "Error response from daemon: denied"
|| message == $"Error response from daemon: Head \"https://{server}/v2/valet-customers/valet-cli/manifests/latest\": unauthorized")
{
errorMessage = @"You are not authorized to access Valet yet. Please ensure you've completed the following:
- Requested access to Valet and received onboarding instructions via email.
- Accepted all of the repository invites sent after being onboarded.
- The GitHub personal access token used above contains the 'read:packages' scope."
: $"There was an error pulling the {image}:{version} image from the {server} docker repository.\nError: {message}";
- The GitHub personal access token used above contains the 'read:packages' scope.";
}

throw new Exception(errorMessage);
}
Console.WriteLine($"Successfully downloaded {image}:{version}");
Expand Down

0 comments on commit fb0bd8f

Please sign in to comment.