private static void AuthenticationExceptionHandler(MongoAuthenticationException ex, List <TreeNode> trvMongoDb, TreeNode connectionNode, string mongoConnKey) { //需要验证的数据服务器,没有Admin权限无法获得数据库列表 if (!GuiConfig.IsUseDefaultLanguage) { connectionNode.Text += "[" + GuiConfig.GetText( TextType.ExceptionAuthenticationException) + "]"; Utility.ExceptionDeal(ex, GuiConfig.GetText( TextType.ExceptionAuthenticationException), GuiConfig.GetText( TextType.ExceptionAuthenticationExceptionNote)); } else { connectionNode.Text += "[MongoAuthenticationException]"; Utility.ExceptionDeal(ex, "MongoAuthenticationException:", "Please check UserName and Password"); } connectionNode.Tag = ConstMgr.ConnectionExceptionTag + ":" + mongoConnKey; trvMongoDb.Add(connectionNode); }
public void GetChannel_should_clear_connection_pool_when_opening_connection_throws_MongoAuthenticationException( [Values(false, true)] bool async) { var connectionId = new ConnectionId(new ServerId(_clusterId, _endPoint)); var mockConnectionHandle = new Mock <IConnectionHandle>(); var mockConnectionExceptionHandler = new Mock <IConnectionExceptionHandler>(); LoadBalancedServer server = null; var mockConnectionPool = new Mock <IConnectionPool>(); var authenticationException = new MongoAuthenticationException(connectionId, "Invalid login.") { ServiceId = ObjectId.GenerateNewId() }; mockConnectionPool .Setup(p => p.AcquireConnection(It.IsAny <CancellationToken>())) .Callback(() => server.HandleExceptionOnOpen(authenticationException)) .Throws(authenticationException); mockConnectionPool .Setup(p => p.AcquireConnectionAsync(It.IsAny <CancellationToken>())) .Callback(() => server.HandleExceptionOnOpen(authenticationException)) .Throws(authenticationException); mockConnectionPool.Setup(p => p.Clear(It.IsAny <ObjectId>())); var mockConnectionPoolFactory = new Mock <IConnectionPoolFactory>(); mockConnectionPoolFactory .Setup(f => f.CreateConnectionPool(It.IsAny <ServerId>(), _endPoint, It.IsAny <IConnectionExceptionHandler>())) .Returns(mockConnectionPool.Object); server = new LoadBalancedServer( _clusterId, _clusterClock, _settings, _endPoint, mockConnectionPoolFactory.Object, _capturedEvents, _serverApi); server.Initialize(); var exception = Record.Exception(() => { if (async) { server.GetChannelAsync(CancellationToken.None).GetAwaiter().GetResult(); } else { server.GetChannel(CancellationToken.None); } }); exception.Should().BeOfType <MongoAuthenticationException>(); mockConnectionPool.Verify(p => p.Clear(It.IsAny <ObjectId>()), Times.Once()); }
/// <summary> /// GetThreatLevel of mongoauthenticationexception /// </summary> /// <param name="exceptione"></param> /// <returns>Level</returns> public LogLevels.Levels GetThreatLevel(MongoAuthenticationException exceptione) { return(LogLevels.Levels.Fatal); }