aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/ut/settings_ut.cpp
diff options
context:
space:
mode:
authorqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
committerqrort <qrort@yandex-team.com>2022-11-30 23:47:12 +0300
commit22f8ae0e3f5d68b92aecccdf96c1d841a0334311 (patch)
treebffa27765faf54126ad44bcafa89fadecb7a73d7 /library/cpp/tvmauth/client/ut/settings_ut.cpp
parent332b99e2173f0425444abb759eebcb2fafaa9209 (diff)
downloadydb-22f8ae0e3f5d68b92aecccdf96c1d841a0334311.tar.gz
validate canons without yatest_common
Diffstat (limited to 'library/cpp/tvmauth/client/ut/settings_ut.cpp')
-rw-r--r--library/cpp/tvmauth/client/ut/settings_ut.cpp158
1 files changed, 158 insertions, 0 deletions
diff --git a/library/cpp/tvmauth/client/ut/settings_ut.cpp b/library/cpp/tvmauth/client/ut/settings_ut.cpp
new file mode 100644
index 0000000000..726beaf928
--- /dev/null
+++ b/library/cpp/tvmauth/client/ut/settings_ut.cpp
@@ -0,0 +1,158 @@
+#include "common.h"
+
+#include <library/cpp/tvmauth/client/misc/api/settings.h>
+
+#include <library/cpp/testing/unittest/registar.h>
+
+using namespace NTvmAuth;
+
+Y_UNIT_TEST_SUITE(ClientSettings) {
+#if !defined(_win_)
+ Y_UNIT_TEST(CheckValid) {
+ struct TTestCase {
+ TString Name;
+ NTvmApi::TClientSettings Settings;
+ TString Err;
+ };
+ std::vector<TTestCase> cases = {
+ TTestCase{
+ .Name = "default",
+ .Settings = {},
+ .Err = "Invalid settings: nothing to do",
+ },
+ TTestCase{
+ .Name = "only secret",
+ .Settings = {
+ .Secret = TStringBuf("foobar"),
+ },
+ .Err = "Secret is present but destinations list is empty. It makes no sense",
+ },
+ TTestCase{
+ .Name = "only dsts",
+ .Settings = {
+ .FetchServiceTicketsForDsts = {42},
+ },
+ .Err = "SelfTvmId cannot be 0 if fetching of Service Tickets required",
+ },
+ TTestCase{
+ .Name = "dsts with selfTvmId",
+ .Settings = {
+ .SelfTvmId = 43,
+ .FetchServiceTicketsForDsts = {42},
+ },
+ .Err = "Secret is required for fetching of Service Tickets",
+ },
+ TTestCase{
+ .Name = "correct service tickets fetching",
+ .Settings = {
+ .SelfTvmId = 43,
+ .Secret = TStringBuf("foobar"),
+ .FetchServiceTicketsForDsts = {42},
+ },
+ .Err = "",
+ },
+ TTestCase{
+ .Name = "only check srv flag",
+ .Settings = {
+ .CheckServiceTickets = true,
+ },
+ .Err = "SelfTvmId cannot be 0 if checking of Service Tickets required",
+ },
+ TTestCase{
+ .Name = "tirole without disk cache",
+ .Settings = {
+ .SelfTvmId = 43,
+ .Secret = TStringBuf("foobar"),
+ .FetchRolesForIdmSystemSlug = "kek",
+ },
+ .Err = "Disk cache must be enabled to use roles: they can be heavy",
+ },
+ };
+
+ for (const TTestCase& c : cases) {
+ if (c.Err) {
+ UNIT_ASSERT_EXCEPTION_CONTAINS_C(
+ c.Settings.CheckValid(),
+ TBrokenTvmClientSettings,
+ c.Err,
+ c.Name);
+ } else {
+ UNIT_ASSERT_NO_EXCEPTION_C(c.Settings.CheckValid(), c.Name);
+ }
+ }
+
+ NTvmApi::TClientSettings s{.DiskCacheDir = "/impossible/dir"};
+ UNIT_ASSERT_EXCEPTION(s.CheckValid(), TPermissionDenied);
+ }
+
+ Y_UNIT_TEST(CloneNormalized) {
+ NTvmApi::TClientSettings original;
+ original.FetchServiceTicketsForDsts = {43};
+
+ UNIT_ASSERT_EXCEPTION_CONTAINS(original.CloneNormalized(),
+ TBrokenTvmClientSettings,
+ "SelfTvmId cannot be 0 if fetching of Service Tickets required");
+ original.SelfTvmId = 15;
+ original.Secret = "bar";
+ original.DiskCacheDir = "./";
+
+ NTvmApi::TClientSettings::TDstVector expected = {43};
+ UNIT_ASSERT_VALUES_EQUAL(expected, original.CloneNormalized().FetchServiceTicketsForDsts);
+
+ original.FetchServiceTicketsForDstsWithAliases = {{"foo", 42}};
+ expected = {42, 43};
+ UNIT_ASSERT_VALUES_EQUAL(expected, original.CloneNormalized().FetchServiceTicketsForDsts);
+
+ original.FetchRolesForIdmSystemSlug = "kek";
+ expected = {42, 43, 2028120};
+ UNIT_ASSERT_VALUES_EQUAL(expected, original.CloneNormalized().FetchServiceTicketsForDsts);
+
+ original.FetchServiceTicketsForDsts.push_back(2028120);
+ expected = {42, 43, 2028120};
+ UNIT_ASSERT_VALUES_EQUAL(expected, original.CloneNormalized().FetchServiceTicketsForDsts);
+ }
+
+ Y_UNIT_TEST(NeedServiceTicketsFetching) {
+ NTvmApi::TClientSettings s;
+
+ UNIT_ASSERT(!s.NeedServiceTicketsFetching());
+
+ s.FetchServiceTicketsForDsts = {42};
+ UNIT_ASSERT(s.NeedServiceTicketsFetching());
+ s.FetchServiceTicketsForDsts.clear();
+
+ s.FetchServiceTicketsForDstsWithAliases = {{"foo", 42}};
+ UNIT_ASSERT(s.NeedServiceTicketsFetching());
+ s.FetchServiceTicketsForDstsWithAliases.clear();
+
+ s.FetchRolesForIdmSystemSlug = "bar";
+ UNIT_ASSERT(s.NeedServiceTicketsFetching());
+ s.FetchRolesForIdmSystemSlug.clear();
+ }
+
+ Y_UNIT_TEST(permitions) {
+ UNIT_ASSERT_EXCEPTION(NTvmApi::TClientSettings::CheckPermissions("/qwerty"), TPermissionDenied);
+
+ const TString tmpDir = "./cache_dir";
+
+ NFs::RemoveRecursive(tmpDir);
+ NFs::MakeDirectory(tmpDir, NFs::FP_OWNER_WRITE | NFs::FP_GROUP_WRITE | NFs::FP_ALL_WRITE);
+ UNIT_ASSERT_EXCEPTION(NTvmApi::TClientSettings::CheckPermissions(tmpDir), TPermissionDenied);
+
+ NFs::RemoveRecursive(tmpDir);
+ NFs::MakeDirectory(tmpDir, NFs::FP_OWNER_READ | NFs::FP_GROUP_READ | NFs::FP_ALL_READ);
+ UNIT_ASSERT_EXCEPTION(NTvmApi::TClientSettings::CheckPermissions(tmpDir), TPermissionDenied);
+
+ NFs::RemoveRecursive(tmpDir);
+ NFs::MakeDirectory(tmpDir, NFs::FP_COMMON_FILE);
+ UNIT_ASSERT_NO_EXCEPTION(NTvmApi::TClientSettings::CheckPermissions(tmpDir));
+ }
+#endif
+
+ Y_UNIT_TEST(Dst) {
+ UNIT_ASSERT_EXCEPTION_CONTAINS(NTvmApi::TClientSettings::TDst(0), yexception, "TvmId cannot be 0");
+ UNIT_ASSERT_EXCEPTION_CONTAINS(NTvmApi::TClientSettings::TDstMap({{"blackbox", 0}}),
+ TBrokenTvmClientSettings,
+ "TvmId cannot be 0");
+ }
+}