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

Commit fb0bd8f

Browse files
authored
Additional docker auth error mesage (#97)
* one more auth error message to check * Add unit test for new error message check
1 parent 6e80c1a commit fb0bd8f

2 files changed

Lines changed: 43 additions & 4 deletions

File tree

src/Valet.UnitTests/Services/DockerServiceTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,40 @@ public void UpdateImageAsync_InvalidCredentialsProvided_ThrowsUnauthorized()
147147
_processService.VerifyAll();
148148
}
149149

150+
[Test]
151+
public void UpdateImageAsync_Unauthenticated_ThrowsUnauthorized()
152+
{
153+
// Arrange
154+
var image = "valet-customers/valet-cli";
155+
var server = "ghcr.io";
156+
var version = "latest";
157+
158+
_processService.Setup(handler =>
159+
handler.RunAndCaptureAsync(
160+
"docker",
161+
$"pull {server}/{image}:{version} --quiet",
162+
It.IsAny<string?>(),
163+
It.IsAny<IEnumerable<(string, string)>?>(),
164+
It.IsAny<bool>(),
165+
null
166+
)
167+
).ReturnsAsync(("", $"Error response from daemon: Head \"https://{server}/v2/valet-customers/valet-cli/manifests/latest\": unauthorized", 1));
168+
169+
// Act/Assert
170+
Assert.ThrowsAsync<Exception>(() => _dockerService.UpdateImageAsync(
171+
image,
172+
server,
173+
version,
174+
null,
175+
null
176+
),
177+
@"You are not authorized to access Valet yet. Please ensure you've completed the following:
178+
- Requested access to Valet and received onboarding instructions via email.
179+
- Accepted all of the repository invites sent after being onboarded.
180+
- The GitHub personal access token used above contains the 'read:packages' scope.");
181+
_processService.VerifyAll();
182+
}
183+
150184
[Test]
151185
public void UpdateImageAsync_InvalidCredentialsProvided_ThrowsUnknownError()
152186
{

src/Valet/Services/DockerService.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,17 @@ private async Task DockerPullAsync(string image, string server, string version)
161161
if (exitCode != 0)
162162
{
163163
string message = standardError.Trim();
164-
string? errorMessage = message == "Error response from daemon: denied"
165-
? @"You are not authorized to access Valet yet. Please ensure you've completed the following:
164+
string errorMessage = $"There was an error pulling the {image}:{version} image from the {server} docker repository.\nError: {message}";
165+
166+
if (message == "Error response from daemon: denied"
167+
|| message == $"Error response from daemon: Head \"https://{server}/v2/valet-customers/valet-cli/manifests/latest\": unauthorized")
168+
{
169+
errorMessage = @"You are not authorized to access Valet yet. Please ensure you've completed the following:
166170
- Requested access to Valet and received onboarding instructions via email.
167171
- Accepted all of the repository invites sent after being onboarded.
168-
- The GitHub personal access token used above contains the 'read:packages' scope."
169-
: $"There was an error pulling the {image}:{version} image from the {server} docker repository.\nError: {message}";
172+
- The GitHub personal access token used above contains the 'read:packages' scope.";
173+
}
174+
170175
throw new Exception(errorMessage);
171176
}
172177
Console.WriteLine($"Successfully downloaded {image}:{version}");

0 commit comments

Comments
 (0)