Пример #1
0
        public async Task UpdateAcrTagAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrTagAttributesMR)))
            {
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var tag    = "latest";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                await client.UpdateAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag, updateAttributes);

                var tagAttributes = await client.GetAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag);

                Assert.False(tagAttributes.TagAttributes.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag, updateAttributes);

                tagAttributes = await client.GetAcrTagAttributesAsync(ACRTestUtil.ProdRepository, tag);

                Assert.True(tagAttributes.TagAttributes.ChangeableAttributes.WriteEnabled);
            }
        }
Пример #2
0
        public async Task UpdateAcrManifestAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrManifestAttributesMR)))
            {
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var digest = "sha256:eabe547f78d4c18c708dd97ec3166cf7464cc651f1cbb67e70d407405b7ad7b6";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                await client.UpdateAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest, updateAttributes);

                var updatedManifest = await client.GetAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest);

                Assert.False(updatedManifest.Manifest.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest, updateAttributes);

                updatedManifest = await client.GetAcrManifestAttributesAsync(ACRTestUtil.ProdRepository, digest);

                Assert.Equal(ExpectedAttributesOfProdRepository.ImageName, updatedManifest.ImageName);
                Assert.Equal(ExpectedAttributesOfProdRepository.Registry, updatedManifest.Registry);
                VerifyAcrManifestAttributesBase(ExpectedAttributesOfProdRepository.Manifest, updatedManifest.Manifest);
            }
        }
Пример #3
0
        public async Task GetManifestMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(GetManifestMR)))
            {
                var tag    = "latest";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var manifest = await client.GetManifestAsync(ACRTestUtil.TestRepository, tag);

                Assert.Equal(1, manifest.SchemaVersion);
                Assert.Equal(ACRTestUtil.TestRepository, manifest.Name);
                Assert.Equal(tag, manifest.Tag);
                Assert.Equal("amd64", manifest.Architecture);
                Assert.Equal(10, manifest.FsLayers.Count);
                Assert.Equal(10, manifest.ImageHistories.Count);
                Assert.Equal(1, manifest.Signatures.Count);
                var signature = manifest.Signatures[0];
                Assert.NotEqual(string.Empty, signature.ProtectedHeader);
                Assert.NotEqual(string.Empty, signature.Signature);
                Assert.Equal("P-256", signature.Header.Jwk.Crv);
                Assert.NotEqual(string.Empty, signature.Header.Jwk.Kid);
                Assert.Equal("EC", signature.Header.Jwk.Kty);
                Assert.NotEqual(string.Empty, signature.Header.Jwk.X);
                Assert.NotEqual(string.Empty, signature.Header.Jwk.Y);
            }
        }
