public ExternalUserAssociation Get(string issuer, string providerKey)
        {
            ExternalUserAssociation externalUserAssociation = null;

            _sqlObjectFactory.GetConnection().Using(connection =>
                                                    externalUserAssociation = connection.QuerySingleOrDefault <ExternalUserAssociation>("SELECT ExternalUserAssociationID, UserID, Issuer, ProviderKey, Name FROM pf_ExternalUserAssociation WHERE Issuer = @Issuer AND ProviderKey = @ProviderKey", new { Issuer = issuer, ProviderKey = providerKey }));
            return(externalUserAssociation);
        }
        public ExternalUserAssociation Get(int externalUserAssociationID)
        {
            ExternalUserAssociation externalUserAssociation = null;

            _sqlObjectFactory.GetConnection().Using(connection =>
                                                    externalUserAssociation = connection.QuerySingleOrDefault <ExternalUserAssociation>("SELECT ExternalUserAssociationID, UserID, Issuer, ProviderKey, Name FROM pf_ExternalUserAssociation WHERE ExternalUserAssociationID = @ExternalUserAssociationID", new { ExternalUserAssociationID = externalUserAssociationID }));
            return(externalUserAssociation);
        }
        public void GetExternalUserAssociationsThrowsIfAssociationDoesntMatchUser()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 456, UserID = 789
            };
            var user = new User();

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).Returns(association);

            Assert.Throws <Exception>(() => manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty));
        }
        public void RemoveAssociationThrowsIfUserIDsDontMatch()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 123, UserID = 456
            };
            var user = new User(789, DateTime.MaxValue);

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).Returns(association);

            Assert.Throws <Exception>(() => manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty));
        }
Exemplo n.º 5
0
        public async Task GetExternalUserAssociationsThrowsIfAssociationDoesntMatchUser()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 456, UserID = 789
            };
            var user = new User();

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).ReturnsAsync(association);

            await Assert.ThrowsAsync <Exception>(async() => await manager.RemoveAssociation(user, association.ExternalUserAssociationID, string.Empty));
        }
        public void GetExternalUserAssociationsCallsRepoWithMatchingUserIDs()
        {
            var manager     = GetManager();
            var user        = new User(123, DateTime.MaxValue);
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 456, UserID = user.UserID
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).Returns(association);

            manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty);

            _externalUserAssociationRepo.Verify(x => x.Delete(association.ExternalUserAssociationID), Times.Once());
        }
        public void RemoveAssociationCallsRepoOnSuccessfulMatch()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 123, UserID = 456
            };
            var user = new User(association.UserID, DateTime.MaxValue);

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).Returns(association);

            manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty);

            _externalUserAssociationRepo.Verify(x => x.Delete(association.ExternalUserAssociationID), Times.Once());
        }
        public void RemoveAssociationLogsTheRemoval()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 123, Issuer = "Google", Name = "Jeffy", ProviderKey = "oihfoihfef", UserID = 456
            };
            var          user = new User(association.UserID, DateTime.MaxValue);
            const string ip   = "1.1.1.1";

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).Returns(association);

            manager.RemoveAssociation(user, association.ExternalUserAssociationID, ip);

            _securityLogService.Verify(x => x.CreateLogEntry(user, user, ip, It.IsAny <string>(), SecurityLogType.ExternalAssociationRemoved), Times.Once());
        }
Exemplo n.º 9
0
        public async Task RemoveAssociationCallsRepoOnSuccessfulMatch()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 123, UserID = 456
            };
            var user = new User {
                UserID = association.UserID
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).ReturnsAsync(association);

            await manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty);

            _externalUserAssociationRepo.Verify(x => x.Delete(association.ExternalUserAssociationID), Times.Once());
        }
Exemplo n.º 10
0
        public async Task ExternalUserAssociationCheckResultFalseNoUserCallsSecurityLog()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                Issuer = "Google", UserID = 123, ProviderKey = "abc"
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.Issuer, association.ProviderKey)).ReturnsAsync(association);
            _userRepo.Setup(x => x.GetUser(association.UserID)).ReturnsAsync((User)null);
            const string ip         = "1.1.1.1";
            var          authResult = new ExternalLoginInfo("Google", "abc", "");

            await manager.ExternalUserAssociationCheck(authResult, ip);

            _securityLogService.Verify(x => x.CreateLogEntry((int?)null, null, ip, It.IsAny <string>(), SecurityLogType.ExternalAssociationCheckFailed), Times.Once());
        }
