|
| 1 | +#include "impl/trace_lazy.h" |
1 | 2 | #include "ut_utils/topic_sdk_test_setup.h"
|
2 | 3 |
|
| 4 | +#include <format> |
3 | 5 | #include <ydb/library/persqueue/topic_parser_public/topic_parser.h>
|
| 6 | +#include <ydb/public/api/protos/persqueue_error_codes_v1.pb.h> |
4 | 7 | #include <ydb/public/sdk/cpp/client/ydb_topic/topic.h>
|
5 | 8 | #include <ydb/public/sdk/cpp/client/ydb_persqueue_core/persqueue.h>
|
6 | 9 | #include <ydb/public/sdk/cpp/client/ydb_persqueue_core/impl/common.h>
|
|
10 | 13 | #include <library/cpp/threading/future/future.h>
|
11 | 14 | #include <library/cpp/threading/future/async.h>
|
12 | 15 |
|
13 |
| -#include <future> |
14 |
| - |
15 | 16 | namespace NYdb::NTopic::NTests {
|
16 | 17 |
|
17 | 18 | Y_UNIT_TEST_SUITE(Describe) {
|
@@ -344,5 +345,73 @@ namespace NYdb::NTopic::NTests {
|
344 | 345 | DescribeConsumer(setup, client, false, false, true, true);
|
345 | 346 | DescribePartition(setup, client, false, false, true, true);
|
346 | 347 | }
|
| 348 | + |
| 349 | + TDescribePartitionResult RunPermissionTest(TTopicSdkTestSetup& setup, int userId, bool existingTopic, bool allowUpdateRow, bool allowDescribeSchema) { |
| 350 | + TString authToken = TStringBuilder() << "x-user-" << userId << "@builtin"; |
| 351 | + Cerr << std::format("=== existingTopic={} allowUpdateRow={} allowDescribeSchema={} authToken={}\n", |
| 352 | + existingTopic, allowUpdateRow, allowDescribeSchema, std::string(authToken)); |
| 353 | + |
| 354 | + auto driverConfig = setup.MakeDriverConfig().SetAuthToken(authToken); |
| 355 | + auto client = TTopicClient(TDriver(driverConfig)); |
| 356 | + auto settings = TDescribePartitionSettings().IncludeLocation(true); |
| 357 | + i64 testPartitionId = 0; |
| 358 | + |
| 359 | + NACLib::TDiffACL acl; |
| 360 | + if (allowDescribeSchema) { |
| 361 | + acl.AddAccess(NACLib::EAccessType::Allow, NACLib::DescribeSchema, authToken); |
| 362 | + } |
| 363 | + if (allowUpdateRow) { |
| 364 | + acl.AddAccess(NACLib::EAccessType::Allow, NACLib::UpdateRow, authToken); |
| 365 | + } |
| 366 | + setup.GetServer().AnnoyingClient->ModifyACL("/Root", TEST_TOPIC, acl.SerializeAsString()); |
| 367 | + |
| 368 | + return client.DescribePartition(existingTopic ? TEST_TOPIC : "bad-topic", testPartitionId, settings).GetValueSync(); |
| 369 | + } |
| 370 | + |
| 371 | + Y_UNIT_TEST(DescribePartitionPermissions) { |
| 372 | + TTopicSdkTestSetup setup(TEST_CASE_NAME); |
| 373 | + setup.GetServer().EnableLogs({NKikimrServices::TX_PROXY_SCHEME_CACHE, NKikimrServices::SCHEME_BOARD_SUBSCRIBER}, NActors::NLog::PRI_TRACE); |
| 374 | + |
| 375 | + int userId = 0; |
| 376 | + |
| 377 | + struct Expectation { |
| 378 | + bool existingTopic; |
| 379 | + bool allowUpdateRow; |
| 380 | + bool allowDescribeSchema; |
| 381 | + EStatus status; |
| 382 | + NYql::TIssueCode issueCode; |
| 383 | + }; |
| 384 | + |
| 385 | + std::vector<Expectation> expectations{ |
| 386 | + {0, 0, 0, EStatus::SCHEME_ERROR, Ydb::PersQueue::ErrorCode::ACCESS_DENIED}, |
| 387 | + {0, 0, 1, EStatus::SCHEME_ERROR, Ydb::PersQueue::ErrorCode::ACCESS_DENIED}, |
| 388 | + {0, 1, 0, EStatus::SCHEME_ERROR, Ydb::PersQueue::ErrorCode::ACCESS_DENIED}, |
| 389 | + {0, 1, 1, EStatus::SCHEME_ERROR, Ydb::PersQueue::ErrorCode::ACCESS_DENIED}, |
| 390 | + {1, 0, 0, EStatus::SCHEME_ERROR, Ydb::PersQueue::ErrorCode::ACCESS_DENIED}, |
| 391 | + {1, 0, 1, EStatus::SUCCESS, 0}, |
| 392 | + {1, 1, 0, EStatus::SUCCESS, 0}, |
| 393 | + {1, 1, 1, EStatus::SUCCESS, 0}, |
| 394 | + }; |
| 395 | + |
| 396 | + for (auto [existing, update, describe, status, issue] : expectations) { |
| 397 | + auto result = RunPermissionTest(setup, userId++, existing, update, describe); |
| 398 | + auto resultStatus = result.GetStatus(); |
| 399 | + auto line = TStringBuilder() << "=== status=" << resultStatus; |
| 400 | + NYql::TIssueCode resultIssue = 0; |
| 401 | + if (!result.GetIssues().Empty()) { |
| 402 | + resultIssue = result.GetIssues().begin()->GetCode(); |
| 403 | + line << " issueCode=" << resultIssue; |
| 404 | + } |
| 405 | + Cerr << (line << " issues=" << result.GetIssues().ToOneLineString() << Endl); |
| 406 | + |
| 407 | + UNIT_ASSERT_EQUAL(resultStatus, status); |
| 408 | + UNIT_ASSERT_EQUAL(resultIssue, issue); |
| 409 | + if (resultStatus == EStatus::SUCCESS) { |
| 410 | + auto& p = result.GetPartitionDescription().GetPartition(); |
| 411 | + UNIT_ASSERT(p.GetActive()); |
| 412 | + UNIT_ASSERT(p.GetPartitionLocation().Defined()); |
| 413 | + } |
| 414 | + } |
| 415 | + } |
347 | 416 | }
|
348 | 417 | }
|
0 commit comments