blob: 2b6daedb03846b1c26b93b337dc0ae2501dd3de0 (
plain) (
blame)
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
|
#pragma once
#include "misc/async_updater.h"
#include "misc/checker.h"
#include "misc/default_uid_checker.h"
#include "misc/getter.h"
#include "misc/src_checker.h"
namespace NTvmAuth {
class TMockedUpdater: public TAsyncUpdaterBase {
public:
struct TSettings {
struct TTuple {
TClientSettings::TAlias Alias;
TTvmId Id = 0;
TString Value; // ticket or error
};
TTvmId SelfTvmId = 0;
TVector<TTuple> Backends;
TVector<TTuple> BadBackends;
EBlackboxEnv UserTicketEnv = EBlackboxEnv::Test;
NRoles::TRolesPtr Roles;
static TSettings CreateDeafult();
};
TMockedUpdater(const TSettings& settings = TSettings::CreateDeafult());
TClientStatus GetStatus() const override {
return TClientStatus();
}
NRoles::TRolesPtr GetRoles() const override {
Y_ENSURE_EX(Roles_, TIllegalUsage() << "Roles are not provided");
return Roles_;
}
TString GetServiceTicketFor(const TClientSettings::TAlias& dst) const override {
auto c = GetCachedServiceTickets();
return TServiceTicketGetter::GetTicket(dst, c);
}
TString GetServiceTicketFor(const TTvmId dst) const override {
auto c = GetCachedServiceTickets();
return TServiceTicketGetter::GetTicket(dst, c);
}
TCheckedServiceTicket CheckServiceTicket(TStringBuf ticket, const TServiceContext::TCheckFlags& flags) const override {
TServiceContextPtr c = GetCachedServiceContext();
TCheckedServiceTicket res = TServiceTicketChecker::Check(ticket, c, flags);
if (Roles_ && res) {
NRoles::TRolesPtr roles = GetRoles();
return TSrcChecker::Check(std::move(res), roles);
}
return res;
}
TCheckedUserTicket CheckUserTicket(TStringBuf ticket, TMaybe<EBlackboxEnv> overridenEnv) const override {
auto c = GetCachedUserContext(overridenEnv);
TCheckedUserTicket res = TUserTicketChecker::Check(ticket, c);
if (Roles_ && res && res.GetEnv() == EBlackboxEnv::ProdYateam) {
NRoles::TRolesPtr roles = GetRoles();
return TDefaultUidChecker::Check(std::move(res), roles);
}
return res;
}
using TAsyncUpdaterBase::SetServiceContext;
using TAsyncUpdaterBase::SetServiceTickets;
using TAsyncUpdaterBase::SetUpdateTimeOfPublicKeys;
using TAsyncUpdaterBase::SetUpdateTimeOfServiceTickets;
using TAsyncUpdaterBase::SetUserContext;
protected:
NRoles::TRolesPtr Roles_;
};
}
|