Exemplo n.º 11
0
        public async Task GetExternalUserAssociationsCallsRepoWithMatchingUserIDs()
        {
            var manager = GetManager();
            var user    = new User {
                UserID = 123
            };
            var association = new ExternalUserAssociation {
                ExternalUserAssociationID = 456, UserID = user.UserID
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.ExternalUserAssociationID)).ReturnsAsync(association);

            await manager.RemoveAssociation(user, association.ExternalUserAssociationID, String.Empty);

            _externalUserAssociationRepo.Verify(x => x.Delete(association.ExternalUserAssociationID), Times.Once());
        }
        public ExternalUserAssociation Get(int externalUserAssociationID)
        {
            ExternalUserAssociation externalUserAssociation = null;

            _sqlObjectFactory.GetConnection().Using(connection => connection.Command(_sqlObjectFactory, "SELECT ExternalUserAssociationID, UserID, Issuer, ProviderKey, Name FROM pf_ExternalUserAssociation WHERE ExternalUserAssociationID = @ExternalUserAssociationID")
                                                    .AddParameter(_sqlObjectFactory, "@ExternalUserAssociationID", externalUserAssociationID)
                                                    .ExecuteReader()
                                                    .ReadOne(r => externalUserAssociation = new ExternalUserAssociation
            {
                ExternalUserAssociationID = r.GetInt32(0),
                UserID      = r.GetInt32(1),
                Issuer      = r.GetString(2),
                ProviderKey = r.GetString(3),
                Name        = r.GetString(4)
            }));
            return(externalUserAssociation);
        }
Exemplo n.º 13
0
        public ExternalUserAssociation Get(string issuer, string providerKey)
        {
            ExternalUserAssociation externalUserAssociation = null;

            _sqlObjectFactory.GetConnection().Using(connection => connection.Command("SELECT ExternalUserAssociationID, UserID, Issuer, ProviderKey, Name FROM pf_ExternalUserAssociation WHERE Issuer = @Issuer AND ProviderKey = @ProviderKey")
                                                    .AddParameter("@Issuer", issuer)
                                                    .AddParameter("@ProviderKey", providerKey)
                                                    .ExecuteReader()
                                                    .ReadOne(r => externalUserAssociation = new ExternalUserAssociation
            {
                ExternalUserAssociationID = r.GetInt32(0),
                UserID      = r.GetInt32(1),
                Issuer      = r.GetString(2),
                ProviderKey = r.GetString(3),
                Name        = r.GetString(4)
            }));
            return(externalUserAssociation);
        }
Exemplo n.º 14
0
        public async Task ExternalUserAssociationCheckResultTrueCallsSecurityLog()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                Issuer = "Google", UserID = 123, ProviderKey = "abc"
            };
            var user = new User {
                UserID = association.UserID
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.Issuer, association.ProviderKey)).ReturnsAsync(association);
            _userRepo.Setup(x => x.GetUser(association.UserID)).ReturnsAsync(user);
            const string ip         = "1.1.1.1";
            var          authResult = new ExternalLoginInfo("Google", "abc", "");

            await manager.ExternalUserAssociationCheck(authResult, ip);

            _securityLogService.Verify(x => x.CreateLogEntry(user, user, ip, It.IsAny <string>(), SecurityLogType.ExternalAssociationCheckSuccessful));
        }
        public void ExternalUserAssociationCheckResultTrueCallsSecurityLog()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                Issuer = "Google", UserID = 123, ProviderKey = "abc"
            };
            var user = new User(association.UserID, DateTime.MinValue);

            _externalUserAssociationRepo.Setup(x => x.Get(association.Issuer, association.ProviderKey)).Returns(association);
            _userRepo.Setup(x => x.GetUser(association.UserID)).Returns(user);
            const string ip         = "1.1.1.1";
            var          authResult = new ExternalAuthenticationResult {
                Issuer = "Google", ProviderKey = "abc"
            };

            manager.ExternalUserAssociationCheck(authResult, ip);

            _securityLogService.Verify(x => x.CreateLogEntry(user, user, ip, It.IsAny <string>(), SecurityLogType.ExternalAssociationCheckSuccessful));
        }
        public void ExternalUserAssociationCheckResultTrueWithHydratedResultIfMatchingAssociationAndUser()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                Issuer = "Google", UserID = 123, ProviderKey = "abc"
            };
            var user = new User(association.UserID, DateTime.MinValue);

            _externalUserAssociationRepo.Setup(x => x.Get(association.Issuer, association.ProviderKey)).Returns(association);
            _userRepo.Setup(x => x.GetUser(association.UserID)).Returns(user);
            var authResult = new ExternalAuthenticationResult {
                Issuer = "Google", ProviderKey = "abc"
            };

            var result = manager.ExternalUserAssociationCheck(authResult, "");

            Assert.True(result.Successful);
            Assert.Same(user, result.User);
            Assert.Same(association, result.ExternalUserAssociation);
        }
Exemplo n.º 17
0
        public async Task ExternalUserAssociationCheckResultTrueWithHydratedResultIfMatchingAssociationAndUser()
        {
            var manager     = GetManager();
            var association = new ExternalUserAssociation {
                Issuer = "Google", UserID = 123, ProviderKey = "abc"
            };
            var user = new User {
                UserID = association.UserID
            };

            _externalUserAssociationRepo.Setup(x => x.Get(association.Issuer, association.ProviderKey)).ReturnsAsync(association);
            _userRepo.Setup(x => x.GetUser(association.UserID)).ReturnsAsync(user);
            var authResult = new ExternalLoginInfo("Google", "abc", "");

            var result = await manager.ExternalUserAssociationCheck(authResult, "");

            Assert.True(result.Successful);
            Assert.Same(user, result.User);
            Assert.Same(association, result.ExternalUserAssociation);
        }