Пример #4
0
        public async Task UpdateAcrManifestAttributes()
        {
            using (var context = MockContext.Start(GetType(), nameof(UpdateAcrManifestAttributes)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                var digest = "sha256:dbefd3c583a226ddcef02536cd761d2d86dc7e6f21c53f83957736d6246e9ed8";

                //Update attributes
                await client.Manifests.UpdateAttributesAsync(ACRTestUtil.changeableRepository, digest, updateAttributes);

                var updatedManifest = await client.Manifests.GetAttributesAsync(ACRTestUtil.changeableRepository, digest);

                //Check for success
                Assert.False(updatedManifest.Attributes.ChangeableAttributes.WriteEnabled);

                //Return attributes to original
                updateAttributes.WriteEnabled = true;
                await client.Manifests.UpdateAttributesAsync(ACRTestUtil.changeableRepository, digest, updateAttributes);

                updatedManifest = await client.Manifests.GetAttributesAsync(ACRTestUtil.changeableRepository, digest);

                Assert.Equal(ExpectedAttributesChangeableRepository.ImageName, updatedManifest.ImageName);
                Assert.Equal(ExpectedAttributesChangeableRepository.Registry, updatedManifest.Registry);
                VerifyAcrManifestAttributesBase(ExpectedAttributesChangeableRepository.Attributes, updatedManifest.Attributes);
            }
        }
Пример #5
0
        public async Task UpdateAcrRepositoryAttributes()
        {
            using (var context = MockContext.Start(GetType(), nameof(UpdateAcrRepositoryAttributes)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                //Changeable attributes
                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = false, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                await client.Repository.UpdateAttributesAsync(ACRTestUtil.changeableRepository, updateAttributes);

                var repositoryDetails = await client.Repository.GetAttributesAsync(ACRTestUtil.changeableRepository);

                //Undo change in remote (in case this fails)
                updateAttributes.WriteEnabled  = true;
                updateAttributes.DeleteEnabled = true;
                await client.Repository.UpdateAttributesAsync(ACRTestUtil.changeableRepository, updateAttributes);

                //Check success
                Assert.Equal(1, repositoryDetails.TagCount);
                Assert.Equal(1, repositoryDetails.ManifestCount);
                Assert.Equal(ACRTestUtil.changeableRepository, repositoryDetails.ImageName);
                Assert.False(repositoryDetails.ChangeableAttributes.DeleteEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ListEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ReadEnabled);
                Assert.False(repositoryDetails.ChangeableAttributes.WriteEnabled);
            }
        }
Пример #6
0
        public async Task UpdateAcrRepositoryAttributesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrRepositoryAttributesMR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var updateAttributes = new ChangeableAttributes()
                {
                    DeleteEnabled = true, ListEnabled = true, ReadEnabled = true, WriteEnabled = false
                };
                await client.UpdateAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository, updateAttributes);

                var repositoryDetails = await client.GetAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(ACRTestUtil.ManagedTestRegistryFullName, repositoryDetails.Registry);
                Assert.Equal(1, repositoryDetails.TagCount);
                Assert.Equal(1, repositoryDetails.ManifestCount);
                Assert.Equal("2018-09-28T23:37:52.0356217Z", repositoryDetails.LastUpdateTime);
                Assert.Equal("2018-09-28T23:37:51.9668212Z", repositoryDetails.CreatedTime);
                Assert.Equal(ACRTestUtil.ProdRepository, repositoryDetails.ImageName);
                Assert.True(repositoryDetails.ChangeableAttributes.DeleteEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ListEnabled);
                Assert.True(repositoryDetails.ChangeableAttributes.ReadEnabled);
                Assert.False(repositoryDetails.ChangeableAttributes.WriteEnabled);

                updateAttributes.WriteEnabled = true;
                await client.UpdateAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository, updateAttributes);
            }
        }
Пример #7
0
        public async Task DeleteAcrRepository()
        {
            using (var context = MockContext.Start(GetType(), nameof(DeleteAcrRepository)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                var repositories = await client.Repository.GetListAsync();

                //Selects one of the previously stored hello-world repositories for deletion
                string deletableRepo = "";
                foreach (var repo in repositories.Names)
                {
                    if (repo.StartsWith("hello-world"))
                    {
                        deletableRepo = repo;
                        continue;
                    }
                }
                var deletedRepo = await client.Repository.DeleteAsync(deletableRepo);

                Assert.Equal(1, deletedRepo.ManifestsDeleted.Count);
                Assert.Equal("sha256:92c7f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e899a", deletedRepo.ManifestsDeleted[0]);
                Assert.Equal(1, deletedRepo.TagsDeleted.Count);
                Assert.Collection(deletedRepo.TagsDeleted, tag => Assert.Equal("latest", tag));
            }
        }
Пример #8
0
        public async Task DeleteAcrTagCRThrowException()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(DeleteAcrTagCRThrowException)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                await Assert.ThrowsAsync <AcrErrorsException>(() => client.DeleteAcrTagAsync(ACRTestUtil.ProdRepository, "latest"));
            }
        }
Пример #9
0
        public async Task GetAcrRepositoriesCRThrowException()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(GetAcrRepositoriesCRThrowException)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                await Assert.ThrowsAsync <AcrErrorsException>(() => client.GetAcrRepositoriesAsync());
            }
        }
Пример #10
0
        public async Task GetAcrRepositoryDetailsCRThrowException()
        {
            using (var context = MockContext.Start(this.GetType(), nameof(GetAcrRepositoryDetailsCRThrowException)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                await Assert.ThrowsAsync <AcrErrorsException>(() => client.GetAcrRepositoryAttributesAsync(ACRTestUtil.ProdRepository));
            }
        }
Пример #11
0
        public async Task DeleteAcrRepositoryCRThrowException()
        {
            using (var context = MockContext.Start(this.GetType(), nameof(DeleteAcrRepositoryCRThrowException)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistryForDeleting);

                await Assert.ThrowsAsync <AcrErrorsException>(() => client.DeleteAcrRepositoryAsync("prod/bash"));
            }
        }
Пример #12
0
        public async Task UpdateAcrTagAttributesCRThrowException()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(UpdateAcrTagAttributesCRThrowException)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                await Assert.ThrowsAsync <AcrErrorsException>(() => client.UpdateAcrTagAttributesAsync(ACRTestUtil.ProdRepository, "latest", default(ChangeableAttributes)));
            }
        }
