Example #1
0
        public async Task WhenNoEnrollmentProvided_ThenDeviceCertiticateAuthenticationIsOff(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            var adapter = new ResourceManagerAdapter(await credential);

            Assert.IsFalse(adapter.IsDeviceCertiticateAuthenticationEnabled);
        }
Example #2
0
        public async Task WhenUserNotInRole_ThenIsGrantedPermissionReturnsFalse(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            var adapter = new ResourceManagerAdapter(await credential);

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                "compute.disks.create");

            Assert.IsFalse(result);
        }
Example #3
0
        public async Task WhenUserInRole_ThenIsGrantedPermissionReturnsTrue(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            var adapter = new ResourceManagerAdapter(await credential);

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                Permissions.ComputeInstancesGet);

            Assert.IsTrue(result);
        }
 public async Task WhenUserNotInRole_ThenGetProjectThrowsResourceAccessDeniedException(
     [Credential(Role = PredefinedRole.IapTunnelUser)] ResourceTask <ICredential> credential)
 {
     using (var adapter = new ResourceManagerAdapter(await credential))
     {
         AssertEx.ThrowsAggregateException <ResourceAccessDeniedException>(
             () => adapter.GetProjectAsync(
                 TestProject.ProjectId,
                 CancellationToken.None).Wait());
     }
 }
Example #5
0
        public async Task WhenUserInRole_ThenIsGrantedPermissionReturnsTrue(
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            var adapter = new ResourceManagerAdapter(await credential.GetCredentialAsync());

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                "compute.instances.get");

            Assert.IsTrue(result);
        }
        public async Task WhenUserInViewerRole_ThenGetProjectReturnsProject(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            using (var adapter = new ResourceManagerAdapter(await credential))
            {
                var project = await adapter.GetProjectAsync(
                    TestProject.ProjectId,
                    CancellationToken.None);

                Assert.IsNotNull(project);
                Assert.AreEqual(TestProject.ProjectId, project.ProjectId);
            }
        }
Example #7
0
        public async Task WhenProjectIdExists_ThenQueryProjectsByIdReturnsProject(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            using (var adapter = new ResourceManagerAdapter(await credential))
            {
                var project = await adapter.QueryProjectsById(
                    TestProject.ProjectId,
                    CancellationToken.None);

                Assert.IsNotNull(project);
                Assert.AreEqual(1, project.Count());
                Assert.AreEqual(TestProject.ProjectId, project.First().ProjectId);
            }
        }
        public async Task WhenUserNotInRole_ThenIsGrantedPermissionReturnsFalse(
            [LinuxInstance] InstanceRequest testInstance,
            [Credential(Role = PredefinedRole.ComputeViewer)] CredentialRequest credential)
        {
            await testInstance.AwaitReady();

            var instanceRef = await testInstance.GetInstanceAsync();

            var adapter = new ResourceManagerAdapter(await credential.GetCredentialAsync());

            var result = await adapter.IsGrantedPermission(
                TestProject.ProjectId,
                "iam.serviceAccounts.actAs");

            Assert.IsFalse(result);
        }
        public async Task WhenProjectIdExists_ThenQueryProjectsByIdReturnsProject(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            using (var adapter = new ResourceManagerAdapter(await credential))
            {
                var result = await adapter.ListProjects(
                    ProjectFilter.ByProjectId(TestProject.ProjectId),
                    null,
                    CancellationToken.None);

                Assert.IsNotNull(result);
                Assert.IsFalse(result.IsTruncated);
                Assert.AreEqual(1, result.Projects.Count());
                Assert.AreEqual(TestProject.ProjectId, result.Projects.First().ProjectId);
            }
        }
Example #10
0
        public async Task WhenProjectIdExists_ThenQueryProjectsByPrefixReturnsProject(
            [Credential(Role = PredefinedRole.ComputeViewer)] ResourceTask <ICredential> credential)
        {
            using (var adapter = new ResourceManagerAdapter(await credential))
            {
                // Remove last character from project ID.
                var prefix = TestProject.ProjectId.Substring(0, TestProject.ProjectId.Length - 1);

                var project = await adapter.QueryProjectsByPrefix(
                    prefix,
                    CancellationToken.None);

                Assert.IsNotNull(project);
                Assert.IsTrue(project.Any());
                CollectionAssert.Contains(
                    project.Select(p => p.ProjectId),
                    TestProject.ProjectId);
            }
        }
Example #11
0
        public void WhenEnrollmentProvided_ThenDeviceCertiticateAuthenticationIsOn()
        {
            var adapter = new ResourceManagerAdapter(CreateAuthorizationAdapterForSecureConnectUser());

            Assert.IsTrue(adapter.IsDeviceCertiticateAuthenticationEnabled);
        }