diff --git a/src/Valet.UnitTests/Services/DockerServiceTests.cs b/src/Valet.UnitTests/Services/DockerServiceTests.cs index 1280ee1..a2ed1bc 100644 --- a/src/Valet.UnitTests/Services/DockerServiceTests.cs +++ b/src/Valet.UnitTests/Services/DockerServiceTests.cs @@ -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(), + It.IsAny?>(), + It.IsAny(), + null + ) + ).ReturnsAsync(("", $"Error response from daemon: Head \"https://{server}/v2/valet-customers/valet-cli/manifests/latest\": unauthorized", 1)); + + // Act/Assert + Assert.ThrowsAsync(() => _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() { diff --git a/src/Valet/Services/DockerService.cs b/src/Valet/Services/DockerService.cs index 6dd8f8e..4e416cd 100644 --- a/src/Valet/Services/DockerService.cs +++ b/src/Valet/Services/DockerService.cs @@ -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}");