diff --git a/src/Ydb.Sdk/tests/Auth/TestStaticAuth.cs b/src/Ydb.Sdk/tests/Auth/TestStaticAuth.cs index 940004b5..cb203da3 100644 --- a/src/Ydb.Sdk/tests/Auth/TestStaticAuth.cs +++ b/src/Ydb.Sdk/tests/Auth/TestStaticAuth.cs @@ -41,7 +41,26 @@ private async Task DropUser(TableClient tableClient, string user) _logger.LogInformation($"User {user} dropped successfully"); } - private async Task DoAuth(string? passwordCreate, string? passwordAuth, int maxRetries = 5) + private async Task Authorize(string user, string? password, int maxRetries) + { + var driverConfig = new DriverConfig( + endpoint: "grpc://localhost:2136", + database: "/local", + new StaticCredentialsProvider(user, password, _loggerFactory) { MaxRetries = maxRetries } + ); + + _logger.LogInformation($"DriverConfig for {user} created"); + + await using var driver = await Driver.CreateInitialized(driverConfig, _loggerFactory); + _logger.LogInformation($"Driver for {user} created and initialized"); + using var tableClient = new TableClient(driver); + + var response = await Utils.ExecuteDataQuery(tableClient, "SELECT 1"); + var row = response.Result.ResultSets[0].Rows[0]; + Assert.Equal(1, row[0].GetInt32()); + } + + private async Task CheckAuth(string? passwordCreate, string? passwordAuth, int maxRetries = 5) { _logger.LogInformation("Creating anon driver"); var anonDriverConfig = new DriverConfig( @@ -60,21 +79,7 @@ private async Task DoAuth(string? passwordCreate, string? passwordAuth, int maxR try { - var driverConfig = new DriverConfig( - endpoint: "grpc://localhost:2136", - database: "/local", - new StaticCredentialsProvider(user, passwordAuth, _loggerFactory) { MaxRetries = maxRetries } - ); - - _logger.LogInformation($"DriverConfig for {user} created"); - - await using var driver = await Driver.CreateInitialized(driverConfig, _loggerFactory); - _logger.LogInformation($"Driver for {user} created and initialized"); - using var tableClient = new TableClient(driver); - - var response = await Utils.ExecuteDataQuery(tableClient, "SELECT 1"); - var row = response.Result.ResultSets[0].Rows[0]; - Assert.Equal(1, row[0].GetInt32()); + await Authorize(user, passwordAuth, maxRetries); } finally { @@ -86,20 +91,20 @@ private async Task DoAuth(string? passwordCreate, string? passwordAuth, int maxR [Fact] public async Task GoodAuth() { - await DoAuth("test_password", "test_password"); + await CheckAuth("test_password", "test_password"); } [Fact] public async Task NoPasswordAuth() { - await DoAuth(null, null); + await CheckAuth(null, null); } [Fact] public async Task WrongPassword() { await Assert.ThrowsAsync( - async () => await DoAuth("good_password", "wrong_password", maxRetries: 1)); + async () => await CheckAuth("good_password", "wrong_password", maxRetries: 1)); } [Fact]