Пример #13
0
        public async Task GetAcrAccessTokenFromLogin()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetAcrAccessTokenFromLogin)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var accessToken = await client.AccessTokens.GetFromLoginAsync(ACRTestUtil.ManagedTestRegistryFullName, ACRTestUtil.Scope);

                ValidateAccessToken(accessToken.AccessTokenProperty);
            }
        }
Пример #14
0
        public async Task GetAcrRefreshTokenFromExchange()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetAcrRefreshTokenFromExchange)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var refreshToken = await client.RefreshTokens.GetFromExchangeAsync("access_token", ACRTestUtil.ManagedTestRegistryFullName, null, null, await ACRTestUtil.GetAADAccessToken());

                ValidateRefreshToken(refreshToken.RefreshTokenProperty);
            }
        }
Пример #15
0
        public async Task CancelBlobUpload()
        {
            using (var context = MockContext.Start(GetType(), nameof(CancelBlobUpload)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                var uploadInfo = await client.Blob.StartUploadAsync(ACRTestUtil.changeableRepository);

                await client.Blob.CancelUploadAsync(uploadInfo.Location);
            }
        }
Пример #16
0
        public async Task GetAcrManifestAttributesCRReturnsNull()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(GetAcrManifestAttributesCRReturnsNull)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                var manifestAttributes = await client.GetAcrManifestAttributesAsync(ACRTestUtil.ProdRepository,
                                                                                    "sha256:eabe547f78d4c18c708dd97ec3166cf7464cc651f1cbb67e70d407405b7ad7b6");

                Assert.Null(manifestAttributes);
            }
        }
Пример #17
0
        public async Task CheckBlob()
        {
            using (var context = MockContext.Start(GetType(), nameof(CheckBlob)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var blob = await client.Blob.CheckAsync(ACRTestUtil.ProdRepository, ProdConfigBlobDigest);

                Assert.Equal(blob.DockerContentDigest, ProdConfigBlobDigest);
                Assert.Equal(5635, blob.ContentLength);
            }
        }
Пример #18
0
        public async Task CheckBlobChunk()
        {
            using (var context = MockContext.Start(GetType(), nameof(CheckBlobChunk)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var blobData = await client.Blob.CheckChunkAsync(ACRTestUtil.ProdRepository, ProdConfigBlobDigest, "bytes=0-300");

                //Range is actually ignored in this request. Ends up working quite similarly to CheckBlob
                Assert.Equal(5635, blobData.ContentLength);
            }
        }
Пример #19
0
        public async Task GetV2Manifest()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetV2Manifest)))
            {
                var tag    = "latest";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var manifest = (V2Manifest)await client.Manifests.GetAsync(ACRTestUtil.TestRepository, tag, ACRTestUtil.MediatypeV2Manifest);

                VerifyManifest(ExpectedV2ManifestProd, manifest);
            }
        }
Пример #20
0
        public async Task GetOCIIndex()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetOCIIndex)))
            {
                var tag    = "oci";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var manifest = (OCIIndex)await client.Manifests.GetAsync(ACRTestUtil.ManifestListTestRepository, tag, ACRTestUtil.MediatypeOCIIndex);

                VerifyManifest(ExpectedOCIIndex, manifest);
            }
        }
Пример #21
0
        public async Task MoreScopeTests(string headerValue, string expectedScope)
        {
            using (var context = MockContext.Start(GetType(), nameof(MoreScopeTests)))
            {
                var _httpRequest = new HttpRequestMessage();
                _httpRequest.Headers.Add("Www-Authenticate", headerValue);

                var client = await ACRTestUtil.GetCredentialsAsync(context, ACRTestUtil.ManagedTestRegistryForChanges);

                string actualScope = client.GetScopeFromHeaders(_httpRequest.Headers);
                Assert.Equal(expectedScope, actualScope);
            }
        }
