Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kunga committed Jan 22, 2025
1 parent 45f4bda commit 61857bc
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions ydb/core/sys_view/ut_kqp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2702,6 +2702,68 @@ Y_UNIT_TEST_SUITE(SystemView) {
NKqp::CompareYson(expected, NKqp::StreamResultToYson(it));
}
}

Y_UNIT_TEST(PlayWithTenant) {
TTestEnv env;
env.GetServer().GetRuntime()->SetLogPriority(NKikimrServices::FLAT_TX_SCHEMESHARD, NLog::PRI_DEBUG);
env.GetServer().GetRuntime()->SetLogPriority(NKikimrServices::TICKET_PARSER, NLog::PRI_DEBUG);
env.GetServer().GetRuntime()->GetAppData().AdministrationAllowedSIDs.emplace_back("root@builtin");
env.GetServer().GetRuntime()->GetAppData().AuthConfig.SetDomainLoginOnly(false);
env.GetServer().GetRuntime()->GetAppData().FeatureFlags.SetCheckDatabaseAccessPermission(false);
env.GetClient().SetSecurityToken("root@builtin");
CreateTenantsAndTables(env, true);

env.GetClient().CreateUser("/Root", "user1", "password1");
env.GetClient().CreateUser("/Root/Tenant1", "user2", "password2");

Cerr << env.GetClient().Describe(env.GetServer().GetRuntime(), "/Root").DebugString() << Endl;

{
auto driverConfig = TDriverConfig()
.SetEndpoint(env.GetEndpoint())
.SetDatabase("/Root")
.SetCredentialsProviderFactory(NYdb::CreateLoginCredentialsProviderFactory({
.User = "user1",
.Password = "password1",
}));
auto driver = TDriver(driverConfig);
TTableClient client(driver);

auto it = client.StreamExecuteScanQuery(R"(
SELECT 1
)").GetValueSync();

auto expected = R"([
[1]
])";
UNIT_ASSERT_C(it.IsSuccess(), it.GetIssues().ToString());
NKqp::CompareYson(expected, NKqp::StreamResultToYson(it));
}

Cerr << env.GetClient().Describe(env.GetServer().GetRuntime(), "/Root/Tenant1").DebugString() << Endl;

{
auto driverConfig = TDriverConfig()
.SetEndpoint(env.GetEndpoint())
.SetDatabase("/Root/Tenant1")
.SetCredentialsProviderFactory(NYdb::CreateLoginCredentialsProviderFactory({
.User = "user2",
.Password = "password2",
}));
auto driver = TDriver(driverConfig);
TTableClient client(driver);

auto it = client.StreamExecuteScanQuery(R"(
SELECT 1
)").GetValueSync();

auto expected = R"([
[1]
])";
UNIT_ASSERT_C(it.IsSuccess(), it.GetIssues().ToString());
NKqp::CompareYson(expected, NKqp::StreamResultToYson(it));
}
}
}

} // NSysView
Expand Down

0 comments on commit 61857bc

Please sign in to comment.