public async Task TestPush_missingBlobsAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "gcr.io", "distroless/java").NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync("latest").ConfigureAwait(false); registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); try { await registryClient.PushManifestAsync((V22ManifestTemplate)manifestTemplate, "latest").ConfigureAwait(false); Assert.Fail("Pushing manifest without its BLOBs should fail"); } catch (RegistryErrorException ex) { HttpResponseMessage httpResponse = ex.Cause; Assert.AreEqual( HttpStatusCode.BadRequest, httpResponse.StatusCode); } }
public async Task TestPull_unknownBlobAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); DescriptorDigest nonexistentDigest = DescriptorDigest.FromHash( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); try { await registryClient .PullBlob(nonexistentDigest, _ => { }, _ => { }) .WriteToAsync(Stream.Null).ConfigureAwait(false); Assert.Fail("Trying to pull nonexistent blob should have errored"); } catch (IOException ex) when(ex.InnerException is RegistryErrorException) { StringAssert.Contains( ex.Message, "pull BLOB for localhost:5000/busybox with digest " + nonexistentDigest); } }
public async Task TestPullAsync() { // Pulls the busybox image. localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); V21ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V21ManifestTemplate>("latest").ConfigureAwait(false); DescriptorDigest realDigest = manifestTemplate.GetLayerDigests().First(); // Pulls a layer BLOB of the busybox image. LongAdder totalByteCount = new LongAdder(); LongAdder expectedSize = new LongAdder(); IBlob pulledBlob = registryClient.PullBlob( realDigest, size => { Assert.AreEqual(0, expectedSize.Sum()); expectedSize.Add(size); }, totalByteCount.Add); BlobDescriptor blobDescriptor = await pulledBlob.WriteToAsync(Stream.Null).ConfigureAwait(false); Assert.AreEqual(realDigest, blobDescriptor.GetDigest()); Assert.IsTrue(expectedSize.Sum() > 0); Assert.AreEqual(expectedSize.Sum(), totalByteCount.Sum()); }
public async Task TestPushAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); IBlob testLayerBlob = Blobs.From("crepecake"); // Known digest for 'crepecake' DescriptorDigest testLayerBlobDigest = DescriptorDigest.FromHash( "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); IBlob testContainerConfigurationBlob = Blobs.From("12345"); DescriptorDigest testContainerConfigurationBlobDigest = DescriptorDigest.FromHash( "5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5"); // Creates a valid image manifest. V22ManifestTemplate expectedManifestTemplate = new V22ManifestTemplate(); expectedManifestTemplate.AddLayer(9, testLayerBlobDigest); expectedManifestTemplate.SetContainerConfiguration(5, testContainerConfigurationBlobDigest); // Pushes the BLOBs. RegistryClient registryClient = RegistryClient.CreateFactory(EVENT_HANDLERS, "localhost:5000", "testimage") .SetAllowInsecureRegistries(true) .NewRegistryClient(); Assert.IsFalse( await registryClient.PushBlobAsync(testLayerBlobDigest, testLayerBlob, null, _ => { }).ConfigureAwait(false)); Assert.IsFalse( await registryClient.PushBlobAsync( testContainerConfigurationBlobDigest, testContainerConfigurationBlob, null, _ => { }).ConfigureAwait(false)); // Pushes the manifest. DescriptorDigest imageDigest = await registryClient.PushManifestAsync(expectedManifestTemplate, "latest").ConfigureAwait(false); // Pulls the manifest. V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); Assert.AreEqual(1, manifestTemplate.Layers.Count); Assert.AreEqual(testLayerBlobDigest, manifestTemplate.Layers[0].Digest); Assert.IsNotNull(manifestTemplate.GetContainerConfiguration()); Assert.AreEqual( testContainerConfigurationBlobDigest, manifestTemplate.GetContainerConfiguration().Digest); // Pulls the manifest by digest. V22ManifestTemplate manifestTemplateByDigest = await registryClient.PullManifestAsync <V22ManifestTemplate>(imageDigest.ToString()).ConfigureAwait(false); Assert.AreEqual( await Digests.ComputeJsonDigestAsync(manifestTemplate).ConfigureAwait(false), await Digests.ComputeJsonDigestAsync(manifestTemplateByDigest).ConfigureAwait(false)); }
public async Task TestPull_v22Async() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "gcr.io", "distroless/java").NewRegistryClient(); IManifestTemplate manifestTemplate = await registryClient.PullManifestAsync("latest").ConfigureAwait(false); Assert.AreEqual(2, manifestTemplate.SchemaVersion); V22ManifestTemplate v22ManifestTemplate = (V22ManifestTemplate)manifestTemplate; Assert.IsTrue(v22ManifestTemplate.Layers.Count > 0); }
public async Task TestCheck_doesNotExistAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); DescriptorDigest fakeBlobDigest = DescriptorDigest.FromHash( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"); Assert.IsFalse(await registryClient.CheckBlobAsync(new BlobDescriptor(fakeBlobDigest)).ConfigureAwait(false)); }
public async Task TestPull_v21Async() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); V21ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V21ManifestTemplate>("latest").ConfigureAwait(false); Assert.AreEqual(1, manifestTemplate.SchemaVersion); Assert.IsTrue(manifestTemplate.FsLayers.Count > 0); }
private RegistryClient.Factory NewRegistryClientFactory(ImageConfiguration imageConfiguration) { RegistryClient.Factory factory = RegistryClient.CreateFactory( GetEventHandlers(), imageConfiguration.GetImageRegistry(), imageConfiguration.GetImageRepository()) .SetAllowInsecureRegistries(GetAllowInsecureRegistries()); if (GetToolName() != null) { factory.AddUserAgentValue(new ProductInfoHeaderValue(GetToolName(), GetToolVersion())); } return(factory); }
public async Task TestCheck_existsAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); V22ManifestTemplate manifestTemplate = await registryClient.PullManifestAsync <V22ManifestTemplate>("latest").ConfigureAwait(false); DescriptorDigest blobDigest = manifestTemplate.Layers[0].Digest; Assert.IsTrue(await registryClient.CheckBlobAsync(new BlobDescriptor(blobDigest)).ConfigureAwait(false)); }
public async Task TestGetRegistryAuthenticatorAsync() { RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "registry.hub.docker.com", "library/busybox") .NewRegistryClient(); RegistryAuthenticator registryAuthenticator = await registryClient.GetRegistryAuthenticatorAsync().ConfigureAwait(false); Assert.IsNotNull(registryAuthenticator); Authorization authorization = await registryAuthenticator.AuthenticatePullAsync(null).ConfigureAwait(false); RegistryClient authorizedRegistryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "registry.hub.docker.com", "library/busybox") .SetAuthorization(authorization) .NewRegistryClient(); await authorizedRegistryClient.PullManifestAsync("latest").ConfigureAwait(false); }
public async Task TestPushAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); IBlob testBlob = Blobs.From("crepecake"); // Known digest for 'crepecake' DescriptorDigest testBlobDigest = DescriptorDigest.FromHash( "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "testimage") .SetAllowInsecureRegistries(true) .NewRegistryClient(); Assert.IsFalse(await registryClient.PushBlobAsync(testBlobDigest, testBlob, null, _ => { }).ConfigureAwait(false)); }
public async Task TestAuthenticateAsync() { ImageReference dockerHubImageReference = ImageReference.Parse("library/busybox"); RegistryAuthenticator registryAuthenticator = await RegistryClient.CreateFactory( EventHandlers.NONE, dockerHubImageReference.GetRegistry(), dockerHubImageReference.GetRepository()) .NewRegistryClient() .GetRegistryAuthenticatorAsync().ConfigureAwait(false); Assert.IsNotNull(registryAuthenticator); Authorization authorization = await registryAuthenticator.AuthenticatePullAsync(null).ConfigureAwait(false); // Checks that some token was received. Assert.IsTrue(0 < authorization.GetToken().Length); }
public async Task TestPull_unknownManifestAsync() { localRegistry.PullAndPushToLocal("busybox", "busybox"); try { RegistryClient registryClient = RegistryClient.CreateFactory(EventHandlers.NONE, "localhost:5000", "busybox") .SetAllowInsecureRegistries(true) .NewRegistryClient(); await registryClient.PullManifestAsync("nonexistent-tag").ConfigureAwait(false); Assert.Fail("Trying to pull nonexistent image should have errored"); } catch (RegistryErrorException ex) { Assert.That(ex.Message, Does.Contain("pull image manifest for localhost:5000/busybox:nonexistent-tag")); } }
public void SetUp() { testRegistryClientFactory = RegistryClient.CreateFactory(eventHandlers, "some.server.url", "some image name"); }