Пример #22
0
        public async Task DeleteAcrTagMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(DeleteAcrTagMR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistryForDeleting);

                await client.DeleteAcrTagAsync(ACRTestUtil.ProdRepository, "latest");

                var tags = await client.GetTagListAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(0, tags.Tags.Count);
            }
        }
Пример #23
0
        public async Task GetTagsCR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(GetTagsCR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                var tags = await client.GetTagListAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(1, tags.Tags.Count);
                Assert.Equal("latest", tags.Tags[0]);
                Assert.Equal(ACRTestUtil.ProdRepository, tags.Name);
            }
        }
Пример #24
0
        public async Task GetTags()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetTags)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var tags = await client.Tag.GetListAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(2, tags.Tags.Count);
                Assert.Equal("latest", tags.Tags[1].Name);
                Assert.Equal(ACRTestUtil.ProdRepository, tags.ImageName);
            }
        }
Пример #25
0
        public async Task ListRepositoryCR()
        {
            using (var context = MockContext.Start(this.GetType(), nameof(ListRepositoryCR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ClassicTestRegistry);

                var repositories = await client.GetRepositoriesAsync();

                Assert.Equal(2, repositories.Names.Count);
                Assert.Collection(repositories.Names, name => Assert.Equal(ACRTestUtil.ProdRepository, name),
                                  name => Assert.Equal(ACRTestUtil.TestRepository, name));
            }
        }
Пример #26
0
        public async Task GetAcrRepositoriesMR()
        {
            using (var context = MockContext.Start(GetType().FullName, nameof(GetAcrRepositoriesMR)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var repositories = await client.GetAcrRepositoriesAsync();

                Assert.Equal(2, repositories.Names.Count);
                Assert.Collection(repositories.Names, name => Assert.Equal(ACRTestUtil.ProdRepository, name),
                                  name => Assert.Equal(ACRTestUtil.TestRepository, name));
            }
        }
Пример #27
0
        public async Task GetBlob()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetBlob)))
            {
                AzureContainerRegistryClient client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                Stream blob = await client.Blob.GetAsync(ACRTestUtil.ProdRepository, ProdConfigBlobDigest);

                StreamReader reader       = new StreamReader(blob, Encoding.UTF8);
                string       originalBlob = reader.ReadToEnd();
                Assert.Equal(ProdConfigBlob, originalBlob);
            }
        }
Пример #28
0
        public async Task CreateManifestList()
        {
            using (var context = MockContext.Start(GetType(), nameof(CreateManifestList)))
            {
                var tag    = "test-manifest-list";
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                await client.Manifests.CreateAsync(ACRTestUtil.ManifestListTestRepository, tag, ExpectedManifestList);

                var manifest = (ManifestList)await client.Manifests.GetAsync(ACRTestUtil.ManifestListTestRepository, tag, ACRTestUtil.MediatypeManifestList);

                VerifyManifest(ExpectedManifestList, manifest);
            }
        }
Пример #29
0
        public async Task GetAcrManifests()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetAcrManifests)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var manifests = await client.Manifests.GetListAsync(ACRTestUtil.ProdRepository);

                Assert.Equal(ExpectedAttributesOfProdRepository.ImageName, manifests.ImageName);
                Assert.Equal(ExpectedAttributesOfProdRepository.Registry, manifests.Registry);
                Assert.Equal(2, manifests.ManifestsAttributes.Count);
                VerifyAcrManifestAttributesBase(ExpectedAttributesOfProdRepository.Attributes, manifests.ManifestsAttributes[1]);
            }
        }
Пример #30
0
        public async Task GetAcrManifestAttributes()
        {
            using (var context = MockContext.Start(GetType(), nameof(GetAcrManifestAttributes)))
            {
                var client = await ACRTestUtil.GetACRClientAsync(context, ACRTestUtil.ManagedTestRegistry);

                var repositoryAttributes = await client.Manifests.GetAttributesAsync(ACRTestUtil.ProdRepository,
                                                                                     "sha256:dbefd3c583a226ddcef02536cd761d2d86dc7e6f21c53f83957736d6246e9ed8");

                Assert.Equal(ExpectedAttributesOfProdRepository.ImageName, repositoryAttributes.ImageName);
                Assert.Equal(ExpectedAttributesOfProdRepository.Registry, repositoryAttributes.Registry);
                VerifyAcrManifestAttributesBase(ExpectedAttributesOfProdRepository.Attributes, repositoryAttributes.Attributes);
            }
        }