public void Setup() { _identityFacade = new Mock <IIdentityFacade>(); _postRepository = new Mock <IBlogRepository>(); _accessValidator = new AccessValidator(_identityFacade.Object, _postRepository.Object); _user1 = new ApplicationUser() { Id = "1", UserName = "******" }; _post1 = new Post() { Id = 1, Author = "Shrek", AuthorId = "1", Content = "lol", SubTitle = "ultralol" }; _comment1 = new Comment() { Id = 1, AuthorId = "1" }; _postRepository.Setup(x => x.GetPost(It.IsAny <int>())).Returns(_post1); _postRepository.Setup(x => x.GetComment(It.IsAny <int>())).Returns(_comment1); _identityFacade.Setup(x => x.GetUserId()).Returns(_user1.Id); //getcomment //getuserid }
//[ValidateAntiForgeryToken] public async Task <ActionResult> GuestLogin(string guestUser, string returnUrl) { //if (!ModelState.IsValid) //{ // return View(model); //} var model = AccessValidator.GuestLogin(guestUser); // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: return(RedirectToLocal(returnUrl)); case SignInStatus.LockedOut: return(View("Lockout")); case SignInStatus.RequiresVerification: return(RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe })); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return(View(model)); } }
public DeleteAnswerCommandHandlerTests() { _mockAnswerRepository = new Mock <IAnswerRepository>(); _mockCurrentUserService = new Mock <ICurrentUserService>(); var accessValidator = new AccessValidator(); _handler = new DeleteAnswerCommandHandler( _mockCurrentUserService.Object, _mockAnswerRepository.Object, accessValidator); }
public void Setup() { _currentUserProviderMock = new Mock <ICurrentUserProvider>(); _projectAccessCheckerMock = new Mock <IProjectAccessChecker>(); _contentRestrictionsCheckerMock = new Mock <IContentRestrictionsChecker>(); _projectAccessCheckerMock.Setup(p => p.HasCurrentUserAccessToProject(ProjectWithoutAccess)).Returns(false); _projectAccessCheckerMock.Setup(p => p.HasCurrentUserAccessToProject(ProjectWithAccess)).Returns(true); _contentRestrictionsCheckerMock.Setup(c => c.HasCurrentUserExplicitNoRestrictions()).Returns(true); _contentRestrictionsCheckerMock.Setup(c => c.HasCurrentUserExplicitAccessToContent(RestrictedToContent)).Returns(false); _loggerMock = new Mock <ILogger <AccessValidator> >(); _dut = new AccessValidator( _currentUserProviderMock.Object, _projectAccessCheckerMock.Object, _contentRestrictionsCheckerMock.Object, _loggerMock.Object); }
public void Setup() { _currentUserProviderMock = new Mock <ICurrentUserProvider>(); _projectAccessCheckerMock = new Mock <IProjectAccessChecker>(); _projectAccessCheckerMock.Setup(p => p.HasCurrentUserAccessToProject(_projectWithoutAccess)).Returns(false); _projectAccessCheckerMock.Setup(p => p.HasCurrentUserAccessToProject(_projectWithAccess)).Returns(true); var invitationHelperMock = new Mock <IInvitationHelper>(); invitationHelperMock.Setup(p => p.GetProjectNameAsync(_invitationIdWithAccessToProject)) .Returns(Task.FromResult(_projectWithAccess)); invitationHelperMock.Setup(p => p.GetProjectNameAsync(_invitationIdWithoutAccessToProject)) .Returns(Task.FromResult(_projectWithoutAccess)); _loggerMock = new Mock <ILogger <AccessValidator> >(); _dut = new AccessValidator( _currentUserProviderMock.Object, _projectAccessCheckerMock.Object, invitationHelperMock.Object, _loggerMock.Object); }
private DirectoryInfo DifferencePartialParallelCopy(DirectoryInfo source, DirectoryInfo target, LogOptions _logOptions, ParallelOptions _po) { DirectoryInfo newDirectoryInfo = null; try { newDirectoryInfo = target; OnAtomicCurrent?.Invoke(this, new StringEventArgs(source.FullName)); } catch (Exception Ex) { Logger.log(newDirectoryInfo.FullName, Ex.Message, _logOptions); } try { Parallel.ForEach(source.GetFiles(), _po, (fileInfo, state) => { OnAtomicCurrent?.Invoke(this, new StringEventArgs(fileInfo.FullName)); _po.CancellationToken.ThrowIfCancellationRequested(); if (_po.CancellationToken.IsCancellationRequested) { state.Break(); } try { if (fileInfo.Exists && ((File.GetAttributes(fileInfo.FullName) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) && AccessViolationHelper.IsNotLocked(fileInfo.FullName, _logOptions)) { if (AccessValidator.CanRead(fileInfo.FullName)) { var _targetpath = Path.Combine(newDirectoryInfo.FullName, fileInfo.Name); if (File.Exists(_targetpath)) { if (IsSourceNewer(fileInfo.FullName, _targetpath)) { fileInfo.CopyTo(_targetpath, true); File.SetAttributes(_targetpath, FileAttributes.Normal); } } else { fileInfo.CopyTo(_targetpath, true); File.SetAttributes(_targetpath, FileAttributes.Normal); } } else { Logger.log(fileInfo.FullName, "Access Denied", _logOptions); } } } catch (Exception Ex) { try { Logger.log(fileInfo.FullName, Ex.Message, _logOptions); } catch (Exception) { throw; } } }); } catch (OperationCanceledException) { throw; } foreach (DirectoryInfo childDirectoryInfo in source.GetDirectories()) { if (_po.CancellationToken.IsCancellationRequested) { _po.CancellationToken.ThrowIfCancellationRequested(); } try { if (childDirectoryInfo.Exists && (childDirectoryInfo.Attributes & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) { newDirectoryInfo = target.CreateSubdirectory(childDirectoryInfo.Name); DifferencePartialParallelCopy(childDirectoryInfo, newDirectoryInfo, _logOptions, _po); } else { Logger.log(childDirectoryInfo.FullName, "Reparse Point / Hard Link", _logOptions); } } catch (Exception Ex) { try { if (!Ex.Message.Contains("The operation was canceled.")) { Logger.log(childDirectoryInfo.FullName, Ex.Message, _logOptions); } continue; } catch (Exception) { throw; } } } return(newDirectoryInfo); }
private DirectoryInfo CopyRecursive(DirectoryInfo source, DirectoryInfo target, LogOptions _logOptions, CancellationToken token) { DirectoryInfo newDirectoryInfo = null; if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } try { newDirectoryInfo = target; OnAtomicCurrent?.Invoke(this, new StringEventArgs(source.FullName)); } catch (Exception Ex) { Logger.log(newDirectoryInfo.FullName, Ex.Message, _logOptions); } foreach (var fileInfo in source.GetFiles()) { OnAtomicCurrent?.Invoke(this, new StringEventArgs(fileInfo.FullName)); if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } try { if (fileInfo.Exists && ((File.GetAttributes(fileInfo.FullName) & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) && AccessViolationHelper.IsNotLocked(fileInfo.FullName, _logOptions)) { if (AccessValidator.CanRead(fileInfo.FullName)) { var _targetpath = Path.Combine(newDirectoryInfo.FullName, fileInfo.Name); fileInfo.CopyTo(_targetpath, true); File.SetAttributes(_targetpath, FileAttributes.Normal); } else { Logger.log(fileInfo.FullName, "Access Denied", _logOptions); } } } catch (OperationCanceledException) { throw; } catch (Exception Ex) { try { if (!Ex.Message.Contains("The operation was canceled.")) { Logger.log(fileInfo.FullName, Ex.Message, _logOptions); } else { break; } continue; } catch (Exception) { throw; } } } foreach (var childDirectoryInfo in source.GetDirectories()) { if (token.IsCancellationRequested) { token.ThrowIfCancellationRequested(); } try { if (childDirectoryInfo.Exists && (childDirectoryInfo.Attributes & FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint) { newDirectoryInfo = target.CreateSubdirectory(childDirectoryInfo.Name); CopyRecursive(childDirectoryInfo, newDirectoryInfo, _logOptions, token); } else { Logger.log(childDirectoryInfo.FullName, "Reparse Point / Hard Link", _logOptions); } } catch (OperationCanceledException) { throw; } catch (Exception Ex) { try { if (!Ex.Message.Contains("The operation was canceled.")) { Logger.log(childDirectoryInfo.FullName, Ex.Message, _logOptions); } else { break; } continue; } catch (Exception) { throw; } } } return(newDirectoryInfo); }
//创建访问验证对象并调用其Validate()方法实现身份验证 public bool Validate(string userId) { validator = new AccessValidator(); return(validator.Validate(userId)); }