1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
#include "common.h"
#include <library/cpp/tvmauth/client/mocked_updater.h>
#include <library/cpp/tvmauth/client/misc/checker.h>
#include <library/cpp/tvmauth/client/misc/getter.h>
#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h>
#include <library/cpp/tvmauth/type.h>
#include <library/cpp/testing/unittest/registar.h>
using namespace NTvmAuth;
Y_UNIT_TEST_SUITE(ClientChecker) {
static const TTvmId OK_CLIENT = 100500;
static const TString PROD_TICKET = "3:user:CAsQ__________9_Gg4KAgh7EHsg0oXYzAQoAA:N8PvrDNLh-5JywinxJntLeQGDEHBUxfzjuvB8-_BEUv1x9CALU7do8irDlDYVeVVDr4AIpR087YPZVzWPAqmnBuRJS0tJXekmDDvrivLnbRrzY4IUXZ_fImB0fJhTyVetKv6RD11bGqnAJeDpIukBwPTbJc_EMvKDt8V490CJFw";
static const TString TEST_TICKET = "3:user:CA0Q__________9_Gg4KAgh7EHsg0oXYzAQoAQ:FSADps3wNGm92Vyb1E9IVq5M6ZygdGdt1vafWWEhfDDeCLoVA-sJesxMl2pGW4OxJ8J1r_MfpG3ZoBk8rLVMHUFrPa6HheTbeXFAWl8quEniauXvKQe4VyrpA1SPgtRoFqi5upSDIJzEAe1YRJjq1EClQ_slMt8R0kA_JjKUX54";
static const TString PROD_YATEAM_TICKET = "3:user:CAwQ__________9_Gg4KAgh7EHsg0oXYzAQoAg:M9dEFEWHLHXiL7brCsyfYlm254PE6VeshUjI62u2qMDRzt6-0jAoJTIdDiogerItht1YFYSn8fSqmMf23_rueGj-wkmvyNzbcBSk3jtK2U5sai_W0bK6OwukR9tzWzi1Gcgg9DrNEeIKFvs1EBqYCF4mPHWo5bgk0CR580Cgit4";
static const TString TEST_YATEAM_TICKET = "3:user:CA4Q__________9_Gg4KAgh7EHsg0oXYzAQoAw:IlaV3htk3jYrviIOz3k3Dfwz7p-bYYpbrgdn53GiUrMGdrT9eobHeuzNvPLrWB0yuYZAD46C3MGxok4GGmHhT73mki4XOCX8yWT4jW_hzcHBik1442tjWwh8IWqV_7q5j5496suVuLWjnZORWbb7I-2iwdIlU1BUiDfhoAolCq8";
static const TString STRESS_TICKET = "3:user:CA8Q__________9_Gg4KAgh7EHsg0oXYzAQoBA:GBuG_TLo6SL2OYFxp7Zly04HPNzmAF7Fu2E8E9SnwQDoxq9rf7VThSPtTmnBSAl5UVRRPkMsRtzzHZ87qtj6l-PvF0K7PrDu7-yS_xiFTgAl9sEfXAIHJVzZLoksGRgpoBtpBUg9vVaJsPns0kWFKJgq8M-Mk9agrSk7sb2VUeQ";
static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU";
Y_UNIT_TEST(User) {
NTvmApi::TClientSettings s;
s.SetSelfTvmId(OK_CLIENT);
s.EnableServiceTicketChecking();
s.SetDiskCacheDir(GetCachePath());
auto l = MakeIntrusive<TLogger>();
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
UNIT_ASSERT_EXCEPTION(TUserTicketChecker(u), TBrokenTvmClientSettings);
}
UNIT_ASSERT_C(l->Stream.Str().find("was successfully fetched") == TString::npos, l->Stream.Str());
s.EnableUserTicketChecking(EBlackboxEnv::Prod);
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TUserTicketChecker c(u);
UNIT_ASSERT(c.Check(PROD_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_TICKET, {}));
UNIT_ASSERT(!c.Check(PROD_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(STRESS_TICKET, {}));
UNIT_ASSERT(!c.Check(PROD_TICKET, EBlackboxEnv::ProdYateam));
UNIT_ASSERT(!c.Check(TEST_TICKET, EBlackboxEnv::ProdYateam));
UNIT_ASSERT(c.Check(PROD_YATEAM_TICKET, EBlackboxEnv::ProdYateam));
UNIT_ASSERT(!c.Check(TEST_YATEAM_TICKET, EBlackboxEnv::ProdYateam));
UNIT_ASSERT(!c.Check(STRESS_TICKET, EBlackboxEnv::ProdYateam));
UNIT_ASSERT_EXCEPTION(c.Check(PROD_TICKET, EBlackboxEnv::Stress), TBrokenTvmClientSettings);
}
s.EnableUserTicketChecking(EBlackboxEnv::Test);
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TUserTicketChecker c(u);
UNIT_ASSERT(!c.Check(PROD_TICKET, {}));
UNIT_ASSERT(c.Check(TEST_TICKET, {}));
UNIT_ASSERT(!c.Check(PROD_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(STRESS_TICKET, {}));
}
s.EnableUserTicketChecking(EBlackboxEnv::ProdYateam);
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TUserTicketChecker c(u);
UNIT_ASSERT(!c.Check(PROD_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_TICKET, {}));
UNIT_ASSERT(c.Check(PROD_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(STRESS_TICKET, {}));
}
s.EnableUserTicketChecking(EBlackboxEnv::TestYateam);
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TUserTicketChecker c(u);
UNIT_ASSERT(!c.Check(PROD_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_TICKET, {}));
UNIT_ASSERT(!c.Check(PROD_YATEAM_TICKET, {}));
UNIT_ASSERT(c.Check(TEST_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(STRESS_TICKET, {}));
}
s.EnableUserTicketChecking(EBlackboxEnv::Stress);
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TUserTicketChecker c(u);
UNIT_ASSERT(c.Check(PROD_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_TICKET, {}));
UNIT_ASSERT(!c.Check(PROD_YATEAM_TICKET, {}));
UNIT_ASSERT(!c.Check(TEST_YATEAM_TICKET, {}));
UNIT_ASSERT(c.Check(STRESS_TICKET, {}));
}
}
Y_UNIT_TEST(Service) {
NTvmApi::TClientSettings s;
s.EnableUserTicketChecking(EBlackboxEnv::Stress);
s.SetSelfTvmId(OK_CLIENT);
s.SetDiskCacheDir(GetCachePath());
auto l = MakeIntrusive<TLogger>();
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
UNIT_ASSERT_EXCEPTION(TServiceTicketChecker(u), TBrokenTvmClientSettings);
}
UNIT_ASSERT_C(l->Stream.Str().find("was successfully fetched") == TString::npos, l->Stream.Str());
s.EnableServiceTicketChecking();
l = MakeIntrusive<TLogger>();
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TServiceTicketChecker c(u);
UNIT_ASSERT(c.Check(SRV_TICKET));
UNIT_ASSERT(!c.Check(PROD_TICKET));
}
UNIT_ASSERT_C(l->Stream.Str().find("was successfully fetched") == TString::npos, l->Stream.Str());
s.SetSelfTvmId(17);
l = MakeIntrusive<TLogger>();
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TServiceTicketChecker c(u);
UNIT_ASSERT(!c.Check(SRV_TICKET));
UNIT_ASSERT(!c.Check(PROD_TICKET));
}
UNIT_ASSERT_C(l->Stream.Str().find("was successfully fetched") == TString::npos, l->Stream.Str());
}
Y_UNIT_TEST(Tickets) {
NTvmApi::TClientSettings s;
s.SetSelfTvmId(OK_CLIENT);
s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}});
s.SetDiskCacheDir(GetCachePath());
auto l = MakeIntrusive<TLogger>();
{
auto u = NTvmApi::TThreadedUpdater::Create(s, l);
UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus().GetCode());
TServiceTicketGetter g(u);
UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", g.GetTicket("blackbox"));
UNIT_ASSERT_EXCEPTION_CONTAINS(g.GetTicket("blackbox2"),
TBrokenTvmClientSettings,
"Destination 'blackbox2' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)");
}
UNIT_ASSERT_C(l->Stream.Str().find("was successfully fetched") == TString::npos, l->Stream.Str());
}
Y_UNIT_TEST(ErrorForDst) {
TServiceTicketGetter g(new TMockedUpdater);
UNIT_ASSERT_VALUES_EQUAL(TMockedUpdater::TSettings::CreateDeafult().Backends.at(0).Value,
g.GetTicket("my_dest"));
UNIT_ASSERT_VALUES_EQUAL(TMockedUpdater::TSettings::CreateDeafult().Backends.at(0).Value,
g.GetTicket(42));
UNIT_ASSERT_EXCEPTION_CONTAINS(g.GetTicket("my_bad_dest"),
TMissingServiceTicket,
"Failed to get ticket for 'my_bad_dest': Dst is not found");
UNIT_ASSERT_EXCEPTION_CONTAINS(g.GetTicket(43),
TMissingServiceTicket,
"Failed to get ticket for '43': Dst is not found");
}
}
|