Esempio n. 1
0
        public void VerifyOwnership_ThrowsExceptionIfOwnerDoesNotMatch()
        {
            IListApplicationService service = new ListApplicationsService(null);

            Assert.ThrowsAsync <UnauthorizedException>(() => service.VerifyOwnership(new Application {
                User = "******"
            }, "user-id"));
        }
Esempio n. 2
0
        public async Task FindByOwnerIdsConvertsToLookupAndRemovesSecret()
        {
            var mockRepo    = new Mock <IListApplicationRepository>();
            var mockAppList = new List <Application>
            {
                new Application
                {
                    Id        = "1",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
                new Application
                {
                    Id        = "2",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
                new Application
                {
                    Id        = "3",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
                new Application
                {
                    Id        = "3",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
            };

            mockRepo.Setup(x => x.ListApplicationsByOwners(It.IsAny <IEnumerable <string> >())).ReturnsAsync(mockAppList);
            var service = new ListApplicationsService(mockRepo.Object);
            var apps    = await service.FindByOwnerIds(new[] { "user", "user1" });

            foreach (var application in apps["user"].ToList())
            {
                Assert.Null(application.Secret);
                Assert.AreEqual("user", application.User);
            }
            foreach (var application in apps["user1"].ToList())
            {
                Assert.Null(application.Secret);
                Assert.AreEqual("user1", application.User);
            }
        }
Esempio n. 3
0
        public async Task VerifyOwnership_ReturnsOriginalApplicationIfUserMatches()
        {
            IListApplicationService service = new ListApplicationsService(null);
            var mockApp = new Application
            {
                User = "******"
            };
            var app = await service.VerifyOwnership(mockApp, "user-id");

            Assert.AreSame(mockApp, app);
        }
Esempio n. 4
0
        public async Task FindByIds_RemovesSecret()
        {
            var mockRepo    = new Mock <IListApplicationRepository>();
            var mockAppList = new List <Application>
            {
                new Application
                {
                    Id        = "1",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
                new Application
                {
                    Id        = "2",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
                new Application
                {
                    Id        = "3",
                    Name      = "test-name",
                    Secret    = "secret",
                    User      = "******",
                    CreatedAt = DateTime.Now
                },
            };

            mockRepo.Setup(x => x.FindByIds(It.IsAny <IEnumerable <string> >())).ReturnsAsync(mockAppList);
            var service = new ListApplicationsService(mockRepo.Object);
            var apps    = await service.FindByIds(new[] { "1", "2", "3" });

            foreach (var application in apps.ToList())
            {
                Assert.Null(application.Value.Secret);
            }
        }