public void NotAuthorizedException_Constructor_01_NullMessage() { // Arrange // Act var exception = new NotAuthorizedException(null); // Assert exception.Message.Should().Be("User is not authorized to perform this action."); }
public void NotAuthorizedException_Base_Constructor() { // Arrange // Act var exception = new NotAuthorizedException(); // Assert exception.Message.Should().Be("Exception of type 'Pims.Dal.Exceptions.NotAuthorizedException' was thrown."); }
public void NotAuthorizedException_Constructor_01() { // Arrange var msg = "test"; // Act var exception = new NotAuthorizedException(msg); // Assert exception.Message.Should().Be(msg); }
private void CheckAuthorisation() { if (DesignMode) { return; } var type = GetType(); var attributes = type.GetCustomAttributes(AuthorisationType, true) .OfType <AuthorisationAttribute>(); foreach (var attribute in attributes) { if (!attribute.IsAuthorized()) { switch (UnauthorizedResult) { case UnauthorizedFormResult.Nothing: break; case UnauthorizedFormResult.Disable: Enabled = false; break; case UnauthorizedFormResult.Hide: Visible = false; WinApi.SuspendDrawing(this); break; case UnauthorizedFormResult.Exception: var exception = new NotAuthorizedException(type); var args = new HandledEventArgs(); OnAuthorisationFailed(exception, args); if (!args.Handled) { throw exception; } break; default: throw new ArgumentOutOfRangeException(); } } else if (UnauthorizedResult == UnauthorizedFormResult.Hide) { Visible = true; WinApi.ResumeDrawing(this); } else if (UnauthorizedResult == UnauthorizedFormResult.Disable) { Enabled = true; } } }
private void RenderHttpException(NotAuthorizedException ex) { DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "<p><b>Permission error</b></p>" + ex.Message.Replace("\n", "<br />"), DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.RedError); if (LogContext.IsLogActive) { var logKey = "Error accessing data"; LogContext.Log(ModuleContext.ModuleId, logKey, "Error", ex.MessageAsList()); //LogContext.Log(logKey, "StackTrace", ex.StackTrace); //DotNetNuke.UI.Skins.Skin.AddModuleMessage(this, "<p>More info is availale on de browser console (F12)</p>", DotNetNuke.UI.Skins.Controls.ModuleMessage.ModuleMessageType.BlueInfo); } LoggingUtils.ProcessLogFileException(this, ex); }
public void NotAuthorizedException_Constructor_02_NullMessage() { // Arrange var error = new Exception("inner"); // Act var exception = new NotAuthorizedException(null, error); // Assert exception.Message.Should().Be("User is not authorized to perform this action."); exception.InnerException.Should().Be(error); }
public void NotAuthorizedException_Constructor_02() { // Arrange var msg = "test"; var error = new Exception("inner"); // Act var exception = new NotAuthorizedException(msg, error); // Assert exception.Message.Should().Be(msg); exception.InnerException.Should().Be(error); }
private Exception CatchException(Exception ex) { throw ex switch { UsernameExistsException _ => new BusinessException(ErrorCode.UsernameAlreadyExists, ex), NotAuthorizedException _ => new BusinessException(ErrorCode.NotAuthorized, ex), TooManyRequestsException _ => new BusinessException(ErrorCode.TooManyRequests, ex), PasswordResetRequiredException _ => new BusinessException(ErrorCode.PasswordResetRequired, ex), UserNotFoundException _ => new BusinessException(ErrorCode.UserNotFound, ex), UserNotConfirmedException _ => new BusinessException(ErrorCode.UserNotConfirmed, ex), InvalidPasswordException _ => new BusinessException(ErrorCode.InvalidPassword, ex), CodeMismatchException _ => new BusinessException(ErrorCode.CodeMismatch, ex), ExpiredCodeException _ => new BusinessException(ErrorCode.ExpiredCode, ex), LimitExceededException _ => new BusinessException(ErrorCode.LimitExceeded, ex), BusinessException _ => ex, _ => new CriticalException(ErrorCode.InternalServerError, ex), }; }
protected void OnAuthorisationFailed(NotAuthorizedException exception, HandledEventArgs args) { args.Handled = false; }