aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoralexnick <alexnick@yandex-team.ru>2022-06-06 14:41:21 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-06-06 14:41:21 +0300
commit4b0f8c16ff71970dccb14363516742466369853c (patch)
treed4e5a3083f38a6c088b50587f15aef65e26e212d
parentd3dd33b79bc27e1804803d6817809cb725be799a (diff)
downloadydb-4b0f8c16ff71970dccb14363516742466369853c.tar.gz
small fixes
fix for empty describe REVIEW: 2494544 move mocks inside kikimr REVIEW: 2489498 REVIEW: 2494836 x-ydb-stable-ref: 7a44dc8e4477c215c79bb76282da27afd0fbc52a
-rw-r--r--ydb/core/testlib/service_mocks/access_service_mock.h68
-rw-r--r--ydb/core/testlib/service_mocks/database_service_mock.h73
-rw-r--r--ydb/core/testlib/service_mocks/datastreams_service_mock.h31
-rw-r--r--ydb/core/testlib/service_mocks/folder_service_mock.h23
-rw-r--r--ydb/core/testlib/service_mocks/iam_token_service_mock.h43
-rw-r--r--ydb/core/testlib/service_mocks/service_account_service_mock.h65
-rw-r--r--ydb/core/testlib/service_mocks/user_account_service_mock.h22
-rw-r--r--ydb/core/testlib/ya.make8
8 files changed, 0 insertions, 333 deletions
diff --git a/ydb/core/testlib/service_mocks/access_service_mock.h b/ydb/core/testlib/service_mocks/access_service_mock.h
index ab19356a16..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/access_service_mock.h
+++ b/ydb/core/testlib/service_mocks/access_service_mock.h
@@ -1,68 +0,0 @@
-#pragma once
-
-#include <yandex/cloud/priv/servicecontrol/v1/access_service.grpc.pb.h>
-
-#include <library/cpp/testing/unittest/registar.h>
-
-#include <iterator>
-
-class TAccessServiceMock : public yandex::cloud::priv::servicecontrol::v1::AccessService::Service {
-public:
- template <class TResonseProto>
- struct TResponse {
- TResonseProto Response;
- grpc::Status Status = grpc::Status::OK;
- bool RequireRequestId = false;
- };
-
- THashMap<TString, TResponse<yandex::cloud::priv::servicecontrol::v1::AuthenticateResponse>> AuthenticateData;
- THashMap<TString, TResponse<yandex::cloud::priv::servicecontrol::v1::AuthorizeResponse>> AuthorizeData;
-
- template <class TResonseProto>
- void CheckRequestId(grpc::ServerContext* ctx, const TResponse<TResonseProto>& resp, const TString& token) {
- if (resp.RequireRequestId) {
- auto [reqIdBegin, reqIdEnd] = ctx->client_metadata().equal_range("x-request-id");
- UNIT_ASSERT_C(reqIdBegin != reqIdEnd, "RequestId is expected. Token: " << token);
- UNIT_ASSERT_VALUES_EQUAL_C(std::distance(reqIdBegin, reqIdEnd), 1, "Only one RequestId is expected. Token: " << token);
- UNIT_ASSERT_C(!reqIdBegin->second.empty(), "RequestId is expected to be not empty. Token: " << token);
- }
- }
-
- virtual grpc::Status Authenticate(
- grpc::ServerContext* ctx,
- const yandex::cloud::priv::servicecontrol::v1::AuthenticateRequest* request,
- yandex::cloud::priv::servicecontrol::v1::AuthenticateResponse* response) override
- {
- TString key;
- if (request->has_signature()) {
- key = request->signature().v4_parameters().service();
- } else {
- key = request->iam_token();
- }
-
- auto it = AuthenticateData.find(key);
- if (it != AuthenticateData.end()) {
- response->CopyFrom(it->second.Response);
- CheckRequestId(ctx, it->second, key);
- return it->second.Status;
- } else {
- return grpc::Status(grpc::StatusCode::PERMISSION_DENIED, "Permission Denied");
- }
- }
-
- virtual grpc::Status Authorize(
- grpc::ServerContext* ctx,
- const yandex::cloud::priv::servicecontrol::v1::AuthorizeRequest* request,
- yandex::cloud::priv::servicecontrol::v1::AuthorizeResponse* response) override
- {
- const TString& token = request->signature().access_key_id() + request->iam_token() + "-" + request->permission() + "-" + request->resource_path(0).id();
- auto it = AuthorizeData.find(token);
- if (it != AuthorizeData.end()) {
- response->CopyFrom(it->second.Response);
- CheckRequestId(ctx, it->second, token);
- return it->second.Status;
- } else {
- return grpc::Status(grpc::StatusCode::PERMISSION_DENIED, "Permission Denied");
- }
- }
-};
diff --git a/ydb/core/testlib/service_mocks/database_service_mock.h b/ydb/core/testlib/service_mocks/database_service_mock.h
index e232c22d36..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/database_service_mock.h
+++ b/ydb/core/testlib/service_mocks/database_service_mock.h
@@ -1,73 +0,0 @@
-#pragma once
-
-#include <cloud/bitbucket/private-api/yandex/cloud/priv/ydb/v1/database_service.grpc.pb.h>
-
-class TDatabaseServiceMock : public yandex::cloud::priv::ydb::v1::DatabaseService::Service {
-public:
- THashMap<TString, yandex::cloud::priv::ydb::v1::Database> PersistentDatabases;
- THashMap<TString, yandex::cloud::priv::ydb::v1::Database> TemporaryDatabases;
- TString Identity;
-
- TMaybe<grpc::Status> CheckAuthorization(grpc::ServerContext* context) {
- if (!Identity.empty()) {
- auto[reqIdBegin, reqIdEnd] = context->client_metadata().equal_range("authorization");
- UNIT_ASSERT_C(reqIdBegin != reqIdEnd, "Authorization is expected.");
- if (Identity != TStringBuf(reqIdBegin->second.cbegin(), reqIdBegin->second.cend())) {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED,
- TStringBuilder() << "Access for user " << Identity << " is forbidden");
- }
- }
-
- return Nothing();
- }
-
- virtual grpc::Status GetByPath(grpc::ServerContext* context,
- const yandex::cloud::priv::ydb::v1::GetDatabaseByPathRequest* request,
- yandex::cloud::priv::ydb::v1::Database* response) override
- {
- auto status = CheckAuthorization(context);
- auto parts = SplitString(request->path(), "/");
- Y_ENSURE(parts.size() >= 3);
- TString canonizedPath = "/" + JoinRange("/", parts.begin(), parts.begin() + 3);
-
- if (auto itPersistent = PersistentDatabases.find(canonizedPath); itPersistent != PersistentDatabases.end()) {
- *response = itPersistent->second;
- return grpc::Status::OK;
- } else {
- auto it = TemporaryDatabases.find(canonizedPath);
- if (it == TemporaryDatabases.end()) {
- return grpc::Status(grpc::StatusCode::NOT_FOUND, TStringBuilder() << " database with name " << request->path() << " not found");
- } else {
- *response = it->second;
- return grpc::Status::OK;
- }
- }
- }
-
- virtual grpc::Status ListAll(grpc::ServerContext* context,
- const yandex::cloud::priv::ydb::v1::ListAllDatabasesRequest* request,
- yandex::cloud::priv::ydb::v1::ListAllDatabasesResponse* response) override
- {
- auto status = CheckAuthorization(context);
- if (status.Defined()) {
- return *status;
- }
-
- if (PersistentDatabases.empty()) {
- return grpc::Status::OK;
- }
- auto it = PersistentDatabases.begin();
- if (!request->page_token().empty()) {
- it = PersistentDatabases.find(request->page_token());
- }
- Y_ENSURE(it != PersistentDatabases.end());
- *response->add_databases() = it->second;
- it++;
- if (it != PersistentDatabases.end()) {
- response->set_next_page_token(it->first);
- }
- return grpc::Status::OK;
- }
-
-};
-
diff --git a/ydb/core/testlib/service_mocks/datastreams_service_mock.h b/ydb/core/testlib/service_mocks/datastreams_service_mock.h
index 3f65899cfc..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/datastreams_service_mock.h
+++ b/ydb/core/testlib/service_mocks/datastreams_service_mock.h
@@ -1,31 +0,0 @@
-#pragma once
-
-#include <ydb/public/api/grpc/draft/ydb_datastreams_v1.grpc.pb.h>
-#include "access_service_mock.h"
-#include "datastreams_service_mock.h"
-
-class TDataStreamsServiceMock : public Ydb::DataStreams::V1::DataStreamsService::Service {
-public:
- virtual grpc::Status PutRecords(grpc::ServerContext*,
- const Ydb::DataStreams::V1::PutRecordsRequest* request,
- Ydb::DataStreams::V1::PutRecordsResponse* response) override
- {
- Y_UNUSED(response);
- for (const auto& record : request->records()) {
- if (record.partition_key() == "Sleep") {
- Sleep(TDuration::Seconds(3));
- } else if (record.partition_key() == "InvalidArgument") {
- return grpc::Status(grpc::StatusCode::INVALID_ARGUMENT, "Invalid argument");
- } else if (record.partition_key() == "Unauthenticated") {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED, "Access denied");
- }
- }
- response->mutable_operation()->set_status(Ydb::StatusIds::SUCCESS);
- response->mutable_operation()->set_ready(true);
- response->mutable_operation()->set_id("12345");
-
- return grpc::Status::OK;
- }
-
-};
-
diff --git a/ydb/core/testlib/service_mocks/folder_service_mock.h b/ydb/core/testlib/service_mocks/folder_service_mock.h
index 5b1309ffc4..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/folder_service_mock.h
+++ b/ydb/core/testlib/service_mocks/folder_service_mock.h
@@ -1,23 +0,0 @@
-#pragma once
-
-#include <yandex/cloud/priv/resourcemanager/v1/transitional/folder_service.grpc.pb.h>
-
-class TFolderServiceMock : public yandex::cloud::priv::resourcemanager::v1::transitional::FolderService::Service {
-public:
- THashMap<TString, yandex::cloud::priv::resourcemanager::v1::Folder> Folders;
-
- virtual grpc::Status List(
- grpc::ServerContext*,
- const yandex::cloud::priv::resourcemanager::v1::transitional::ListFoldersRequest* request,
- yandex::cloud::priv::resourcemanager::v1::transitional::ListFoldersResponse* response) override {
- TString key = request->id();
- auto it = Folders.find(key);
- if (it != Folders.end()) {
- response->add_result()->CopyFrom(it->second);
- return grpc::Status::OK;
- } else {
- return grpc::Status(grpc::StatusCode::NOT_FOUND, "Not Found");
- }
- }
-};
-
diff --git a/ydb/core/testlib/service_mocks/iam_token_service_mock.h b/ydb/core/testlib/service_mocks/iam_token_service_mock.h
index f8f6ea0f30..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/iam_token_service_mock.h
+++ b/ydb/core/testlib/service_mocks/iam_token_service_mock.h
@@ -1,43 +0,0 @@
-#pragma once
-
-#include <yandex/cloud/priv/iam/v1/iam_token_service.grpc.pb.h>
-
-class TIamTokenServiceMock : public yandex::cloud::priv::iam::v1::IamTokenService::Service {
-public:
- THashMap<TString, yandex::cloud::priv::iam::v1::CreateIamTokenResponse> IamTokens;
- TString Identity;
-
- TMaybe<grpc::Status> CheckAuthorization(grpc::ServerContext* context) {
- if (!Identity.empty()) {
- auto[reqIdBegin, reqIdEnd] = context->client_metadata().equal_range("authorization");
- UNIT_ASSERT_C(reqIdBegin != reqIdEnd, "Authorization is expected.");
- if (Identity != TStringBuf(reqIdBegin->second.cbegin(), reqIdBegin->second.cend())) {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED,
- TStringBuilder() << "Access for user " << Identity << " is forbidden");
- }
- }
-
- return Nothing();
- }
-
- virtual grpc::Status CreateForServiceAccount(grpc::ServerContext* context,
- const yandex::cloud::priv::iam::v1::CreateIamTokenForServiceAccountRequest* request,
- yandex::cloud::priv::iam::v1::CreateIamTokenResponse* response) override
- {
- auto status = CheckAuthorization(context);
- if (status.Defined()) {
- return *status;
- }
-
- TString id = request->service_account_id();
- auto it = IamTokens.find(id);
- if (it != IamTokens.end()) {
- response->CopyFrom(it->second);
- return grpc::Status::OK;
- } else {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED, "Iam token not found");
- }
- }
-
-};
-
diff --git a/ydb/core/testlib/service_mocks/service_account_service_mock.h b/ydb/core/testlib/service_mocks/service_account_service_mock.h
index 583396fc0f..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/service_account_service_mock.h
+++ b/ydb/core/testlib/service_mocks/service_account_service_mock.h
@@ -1,65 +0,0 @@
-#pragma once
-
-#include <yandex/cloud/priv/iam/v1/service_account_service.grpc.pb.h>
-
-class TServiceAccountServiceMock : public yandex::cloud::priv::iam::v1::ServiceAccountService::Service {
-public:
- THashMap<TString, yandex::cloud::priv::iam::v1::ServiceAccount> ServiceAccountData;
- THashMap<TString, yandex::cloud::priv::iam::v1::IamToken> IamTokens;
- TString Identity;
-
- TMaybe<grpc::Status> CheckAuthorization(grpc::ServerContext* context) {
- if (!Identity.empty()) {
- auto[reqIdBegin, reqIdEnd] = context->client_metadata().equal_range("authorization");
- if (reqIdBegin == reqIdEnd) {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED,
- TStringBuilder() << "Authorization data is not provided");
- } else if (Identity != TStringBuf(reqIdBegin->second.cbegin(), reqIdBegin->second.cend())) {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED,
- TStringBuilder() << "Access for user " << Identity << " is forbidden");
- }
- }
-
- return Nothing();
- }
-
- virtual grpc::Status Get(grpc::ServerContext* context,
- const yandex::cloud::priv::iam::v1::GetServiceAccountRequest* request,
- yandex::cloud::priv::iam::v1::ServiceAccount* response) override
- {
- auto status = CheckAuthorization(context);
- if (status.Defined()) {
- return *status;
- }
-
- TString id = request->service_account_id();
- auto it = ServiceAccountData.find(id);
- if (it != ServiceAccountData.end()) {
- response->CopyFrom(it->second);
- return grpc::Status::OK;
- } else {
- return grpc::Status(grpc::StatusCode::NOT_FOUND, "Not Found");
- }
- }
-
- virtual grpc::Status IssueToken(grpc::ServerContext* context,
- const yandex::cloud::priv::iam::v1::IssueTokenRequest* request,
- yandex::cloud::priv::iam::v1::IamToken* response) override
- {
- auto status = CheckAuthorization(context);
- if (status.Defined()) {
- return *status;
- }
-
- TString id = request->service_account_id();
- auto it = IamTokens.find(id);
- if (it != IamTokens.end()) {
- response->CopyFrom(it->second);
- return grpc::Status::OK;
- } else {
- return grpc::Status(grpc::StatusCode::UNAUTHENTICATED, "Iam token not found");
- }
- }
-
-};
-
diff --git a/ydb/core/testlib/service_mocks/user_account_service_mock.h b/ydb/core/testlib/service_mocks/user_account_service_mock.h
index ddd7bb34cf..e69de29bb2 100644
--- a/ydb/core/testlib/service_mocks/user_account_service_mock.h
+++ b/ydb/core/testlib/service_mocks/user_account_service_mock.h
@@ -1,22 +0,0 @@
-#pragma once
-
-#include <yandex/cloud/priv/iam/v1/user_account_service.grpc.pb.h>
-
-class TUserAccountServiceMock : public yandex::cloud::priv::iam::v1::UserAccountService::Service {
-public:
- THashMap<TString, yandex::cloud::priv::iam::v1::UserAccount> UserAccountData;
-
- virtual grpc::Status Get(grpc::ServerContext*,
- const yandex::cloud::priv::iam::v1::GetUserAccountRequest* request,
- yandex::cloud::priv::iam::v1::UserAccount* response) override {
- TString id = request->user_account_id();
- auto it = UserAccountData.find(id);
- if (it != UserAccountData.end()) {
- response->CopyFrom(it->second);
- return grpc::Status::OK;
- } else {
- return grpc::Status(grpc::StatusCode::NOT_FOUND, "Not Found");
- }
- }
-};
-
diff --git a/ydb/core/testlib/ya.make b/ydb/core/testlib/ya.make
index b3332a1d7c..e670df9015 100644
--- a/ydb/core/testlib/ya.make
+++ b/ydb/core/testlib/ya.make
@@ -22,13 +22,6 @@ SRCS(
tenant_runtime.h
test_client.cpp
test_client.h
- service_mocks/access_service_mock.h
- service_mocks/datastreams_service_mock.h
- service_mocks/iam_token_service_mock.h
- service_mocks/user_account_service_mock.h
- service_mocks/database_service_mock.h
- service_mocks/folder_service_mock.h
- service_mocks/service_account_service_mock.h
)
PEERDIR(
@@ -119,5 +112,4 @@ END()
RECURSE(
actors
basics
- service_mocks
)