diff options
author | cerevra <cerevra@yandex-team.ru> | 2022-02-10 16:45:59 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:59 +0300 |
commit | 4f292c7e2fd0a41da93fda51b2d440c979a330b7 (patch) | |
tree | 1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp | |
parent | bf41dd01f6c920583e9faae7cd55ed25e547e052 (diff) | |
download | ydb-4f292c7e2fd0a41da93fda51b2d440c979a330b7.tar.gz |
Restoring authorship annotation for <cerevra@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp')
937 files changed, 15690 insertions, 15690 deletions
diff --git a/library/cpp/accurate_accumulate/benchmark/main.cpp b/library/cpp/accurate_accumulate/benchmark/main.cpp index 54857b9fa6..3c5e6e775d 100644 --- a/library/cpp/accurate_accumulate/benchmark/main.cpp +++ b/library/cpp/accurate_accumulate/benchmark/main.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/accurate_accumulate/accurate_accumulate.h> +#include <library/cpp/accurate_accumulate/accurate_accumulate.h> #include <library/cpp/testing/benchmark/bench.h> #include <util/generic/algorithm.h> diff --git a/library/cpp/accurate_accumulate/benchmark/metrics/main.py b/library/cpp/accurate_accumulate/benchmark/metrics/main.py index 317eb597c6..311fc219ce 100644 --- a/library/cpp/accurate_accumulate/benchmark/metrics/main.py +++ b/library/cpp/accurate_accumulate/benchmark/metrics/main.py @@ -3,5 +3,5 @@ import yatest.common as yc def test_export_metrics(metrics): metrics.set_benchmark(yc.execute_benchmark( - 'library/cpp/accurate_accumulate/benchmark/benchmark', + 'library/cpp/accurate_accumulate/benchmark/benchmark', threads=8)) diff --git a/library/cpp/accurate_accumulate/benchmark/metrics/ya.make b/library/cpp/accurate_accumulate/benchmark/metrics/ya.make index a8a8b05390..5d532e1479 100644 --- a/library/cpp/accurate_accumulate/benchmark/metrics/ya.make +++ b/library/cpp/accurate_accumulate/benchmark/metrics/ya.make @@ -12,6 +12,6 @@ TAG( TEST_SRCS(main.py) -DEPENDS(library/cpp/accurate_accumulate/benchmark) +DEPENDS(library/cpp/accurate_accumulate/benchmark) END() diff --git a/library/cpp/accurate_accumulate/benchmark/ya.make b/library/cpp/accurate_accumulate/benchmark/ya.make index 52ad4f9bd2..20fd877389 100644 --- a/library/cpp/accurate_accumulate/benchmark/ya.make +++ b/library/cpp/accurate_accumulate/benchmark/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/accurate_accumulate + library/cpp/accurate_accumulate ) END() diff --git a/library/cpp/actors/core/actorsystem.cpp b/library/cpp/actors/core/actorsystem.cpp index f4642fc6bd..c58698a206 100644 --- a/library/cpp/actors/core/actorsystem.cpp +++ b/library/cpp/actors/core/actorsystem.cpp @@ -11,7 +11,7 @@ #include "log.h" #include "probes.h" #include "ask.h" -#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> #include <util/generic/hash.h> #include <util/system/rwlock.h> diff --git a/library/cpp/actors/core/actorsystem.h b/library/cpp/actors/core/actorsystem.h index 1a7409ee6c..40499d7586 100644 --- a/library/cpp/actors/core/actorsystem.h +++ b/library/cpp/actors/core/actorsystem.h @@ -11,7 +11,7 @@ #include "mon_stats.h" #include <library/cpp/threading/future/future.h> -#include <library/cpp/actors/util/ticket_lock.h> +#include <library/cpp/actors/util/ticket_lock.h> #include <util/generic/vector.h> #include <util/datetime/base.h> diff --git a/library/cpp/actors/core/defs.h b/library/cpp/actors/core/defs.h index 832d354e41..980b7d767b 100644 --- a/library/cpp/actors/core/defs.h +++ b/library/cpp/actors/core/defs.h @@ -2,7 +2,7 @@ // unique tag to fix pragma once gcc glueing: ./library/actorlib/core/defs.h -#include <library/cpp/actors/util/defs.h> +#include <library/cpp/actors/util/defs.h> #include <util/generic/hash.h> #include <util/string/printf.h> diff --git a/library/cpp/actors/core/event.h b/library/cpp/actors/core/event.h index d63b87dc07..6ff02aaf94 100644 --- a/library/cpp/actors/core/event.h +++ b/library/cpp/actors/core/event.h @@ -5,7 +5,7 @@ #include "callstack.h" #include "event_load.h" -#include <library/cpp/actors/wilson/wilson_trace.h> +#include <library/cpp/actors/wilson/wilson_trace.h> #include <util/system/hp_timer.h> #include <util/generic/maybe.h> diff --git a/library/cpp/actors/core/event_load.h b/library/cpp/actors/core/event_load.h index 00ae9f25c4..0dab1dd374 100644 --- a/library/cpp/actors/core/event_load.h +++ b/library/cpp/actors/core/event_load.h @@ -3,8 +3,8 @@ #include <util/stream/walk.h> #include <util/system/types.h> #include <util/generic/string.h> -#include <library/cpp/actors/util/rope.h> -#include <library/cpp/actors/wilson/wilson_trace.h> +#include <library/cpp/actors/util/rope.h> +#include <library/cpp/actors/wilson/wilson_trace.h> namespace NActors { class IEventHandle; diff --git a/library/cpp/actors/core/event_pb.h b/library/cpp/actors/core/event_pb.h index 5eaa4a5533..d7546b901a 100644 --- a/library/cpp/actors/core/event_pb.h +++ b/library/cpp/actors/core/event_pb.h @@ -5,7 +5,7 @@ #include <google/protobuf/io/zero_copy_stream.h> #include <google/protobuf/arena.h> -#include <library/cpp/actors/protos/actors.pb.h> +#include <library/cpp/actors/protos/actors.pb.h> #include <util/generic/deque.h> #include <util/system/context.h> #include <util/system/filemap.h> diff --git a/library/cpp/actors/core/event_pb_payload_ut.cpp b/library/cpp/actors/core/event_pb_payload_ut.cpp index 8426f5255b..eab007bc15 100644 --- a/library/cpp/actors/core/event_pb_payload_ut.cpp +++ b/library/cpp/actors/core/event_pb_payload_ut.cpp @@ -2,7 +2,7 @@ #include "events.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/protos/unittests.pb.h> +#include <library/cpp/actors/protos/unittests.pb.h> using namespace NActors; diff --git a/library/cpp/actors/core/event_pb_ut.cpp b/library/cpp/actors/core/event_pb_ut.cpp index 7aece4a24b..a16c3092b3 100644 --- a/library/cpp/actors/core/event_pb_ut.cpp +++ b/library/cpp/actors/core/event_pb_ut.cpp @@ -1,7 +1,7 @@ #include "event_pb.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/protos/unittests.pb.h> +#include <library/cpp/actors/protos/unittests.pb.h> Y_UNIT_TEST_SUITE(TEventSerialization) { struct TMockEvent: public NActors::IEventBase { diff --git a/library/cpp/actors/core/events.h b/library/cpp/actors/core/events.h index b141892c62..702cf50fad 100644 --- a/library/cpp/actors/core/events.h +++ b/library/cpp/actors/core/events.h @@ -3,7 +3,7 @@ #include "event.h" #include "event_pb.h" -#include <library/cpp/actors/protos/actors.pb.h> +#include <library/cpp/actors/protos/actors.pb.h> #include <util/system/unaligned_mem.h> namespace NActors { diff --git a/library/cpp/actors/core/executor_pool_base.h b/library/cpp/actors/core/executor_pool_base.h index a7aade3b61..c84ce1af77 100644 --- a/library/cpp/actors/core/executor_pool_base.h +++ b/library/cpp/actors/core/executor_pool_base.h @@ -3,9 +3,9 @@ #include "actorsystem.h" #include "executor_thread.h" #include "scheduler_queue.h" -#include <library/cpp/actors/util/affinity.h> -#include <library/cpp/actors/util/unordered_cache.h> -#include <library/cpp/actors/util/threadparkpad.h> +#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/util/unordered_cache.h> +#include <library/cpp/actors/util/threadparkpad.h> namespace NActors { class TExecutorPoolBaseMailboxed: public IExecutorPool { diff --git a/library/cpp/actors/core/executor_pool_basic.cpp b/library/cpp/actors/core/executor_pool_basic.cpp index 5fc3baee85..4dce16939a 100644 --- a/library/cpp/actors/core/executor_pool_basic.cpp +++ b/library/cpp/actors/core/executor_pool_basic.cpp @@ -1,7 +1,7 @@ #include "executor_pool_basic.h" #include "probes.h" #include "mailbox.h" -#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> #ifdef _linux_ diff --git a/library/cpp/actors/core/executor_pool_basic.h b/library/cpp/actors/core/executor_pool_basic.h index 1033268e0c..023190f7fe 100644 --- a/library/cpp/actors/core/executor_pool_basic.h +++ b/library/cpp/actors/core/executor_pool_basic.h @@ -4,8 +4,8 @@ #include "executor_thread.h" #include "scheduler_queue.h" #include "executor_pool_base.h" -#include <library/cpp/actors/util/unordered_cache.h> -#include <library/cpp/actors/util/threadparkpad.h> +#include <library/cpp/actors/util/unordered_cache.h> +#include <library/cpp/actors/util/threadparkpad.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include <util/system/mutex.h> diff --git a/library/cpp/actors/core/executor_pool_basic_ut.cpp b/library/cpp/actors/core/executor_pool_basic_ut.cpp index 850c657e93..76dff693af 100644 --- a/library/cpp/actors/core/executor_pool_basic_ut.cpp +++ b/library/cpp/actors/core/executor_pool_basic_ut.cpp @@ -3,10 +3,10 @@ #include "hfunc.h" #include "scheduler_basic.h" -#include <library/cpp/actors/util/should_continue.h> +#include <library/cpp/actors/util/should_continue.h> #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/protos/unittests.pb.h> +#include <library/cpp/actors/protos/unittests.pb.h> using namespace NActors; diff --git a/library/cpp/actors/core/executor_pool_io.cpp b/library/cpp/actors/core/executor_pool_io.cpp index ede73fe21d..fb557ae6b0 100644 --- a/library/cpp/actors/core/executor_pool_io.cpp +++ b/library/cpp/actors/core/executor_pool_io.cpp @@ -1,6 +1,6 @@ #include "executor_pool_io.h" #include "mailbox.h" -#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> namespace NActors { diff --git a/library/cpp/actors/core/executor_pool_io.h b/library/cpp/actors/core/executor_pool_io.h index b51c6f65c2..e576d642a1 100644 --- a/library/cpp/actors/core/executor_pool_io.h +++ b/library/cpp/actors/core/executor_pool_io.h @@ -4,9 +4,9 @@ #include "executor_thread.h" #include "scheduler_queue.h" #include "executor_pool_base.h" -#include <library/cpp/actors/util/ticket_lock.h> -#include <library/cpp/actors/util/unordered_cache.h> -#include <library/cpp/actors/util/threadparkpad.h> +#include <library/cpp/actors/util/ticket_lock.h> +#include <library/cpp/actors/util/unordered_cache.h> +#include <library/cpp/actors/util/threadparkpad.h> #include <util/system/condvar.h> namespace NActors { diff --git a/library/cpp/actors/core/executor_pool_united.cpp b/library/cpp/actors/core/executor_pool_united.cpp index 6950748e03..dac6245635 100644 --- a/library/cpp/actors/core/executor_pool_united.cpp +++ b/library/cpp/actors/core/executor_pool_united.cpp @@ -6,7 +6,7 @@ #include "probes.h" #include "mailbox.h" #include "scheduler_queue.h" -#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> #include <library/cpp/actors/util/futex.h> #include <library/cpp/actors/util/intrinsics.h> diff --git a/library/cpp/actors/core/executor_pool_united.h b/library/cpp/actors/core/executor_pool_united.h index 7b9aee74ec..a090ba2466 100644 --- a/library/cpp/actors/core/executor_pool_united.h +++ b/library/cpp/actors/core/executor_pool_united.h @@ -5,7 +5,7 @@ #include "scheduler_queue.h" #include "executor_pool_base.h" -#include <library/cpp/actors/util/unordered_cache.h> +#include <library/cpp/actors/util/unordered_cache.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include <library/cpp/actors/util/unordered_cache.h> diff --git a/library/cpp/actors/core/executor_pool_united_ut.cpp b/library/cpp/actors/core/executor_pool_united_ut.cpp index d6a53010c2..d4df17f1b8 100644 --- a/library/cpp/actors/core/executor_pool_united_ut.cpp +++ b/library/cpp/actors/core/executor_pool_united_ut.cpp @@ -3,10 +3,10 @@ #include "hfunc.h" #include "scheduler_basic.h" -#include <library/cpp/actors/util/should_continue.h> +#include <library/cpp/actors/util/should_continue.h> #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/protos/unittests.pb.h> +#include <library/cpp/actors/protos/unittests.pb.h> using namespace NActors; diff --git a/library/cpp/actors/core/executor_thread.cpp b/library/cpp/actors/core/executor_thread.cpp index 2d840fa32a..446b651efd 100644 --- a/library/cpp/actors/core/executor_thread.cpp +++ b/library/cpp/actors/core/executor_thread.cpp @@ -5,13 +5,13 @@ #include "event.h" #include "events.h" -#include <library/cpp/actors/prof/tag.h> -#include <library/cpp/actors/util/affinity.h> +#include <library/cpp/actors/prof/tag.h> +#include <library/cpp/actors/util/affinity.h> #include <library/cpp/actors/util/datetime.h> -#include <library/cpp/actors/util/thread.h> +#include <library/cpp/actors/util/thread.h> #ifdef BALLOC -#include <library/cpp/balloc/optional/operators.h> +#include <library/cpp/balloc/optional/operators.h> #endif #ifdef _linux_ diff --git a/library/cpp/actors/core/interconnect.h b/library/cpp/actors/core/interconnect.h index 26349e4573..679a4b8cc6 100644 --- a/library/cpp/actors/core/interconnect.h +++ b/library/cpp/actors/core/interconnect.h @@ -2,7 +2,7 @@ #include "events.h" #include "event_local.h" -#include <library/cpp/actors/protos/interconnect.pb.h> +#include <library/cpp/actors/protos/interconnect.pb.h> #include <util/string/cast.h> #include <util/string/builder.h> diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h index 071c9a2d3d..c11a7cf3c1 100644 --- a/library/cpp/actors/core/log.h +++ b/library/cpp/actors/core/log.h @@ -13,13 +13,13 @@ #include <util/generic/vector.h> #include <util/string/printf.h> #include <util/string/builder.h> -#include <library/cpp/logger/all.h> +#include <library/cpp/logger/all.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include <library/cpp/monlib/metrics/metric_registry.h> -#include <library/cpp/json/writer/json.h> -#include <library/cpp/svnversion/svnversion.h> +#include <library/cpp/json/writer/json.h> +#include <library/cpp/svnversion/svnversion.h> -#include <library/cpp/actors/memory_log/memlog.h> +#include <library/cpp/actors/memory_log/memlog.h> // TODO: limit number of messages per second // TODO: make TLogComponentLevelRequest/Response network messages diff --git a/library/cpp/actors/core/log_ut.cpp b/library/cpp/actors/core/log_ut.cpp index 85439869bc..09b5f88ea2 100644 --- a/library/cpp/actors/core/log_ut.cpp +++ b/library/cpp/actors/core/log_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/testlib/test_runtime.h> +#include <library/cpp/actors/testlib/test_runtime.h> using namespace NMonitoring; using namespace NActors; diff --git a/library/cpp/actors/core/mailbox.h b/library/cpp/actors/core/mailbox.h index b097ed0db9..0bd9c4d314 100644 --- a/library/cpp/actors/core/mailbox.h +++ b/library/cpp/actors/core/mailbox.h @@ -5,7 +5,7 @@ #include "actor.h" #include "mailbox_queue_simple.h" #include "mailbox_queue_revolving.h" -#include <library/cpp/actors/util/unordered_cache.h> +#include <library/cpp/actors/util/unordered_cache.h> #include <library/cpp/threading/queue/mpsc_htswap.h> #include <library/cpp/threading/queue/mpsc_read_as_filled.h> #include <util/generic/hash.h> diff --git a/library/cpp/actors/core/mailbox_queue_revolving.h b/library/cpp/actors/core/mailbox_queue_revolving.h index 8524c78856..b0e78a18db 100644 --- a/library/cpp/actors/core/mailbox_queue_revolving.h +++ b/library/cpp/actors/core/mailbox_queue_revolving.h @@ -1,7 +1,7 @@ #pragma once #include "defs.h" -#include <library/cpp/actors/util/queue_chunk.h> +#include <library/cpp/actors/util/queue_chunk.h> namespace NActors { // add some concurrency to basic queue to avoid hangs under contention (we pay with memory, so use only when really expect contention) diff --git a/library/cpp/actors/core/mailbox_queue_simple.h b/library/cpp/actors/core/mailbox_queue_simple.h index a47f5cadcd..2e44c21adb 100644 --- a/library/cpp/actors/core/mailbox_queue_simple.h +++ b/library/cpp/actors/core/mailbox_queue_simple.h @@ -1,8 +1,8 @@ #pragma once #include "defs.h" -#include <library/cpp/actors/util/ticket_lock.h> -#include <library/cpp/actors/util/queue_oneone_inplace.h> +#include <library/cpp/actors/util/ticket_lock.h> +#include <library/cpp/actors/util/queue_oneone_inplace.h> namespace NActors { // dead-simple one-one queue, based on serializability guaranties of x64 and ticket lock to ensure writer unicity. diff --git a/library/cpp/actors/core/probes.h b/library/cpp/actors/core/probes.h index 2faeeea2e8..4912d6dd26 100644 --- a/library/cpp/actors/core/probes.h +++ b/library/cpp/actors/core/probes.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <util/generic/vector.h> #define LWACTORID(x) (x).RawX1(), (x).RawX2(), (x).NodeId(), (x).PoolID() diff --git a/library/cpp/actors/core/scheduler_actor.cpp b/library/cpp/actors/core/scheduler_actor.cpp index 57400d2ec1..febc5e40dd 100644 --- a/library/cpp/actors/core/scheduler_actor.cpp +++ b/library/cpp/actors/core/scheduler_actor.cpp @@ -4,7 +4,7 @@ #include "scheduler_actor.h" #include "scheduler_queue.h" -#include <library/cpp/actors/interconnect/poller_actor.h> +#include <library/cpp/actors/interconnect/poller_actor.h> #include <util/system/hp_timer.h> #ifdef __linux__ diff --git a/library/cpp/actors/core/scheduler_actor_ut.cpp b/library/cpp/actors/core/scheduler_actor_ut.cpp index 2a5114a57a..09b7369d36 100644 --- a/library/cpp/actors/core/scheduler_actor_ut.cpp +++ b/library/cpp/actors/core/scheduler_actor_ut.cpp @@ -6,7 +6,7 @@ #include "events.h" #include "event_local.h" #include "hfunc.h" -#include <library/cpp/actors/interconnect/poller_actor.h> +#include <library/cpp/actors/interconnect/poller_actor.h> #include <library/cpp/testing/unittest/registar.h> #include <util/system/sanitizers.h> diff --git a/library/cpp/actors/core/scheduler_basic.cpp b/library/cpp/actors/core/scheduler_basic.cpp index 38d4eac1fa..fba200e16b 100644 --- a/library/cpp/actors/core/scheduler_basic.cpp +++ b/library/cpp/actors/core/scheduler_basic.cpp @@ -2,10 +2,10 @@ #include "scheduler_queue.h" #include <library/cpp/actors/util/datetime.h> -#include <library/cpp/actors/util/thread.h> +#include <library/cpp/actors/util/thread.h> #ifdef BALLOC -#include <library/cpp/balloc/optional/operators.h> +#include <library/cpp/balloc/optional/operators.h> #endif namespace NActors { diff --git a/library/cpp/actors/core/scheduler_basic.h b/library/cpp/actors/core/scheduler_basic.h index 952d16fb91..2ccde39235 100644 --- a/library/cpp/actors/core/scheduler_basic.h +++ b/library/cpp/actors/core/scheduler_basic.h @@ -3,7 +3,7 @@ #include "actorsystem.h" #include "monotonic.h" #include "scheduler_queue.h" -#include <library/cpp/actors/util/queue_chunk.h> +#include <library/cpp/actors/util/queue_chunk.h> #include <library/cpp/threading/future/legacy_future.h> #include <util/generic/hash.h> #include <util/generic/map.h> diff --git a/library/cpp/actors/core/scheduler_queue.h b/library/cpp/actors/core/scheduler_queue.h index c6cdb12004..3b8fac28f0 100644 --- a/library/cpp/actors/core/scheduler_queue.h +++ b/library/cpp/actors/core/scheduler_queue.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/util/queue_chunk.h> +#include <library/cpp/actors/util/queue_chunk.h> namespace NActors { class IEventHandle; diff --git a/library/cpp/actors/core/ut/ya.make b/library/cpp/actors/core/ut/ya.make index 9621339f78..3ee28d5850 100644 --- a/library/cpp/actors/core/ut/ya.make +++ b/library/cpp/actors/core/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/actors/core) +UNITTEST_FOR(library/cpp/actors/core) OWNER( alexvru @@ -24,8 +24,8 @@ ENDIF() PEERDIR( - library/cpp/actors/interconnect - library/cpp/actors/testlib + library/cpp/actors/interconnect + library/cpp/actors/testlib ) SRCS( diff --git a/library/cpp/actors/core/ya.make b/library/cpp/actors/core/ya.make index 217d467b57..880a9d00db 100644 --- a/library/cpp/actors/core/ya.make +++ b/library/cpp/actors/core/ya.make @@ -14,7 +14,7 @@ ENDIF() IF (ALLOCATOR == "B" OR ALLOCATOR == "BS" OR ALLOCATOR == "C") CXXFLAGS(-DBALLOC) PEERDIR( - library/cpp/balloc/optional + library/cpp/balloc/optional ) ENDIF() @@ -103,16 +103,16 @@ GENERATE_ENUM_SERIALIZATION(defs.h) GENERATE_ENUM_SERIALIZATION(actor.h) PEERDIR( - library/cpp/actors/memory_log - library/cpp/actors/prof - library/cpp/actors/protos - library/cpp/actors/util - library/cpp/execprofile - library/cpp/json/writer - library/cpp/logger - library/cpp/lwtrace + library/cpp/actors/memory_log + library/cpp/actors/prof + library/cpp/actors/protos + library/cpp/actors/util + library/cpp/execprofile + library/cpp/json/writer + library/cpp/logger + library/cpp/lwtrace library/cpp/monlib/dynamic_counters - library/cpp/svnversion + library/cpp/svnversion library/cpp/threading/future ) diff --git a/library/cpp/actors/dnscachelib/probes.h b/library/cpp/actors/dnscachelib/probes.h index 6880de8e6c..313b7b8712 100644 --- a/library/cpp/actors/dnscachelib/probes.h +++ b/library/cpp/actors/dnscachelib/probes.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #define DNSCACHELIB_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ PROBE(Created, GROUPS(), TYPES(), NAMES()) \ diff --git a/library/cpp/actors/dnscachelib/ya.make b/library/cpp/actors/dnscachelib/ya.make index 9e82c72dc1..e3a6ad6202 100644 --- a/library/cpp/actors/dnscachelib/ya.make +++ b/library/cpp/actors/dnscachelib/ya.make @@ -18,7 +18,7 @@ SRCS( PEERDIR( contrib/libs/c-ares - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/actors/helpers/activeactors.h b/library/cpp/actors/helpers/activeactors.h index 52b8fc1d39..0fdb0fab10 100644 --- a/library/cpp/actors/helpers/activeactors.h +++ b/library/cpp/actors/helpers/activeactors.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/actors/core/actor.h> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/events.h> #include <util/generic/hash_set.h> namespace NActors { diff --git a/library/cpp/actors/helpers/flow_controlled_queue.cpp b/library/cpp/actors/helpers/flow_controlled_queue.cpp index 52c30d6a4d..d75cc54023 100644 --- a/library/cpp/actors/helpers/flow_controlled_queue.cpp +++ b/library/cpp/actors/helpers/flow_controlled_queue.cpp @@ -1,7 +1,7 @@ #include "flow_controlled_queue.h" -#include <library/cpp/actors/core/interconnect.h> -#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/interconnect.h> +#include <library/cpp/actors/core/hfunc.h> #include <library/cpp/actors/util/datetime.h> #include <util/generic/deque.h> diff --git a/library/cpp/actors/helpers/flow_controlled_queue.h b/library/cpp/actors/helpers/flow_controlled_queue.h index 89c380bbf4..d250405304 100644 --- a/library/cpp/actors/helpers/flow_controlled_queue.h +++ b/library/cpp/actors/helpers/flow_controlled_queue.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> namespace NActors { diff --git a/library/cpp/actors/helpers/future_callback.h b/library/cpp/actors/helpers/future_callback.h index 1939d06b34..8ca0d99fda 100644 --- a/library/cpp/actors/helpers/future_callback.h +++ b/library/cpp/actors/helpers/future_callback.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> #include <library/cpp/actors/core/hfunc.h> namespace NActors { diff --git a/library/cpp/actors/helpers/selfping_actor.cpp b/library/cpp/actors/helpers/selfping_actor.cpp index e1485ddf90..f9bfaf8dc0 100644 --- a/library/cpp/actors/helpers/selfping_actor.cpp +++ b/library/cpp/actors/helpers/selfping_actor.cpp @@ -1,10 +1,10 @@ #include "selfping_actor.h" -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/hfunc.h> #include <library/cpp/containers/stack_vector/stack_vec.h> -#include <library/cpp/sliding_window/sliding_window.h> +#include <library/cpp/sliding_window/sliding_window.h> namespace NActors { diff --git a/library/cpp/actors/helpers/ya.make b/library/cpp/actors/helpers/ya.make index dafb8c0e17..d8771179de 100644 --- a/library/cpp/actors/helpers/ya.make +++ b/library/cpp/actors/helpers/ya.make @@ -13,7 +13,7 @@ SRCS( ) PEERDIR( - library/cpp/actors/core + library/cpp/actors/core library/cpp/monlib/dynamic_counters ) diff --git a/library/cpp/actors/http/http_cache.cpp b/library/cpp/actors/http/http_cache.cpp index e9fa22ff34..27c4eeb6f3 100644 --- a/library/cpp/actors/http/http_cache.cpp +++ b/library/cpp/actors/http/http_cache.cpp @@ -1,11 +1,11 @@ #include "http.h" #include "http_proxy.h" #include "http_cache.h" -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/executor_pool_basic.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/scheduler_basic.h> -#include <library/cpp/actors/http/http.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/executor_pool_basic.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/scheduler_basic.h> +#include <library/cpp/actors/http/http.h> #include <library/cpp/digest/md5/md5.h> #include <util/digest/multi.h> #include <util/generic/queue.h> diff --git a/library/cpp/actors/http/http_cache.h b/library/cpp/actors/http/http_cache.h index e3746471cc..ac38bdcac8 100644 --- a/library/cpp/actors/http/http_cache.h +++ b/library/cpp/actors/http/http_cache.h @@ -1,5 +1,5 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> #include "http.h" namespace NHttp { diff --git a/library/cpp/actors/http/http_config.h b/library/cpp/actors/http/http_config.h index 3402770eb4..faeff79449 100644 --- a/library/cpp/actors/http/http_config.h +++ b/library/cpp/actors/http/http_config.h @@ -1,7 +1,7 @@ #pragma once #include <util/network/sock.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/protos/services_common.pb.h> namespace NHttp { diff --git a/library/cpp/actors/http/http_proxy.h b/library/cpp/actors/http/http_proxy.h index 868fc81e73..afd0170997 100644 --- a/library/cpp/actors/http/http_proxy.h +++ b/library/cpp/actors/http/http_proxy.h @@ -1,13 +1,13 @@ #pragma once -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/actor.h> -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/event_local.h> -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/interconnect/poller_actor.h> -#include <library/cpp/dns/cache.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/event_local.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/interconnect/poller_actor.h> +#include <library/cpp/dns/cache.h> #include <library/cpp/monlib/metrics/metric_registry.h> #include <util/generic/variant.h> #include "http.h" diff --git a/library/cpp/actors/http/http_static.cpp b/library/cpp/actors/http/http_static.cpp index e89f5c2e44..c075c5f693 100644 --- a/library/cpp/actors/http/http_static.cpp +++ b/library/cpp/actors/http/http_static.cpp @@ -1,10 +1,10 @@ #include "http_proxy.h" #include "http_static.h" -#include <library/cpp/actors/core/executor_pool_basic.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/scheduler_basic.h> -#include <library/cpp/actors/http/http.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/actors/core/executor_pool_basic.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/scheduler_basic.h> +#include <library/cpp/actors/http/http.h> +#include <library/cpp/resource/resource.h> #include <util/folder/path.h> #include <util/stream/file.h> diff --git a/library/cpp/actors/http/http_static.h b/library/cpp/actors/http/http_static.h index 04023ab1cd..f91e15dfb1 100644 --- a/library/cpp/actors/http/http_static.h +++ b/library/cpp/actors/http/http_static.h @@ -1,5 +1,5 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> #include "http.h" namespace NHttp { diff --git a/library/cpp/actors/http/http_ut.cpp b/library/cpp/actors/http/http_ut.cpp index 0cd80087f7..4c922f8d0f 100644 --- a/library/cpp/actors/http/http_ut.cpp +++ b/library/cpp/actors/http/http_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> -#include <library/cpp/actors/core/executor_pool_basic.h> -#include <library/cpp/actors/core/scheduler_basic.h> -#include <library/cpp/actors/testlib/test_runtime.h> +#include <library/cpp/actors/core/executor_pool_basic.h> +#include <library/cpp/actors/core/scheduler_basic.h> +#include <library/cpp/actors/testlib/test_runtime.h> #include <util/system/tempfile.h> #include "http.h" #include "http_proxy.h" diff --git a/library/cpp/actors/http/ut/ya.make b/library/cpp/actors/http/ut/ya.make index 43f0b8e7e2..8b4c04c4d3 100644 --- a/library/cpp/actors/http/ut/ya.make +++ b/library/cpp/actors/http/ut/ya.make @@ -1,11 +1,11 @@ -UNITTEST_FOR(library/cpp/actors/http) +UNITTEST_FOR(library/cpp/actors/http) OWNER(xenoxeno) SIZE(SMALL) PEERDIR( - library/cpp/actors/testlib + library/cpp/actors/testlib ) IF (NOT OS_WINDOWS) diff --git a/library/cpp/actors/http/ya.make b/library/cpp/actors/http/ya.make index 909a70c681..7ce68b7a75 100644 --- a/library/cpp/actors/http/ya.make +++ b/library/cpp/actors/http/ya.make @@ -23,9 +23,9 @@ SRCS( PEERDIR( contrib/libs/openssl - library/cpp/actors/core - library/cpp/actors/interconnect - library/cpp/dns + library/cpp/actors/core + library/cpp/actors/interconnect + library/cpp/dns library/cpp/monlib/metrics library/cpp/string_utils/quote ) diff --git a/library/cpp/actors/interconnect/event_filter.h b/library/cpp/actors/interconnect/event_filter.h index 2c482c60b2..47dabf5f16 100644 --- a/library/cpp/actors/interconnect/event_filter.h +++ b/library/cpp/actors/interconnect/event_filter.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/event.h> +#include <library/cpp/actors/core/event.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/events_local.h b/library/cpp/actors/interconnect/events_local.h index d57fb5d444..8a46ffd535 100644 --- a/library/cpp/actors/interconnect/events_local.h +++ b/library/cpp/actors/interconnect/events_local.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/event_local.h> -#include <library/cpp/actors/protos/interconnect.pb.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/event_local.h> +#include <library/cpp/actors/protos/interconnect.pb.h> #include <util/generic/deque.h> #include <util/network/address.h> diff --git a/library/cpp/actors/interconnect/interconnect.h b/library/cpp/actors/interconnect/interconnect.h index 6d302c09b4..225a5243fd 100644 --- a/library/cpp/actors/interconnect/interconnect.h +++ b/library/cpp/actors/interconnect/interconnect.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/interconnect.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/interconnect.h> #include <util/generic/map.h> #include <util/network/address.h> diff --git a/library/cpp/actors/interconnect/interconnect_channel.cpp b/library/cpp/actors/interconnect/interconnect_channel.cpp index c0323e87cb..a66ba2a154 100644 --- a/library/cpp/actors/interconnect/interconnect_channel.cpp +++ b/library/cpp/actors/interconnect/interconnect_channel.cpp @@ -1,12 +1,12 @@ #include "interconnect_channel.h" -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/executor_thread.h> -#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/executor_thread.h> +#include <library/cpp/actors/core/log.h> #include <library/cpp/actors/core/probes.h> -#include <library/cpp/actors/protos/services_common.pb.h> -#include <library/cpp/actors/prof/tag.h> -#include <library/cpp/digest/crc32c/crc32c.h> +#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/prof/tag.h> +#include <library/cpp/digest/crc32c/crc32c.h> LWTRACE_USING(ACTORLIB_PROVIDER); diff --git a/library/cpp/actors/interconnect/interconnect_channel.h b/library/cpp/actors/interconnect/interconnect_channel.h index edaa82ba95..e4a0ae3cda 100644 --- a/library/cpp/actors/interconnect/interconnect_channel.h +++ b/library/cpp/actors/interconnect/interconnect_channel.h @@ -1,15 +1,15 @@ #pragma once #include <library/cpp/monlib/dynamic_counters/counters.h> -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/event_load.h> -#include <library/cpp/actors/util/rope.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/event_load.h> +#include <library/cpp/actors/util/rope.h> #include <util/generic/deque.h> #include <util/generic/vector.h> #include <util/generic/map.h> #include <util/stream/walk.h> -#include <library/cpp/actors/wilson/wilson_event.h> -#include <library/cpp/actors/helpers/mon_histogram_helper.h> +#include <library/cpp/actors/wilson/wilson_event.h> +#include <library/cpp/actors/helpers/mon_histogram_helper.h> #include "interconnect_common.h" #include "interconnect_counters.h" diff --git a/library/cpp/actors/interconnect/interconnect_common.h b/library/cpp/actors/interconnect/interconnect_common.h index 0cc545fcc7..285709a00c 100644 --- a/library/cpp/actors/interconnect/interconnect_common.h +++ b/library/cpp/actors/interconnect/interconnect_common.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/actors/core/actorid.h> -#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/actorid.h> +#include <library/cpp/actors/core/actorsystem.h> #include <library/cpp/actors/util/datetime.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include <library/cpp/monlib/metrics/metric_registry.h> diff --git a/library/cpp/actors/interconnect/interconnect_handshake.cpp b/library/cpp/actors/interconnect/interconnect_handshake.cpp index d7196b142f..9ede998d8e 100644 --- a/library/cpp/actors/interconnect/interconnect_handshake.cpp +++ b/library/cpp/actors/interconnect/interconnect_handshake.cpp @@ -1,9 +1,9 @@ #include "interconnect_handshake.h" #include "interconnect_tcp_proxy.h" -#include <library/cpp/actors/core/actor_coroutine.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/actor_coroutine.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include <util/system/getpid.h> #include <google/protobuf/text_format.h> diff --git a/library/cpp/actors/interconnect/interconnect_handshake.h b/library/cpp/actors/interconnect/interconnect_handshake.h index 98608c6675..b3c0db6c5d 100644 --- a/library/cpp/actors/interconnect/interconnect_handshake.h +++ b/library/cpp/actors/interconnect/interconnect_handshake.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/core/events.h> #include "interconnect_common.h" #include "interconnect_impl.h" diff --git a/library/cpp/actors/interconnect/interconnect_impl.h b/library/cpp/actors/interconnect/interconnect_impl.h index 0787b3dfb1..ee29e4d397 100644 --- a/library/cpp/actors/interconnect/interconnect_impl.h +++ b/library/cpp/actors/interconnect/interconnect_impl.h @@ -1,9 +1,9 @@ #pragma once #include "interconnect.h" -#include <library/cpp/actors/protos/interconnect.pb.h> -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/helpers/mon_histogram_helper.h> +#include <library/cpp/actors/protos/interconnect.pb.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/helpers/mon_histogram_helper.h> #include <library/cpp/monlib/dynamic_counters/counters.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/interconnect_mon.h b/library/cpp/actors/interconnect/interconnect_mon.h index 1150a22ca8..3fb26053fb 100644 --- a/library/cpp/actors/interconnect/interconnect_mon.h +++ b/library/cpp/actors/interconnect/interconnect_mon.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> #include "interconnect_common.h" namespace NInterconnect { diff --git a/library/cpp/actors/interconnect/interconnect_nameserver_table.cpp b/library/cpp/actors/interconnect/interconnect_nameserver_table.cpp index ed66bbce0b..43419bf70d 100644 --- a/library/cpp/actors/interconnect/interconnect_nameserver_table.cpp +++ b/library/cpp/actors/interconnect/interconnect_nameserver_table.cpp @@ -4,8 +4,8 @@ #include "interconnect_nameserver_base.h" #include "events_local.h" -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/memory_log/memlog.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/memory_log/memlog.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/interconnect_stream.cpp b/library/cpp/actors/interconnect/interconnect_stream.cpp index feeba23880..158ebc9e1d 100644 --- a/library/cpp/actors/interconnect/interconnect_stream.cpp +++ b/library/cpp/actors/interconnect/interconnect_stream.cpp @@ -1,6 +1,6 @@ #include "interconnect_stream.h" #include "logging.h" -#include <library/cpp/openssl/init/init.h> +#include <library/cpp/openssl/init/init.h> #include <util/network/socket.h> #include <openssl/ssl.h> #include <openssl/err.h> diff --git a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp index cd7d337f41..0abe9fe659 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp +++ b/library/cpp/actors/interconnect/interconnect_tcp_input_session.cpp @@ -1,6 +1,6 @@ #include "interconnect_tcp_session.h" #include "interconnect_tcp_proxy.h" -#include <library/cpp/actors/core/probes.h> +#include <library/cpp/actors/core/probes.h> #include <library/cpp/actors/util/datetime.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/interconnect_tcp_proxy.cpp b/library/cpp/actors/interconnect/interconnect_tcp_proxy.cpp index 183949d29e..7e2d8ccb94 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_proxy.cpp +++ b/library/cpp/actors/interconnect/interconnect_tcp_proxy.cpp @@ -1,8 +1,8 @@ #include "interconnect_tcp_proxy.h" #include "interconnect_handshake.h" #include "interconnect_tcp_session.h" -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include <library/cpp/monlib/service/pages/templates.h> #include <util/system/getpid.h> diff --git a/library/cpp/actors/interconnect/interconnect_tcp_proxy.h b/library/cpp/actors/interconnect/interconnect_tcp_proxy.h index 80dfca7e78..023e5bd1ee 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_proxy.h +++ b/library/cpp/actors/interconnect/interconnect_tcp_proxy.h @@ -1,9 +1,9 @@ #pragma once -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/core/events.h> #include <library/cpp/monlib/dynamic_counters/counters.h> #include "interconnect_common.h" diff --git a/library/cpp/actors/interconnect/interconnect_tcp_server.cpp b/library/cpp/actors/interconnect/interconnect_tcp_server.cpp index 9e4845475f..b95c994598 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_server.cpp +++ b/library/cpp/actors/interconnect/interconnect_tcp_server.cpp @@ -1,8 +1,8 @@ #include "interconnect_tcp_server.h" #include "interconnect_handshake.h" -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include "interconnect_common.h" diff --git a/library/cpp/actors/interconnect/interconnect_tcp_server.h b/library/cpp/actors/interconnect/interconnect_tcp_server.h index 3870cb7091..fc71073c2d 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_server.h +++ b/library/cpp/actors/interconnect/interconnect_tcp_server.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/core/events.h> #include "interconnect_common.h" #include "poller_actor.h" diff --git a/library/cpp/actors/interconnect/interconnect_tcp_session.cpp b/library/cpp/actors/interconnect/interconnect_tcp_session.cpp index cebfdcbb50..2ded7f9f53 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_session.cpp +++ b/library/cpp/actors/interconnect/interconnect_tcp_session.cpp @@ -2,11 +2,11 @@ #include "interconnect_tcp_session.h" #include "interconnect_handshake.h" -#include <library/cpp/actors/core/probes.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/interconnect.h> +#include <library/cpp/actors/core/probes.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/interconnect.h> #include <library/cpp/actors/util/datetime.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include <library/cpp/monlib/service/pages/templates.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/interconnect_tcp_session.h b/library/cpp/actors/interconnect/interconnect_tcp_session.h index 4d93a30937..7fc00dbcc5 100644 --- a/library/cpp/actors/interconnect/interconnect_tcp_session.h +++ b/library/cpp/actors/interconnect/interconnect_tcp_session.h @@ -1,17 +1,17 @@ #pragma once -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/helpers/mon_histogram_helper.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/helpers/mon_histogram_helper.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include <library/cpp/actors/util/datetime.h> -#include <library/cpp/actors/util/rope.h> -#include <library/cpp/actors/util/funnel_queue.h> -#include <library/cpp/actors/util/recentwnd.h> +#include <library/cpp/actors/util/rope.h> +#include <library/cpp/actors/util/funnel_queue.h> +#include <library/cpp/actors/util/recentwnd.h> #include <library/cpp/monlib/dynamic_counters/counters.h> -#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> #include <util/generic/queue.h> #include <util/generic/deque.h> diff --git a/library/cpp/actors/interconnect/load.cpp b/library/cpp/actors/interconnect/load.cpp index ae9a2d85d6..2a8443da71 100644 --- a/library/cpp/actors/interconnect/load.cpp +++ b/library/cpp/actors/interconnect/load.cpp @@ -1,11 +1,11 @@ #include "load.h" #include "interconnect_common.h" #include "events_local.h" -#include <library/cpp/actors/protos/services_common.pb.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/hfunc.h> #include <util/generic/queue.h> namespace NInterconnect { diff --git a/library/cpp/actors/interconnect/load.h b/library/cpp/actors/interconnect/load.h index 258b035f67..0a01a0dc04 100644 --- a/library/cpp/actors/interconnect/load.h +++ b/library/cpp/actors/interconnect/load.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> namespace NInterconnect { // load responder -- lives on every node as a service actor diff --git a/library/cpp/actors/interconnect/logging.h b/library/cpp/actors/interconnect/logging.h index 5dd16f3b62..c429d1cade 100644 --- a/library/cpp/actors/interconnect/logging.h +++ b/library/cpp/actors/interconnect/logging.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/protos/services_common.pb.h> #define LOG_LOG_IC_X(component, marker, priority, ...) \ do { \ diff --git a/library/cpp/actors/interconnect/packet.h b/library/cpp/actors/interconnect/packet.h index 6a640f98a3..4ba50a2b5f 100644 --- a/library/cpp/actors/interconnect/packet.h +++ b/library/cpp/actors/interconnect/packet.h @@ -1,13 +1,13 @@ #pragma once -#include <library/cpp/actors/core/event_pb.h> -#include <library/cpp/actors/core/event_load.h> +#include <library/cpp/actors/core/event_pb.h> +#include <library/cpp/actors/core/event_load.h> #include <library/cpp/actors/core/events.h> #include <library/cpp/actors/core/actor.h> #include <library/cpp/containers/stack_vector/stack_vec.h> -#include <library/cpp/actors/util/rope.h> -#include <library/cpp/actors/prof/tag.h> -#include <library/cpp/digest/crc32c/crc32c.h> +#include <library/cpp/actors/util/rope.h> +#include <library/cpp/actors/prof/tag.h> +#include <library/cpp/digest/crc32c/crc32c.h> #include <library/cpp/lwtrace/shuttle.h> #include <util/generic/string.h> #include <util/generic/list.h> diff --git a/library/cpp/actors/interconnect/poller.h b/library/cpp/actors/interconnect/poller.h index ce48d6f2cb..ff7979369f 100644 --- a/library/cpp/actors/interconnect/poller.h +++ b/library/cpp/actors/interconnect/poller.h @@ -1,7 +1,7 @@ #pragma once #include <functional> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/events.h> namespace NActors { class TSharedDescriptor: public TThrRefBase { diff --git a/library/cpp/actors/interconnect/poller_actor.cpp b/library/cpp/actors/interconnect/poller_actor.cpp index b2c41d8afc..e75cbcaef4 100644 --- a/library/cpp/actors/interconnect/poller_actor.cpp +++ b/library/cpp/actors/interconnect/poller_actor.cpp @@ -2,12 +2,12 @@ #include "interconnect_common.h" #include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/hfunc.h> -#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/hfunc.h> +#include <library/cpp/actors/core/log.h> #include <library/cpp/actors/core/probes.h> #include <library/cpp/actors/protos/services_common.pb.h> -#include <library/cpp/actors/util/funnel_queue.h> +#include <library/cpp/actors/util/funnel_queue.h> #include <util/generic/intrlist.h> #include <util/system/thread.h> diff --git a/library/cpp/actors/interconnect/poller_actor.h b/library/cpp/actors/interconnect/poller_actor.h index b0291b25c6..f927b82089 100644 --- a/library/cpp/actors/interconnect/poller_actor.h +++ b/library/cpp/actors/interconnect/poller_actor.h @@ -2,7 +2,7 @@ #include "events_local.h" #include "poller.h" -#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actor.h> namespace NActors { struct TEvPollerRegister : TEventLocal<TEvPollerRegister, ui32(ENetwork::EvPollerRegister)> { diff --git a/library/cpp/actors/interconnect/poller_tcp_unit.cpp b/library/cpp/actors/interconnect/poller_tcp_unit.cpp index 9f6b9d3d82..59e7dda810 100644 --- a/library/cpp/actors/interconnect/poller_tcp_unit.cpp +++ b/library/cpp/actors/interconnect/poller_tcp_unit.cpp @@ -7,8 +7,8 @@ #include "poller_tcp_unit_select.h" #include "poller.h" -#include <library/cpp/actors/prof/tag.h> -#include <library/cpp/actors/util/intrinsics.h> +#include <library/cpp/actors/prof/tag.h> +#include <library/cpp/actors/util/intrinsics.h> #if defined _linux_ #include <pthread.h> diff --git a/library/cpp/actors/interconnect/poller_tcp_unit.h b/library/cpp/actors/interconnect/poller_tcp_unit.h index e0154719bc..692168b968 100644 --- a/library/cpp/actors/interconnect/poller_tcp_unit.h +++ b/library/cpp/actors/interconnect/poller_tcp_unit.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/thread.h> -#include <library/cpp/actors/util/funnel_queue.h> +#include <library/cpp/actors/util/funnel_queue.h> #include "interconnect_stream.h" diff --git a/library/cpp/actors/interconnect/slowpoke_actor.h b/library/cpp/actors/interconnect/slowpoke_actor.h index 884cabc321..4b02e5da48 100644 --- a/library/cpp/actors/interconnect/slowpoke_actor.h +++ b/library/cpp/actors/interconnect/slowpoke_actor.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> namespace NActors { diff --git a/library/cpp/actors/interconnect/ut/channel_scheduler_ut.cpp b/library/cpp/actors/interconnect/ut/channel_scheduler_ut.cpp index 156725eb85..565a511859 100644 --- a/library/cpp/actors/interconnect/ut/channel_scheduler_ut.cpp +++ b/library/cpp/actors/interconnect/ut/channel_scheduler_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/actors/interconnect/channel_scheduler.h> -#include <library/cpp/actors/interconnect/events_local.h> +#include <library/cpp/actors/interconnect/channel_scheduler.h> +#include <library/cpp/actors/interconnect/events_local.h> #include <library/cpp/testing/unittest/registar.h> using namespace NActors; diff --git a/library/cpp/actors/interconnect/ut/event_holder_pool_ut.cpp b/library/cpp/actors/interconnect/ut/event_holder_pool_ut.cpp index 0ee45288fc..e6b2bd4e4c 100644 --- a/library/cpp/actors/interconnect/ut/event_holder_pool_ut.cpp +++ b/library/cpp/actors/interconnect/ut/event_holder_pool_ut.cpp @@ -1,9 +1,9 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/event_local.h> -#include <library/cpp/actors/interconnect/interconnect_common.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/event_local.h> +#include <library/cpp/actors/interconnect/interconnect_common.h> #include <library/cpp/monlib/dynamic_counters/counters.h> -#include <library/cpp/actors/interconnect/event_holder_pool.h> +#include <library/cpp/actors/interconnect/event_holder_pool.h> #include <atomic> diff --git a/library/cpp/actors/interconnect/ut/large.cpp b/library/cpp/actors/interconnect/ut/large.cpp index 57d199b9f8..ba2a50c6f6 100644 --- a/library/cpp/actors/interconnect/ut/large.cpp +++ b/library/cpp/actors/interconnect/ut/large.cpp @@ -2,7 +2,7 @@ #include "lib/test_events.h" #include "lib/test_actors.h" -#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> #include <library/cpp/testing/unittest/tests_data.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h b/library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h index 84c739b612..2b6d27cd3f 100644 --- a/library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h +++ b/library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h @@ -3,8 +3,8 @@ #include "node.h" #include "interrupter.h" -#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> -#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> +#include <library/cpp/actors/core/events.h> #include <library/cpp/testing/unittest/tests_data.h> #include <util/generic/noncopyable.h> diff --git a/library/cpp/actors/interconnect/ut/lib/node.h b/library/cpp/actors/interconnect/ut/lib/node.h index 41ba59a03d..ff30b1445e 100644 --- a/library/cpp/actors/interconnect/ut/lib/node.h +++ b/library/cpp/actors/interconnect/ut/lib/node.h @@ -1,13 +1,13 @@ #pragma once -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/executor_pool_basic.h> -#include <library/cpp/actors/core/scheduler_basic.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/executor_pool_basic.h> +#include <library/cpp/actors/core/scheduler_basic.h> #include <library/cpp/actors/core/mailbox.h> #include <library/cpp/actors/dnsresolver/dnsresolver.h> -#include <library/cpp/actors/interconnect/interconnect_tcp_server.h> -#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_server.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> #include <library/cpp/actors/interconnect/interconnect_proxy_wrapper.h> using namespace NActors; diff --git a/library/cpp/actors/interconnect/ut/lib/test_events.h b/library/cpp/actors/interconnect/ut/lib/test_events.h index ecb59a6628..cd0d9e0152 100644 --- a/library/cpp/actors/interconnect/ut/lib/test_events.h +++ b/library/cpp/actors/interconnect/ut/lib/test_events.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/actors/interconnect/ut/protos/interconnect_test.pb.h> +#include <library/cpp/actors/interconnect/ut/protos/interconnect_test.pb.h> namespace NActors { enum { diff --git a/library/cpp/actors/interconnect/ut/ya.make b/library/cpp/actors/interconnect/ut/ya.make index 7cb3169a4d..2f5b13352e 100644 --- a/library/cpp/actors/interconnect/ut/ya.make +++ b/library/cpp/actors/interconnect/ut/ya.make @@ -24,10 +24,10 @@ SRCS( ) PEERDIR( - library/cpp/actors/core - library/cpp/actors/interconnect - library/cpp/actors/interconnect/ut/lib - library/cpp/actors/interconnect/ut/protos + library/cpp/actors/core + library/cpp/actors/interconnect + library/cpp/actors/interconnect/ut/lib + library/cpp/actors/interconnect/ut/protos library/cpp/actors/testlib library/cpp/digest/md5 library/cpp/testing/unittest diff --git a/library/cpp/actors/interconnect/ut_fat/main.cpp b/library/cpp/actors/interconnect/ut_fat/main.cpp index 7ff80ef8e5..5d19bc3003 100644 --- a/library/cpp/actors/interconnect/ut_fat/main.cpp +++ b/library/cpp/actors/interconnect/ut_fat/main.cpp @@ -1,11 +1,11 @@ -#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> -#include <library/cpp/actors/interconnect/ut/protos/interconnect_test.pb.h> -#include <library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h> -#include <library/cpp/actors/interconnect/ut/lib/interrupter.h> -#include <library/cpp/actors/interconnect/ut/lib/test_events.h> -#include <library/cpp/actors/interconnect/ut/lib/test_actors.h> -#include <library/cpp/actors/interconnect/ut/lib/node.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> +#include <library/cpp/actors/interconnect/ut/protos/interconnect_test.pb.h> +#include <library/cpp/actors/interconnect/ut/lib/ic_test_cluster.h> +#include <library/cpp/actors/interconnect/ut/lib/interrupter.h> +#include <library/cpp/actors/interconnect/ut/lib/test_events.h> +#include <library/cpp/actors/interconnect/ut/lib/test_actors.h> +#include <library/cpp/actors/interconnect/ut/lib/node.h> #include <library/cpp/testing/unittest/tests_data.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/actors/interconnect/ut_fat/ya.make b/library/cpp/actors/interconnect/ut_fat/ya.make index 40c7c971e1..6e58d08154 100644 --- a/library/cpp/actors/interconnect/ut_fat/ya.make +++ b/library/cpp/actors/interconnect/ut_fat/ya.make @@ -14,11 +14,11 @@ SRCS( ) PEERDIR( - library/cpp/actors/core - library/cpp/actors/interconnect + library/cpp/actors/core + library/cpp/actors/interconnect library/cpp/actors/interconnect/mock - library/cpp/actors/interconnect/ut/lib - library/cpp/actors/interconnect/ut/protos + library/cpp/actors/interconnect/ut/lib + library/cpp/actors/interconnect/ut/protos library/cpp/testing/unittest ) diff --git a/library/cpp/actors/interconnect/ya.make b/library/cpp/actors/interconnect/ya.make index df26c59353..60d29b0fc0 100644 --- a/library/cpp/actors/interconnect/ya.make +++ b/library/cpp/actors/interconnect/ya.make @@ -74,21 +74,21 @@ ENDIF() PEERDIR( contrib/libs/libc_compat contrib/libs/openssl - library/cpp/actors/core + library/cpp/actors/core library/cpp/actors/dnscachelib library/cpp/actors/dnsresolver - library/cpp/actors/helpers - library/cpp/actors/prof - library/cpp/actors/protos - library/cpp/actors/util - library/cpp/digest/crc32c + library/cpp/actors/helpers + library/cpp/actors/prof + library/cpp/actors/protos + library/cpp/actors/util + library/cpp/digest/crc32c library/cpp/json - library/cpp/lwtrace + library/cpp/lwtrace library/cpp/monlib/dynamic_counters library/cpp/monlib/metrics library/cpp/monlib/service/pages/tablesorter - library/cpp/openssl/init - library/cpp/packedtypes + library/cpp/openssl/init + library/cpp/packedtypes ) END() diff --git a/library/cpp/actors/prof/tag.cpp b/library/cpp/actors/prof/tag.cpp index f2452f3fed..9ccf03e1a9 100644 --- a/library/cpp/actors/prof/tag.cpp +++ b/library/cpp/actors/prof/tag.cpp @@ -1,8 +1,8 @@ #include "tag.h" #include "tcmalloc.h" -#include <library/cpp/charset/ci_string.h> -#include <library/cpp/containers/atomizer/atomizer.h> +#include <library/cpp/charset/ci_string.h> +#include <library/cpp/containers/atomizer/atomizer.h> #include <library/cpp/malloc/api/malloc.h> #if defined(PROFILE_MEMORY_ALLOCATIONS) diff --git a/library/cpp/actors/prof/ut/ya.make b/library/cpp/actors/prof/ut/ya.make index bb964c5385..47c58a8fb7 100644 --- a/library/cpp/actors/prof/ut/ya.make +++ b/library/cpp/actors/prof/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/actors/prof) +UNITTEST_FOR(library/cpp/actors/prof) OWNER( agri diff --git a/library/cpp/actors/prof/ya.make b/library/cpp/actors/prof/ya.make index e19ef01820..b5e2497563 100644 --- a/library/cpp/actors/prof/ya.make +++ b/library/cpp/actors/prof/ya.make @@ -10,14 +10,14 @@ SRCS( ) PEERDIR( - library/cpp/charset - library/cpp/containers/atomizer + library/cpp/charset + library/cpp/containers/atomizer ) IF (PROFILE_MEMORY_ALLOCATIONS) CFLAGS(-DPROFILE_MEMORY_ALLOCATIONS) PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api library/cpp/lfalloc/dbg_info library/cpp/ytalloc/api ) diff --git a/library/cpp/actors/protos/interconnect.proto b/library/cpp/actors/protos/interconnect.proto index 316ccdcd65..2e3b0d0d15 100644 --- a/library/cpp/actors/protos/interconnect.proto +++ b/library/cpp/actors/protos/interconnect.proto @@ -1,4 +1,4 @@ -import "library/cpp/actors/protos/actors.proto"; +import "library/cpp/actors/protos/actors.proto"; import "google/protobuf/descriptor.proto"; package NActorsInterconnect; diff --git a/library/cpp/actors/testlib/test_runtime.cpp b/library/cpp/actors/testlib/test_runtime.cpp index 458f6ec51a..6fa25b9965 100644 --- a/library/cpp/actors/testlib/test_runtime.cpp +++ b/library/cpp/actors/testlib/test_runtime.cpp @@ -1,16 +1,16 @@ #include "test_runtime.h" -#include <library/cpp/actors/core/actor_bootstrapped.h> -#include <library/cpp/actors/core/callstack.h> -#include <library/cpp/actors/core/executor_pool_basic.h> -#include <library/cpp/actors/core/executor_pool_io.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/scheduler_basic.h> +#include <library/cpp/actors/core/actor_bootstrapped.h> +#include <library/cpp/actors/core/callstack.h> +#include <library/cpp/actors/core/executor_pool_basic.h> +#include <library/cpp/actors/core/executor_pool_io.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/scheduler_basic.h> #include <library/cpp/actors/util/datetime.h> -#include <library/cpp/actors/protos/services_common.pb.h> +#include <library/cpp/actors/protos/services_common.pb.h> #include <library/cpp/random_provider/random_provider.h> -#include <library/cpp/actors/interconnect/interconnect.h> -#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> +#include <library/cpp/actors/interconnect/interconnect.h> +#include <library/cpp/actors/interconnect/interconnect_tcp_proxy.h> #include <library/cpp/actors/interconnect/interconnect_proxy_wrapper.h> #include <util/generic/maybe.h> diff --git a/library/cpp/actors/testlib/test_runtime.h b/library/cpp/actors/testlib/test_runtime.h index a68da49167..26e3b45c98 100644 --- a/library/cpp/actors/testlib/test_runtime.h +++ b/library/cpp/actors/testlib/test_runtime.h @@ -1,13 +1,13 @@ #pragma once -#include <library/cpp/actors/core/actor.h> -#include <library/cpp/actors/core/actorsystem.h> -#include <library/cpp/actors/core/log.h> -#include <library/cpp/actors/core/events.h> -#include <library/cpp/actors/core/executor_thread.h> -#include <library/cpp/actors/core/mailbox.h> -#include <library/cpp/actors/util/should_continue.h> -#include <library/cpp/actors/interconnect/poller_tcp.h> +#include <library/cpp/actors/core/actor.h> +#include <library/cpp/actors/core/actorsystem.h> +#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/events.h> +#include <library/cpp/actors/core/executor_thread.h> +#include <library/cpp/actors/core/mailbox.h> +#include <library/cpp/actors/util/should_continue.h> +#include <library/cpp/actors/interconnect/poller_tcp.h> #include <library/cpp/actors/interconnect/mock/ic_mock.h> #include <library/cpp/random_provider/random_provider.h> #include <library/cpp/time_provider/time_provider.h> diff --git a/library/cpp/actors/testlib/ya.make b/library/cpp/actors/testlib/ya.make index dedd349668..1afb3f6059 100644 --- a/library/cpp/actors/testlib/ya.make +++ b/library/cpp/actors/testlib/ya.make @@ -9,9 +9,9 @@ SRCS( ) PEERDIR( - library/cpp/actors/core + library/cpp/actors/core library/cpp/actors/interconnect/mock - library/cpp/actors/protos + library/cpp/actors/protos library/cpp/random_provider library/cpp/time_provider ) diff --git a/library/cpp/actors/util/ut/ya.make b/library/cpp/actors/util/ut/ya.make index c4cabb9b03..3b08b77984 100644 --- a/library/cpp/actors/util/ut/ya.make +++ b/library/cpp/actors/util/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/actors/util) +UNITTEST_FOR(library/cpp/actors/util) IF (WITH_VALGRIND) TIMEOUT(600) diff --git a/library/cpp/actors/wilson/wilson_event.h b/library/cpp/actors/wilson/wilson_event.h index ec3a096bc5..7d89c33b51 100644 --- a/library/cpp/actors/wilson/wilson_event.h +++ b/library/cpp/actors/wilson/wilson_event.h @@ -4,7 +4,7 @@ #include <library/cpp/string_utils/base64/base64.h> -#include <library/cpp/actors/core/log.h> +#include <library/cpp/actors/core/log.h> namespace NWilson { #if !defined(_win_) diff --git a/library/cpp/archive/ut/ya.make b/library/cpp/archive/ut/ya.make index 0d33a63c11..4f324ccfc6 100644 --- a/library/cpp/archive/ut/ya.make +++ b/library/cpp/archive/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(pg) PEERDIR( - ADDINCL library/cpp/archive + ADDINCL library/cpp/archive ) -SRCDIR(library/cpp/archive) +SRCDIR(library/cpp/archive) SRCS( yarchive_ut.cpp diff --git a/library/cpp/balloc/balloc.cpp b/library/cpp/balloc/balloc.cpp index cdf32632d3..fab489db4c 100644 --- a/library/cpp/balloc/balloc.cpp +++ b/library/cpp/balloc/balloc.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/balloc/lib/balloc.h> +#include <library/cpp/balloc/lib/balloc.h> #include <errno.h> namespace NBalloc { diff --git a/library/cpp/balloc/malloc-info.cpp b/library/cpp/balloc/malloc-info.cpp index cfdd20d127..604b1fb145 100644 --- a/library/cpp/balloc/malloc-info.cpp +++ b/library/cpp/balloc/malloc-info.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> #include <string.h> diff --git a/library/cpp/balloc/optional/operators.h b/library/cpp/balloc/optional/operators.h index fef01120c0..6107d28a6e 100644 --- a/library/cpp/balloc/optional/operators.h +++ b/library/cpp/balloc/optional/operators.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> #include <util/string/type.h> inline bool BallocEnabled() { diff --git a/library/cpp/balloc/optional/ya.make b/library/cpp/balloc/optional/ya.make index b50758e787..f740fc0b7d 100644 --- a/library/cpp/balloc/optional/ya.make +++ b/library/cpp/balloc/optional/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) END() diff --git a/library/cpp/balloc/ya.make b/library/cpp/balloc/ya.make index adba9190bd..d4457fbba9 100644 --- a/library/cpp/balloc/ya.make +++ b/library/cpp/balloc/ya.make @@ -19,7 +19,7 @@ ELSE() ) PEERDIR( - library/cpp/balloc/lib + library/cpp/balloc/lib ) ENDIF() diff --git a/library/cpp/binsaver/ut/binsaver_ut.cpp b/library/cpp/binsaver/ut/binsaver_ut.cpp index edd17fb58b..37eba5406f 100644 --- a/library/cpp/binsaver/ut/binsaver_ut.cpp +++ b/library/cpp/binsaver/ut/binsaver_ut.cpp @@ -1,7 +1,7 @@ -#include <library/cpp/binsaver/util_stream_io.h> -#include <library/cpp/binsaver/mem_io.h> -#include <library/cpp/binsaver/bin_saver.h> -#include <library/cpp/binsaver/ut_util/ut_util.h> +#include <library/cpp/binsaver/util_stream_io.h> +#include <library/cpp/binsaver/mem_io.h> +#include <library/cpp/binsaver/bin_saver.h> +#include <library/cpp/binsaver/ut_util/ut_util.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/buffer.h> diff --git a/library/cpp/binsaver/ut/ya.make b/library/cpp/binsaver/ut/ya.make index 7e3fb5c1ba..43dc20bff7 100644 --- a/library/cpp/binsaver/ut/ya.make +++ b/library/cpp/binsaver/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/binsaver) +UNITTEST_FOR(library/cpp/binsaver) OWNER(gulin) @@ -6,6 +6,6 @@ SRCS( binsaver_ut.cpp ) -PEERDIR(library/cpp/binsaver/ut_util) +PEERDIR(library/cpp/binsaver/ut_util) END() diff --git a/library/cpp/binsaver/ut_util/ut_util.h b/library/cpp/binsaver/ut_util/ut_util.h index e07a4f6fe5..52e7bcf8e1 100644 --- a/library/cpp/binsaver/ut_util/ut_util.h +++ b/library/cpp/binsaver/ut_util/ut_util.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/binsaver/bin_saver.h> -#include <library/cpp/binsaver/mem_io.h> -#include <library/cpp/binsaver/util_stream_io.h> +#include <library/cpp/binsaver/bin_saver.h> +#include <library/cpp/binsaver/mem_io.h> +#include <library/cpp/binsaver/util_stream_io.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/binsaver/ut_util/ya.make b/library/cpp/binsaver/ut_util/ya.make index 6023a2cd8e..7e60f13ef3 100644 --- a/library/cpp/binsaver/ut_util/ya.make +++ b/library/cpp/binsaver/ut_util/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/binsaver + library/cpp/binsaver library/cpp/testing/unittest ) diff --git a/library/cpp/bit_io/bitoutput.h b/library/cpp/bit_io/bitoutput.h index 255b93c0a0..2b886c1f02 100644 --- a/library/cpp/bit_io/bitoutput.h +++ b/library/cpp/bit_io/bitoutput.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/deprecated/accessors/accessors.h> +#include <library/cpp/deprecated/accessors/accessors.h> #include <util/stream/output.h> #include <util/system/yassert.h> diff --git a/library/cpp/bit_io/ut/ya.make b/library/cpp/bit_io/ut/ya.make index 73ae39ff04..07ee5b4997 100644 --- a/library/cpp/bit_io/ut/ya.make +++ b/library/cpp/bit_io/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/bit_io) +UNITTEST_FOR(library/cpp/bit_io) OWNER( velavokr diff --git a/library/cpp/bit_io/ya.make b/library/cpp/bit_io/ya.make index fc3359138d..df1de81ff9 100644 --- a/library/cpp/bit_io/ya.make +++ b/library/cpp/bit_io/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/deprecated/accessors + library/cpp/deprecated/accessors ) SRCS( diff --git a/library/cpp/blockcodecs/README.md b/library/cpp/blockcodecs/README.md index b1f0d884c9..417917a475 100644 --- a/library/cpp/blockcodecs/README.md +++ b/library/cpp/blockcodecs/README.md @@ -1,5 +1,5 @@ This is a simple library for block data compression (this means data is compressed/uncompressed -by whole blocks in memory). It's a lite-version of the `library/cpp/codecs`. Lite here means that it +by whole blocks in memory). It's a lite-version of the `library/cpp/codecs`. Lite here means that it provide only well-known compression algorithms, without the possibility of learning. There are two possible ways to work with it. @@ -19,5 +19,5 @@ write to the resulting stream). Using codec plugins =================== If you don't want your code to bloat from unused codecs, you can use the small version of the -library: `library/cpp/blockcodecs/core`. In that case, you need to manually set `PEERDIR()`s to -needed codecs (i.e. `PEERDIR(library/cpp/blockcodecs/codecs/lzma)`). +library: `library/cpp/blockcodecs/core`. In that case, you need to manually set `PEERDIR()`s to +needed codecs (i.e. `PEERDIR(library/cpp/blockcodecs/codecs/lzma)`). diff --git a/library/cpp/blockcodecs/codecs.h b/library/cpp/blockcodecs/codecs.h index 8d9ae42722..fd499b54b0 100644 --- a/library/cpp/blockcodecs/codecs.h +++ b/library/cpp/blockcodecs/codecs.h @@ -1,3 +1,3 @@ #pragma once -#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/codecs.h> diff --git a/library/cpp/blockcodecs/codecs/brotli/brotli.cpp b/library/cpp/blockcodecs/codecs/brotli/brotli.cpp index ff7d413105..6e3cd971bd 100644 --- a/library/cpp/blockcodecs/codecs/brotli/brotli.cpp +++ b/library/cpp/blockcodecs/codecs/brotli/brotli.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/brotli/include/brotli/encode.h> #include <contrib/libs/brotli/include/brotli/decode.h> diff --git a/library/cpp/blockcodecs/codecs/brotli/ya.make b/library/cpp/blockcodecs/codecs/brotli/ya.make index dfe81fa403..17aff0bb72 100644 --- a/library/cpp/blockcodecs/codecs/brotli/ya.make +++ b/library/cpp/blockcodecs/codecs/brotli/ya.make @@ -5,7 +5,7 @@ OWNER(pg) PEERDIR( contrib/libs/brotli/enc contrib/libs/brotli/dec - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/bzip/bzip.cpp b/library/cpp/blockcodecs/codecs/bzip/bzip.cpp index 645ed27421..3a5cfdd0e9 100644 --- a/library/cpp/blockcodecs/codecs/bzip/bzip.cpp +++ b/library/cpp/blockcodecs/codecs/bzip/bzip.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/libbz2/bzlib.h> diff --git a/library/cpp/blockcodecs/codecs/bzip/ya.make b/library/cpp/blockcodecs/codecs/bzip/ya.make index c2dd3d29d6..f0a8aefd62 100644 --- a/library/cpp/blockcodecs/codecs/bzip/ya.make +++ b/library/cpp/blockcodecs/codecs/bzip/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/libbz2 - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp b/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp index f90e9d31ad..da2831fbd2 100644 --- a/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp +++ b/library/cpp/blockcodecs/codecs/fastlz/fastlz.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/fastlz/fastlz.h> diff --git a/library/cpp/blockcodecs/codecs/fastlz/ya.make b/library/cpp/blockcodecs/codecs/fastlz/ya.make index 6f6c7250c0..59c09b329b 100644 --- a/library/cpp/blockcodecs/codecs/fastlz/ya.make +++ b/library/cpp/blockcodecs/codecs/fastlz/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/fastlz - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/legacy_zstd06/legacy_zstd06.cpp b/library/cpp/blockcodecs/codecs/legacy_zstd06/legacy_zstd06.cpp index 9f149c1091..042f031679 100644 --- a/library/cpp/blockcodecs/codecs/legacy_zstd06/legacy_zstd06.cpp +++ b/library/cpp/blockcodecs/codecs/legacy_zstd06/legacy_zstd06.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/zstd06/common/zstd.h> #include <contrib/libs/zstd06/common/zstd_static.h> diff --git a/library/cpp/blockcodecs/codecs/legacy_zstd06/ya.make b/library/cpp/blockcodecs/codecs/legacy_zstd06/ya.make index ef7e573272..067f731233 100644 --- a/library/cpp/blockcodecs/codecs/legacy_zstd06/ya.make +++ b/library/cpp/blockcodecs/codecs/legacy_zstd06/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/zstd06 - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/lz4/lz4.cpp b/library/cpp/blockcodecs/codecs/lz4/lz4.cpp index 6edf3695a1..fbf0fe110f 100644 --- a/library/cpp/blockcodecs/codecs/lz4/lz4.cpp +++ b/library/cpp/blockcodecs/codecs/lz4/lz4.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/lz4/lz4.h> #include <contrib/libs/lz4/lz4hc.h> diff --git a/library/cpp/blockcodecs/codecs/lz4/ya.make b/library/cpp/blockcodecs/codecs/lz4/ya.make index 60b13c1191..f2471d7d96 100644 --- a/library/cpp/blockcodecs/codecs/lz4/ya.make +++ b/library/cpp/blockcodecs/codecs/lz4/ya.make @@ -5,7 +5,7 @@ OWNER(pg) PEERDIR( contrib/libs/lz4 contrib/libs/lz4/generated - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/lzma/lzma.cpp b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp index aabe52567a..6c8d5fded4 100644 --- a/library/cpp/blockcodecs/codecs/lzma/lzma.cpp +++ b/library/cpp/blockcodecs/codecs/lzma/lzma.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/lzmasdk/LzmaLib.h> diff --git a/library/cpp/blockcodecs/codecs/lzma/ya.make b/library/cpp/blockcodecs/codecs/lzma/ya.make index af78faa05d..e145834da6 100644 --- a/library/cpp/blockcodecs/codecs/lzma/ya.make +++ b/library/cpp/blockcodecs/codecs/lzma/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/lzmasdk - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/snappy/snappy.cpp b/library/cpp/blockcodecs/codecs/snappy/snappy.cpp index 8db69e8a29..f6be05a05f 100644 --- a/library/cpp/blockcodecs/codecs/snappy/snappy.cpp +++ b/library/cpp/blockcodecs/codecs/snappy/snappy.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/snappy/snappy.h> diff --git a/library/cpp/blockcodecs/codecs/snappy/ya.make b/library/cpp/blockcodecs/codecs/snappy/ya.make index fa411340b3..0cf2be2f94 100644 --- a/library/cpp/blockcodecs/codecs/snappy/ya.make +++ b/library/cpp/blockcodecs/codecs/snappy/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/snappy - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/zlib/ya.make b/library/cpp/blockcodecs/codecs/zlib/ya.make index 488d7da047..9f04995f66 100644 --- a/library/cpp/blockcodecs/codecs/zlib/ya.make +++ b/library/cpp/blockcodecs/codecs/zlib/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/zlib - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/zlib/zlib.cpp b/library/cpp/blockcodecs/codecs/zlib/zlib.cpp index a9cab30d1e..cdb556c36d 100644 --- a/library/cpp/blockcodecs/codecs/zlib/zlib.cpp +++ b/library/cpp/blockcodecs/codecs/zlib/zlib.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #include <contrib/libs/zlib/zlib.h> diff --git a/library/cpp/blockcodecs/codecs/zstd/ya.make b/library/cpp/blockcodecs/codecs/zstd/ya.make index 210d0a2a1f..c077dd47b7 100644 --- a/library/cpp/blockcodecs/codecs/zstd/ya.make +++ b/library/cpp/blockcodecs/codecs/zstd/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/zstd - library/cpp/blockcodecs/core + library/cpp/blockcodecs/core ) SRCS( diff --git a/library/cpp/blockcodecs/codecs/zstd/zstd.cpp b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp index 4ecc5f50a2..95299b3f6d 100644 --- a/library/cpp/blockcodecs/codecs/zstd/zstd.cpp +++ b/library/cpp/blockcodecs/codecs/zstd/zstd.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/blockcodecs/core/codecs.h> -#include <library/cpp/blockcodecs/core/common.h> -#include <library/cpp/blockcodecs/core/register.h> +#include <library/cpp/blockcodecs/core/codecs.h> +#include <library/cpp/blockcodecs/core/common.h> +#include <library/cpp/blockcodecs/core/register.h> #define ZSTD_STATIC_LINKING_ONLY #include <contrib/libs/zstd/include/zstd.h> diff --git a/library/cpp/blockcodecs/fuzz/main.cpp b/library/cpp/blockcodecs/fuzz/main.cpp index 5cb21dc17c..763c6c5a10 100644 --- a/library/cpp/blockcodecs/fuzz/main.cpp +++ b/library/cpp/blockcodecs/fuzz/main.cpp @@ -1,9 +1,9 @@ #include <contrib/libs/protobuf-mutator/src/libfuzzer/libfuzzer_macro.h> #include <google/protobuf/stubs/logging.h> -#include <library/cpp/blockcodecs/codecs.h> -#include <library/cpp/blockcodecs/fuzz/proto/case.pb.h> -#include <library/cpp/blockcodecs/stream.h> +#include <library/cpp/blockcodecs/codecs.h> +#include <library/cpp/blockcodecs/fuzz/proto/case.pb.h> +#include <library/cpp/blockcodecs/stream.h> #include <util/stream/input.h> #include <util/stream/length.h> diff --git a/library/cpp/blockcodecs/fuzz/ya.make b/library/cpp/blockcodecs/fuzz/ya.make index 60ff8c35a9..bc8becc9e1 100644 --- a/library/cpp/blockcodecs/fuzz/ya.make +++ b/library/cpp/blockcodecs/fuzz/ya.make @@ -15,8 +15,8 @@ IF (NOT MSVC) PEERDIR( contrib/libs/protobuf contrib/libs/protobuf-mutator - library/cpp/blockcodecs - library/cpp/blockcodecs/fuzz/proto + library/cpp/blockcodecs + library/cpp/blockcodecs/fuzz/proto ) END() diff --git a/library/cpp/blockcodecs/stream.h b/library/cpp/blockcodecs/stream.h index a6d0d7bdca..96c479cf7e 100644 --- a/library/cpp/blockcodecs/stream.h +++ b/library/cpp/blockcodecs/stream.h @@ -1,3 +1,3 @@ #pragma once -#include <library/cpp/blockcodecs/core/stream.h> +#include <library/cpp/blockcodecs/core/stream.h> diff --git a/library/cpp/blockcodecs/ut/ya.make b/library/cpp/blockcodecs/ut/ya.make index 6edd6f6445..25b882c15b 100644 --- a/library/cpp/blockcodecs/ut/ya.make +++ b/library/cpp/blockcodecs/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/blockcodecs) +UNITTEST_FOR(library/cpp/blockcodecs) OWNER(pg) diff --git a/library/cpp/blockcodecs/ya.make b/library/cpp/blockcodecs/ya.make index b59c5470ec..b8f03d5421 100644 --- a/library/cpp/blockcodecs/ya.make +++ b/library/cpp/blockcodecs/ya.make @@ -3,16 +3,16 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/blockcodecs/core - library/cpp/blockcodecs/codecs/brotli - library/cpp/blockcodecs/codecs/bzip - library/cpp/blockcodecs/codecs/fastlz - library/cpp/blockcodecs/codecs/legacy_zstd06 - library/cpp/blockcodecs/codecs/lz4 - library/cpp/blockcodecs/codecs/lzma - library/cpp/blockcodecs/codecs/snappy - library/cpp/blockcodecs/codecs/zlib - library/cpp/blockcodecs/codecs/zstd + library/cpp/blockcodecs/core + library/cpp/blockcodecs/codecs/brotli + library/cpp/blockcodecs/codecs/bzip + library/cpp/blockcodecs/codecs/fastlz + library/cpp/blockcodecs/codecs/legacy_zstd06 + library/cpp/blockcodecs/codecs/lz4 + library/cpp/blockcodecs/codecs/lzma + library/cpp/blockcodecs/codecs/snappy + library/cpp/blockcodecs/codecs/zlib + library/cpp/blockcodecs/codecs/zstd ) SRCS( diff --git a/library/cpp/build_info/build_info.cpp.in b/library/cpp/build_info/build_info.cpp.in index 693290cbb5..71403af13e 100644 --- a/library/cpp/build_info/build_info.cpp.in +++ b/library/cpp/build_info/build_info.cpp.in @@ -1,4 +1,4 @@ -#include <library/cpp/build_info/build_info.h> +#include <library/cpp/build_info/build_info.h> extern "C" const char* GetBuildType() { return "@BUILD_TYPE@"; diff --git a/library/cpp/build_info/build_info_static.cpp b/library/cpp/build_info/build_info_static.cpp index 5cabef8b06..238fb1ecb0 100644 --- a/library/cpp/build_info/build_info_static.cpp +++ b/library/cpp/build_info/build_info_static.cpp @@ -1,6 +1,6 @@ #include "build_info_static.h" -#include <library/cpp/build_info/buildinfo_data.h> +#include <library/cpp/build_info/buildinfo_data.h> extern "C" const char* GetCompilerVersion() { #if defined(BUILD_COMPILER_VERSION) diff --git a/library/cpp/build_info/sandbox.cpp.in b/library/cpp/build_info/sandbox.cpp.in index c7434bf444..ac3b2d9004 100644 --- a/library/cpp/build_info/sandbox.cpp.in +++ b/library/cpp/build_info/sandbox.cpp.in @@ -1,4 +1,4 @@ -#include <library/cpp/build_info/sandbox.h> +#include <library/cpp/build_info/sandbox.h> #include <library/cpp/string_utils/base64/base64.h> #include <util/generic/string.h> #include <util/string/subst.h> diff --git a/library/cpp/cgiparam/cgiparam.cpp b/library/cpp/cgiparam/cgiparam.cpp index a9a4d06a38..f3277b8e4b 100644 --- a/library/cpp/cgiparam/cgiparam.cpp +++ b/library/cpp/cgiparam/cgiparam.cpp @@ -34,7 +34,7 @@ bool TCgiParameters::Erase(const TStringBuf name, const TStringBuf val) { const auto pair = equal_range(name); bool found = false; - for (auto it = pair.first; it != pair.second;) { + for (auto it = pair.first; it != pair.second;) { if (val == it->second) { it = erase(it); found = true; diff --git a/library/cpp/charset/generated/cp_data.cpp b/library/cpp/charset/generated/cp_data.cpp index ab017c120f..202362c596 100644 --- a/library/cpp/charset/generated/cp_data.cpp +++ b/library/cpp/charset/generated/cp_data.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/charset/codepage.h> +#include <library/cpp/charset/codepage.h> extern const char defchars[][DEFCHAR_BUF]; diff --git a/library/cpp/charset/generated/encrec_data.cpp b/library/cpp/charset/generated/encrec_data.cpp index dc1eb1ecf8..ca59f8ddef 100644 --- a/library/cpp/charset/generated/encrec_data.cpp +++ b/library/cpp/charset/generated/encrec_data.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/charset/codepage.h> +#include <library/cpp/charset/codepage.h> extern const char defchars[][DEFCHAR_BUF]; static const char PP_00[257] = diff --git a/library/cpp/charset/ut/ya.make b/library/cpp/charset/ut/ya.make index 17384046f4..1f9934c712 100644 --- a/library/cpp/charset/ut/ya.make +++ b/library/cpp/charset/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/charset) +UNITTEST_FOR(library/cpp/charset) OWNER(alzobnin) diff --git a/library/cpp/codecs/README.md b/library/cpp/codecs/README.md index 382c3fed02..42646ccd97 100644 --- a/library/cpp/codecs/README.md +++ b/library/cpp/codecs/README.md @@ -1,5 +1,5 @@ This is a library of compression algorithms with a unified interface and serialization. -See also library/cpp/codecs/static, where a support for statically compiled dictionaries is implemented. +See also library/cpp/codecs/static, where a support for statically compiled dictionaries is implemented. All algorithms have a common `ICodec` interface (described in codecs.h). diff --git a/library/cpp/codecs/codecs_registry.cpp b/library/cpp/codecs/codecs_registry.cpp index 837118719c..17d07062ab 100644 --- a/library/cpp/codecs/codecs_registry.cpp +++ b/library/cpp/codecs/codecs_registry.cpp @@ -6,7 +6,7 @@ #include "comptable_codec.h" #include "zstd_dict_codec.h" -#include <library/cpp/blockcodecs/codecs.h> +#include <library/cpp/blockcodecs/codecs.h> #include <util/string/builder.h> #include <util/string/cast.h> diff --git a/library/cpp/codecs/comptable_codec.cpp b/library/cpp/codecs/comptable_codec.cpp index ab0196f50a..476b8ada80 100644 --- a/library/cpp/codecs/comptable_codec.cpp +++ b/library/cpp/codecs/comptable_codec.cpp @@ -1,6 +1,6 @@ #include "comptable_codec.h" -#include <library/cpp/comptable/comptable.h> +#include <library/cpp/comptable/comptable.h> #include <util/string/cast.h> namespace NCodecs { diff --git a/library/cpp/codecs/greedy_dict/ut/ya.make b/library/cpp/codecs/greedy_dict/ut/ya.make index a29ffe1e24..bd67d1a452 100644 --- a/library/cpp/codecs/greedy_dict/ut/ya.make +++ b/library/cpp/codecs/greedy_dict/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/codecs/greedy_dict) +UNITTEST_FOR(library/cpp/codecs/greedy_dict) OWNER(velavokr) diff --git a/library/cpp/codecs/huffman_codec.cpp b/library/cpp/codecs/huffman_codec.cpp index b9bb53ad60..650fe7cdfd 100644 --- a/library/cpp/codecs/huffman_codec.cpp +++ b/library/cpp/codecs/huffman_codec.cpp @@ -1,6 +1,6 @@ #include "huffman_codec.h" -#include <library/cpp/bit_io/bitinput.h> -#include <library/cpp/bit_io/bitoutput.h> +#include <library/cpp/bit_io/bitinput.h> +#include <library/cpp/bit_io/bitoutput.h> #include <util/generic/algorithm.h> #include <util/generic/bitops.h> diff --git a/library/cpp/codecs/pfor_codec.h b/library/cpp/codecs/pfor_codec.h index 3a4e0bb288..d7d4bb8bf4 100644 --- a/library/cpp/codecs/pfor_codec.h +++ b/library/cpp/codecs/pfor_codec.h @@ -5,8 +5,8 @@ #include "delta_codec.h" #include "tls_cache.h" -#include <library/cpp/bit_io/bitinput.h> -#include <library/cpp/bit_io/bitoutput.h> +#include <library/cpp/bit_io/bitinput.h> +#include <library/cpp/bit_io/bitoutput.h> #include <util/string/cast.h> namespace NCodecs { diff --git a/library/cpp/codecs/sample.h b/library/cpp/codecs/sample.h index d4dd186bd5..15f03afcc5 100644 --- a/library/cpp/codecs/sample.h +++ b/library/cpp/codecs/sample.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/deprecated/accessors/accessors.h> +#include <library/cpp/deprecated/accessors/accessors.h> #include <util/generic/buffer.h> #include <util/generic/vector.h> diff --git a/library/cpp/codecs/solar_codec.cpp b/library/cpp/codecs/solar_codec.cpp index 773678c5a4..d0692fe2a4 100644 --- a/library/cpp/codecs/solar_codec.cpp +++ b/library/cpp/codecs/solar_codec.cpp @@ -1,6 +1,6 @@ #include "solar_codec.h" -#include <library/cpp/codecs/greedy_dict/gd_builder.h> +#include <library/cpp/codecs/greedy_dict/gd_builder.h> #include <library/cpp/containers/comptrie/comptrie_builder.h> #include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h> diff --git a/library/cpp/codecs/solar_codec.h b/library/cpp/codecs/solar_codec.h index 35e42b8309..7158ae7926 100644 --- a/library/cpp/codecs/solar_codec.h +++ b/library/cpp/codecs/solar_codec.h @@ -2,7 +2,7 @@ #include "codecs.h" #include <library/cpp/containers/comptrie/comptrie_trie.h> -#include <library/cpp/codecs/greedy_dict/gd_builder.h> +#include <library/cpp/codecs/greedy_dict/gd_builder.h> #include <util/string/cast.h> #include <util/string/escape.h> diff --git a/library/cpp/codecs/static/README b/library/cpp/codecs/static/README index d73254e855..1b07f02433 100644 --- a/library/cpp/codecs/static/README +++ b/library/cpp/codecs/static/README @@ -1 +1 @@ -Support of static libraries in library/cpp/codecs. See library/cpp/codecs/static/example. +Support of static libraries in library/cpp/codecs. See library/cpp/codecs/static/example. diff --git a/library/cpp/codecs/static/builder.cpp b/library/cpp/codecs/static/builder.cpp index 344ceeb362..93e34a3edb 100644 --- a/library/cpp/codecs/static/builder.cpp +++ b/library/cpp/codecs/static/builder.cpp @@ -1,9 +1,9 @@ #include "builder.h" #include "common.h" -#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> -#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/codecs.h> #include <util/generic/yexception.h> #include <util/string/subst.h> diff --git a/library/cpp/codecs/static/builder.h b/library/cpp/codecs/static/builder.h index c67dcfc9c9..d7533be4d5 100644 --- a/library/cpp/codecs/static/builder.h +++ b/library/cpp/codecs/static/builder.h @@ -2,7 +2,7 @@ #include "static.h" -#include <library/cpp/svnversion/svnversion.h> +#include <library/cpp/svnversion/svnversion.h> #include <util/datetime/base.h> #include <util/generic/string.h> diff --git a/library/cpp/codecs/static/example/example.cpp b/library/cpp/codecs/static/example/example.cpp index e751ed7e2e..5b750b717e 100644 --- a/library/cpp/codecs/static/example/example.cpp +++ b/library/cpp/codecs/static/example/example.cpp @@ -1,6 +1,6 @@ #include "example.h" -#include <library/cpp/codecs/static/static.h> +#include <library/cpp/codecs/static/static.h> #include <util/generic/yexception.h> diff --git a/library/cpp/codecs/static/example/ya.make b/library/cpp/codecs/static/example/ya.make index db5f730587..ca6c5fd900 100644 --- a/library/cpp/codecs/static/example/ya.make +++ b/library/cpp/codecs/static/example/ya.make @@ -7,8 +7,8 @@ SRCS( ) PEERDIR( - library/cpp/codecs - library/cpp/codecs/static + library/cpp/codecs + library/cpp/codecs/static ) ARCHIVE_ASM( diff --git a/library/cpp/codecs/static/static.cpp b/library/cpp/codecs/static/static.cpp index a13a545382..44a07dd73a 100644 --- a/library/cpp/codecs/static/static.cpp +++ b/library/cpp/codecs/static/static.cpp @@ -1,8 +1,8 @@ #include "static.h" #include "common.h" -#include <library/cpp/codecs/static/static_codec_info.pb.h> -#include <library/cpp/archive/yarchive.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/archive/yarchive.h> #include <util/draft/datetime.h> diff --git a/library/cpp/codecs/static/static.h b/library/cpp/codecs/static/static.h index 80e77999d6..c1eaed2a74 100644 --- a/library/cpp/codecs/static/static.h +++ b/library/cpp/codecs/static/static.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/codecs.h> #include <util/generic/strbuf.h> #include <util/generic/string.h> diff --git a/library/cpp/codecs/static/tools/common/ct_common.cpp b/library/cpp/codecs/static/tools/common/ct_common.cpp index de25d39cba..fe77691280 100644 --- a/library/cpp/codecs/static/tools/common/ct_common.cpp +++ b/library/cpp/codecs/static/tools/common/ct_common.cpp @@ -1,7 +1,7 @@ #include "ct_common.h" -#include <library/cpp/codecs/codecs.h> -#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> #include <library/cpp/string_utils/base64/base64.h> #include <util/stream/output.h> diff --git a/library/cpp/codecs/static/tools/common/ya.make b/library/cpp/codecs/static/tools/common/ya.make index 4a429b7099..d624222dad 100644 --- a/library/cpp/codecs/static/tools/common/ya.make +++ b/library/cpp/codecs/static/tools/common/ya.make @@ -7,8 +7,8 @@ SRCS( ) PEERDIR( - library/cpp/codecs - library/cpp/codecs/static + library/cpp/codecs + library/cpp/codecs/static library/cpp/getopt/small library/cpp/string_utils/base64 util/draft diff --git a/library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker.cpp b/library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker.cpp index f2179ee2e9..9c8d568d82 100644 --- a/library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker.cpp +++ b/library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker.cpp @@ -1,7 +1,7 @@ -#include <library/cpp/codecs/static/tools/common/ct_common.h> -#include <library/cpp/codecs/static/static.h> -#include <library/cpp/codecs/static/static_codec_info.pb.h> -#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/static/tools/common/ct_common.h> +#include <library/cpp/codecs/static/static.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/codecs/codecs.h> #include <library/cpp/getopt/small/last_getopt.h> #include <util/digest/city.h> diff --git a/library/cpp/codecs/static/tools/static_codec_checker/ya.make b/library/cpp/codecs/static/tools/static_codec_checker/ya.make index 3d404c3643..90e06ca448 100644 --- a/library/cpp/codecs/static/tools/static_codec_checker/ya.make +++ b/library/cpp/codecs/static/tools/static_codec_checker/ya.make @@ -7,9 +7,9 @@ SRCS( ) PEERDIR( - library/cpp/codecs - library/cpp/codecs/static - library/cpp/codecs/static/tools/common + library/cpp/codecs + library/cpp/codecs/static + library/cpp/codecs/static/tools/common library/cpp/getopt/small ) diff --git a/library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator.cpp b/library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator.cpp index 8684ddc073..45fdb5c5fe 100644 --- a/library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator.cpp +++ b/library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator.cpp @@ -1,7 +1,7 @@ -#include <library/cpp/codecs/static/tools/common/ct_common.h> -#include <library/cpp/codecs/static/static_codec_info.pb.h> -#include <library/cpp/codecs/static/builder.h> -#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/static/tools/common/ct_common.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/codecs/static/builder.h> +#include <library/cpp/codecs/codecs.h> #include <library/cpp/getopt/small/last_getopt.h> diff --git a/library/cpp/codecs/static/tools/static_codec_generator/ya.make b/library/cpp/codecs/static/tools/static_codec_generator/ya.make index 21cafe805f..efbc440dd1 100644 --- a/library/cpp/codecs/static/tools/static_codec_generator/ya.make +++ b/library/cpp/codecs/static/tools/static_codec_generator/ya.make @@ -7,10 +7,10 @@ SRCS( ) PEERDIR( - library/cpp/codecs - library/cpp/codecs/static - library/cpp/codecs/static/tools/common - library/cpp/digest/md5 + library/cpp/codecs + library/cpp/codecs/static + library/cpp/codecs/static/tools/common + library/cpp/digest/md5 library/cpp/getopt/small ) diff --git a/library/cpp/codecs/static/tools/tests/static_codec_tools.py b/library/cpp/codecs/static/tools/tests/static_codec_tools.py index fc948ee4ad..db4140e370 100644 --- a/library/cpp/codecs/static/tools/tests/static_codec_tools.py +++ b/library/cpp/codecs/static/tools/tests/static_codec_tools.py @@ -4,15 +4,15 @@ import yatest.common as tt import os.path as op def test_static_codec_tools(): - tt.execute([tt.binary_path("library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator")] + tt.execute([tt.binary_path("library/cpp/codecs/static/tools/static_codec_generator/static_codec_generator")] + ["-m", "test codec", "-r", "sbr://143310406", "-f", "plain", "-c", "solar-8k-a:huffman", "-s", "1", "--fake-revision", "r2385905", "--fake-timestamp", "1467494385", "sample.txt"], timeout=60) assert(op.exists("solar-8k-a.huffman.1467494385.codec_info")) - tt.canonical_execute(tt.binary_path("library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker"), + tt.canonical_execute(tt.binary_path("library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker"), args=["-c", "solar-8k-a.huffman.1467494385.codec_info"], timeout=60) - tt.execute([tt.binary_path("library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker")] + tt.execute([tt.binary_path("library/cpp/codecs/static/tools/static_codec_checker/static_codec_checker")] + ["-c", "solar-8k-a.huffman.1467494385.codec_info", "-f", "plain", "-t", "sample.txt"], timeout=60) return tt.canonical_file("solar-8k-a.huffman.1467494385.codec_info") diff --git a/library/cpp/codecs/static/tools/tests/ya.make b/library/cpp/codecs/static/tools/tests/ya.make index ccf7c6cfe4..c5324eaf53 100644 --- a/library/cpp/codecs/static/tools/tests/ya.make +++ b/library/cpp/codecs/static/tools/tests/ya.make @@ -11,8 +11,8 @@ TIMEOUT(4200) TAG(ya:not_autocheck) DEPENDS( - library/cpp/codecs/static/tools/static_codec_checker - library/cpp/codecs/static/tools/static_codec_generator + library/cpp/codecs/static/tools/static_codec_checker + library/cpp/codecs/static/tools/static_codec_generator ) diff --git a/library/cpp/codecs/static/ut/builder_ut.cpp b/library/cpp/codecs/static/ut/builder_ut.cpp index a44745a2e4..b47c279ed1 100644 --- a/library/cpp/codecs/static/ut/builder_ut.cpp +++ b/library/cpp/codecs/static/ut/builder_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/codecs/static/builder.h> -#include <library/cpp/codecs/static/static_codec_info.pb.h> +#include <library/cpp/codecs/static/builder.h> +#include <library/cpp/codecs/static/static_codec_info.pb.h> #include <util/string/vector.h> class TStaticCodecInfoBuilderTest: public NUnitTest::TTestBase { diff --git a/library/cpp/codecs/static/ut/static_ut.cpp b/library/cpp/codecs/static/ut/static_ut.cpp index c774165d3b..57e1e62887 100644 --- a/library/cpp/codecs/static/ut/static_ut.cpp +++ b/library/cpp/codecs/static/ut/static_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/codecs/static/example/example.h> +#include <library/cpp/codecs/static/example/example.h> class TStaticCodecUsageTest: public NUnitTest::TTestBase { UNIT_TEST_SUITE(TStaticCodecUsageTest) diff --git a/library/cpp/codecs/static/ut/ya.make b/library/cpp/codecs/static/ut/ya.make index 14d27703a6..b9116097d8 100644 --- a/library/cpp/codecs/static/ut/ya.make +++ b/library/cpp/codecs/static/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/codecs/static) +UNITTEST_FOR(library/cpp/codecs/static) OWNER(velavokr) @@ -8,7 +8,7 @@ SRCS( ) PEERDIR( - library/cpp/codecs/static/example + library/cpp/codecs/static/example ) END() diff --git a/library/cpp/codecs/static/ya.make b/library/cpp/codecs/static/ya.make index 41a164f171..00e00fd8d4 100644 --- a/library/cpp/codecs/static/ya.make +++ b/library/cpp/codecs/static/ya.make @@ -9,9 +9,9 @@ SRCS( ) PEERDIR( - library/cpp/codecs - library/cpp/archive - library/cpp/svnversion + library/cpp/codecs + library/cpp/archive + library/cpp/svnversion util/draft ) diff --git a/library/cpp/codecs/ut/codecs_ut.cpp b/library/cpp/codecs/ut/codecs_ut.cpp index c244c368cc..caf6089aef 100644 --- a/library/cpp/codecs/ut/codecs_ut.cpp +++ b/library/cpp/codecs/ut/codecs_ut.cpp @@ -1,9 +1,9 @@ -#include <library/cpp/codecs/delta_codec.h> -#include <library/cpp/codecs/huffman_codec.h> -#include <library/cpp/codecs/pfor_codec.h> -#include <library/cpp/codecs/solar_codec.h> -#include <library/cpp/codecs/zstd_dict_codec.h> -#include <library/cpp/codecs/comptable_codec.h> +#include <library/cpp/codecs/delta_codec.h> +#include <library/cpp/codecs/huffman_codec.h> +#include <library/cpp/codecs/pfor_codec.h> +#include <library/cpp/codecs/solar_codec.h> +#include <library/cpp/codecs/zstd_dict_codec.h> +#include <library/cpp/codecs/comptable_codec.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/codecs/ut/float_huffman_ut.cpp b/library/cpp/codecs/ut/float_huffman_ut.cpp index 915767019e..3156fb1f46 100644 --- a/library/cpp/codecs/ut/float_huffman_ut.cpp +++ b/library/cpp/codecs/ut/float_huffman_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/codecs/float_huffman.h> +#include <library/cpp/codecs/float_huffman.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/codecs/ut/tls_cache_ut.cpp b/library/cpp/codecs/ut/tls_cache_ut.cpp index 6a405ee8af..8101af761f 100644 --- a/library/cpp/codecs/ut/tls_cache_ut.cpp +++ b/library/cpp/codecs/ut/tls_cache_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/codecs/tls_cache.h> +#include <library/cpp/codecs/tls_cache.h> Y_UNIT_TEST_SUITE(CodecsBufferFactoryTest){ void AssignToBuffer(TBuffer & buf, TStringBuf val){ diff --git a/library/cpp/codecs/ut/ya.make b/library/cpp/codecs/ut/ya.make index 2bac67788f..90841b05ef 100644 --- a/library/cpp/codecs/ut/ya.make +++ b/library/cpp/codecs/ut/ya.make @@ -7,7 +7,7 @@ OWNER( PEERDIR( library/cpp/string_utils/base64 - library/cpp/codecs + library/cpp/codecs library/cpp/string_utils/relaxed_escaper ) diff --git a/library/cpp/codecs/ya.make b/library/cpp/codecs/ya.make index 6b8a92d1f6..7e76fb0c9a 100644 --- a/library/cpp/codecs/ya.make +++ b/library/cpp/codecs/ya.make @@ -20,13 +20,13 @@ SRCS( PEERDIR( contrib/libs/zstd - library/cpp/bit_io - library/cpp/blockcodecs - library/cpp/codecs/greedy_dict - library/cpp/comptable + library/cpp/bit_io + library/cpp/blockcodecs + library/cpp/codecs/greedy_dict + library/cpp/comptable library/cpp/containers/comptrie - library/cpp/deprecated/accessors - library/cpp/packers + library/cpp/deprecated/accessors + library/cpp/packers library/cpp/string_utils/relaxed_escaper ) diff --git a/library/cpp/codecs/zstd_dict_codec.cpp b/library/cpp/codecs/zstd_dict_codec.cpp index 7c8b01c4f7..c42a2879e6 100644 --- a/library/cpp/codecs/zstd_dict_codec.cpp +++ b/library/cpp/codecs/zstd_dict_codec.cpp @@ -1,6 +1,6 @@ #include "zstd_dict_codec.h" -#include <library/cpp/packers/packers.h> +#include <library/cpp/packers/packers.h> #include <util/generic/ptr.h> #include <util/generic/refcount.h> diff --git a/library/cpp/colorizer/ut/colorizer_ut.cpp b/library/cpp/colorizer/ut/colorizer_ut.cpp index a6d18ac46c..20341440af 100644 --- a/library/cpp/colorizer/ut/colorizer_ut.cpp +++ b/library/cpp/colorizer/ut/colorizer_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/str.h> diff --git a/library/cpp/colorizer/ut/ya.make b/library/cpp/colorizer/ut/ya.make index f3e60d4521..8a28c189af 100644 --- a/library/cpp/colorizer/ut/ya.make +++ b/library/cpp/colorizer/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/colorizer) +UNITTEST_FOR(library/cpp/colorizer) OWNER(pg) diff --git a/library/cpp/compproto/ut/ya.make b/library/cpp/compproto/ut/ya.make index 0ad1eb4c6f..f197a58269 100644 --- a/library/cpp/compproto/ut/ya.make +++ b/library/cpp/compproto/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(ironpeter) PEERDIR( - ADDINCL library/cpp/compproto + ADDINCL library/cpp/compproto ) -SRCDIR(library/cpp/compproto) +SRCDIR(library/cpp/compproto) SRCS( compproto_ut.cpp diff --git a/library/cpp/comptable/comptable.cpp b/library/cpp/comptable/comptable.cpp index c81e12f4a4..8a92d4d1aa 100644 --- a/library/cpp/comptable/comptable.cpp +++ b/library/cpp/comptable/comptable.cpp @@ -4,7 +4,7 @@ #include <util/generic/vector.h> #include <util/string/cast.h> #include <util/stream/file.h> -#include <library/cpp/compproto/huff.h> +#include <library/cpp/compproto/huff.h> #include "comptable.h" diff --git a/library/cpp/comptable/comptable.h b/library/cpp/comptable/comptable.h index 8f604d0c74..d225fed7a0 100644 --- a/library/cpp/comptable/comptable.h +++ b/library/cpp/comptable/comptable.h @@ -4,7 +4,7 @@ #include <util/memory/blob.h> #include <util/ysaveload.h> -#include <library/cpp/compproto/huff.h> +#include <library/cpp/compproto/huff.h> namespace NCompTable { struct TCompressorTable { diff --git a/library/cpp/comptable/usage/usage.cpp b/library/cpp/comptable/usage/usage.cpp index 2285f33500..9997c83686 100644 --- a/library/cpp/comptable/usage/usage.cpp +++ b/library/cpp/comptable/usage/usage.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/comptable/comptable.h> +#include <library/cpp/comptable/comptable.h> #include <util/random/random.h> #include <util/random/fast.h> diff --git a/library/cpp/comptable/usage/ya.make b/library/cpp/comptable/usage/ya.make index 8c832c3596..ab31e7528c 100644 --- a/library/cpp/comptable/usage/ya.make +++ b/library/cpp/comptable/usage/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/comptable + library/cpp/comptable ) END() diff --git a/library/cpp/comptable/ut/comptable_ut.cpp b/library/cpp/comptable/ut/comptable_ut.cpp index d460b6ca28..5901d0246f 100644 --- a/library/cpp/comptable/ut/comptable_ut.cpp +++ b/library/cpp/comptable/ut/comptable_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/comptable/comptable.h> +#include <library/cpp/comptable/comptable.h> #include <library/cpp/testing/unittest/registar.h> #include <util/random/random.h> diff --git a/library/cpp/comptable/ut/ya.make b/library/cpp/comptable/ut/ya.make index 308ecd7077..d0a49793a5 100644 --- a/library/cpp/comptable/ut/ya.make +++ b/library/cpp/comptable/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/comptable) +UNITTEST_FOR(library/cpp/comptable) OWNER(ironpeter) diff --git a/library/cpp/comptable/ya.make b/library/cpp/comptable/ya.make index 3ef9d934ae..314603c62a 100644 --- a/library/cpp/comptable/ya.make +++ b/library/cpp/comptable/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/compproto + library/cpp/compproto ) END() diff --git a/library/cpp/containers/atomizer/atomizer.h b/library/cpp/containers/atomizer/atomizer.h index df25899dbb..5e40f47ab9 100644 --- a/library/cpp/containers/atomizer/atomizer.h +++ b/library/cpp/containers/atomizer/atomizer.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/containers/str_map/str_map.h> +#include <library/cpp/containers/str_map/str_map.h> #include <util/generic/vector.h> #include <util/generic/utility.h> diff --git a/library/cpp/containers/atomizer/ya.make b/library/cpp/containers/atomizer/ya.make index 7076e9d915..55165a3b67 100644 --- a/library/cpp/containers/atomizer/ya.make +++ b/library/cpp/containers/atomizer/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(g:util) PEERDIR( - library/cpp/containers/str_map + library/cpp/containers/str_map ) SRCS( diff --git a/library/cpp/containers/bitseq/ut/ya.make b/library/cpp/containers/bitseq/ut/ya.make index acaa044db2..7155e82c06 100644 --- a/library/cpp/containers/bitseq/ut/ya.make +++ b/library/cpp/containers/bitseq/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/containers/bitseq) +UNITTEST_FOR(library/cpp/containers/bitseq) OWNER(g:util) diff --git a/library/cpp/containers/compact_vector/ut/ya.make b/library/cpp/containers/compact_vector/ut/ya.make index f3e72ed41c..5e655bc619 100644 --- a/library/cpp/containers/compact_vector/ut/ya.make +++ b/library/cpp/containers/compact_vector/ut/ya.make @@ -2,7 +2,7 @@ UNITTEST() OWNER(nga) -SRCDIR(library/cpp/containers/compact_vector) +SRCDIR(library/cpp/containers/compact_vector) SRCS( compact_vector_ut.cpp diff --git a/library/cpp/containers/comptrie/README.md b/library/cpp/containers/comptrie/README.md index c5efc26cb3..43c298e2c8 100644 --- a/library/cpp/containers/comptrie/README.md +++ b/library/cpp/containers/comptrie/README.md @@ -37,7 +37,7 @@ integer type, which means that arithmetical operations must be defined for it. serialize the value type to a continuous memory buffer, deserialize it back, and quickly determine its size using the pointer to the beginning of this memory buffer. Good packers have already been written for most types, and they are available in -library/cpp/packers. For more information, please refer to the documentation for these packers. +library/cpp/packers. For more information, please refer to the documentation for these packers. The set.h file defines a modification for cases when keys must be stored without values. diff --git a/library/cpp/containers/comptrie/benchmark/main.cpp b/library/cpp/containers/comptrie/benchmark/main.cpp index 431034137b..6e42dad18a 100644 --- a/library/cpp/containers/comptrie/benchmark/main.cpp +++ b/library/cpp/containers/comptrie/benchmark/main.cpp @@ -5,11 +5,11 @@ #include <library/cpp/containers/comptrie/search_iterator.h> #include <library/cpp/containers/comptrie/pattern_searcher.h> -#include <library/cpp/on_disk/aho_corasick/writer.h> -#include <library/cpp/on_disk/aho_corasick/reader.h> -#include <library/cpp/on_disk/aho_corasick/helpers.h> +#include <library/cpp/on_disk/aho_corasick/writer.h> +#include <library/cpp/on_disk/aho_corasick/reader.h> +#include <library/cpp/on_disk/aho_corasick/helpers.h> -#include <library/cpp/containers/dense_hash/dense_hash.h> +#include <library/cpp/containers/dense_hash/dense_hash.h> #include <util/stream/file.h> #include <util/generic/algorithm.h> diff --git a/library/cpp/containers/comptrie/chunked_helpers_trie.h b/library/cpp/containers/comptrie/chunked_helpers_trie.h index c139afd316..cfa35f5ba2 100644 --- a/library/cpp/containers/comptrie/chunked_helpers_trie.h +++ b/library/cpp/containers/comptrie/chunked_helpers_trie.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/on_disk/chunks/chunked_helpers.h> +#include <library/cpp/on_disk/chunks/chunked_helpers.h> #include "comptrie.h" diff --git a/library/cpp/containers/comptrie/comptrie_builder.inl b/library/cpp/containers/comptrie/comptrie_builder.inl index 5e6bb0f0ad..f273fa6571 100644 --- a/library/cpp/containers/comptrie/comptrie_builder.inl +++ b/library/cpp/containers/comptrie/comptrie_builder.inl @@ -5,7 +5,7 @@ #include "make_fast_layout.h" #include "array_with_size.h" -#include <library/cpp/containers/compact_vector/compact_vector.h> +#include <library/cpp/containers/compact_vector/compact_vector.h> #include <util/memory/alloc.h> #include <util/memory/blob.h> diff --git a/library/cpp/containers/comptrie/comptrie_packer.h b/library/cpp/containers/comptrie/comptrie_packer.h index f997d89dd1..0341eeeae3 100644 --- a/library/cpp/containers/comptrie/comptrie_packer.h +++ b/library/cpp/containers/comptrie/comptrie_packer.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/packers/packers.h> +#include <library/cpp/packers/packers.h> template <class T> class TCompactTriePacker { diff --git a/library/cpp/containers/comptrie/loader/loader.h b/library/cpp/containers/comptrie/loader/loader.h index d4f3c0503f..ee10e9b451 100644 --- a/library/cpp/containers/comptrie/loader/loader.h +++ b/library/cpp/containers/comptrie/loader/loader.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/archive/yarchive.h> +#include <library/cpp/archive/yarchive.h> #include <util/generic/string.h> #include <util/generic/ptr.h> #include <util/generic/yexception.h> diff --git a/library/cpp/containers/comptrie/loader/ya.make b/library/cpp/containers/comptrie/loader/ya.make index 2054a8d777..1e23e442a0 100644 --- a/library/cpp/containers/comptrie/loader/ya.make +++ b/library/cpp/containers/comptrie/loader/ya.make @@ -8,7 +8,7 @@ SRCS( ) PEERDIR( - library/cpp/archive + library/cpp/archive library/cpp/containers/comptrie ) diff --git a/library/cpp/containers/comptrie/pattern_searcher.h b/library/cpp/containers/comptrie/pattern_searcher.h index d3cfe82ebf..caab51dc1c 100644 --- a/library/cpp/containers/comptrie/pattern_searcher.h +++ b/library/cpp/containers/comptrie/pattern_searcher.h @@ -3,7 +3,7 @@ #include "comptrie_builder.h" #include "comptrie_trie.h" #include "comptrie_impl.h" -#include <library/cpp/packers/packers.h> +#include <library/cpp/packers/packers.h> #include <util/system/yassert.h> #include <util/generic/vector.h> diff --git a/library/cpp/containers/comptrie/ya.make b/library/cpp/containers/comptrie/ya.make index e063792717..81352da4b2 100644 --- a/library/cpp/containers/comptrie/ya.make +++ b/library/cpp/containers/comptrie/ya.make @@ -26,9 +26,9 @@ SRCS( ) PEERDIR( - library/cpp/packers - library/cpp/containers/compact_vector - library/cpp/on_disk/chunks + library/cpp/packers + library/cpp/containers/compact_vector + library/cpp/on_disk/chunks util/draft ) diff --git a/library/cpp/containers/flat_hash/benchmark/flat_hash_benchmark.cpp b/library/cpp/containers/flat_hash/benchmark/flat_hash_benchmark.cpp index e2fb2ec3a1..040cff3fff 100644 --- a/library/cpp/containers/flat_hash/benchmark/flat_hash_benchmark.cpp +++ b/library/cpp/containers/flat_hash/benchmark/flat_hash_benchmark.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/containers/flat_hash/flat_hash.h> +#include <library/cpp/containers/flat_hash/flat_hash.h> -#include <library/cpp/containers/dense_hash/dense_hash.h> +#include <library/cpp/containers/dense_hash/dense_hash.h> #include <library/cpp/testing/benchmark/bench.h> #include <util/random/random.h> diff --git a/library/cpp/containers/flat_hash/benchmark/ya.make b/library/cpp/containers/flat_hash/benchmark/ya.make index a6f733431b..6f9aedf50d 100644 --- a/library/cpp/containers/flat_hash/benchmark/ya.make +++ b/library/cpp/containers/flat_hash/benchmark/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/containers/flat_hash + library/cpp/containers/flat_hash ) END() diff --git a/library/cpp/containers/flat_hash/flat_hash.h b/library/cpp/containers/flat_hash/flat_hash.h index e9555b27bc..582b8ae8f5 100644 --- a/library/cpp/containers/flat_hash/flat_hash.h +++ b/library/cpp/containers/flat_hash/flat_hash.h @@ -1,11 +1,11 @@ #pragma once -#include <library/cpp/containers/flat_hash/lib/map.h> -#include <library/cpp/containers/flat_hash/lib/containers.h> -#include <library/cpp/containers/flat_hash/lib/probings.h> -#include <library/cpp/containers/flat_hash/lib/set.h> -#include <library/cpp/containers/flat_hash/lib/size_fitters.h> -#include <library/cpp/containers/flat_hash/lib/expanders.h> +#include <library/cpp/containers/flat_hash/lib/map.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/probings.h> +#include <library/cpp/containers/flat_hash/lib/set.h> +#include <library/cpp/containers/flat_hash/lib/size_fitters.h> +#include <library/cpp/containers/flat_hash/lib/expanders.h> #include <util/str_stl.h> diff --git a/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/fuzz.cpp b/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/fuzz.cpp index 0147288df2..9b4cb4c983 100644 --- a/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/fuzz.cpp +++ b/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/fuzz.cpp @@ -1,10 +1,10 @@ -#include <library/cpp/containers/flat_hash/lib/map.h> -#include <library/cpp/containers/flat_hash/lib/containers.h> -#include <library/cpp/containers/flat_hash/lib/probings.h> -#include <library/cpp/containers/flat_hash/lib/size_fitters.h> -#include <library/cpp/containers/flat_hash/lib/expanders.h> +#include <library/cpp/containers/flat_hash/lib/map.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/probings.h> +#include <library/cpp/containers/flat_hash/lib/size_fitters.h> +#include <library/cpp/containers/flat_hash/lib/expanders.h> -#include <library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/fuzz_common.h> +#include <library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/fuzz_common.h> #include <util/generic/hash.h> #include <util/generic/xrange.h> diff --git a/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/ya.make b/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/ya.make index 65478c69b6..3a5d3d6d8c 100644 --- a/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/ya.make +++ b/library/cpp/containers/flat_hash/lib/fuzz/dense_map_fuzz/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/containers/flat_hash/lib/fuzz/fuzz_common + library/cpp/containers/flat_hash/lib/fuzz/fuzz_common ) SIZE(LARGE) diff --git a/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/fuzz.cpp b/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/fuzz.cpp index f15f0877e4..7fb73af0e9 100644 --- a/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/fuzz.cpp +++ b/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/fuzz.cpp @@ -1,10 +1,10 @@ -#include <library/cpp/containers/flat_hash/lib/map.h> -#include <library/cpp/containers/flat_hash/lib/containers.h> -#include <library/cpp/containers/flat_hash/lib/probings.h> -#include <library/cpp/containers/flat_hash/lib/size_fitters.h> -#include <library/cpp/containers/flat_hash/lib/expanders.h> +#include <library/cpp/containers/flat_hash/lib/map.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/probings.h> +#include <library/cpp/containers/flat_hash/lib/size_fitters.h> +#include <library/cpp/containers/flat_hash/lib/expanders.h> -#include <library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/fuzz_common.h> +#include <library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/fuzz_common.h> #include <util/generic/hash.h> #include <util/generic/xrange.h> diff --git a/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/ya.make b/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/ya.make index 65478c69b6..3a5d3d6d8c 100644 --- a/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/ya.make +++ b/library/cpp/containers/flat_hash/lib/fuzz/flat_map_fuzz/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/containers/flat_hash/lib/fuzz/fuzz_common + library/cpp/containers/flat_hash/lib/fuzz/fuzz_common ) SIZE(LARGE) diff --git a/library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/ya.make b/library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/ya.make index a4a01e75f0..ecb590e116 100644 --- a/library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/ya.make +++ b/library/cpp/containers/flat_hash/lib/fuzz/fuzz_common/ya.make @@ -5,7 +5,7 @@ OWNER(tender-bum) SRCS(fuzz_common.cpp) PEERDIR( - library/cpp/containers/flat_hash/lib + library/cpp/containers/flat_hash/lib ) END() diff --git a/library/cpp/containers/flat_hash/lib/ut/containers_ut.cpp b/library/cpp/containers/flat_hash/lib/ut/containers_ut.cpp index ac0b2e49cb..b17b30fa80 100644 --- a/library/cpp/containers/flat_hash/lib/ut/containers_ut.cpp +++ b/library/cpp/containers/flat_hash/lib/ut/containers_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/lib/ut/iterator_ut.cpp b/library/cpp/containers/flat_hash/lib/ut/iterator_ut.cpp index f8ef0a4292..0b77bf043f 100644 --- a/library/cpp/containers/flat_hash/lib/ut/iterator_ut.cpp +++ b/library/cpp/containers/flat_hash/lib/ut/iterator_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/containers/flat_hash/lib/iterator.h> -#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/iterator.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/lib/ut/probings_ut.cpp b/library/cpp/containers/flat_hash/lib/ut/probings_ut.cpp index 0a9339cae7..593f8cbb1b 100644 --- a/library/cpp/containers/flat_hash/lib/ut/probings_ut.cpp +++ b/library/cpp/containers/flat_hash/lib/ut/probings_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/flat_hash/lib/probings.h> +#include <library/cpp/containers/flat_hash/lib/probings.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/lib/ut/size_fitters_ut.cpp b/library/cpp/containers/flat_hash/lib/ut/size_fitters_ut.cpp index 6d3e9cb8bd..4167947ece 100644 --- a/library/cpp/containers/flat_hash/lib/ut/size_fitters_ut.cpp +++ b/library/cpp/containers/flat_hash/lib/ut/size_fitters_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/flat_hash/lib/size_fitters.h> +#include <library/cpp/containers/flat_hash/lib/size_fitters.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/lib/ut/table_ut.cpp b/library/cpp/containers/flat_hash/lib/ut/table_ut.cpp index 19606c7948..ea511e2c6a 100644 --- a/library/cpp/containers/flat_hash/lib/ut/table_ut.cpp +++ b/library/cpp/containers/flat_hash/lib/ut/table_ut.cpp @@ -1,8 +1,8 @@ -#include <library/cpp/containers/flat_hash/lib/containers.h> -#include <library/cpp/containers/flat_hash/lib/expanders.h> -#include <library/cpp/containers/flat_hash/lib/probings.h> -#include <library/cpp/containers/flat_hash/lib/size_fitters.h> -#include <library/cpp/containers/flat_hash/lib/table.h> +#include <library/cpp/containers/flat_hash/lib/containers.h> +#include <library/cpp/containers/flat_hash/lib/expanders.h> +#include <library/cpp/containers/flat_hash/lib/probings.h> +#include <library/cpp/containers/flat_hash/lib/size_fitters.h> +#include <library/cpp/containers/flat_hash/lib/table.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/lib/ut/ya.make b/library/cpp/containers/flat_hash/lib/ut/ya.make index 4233dfb56c..04d65a8c6e 100644 --- a/library/cpp/containers/flat_hash/lib/ut/ya.make +++ b/library/cpp/containers/flat_hash/lib/ut/ya.make @@ -11,7 +11,7 @@ SRCS( ) PEERDIR( - library/cpp/containers/flat_hash/lib + library/cpp/containers/flat_hash/lib ) END() diff --git a/library/cpp/containers/flat_hash/ut/flat_hash_ut.cpp b/library/cpp/containers/flat_hash/ut/flat_hash_ut.cpp index d1b9072c0b..2b9d6a1dc2 100644 --- a/library/cpp/containers/flat_hash/ut/flat_hash_ut.cpp +++ b/library/cpp/containers/flat_hash/ut/flat_hash_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/flat_hash/flat_hash.h> +#include <library/cpp/containers/flat_hash/flat_hash.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/containers/flat_hash/ut/ya.make b/library/cpp/containers/flat_hash/ut/ya.make index 5f3a733c00..1d33d36120 100644 --- a/library/cpp/containers/flat_hash/ut/ya.make +++ b/library/cpp/containers/flat_hash/ut/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/containers/flat_hash + library/cpp/containers/flat_hash ) END() diff --git a/library/cpp/containers/flat_hash/ya.make b/library/cpp/containers/flat_hash/ya.make index 3d0f17f8db..612e2c1cde 100644 --- a/library/cpp/containers/flat_hash/ya.make +++ b/library/cpp/containers/flat_hash/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(tender-bum) PEERDIR( - library/cpp/containers/flat_hash/lib + library/cpp/containers/flat_hash/lib ) SRCS( diff --git a/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp b/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp index 94a9dfe120..cab2365cce 100644 --- a/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp +++ b/library/cpp/containers/intrusive_avl_tree/ut/avltree_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/containers/intrusive_avl_tree/avltree.h> +#include <library/cpp/containers/intrusive_avl_tree/avltree.h> class TAvlTreeTest: public TTestBase { UNIT_TEST_SUITE(TAvlTreeTest); diff --git a/library/cpp/containers/intrusive_avl_tree/ut/ya.make b/library/cpp/containers/intrusive_avl_tree/ut/ya.make index 5ac59fa542..87920306d7 100644 --- a/library/cpp/containers/intrusive_avl_tree/ut/ya.make +++ b/library/cpp/containers/intrusive_avl_tree/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/containers/intrusive_avl_tree) +UNITTEST_FOR(library/cpp/containers/intrusive_avl_tree) OWNER( pg diff --git a/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp b/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp index 5e85623c73..92370760b5 100644 --- a/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp +++ b/library/cpp/containers/intrusive_rb_tree/fuzz/rb_tree_fuzzing.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> +#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> #include <util/generic/deque.h> #include <stdint.h> diff --git a/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make b/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make index 4e3d967f22..61be9919e6 100644 --- a/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make +++ b/library/cpp/containers/intrusive_rb_tree/fuzz/ya.make @@ -10,7 +10,7 @@ SIZE(LARGE) TAG(ya:fat) PEERDIR( - library/cpp/containers/intrusive_rb_tree + library/cpp/containers/intrusive_rb_tree ) SRCS( diff --git a/library/cpp/containers/intrusive_rb_tree/ut/ya.make b/library/cpp/containers/intrusive_rb_tree/ut/ya.make index d243014bf5..6f1e3b38ee 100644 --- a/library/cpp/containers/intrusive_rb_tree/ut/ya.make +++ b/library/cpp/containers/intrusive_rb_tree/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/containers/intrusive_rb_tree) +UNITTEST_FOR(library/cpp/containers/intrusive_rb_tree) OWNER( pg diff --git a/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp b/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp index 04a95e6d25..e867808ee4 100644 --- a/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp +++ b/library/cpp/containers/paged_vector/ut/paged_vector_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/paged_vector/paged_vector.h> +#include <library/cpp/containers/paged_vector/paged_vector.h> #include <library/cpp/testing/unittest/registar.h> #include <stdexcept> diff --git a/library/cpp/containers/paged_vector/ut/ya.make b/library/cpp/containers/paged_vector/ut/ya.make index 0431261100..74cfe5fb4a 100644 --- a/library/cpp/containers/paged_vector/ut/ya.make +++ b/library/cpp/containers/paged_vector/ut/ya.make @@ -3,7 +3,7 @@ UNITTEST() OWNER(velavokr) PEERDIR( - library/cpp/containers/paged_vector + library/cpp/containers/paged_vector ) SRCS( diff --git a/library/cpp/containers/stack_array/ut/tests_ut.cpp b/library/cpp/containers/stack_array/ut/tests_ut.cpp index 7495b2b661..3e96384f0e 100644 --- a/library/cpp/containers/stack_array/ut/tests_ut.cpp +++ b/library/cpp/containers/stack_array/ut/tests_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/stack_array/stack_array.h> +#include <library/cpp/containers/stack_array/stack_array.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TestStackArray) { diff --git a/library/cpp/containers/stack_array/ut/ya.make b/library/cpp/containers/stack_array/ut/ya.make index 2d6551b7f6..7db7340073 100644 --- a/library/cpp/containers/stack_array/ut/ya.make +++ b/library/cpp/containers/stack_array/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/containers/stack_array) +UNITTEST_FOR(library/cpp/containers/stack_array) OWNER(pg) diff --git a/library/cpp/containers/top_keeper/README.md b/library/cpp/containers/top_keeper/README.md index b5d3add816..f160fb1c01 100644 --- a/library/cpp/containers/top_keeper/README.md +++ b/library/cpp/containers/top_keeper/README.md @@ -11,7 +11,7 @@ TopKeeper - структура данных для поддержания "top M 5) Удаляем элементы из правой половины Трудоёмкость: -На M добавлений происходит 1 PartitionSort (усреднённая оценка трудоёмкости - О(M)) и удаление M элементов. Таким образом достигается О(1) операций в среднем на 1 добавление. Для алгоритма TLimitedHeap (library/cpp/containers/limited_heap) - эта оценка О(log (M)) +На M добавлений происходит 1 PartitionSort (усреднённая оценка трудоёмкости - О(M)) и удаление M элементов. Таким образом достигается О(1) операций в среднем на 1 добавление. Для алгоритма TLimitedHeap (library/cpp/containers/limited_heap) - эта оценка О(log (M)) Тесты: На случайных потоках данных количество сравнений у TopKeeper и LimitedHeap одинаково (происходит потому что минимум у первого обновляется раз в M добавлений, а у второго - при каждом добавлении). Худший случай LimitedHeap - сортированная последовательность (добавляем каждый элемент), на таком потоке для 2 000 000 000 int TopKeeper выигрывает во много раз. diff --git a/library/cpp/containers/top_keeper/top_keeper/README.md b/library/cpp/containers/top_keeper/top_keeper/README.md index 2b0f67b214..f160fb1c01 100644 --- a/library/cpp/containers/top_keeper/top_keeper/README.md +++ b/library/cpp/containers/top_keeper/top_keeper/README.md @@ -11,7 +11,7 @@ TopKeeper - структура данных для поддержания "top M 5) Удаляем элементы из правой половины Трудоёмкость: -На M добавлений происходит 1 PartitionSort (усреднённая оценка трудоёмкости - О(M)) и удаление M элементов. Таким образом достигается О(1) операций в среднем на 1 добавление. Для алгоритма TLimitedHeap (library/cpp/containers/limited_heap) - эта оценка О(log (M)) +На M добавлений происходит 1 PartitionSort (усреднённая оценка трудоёмкости - О(M)) и удаление M элементов. Таким образом достигается О(1) операций в среднем на 1 добавление. Для алгоритма TLimitedHeap (library/cpp/containers/limited_heap) - эта оценка О(log (M)) Тесты: На случайных потоках данных количество сравнений у TopKeeper и LimitedHeap одинаково (происходит потому что минимум у первого обновляется раз в M добавлений, а у второго - при каждом добавлении). Худший случай LimitedHeap - сортированная последовательность (добавляем каждый элемент), на таком потоке для 2 000 000 000 int TopKeeper выигрывает во много раз. @@ -23,4 +23,4 @@ TopKeeper - структура данных для поддержания "top M В ситуации когда нужны чередующиеся добавления / извлечения - используйте LimitedHeap Примеры использования: -library/cpp/containers/top_keeper/ut +library/cpp/containers/top_keeper/ut diff --git a/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp b/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp index 61bc58ccb5..a938279025 100644 --- a/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp +++ b/library/cpp/containers/top_keeper/top_keeper/ut/top_keeper_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/containers/limited_heap/limited_heap.h> -#include <library/cpp/containers/top_keeper/top_keeper.h> +#include <library/cpp/containers/limited_heap/limited_heap.h> +#include <library/cpp/containers/top_keeper/top_keeper.h> #include <library/cpp/testing/unittest/registar.h> #include <util/random/random.h> diff --git a/library/cpp/containers/top_keeper/top_keeper/ut/ya.make b/library/cpp/containers/top_keeper/top_keeper/ut/ya.make index 58bc33c3a9..8553389e17 100644 --- a/library/cpp/containers/top_keeper/top_keeper/ut/ya.make +++ b/library/cpp/containers/top_keeper/top_keeper/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/containers/top_keeper) +UNITTEST_FOR(library/cpp/containers/top_keeper) OWNER( mbusel diff --git a/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp b/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp index 9609b71ea8..a938279025 100644 --- a/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp +++ b/library/cpp/containers/top_keeper/ut/top_keeper_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/containers/limited_heap/limited_heap.h> +#include <library/cpp/containers/limited_heap/limited_heap.h> #include <library/cpp/containers/top_keeper/top_keeper.h> #include <library/cpp/testing/unittest/registar.h> #include <util/random/random.h> diff --git a/library/cpp/containers/ya.make b/library/cpp/containers/ya.make index 06daa1be53..4b1b315e6a 100644 --- a/library/cpp/containers/ya.make +++ b/library/cpp/containers/ya.make @@ -1,71 +1,71 @@ RECURSE( 2d_array - absl_flat_hash + absl_flat_hash absl_tstring_flat_hash - atomizer - bitseq - bitseq/ut - compact_vector - compact_vector/ut + atomizer + bitseq + bitseq/ut + compact_vector + compact_vector/ut comptrie comptrie/loader comptrie/loader/ut comptrie/ut comptrie/benchmark concurrent_hash - concurrent_hash_set - concurrent_hash_set/ut - dense_hash - dense_hash/dense_hash_benchmark - dense_hash/ut - dictionary - dictionary/ut + concurrent_hash_set + concurrent_hash_set/ut + dense_hash + dense_hash/dense_hash_benchmark + dense_hash/ut + dictionary + dictionary/ut disjoint_interval_tree disjoint_interval_tree/ut ext_priority_queue ext_priority_queue/ut - fast_trie - fast_trie/ut - flat_hash - flat_hash/benchmark - flat_hash/lib - flat_hash/lib/concepts - flat_hash/lib/fuzz - flat_hash/lib/ut - flat_hash/ut - hash_trie - heap_dict - heap_dict/benchmark - heap_dict/ut - intrusive_avl_tree - intrusive_avl_tree/ut - intrusive_hash - intrusive_hash/ut - intrusive_rb_tree - intrusive_rb_tree/fuzz - intrusive_rb_tree/ut - limited_heap - mh_heap - mh_heap/ut - paged_vector - paged_vector/ut - rarefied_array - ring_buffer - safe_vector - safe_vector/ut - segmented_pool_container + fast_trie + fast_trie/ut + flat_hash + flat_hash/benchmark + flat_hash/lib + flat_hash/lib/concepts + flat_hash/lib/fuzz + flat_hash/lib/ut + flat_hash/ut + hash_trie + heap_dict + heap_dict/benchmark + heap_dict/ut + intrusive_avl_tree + intrusive_avl_tree/ut + intrusive_hash + intrusive_hash/ut + intrusive_rb_tree + intrusive_rb_tree/fuzz + intrusive_rb_tree/ut + limited_heap + mh_heap + mh_heap/ut + paged_vector + paged_vector/ut + rarefied_array + ring_buffer + safe_vector + safe_vector/ut + segmented_pool_container sorted_vector sorted_vector/ut - spars_ar - stack_array - stack_array/ut + spars_ar + stack_array + stack_array/ut stack_vector - str_hash - str_map + str_hash + str_map top_keeper top_keeper/ut - two_level_hash - two_level_hash/ut + two_level_hash + two_level_hash/ut vp_tree vp_tree/ut ) diff --git a/library/cpp/coroutine/engine/cont_poller.h b/library/cpp/coroutine/engine/cont_poller.h index a1cd1a71f5..b638b2df1a 100644 --- a/library/cpp/coroutine/engine/cont_poller.h +++ b/library/cpp/coroutine/engine/cont_poller.h @@ -3,7 +3,7 @@ #include "poller.h" #include "sockmap.h" -#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> +#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> #include <util/datetime/base.h> #include <util/memory/pool.h> diff --git a/library/cpp/coroutine/engine/impl.h b/library/cpp/coroutine/engine/impl.h index 9065909795..283a96ecf1 100644 --- a/library/cpp/coroutine/engine/impl.h +++ b/library/cpp/coroutine/engine/impl.h @@ -8,7 +8,7 @@ #include "trampoline.h" #include "custom_time.h" -#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> +#include <library/cpp/containers/intrusive_rb_tree/rb_tree.h> #include <util/system/error.h> #include <util/generic/ptr.h> diff --git a/library/cpp/coroutine/engine/ya.make b/library/cpp/coroutine/engine/ya.make index 02b0df72ea..8c20b9afc3 100644 --- a/library/cpp/coroutine/engine/ya.make +++ b/library/cpp/coroutine/engine/ya.make @@ -10,7 +10,7 @@ GENERATE_ENUM_SERIALIZATION(stack/stack_common.h) PEERDIR( contrib/libs/libc_compat - library/cpp/containers/intrusive_rb_tree + library/cpp/containers/intrusive_rb_tree ) SRCS( diff --git a/library/cpp/coroutine/listener/listen.cpp b/library/cpp/coroutine/listener/listen.cpp index 6f64976a9f..3d4e711d1d 100644 --- a/library/cpp/coroutine/listener/listen.cpp +++ b/library/cpp/coroutine/listener/listen.cpp @@ -1,7 +1,7 @@ #include "listen.h" -#include <library/cpp/coroutine/engine/impl.h> -#include <library/cpp/coroutine/engine/network.h> +#include <library/cpp/coroutine/engine/impl.h> +#include <library/cpp/coroutine/engine/network.h> #include <util/network/ip.h> #include <util/network/address.h> diff --git a/library/cpp/coroutine/listener/ya.make b/library/cpp/coroutine/listener/ya.make index a291679c7b..700c3abe3e 100644 --- a/library/cpp/coroutine/listener/ya.make +++ b/library/cpp/coroutine/listener/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/coroutine/engine + library/cpp/coroutine/engine ) SRCS( diff --git a/library/cpp/dbg_output/DONT_COMMIT.h b/library/cpp/dbg_output/DONT_COMMIT.h index a53cf52103..e7b3182c20 100644 --- a/library/cpp/dbg_output/DONT_COMMIT.h +++ b/library/cpp/dbg_output/DONT_COMMIT.h @@ -10,7 +10,7 @@ #include "dumpers.cpp" #include "engine.cpp" -#include <library/cpp/colorizer/colors.cpp> -#include <library/cpp/colorizer/output.cpp> +#include <library/cpp/colorizer/colors.cpp> +#include <library/cpp/colorizer/output.cpp> #undef DBGDUMP_INLINE_IF_INCLUDED diff --git a/library/cpp/dbg_output/colorscheme.h b/library/cpp/dbg_output/colorscheme.h index 3f32487a95..a5b9cf749a 100644 --- a/library/cpp/dbg_output/colorscheme.h +++ b/library/cpp/dbg_output/colorscheme.h @@ -1,7 +1,7 @@ #pragma once #include "engine.h" -#include <library/cpp/colorizer/output.h> +#include <library/cpp/colorizer/output.h> #ifndef DBG_OUTPUT_DEFAULT_COLOR_SCHEME #define DBG_OUTPUT_DEFAULT_COLOR_SCHEME NDbgDump::NColorScheme::TPlain @@ -68,7 +68,7 @@ namespace NDbgDump { } // Background color modifiers - // TODO: support backgrounds in library/cpp/colorizer + // TODO: support backgrounds in library/cpp/colorizer DBG_OUTPUT_COLOR_HANDLER(Key) { if (Depth++ == 0 && Colors.IsTTY()) { stream << DumpRaw(TStringBuf("\033[42m")); diff --git a/library/cpp/dbg_output/ut/dbg_output_ut.cpp b/library/cpp/dbg_output/ut/dbg_output_ut.cpp index 8ebc729e73..7b285c84cb 100644 --- a/library/cpp/dbg_output/ut/dbg_output_ut.cpp +++ b/library/cpp/dbg_output/ut/dbg_output_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/dbg_output/dump.h> +#include <library/cpp/dbg_output/dump.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/str.h> diff --git a/library/cpp/dbg_output/ut/ya.make b/library/cpp/dbg_output/ut/ya.make index 49fa473880..201601295d 100644 --- a/library/cpp/dbg_output/ut/ya.make +++ b/library/cpp/dbg_output/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/dbg_output) +UNITTEST_FOR(library/cpp/dbg_output) OWNER(pg) diff --git a/library/cpp/dbg_output/ya.make b/library/cpp/dbg_output/ya.make index 3803157cc2..7d54108f93 100644 --- a/library/cpp/dbg_output/ya.make +++ b/library/cpp/dbg_output/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/colorizer + library/cpp/colorizer ) SRCS( diff --git a/library/cpp/deprecated/accessors/ut/ya.make b/library/cpp/deprecated/accessors/ut/ya.make index bfc2ec5f2d..5ea976566f 100644 --- a/library/cpp/deprecated/accessors/ut/ya.make +++ b/library/cpp/deprecated/accessors/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/deprecated/accessors) +UNITTEST_FOR(library/cpp/deprecated/accessors) OWNER(velavokr) diff --git a/library/cpp/deprecated/enum_codegen/ut/ya.make b/library/cpp/deprecated/enum_codegen/ut/ya.make index d6d05b2960..32e7ad77a2 100644 --- a/library/cpp/deprecated/enum_codegen/ut/ya.make +++ b/library/cpp/deprecated/enum_codegen/ut/ya.make @@ -2,10 +2,10 @@ UNITTEST() OWNER(g:util) -SRCDIR(library/cpp/deprecated/enum_codegen) +SRCDIR(library/cpp/deprecated/enum_codegen) PEERDIR( - library/cpp/deprecated/enum_codegen + library/cpp/deprecated/enum_codegen ) SRCS( diff --git a/library/cpp/deprecated/kmp/ut/ya.make b/library/cpp/deprecated/kmp/ut/ya.make index 12aafef305..9c54ee2715 100644 --- a/library/cpp/deprecated/kmp/ut/ya.make +++ b/library/cpp/deprecated/kmp/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/deprecated/kmp) +UNITTEST_FOR(library/cpp/deprecated/kmp) OWNER(g:util) diff --git a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp index 688f6e6faf..afbd5b3358 100644 --- a/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp +++ b/library/cpp/deprecated/mapped_file/ut/mapped_file_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/deprecated/mapped_file/mapped_file.h> +#include <library/cpp/deprecated/mapped_file/mapped_file.h> #include <library/cpp/testing/unittest/registar.h> #include <util/system/fs.h> diff --git a/library/cpp/deprecated/split/split_iterator.h b/library/cpp/deprecated/split/split_iterator.h index eaf2575623..0eacc29228 100644 --- a/library/cpp/deprecated/split/split_iterator.h +++ b/library/cpp/deprecated/split/split_iterator.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/deprecated/kmp/kmp.h> +#include <library/cpp/deprecated/kmp/kmp.h> #include <util/string/cast.h> #include <util/string/util.h> #include <util/string/builder.h> diff --git a/library/cpp/deprecated/split/ya.make b/library/cpp/deprecated/split/ya.make index 2f5b144655..946e685ac8 100644 --- a/library/cpp/deprecated/split/ya.make +++ b/library/cpp/deprecated/split/ya.make @@ -8,7 +8,7 @@ SRCS( ) PEERDIR( - library/cpp/deprecated/kmp + library/cpp/deprecated/kmp ) END() diff --git a/library/cpp/deprecated/ya.make b/library/cpp/deprecated/ya.make index b17f631132..6c753f68a9 100644 --- a/library/cpp/deprecated/ya.make +++ b/library/cpp/deprecated/ya.make @@ -13,10 +13,10 @@ RECURSE( fgood fgood/ut histogram - ipreg1 - ipreg1/ut - ipreg1/ut_full - ipreg1/util + ipreg1 + ipreg1/ut + ipreg1/ut_full + ipreg1/util iter kmp kmp/ut diff --git a/library/cpp/diff/README.md b/library/cpp/diff/README.md index f8021b0aad..ff68b10eae 100644 --- a/library/cpp/diff/README.md +++ b/library/cpp/diff/README.md @@ -1 +1 @@ -Note: underlying algorithm `library/cpp/lcs` has complexity of O(r log n) by time and O(r) of additional memory, where r is the number of pairs (i, j) for which S1[i] = S2[j]. When comparing file with itself (or with little modifications) it becomes quadratic on the number of occurences of the most frequent line. +Note: underlying algorithm `library/cpp/lcs` has complexity of O(r log n) by time and O(r) of additional memory, where r is the number of pairs (i, j) for which S1[i] = S2[j]. When comparing file with itself (or with little modifications) it becomes quadratic on the number of occurences of the most frequent line. diff --git a/library/cpp/diff/diff.h b/library/cpp/diff/diff.h index 92aeda0f74..94fb00cd0b 100644 --- a/library/cpp/diff/diff.h +++ b/library/cpp/diff/diff.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/lcs/lcs_via_lis.h> +#include <library/cpp/lcs/lcs_via_lis.h> #include <util/generic/algorithm.h> #include <util/generic/array_ref.h> diff --git a/library/cpp/diff/ya.make b/library/cpp/diff/ya.make index 3b48b7a379..a05b7ccbbc 100644 --- a/library/cpp/diff/ya.make +++ b/library/cpp/diff/ya.make @@ -3,8 +3,8 @@ LIBRARY() OWNER(antonovvk) PEERDIR( - library/cpp/lcs - library/cpp/containers/stack_array + library/cpp/lcs + library/cpp/containers/stack_array ) SRCS( diff --git a/library/cpp/digest/argonish/README.md b/library/cpp/digest/argonish/README.md index 9fbacd2504..7b3ae79cca 100644 --- a/library/cpp/digest/argonish/README.md +++ b/library/cpp/digest/argonish/README.md @@ -50,7 +50,7 @@ How to use ---------- ``` -#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/argon2.h> ... uint32_t tcost = 1; /* one pass */ uint32_t mcost = 32; /* in KB */ @@ -59,7 +59,7 @@ NArgonish::TArgon2Factory afactory; THolder<NArgonish::IArgon2Base> argon2 = afactory.Create(NArgonish::EArgon2Type::Argon2d, tcost, mcost, threads); argon2->Hash(input, insize, salt, saltsize, out, outlen); ... -#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/blake2b.h> ... NArgonish::TBlake2BFactory bfactory; uint32_t outlen = 32; diff --git a/library/cpp/digest/argonish/benchmark/mbench.cpp b/library/cpp/digest/argonish/benchmark/mbench.cpp index adff57302a..178c1169c9 100644 --- a/library/cpp/digest/argonish/benchmark/mbench.cpp +++ b/library/cpp/digest/argonish/benchmark/mbench.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/benchmark/bench.h> -#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/argon2.h> Y_CPU_BENCHMARK(Argon2d_2048_REF, iface) { NArgonish::TArgon2Factory factory; diff --git a/library/cpp/digest/argonish/benchmark/ya.make b/library/cpp/digest/argonish/benchmark/ya.make index 48f6f826f3..5aad1b238f 100644 --- a/library/cpp/digest/argonish/benchmark/ya.make +++ b/library/cpp/digest/argonish/benchmark/ya.make @@ -3,7 +3,7 @@ OWNER(e-sidorov) Y_BENCHMARK() PEERDIR( - library/cpp/digest/argonish + library/cpp/digest/argonish ) SRCS( diff --git a/library/cpp/digest/argonish/factory/factory.cpp b/library/cpp/digest/argonish/factory/factory.cpp index 2008f068c2..c1f5f5ce79 100644 --- a/library/cpp/digest/argonish/factory/factory.cpp +++ b/library/cpp/digest/argonish/factory/factory.cpp @@ -2,14 +2,14 @@ // Created by Evgeny Sidorov on 12/04/17. // -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h> #if !defined(_arm64_) -#include <library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h> -#include <library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h> -#include <library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h> -#include <library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h> +#include <library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h> +#include <library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h> +#include <library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h> +#include <library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h> #endif #include <util/system/cpu_id.h> diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_avx2.h b/library/cpp/digest/argonish/internal/argon2/argon2_avx2.h index a1697e649b..8bf5367817 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_avx2.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_avx2.h @@ -2,7 +2,7 @@ #include <immintrin.h> #include "argon2_base.h" -#include <library/cpp/digest/argonish/internal/blamka/blamka_avx2.h> +#include <library/cpp/digest/argonish/internal/blamka/blamka_avx2.h> namespace NArgonish { template <ui32 mcost, ui32 threads> diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_base.h b/library/cpp/digest/argonish/internal/argon2/argon2_base.h index 9b7baf491f..2385cc947c 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_base.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_base.h @@ -1,13 +1,13 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> #include <library/cpp/threading/poor_man_openmp/thread_helper.h> namespace NArgonish { const ui32 ARGON2_PREHASH_DIGEST_LENGTH = 64; - const ui32 ARGON2_SECRET_MAX_LENGTH = 64; + const ui32 ARGON2_SECRET_MAX_LENGTH = 64; const ui32 ARGON2_PREHASH_SEED_LENGTH = 72; const ui32 ARGON2_BLOCK_SIZE = 1024; const ui32 ARGON2_QWORDS_IN_BLOCK = ARGON2_BLOCK_SIZE / 8; diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_ref.h b/library/cpp/digest/argonish/internal/argon2/argon2_ref.h index e57700c19b..8e5e3fa971 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_ref.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_ref.h @@ -1,7 +1,7 @@ #pragma once #include "argon2_base.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_ref.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_ref.h> namespace NArgonish { static inline ui64 FBlaMka(ui64 x, ui64 y) { diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_sse2.h b/library/cpp/digest/argonish/internal/argon2/argon2_sse2.h index 26a5f7023c..1d2230a657 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_sse2.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_sse2.h @@ -2,7 +2,7 @@ #include <emmintrin.h> #include "argon2_base.h" -#include <library/cpp/digest/argonish/internal/blamka/blamka_sse2.h> +#include <library/cpp/digest/argonish/internal/blamka/blamka_sse2.h> namespace NArgonish { template <ui32 mcost, ui32 threads> diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_sse41.h b/library/cpp/digest/argonish/internal/argon2/argon2_sse41.h index 50069d7a62..1ad35048ea 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_sse41.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_sse41.h @@ -2,7 +2,7 @@ #include <smmintrin.h> #include "argon2_base.h" -#include <library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h> +#include <library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h> namespace NArgonish { template <ui32 mcost, ui32 threads> diff --git a/library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h b/library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h index 78e0aad805..a25a416834 100644 --- a/library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h +++ b/library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h @@ -3,7 +3,7 @@ #include <emmintrin.h> #include <tmmintrin.h> #include "argon2_base.h" -#include <library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h> +#include <library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h> namespace NArgonish { template <ui32 mcost, ui32 threads> diff --git a/library/cpp/digest/argonish/internal/argon2/ya.make b/library/cpp/digest/argonish/internal/argon2/ya.make index 592e014951..85459865ba 100644 --- a/library/cpp/digest/argonish/internal/argon2/ya.make +++ b/library/cpp/digest/argonish/internal/argon2/ya.make @@ -3,8 +3,8 @@ LIBRARY() OWNER(e-sidorov) PEERDIR( - library/cpp/digest/argonish/internal/blamka - library/cpp/digest/argonish/internal/blake2b + library/cpp/digest/argonish/internal/blamka + library/cpp/digest/argonish/internal/blake2b ) END() diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b.h b/library/cpp/digest/argonish/internal/blake2b/blake2b.h index 961172210e..3dcfc3fc48 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b.h @@ -2,7 +2,7 @@ #include <util/generic/yexception.h> #include <util/system/compiler.h> -#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/blake2b.h> namespace NArgonish { const ui32 BLAKE2B_BLOCKBYTES = 128; diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h b/library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h index d232be4b8d..359ca90ebb 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h @@ -2,7 +2,7 @@ #include <immintrin.h> #include "blake2b.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_avx2.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_avx2.h> namespace NArgonish { template <> diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h b/library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h index 665e62fbbd..ef98ed8fc8 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h @@ -1,7 +1,7 @@ #pragma once #include "blake2b.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_ref.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_ref.h> namespace NArgonish { static const ui8 Sigma[12][16] = { diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h b/library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h index 31e8616fcc..e85a78044c 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h @@ -2,7 +2,7 @@ #include <emmintrin.h> #include "blake2b.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_sse2.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_sse2.h> namespace NArgonish { template <> diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h b/library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h index 1aa0b6d126..1a033bcceb 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h @@ -3,7 +3,7 @@ #include <smmintrin.h> #include "blake2b.h" #include "load_sse41.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> namespace NArgonish { template <> diff --git a/library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h b/library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h index f37b589f3c..4cca5a5e7f 100644 --- a/library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h +++ b/library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h @@ -3,7 +3,7 @@ #include <emmintrin.h> #include <tmmintrin.h> #include "blake2b.h" -#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> namespace NArgonish { template <> diff --git a/library/cpp/digest/argonish/internal/blake2b/ya.make b/library/cpp/digest/argonish/internal/blake2b/ya.make index 9f679c01ca..0aa6806b31 100644 --- a/library/cpp/digest/argonish/internal/blake2b/ya.make +++ b/library/cpp/digest/argonish/internal/blake2b/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(e-sidorov) PEERDIR( - library/cpp/digest/argonish/internal/rotations + library/cpp/digest/argonish/internal/rotations ) END() diff --git a/library/cpp/digest/argonish/internal/blamka/blamka_avx2.h b/library/cpp/digest/argonish/internal/blamka/blamka_avx2.h index 57246a1c55..02c506d6ff 100644 --- a/library/cpp/digest/argonish/internal/blamka/blamka_avx2.h +++ b/library/cpp/digest/argonish/internal/blamka/blamka_avx2.h @@ -1,7 +1,7 @@ #pragma once #include <immintrin.h> -#include <library/cpp/digest/argonish/internal/rotations/rotations_avx2.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_avx2.h> namespace NArgonish { static inline void BlamkaG1AVX2( diff --git a/library/cpp/digest/argonish/internal/blamka/blamka_sse2.h b/library/cpp/digest/argonish/internal/blamka/blamka_sse2.h index a35342c29a..1b55651b34 100644 --- a/library/cpp/digest/argonish/internal/blamka/blamka_sse2.h +++ b/library/cpp/digest/argonish/internal/blamka/blamka_sse2.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/digest/argonish/internal/rotations/rotations_sse2.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_sse2.h> namespace NArgonish { static inline void BlamkaG1SSE2( diff --git a/library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h b/library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h index 81a27353a4..46e8500cd6 100644 --- a/library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h +++ b/library/cpp/digest/argonish/internal/blamka/blamka_ssse3.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> +#include <library/cpp/digest/argonish/internal/rotations/rotations_ssse3.h> namespace NArgonish { static inline void BlamkaG1SSSE3( diff --git a/library/cpp/digest/argonish/internal/blamka/ya.make b/library/cpp/digest/argonish/internal/blamka/ya.make index 9f679c01ca..0aa6806b31 100644 --- a/library/cpp/digest/argonish/internal/blamka/ya.make +++ b/library/cpp/digest/argonish/internal/blamka/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(e-sidorov) PEERDIR( - library/cpp/digest/argonish/internal/rotations + library/cpp/digest/argonish/internal/rotations ) END() diff --git a/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.cpp b/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.cpp index 9602959df4..c1cf004f58 100644 --- a/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.cpp +++ b/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.cpp @@ -3,10 +3,10 @@ // #include "proxy_avx2.h" -#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> -#include <library/cpp/digest/argonish/internal/argon2/argon2_avx2.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_avx2.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b_avx2.h> #define ZEROUPPER _mm256_zeroupper(); diff --git a/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h b/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h index 9d082255d5..eec0094563 100644 --- a/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h +++ b/library/cpp/digest/argonish/internal/proxies/avx2/proxy_avx2.h @@ -1,9 +1,9 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> namespace NArgonish { ARGON2_PROXY_CLASS_DECL(AVX2) diff --git a/library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h b/library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h index acc2284e60..5ed5f53b4f 100644 --- a/library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h +++ b/library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h @@ -45,12 +45,12 @@ ythrow yexception() << "key is null or keylen equals 0 or key is too long"; \ \ ARGON2_INSTANCE_DECL(IS, 1, 1) \ - ARGON2_INSTANCE_DECL(IS, 8, 1) \ + ARGON2_INSTANCE_DECL(IS, 8, 1) \ ARGON2_INSTANCE_DECL(IS, 16, 1) \ ARGON2_INSTANCE_DECL(IS, 32, 1) \ ARGON2_INSTANCE_DECL(IS, 64, 1) \ - ARGON2_INSTANCE_DECL(IS, 128, 1) \ - ARGON2_INSTANCE_DECL(IS, 256, 1) \ + ARGON2_INSTANCE_DECL(IS, 128, 1) \ + ARGON2_INSTANCE_DECL(IS, 256, 1) \ ARGON2_INSTANCE_DECL(IS, 512, 1) \ ARGON2_INSTANCE_DECL(IS, 1024, 1) \ ARGON2_INSTANCE_DECL(IS, 2048, 1) \ diff --git a/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.cpp b/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.cpp index 9cff2e41ff..0bc51866fd 100644 --- a/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.cpp +++ b/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.cpp @@ -3,10 +3,10 @@ // #include "proxy_ref.h" -#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> -#include <library/cpp/digest/argonish/internal/argon2/argon2_ref.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_ref.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b_ref.h> #include <stdexcept> diff --git a/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h b/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h index 9123c4f201..821abc50cd 100644 --- a/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h +++ b/library/cpp/digest/argonish/internal/proxies/ref/proxy_ref.h @@ -1,9 +1,9 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> namespace NArgonish { ARGON2_PROXY_CLASS_DECL(REF) diff --git a/library/cpp/digest/argonish/internal/proxies/ref/ya.make b/library/cpp/digest/argonish/internal/proxies/ref/ya.make index b38ff92194..7a15f44611 100644 --- a/library/cpp/digest/argonish/internal/proxies/ref/ya.make +++ b/library/cpp/digest/argonish/internal/proxies/ref/ya.make @@ -5,9 +5,9 @@ LIBRARY() NO_UTIL() PEERDIR( - library/cpp/digest/argonish/internal/proxies/macro - library/cpp/digest/argonish/internal/argon2 - library/cpp/digest/argonish/internal/blake2b + library/cpp/digest/argonish/internal/proxies/macro + library/cpp/digest/argonish/internal/argon2 + library/cpp/digest/argonish/internal/blake2b ) SRCS( diff --git a/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.cpp b/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.cpp index 16e5c18df6..3e63c9ad62 100644 --- a/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.cpp +++ b/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.cpp @@ -3,10 +3,10 @@ // #include "proxy_sse2.h" -#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> -#include <library/cpp/digest/argonish/internal/argon2/argon2_sse2.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_sse2.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b_sse2.h> #define ZEROUPPER ; diff --git a/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h b/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h index 3173078647..a2b74cd9a7 100644 --- a/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h +++ b/library/cpp/digest/argonish/internal/proxies/sse2/proxy_sse2.h @@ -1,9 +1,9 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> namespace NArgonish { ARGON2_PROXY_CLASS_DECL(SSE2) diff --git a/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.cpp b/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.cpp index 9aa1beb42b..b633ad8cbf 100644 --- a/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.cpp +++ b/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.cpp @@ -3,10 +3,10 @@ // #include "proxy_sse41.h" -#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> -#include <library/cpp/digest/argonish/internal/argon2/argon2_sse41.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_sse41.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b_sse41.h> #define ZEROUPPER ; diff --git a/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h b/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h index 8e7f61404b..2a4b6614aa 100644 --- a/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h +++ b/library/cpp/digest/argonish/internal/proxies/sse41/proxy_sse41.h @@ -1,9 +1,9 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> namespace NArgonish { ARGON2_PROXY_CLASS_DECL(SSE41) diff --git a/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.cpp b/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.cpp index 71b5b5fa27..d77b55737c 100644 --- a/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.cpp +++ b/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.cpp @@ -3,10 +3,10 @@ // #include "proxy_ssse3.h" -#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> -#include <library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> -#include <library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_base.h> +#include <library/cpp/digest/argonish/internal/argon2/argon2_ssse3.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b.h> +#include <library/cpp/digest/argonish/internal/blake2b/blake2b_ssse3.h> #define ZEROUPPER ; diff --git a/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h b/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h index a025f99714..994133e88e 100644 --- a/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h +++ b/library/cpp/digest/argonish/internal/proxies/ssse3/proxy_ssse3.h @@ -1,9 +1,9 @@ #pragma once #include <util/generic/yexception.h> -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> -#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/internal/proxies/macro/proxy_macros.h> namespace NArgonish { ARGON2_PROXY_CLASS_DECL(SSSE3) diff --git a/library/cpp/digest/argonish/ut/ut.cpp b/library/cpp/digest/argonish/ut/ut.cpp index e7d8b795b9..12ef530a18 100644 --- a/library/cpp/digest/argonish/ut/ut.cpp +++ b/library/cpp/digest/argonish/ut/ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(ArgonishTest) { @@ -134,7 +134,7 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { const ui32 mcost = 16; const ui32 tcost = 1; TArrayHolder<ui8> memory(new ui8[mcost * 1024]); - const ui8 TResult[165] = { + const ui8 TResult[165] = { 0xe6, 0xff, 0x7b, 0xa1, 0xfa, 0x93, 0x0a, 0x51, 0x24, 0xf3, 0xbc, 0xc4, 0x98, 0xe2, 0x32, 0x08, 0x22, 0x7d, 0x4d, 0xf9, 0xe7, 0x2c, 0xd2, 0xd8, @@ -163,13 +163,13 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) { auto argon2d = factory.Create((NArgonish::EInstructionSet)i, NArgonish::EArgon2Type::Argon2d, tcost, mcost, 1, FrSecret, sizeof(FrSecret)); - ui8 hashResult[sizeof(TResult)]; + ui8 hashResult[sizeof(TResult)]; argon2d->HashWithCustomMemory(memory.Get(), mcost * 1024, FrPassword, sizeof(FrPassword), FrSalt, sizeof(FrSalt), hashResult, sizeof(hashResult)); - UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(hashResult)) == 0); + UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(hashResult)) == 0); UNIT_ASSERT(argon2d->VerifyWithCustomMemory(memory.Get(), mcost * 1024, FrPassword, sizeof(FrPassword), - FrSalt, sizeof(FrSalt), TResult, sizeof(TResult))); + FrSalt, sizeof(FrSalt), TResult, sizeof(TResult))); } } catch (...) { UNIT_FAIL("Argon2 fraction len test fail"); @@ -195,7 +195,7 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { } Y_UNIT_TEST(Argon2d) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x7b, 0xa5, 0xa1, 0x7a, 0x72, 0xf7, 0xe5, 0x99, 0x77, 0xf7, 0xf2, 0x3d, 0x10, 0xe6, 0x21, 0x89, 0x8c, 0x63, 0xce, 0xbe, 0xed, 0xda, 0xbd, 0x15, @@ -212,17 +212,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x87, 0x4d, 0x23, 0xfb, 0x9f, 0x55, 0xe2, 0xff, 0x66, 0xbc, 0x19, 0x03, 0x46, 0xe7, 0x01, 0x19, 0x7c, 0x9f, 0x25, 0xd1, 0x1d, 0xa4, 0x5a, 0xad, @@ -239,17 +239,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x99, 0xdf, 0xcf, 0xc2, 0x89, 0x76, 0x93, 0x9d, 0xa2, 0x97, 0x09, 0x44, 0x34, 0xd8, 0x6f, 0xd0, 0x0c, 0x94, 0x9a, 0x0f, 0x31, 0x8c, 0x22, 0xf0, @@ -266,17 +266,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x59, 0xb0, 0x94, 0x62, 0xcf, 0xdc, 0xd2, 0xb4, 0x0a, 0xbd, 0x17, 0x81, 0x0a, 0x47, 0x4a, 0x8e, 0xc1, 0xab, 0xb7, 0xc1, 0x8d, 0x07, 0x53, 0x7c, @@ -293,17 +293,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0xc1, 0x0f, 0x00, 0x5e, 0xf8, 0x78, 0xc8, 0x07, 0x0e, 0x2c, 0xc5, 0x2f, 0x57, 0x75, 0x25, 0xc9, 0x71, 0xc7, 0x30, 0xeb, 0x00, 0x64, 0x4a, 0x4e, @@ -320,17 +320,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x6c, 0x00, 0xb7, 0xa9, 0x00, 0xe5, 0x00, 0x4c, 0x24, 0x46, 0x9e, 0xc1, 0xe7, 0xc0, 0x1a, 0x99, 0xb2, 0xb8, 0xf7, 0x73, 0x75, 0xd4, 0xec, 0xa7, @@ -347,17 +347,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p_2th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x2b, 0x47, 0x35, 0x39, 0x4a, 0x40, 0x3c, 0xc9, 0x05, 0xfb, 0x51, 0x25, 0x96, 0x68, 0x64, 0x43, 0x02, 0x16, 0x38, 0xa6, 0xc1, 0x58, 0xfc, 0x8d, @@ -374,17 +374,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x4f, 0x93, 0xb5, 0xad, 0x78, 0xa4, 0xa9, 0x49, 0xfb, 0xe3, 0x55, 0x96, 0xd5, 0xa0, 0xc2, 0xab, 0x6f, 0x52, 0x2d, 0x2d, 0x29, 0xbc, 0x98, 0x49, @@ -401,17 +401,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x8f, 0xa2, 0x7c, 0xed, 0x28, 0x38, 0x79, 0x0f, 0xba, 0x5c, 0x11, 0x85, 0x1c, 0xdf, 0x90, 0x88, 0xb2, 0x18, 0x44, 0xd7, 0xf0, 0x4c, 0x97, 0xb2, @@ -428,17 +428,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x61, 0x1c, 0x99, 0x3c, 0xb0, 0xb7, 0x23, 0x16, 0xbd, 0xa2, 0x6c, 0x4c, 0x2f, 0xe8, 0x2d, 0x39, 0x9c, 0x8f, 0x1c, 0xfd, 0x45, 0xd9, 0x58, 0xa9, @@ -455,17 +455,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_128) { - const ui8 TResult[128] = { + const ui8 TResult[128] = { 0x4e, 0xc4, 0x6c, 0x4e, 0x8c, 0x32, 0x89, 0x65, 0xf9, 0x82, 0x2b, 0x00, 0x95, 0x00, 0x50, 0x0a, 0x72, 0x0d, 0xc5, 0x12, 0x8d, 0x6b, 0xbd, 0x84, @@ -494,17 +494,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Blake2B_16_ABC) { - const ui8 TResult[16] = { + const ui8 TResult[16] = { 0xcf, 0x4a, 0xb7, 0x91, 0xc6, 0x2b, 0x8d, 0x2b, 0x21, 0x09, 0xc9, 0x02, 0x75, 0x28, 0x78, 0x16}; const ui8 data[] = {'a', 'b', 'c'}; @@ -512,18 +512,18 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { NArgonish::TBlake2BFactory factory; NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet(); for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) { - auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); + auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); ui8 hashResult[16] = {0}; blake2b->Update(data, sizeof(data)); blake2b->Final(hashResult, sizeof(hashResult)); - UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); + UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); } } Y_UNIT_TEST(Blake2B_64_ABC) { - const ui8 TResult[64] = { + const ui8 TResult[64] = { 0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d, 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9, 0x4c, 0x21, 0x2f, 0x14, 0x68, 0x5a, 0xc4, 0xb7, @@ -537,13 +537,13 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { NArgonish::TBlake2BFactory factory; NArgonish::EInstructionSet maxInstructionSet = factory.GetInstructionSet(); for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)maxInstructionSet; ++i) { - auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); + auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); ui8 hashResult[64] = {0}; blake2b->Update(data, sizeof(data)); blake2b->Final(hashResult, sizeof(hashResult)); - UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); + UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); } } } diff --git a/library/cpp/digest/argonish/ut/ya.make b/library/cpp/digest/argonish/ut/ya.make index 965f23a5df..3440908799 100644 --- a/library/cpp/digest/argonish/ut/ya.make +++ b/library/cpp/digest/argonish/ut/ya.make @@ -1,9 +1,9 @@ -UNITTEST_FOR(library/cpp/digest/argonish) +UNITTEST_FOR(library/cpp/digest/argonish) OWNER(e-sidorov) PEERDIR( - library/cpp/digest/argonish + library/cpp/digest/argonish ) SRCS( diff --git a/library/cpp/digest/argonish/ut_fat/ut.cpp b/library/cpp/digest/argonish/ut_fat/ut.cpp index 535b6d588a..41fa001685 100644 --- a/library/cpp/digest/argonish/ut_fat/ut.cpp +++ b/library/cpp/digest/argonish/ut_fat/ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/digest/argonish/argon2.h> -#include <library/cpp/digest/argonish/blake2b.h> +#include <library/cpp/digest/argonish/argon2.h> +#include <library/cpp/digest/argonish/blake2b.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(ArgonishTest) { @@ -100,7 +100,7 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { } Y_UNIT_TEST(Argon2d) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x7b, 0xa5, 0xa1, 0x7a, 0x72, 0xf7, 0xe5, 0x99, 0x77, 0xf7, 0xf2, 0x3d, 0x10, 0xe6, 0x21, 0x89, 0x8c, 0x63, 0xce, 0xbe, 0xed, 0xda, 0xbd, 0x15, @@ -116,17 +116,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x87, 0x4d, 0x23, 0xfb, 0x9f, 0x55, 0xe2, 0xff, 0x66, 0xbc, 0x19, 0x03, 0x46, 0xe7, 0x01, 0x19, 0x7c, 0x9f, 0x25, 0xd1, 0x1d, 0xa4, 0x5a, 0xad, @@ -142,17 +142,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x99, 0xdf, 0xcf, 0xc2, 0x89, 0x76, 0x93, 0x9d, 0xa2, 0x97, 0x09, 0x44, 0x34, 0xd8, 0x6f, 0xd0, 0x0c, 0x94, 0x9a, 0x0f, 0x31, 0x8c, 0x22, 0xf0, @@ -168,17 +168,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x59, 0xb0, 0x94, 0x62, 0xcf, 0xdc, 0xd2, 0xb4, 0x0a, 0xbd, 0x17, 0x81, 0x0a, 0x47, 0x4a, 0x8e, 0xc1, 0xab, 0xb7, 0xc1, 0x8d, 0x07, 0x53, 0x7c, @@ -194,17 +194,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0xc1, 0x0f, 0x00, 0x5e, 0xf8, 0x78, 0xc8, 0x07, 0x0e, 0x2c, 0xc5, 0x2f, 0x57, 0x75, 0x25, 0xc9, 0x71, 0xc7, 0x30, 0xeb, 0x00, 0x64, 0x4a, 0x4e, @@ -220,17 +220,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id_2p) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x6c, 0x00, 0xb7, 0xa9, 0x00, 0xe5, 0x00, 0x4c, 0x24, 0x46, 0x9e, 0xc1, 0xe7, 0xc0, 0x1a, 0x99, 0xb2, 0xb8, 0xf7, 0x73, 0x75, 0xd4, 0xec, 0xa7, @@ -246,17 +246,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p_2th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x2b, 0x47, 0x35, 0x39, 0x4a, 0x40, 0x3c, 0xc9, 0x05, 0xfb, 0x51, 0x25, 0x96, 0x68, 0x64, 0x43, 0x02, 0x16, 0x38, 0xa6, 0xc1, 0x58, 0xfc, 0x8d, @@ -272,17 +272,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2id_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x4f, 0x93, 0xb5, 0xad, 0x78, 0xa4, 0xa9, 0x49, 0xfb, 0xe3, 0x55, 0x96, 0xd5, 0xa0, 0xc2, 0xab, 0x6f, 0x52, 0x2d, 0x2d, 0x29, 0xbc, 0x98, 0x49, @@ -298,17 +298,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2id->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2id->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x8f, 0xa2, 0x7c, 0xed, 0x28, 0x38, 0x79, 0x0f, 0xba, 0x5c, 0x11, 0x85, 0x1c, 0xdf, 0x90, 0x88, 0xb2, 0x18, 0x44, 0xd7, 0xf0, 0x4c, 0x97, 0xb2, @@ -324,17 +324,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2i_2p_4th) { - const ui8 TResult[32] = { + const ui8 TResult[32] = { 0x61, 0x1c, 0x99, 0x3c, 0xb0, 0xb7, 0x23, 0x16, 0xbd, 0xa2, 0x6c, 0x4c, 0x2f, 0xe8, 0x2d, 0x39, 0x9c, 0x8f, 0x1c, 0xfd, 0x45, 0xd9, 0x58, 0xa9, @@ -350,17 +350,17 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2i->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2i->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Argon2d_128) { - const ui8 TResult[128] = { + const ui8 TResult[128] = { 0x4e, 0xc4, 0x6c, 0x4e, 0x8c, 0x32, 0x89, 0x65, 0xf9, 0x82, 0x2b, 0x00, 0x95, 0x00, 0x50, 0x0a, 0x72, 0x0d, 0xc5, 0x12, 0x8d, 0x6b, 0xbd, 0x84, @@ -388,35 +388,35 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { argon2d->Hash(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), result, sizeof(result), GenKatAAD, sizeof(GenKatAAD)); - UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); + UNIT_ASSERT(memcmp(result, TResult, sizeof(result)) == 0); UNIT_ASSERT(argon2d->Verify(GenKatPassword, sizeof(GenKatPassword), GenKatSalt, sizeof(GenKatSalt), - TResult, sizeof(TResult), + TResult, sizeof(TResult), GenKatAAD, sizeof(GenKatAAD))); } } Y_UNIT_TEST(Blake2B_16_ABC) { - const ui8 TResult[16] = { + const ui8 TResult[16] = { 0xcf, 0x4a, 0xb7, 0x91, 0xc6, 0x2b, 0x8d, 0x2b, 0x21, 0x09, 0xc9, 0x02, 0x75, 0x28, 0x78, 0x16}; const ui8 data[] = {'a', 'b', 'c'}; NArgonish::TBlake2BFactory factory; for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)MaxArch; ++i) { - auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); + auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); ui8 hashResult[16] = {0}; blake2b->Update(data, sizeof(data)); blake2b->Final(hashResult, sizeof(hashResult)); - UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); + UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); } } Y_UNIT_TEST(Blake2B_64_ABC) { - const ui8 TResult[64] = { + const ui8 TResult[64] = { 0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d, 0x6a, 0x27, 0x97, 0xb6, 0x9f, 0x12, 0xf6, 0xe9, 0x4c, 0x21, 0x2f, 0x14, 0x68, 0x5a, 0xc4, 0xb7, @@ -429,13 +429,13 @@ Y_UNIT_TEST_SUITE(ArgonishTest) { NArgonish::TBlake2BFactory factory; for (int i = (int)NArgonish::EInstructionSet::REF; i <= (int)(int)MaxArch; ++i) { - auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); + auto blake2b = factory.Create((NArgonish::EInstructionSet)i, sizeof(TResult)); ui8 hashResult[64] = {0}; blake2b->Update(data, sizeof(data)); blake2b->Final(hashResult, sizeof(hashResult)); - UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); + UNIT_ASSERT(memcmp(hashResult, TResult, sizeof(TResult)) == 0); } } } diff --git a/library/cpp/digest/argonish/ut_fat/ya.make b/library/cpp/digest/argonish/ut_fat/ya.make index 2d79d1b50d..94ebda9225 100644 --- a/library/cpp/digest/argonish/ut_fat/ya.make +++ b/library/cpp/digest/argonish/ut_fat/ya.make @@ -1,9 +1,9 @@ -UNITTEST_FOR(library/cpp/digest/argonish) +UNITTEST_FOR(library/cpp/digest/argonish) OWNER(e-sidorov) PEERDIR( - library/cpp/digest/argonish + library/cpp/digest/argonish ) SRCS( diff --git a/library/cpp/digest/crc32c/ut/ya.make b/library/cpp/digest/crc32c/ut/ya.make index 08b2cca955..325622e080 100644 --- a/library/cpp/digest/crc32c/ut/ya.make +++ b/library/cpp/digest/crc32c/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/crc32c) +UNITTEST_FOR(library/cpp/digest/crc32c) OWNER(pg) diff --git a/library/cpp/digest/lower_case/ut/ya.make b/library/cpp/digest/lower_case/ut/ya.make index 8ab3a5564d..f083257b3d 100644 --- a/library/cpp/digest/lower_case/ut/ya.make +++ b/library/cpp/digest/lower_case/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/lower_case) +UNITTEST_FOR(library/cpp/digest/lower_case) OWNER( pg diff --git a/library/cpp/digest/md5/bench/main.cpp b/library/cpp/digest/md5/bench/main.cpp index 488fa26771..70672e6741 100644 --- a/library/cpp/digest/md5/bench/main.cpp +++ b/library/cpp/digest/md5/bench/main.cpp @@ -1,6 +1,6 @@ #include <benchmark/benchmark.h> -#include <library/cpp/digest/md5/md5.h> +#include <library/cpp/digest/md5/md5.h> #define MD5_DEF(N) \ static void MD5Benchmark_##N(benchmark::State& st) { \ diff --git a/library/cpp/digest/md5/bench/ya.make b/library/cpp/digest/md5/bench/ya.make index 35abaeae30..5c3e3c1c42 100644 --- a/library/cpp/digest/md5/bench/ya.make +++ b/library/cpp/digest/md5/bench/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/digest/md5 + library/cpp/digest/md5 ) SRCS( diff --git a/library/cpp/digest/md5/medium_ut/ya.make b/library/cpp/digest/md5/medium_ut/ya.make index 7b895a5c00..418c57f086 100644 --- a/library/cpp/digest/md5/medium_ut/ya.make +++ b/library/cpp/digest/md5/medium_ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/md5) +UNITTEST_FOR(library/cpp/digest/md5) SIZE(MEDIUM) diff --git a/library/cpp/digest/md5/ut/ya.make b/library/cpp/digest/md5/ut/ya.make index caff598a3f..ad1eddbff2 100644 --- a/library/cpp/digest/md5/ut/ya.make +++ b/library/cpp/digest/md5/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/md5) +UNITTEST_FOR(library/cpp/digest/md5) OWNER( pg diff --git a/library/cpp/digest/old_crc/crc.cpp b/library/cpp/digest/old_crc/crc.cpp index d363edd2ef..994755f34d 100644 --- a/library/cpp/digest/old_crc/crc.cpp +++ b/library/cpp/digest/old_crc/crc.cpp @@ -1,6 +1,6 @@ #include "crc.h" -#include <library/cpp/digest/old_crc/crc.inc> +#include <library/cpp/digest/old_crc/crc.inc> #include <util/system/defaults.h> diff --git a/library/cpp/digest/old_crc/ut/ya.make b/library/cpp/digest/old_crc/ut/ya.make index 070b838811..a783bbae5b 100644 --- a/library/cpp/digest/old_crc/ut/ya.make +++ b/library/cpp/digest/old_crc/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/old_crc) +UNITTEST_FOR(library/cpp/digest/old_crc) OWNER( pg diff --git a/library/cpp/digest/old_crc/ya.make b/library/cpp/digest/old_crc/ya.make index 477e0030de..aa6ea8f6c5 100644 --- a/library/cpp/digest/old_crc/ya.make +++ b/library/cpp/digest/old_crc/ya.make @@ -10,7 +10,7 @@ SRCS( ) RUN_PROGRAM( - library/cpp/digest/old_crc/gencrc + library/cpp/digest/old_crc/gencrc STDOUT crc.inc ) diff --git a/library/cpp/digest/sfh/ut/ya.make b/library/cpp/digest/sfh/ut/ya.make index 258d586f24..256a66295a 100644 --- a/library/cpp/digest/sfh/ut/ya.make +++ b/library/cpp/digest/sfh/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/digest/sfh) +UNITTEST_FOR(library/cpp/digest/sfh) OWNER( pg diff --git a/library/cpp/dns/ut/dns_ut.cpp b/library/cpp/dns/ut/dns_ut.cpp index d91cd77783..aae05a742c 100644 --- a/library/cpp/dns/ut/dns_ut.cpp +++ b/library/cpp/dns/ut/dns_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/dns/cache.h> +#include <library/cpp/dns/cache.h> #include <util/network/address.h> Y_UNIT_TEST_SUITE(TestDNS) { diff --git a/library/cpp/dns/ut/ya.make b/library/cpp/dns/ut/ya.make index f7d06c347b..7cfd0c4c32 100644 --- a/library/cpp/dns/ut/ya.make +++ b/library/cpp/dns/ut/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/dns + library/cpp/dns ) SRCS( diff --git a/library/cpp/enumbitset/ut/ya.make b/library/cpp/enumbitset/ut/ya.make index aae9e33042..c893e6eb13 100644 --- a/library/cpp/enumbitset/ut/ya.make +++ b/library/cpp/enumbitset/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/enumbitset) +UNITTEST_FOR(library/cpp/enumbitset) OWNER(alzobnin) diff --git a/library/cpp/execprofile/autostart/start.cpp b/library/cpp/execprofile/autostart/start.cpp index 4b5d41b8a4..4fffb03ae1 100644 --- a/library/cpp/execprofile/autostart/start.cpp +++ b/library/cpp/execprofile/autostart/start.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/execprofile/profile.h> +#include <library/cpp/execprofile/profile.h> namespace { struct TInit { diff --git a/library/cpp/execprofile/autostart/ya.make b/library/cpp/execprofile/autostart/ya.make index 9305a13048..a5b61f075f 100644 --- a/library/cpp/execprofile/autostart/ya.make +++ b/library/cpp/execprofile/autostart/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/execprofile + library/cpp/execprofile ) SRCS( diff --git a/library/cpp/getopt/last_getopt_demo/demo.cpp b/library/cpp/getopt/last_getopt_demo/demo.cpp index ddcd9ea1de..79426a9cc9 100644 --- a/library/cpp/getopt/last_getopt_demo/demo.cpp +++ b/library/cpp/getopt/last_getopt_demo/demo.cpp @@ -1,6 +1,6 @@ #include <library/cpp/getopt/last_getopt.h> #include <library/cpp/getopt/modchooser.h> -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> // For the sake of this example, let's implement Wget diff --git a/library/cpp/getopt/print.cpp b/library/cpp/getopt/print.cpp index d2c46477af..8cf1c62e4d 100644 --- a/library/cpp/getopt/print.cpp +++ b/library/cpp/getopt/print.cpp @@ -6,8 +6,8 @@ #include "posix_getopt.h" #include "ygetopt.h" -#include <library/cpp/svnversion/svnversion.h> -#include <library/cpp/build_info/build_info.h> +#include <library/cpp/svnversion/svnversion.h> +#include <library/cpp/build_info/build_info.h> namespace NLastGetoptPrivate { TString InitVersionString() { diff --git a/library/cpp/getopt/small/completer_command.cpp b/library/cpp/getopt/small/completer_command.cpp index 2027ebbd77..5e593eec7e 100644 --- a/library/cpp/getopt/small/completer_command.cpp +++ b/library/cpp/getopt/small/completer_command.cpp @@ -4,7 +4,7 @@ #include "last_getopt.h" #include "wrap.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/string/subst.h> diff --git a/library/cpp/getopt/small/last_getopt_opts.cpp b/library/cpp/getopt/small/last_getopt_opts.cpp index 488a814d6e..03c432849f 100644 --- a/library/cpp/getopt/small/last_getopt_opts.cpp +++ b/library/cpp/getopt/small/last_getopt_opts.cpp @@ -3,7 +3,7 @@ #include "wrap.h" #include "last_getopt_parser.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/stream/format.h> #include <util/charset/utf8.h> diff --git a/library/cpp/getopt/small/last_getopt_opts.h b/library/cpp/getopt/small/last_getopt_opts.h index 9112cb3b1c..825b99c871 100644 --- a/library/cpp/getopt/small/last_getopt_opts.h +++ b/library/cpp/getopt/small/last_getopt_opts.h @@ -2,7 +2,7 @@ #include "last_getopt_opt.h" -#include <library/cpp/colorizer/fwd.h> +#include <library/cpp/colorizer/fwd.h> #include <util/generic/map.h> diff --git a/library/cpp/getopt/small/last_getopt_parser.cpp b/library/cpp/getopt/small/last_getopt_parser.cpp index bd7ded5e14..7668b12a03 100644 --- a/library/cpp/getopt/small/last_getopt_parser.cpp +++ b/library/cpp/getopt/small/last_getopt_parser.cpp @@ -1,6 +1,6 @@ #include "last_getopt_parser.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/string/escape.h> diff --git a/library/cpp/getopt/small/last_getopt_parser.h b/library/cpp/getopt/small/last_getopt_parser.h index 2860218ca4..2cf8a6c308 100644 --- a/library/cpp/getopt/small/last_getopt_parser.h +++ b/library/cpp/getopt/small/last_getopt_parser.h @@ -2,7 +2,7 @@ #include "last_getopt_opts.h" -#include <library/cpp/colorizer/fwd.h> +#include <library/cpp/colorizer/fwd.h> #include <util/generic/hash_set.h> #include <util/generic/list.h> diff --git a/library/cpp/getopt/small/modchooser.cpp b/library/cpp/getopt/small/modchooser.cpp index 71df8e3d9a..2fa5cfd070 100644 --- a/library/cpp/getopt/small/modchooser.cpp +++ b/library/cpp/getopt/small/modchooser.cpp @@ -4,7 +4,7 @@ #include "last_getopt.h" #include "modchooser.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/stream/output.h> #include <util/stream/format.h> diff --git a/library/cpp/getopt/small/wrap.cpp b/library/cpp/getopt/small/wrap.cpp index 08032c8de5..9fbd38842a 100644 --- a/library/cpp/getopt/small/wrap.cpp +++ b/library/cpp/getopt/small/wrap.cpp @@ -1,6 +1,6 @@ #include "wrap.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/generic/string.h> #include <util/stream/str.h> diff --git a/library/cpp/getopt/small/ya.make b/library/cpp/getopt/small/ya.make index 941096d8c6..96de0f04b1 100644 --- a/library/cpp/getopt/small/ya.make +++ b/library/cpp/getopt/small/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/colorizer + library/cpp/colorizer ) SRCS( diff --git a/library/cpp/getopt/ut/last_getopt_ut.cpp b/library/cpp/getopt/ut/last_getopt_ut.cpp index ffa9c0399c..c99a1d053d 100644 --- a/library/cpp/getopt/ut/last_getopt_ut.cpp +++ b/library/cpp/getopt/ut/last_getopt_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/getopt/last_getopt.h> -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <library/cpp/testing/unittest/registar.h> #include <util/generic/array_size.h> diff --git a/library/cpp/getopt/ya.make b/library/cpp/getopt/ya.make index 99c49e8118..6df23b22b2 100644 --- a/library/cpp/getopt/ya.make +++ b/library/cpp/getopt/ya.make @@ -4,8 +4,8 @@ OWNER(pg) PEERDIR( library/cpp/getopt/small - library/cpp/svnversion - library/cpp/build_info + library/cpp/svnversion + library/cpp/build_info ) SRCS( diff --git a/library/cpp/grpc/server/grpc_request.h b/library/cpp/grpc/server/grpc_request.h index 034de84776..5bd8d3902b 100644 --- a/library/cpp/grpc/server/grpc_request.h +++ b/library/cpp/grpc/server/grpc_request.h @@ -5,7 +5,7 @@ #include <google/protobuf/message.h> #include <library/cpp/monlib/dynamic_counters/counters.h> -#include <library/cpp/logger/priority.h> +#include <library/cpp/logger/priority.h> #include "grpc_response.h" #include "event_callback.h" diff --git a/library/cpp/histogram/adaptive/adaptive_histogram.h b/library/cpp/histogram/adaptive/adaptive_histogram.h index b9155a9f0d..fa8f48433f 100644 --- a/library/cpp/histogram/adaptive/adaptive_histogram.h +++ b/library/cpp/histogram/adaptive/adaptive_histogram.h @@ -3,7 +3,7 @@ #include "histogram.h" #include "common.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/ptr.h> #include <util/generic/set.h> diff --git a/library/cpp/histogram/adaptive/auto_histogram.h b/library/cpp/histogram/adaptive/auto_histogram.h index f25ffd5435..9fdf0b9abe 100644 --- a/library/cpp/histogram/adaptive/auto_histogram.h +++ b/library/cpp/histogram/adaptive/auto_histogram.h @@ -4,7 +4,7 @@ #include "fixed_bin_histogram.h" #include "histogram.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/ptr.h> #include <util/generic/yexception.h> diff --git a/library/cpp/histogram/adaptive/block_histogram.cpp b/library/cpp/histogram/adaptive/block_histogram.cpp index cb558eac5c..6586d13ff6 100644 --- a/library/cpp/histogram/adaptive/block_histogram.cpp +++ b/library/cpp/histogram/adaptive/block_histogram.cpp @@ -1,6 +1,6 @@ #include "block_histogram.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/algorithm.h> #include <util/generic/yexception.h> diff --git a/library/cpp/histogram/adaptive/block_histogram.h b/library/cpp/histogram/adaptive/block_histogram.h index 1f7c5227fb..266bb2f2b2 100644 --- a/library/cpp/histogram/adaptive/block_histogram.h +++ b/library/cpp/histogram/adaptive/block_histogram.h @@ -3,7 +3,7 @@ #include "histogram.h" #include "common.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/ptr.h> #include <util/generic/vector.h> diff --git a/library/cpp/histogram/adaptive/fixed_bin_histogram.cpp b/library/cpp/histogram/adaptive/fixed_bin_histogram.cpp index 41df8d5677..558aba9e2d 100644 --- a/library/cpp/histogram/adaptive/fixed_bin_histogram.cpp +++ b/library/cpp/histogram/adaptive/fixed_bin_histogram.cpp @@ -1,7 +1,7 @@ #include "fixed_bin_histogram.h" #include "auto_histogram.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/algorithm.h> #include <util/generic/yexception.h> diff --git a/library/cpp/histogram/adaptive/fixed_bin_histogram.h b/library/cpp/histogram/adaptive/fixed_bin_histogram.h index 7894e9543c..bd380bd94a 100644 --- a/library/cpp/histogram/adaptive/fixed_bin_histogram.h +++ b/library/cpp/histogram/adaptive/fixed_bin_histogram.h @@ -2,7 +2,7 @@ #include "histogram.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/ptr.h> #include <util/generic/vector.h> diff --git a/library/cpp/histogram/adaptive/multi_histogram.h b/library/cpp/histogram/adaptive/multi_histogram.h index 011eb6de4c..41caac5ba6 100644 --- a/library/cpp/histogram/adaptive/multi_histogram.h +++ b/library/cpp/histogram/adaptive/multi_histogram.h @@ -3,7 +3,7 @@ #include "histogram.h" #include "auto_histogram.h" -#include <library/cpp/histogram/adaptive/protos/histo.pb.h> +#include <library/cpp/histogram/adaptive/protos/histo.pb.h> #include <util/generic/hash.h> #include <util/generic/ptr.h> diff --git a/library/cpp/histogram/adaptive/protos/python/ya.make b/library/cpp/histogram/adaptive/protos/python/ya.make index 3f2e13eed1..3328c27965 100644 --- a/library/cpp/histogram/adaptive/protos/python/ya.make +++ b/library/cpp/histogram/adaptive/protos/python/ya.make @@ -1,3 +1,3 @@ OWNER(abogutskiy) -PY_PROTOS_FOR(library/cpp/histogram/adaptive/protos) +PY_PROTOS_FOR(library/cpp/histogram/adaptive/protos) diff --git a/library/cpp/histogram/adaptive/ya.make b/library/cpp/histogram/adaptive/ya.make index 50789152e9..b589801b27 100644 --- a/library/cpp/histogram/adaptive/ya.make +++ b/library/cpp/histogram/adaptive/ya.make @@ -14,7 +14,7 @@ SRCS( PEERDIR( contrib/libs/protobuf - library/cpp/histogram/adaptive/protos + library/cpp/histogram/adaptive/protos ) END() diff --git a/library/cpp/histogram/hdr/ut/ya.make b/library/cpp/histogram/hdr/ut/ya.make index 83c65dbdde..13ceb143c8 100644 --- a/library/cpp/histogram/hdr/ut/ya.make +++ b/library/cpp/histogram/hdr/ut/ya.make @@ -3,7 +3,7 @@ OWNER( jamel ) -UNITTEST_FOR(library/cpp/histogram/hdr) +UNITTEST_FOR(library/cpp/histogram/hdr) SRCS( histogram_ut.cpp diff --git a/library/cpp/html/escape/ut/escape_ut.cpp b/library/cpp/html/escape/ut/escape_ut.cpp index 4fadc4ede4..cd7b955138 100644 --- a/library/cpp/html/escape/ut/escape_ut.cpp +++ b/library/cpp/html/escape/ut/escape_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/html/escape/escape.h> +#include <library/cpp/html/escape/escape.h> #include <library/cpp/testing/unittest/registar.h> using namespace NHtml; diff --git a/library/cpp/html/escape/ut/ya.make b/library/cpp/html/escape/ut/ya.make index 9fadd6a76a..27d3a3d65a 100644 --- a/library/cpp/html/escape/ut/ya.make +++ b/library/cpp/html/escape/ut/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/html/escape + library/cpp/html/escape ) END() diff --git a/library/cpp/html/pcdata/ut/ya.make b/library/cpp/html/pcdata/ut/ya.make index e6d136fe84..bc947baa89 100644 --- a/library/cpp/html/pcdata/ut/ya.make +++ b/library/cpp/html/pcdata/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/html/pcdata) +UNITTEST_FOR(library/cpp/html/pcdata) OWNER(vladon) diff --git a/library/cpp/html/ya.make b/library/cpp/html/ya.make index a20dcac956..ab904be3b9 100644 --- a/library/cpp/html/ya.make +++ b/library/cpp/html/ya.make @@ -1,32 +1,32 @@ RECURSE( - dehtml - dehtml/ut - detect - blob - entity - entity/ut - escape - escape/ut - face - face/blob - html5 - html5/tests - html5/ut - lexer - lexer/ut - pcdata - pcdata/ut - pdoc - print - relalternate - relalternate/ut + dehtml + dehtml/ut + detect + blob + entity + entity/ut + escape + escape/ut + face + face/blob + html5 + html5/tests + html5/ut + lexer + lexer/ut + pcdata + pcdata/ut + pdoc + print + relalternate + relalternate/ut sanitize - spec - storage - storage/ut - strip - tree - url - zoneconf - zoneconf/ut + spec + storage + storage/ut + strip + tree + url + zoneconf + zoneconf/ut ) diff --git a/library/cpp/http/fetch/exthttpcodes.h b/library/cpp/http/fetch/exthttpcodes.h index a24352210d..6b525052cd 100644 --- a/library/cpp/http/fetch/exthttpcodes.h +++ b/library/cpp/http/fetch/exthttpcodes.h @@ -1,7 +1,7 @@ #pragma once #include <util/system/defaults.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/misc/httpcodes.h> enum ExtHttpCodes { // Custom diff --git a/library/cpp/http/fetch/http_digest.cpp b/library/cpp/http/fetch/http_digest.cpp index 76ed887dd2..1eaa02b7f2 100644 --- a/library/cpp/http/fetch/http_digest.cpp +++ b/library/cpp/http/fetch/http_digest.cpp @@ -1,6 +1,6 @@ #include "http_digest.h" -#include <library/cpp/digest/md5/md5.h> +#include <library/cpp/digest/md5/md5.h> #include <util/stream/output.h> #include <util/stream/str.h> diff --git a/library/cpp/http/fetch/http_digest.h b/library/cpp/http/fetch/http_digest.h index c32a38570e..3b1872d70b 100644 --- a/library/cpp/http/fetch/http_digest.h +++ b/library/cpp/http/fetch/http_digest.h @@ -3,7 +3,7 @@ #include "httpheader.h" #include <util/system/compat.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/misc/httpcodes.h> class httpDigestHandler { protected: diff --git a/library/cpp/http/fetch/httpfetcher.h b/library/cpp/http/fetch/httpfetcher.h index 019dd6492c..7fc251afd2 100644 --- a/library/cpp/http/fetch/httpfetcher.h +++ b/library/cpp/http/fetch/httpfetcher.h @@ -4,7 +4,7 @@ #include <io.h> #endif -#include <library/cpp/http/misc/httpdate.h> +#include <library/cpp/http/misc/httpdate.h> #include "httpagent.h" #include "httpparser.h" diff --git a/library/cpp/http/fetch/httpfsm.rl6 b/library/cpp/http/fetch/httpfsm.rl6 index 3485539a68..eab0328b18 100644 --- a/library/cpp/http/fetch/httpfsm.rl6 +++ b/library/cpp/http/fetch/httpfsm.rl6 @@ -1,15 +1,15 @@ #include <stdio.h> #include <time.h> -#include <library/cpp/charset/doccodes.h> -#include <library/cpp/charset/codepage.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/codepage.h> +#include <library/cpp/http/misc/httpcodes.h> #include <util/datetime/base.h> #include <util/generic/ylimits.h> #include <algorithm> // max -#include <library/cpp/http/fetch/httpheader.h> -#include <library/cpp/http/fetch/httpfsm.h> +#include <library/cpp/http/fetch/httpheader.h> +#include <library/cpp/http/fetch/httpfsm.h> #ifdef _MSC_VER #pragma warning(disable: 4702) // unreachable code @@ -39,7 +39,7 @@ static inline void setguarded(x &val, long cnt) { %%{ machine http_header_parser; -include HttpDateTimeParser "../../../../util/datetime/parser.rl6"; +include HttpDateTimeParser "../../../../util/datetime/parser.rl6"; alphtype unsigned char; diff --git a/library/cpp/http/fetch/httpfsm_ut.cpp b/library/cpp/http/fetch/httpfsm_ut.cpp index 66518bc8c5..b018e80101 100644 --- a/library/cpp/http/fetch/httpfsm_ut.cpp +++ b/library/cpp/http/fetch/httpfsm_ut.cpp @@ -3,7 +3,7 @@ #include "library-htfetch_ut_hreflang_out.h" #include <util/generic/ptr.h> -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> #include <library/cpp/testing/unittest/registar.h> class THttpHeaderParserTestSuite: public TTestBase { diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h index 3bec3e0709..b2810bbd41 100644 --- a/library/cpp/http/fetch/httpheader.h +++ b/library/cpp/http/fetch/httpheader.h @@ -2,7 +2,7 @@ #include "exthttpcodes.h" -#include <library/cpp/mime/types/mime.h> +#include <library/cpp/mime/types/mime.h> #include <util/system/defaults.h> #include <util/system/compat.h> diff --git a/library/cpp/http/fetch/httpload.h b/library/cpp/http/fetch/httpload.h index 44b7b2790a..e22e4b809e 100644 --- a/library/cpp/http/fetch/httpload.h +++ b/library/cpp/http/fetch/httpload.h @@ -7,8 +7,8 @@ #include <util/system/compat.h> #include <util/string/vector.h> #include <util/network/ip.h> -#include <library/cpp/uri/http_url.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/uri/http_url.h> +#include <library/cpp/http/misc/httpcodes.h> /********************************************************/ // Section 1: socket handlers diff --git a/library/cpp/http/fetch/httpparser.h b/library/cpp/http/fetch/httpparser.h index caf3fb8cc1..769828e4ae 100644 --- a/library/cpp/http/fetch/httpparser.h +++ b/library/cpp/http/fetch/httpparser.h @@ -3,9 +3,9 @@ #include "httpfsm.h" #include "httpheader.h" -#include <library/cpp/mime/types/mime.h> +#include <library/cpp/mime/types/mime.h> #include <util/system/yassert.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/misc/httpcodes.h> template <size_t headermax = 100 << 10, size_t bodymax = 1 << 20> struct TFakeCheck { diff --git a/library/cpp/http/fetch/ut/ya.make b/library/cpp/http/fetch/ut/ya.make index 7e44099e23..7486986b36 100644 --- a/library/cpp/http/fetch/ut/ya.make +++ b/library/cpp/http/fetch/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/http/fetch) +UNITTEST_FOR(library/cpp/http/fetch) OWNER( g:zora diff --git a/library/cpp/http/fetch/ya.make b/library/cpp/http/fetch/ya.make index 8c1b086bb7..7737127463 100644 --- a/library/cpp/http/fetch/ya.make +++ b/library/cpp/http/fetch/ya.make @@ -6,12 +6,12 @@ OWNER( PEERDIR( contrib/libs/zlib - library/cpp/charset - library/cpp/digest/md5 - library/cpp/http/misc - library/cpp/logger - library/cpp/mime/types - library/cpp/uri + library/cpp/charset + library/cpp/digest/md5 + library/cpp/http/misc + library/cpp/logger + library/cpp/mime/types + library/cpp/uri ) SRCS( diff --git a/library/cpp/http/io/compression.cpp b/library/cpp/http/io/compression.cpp index be4210f27d..8fa1f62ae6 100644 --- a/library/cpp/http/io/compression.cpp +++ b/library/cpp/http/io/compression.cpp @@ -1,15 +1,15 @@ #include "compression.h" #if defined(ENABLE_GPL) -#include <library/cpp/streams/lz/lz.h> +#include <library/cpp/streams/lz/lz.h> #endif -#include <library/cpp/streams/brotli/brotli.h> -#include <library/cpp/streams/lzma/lzma.h> -#include <library/cpp/streams/bzip2/bzip2.h> +#include <library/cpp/streams/brotli/brotli.h> +#include <library/cpp/streams/lzma/lzma.h> +#include <library/cpp/streams/bzip2/bzip2.h> -#include <library/cpp/blockcodecs/stream.h> -#include <library/cpp/blockcodecs/codecs.h> +#include <library/cpp/blockcodecs/stream.h> +#include <library/cpp/blockcodecs/codecs.h> #include <util/stream/zlib.h> diff --git a/library/cpp/http/io/fuzz/main.cpp b/library/cpp/http/io/fuzz/main.cpp index 1553015281..8ded9c7e32 100644 --- a/library/cpp/http/io/fuzz/main.cpp +++ b/library/cpp/http/io/fuzz/main.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/io/stream.h> #include <util/generic/vector.h> #include <util/stream/mem.h> diff --git a/library/cpp/http/io/fuzz/ya.make b/library/cpp/http/io/fuzz/ya.make index 2226bdbb7e..8b3ccb1969 100644 --- a/library/cpp/http/io/fuzz/ya.make +++ b/library/cpp/http/io/fuzz/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/http/io + library/cpp/http/io ) SIZE(MEDIUM) diff --git a/library/cpp/http/io/headers_ut.cpp b/library/cpp/http/io/headers_ut.cpp index 883dd0d786..1d23ef8fdc 100644 --- a/library/cpp/http/io/headers_ut.cpp +++ b/library/cpp/http/io/headers_ut.cpp @@ -3,7 +3,7 @@ #include <util/generic/strbuf.h> #include <utility> -#include <library/cpp/http/io/headers.h> +#include <library/cpp/http/io/headers.h> #include <library/cpp/testing/unittest/registar.h> namespace { diff --git a/library/cpp/http/io/list_codings/main.cpp b/library/cpp/http/io/list_codings/main.cpp index 20f9df4a26..9818d02bdf 100644 --- a/library/cpp/http/io/list_codings/main.cpp +++ b/library/cpp/http/io/list_codings/main.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/io/stream.h> #include <util/stream/output.h> int main() { diff --git a/library/cpp/http/io/list_codings/ya.make b/library/cpp/http/io/list_codings/ya.make index 02ded23816..e5c5fed6dc 100644 --- a/library/cpp/http/io/list_codings/ya.make +++ b/library/cpp/http/io/list_codings/ya.make @@ -3,7 +3,7 @@ PROGRAM() OWNER(pg) PEERDIR( - library/cpp/http/io + library/cpp/http/io ) SRCS( diff --git a/library/cpp/http/io/stream.cpp b/library/cpp/http/io/stream.cpp index 89942c4748..6689be684f 100644 --- a/library/cpp/http/io/stream.cpp +++ b/library/cpp/http/io/stream.cpp @@ -139,7 +139,7 @@ public: , Buffered_(Slave_, SuggestBufferSize()) , ChunkedInput_(nullptr) , Input_(nullptr) - , FirstLine_(ReadFirstLine(Buffered_)) + , FirstLine_(ReadFirstLine(Buffered_)) , Headers_(&Buffered_) , KeepAlive_(false) , HasContentLength_(false) @@ -151,12 +151,12 @@ public: Y_ASSERT(Input_); } - static TString ReadFirstLine(TBufferedInput& in) { - TString s; - Y_ENSURE_EX(in.ReadLine(s), THttpReadException() << "Failed to get first line"); - return s; - } - + static TString ReadFirstLine(TBufferedInput& in) { + TString s; + Y_ENSURE_EX(in.ReadLine(s), THttpReadException() << "Failed to get first line"); + return s; + } + inline ~TImpl() { } diff --git a/library/cpp/http/io/stream.h b/library/cpp/http/io/stream.h index 0f46920e0c..78ca4fc814 100644 --- a/library/cpp/http/io/stream.h +++ b/library/cpp/http/io/stream.h @@ -18,9 +18,9 @@ struct THttpException: public yexception { struct THttpParseException: public THttpException { }; -struct THttpReadException: public THttpException { -}; - +struct THttpReadException: public THttpException { +}; + /// Чтение ответа HTTP-сервера. class THttpInput: public IInputStream { public: diff --git a/library/cpp/http/io/stream_ut.cpp b/library/cpp/http/io/stream_ut.cpp index 9ad15ad7ac..1ea35df675 100644 --- a/library/cpp/http/io/stream_ut.cpp +++ b/library/cpp/http/io/stream_ut.cpp @@ -1,7 +1,7 @@ #include "stream.h" #include "chunk.h" -#include <library/cpp/http/server/http_ex.h> +#include <library/cpp/http/server/http_ex.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> diff --git a/library/cpp/http/io/ut/medium/ya.make b/library/cpp/http/io/ut/medium/ya.make index 1c51e783fb..235a23dcd7 100644 --- a/library/cpp/http/io/ut/medium/ya.make +++ b/library/cpp/http/io/ut/medium/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/http/io) +UNITTEST_FOR(library/cpp/http/io) SIZE(MEDIUM) diff --git a/library/cpp/http/io/ut/ya.make b/library/cpp/http/io/ut/ya.make index 8f79421039..84f6949db3 100644 --- a/library/cpp/http/io/ut/ya.make +++ b/library/cpp/http/io/ut/ya.make @@ -1,9 +1,9 @@ -UNITTEST_FOR(library/cpp/http/io) +UNITTEST_FOR(library/cpp/http/io) OWNER(g:util) PEERDIR( - library/cpp/http/server + library/cpp/http/server ) SRCS( diff --git a/library/cpp/http/io/ya.make b/library/cpp/http/io/ya.make index 90dd4679ad..dcfbd79885 100644 --- a/library/cpp/http/io/ya.make +++ b/library/cpp/http/io/ya.make @@ -6,10 +6,10 @@ OWNER( ) PEERDIR( - library/cpp/blockcodecs - library/cpp/streams/brotli - library/cpp/streams/bzip2 - library/cpp/streams/lzma + library/cpp/blockcodecs + library/cpp/streams/brotli + library/cpp/streams/bzip2 + library/cpp/streams/lzma ) SRCS( diff --git a/library/cpp/http/misc/httpreqdata.h b/library/cpp/http/misc/httpreqdata.h index fe3eaea5ba..16e59c4d78 100644 --- a/library/cpp/http/misc/httpreqdata.h +++ b/library/cpp/http/misc/httpreqdata.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/digest/lower_case/hash_ops.h> +#include <library/cpp/digest/lower_case/hash_ops.h> #include <util/str_stl.h> diff --git a/library/cpp/http/misc/ut/ya.make b/library/cpp/http/misc/ut/ya.make index fcfa5bdbbf..f4bdd35662 100644 --- a/library/cpp/http/misc/ut/ya.make +++ b/library/cpp/http/misc/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/http/misc) +UNITTEST_FOR(library/cpp/http/misc) OWNER(g:util) diff --git a/library/cpp/http/misc/ya.make b/library/cpp/http/misc/ya.make index 5e52839870..fceb3cf79c 100644 --- a/library/cpp/http/misc/ya.make +++ b/library/cpp/http/misc/ya.make @@ -16,7 +16,7 @@ SRCS( PEERDIR( library/cpp/cgiparam - library/cpp/digest/lower_case + library/cpp/digest/lower_case ) END() diff --git a/library/cpp/http/server/conn.h b/library/cpp/http/server/conn.h index 3ac4788bc2..3aa5329af4 100644 --- a/library/cpp/http/server/conn.h +++ b/library/cpp/http/server/conn.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/io/stream.h> #include <util/generic/ptr.h> class TSocket; diff --git a/library/cpp/http/server/http.h b/library/cpp/http/server/http.h index 015cac718b..b292d38f27 100644 --- a/library/cpp/http/server/http.h +++ b/library/cpp/http/server/http.h @@ -4,7 +4,7 @@ #include "options.h" #include <util/thread/pool.h> -#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/io/stream.h> #include <util/memory/blob.h> #include <util/generic/ptr.h> #include <util/generic/vector.h> diff --git a/library/cpp/http/server/http_ex.h b/library/cpp/http/server/http_ex.h index e6d082881f..1ef43ea4fd 100644 --- a/library/cpp/http/server/http_ex.h +++ b/library/cpp/http/server/http_ex.h @@ -2,7 +2,7 @@ #include "http.h" -#include <library/cpp/http/misc/httpreqdata.h> +#include <library/cpp/http/misc/httpreqdata.h> class THttpClientRequestExtension: public TClientRequest { public: diff --git a/library/cpp/http/server/response.h b/library/cpp/http/server/response.h index 0ae08b9b06..a75cb85605 100644 --- a/library/cpp/http/server/response.h +++ b/library/cpp/http/server/response.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/http/misc/httpcodes.h> -#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/io/stream.h> #include <util/generic/strbuf.h> #include <util/string/cast.h> diff --git a/library/cpp/http/server/ut/ya.make b/library/cpp/http/server/ut/ya.make index d81231448a..bcb4d4c0b8 100644 --- a/library/cpp/http/server/ut/ya.make +++ b/library/cpp/http/server/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/http/server) +UNITTEST_FOR(library/cpp/http/server) OWNER(pg) diff --git a/library/cpp/http/server/ya.make b/library/cpp/http/server/ya.make index d5db661500..bae6f33306 100644 --- a/library/cpp/http/server/ya.make +++ b/library/cpp/http/server/ya.make @@ -17,8 +17,8 @@ SRCS( ) PEERDIR( - library/cpp/http/misc - library/cpp/http/io + library/cpp/http/misc + library/cpp/http/io library/cpp/threading/equeue ) diff --git a/library/cpp/http/ya.make b/library/cpp/http/ya.make index 158e9167e8..fa2d1edef6 100644 --- a/library/cpp/http/ya.make +++ b/library/cpp/http/ya.make @@ -1,25 +1,25 @@ -RECURSE( - client - client/cookies - cookies - coro - examples - fetch +RECURSE( + client + client/cookies + cookies + coro + examples + fetch fetch_gpl - io - io/fuzz - io/list_codings - misc - multipart - push_parser - server - simple - static -) - -IF (NOT OS_WINDOWS) - RECURSE_FOR_TESTS( - io/ut - io/ut/medium - ) -ENDIF() + io + io/fuzz + io/list_codings + misc + multipart + push_parser + server + simple + static +) + +IF (NOT OS_WINDOWS) + RECURSE_FOR_TESTS( + io/ut + io/ut/medium + ) +ENDIF() diff --git a/library/cpp/hyperloglog/ut/ya.make b/library/cpp/hyperloglog/ut/ya.make index 76789b2644..f5f1c0d25a 100644 --- a/library/cpp/hyperloglog/ut/ya.make +++ b/library/cpp/hyperloglog/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/hyperloglog) +UNITTEST_FOR(library/cpp/hyperloglog) OWNER( anskor diff --git a/library/cpp/int128/bench/main.cpp b/library/cpp/int128/bench/main.cpp index aeb5e8e833..be4f8d1500 100644 --- a/library/cpp/int128/bench/main.cpp +++ b/library/cpp/int128/bench/main.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <library/cpp/testing/benchmark/bench.h> #include <util/generic/xrange.h> diff --git a/library/cpp/int128/bench/ya.make b/library/cpp/int128/bench/ya.make index df833a6786..4800e7883d 100644 --- a/library/cpp/int128/bench/ya.make +++ b/library/cpp/int128/bench/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/int128 + library/cpp/int128 ) END() diff --git a/library/cpp/int128/ut/i128_and_intrinsic_identity_ut.cpp b/library/cpp/int128/ut/i128_and_intrinsic_identity_ut.cpp index 9b23acfa14..dbb7507a73 100644 --- a/library/cpp/int128/ut/i128_and_intrinsic_identity_ut.cpp +++ b/library/cpp/int128/ut/i128_and_intrinsic_identity_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/i128_comparison_ut.cpp b/library/cpp/int128/ut/i128_comparison_ut.cpp index 4f8915f861..7b8d508815 100644 --- a/library/cpp/int128/ut/i128_comparison_ut.cpp +++ b/library/cpp/int128/ut/i128_comparison_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/i128_division_ut.cpp b/library/cpp/int128/ut/i128_division_ut.cpp index 45123abf80..46b0ca27f5 100644 --- a/library/cpp/int128/ut/i128_division_ut.cpp +++ b/library/cpp/int128/ut/i128_division_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/i128_type_traits_ut.cpp b/library/cpp/int128/ut/i128_type_traits_ut.cpp index c330ae0362..4ed87bf229 100644 --- a/library/cpp/int128/ut/i128_type_traits_ut.cpp +++ b/library/cpp/int128/ut/i128_type_traits_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/i128_ut.cpp b/library/cpp/int128/ut/i128_ut.cpp index 46477ad17f..c196d132a2 100644 --- a/library/cpp/int128/ut/i128_ut.cpp +++ b/library/cpp/int128/ut/i128_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/int128_old_ut.cpp b/library/cpp/int128/ut/int128_old_ut.cpp index ea61740e56..2c5b9e9610 100644 --- a/library/cpp/int128/ut/int128_old_ut.cpp +++ b/library/cpp/int128/ut/int128_old_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include "int128_ut_helpers.h" diff --git a/library/cpp/int128/ut/int128_typetraits_ut.cpp b/library/cpp/int128/ut/int128_typetraits_ut.cpp index 8329f2463e..fd5f19d7b8 100644 --- a/library/cpp/int128/ut/int128_typetraits_ut.cpp +++ b/library/cpp/int128/ut/int128_typetraits_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <type_traits> diff --git a/library/cpp/int128/ut/int128_ut.cpp b/library/cpp/int128/ut/int128_ut.cpp index e38910186c..7339264017 100644 --- a/library/cpp/int128/ut/int128_ut.cpp +++ b/library/cpp/int128/ut/int128_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/int128_ut_helpers.h b/library/cpp/int128/ut/int128_ut_helpers.h index 2ad19a8999..b7778c3f32 100644 --- a/library/cpp/int128/ut/int128_ut_helpers.h +++ b/library/cpp/int128/ut/int128_ut_helpers.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <array> diff --git a/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp b/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp index 3924f6d743..9decc2fd48 100644 --- a/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp +++ b/library/cpp/int128/ut/int128_via_intrinsic_ut.cpp @@ -1,34 +1,34 @@ -#include <library/cpp/int128/int128.h> - +#include <library/cpp/int128/int128.h> + #include <library/cpp/testing/unittest/registar.h> - + // from https://a.yandex-team.ru/arc/trunk/arcadia/library/ticket_parser/c/src/ut/utils_ut.cpp?rev=4221861 - + #if defined(Y_HAVE_INT128) Y_UNIT_TEST_SUITE(Int128ViaIntrinsicSuite) { - using guint128_t = unsigned __int128; + using guint128_t = unsigned __int128; guint128_t toGcc(ui128 num) { - guint128_t res = 0; + guint128_t res = 0; res |= GetLow(num); res |= guint128_t(GetHigh(num)) << 64; - return res; - } - + return res; + } + Y_UNIT_TEST(bigintTest) { UNIT_ASSERT(guint128_t(127) == toGcc(ui128(127))); UNIT_ASSERT(guint128_t(127) * guint128_t(127) == toGcc(ui128(127) * ui128(127))); UNIT_ASSERT(guint128_t(127) + guint128_t(127) == toGcc(ui128(127) + ui128(127))); UNIT_ASSERT(guint128_t(127) << 3 == toGcc(ui128(127) << 3)); UNIT_ASSERT(guint128_t(127) >> 1 == toGcc(ui128(127) >> 1)); - + UNIT_ASSERT(guint128_t(1000000000027UL) * guint128_t(1000000000027UL) == toGcc(ui128(1000000000027UL) * ui128(1000000000027UL))); UNIT_ASSERT(guint128_t(1000000000027UL) + guint128_t(1000000000027UL) == toGcc(ui128(1000000000027UL) + ui128(1000000000027UL))); UNIT_ASSERT(guint128_t(1000000000027UL) << 3 == toGcc(ui128(1000000000027UL) << 3)); UNIT_ASSERT(guint128_t(1000000000027UL) >> 1 == toGcc(ui128(1000000000027UL) >> 1)); UNIT_ASSERT((guint128_t(1000000000027UL) * guint128_t(1000000000027UL)) << 3 == toGcc((ui128(1000000000027UL) * ui128(1000000000027UL)) << 3)); UNIT_ASSERT((guint128_t(1000000000027UL) + guint128_t(1000000000027UL)) >> 1 == toGcc((ui128(1000000000027UL) + ui128(1000000000027UL)) >> 1)); - + UNIT_ASSERT((ui64)(guint128_t(1000000000027UL) * guint128_t(1000000000027UL)) == GetLow(ui128(1000000000027UL) * ui128(1000000000027UL))); - } -} + } +} #endif diff --git a/library/cpp/int128/ut/ui128_division_ut.cpp b/library/cpp/int128/ut/ui128_division_ut.cpp index 0073838c32..4826a531e0 100644 --- a/library/cpp/int128/ut/ui128_division_ut.cpp +++ b/library/cpp/int128/ut/ui128_division_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #include <util/generic/cast.h> diff --git a/library/cpp/int128/ut/ya.make b/library/cpp/int128/ut/ya.make index 98612fbee3..fd43531c5f 100644 --- a/library/cpp/int128/ut/ya.make +++ b/library/cpp/int128/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/int128) +UNITTEST_FOR(library/cpp/int128) OWNER(vladon) diff --git a/library/cpp/ipmath/ipmath_ut.cpp b/library/cpp/ipmath/ipmath_ut.cpp index 8e5e6e776b..5fe459ecc8 100644 --- a/library/cpp/ipmath/ipmath_ut.cpp +++ b/library/cpp/ipmath/ipmath_ut.cpp @@ -2,7 +2,7 @@ #include "range_set.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/testing/gmock_in_unittest/gmock.h> +#include <library/cpp/testing/gmock_in_unittest/gmock.h> #include <library/cpp/ipv6_address/ipv6_address.h> diff --git a/library/cpp/ipmath/ut/ya.make b/library/cpp/ipmath/ut/ya.make index 74b0a1ab86..b860cefd03 100644 --- a/library/cpp/ipmath/ut/ya.make +++ b/library/cpp/ipmath/ut/ya.make @@ -10,7 +10,7 @@ SRCS( ) PEERDIR( - library/cpp/testing/gmock_in_unittest + library/cpp/testing/gmock_in_unittest ) END() diff --git a/library/cpp/ipv6_address/ipv6_address.h b/library/cpp/ipv6_address/ipv6_address.h index 802af84816..1d7eb0b65f 100644 --- a/library/cpp/ipv6_address/ipv6_address.h +++ b/library/cpp/ipv6_address/ipv6_address.h @@ -4,7 +4,7 @@ #include <util/network/ip.h> #include <util/stream/input.h> -#include <library/cpp/int128/int128.h> +#include <library/cpp/int128/int128.h> #if defined(_freebsd_) // #include required to avoid problem with undefined 'socklen_t' on FreeBSD diff --git a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp index c1a25fcb4d..73bb7cffdd 100644 --- a/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp +++ b/library/cpp/ipv6_address/ut/ipv6_address_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/ipv6_address/ipv6_address.h> +#include <library/cpp/ipv6_address/ipv6_address.h> #include <unordered_set> class TIpv6AddressTest: public TTestBase { diff --git a/library/cpp/ipv6_address/ut/ya.make b/library/cpp/ipv6_address/ut/ya.make index e7e66cbe66..bd22899379 100644 --- a/library/cpp/ipv6_address/ut/ya.make +++ b/library/cpp/ipv6_address/ut/ya.make @@ -1,6 +1,6 @@ OWNER(g:zora) -UNITTEST_FOR(library/cpp/ipv6_address) +UNITTEST_FOR(library/cpp/ipv6_address) SRCS( ipv6_address_ut.cpp diff --git a/library/cpp/ipv6_address/ya.make b/library/cpp/ipv6_address/ya.make index c1573f8779..5c9bf7e383 100644 --- a/library/cpp/ipv6_address/ya.make +++ b/library/cpp/ipv6_address/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/int128 + library/cpp/int128 ) END() diff --git a/library/cpp/json/easy_parse/json_easy_parser.cpp b/library/cpp/json/easy_parse/json_easy_parser.cpp index 54f7b11a00..3c781f544b 100644 --- a/library/cpp/json/easy_parse/json_easy_parser.cpp +++ b/library/cpp/json/easy_parse/json_easy_parser.cpp @@ -1,5 +1,5 @@ #include "json_easy_parser.h" -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/string/cast.h> #include <util/string/split.h> #include <util/string/strip.h> diff --git a/library/cpp/json/easy_parse/ya.make b/library/cpp/json/easy_parse/ya.make index 2390414aff..2304c542f2 100644 --- a/library/cpp/json/easy_parse/ya.make +++ b/library/cpp/json/easy_parse/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/json + library/cpp/json ) END() diff --git a/library/cpp/json/fast_sax/parser.h b/library/cpp/json/fast_sax/parser.h index 68f24815c1..b5f031dd9e 100644 --- a/library/cpp/json/fast_sax/parser.h +++ b/library/cpp/json/fast_sax/parser.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/json/common/defs.h> +#include <library/cpp/json/common/defs.h> namespace NJson { bool ReadJsonFast(TStringBuf in, TJsonCallbacks* callbacks); diff --git a/library/cpp/json/fast_sax/parser.rl6 b/library/cpp/json/fast_sax/parser.rl6 index e4dbc704dd..edb4e9ee1b 100644 --- a/library/cpp/json/fast_sax/parser.rl6 +++ b/library/cpp/json/fast_sax/parser.rl6 @@ -1,5 +1,5 @@ -#include <library/cpp/json/fast_sax/unescape.h> -#include <library/cpp/json/fast_sax/parser.h> +#include <library/cpp/json/fast_sax/unescape.h> +#include <library/cpp/json/fast_sax/parser.h> #include <util/string/cast.h> #include <util/generic/buffer.h> diff --git a/library/cpp/json/fast_sax/ya.make b/library/cpp/json/fast_sax/ya.make index 260fef079e..c6447ab6ac 100644 --- a/library/cpp/json/fast_sax/ya.make +++ b/library/cpp/json/fast_sax/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/json/common + library/cpp/json/common ) SRCS( diff --git a/library/cpp/json/flex_buffers/cvt.cpp b/library/cpp/json/flex_buffers/cvt.cpp index 7037a48fd8..fee0cea0b8 100644 --- a/library/cpp/json/flex_buffers/cvt.cpp +++ b/library/cpp/json/flex_buffers/cvt.cpp @@ -2,8 +2,8 @@ #include <flatbuffers/flexbuffers.h> -#include <library/cpp/json/fast_sax/parser.h> -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/fast_sax/parser.h> +#include <library/cpp/json/json_reader.h> #include <util/generic/vector.h> #include <util/stream/output.h> diff --git a/library/cpp/json/flex_buffers/ut/cvt_ut.cpp b/library/cpp/json/flex_buffers/ut/cvt_ut.cpp index 9ec67ee58e..9fffef4d38 100644 --- a/library/cpp/json/flex_buffers/ut/cvt_ut.cpp +++ b/library/cpp/json/flex_buffers/ut/cvt_ut.cpp @@ -1,5 +1,5 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/json/flex_buffers/cvt.h> +#include <library/cpp/json/flex_buffers/cvt.h> using namespace NJson; diff --git a/library/cpp/json/flex_buffers/ut/ya.make b/library/cpp/json/flex_buffers/ut/ya.make index f92a8ed3f4..3fdc93f88e 100644 --- a/library/cpp/json/flex_buffers/ut/ya.make +++ b/library/cpp/json/flex_buffers/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/json/flex_buffers) +UNITTEST_FOR(library/cpp/json/flex_buffers) OWNER(pg) diff --git a/library/cpp/json/flex_buffers/ya.make b/library/cpp/json/flex_buffers/ya.make index 9329c04800..3ece5e3703 100644 --- a/library/cpp/json/flex_buffers/ya.make +++ b/library/cpp/json/flex_buffers/ya.make @@ -5,7 +5,7 @@ OWNER(pg) ADDINCL(contrib/libs/flatbuffers/include) PEERDIR( - library/cpp/json + library/cpp/json contrib/libs/flatbuffers ) diff --git a/library/cpp/json/fuzzy_test/main.cpp b/library/cpp/json/fuzzy_test/main.cpp index 3676bafa20..29a53aac14 100644 --- a/library/cpp/json/fuzzy_test/main.cpp +++ b/library/cpp/json/fuzzy_test/main.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/random/random.h> #include <util/stream/str.h> diff --git a/library/cpp/json/fuzzy_test/ya.make b/library/cpp/json/fuzzy_test/ya.make index 6658fedfcf..ff50bc1f62 100644 --- a/library/cpp/json/fuzzy_test/ya.make +++ b/library/cpp/json/fuzzy_test/ya.make @@ -3,7 +3,7 @@ FUZZ() OWNER(pg) PEERDIR( - library/cpp/json + library/cpp/json ) SRCS( diff --git a/library/cpp/json/json_reader.h b/library/cpp/json/json_reader.h index 58d8e537f7..b673788330 100644 --- a/library/cpp/json/json_reader.h +++ b/library/cpp/json/json_reader.h @@ -2,8 +2,8 @@ #include "json_value.h" -#include <library/cpp/json/common/defs.h> -#include <library/cpp/json/fast_sax/parser.h> +#include <library/cpp/json/common/defs.h> +#include <library/cpp/json/fast_sax/parser.h> #include <util/generic/yexception.h> @@ -134,7 +134,7 @@ namespace NJson { bool CloseComplexValue(); }; - //// relaxed json, used in library/cpp/scheme + //// relaxed json, used in library/cpp/scheme bool ReadJsonFastTree(TStringBuf in, TJsonValue* out, bool throwOnError = false, bool notClosedBracketIsError = false); TJsonValue ReadJsonFastTree(TStringBuf in, bool notClosedBracketIsError = false); } diff --git a/library/cpp/json/json_value.h b/library/cpp/json/json_value.h index 515141a9eb..f70f4d2ee8 100644 --- a/library/cpp/json/json_value.h +++ b/library/cpp/json/json_value.h @@ -1,3 +1,3 @@ #pragma once -#include <library/cpp/json/writer/json_value.h> +#include <library/cpp/json/writer/json_value.h> diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h index b9a565f5f4..c7f5c9499a 100644 --- a/library/cpp/json/json_writer.h +++ b/library/cpp/json/json_writer.h @@ -1,10 +1,10 @@ #pragma once -// Deprecated. Use library/cpp/json/writer in new code. +// Deprecated. Use library/cpp/json/writer in new code. #include "json_value.h" -#include <library/cpp/json/writer/json.h> +#include <library/cpp/json/writer/json.h> #include <util/stream/output.h> #include <util/generic/hash.h> diff --git a/library/cpp/json/ut/json_prettifier_ut.cpp b/library/cpp/json/ut/json_prettifier_ut.cpp index acfec1477e..ae5f8dd81a 100644 --- a/library/cpp/json/ut/json_prettifier_ut.cpp +++ b/library/cpp/json/ut/json_prettifier_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/json/json_prettifier.h> +#include <library/cpp/json/json_prettifier.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/json/ut/json_reader_fast_ut.cpp b/library/cpp/json/ut/json_reader_fast_ut.cpp index 0218e5ca10..60dffc91c7 100644 --- a/library/cpp/json/ut/json_reader_fast_ut.cpp +++ b/library/cpp/json/ut/json_reader_fast_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_prettifier.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_prettifier.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h> diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp index a724f0675f..cd31afa0b8 100644 --- a/library/cpp/json/ut/json_reader_ut.cpp +++ b/library/cpp/json/ut/json_reader_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_writer.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/str.h> diff --git a/library/cpp/json/ut/json_saveload_ut.cpp b/library/cpp/json/ut/json_saveload_ut.cpp index 8b3637b8c9..b480a80fe4 100644 --- a/library/cpp/json/ut/json_saveload_ut.cpp +++ b/library/cpp/json/ut/json_saveload_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_value.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/buffer.h> diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp index 4110d47244..ca11d34dad 100644 --- a/library/cpp/json/ut/json_writer_ut.cpp +++ b/library/cpp/json/ut/json_writer_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_writer.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/str.h> diff --git a/library/cpp/json/ut/ya.make b/library/cpp/json/ut/ya.make index 661b46a9bb..8e0362d84b 100644 --- a/library/cpp/json/ut/ya.make +++ b/library/cpp/json/ut/ya.make @@ -1,6 +1,6 @@ OWNER(velavokr) -UNITTEST_FOR(library/cpp/json) +UNITTEST_FOR(library/cpp/json) PEERDIR( library/cpp/string_utils/relaxed_escaper diff --git a/library/cpp/json/writer/README b/library/cpp/json/writer/README index bb63029bcd..a20489f32e 100644 --- a/library/cpp/json/writer/README +++ b/library/cpp/json/writer/README @@ -3,7 +3,7 @@ where HTML special characters are always escaped. Use it like this: - #include <library/cpp/json/writer/json.h> + #include <library/cpp/json/writer/json.h> ... NJsonWriter::TBuf json; diff --git a/library/cpp/json/writer/json.cpp b/library/cpp/json/writer/json.cpp index d9cc4924c9..02370c2d79 100644 --- a/library/cpp/json/writer/json.cpp +++ b/library/cpp/json/writer/json.cpp @@ -1,6 +1,6 @@ #include "json.h" -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_value.h> #include <util/string/cast.h> #include <util/string/strspn.h> diff --git a/library/cpp/json/writer/json_ut.cpp b/library/cpp/json/writer/json_ut.cpp index b228218574..9980555683 100644 --- a/library/cpp/json/writer/json_ut.cpp +++ b/library/cpp/json/writer/json_ut.cpp @@ -2,7 +2,7 @@ #include <util/system/sanitizers.h> #include "json.h" -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_value.h> #include <limits> diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h index 93f0a32ef8..3f0f50bc4c 100644 --- a/library/cpp/json/writer/json_value.h +++ b/library/cpp/json/writer/json_value.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/json/common/defs.h> +#include <library/cpp/json/common/defs.h> #include <util/generic/string.h> #include <util/generic/hash.h> diff --git a/library/cpp/json/writer/ut/ya.make b/library/cpp/json/writer/ut/ya.make index 0f2058b079..1e39dae6a1 100644 --- a/library/cpp/json/writer/ut/ya.make +++ b/library/cpp/json/writer/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(myltsev) PEERDIR( - ADDINCL library/cpp/json/writer + ADDINCL library/cpp/json/writer ) -SRCDIR(library/cpp/json/writer) +SRCDIR(library/cpp/json/writer) SRCS( json_ut.cpp diff --git a/library/cpp/json/writer/ya.make b/library/cpp/json/writer/ya.make index 6a4a99eeea..3989ff3504 100644 --- a/library/cpp/json/writer/ya.make +++ b/library/cpp/json/writer/ya.make @@ -7,7 +7,7 @@ OWNER( ) PEERDIR( - library/cpp/json/common + library/cpp/json/common ) SRCS( diff --git a/library/cpp/json/ya.make b/library/cpp/json/ya.make index 700a9cde24..d58eead8ec 100644 --- a/library/cpp/json/ya.make +++ b/library/cpp/json/ya.make @@ -14,9 +14,9 @@ SRCS( PEERDIR( contrib/libs/rapidjson - library/cpp/json/common - library/cpp/json/fast_sax - library/cpp/json/writer + library/cpp/json/common + library/cpp/json/fast_sax + library/cpp/json/writer library/cpp/string_utils/relaxed_escaper ) diff --git a/library/cpp/json/yson/json2yson.h b/library/cpp/json/yson/json2yson.h index 25449a0cf7..758eb6d0cf 100644 --- a/library/cpp/json/yson/json2yson.h +++ b/library/cpp/json/yson/json2yson.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> #include <library/cpp/yson/writer.h> namespace NJson2Yson { diff --git a/library/cpp/json/yson/json2yson_ut.cpp b/library/cpp/json/yson/json2yson_ut.cpp index 5942ea9568..9eb23354cf 100644 --- a/library/cpp/json/yson/json2yson_ut.cpp +++ b/library/cpp/json/yson/json2yson_ut.cpp @@ -1,7 +1,7 @@ -#include "library/cpp/json/yson/json2yson.h" +#include "library/cpp/json/yson/json2yson.h" -#include <library/cpp/blockcodecs/codecs.h> -#include <library/cpp/histogram/simple/histogram.h> +#include <library/cpp/blockcodecs/codecs.h> +#include <library/cpp/histogram/simple/histogram.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> diff --git a/library/cpp/json/yson/ut/ya.make b/library/cpp/json/yson/ut/ya.make index 783dc9ae2e..4ceb65b279 100644 --- a/library/cpp/json/yson/ut/ya.make +++ b/library/cpp/json/yson/ut/ya.make @@ -3,15 +3,15 @@ OWNER( elshiko ) -UNITTEST_FOR(library/cpp/json/yson) +UNITTEST_FOR(library/cpp/json/yson) ALLOCATOR(LF) DATA(sbr://363537653) PEERDIR( - library/cpp/blockcodecs - library/cpp/histogram/simple + library/cpp/blockcodecs + library/cpp/histogram/simple library/cpp/testing/unittest ) diff --git a/library/cpp/json/yson/ya.make b/library/cpp/json/yson/ya.make index c6deed6198..9b289d674f 100644 --- a/library/cpp/json/yson/ya.make +++ b/library/cpp/json/yson/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/json + library/cpp/json library/cpp/yson library/cpp/yson/json ) diff --git a/library/cpp/lcs/lcs_via_lis.h b/library/cpp/lcs/lcs_via_lis.h index e97747792e..d26733d94e 100644 --- a/library/cpp/lcs/lcs_via_lis.h +++ b/library/cpp/lcs/lcs_via_lis.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/containers/paged_vector/paged_vector.h> +#include <library/cpp/containers/paged_vector/paged_vector.h> #include <util/generic/ptr.h> #include <util/generic/hash.h> diff --git a/library/cpp/lcs/ut/ya.make b/library/cpp/lcs/ut/ya.make index 00533bef80..3d12898788 100644 --- a/library/cpp/lcs/ut/ya.make +++ b/library/cpp/lcs/ut/ya.make @@ -3,10 +3,10 @@ OWNER(velavokr) UNITTEST() PEERDIR( - ADDINCL library/cpp/lcs + ADDINCL library/cpp/lcs ) -SRCDIR(library/cpp/lcs) +SRCDIR(library/cpp/lcs) SRCS( lcs_via_lis_ut.cpp diff --git a/library/cpp/lcs/ya.make b/library/cpp/lcs/ya.make index 709cfa2a0d..3a7caafc88 100644 --- a/library/cpp/lcs/ya.make +++ b/library/cpp/lcs/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(velavokr) PEERDIR( - library/cpp/containers/paged_vector + library/cpp/containers/paged_vector ) SRCS( diff --git a/library/cpp/lfalloc/dbg/ya.make b/library/cpp/lfalloc/dbg/ya.make index 3840d80cb6..3dce653a8c 100644 --- a/library/cpp/lfalloc/dbg/ya.make +++ b/library/cpp/lfalloc/dbg/ya.make @@ -24,7 +24,7 @@ ELSE() ENDIF() PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) SET(IDE_FOLDER "util") diff --git a/library/cpp/lfalloc/dbg_info/dbg_info.cpp b/library/cpp/lfalloc/dbg_info/dbg_info.cpp index aa9534da01..1fb9f7ad93 100644 --- a/library/cpp/lfalloc/dbg_info/dbg_info.cpp +++ b/library/cpp/lfalloc/dbg_info/dbg_info.cpp @@ -1,6 +1,6 @@ #include "dbg_info.h" -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> namespace NAllocDbg { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/lfalloc/dbg_info/ya.make b/library/cpp/lfalloc/dbg_info/ya.make index 43462634f0..efecba5993 100644 --- a/library/cpp/lfalloc/dbg_info/ya.make +++ b/library/cpp/lfalloc/dbg_info/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(vskipin) PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) SRCS( diff --git a/library/cpp/lfalloc/lf_allocX64.h b/library/cpp/lfalloc/lf_allocX64.h index 974c8ee7f9..fd2a906d6f 100644 --- a/library/cpp/lfalloc/lf_allocX64.h +++ b/library/cpp/lfalloc/lf_allocX64.h @@ -4,7 +4,7 @@ #include <stdio.h> #include <stdarg.h> -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> #include <util/system/compat.h> #include <util/system/compiler.h> diff --git a/library/cpp/lfalloc/ya.make b/library/cpp/lfalloc/ya.make index c6a74eac74..cace05f9d8 100644 --- a/library/cpp/lfalloc/ya.make +++ b/library/cpp/lfalloc/ya.make @@ -17,7 +17,7 @@ ELSE() ENDIF() PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) SET(IDE_FOLDER "util") diff --git a/library/cpp/lfalloc/yt/ya.make b/library/cpp/lfalloc/yt/ya.make index f4bb1b3701..8c1a4f8a72 100644 --- a/library/cpp/lfalloc/yt/ya.make +++ b/library/cpp/lfalloc/yt/ya.make @@ -21,7 +21,7 @@ ELSE() ENDIF() PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) SET(IDE_FOLDER "util") diff --git a/library/cpp/linear_regression/benchmark/main.cpp b/library/cpp/linear_regression/benchmark/main.cpp index 5361e4ce0f..735d41e988 100644 --- a/library/cpp/linear_regression/benchmark/main.cpp +++ b/library/cpp/linear_regression/benchmark/main.cpp @@ -1,6 +1,6 @@ #include "pool.h" -#include <library/cpp/linear_regression/linear_regression.h> +#include <library/cpp/linear_regression/linear_regression.h> #include <util/datetime/base.h> #include <util/datetime/cputimer.h> diff --git a/library/cpp/linear_regression/benchmark/ya.make b/library/cpp/linear_regression/benchmark/ya.make index 0f3fefe372..bbc4f2683a 100644 --- a/library/cpp/linear_regression/benchmark/ya.make +++ b/library/cpp/linear_regression/benchmark/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/linear_regression + library/cpp/linear_regression ) END() diff --git a/library/cpp/linear_regression/linear_regression.h b/library/cpp/linear_regression/linear_regression.h index 3f398f7436..e57de5ff6c 100644 --- a/library/cpp/linear_regression/linear_regression.h +++ b/library/cpp/linear_regression/linear_regression.h @@ -3,7 +3,7 @@ #include "linear_model.h" #include "welford.h" -#include <library/cpp/accurate_accumulate/accurate_accumulate.h> +#include <library/cpp/accurate_accumulate/accurate_accumulate.h> #include <util/generic/vector.h> #include <util/generic/hash.h> diff --git a/library/cpp/linear_regression/linear_regression_ut.cpp b/library/cpp/linear_regression/linear_regression_ut.cpp index 80e1d9af82..e71a16b67a 100644 --- a/library/cpp/linear_regression/linear_regression_ut.cpp +++ b/library/cpp/linear_regression/linear_regression_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/linear_regression/linear_regression.h> +#include <library/cpp/linear_regression/linear_regression.h> #include <library/cpp/testing/unittest/registar.h> #include <util/generic/vector.h> diff --git a/library/cpp/linear_regression/ut/ya.make b/library/cpp/linear_regression/ut/ya.make index 7ce4cd3400..f410410673 100644 --- a/library/cpp/linear_regression/ut/ya.make +++ b/library/cpp/linear_regression/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(alex-sh) PEERDIR( - ADDINCL library/cpp/linear_regression + ADDINCL library/cpp/linear_regression ) -SRCDIR(library/cpp/linear_regression) +SRCDIR(library/cpp/linear_regression) SRCS( linear_regression_ut.cpp diff --git a/library/cpp/linear_regression/welford.h b/library/cpp/linear_regression/welford.h index 00f1c32ee3..ee865d6693 100644 --- a/library/cpp/linear_regression/welford.h +++ b/library/cpp/linear_regression/welford.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/accurate_accumulate/accurate_accumulate.h> +#include <library/cpp/accurate_accumulate/accurate_accumulate.h> #include <util/ysaveload.h> diff --git a/library/cpp/linear_regression/ya.make b/library/cpp/linear_regression/ya.make index 8a1fb5b98d..4cfcc3d673 100644 --- a/library/cpp/linear_regression/ya.make +++ b/library/cpp/linear_regression/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/accurate_accumulate + library/cpp/accurate_accumulate ) END() diff --git a/library/cpp/logger/global/common.h b/library/cpp/logger/global/common.h index 474c2a7747..7dcf650dec 100644 --- a/library/cpp/logger/global/common.h +++ b/library/cpp/logger/global/common.h @@ -10,7 +10,7 @@ #include <util/string/printf.h> #include <util/system/src_location.h> -#include <library/cpp/logger/log.h> +#include <library/cpp/logger/log.h> namespace NLoggingImpl { const size_t SingletonPriority = 500; diff --git a/library/cpp/logger/global/ut/ya.make b/library/cpp/logger/global/ut/ya.make index c3432e21ba..8aea38906f 100644 --- a/library/cpp/logger/global/ut/ya.make +++ b/library/cpp/logger/global/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(salmin) PEERDIR( - library/cpp/logger/global + library/cpp/logger/global ) -SRCDIR(library/cpp/logger/global) +SRCDIR(library/cpp/logger/global) SRCS( rty_formater_ut.cpp diff --git a/library/cpp/logger/global/ya.make b/library/cpp/logger/global/ya.make index 0fece830c7..20eb361e72 100644 --- a/library/cpp/logger/global/ya.make +++ b/library/cpp/logger/global/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(g:geosaas) PEERDIR( - library/cpp/logger + library/cpp/logger ) IF (OS_WINDOWS) diff --git a/library/cpp/logger/ut/ya.make b/library/cpp/logger/ut/ya.make index 704986e8c6..2a461c1353 100644 --- a/library/cpp/logger/ut/ya.make +++ b/library/cpp/logger/ut/ya.make @@ -3,12 +3,12 @@ UNITTEST() OWNER(pg) PEERDIR( - ADDINCL library/cpp/logger + ADDINCL library/cpp/logger library/cpp/logger/init_context library/cpp/yconf/patcher ) -SRCDIR(library/cpp/logger) +SRCDIR(library/cpp/logger) SRCS( log_ut.cpp diff --git a/library/cpp/lwtrace/control.h b/library/cpp/lwtrace/control.h index 1f654d6bbe..16b24eafd2 100644 --- a/library/cpp/lwtrace/control.h +++ b/library/cpp/lwtrace/control.h @@ -6,7 +6,7 @@ #include "log_shuttle.h" #include "probe.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> #include <google/protobuf/repeated_field.h> diff --git a/library/cpp/lwtrace/custom_action.h b/library/cpp/lwtrace/custom_action.h index c1bb7d2ad3..92a3c66b84 100644 --- a/library/cpp/lwtrace/custom_action.h +++ b/library/cpp/lwtrace/custom_action.h @@ -2,7 +2,7 @@ #include "probe.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> #include <util/generic/hash.h> diff --git a/library/cpp/lwtrace/event.h b/library/cpp/lwtrace/event.h index d88f6c700d..e53a620c45 100644 --- a/library/cpp/lwtrace/event.h +++ b/library/cpp/lwtrace/event.h @@ -4,7 +4,7 @@ #include "signature.h" #include "param_traits.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> namespace NLWTrace { // Common class for all events diff --git a/library/cpp/lwtrace/example1/lwtrace_example1.cpp b/library/cpp/lwtrace/example1/lwtrace_example1.cpp index 85fe9311ed..6b32c405ee 100644 --- a/library/cpp/lwtrace/example1/lwtrace_example1.cpp +++ b/library/cpp/lwtrace/example1/lwtrace_example1.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ PROBE(IterationProbe, GROUPS(), TYPES(i32, double), NAMES("n", "result")) \ diff --git a/library/cpp/lwtrace/example1/ya.make b/library/cpp/lwtrace/example1/ya.make index 5785a16a58..5ae8c4a48e 100644 --- a/library/cpp/lwtrace/example1/ya.make +++ b/library/cpp/lwtrace/example1/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/lwtrace/example2/lwtrace_example2.cpp b/library/cpp/lwtrace/example2/lwtrace_example2.cpp index 10799c144b..7a4f7a1daf 100644 --- a/library/cpp/lwtrace/example2/lwtrace_example2.cpp +++ b/library/cpp/lwtrace/example2/lwtrace_example2.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/lwtrace/control.h> -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/control.h> +#include <library/cpp/lwtrace/all.h> #include <library/cpp/getopt/last_getopt.h> #include <google/protobuf/text_format.h> diff --git a/library/cpp/lwtrace/example2/ya.make b/library/cpp/lwtrace/example2/ya.make index bb694d3224..22e34239c8 100644 --- a/library/cpp/lwtrace/example2/ya.make +++ b/library/cpp/lwtrace/example2/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/lwtrace + library/cpp/lwtrace library/cpp/getopt ) diff --git a/library/cpp/lwtrace/example3/lwtrace_example3.cpp b/library/cpp/lwtrace/example3/lwtrace_example3.cpp index 7f46b71fa0..4493dc0077 100644 --- a/library/cpp/lwtrace/example3/lwtrace_example3.cpp +++ b/library/cpp/lwtrace/example3/lwtrace_example3.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <google/protobuf/text_format.h> #include "my_action.h" diff --git a/library/cpp/lwtrace/example3/my_action.h b/library/cpp/lwtrace/example3/my_action.h index 20fdae8dd2..9a04293ba2 100644 --- a/library/cpp/lwtrace/example3/my_action.h +++ b/library/cpp/lwtrace/example3/my_action.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <util/stream/file.h> // Example of custom state for custom executors diff --git a/library/cpp/lwtrace/example3/ya.make b/library/cpp/lwtrace/example3/ya.make index 905c18f59e..c5b31586e9 100644 --- a/library/cpp/lwtrace/example3/ya.make +++ b/library/cpp/lwtrace/example3/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/lwtrace/example4/lwtrace_example4.cpp b/library/cpp/lwtrace/example4/lwtrace_example4.cpp index 65dcf1b612..7b55a07c75 100644 --- a/library/cpp/lwtrace/example4/lwtrace_example4.cpp +++ b/library/cpp/lwtrace/example4/lwtrace_example4.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #define LWTRACE_EXAMPLE_PROVIDER(PROBE, EVENT, GROUPS, TYPES, NAMES) \ PROBE(BackTrack, GROUPS(), TYPES(NLWTrace::TSymbol), NAMES("frame")) \ diff --git a/library/cpp/lwtrace/example4/ya.make b/library/cpp/lwtrace/example4/ya.make index e547b43004..a3004340a8 100644 --- a/library/cpp/lwtrace/example4/ya.make +++ b/library/cpp/lwtrace/example4/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/lwtrace/example5/lwtrace_example5.cpp b/library/cpp/lwtrace/example5/lwtrace_example5.cpp index 864278a46c..1c324473c2 100644 --- a/library/cpp/lwtrace/example5/lwtrace_example5.cpp +++ b/library/cpp/lwtrace/example5/lwtrace_example5.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/lwtrace/all.h> -#include <library/cpp/lwtrace/lwprobe.h> +#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/lwprobe.h> template <ui64 N> ui64 Fact() { diff --git a/library/cpp/lwtrace/example5/ya.make b/library/cpp/lwtrace/example5/ya.make index 8ff96e7876..06dd4dc569 100644 --- a/library/cpp/lwtrace/example5/ya.make +++ b/library/cpp/lwtrace/example5/ya.make @@ -7,7 +7,7 @@ SRCS( ) PEERDIR( - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.cpp b/library/cpp/lwtrace/mon/mon_lwtrace.cpp index 5d3cacf31e..a61ee9ce22 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.cpp +++ b/library/cpp/lwtrace/mon/mon_lwtrace.cpp @@ -5,13 +5,13 @@ #include <google/protobuf/text_format.h> #include <library/cpp/lwtrace/mon/analytics/all.h> -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <library/cpp/monlib/service/pages/mon_page.h> #include <library/cpp/monlib/service/pages/resource_mon_page.h> #include <library/cpp/monlib/service/pages/templates.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> #include <library/cpp/string_utils/base64/base64.h> -#include <library/cpp/html/pcdata/pcdata.h> +#include <library/cpp/html/pcdata/pcdata.h> #include <util/string/escape.h> #include <util/system/condvar.h> #include <util/system/execpath.h> @@ -3852,7 +3852,7 @@ private: "<li" << (request.GetParams().Get("mode") == "dashboards"? active: "") << "><a href=\"?mode=dashboards\">Dashboard</a></li>" "<li" << (request.GetParams().Get("mode") == "builder"? active: "") << "><a href=\"?mode=builder\">Builder</a></li>" "<li" << (request.GetParams().Get("mode") == "analytics"? active: "") << "><a href=\"?mode=analytics&id=\">Analytics</a></li>" - "<li><a href=\"https://wiki.yandex-team.ru/development/poisk/arcadia/library/cpp/lwtrace/\" target=\"_blank\">Documentation</a></li>" + "<li><a href=\"https://wiki.yandex-team.ru/development/poisk/arcadia/library/cpp/lwtrace/\" target=\"_blank\">Documentation</a></li>" "</ul>" "</div></nav>" ; diff --git a/library/cpp/lwtrace/mon/mon_lwtrace.h b/library/cpp/lwtrace/mon/mon_lwtrace.h index 09c5b5e0b7..8030f6ea61 100644 --- a/library/cpp/lwtrace/mon/mon_lwtrace.h +++ b/library/cpp/lwtrace/mon/mon_lwtrace.h @@ -2,7 +2,7 @@ #include <library/cpp/lwtrace/protos/lwtrace.pb.h> #include <library/cpp/monlib/service/monservice.h> -#include <library/cpp/lwtrace/control.h> +#include <library/cpp/lwtrace/control.h> #include <util/generic/vector.h> diff --git a/library/cpp/lwtrace/mon/ya.make b/library/cpp/lwtrace/mon/ya.make index 8bd476c2a0..bdcb315754 100644 --- a/library/cpp/lwtrace/mon/ya.make +++ b/library/cpp/lwtrace/mon/ya.make @@ -45,10 +45,10 @@ SRCS( PEERDIR( library/cpp/html/pcdata - library/cpp/lwtrace + library/cpp/lwtrace library/cpp/lwtrace/mon/analytics library/cpp/monlib/dynamic_counters - library/cpp/resource + library/cpp/resource library/cpp/string_utils/base64 ) diff --git a/library/cpp/lwtrace/signature.h b/library/cpp/lwtrace/signature.h index f710d67ec7..868bd9bcf2 100644 --- a/library/cpp/lwtrace/signature.h +++ b/library/cpp/lwtrace/signature.h @@ -2,7 +2,7 @@ #include "preprocessor.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> #include <util/generic/cast.h> #include <util/generic/string.h> diff --git a/library/cpp/lwtrace/tests/trace_tests.cpp b/library/cpp/lwtrace/tests/trace_tests.cpp index d33624e225..6762e344a7 100644 --- a/library/cpp/lwtrace/tests/trace_tests.cpp +++ b/library/cpp/lwtrace/tests/trace_tests.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <library/cpp/getopt/last_getopt.h> diff --git a/library/cpp/lwtrace/tests/ya.make b/library/cpp/lwtrace/tests/ya.make index f7fd0b4a8f..6225ab1fa0 100644 --- a/library/cpp/lwtrace/tests/ya.make +++ b/library/cpp/lwtrace/tests/ya.make @@ -9,7 +9,7 @@ SRCS( PEERDIR( contrib/libs/protobuf library/cpp/getopt - library/cpp/lwtrace + library/cpp/lwtrace ) END() diff --git a/library/cpp/lwtrace/trace_ut.cpp b/library/cpp/lwtrace/trace_ut.cpp index 891ca31df2..cb03e4fbde 100644 --- a/library/cpp/lwtrace/trace_ut.cpp +++ b/library/cpp/lwtrace/trace_ut.cpp @@ -1,6 +1,6 @@ #include "all.h" -#include <library/cpp/lwtrace/protos/lwtrace.pb.h> +#include <library/cpp/lwtrace/protos/lwtrace.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/lwtrace/ut/ya.make b/library/cpp/lwtrace/ut/ya.make index 029d7a7391..f43118bab7 100644 --- a/library/cpp/lwtrace/ut/ya.make +++ b/library/cpp/lwtrace/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/lwtrace) +UNITTEST_FOR(library/cpp/lwtrace) OWNER(serxa) diff --git a/library/cpp/lwtrace/ya.make b/library/cpp/lwtrace/ya.make index c2db963ef2..d9accb3006 100644 --- a/library/cpp/lwtrace/ya.make +++ b/library/cpp/lwtrace/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(serxa) PEERDIR( - library/cpp/lwtrace/protos + library/cpp/lwtrace/protos ) SRCS( diff --git a/library/cpp/malloc/api/helpers/io.cpp b/library/cpp/malloc/api/helpers/io.cpp index a69710f925..5177969f4d 100644 --- a/library/cpp/malloc/api/helpers/io.cpp +++ b/library/cpp/malloc/api/helpers/io.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> #include <util/stream/output.h> diff --git a/library/cpp/malloc/api/helpers/ya.make b/library/cpp/malloc/api/helpers/ya.make index 07f9856779..62875bca0e 100644 --- a/library/cpp/malloc/api/helpers/ya.make +++ b/library/cpp/malloc/api/helpers/ya.make @@ -3,7 +3,7 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api ) SRCS( diff --git a/library/cpp/malloc/api/ut/ut.cpp b/library/cpp/malloc/api/ut/ut.cpp index 5951230f6e..7eccd0bf8d 100644 --- a/library/cpp/malloc/api/ut/ut.cpp +++ b/library/cpp/malloc/api/ut/ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> Y_UNIT_TEST_SUITE(MallocApi) { Y_UNIT_TEST(ToStream) { diff --git a/library/cpp/malloc/api/ut/ya.make b/library/cpp/malloc/api/ut/ya.make index 8799b27eb2..e57225b45d 100644 --- a/library/cpp/malloc/api/ut/ya.make +++ b/library/cpp/malloc/api/ut/ya.make @@ -3,7 +3,7 @@ UNITTEST() OWNER(nga) PEERDIR( - library/cpp/malloc/api/helpers + library/cpp/malloc/api/helpers ) SRCS( diff --git a/library/cpp/malloc/jemalloc/malloc-info.cpp b/library/cpp/malloc/jemalloc/malloc-info.cpp index aa1668f45d..2643ca4766 100644 --- a/library/cpp/malloc/jemalloc/malloc-info.cpp +++ b/library/cpp/malloc/jemalloc/malloc-info.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> using namespace NMalloc; diff --git a/library/cpp/malloc/jemalloc/ya.make b/library/cpp/malloc/jemalloc/ya.make index e56db432e8..99db474eab 100644 --- a/library/cpp/malloc/jemalloc/ya.make +++ b/library/cpp/malloc/jemalloc/ya.make @@ -6,11 +6,11 @@ OWNER(nga) IF (OS_ANDROID) PEERDIR( - library/cpp/malloc/system + library/cpp/malloc/system ) ELSE() PEERDIR( - library/cpp/malloc/api + library/cpp/malloc/api contrib/libs/jemalloc ) SRCS( diff --git a/library/cpp/messagebus/acceptor.h b/library/cpp/messagebus/acceptor.h index 00c5788299..57cb010bf2 100644 --- a/library/cpp/messagebus/acceptor.h +++ b/library/cpp/messagebus/acceptor.h @@ -7,7 +7,7 @@ #include "session_impl.h" #include "shutdown_state.h" -#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/actor/actor.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/actor/actor_ut.cpp b/library/cpp/messagebus/actor/actor_ut.cpp index 12f64ac208..b76ab55bfa 100644 --- a/library/cpp/messagebus/actor/actor_ut.cpp +++ b/library/cpp/messagebus/actor/actor_ut.cpp @@ -3,7 +3,7 @@ #include "actor.h" #include "queue_in_actor.h" -#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/misc/test_sync.h> #include <util/generic/object_counter.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/all/ya.make b/library/cpp/messagebus/all/ya.make index 36d9b5adf3..ffa2dbfabc 100644 --- a/library/cpp/messagebus/all/ya.make +++ b/library/cpp/messagebus/all/ya.make @@ -1,10 +1,10 @@ OWNER(g:messagebus) RECURSE_ROOT_RELATIVE( - library/python/messagebus - library/cpp/messagebus/debug_receiver - library/cpp/messagebus/oldmodule - library/cpp/messagebus/rain_check - library/cpp/messagebus/test - library/cpp/messagebus/www + library/python/messagebus + library/cpp/messagebus/debug_receiver + library/cpp/messagebus/oldmodule + library/cpp/messagebus/rain_check + library/cpp/messagebus/test + library/cpp/messagebus/www ) diff --git a/library/cpp/messagebus/codegen.h b/library/cpp/messagebus/codegen.h index d4ce217aa4..83e969e811 100644 --- a/library/cpp/messagebus/codegen.h +++ b/library/cpp/messagebus/codegen.h @@ -1,4 +1,4 @@ #pragma once -#include <library/cpp/messagebus/config/codegen.h> +#include <library/cpp/messagebus/config/codegen.h> diff --git a/library/cpp/messagebus/config/defs.h b/library/cpp/messagebus/config/defs.h index 3fe1f2a6d0..92b1df9969 100644 --- a/library/cpp/messagebus/config/defs.h +++ b/library/cpp/messagebus/config/defs.h @@ -1,11 +1,11 @@ #pragma once -// unique tag to fix pragma once gcc glueing: ./library/cpp/messagebus/defs.h +// unique tag to fix pragma once gcc glueing: ./library/cpp/messagebus/defs.h #include "codegen.h" #include "netaddr.h" -#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> +#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> #include <util/generic/list.h> diff --git a/library/cpp/messagebus/config/ya.make b/library/cpp/messagebus/config/ya.make index 91c555b920..20c7dfed19 100644 --- a/library/cpp/messagebus/config/ya.make +++ b/library/cpp/messagebus/config/ya.make @@ -4,7 +4,7 @@ OWNER(g:messagebus) PEERDIR( library/cpp/getopt - library/cpp/deprecated/enum_codegen + library/cpp/deprecated/enum_codegen ) SRCS( diff --git a/library/cpp/messagebus/debug_receiver/debug_receiver.cpp b/library/cpp/messagebus/debug_receiver/debug_receiver.cpp index bc1354246e..23b02d1003 100644 --- a/library/cpp/messagebus/debug_receiver/debug_receiver.cpp +++ b/library/cpp/messagebus/debug_receiver/debug_receiver.cpp @@ -1,10 +1,10 @@ #include "debug_receiver_handler.h" #include "debug_receiver_proto.h" -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> #include <library/cpp/getopt/last_getopt.h> -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> using namespace NBus; diff --git a/library/cpp/messagebus/debug_receiver/debug_receiver_handler.h b/library/cpp/messagebus/debug_receiver/debug_receiver_handler.h index 3180743607..0aed6b9984 100644 --- a/library/cpp/messagebus/debug_receiver/debug_receiver_handler.h +++ b/library/cpp/messagebus/debug_receiver/debug_receiver_handler.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> struct TDebugReceiverHandler: public NBus::IBusServerHandler { NBus::TBusServerSession* ServerSession; diff --git a/library/cpp/messagebus/debug_receiver/debug_receiver_proto.h b/library/cpp/messagebus/debug_receiver/debug_receiver_proto.h index f71ca3279c..d34710dcf7 100644 --- a/library/cpp/messagebus/debug_receiver/debug_receiver_proto.h +++ b/library/cpp/messagebus/debug_receiver/debug_receiver_proto.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> struct TDebugReceiverMessage: public NBus::TBusMessage { /// constructor to create messages on sending end diff --git a/library/cpp/messagebus/debug_receiver/ya.make b/library/cpp/messagebus/debug_receiver/ya.make index ce1ad26518..f1b14d35bb 100644 --- a/library/cpp/messagebus/debug_receiver/ya.make +++ b/library/cpp/messagebus/debug_receiver/ya.make @@ -10,8 +10,8 @@ SRCS( PEERDIR( library/cpp/getopt - library/cpp/lwtrace - library/cpp/messagebus + library/cpp/lwtrace + library/cpp/messagebus ) END() diff --git a/library/cpp/messagebus/defs.h b/library/cpp/messagebus/defs.h index bcf3faa32a..cb553acc45 100644 --- a/library/cpp/messagebus/defs.h +++ b/library/cpp/messagebus/defs.h @@ -1,4 +1,4 @@ #pragma once -#include <library/cpp/messagebus/config/defs.h> +#include <library/cpp/messagebus/config/defs.h> diff --git a/library/cpp/messagebus/lfqueue_batch.h b/library/cpp/messagebus/lfqueue_batch.h index 986f82c4e4..8128d3154d 100644 --- a/library/cpp/messagebus/lfqueue_batch.h +++ b/library/cpp/messagebus/lfqueue_batch.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/actor/temp_tls_vector.h> +#include <library/cpp/messagebus/actor/temp_tls_vector.h> #include <util/generic/vector.h> #include <util/thread/lfstack.h> diff --git a/library/cpp/messagebus/local_flags.h b/library/cpp/messagebus/local_flags.h index b9e047de18..f589283188 100644 --- a/library/cpp/messagebus/local_flags.h +++ b/library/cpp/messagebus/local_flags.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> +#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> #include <util/generic/string.h> #include <util/stream/output.h> diff --git a/library/cpp/messagebus/mb_lwtrace.cpp b/library/cpp/messagebus/mb_lwtrace.cpp index f0929485a5..c54cd5ab71 100644 --- a/library/cpp/messagebus/mb_lwtrace.cpp +++ b/library/cpp/messagebus/mb_lwtrace.cpp @@ -1,6 +1,6 @@ #include "mb_lwtrace.h" -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <util/generic/singleton.h> diff --git a/library/cpp/messagebus/mb_lwtrace.h b/library/cpp/messagebus/mb_lwtrace.h index ec817ea626..e62728b265 100644 --- a/library/cpp/messagebus/mb_lwtrace.h +++ b/library/cpp/messagebus/mb_lwtrace.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/lwtrace/all.h> +#include <library/cpp/lwtrace/all.h> #include <util/generic/string.h> diff --git a/library/cpp/messagebus/message_status.h b/library/cpp/messagebus/message_status.h index 98273a5a5c..e1878960b3 100644 --- a/library/cpp/messagebus/message_status.h +++ b/library/cpp/messagebus/message_status.h @@ -3,7 +3,7 @@ #include "codegen.h" #include "defs.h" -#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> +#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> namespace NBus { //////////////////////////////////////////////////////////////// diff --git a/library/cpp/messagebus/message_status_counter.cpp b/library/cpp/messagebus/message_status_counter.cpp index d1446bdb95..891c8f5bb2 100644 --- a/library/cpp/messagebus/message_status_counter.cpp +++ b/library/cpp/messagebus/message_status_counter.cpp @@ -3,7 +3,7 @@ #include "key_value_printer.h" #include "text_utils.h" -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> #include <util/stream/str.h> diff --git a/library/cpp/messagebus/message_status_counter.h b/library/cpp/messagebus/message_status_counter.h index 94a0f3e8ac..e8ba2fdd31 100644 --- a/library/cpp/messagebus/message_status_counter.h +++ b/library/cpp/messagebus/message_status_counter.h @@ -2,7 +2,7 @@ #include "message_status.h" -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> #include <util/generic/string.h> diff --git a/library/cpp/messagebus/message_status_counter_ut.cpp b/library/cpp/messagebus/message_status_counter_ut.cpp index 5bdfeff5b0..9598651329 100644 --- a/library/cpp/messagebus/message_status_counter_ut.cpp +++ b/library/cpp/messagebus/message_status_counter_ut.cpp @@ -2,7 +2,7 @@ #include "message_status_counter.h" -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> using namespace NBus; using namespace NBus::NPrivate; diff --git a/library/cpp/messagebus/netaddr.h b/library/cpp/messagebus/netaddr.h index af07a72ad0..f915c8c574 100644 --- a/library/cpp/messagebus/netaddr.h +++ b/library/cpp/messagebus/netaddr.h @@ -1,4 +1,4 @@ #pragma once -#include <library/cpp/messagebus/config/netaddr.h> +#include <library/cpp/messagebus/config/netaddr.h> diff --git a/library/cpp/messagebus/network_ut.cpp b/library/cpp/messagebus/network_ut.cpp index ebca2497f1..f1798419db 100644 --- a/library/cpp/messagebus/network_ut.cpp +++ b/library/cpp/messagebus/network_ut.cpp @@ -2,7 +2,7 @@ #include "network.h" -#include <library/cpp/messagebus/test/helper/fixed_port.h> +#include <library/cpp/messagebus/test/helper/fixed_port.h> using namespace NBus; using namespace NBus::NPrivate; diff --git a/library/cpp/messagebus/oldmodule/module.cpp b/library/cpp/messagebus/oldmodule/module.cpp index f5f559c8b1..24bd778799 100644 --- a/library/cpp/messagebus/oldmodule/module.cpp +++ b/library/cpp/messagebus/oldmodule/module.cpp @@ -1,11 +1,11 @@ #include "module.h" -#include <library/cpp/messagebus/scheduler_actor.h> -#include <library/cpp/messagebus/thread_extra.h> -#include <library/cpp/messagebus/actor/actor.h> -#include <library/cpp/messagebus/actor/queue_in_actor.h> -#include <library/cpp/messagebus/actor/what_thread_does.h> -#include <library/cpp/messagebus/actor/what_thread_does_guard.h> +#include <library/cpp/messagebus/scheduler_actor.h> +#include <library/cpp/messagebus/thread_extra.h> +#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/actor/queue_in_actor.h> +#include <library/cpp/messagebus/actor/what_thread_does.h> +#include <library/cpp/messagebus/actor/what_thread_does_guard.h> #include <util/generic/singleton.h> #include <util/string/printf.h> diff --git a/library/cpp/messagebus/oldmodule/module.h b/library/cpp/messagebus/oldmodule/module.h index 1f0f562136..8d1c4a5d52 100644 --- a/library/cpp/messagebus/oldmodule/module.h +++ b/library/cpp/messagebus/oldmodule/module.h @@ -41,7 +41,7 @@ #include "startsession.h" -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> #include <util/generic/noncopyable.h> #include <util/generic/object_counter.h> diff --git a/library/cpp/messagebus/oldmodule/startsession.cpp b/library/cpp/messagebus/oldmodule/startsession.cpp index b6c266d17d..7c38801d62 100644 --- a/library/cpp/messagebus/oldmodule/startsession.cpp +++ b/library/cpp/messagebus/oldmodule/startsession.cpp @@ -16,7 +16,7 @@ #include "module.h" -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> namespace NBus { void* TBusStarter::_starter(void* data) { diff --git a/library/cpp/messagebus/oldmodule/startsession.h b/library/cpp/messagebus/oldmodule/startsession.h index 6d041edcb8..5e26e7e1e5 100644 --- a/library/cpp/messagebus/oldmodule/startsession.h +++ b/library/cpp/messagebus/oldmodule/startsession.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> #include <util/system/thread.h> diff --git a/library/cpp/messagebus/oldmodule/ya.make b/library/cpp/messagebus/oldmodule/ya.make index e04a65f9e8..ca5eae74f0 100644 --- a/library/cpp/messagebus/oldmodule/ya.make +++ b/library/cpp/messagebus/oldmodule/ya.make @@ -3,8 +3,8 @@ LIBRARY() OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus - library/cpp/messagebus/actor + library/cpp/messagebus + library/cpp/messagebus/actor ) SRCS( diff --git a/library/cpp/messagebus/protobuf/ya.make b/library/cpp/messagebus/protobuf/ya.make index e438d9f5b9..64ff240b51 100644 --- a/library/cpp/messagebus/protobuf/ya.make +++ b/library/cpp/messagebus/protobuf/ya.make @@ -8,8 +8,8 @@ SRCS( PEERDIR( contrib/libs/protobuf - library/cpp/messagebus - library/cpp/messagebus/actor + library/cpp/messagebus + library/cpp/messagebus/actor ) END() diff --git a/library/cpp/messagebus/protobuf/ybusbuf.cpp b/library/cpp/messagebus/protobuf/ybusbuf.cpp index 45bc9a1cce..63415b3737 100644 --- a/library/cpp/messagebus/protobuf/ybusbuf.cpp +++ b/library/cpp/messagebus/protobuf/ybusbuf.cpp @@ -1,6 +1,6 @@ #include "ybusbuf.h" -#include <library/cpp/messagebus/actor/what_thread_does.h> +#include <library/cpp/messagebus/actor/what_thread_does.h> #include <google/protobuf/io/coded_stream.h> diff --git a/library/cpp/messagebus/protobuf/ybusbuf.h b/library/cpp/messagebus/protobuf/ybusbuf.h index 92b5e286b8..57b4267ea5 100644 --- a/library/cpp/messagebus/protobuf/ybusbuf.h +++ b/library/cpp/messagebus/protobuf/ybusbuf.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> #include <google/protobuf/descriptor.h> #include <google/protobuf/message.h> diff --git a/library/cpp/messagebus/rain_check/core/coro_ut.cpp b/library/cpp/messagebus/rain_check/core/coro_ut.cpp index bf7124e871..61a33584a5 100644 --- a/library/cpp/messagebus/rain_check/core/coro_ut.cpp +++ b/library/cpp/messagebus/rain_check/core/coro_ut.cpp @@ -3,7 +3,7 @@ #include "coro.h" #include "spawn.h" -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> using namespace NRainCheck; diff --git a/library/cpp/messagebus/rain_check/core/env.h b/library/cpp/messagebus/rain_check/core/env.h index b53fd59200..f6dd7fceb6 100644 --- a/library/cpp/messagebus/rain_check/core/env.h +++ b/library/cpp/messagebus/rain_check/core/env.h @@ -3,7 +3,7 @@ #include "sleep.h" #include "spawn.h" -#include <library/cpp/messagebus/actor/executor.h> +#include <library/cpp/messagebus/actor/executor.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/rain_check/core/simple_ut.cpp b/library/cpp/messagebus/rain_check/core/simple_ut.cpp index e25dfdf779..d4545e05aa 100644 --- a/library/cpp/messagebus/rain_check/core/simple_ut.cpp +++ b/library/cpp/messagebus/rain_check/core/simple_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> -#include <library/cpp/messagebus/latch.h> +#include <library/cpp/messagebus/latch.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/rain_check/core/sleep.h b/library/cpp/messagebus/rain_check/core/sleep.h index a39d1c4317..1a7a1f8674 100644 --- a/library/cpp/messagebus/rain_check/core/sleep.h +++ b/library/cpp/messagebus/rain_check/core/sleep.h @@ -2,7 +2,7 @@ #include "fwd.h" -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> #include <util/datetime/base.h> diff --git a/library/cpp/messagebus/rain_check/core/sleep_ut.cpp b/library/cpp/messagebus/rain_check/core/sleep_ut.cpp index fdc551d333..2ae85a87b1 100644 --- a/library/cpp/messagebus/rain_check/core/sleep_ut.cpp +++ b/library/cpp/messagebus/rain_check/core/sleep_ut.cpp @@ -1,6 +1,6 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/rain_check/core/spawn_ut.cpp b/library/cpp/messagebus/rain_check/core/spawn_ut.cpp index 122f057004..ba5a5e41cf 100644 --- a/library/cpp/messagebus/rain_check/core/spawn_ut.cpp +++ b/library/cpp/messagebus/rain_check/core/spawn_ut.cpp @@ -1,9 +1,9 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/rain_check/test/helper/misc.h> -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/helper/misc.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> -#include <library/cpp/messagebus/latch.h> +#include <library/cpp/messagebus/latch.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/rain_check/core/task.cpp b/library/cpp/messagebus/rain_check/core/task.cpp index f9acf1e0f7..a098437d53 100644 --- a/library/cpp/messagebus/rain_check/core/task.cpp +++ b/library/cpp/messagebus/rain_check/core/task.cpp @@ -1,6 +1,6 @@ #include "rain_check.h" -#include <library/cpp/messagebus/actor/temp_tls_vector.h> +#include <library/cpp/messagebus/actor/temp_tls_vector.h> #include <util/system/type_name.h> #include <util/system/tls.h> diff --git a/library/cpp/messagebus/rain_check/core/task.h b/library/cpp/messagebus/rain_check/core/task.h index 12b55d347c..7d8778bcda 100644 --- a/library/cpp/messagebus/rain_check/core/task.h +++ b/library/cpp/messagebus/rain_check/core/task.h @@ -2,10 +2,10 @@ #include "fwd.h" -#include <library/cpp/messagebus/actor/actor.h> -#include <library/cpp/messagebus/misc/atomic_box.h> +#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/misc/atomic_box.h> -#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> +#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> #include <util/generic/noncopyable.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/rain_check/core/track.h b/library/cpp/messagebus/rain_check/core/track.h index 094bee1506..d387de7574 100644 --- a/library/cpp/messagebus/rain_check/core/track.h +++ b/library/cpp/messagebus/rain_check/core/track.h @@ -3,9 +3,9 @@ #include "spawn.h" #include "task.h" -#include <library/cpp/messagebus/async_result.h> -#include <library/cpp/messagebus/actor/queue_in_actor.h> -#include <library/cpp/messagebus/misc/atomic_box.h> +#include <library/cpp/messagebus/async_result.h> +#include <library/cpp/messagebus/actor/queue_in_actor.h> +#include <library/cpp/messagebus/misc/atomic_box.h> #include <util/generic/intrlist.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/rain_check/core/track_ut.cpp b/library/cpp/messagebus/rain_check/core/track_ut.cpp index 7762e7770d..05f7de1319 100644 --- a/library/cpp/messagebus/rain_check/core/track_ut.cpp +++ b/library/cpp/messagebus/rain_check/core/track_ut.cpp @@ -2,8 +2,8 @@ #include "track.h" -#include <library/cpp/messagebus/rain_check/test/helper/misc.h> -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/helper/misc.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> using namespace NRainCheck; diff --git a/library/cpp/messagebus/rain_check/core/ya.make b/library/cpp/messagebus/rain_check/core/ya.make index 307ca2192d..c6fb5640d4 100644 --- a/library/cpp/messagebus/rain_check/core/ya.make +++ b/library/cpp/messagebus/rain_check/core/ya.make @@ -3,11 +3,11 @@ LIBRARY() OWNER(g:messagebus) PEERDIR( - library/cpp/coroutine/engine - library/cpp/deprecated/enum_codegen - library/cpp/messagebus - library/cpp/messagebus/actor - library/cpp/messagebus/scheduler + library/cpp/coroutine/engine + library/cpp/deprecated/enum_codegen + library/cpp/messagebus + library/cpp/messagebus/actor + library/cpp/messagebus/scheduler ) SRCS( diff --git a/library/cpp/messagebus/rain_check/http/client.cpp b/library/cpp/messagebus/rain_check/http/client.cpp index 22deca3827..5ef5ceeece 100644 --- a/library/cpp/messagebus/rain_check/http/client.cpp +++ b/library/cpp/messagebus/rain_check/http/client.cpp @@ -2,11 +2,11 @@ #include "http_code_extractor.h" -#include <library/cpp/http/io/stream.h> -#include <library/cpp/neh/factory.h> -#include <library/cpp/neh/http_common.h> -#include <library/cpp/neh/location.h> -#include <library/cpp/neh/neh.h> +#include <library/cpp/http/io/stream.h> +#include <library/cpp/neh/factory.h> +#include <library/cpp/neh/http_common.h> +#include <library/cpp/neh/location.h> +#include <library/cpp/neh/neh.h> #include <util/generic/ptr.h> #include <util/generic/strbuf.h> diff --git a/library/cpp/messagebus/rain_check/http/client.h b/library/cpp/messagebus/rain_check/http/client.h index d16b1db304..d4199c4c98 100644 --- a/library/cpp/messagebus/rain_check/http/client.h +++ b/library/cpp/messagebus/rain_check/http/client.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/messagebus/rain_check/core/task.h> +#include <library/cpp/messagebus/rain_check/core/task.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/misc/httpcodes.h> #include <util/generic/maybe.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/rain_check/http/client_ut.cpp b/library/cpp/messagebus/rain_check/http/client_ut.cpp index 7a0d57e64c..1628114391 100644 --- a/library/cpp/messagebus/rain_check/http/client_ut.cpp +++ b/library/cpp/messagebus/rain_check/http/client_ut.cpp @@ -3,12 +3,12 @@ #include "client.h" #include "http_code_extractor.h" -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> -#include <library/cpp/messagebus/test/helper/fixed_port.h> +#include <library/cpp/messagebus/test/helper/fixed_port.h> -#include <library/cpp/http/io/stream.h> -#include <library/cpp/neh/rpc.h> +#include <library/cpp/http/io/stream.h> +#include <library/cpp/neh/rpc.h> #include <util/generic/cast.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/rain_check/http/http_code_extractor.cpp b/library/cpp/messagebus/rain_check/http/http_code_extractor.cpp index 71e70d454e..51d75762f6 100644 --- a/library/cpp/messagebus/rain_check/http/http_code_extractor.cpp +++ b/library/cpp/messagebus/rain_check/http/http_code_extractor.cpp @@ -1,7 +1,7 @@ #include "http_code_extractor.h" -#include <library/cpp/http/io/stream.h> -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/misc/httpcodes.h> #include <util/generic/maybe.h> #include <util/generic/strbuf.h> @@ -9,10 +9,10 @@ namespace NRainCheck { TMaybe<HttpCodes> TryGetHttpCodeFromErrorDescription(const TStringBuf& errorMessage) { - // Try to get HttpCode from library/cpp/neh response. - // If response has HttpCode and it is not 200 OK, library/cpp/neh will send a message - // "library/cpp/neh/http.cpp:<LINE>: request failed(<FIRST-HTTP-RESPONSE-LINE>)" - // (see library/cpp/neh/http.cpp:625). So, we will try to parse this message and + // Try to get HttpCode from library/cpp/neh response. + // If response has HttpCode and it is not 200 OK, library/cpp/neh will send a message + // "library/cpp/neh/http.cpp:<LINE>: request failed(<FIRST-HTTP-RESPONSE-LINE>)" + // (see library/cpp/neh/http.cpp:625). So, we will try to parse this message and // find out HttpCode in it. It is bad temporary solution, but we have no choice. const TStringBuf SUBSTR = "request failed("; const size_t SUBSTR_LEN = SUBSTR.size(); diff --git a/library/cpp/messagebus/rain_check/http/http_code_extractor.h b/library/cpp/messagebus/rain_check/http/http_code_extractor.h index 727ebcbd61..33b565fa1c 100644 --- a/library/cpp/messagebus/rain_check/http/http_code_extractor.h +++ b/library/cpp/messagebus/rain_check/http/http_code_extractor.h @@ -1,15 +1,15 @@ #pragma once -#include <library/cpp/http/misc/httpcodes.h> +#include <library/cpp/http/misc/httpcodes.h> #include <util/generic/maybe.h> #include <util/generic/strbuf.h> namespace NRainCheck { - // Try to get HttpCode from library/cpp/neh response. - // If response has HttpCode and it is not 200 OK, library/cpp/neh will send a message - // "library/cpp/neh/http.cpp:<LINE>: request failed(<FIRST-HTTP-RESPONSE-LINE>)" - // (see library/cpp/neh/http.cpp:625). So, we will try to parse this message and + // Try to get HttpCode from library/cpp/neh response. + // If response has HttpCode and it is not 200 OK, library/cpp/neh will send a message + // "library/cpp/neh/http.cpp:<LINE>: request failed(<FIRST-HTTP-RESPONSE-LINE>)" + // (see library/cpp/neh/http.cpp:625). So, we will try to parse this message and // find out HttpCode in it. It is bad temporary solution, but we have no choice. TMaybe<HttpCodes> TryGetHttpCodeFromErrorDescription(const TStringBuf& errorMessage); diff --git a/library/cpp/messagebus/rain_check/http/ya.make b/library/cpp/messagebus/rain_check/http/ya.make index 59f7b3b2f2..ef13329df3 100644 --- a/library/cpp/messagebus/rain_check/http/ya.make +++ b/library/cpp/messagebus/rain_check/http/ya.make @@ -8,10 +8,10 @@ SRCS( ) PEERDIR( - library/cpp/messagebus/rain_check/core - library/cpp/neh - library/cpp/http/misc - library/cpp/http/io + library/cpp/messagebus/rain_check/core + library/cpp/neh + library/cpp/http/misc + library/cpp/http/io ) END() diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_client.h b/library/cpp/messagebus/rain_check/messagebus/messagebus_client.h index 5439c0c9a3..0a291cdea6 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_client.h +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_client.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/messagebus/rain_check/core/task.h> +#include <library/cpp/messagebus/rain_check/core/task.h> -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> namespace NRainCheck { class TBusFuture: public TSubtaskCompletion { diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_client_ut.cpp b/library/cpp/messagebus/rain_check/messagebus/messagebus_client_ut.cpp index 0ed2b6e8d0..1b3618558b 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_client_ut.cpp +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_client_ut.cpp @@ -2,10 +2,10 @@ #include "messagebus_client.h" -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> #include <util/generic/cast.h> diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.cpp b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.cpp index bcc31eeb92..5d4b13d664 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.cpp +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.cpp @@ -1,6 +1,6 @@ #include "messagebus_server.h" -#include <library/cpp/messagebus/rain_check/core/spawn.h> +#include <library/cpp/messagebus/rain_check/core/spawn.h> using namespace NRainCheck; diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h index f22b496f19..1334f05fe4 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_server.h @@ -1,9 +1,9 @@ #pragma once -#include <library/cpp/messagebus/rain_check/core/spawn.h> -#include <library/cpp/messagebus/rain_check/core/task.h> +#include <library/cpp/messagebus/rain_check/core/spawn.h> +#include <library/cpp/messagebus/rain_check/core/task.h> -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> #include <util/system/yassert.h> diff --git a/library/cpp/messagebus/rain_check/messagebus/messagebus_server_ut.cpp b/library/cpp/messagebus/rain_check/messagebus/messagebus_server_ut.cpp index fcd23c4961..7c11399f1b 100644 --- a/library/cpp/messagebus/rain_check/messagebus/messagebus_server_ut.cpp +++ b/library/cpp/messagebus/rain_check/messagebus/messagebus_server_ut.cpp @@ -2,9 +2,9 @@ #include "messagebus_server.h" -#include <library/cpp/messagebus/rain_check/test/ut/test.h> +#include <library/cpp/messagebus/rain_check/test/ut/test.h> -#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/example.h> using namespace NBus; using namespace NBus::NTest; diff --git a/library/cpp/messagebus/rain_check/messagebus/ya.make b/library/cpp/messagebus/rain_check/messagebus/ya.make index e5f7c016b1..defdac9a61 100644 --- a/library/cpp/messagebus/rain_check/messagebus/ya.make +++ b/library/cpp/messagebus/rain_check/messagebus/ya.make @@ -3,8 +3,8 @@ LIBRARY() OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus - library/cpp/messagebus/rain_check/core + library/cpp/messagebus + library/cpp/messagebus/rain_check/core ) SRCS( diff --git a/library/cpp/messagebus/rain_check/test/helper/misc.h b/library/cpp/messagebus/rain_check/test/helper/misc.h index 8800c05f6d..9150be4d2f 100644 --- a/library/cpp/messagebus/rain_check/test/helper/misc.h +++ b/library/cpp/messagebus/rain_check/test/helper/misc.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/rain_check/core/rain_check.h> +#include <library/cpp/messagebus/rain_check/core/rain_check.h> #include <array> diff --git a/library/cpp/messagebus/rain_check/test/helper/ya.make b/library/cpp/messagebus/rain_check/test/helper/ya.make index a5dc1e9b6c..aa9e4e6d81 100644 --- a/library/cpp/messagebus/rain_check/test/helper/ya.make +++ b/library/cpp/messagebus/rain_check/test/helper/ya.make @@ -3,7 +3,7 @@ LIBRARY(messagebus-rain_check-test-helper) OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus/rain_check/core + library/cpp/messagebus/rain_check/core ) SRCS( diff --git a/library/cpp/messagebus/rain_check/test/perftest/perftest.cpp b/library/cpp/messagebus/rain_check/test/perftest/perftest.cpp index 14107a407b..22edbd8c6b 100644 --- a/library/cpp/messagebus/rain_check/test/perftest/perftest.cpp +++ b/library/cpp/messagebus/rain_check/test/perftest/perftest.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/messagebus/rain_check/test/helper/misc.h> +#include <library/cpp/messagebus/rain_check/test/helper/misc.h> -#include <library/cpp/messagebus/rain_check/core/rain_check.h> +#include <library/cpp/messagebus/rain_check/core/rain_check.h> #include <util/datetime/base.h> diff --git a/library/cpp/messagebus/rain_check/test/perftest/ya.make b/library/cpp/messagebus/rain_check/test/perftest/ya.make index 04684be5d2..7330a71700 100644 --- a/library/cpp/messagebus/rain_check/test/perftest/ya.make +++ b/library/cpp/messagebus/rain_check/test/perftest/ya.make @@ -3,8 +3,8 @@ PROGRAM(messagebus_rain_check_perftest) OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus/rain_check/core - library/cpp/messagebus/rain_check/test/helper + library/cpp/messagebus/rain_check/core + library/cpp/messagebus/rain_check/test/helper ) SRCS( diff --git a/library/cpp/messagebus/rain_check/test/ut/test.h b/library/cpp/messagebus/rain_check/test/ut/test.h index 91e09d353a..724f6b7530 100644 --- a/library/cpp/messagebus/rain_check/test/ut/test.h +++ b/library/cpp/messagebus/rain_check/test/ut/test.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/messagebus/rain_check/core/rain_check.h> +#include <library/cpp/messagebus/rain_check/core/rain_check.h> -#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/misc/test_sync.h> template <typename TSelf> struct TTestEnvTemplate: public NRainCheck::TSimpleEnvTemplate<TSelf> { diff --git a/library/cpp/messagebus/rain_check/test/ut/ya.make b/library/cpp/messagebus/rain_check/test/ut/ya.make index 823b680749..9f7a93417a 100644 --- a/library/cpp/messagebus/rain_check/test/ut/ya.make +++ b/library/cpp/messagebus/rain_check/test/ut/ya.make @@ -4,10 +4,10 @@ OWNER(g:messagebus) PEERDIR( library/cpp/testing/unittest_main - library/cpp/messagebus/rain_check/core - library/cpp/messagebus/rain_check/http - library/cpp/messagebus/rain_check/messagebus - library/cpp/messagebus/test/helper + library/cpp/messagebus/rain_check/core + library/cpp/messagebus/rain_check/http + library/cpp/messagebus/rain_check/messagebus + library/cpp/messagebus/test/helper ) SRCS( diff --git a/library/cpp/messagebus/remote_client_connection.cpp b/library/cpp/messagebus/remote_client_connection.cpp index 2113e294a7..8c7a6db3a8 100644 --- a/library/cpp/messagebus/remote_client_connection.cpp +++ b/library/cpp/messagebus/remote_client_connection.cpp @@ -4,8 +4,8 @@ #include "network.h" #include "remote_client_session.h" -#include <library/cpp/messagebus/actor/executor.h> -#include <library/cpp/messagebus/actor/temp_tls_vector.h> +#include <library/cpp/messagebus/actor/executor.h> +#include <library/cpp/messagebus/actor/temp_tls_vector.h> #include <util/generic/cast.h> #include <util/thread/singleton.h> diff --git a/library/cpp/messagebus/remote_client_session.cpp b/library/cpp/messagebus/remote_client_session.cpp index 89bffae8f8..3bc421944f 100644 --- a/library/cpp/messagebus/remote_client_session.cpp +++ b/library/cpp/messagebus/remote_client_session.cpp @@ -3,7 +3,7 @@ #include "mb_lwtrace.h" #include "remote_client_connection.h" -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> #include <util/generic/cast.h> #include <util/system/defaults.h> diff --git a/library/cpp/messagebus/remote_connection.cpp b/library/cpp/messagebus/remote_connection.cpp index f9db43291c..22932569db 100644 --- a/library/cpp/messagebus/remote_connection.cpp +++ b/library/cpp/messagebus/remote_connection.cpp @@ -8,7 +8,7 @@ #include "remote_server_session.h" #include "session_impl.h" -#include <library/cpp/messagebus/actor/what_thread_does.h> +#include <library/cpp/messagebus/actor/what_thread_does.h> #include <util/generic/cast.h> #include <util/network/init.h> diff --git a/library/cpp/messagebus/remote_connection.h b/library/cpp/messagebus/remote_connection.h index 68783857d8..4538947368 100644 --- a/library/cpp/messagebus/remote_connection.h +++ b/library/cpp/messagebus/remote_connection.h @@ -16,11 +16,11 @@ #include "misc/granup.h" #include "misc/tokenquota.h" -#include <library/cpp/messagebus/actor/actor.h> -#include <library/cpp/messagebus/actor/executor.h> -#include <library/cpp/messagebus/actor/queue_for_actor.h> -#include <library/cpp/messagebus/actor/queue_in_actor.h> -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/actor/executor.h> +#include <library/cpp/messagebus/actor/queue_for_actor.h> +#include <library/cpp/messagebus/actor/queue_in_actor.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> #include <util/system/atomic.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/remote_connection_status.cpp b/library/cpp/messagebus/remote_connection_status.cpp index b87d532714..2c48b2a287 100644 --- a/library/cpp/messagebus/remote_connection_status.cpp +++ b/library/cpp/messagebus/remote_connection_status.cpp @@ -2,7 +2,7 @@ #include "key_value_printer.h" -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> #include <util/stream/format.h> #include <util/stream/output.h> diff --git a/library/cpp/messagebus/remote_connection_status.h b/library/cpp/messagebus/remote_connection_status.h index ca55fc91de..5db10e51ea 100644 --- a/library/cpp/messagebus/remote_connection_status.h +++ b/library/cpp/messagebus/remote_connection_status.h @@ -7,9 +7,9 @@ #include "queue_config.h" #include "session_config.h" -#include <library/cpp/messagebus/actor/executor.h> +#include <library/cpp/messagebus/actor/executor.h> -#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> +#include <library/cpp/deprecated/enum_codegen/enum_codegen.h> namespace NBus { class TConnectionStatusMonRecord; diff --git a/library/cpp/messagebus/remote_server_session.cpp b/library/cpp/messagebus/remote_server_session.cpp index 947a9dbfaf..6abbf88a60 100644 --- a/library/cpp/messagebus/remote_server_session.cpp +++ b/library/cpp/messagebus/remote_server_session.cpp @@ -3,7 +3,7 @@ #include "remote_connection.h" #include "remote_server_connection.h" -#include <library/cpp/messagebus/actor/temp_tls_vector.h> +#include <library/cpp/messagebus/actor/temp_tls_vector.h> #include <util/generic/cast.h> #include <util/stream/output.h> diff --git a/library/cpp/messagebus/scheduler/scheduler_ut.cpp b/library/cpp/messagebus/scheduler/scheduler_ut.cpp index f334b969d1..a5ea641c10 100644 --- a/library/cpp/messagebus/scheduler/scheduler_ut.cpp +++ b/library/cpp/messagebus/scheduler/scheduler_ut.cpp @@ -2,7 +2,7 @@ #include "scheduler.h" -#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/misc/test_sync.h> using namespace NBus; using namespace NBus::NPrivate; diff --git a/library/cpp/messagebus/scheduler_actor.h b/library/cpp/messagebus/scheduler_actor.h index d2a08c7c94..d0c23c94c4 100644 --- a/library/cpp/messagebus/scheduler_actor.h +++ b/library/cpp/messagebus/scheduler_actor.h @@ -2,9 +2,9 @@ #include "local_tasks.h" -#include <library/cpp/messagebus/actor/actor.h> -#include <library/cpp/messagebus/actor/what_thread_does_guard.h> -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/actor/what_thread_does_guard.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> #include <util/system/mutex.h> diff --git a/library/cpp/messagebus/session.h b/library/cpp/messagebus/session.h index d53daf8982..fb12ab7c22 100644 --- a/library/cpp/messagebus/session.h +++ b/library/cpp/messagebus/session.h @@ -9,7 +9,7 @@ #include "session_config.h" #include "misc/weak_ptr.h" -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> #include <util/generic/array_ref.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/session_config.h b/library/cpp/messagebus/session_config.h index daf9442c38..37df97e986 100644 --- a/library/cpp/messagebus/session_config.h +++ b/library/cpp/messagebus/session_config.h @@ -1,4 +1,4 @@ #pragma once -#include <library/cpp/messagebus/config/session_config.h> +#include <library/cpp/messagebus/config/session_config.h> diff --git a/library/cpp/messagebus/session_impl.h b/library/cpp/messagebus/session_impl.h index a73b2921e5..90ef246ff8 100644 --- a/library/cpp/messagebus/session_impl.h +++ b/library/cpp/messagebus/session_impl.h @@ -10,9 +10,9 @@ #include "shutdown_state.h" #include "ybus.h" -#include <library/cpp/messagebus/actor/actor.h> -#include <library/cpp/messagebus/actor/queue_in_actor.h> -#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> +#include <library/cpp/messagebus/actor/actor.h> +#include <library/cpp/messagebus/actor/queue_in_actor.h> +#include <library/cpp/messagebus/monitoring/mon_proto.pb.h> #include <library/cpp/threading/future/legacy_future.h> diff --git a/library/cpp/messagebus/test/example/client/client.cpp b/library/cpp/messagebus/test/example/client/client.cpp index 6e84556d70..89b5f2c9be 100644 --- a/library/cpp/messagebus/test/example/client/client.cpp +++ b/library/cpp/messagebus/test/example/client/client.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/messagebus/test/example/common/proto.h> +#include <library/cpp/messagebus/test/example/common/proto.h> #include <util/random/random.h> diff --git a/library/cpp/messagebus/test/example/client/ya.make b/library/cpp/messagebus/test/example/client/ya.make index 05c3d6ca5f..a660a01698 100644 --- a/library/cpp/messagebus/test/example/client/ya.make +++ b/library/cpp/messagebus/test/example/client/ya.make @@ -3,7 +3,7 @@ PROGRAM(messagebus_example_client) OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus/test/example/common + library/cpp/messagebus/test/example/common ) SRCS( diff --git a/library/cpp/messagebus/test/example/common/proto.h b/library/cpp/messagebus/test/example/common/proto.h index 8716869e30..a151aac468 100644 --- a/library/cpp/messagebus/test/example/common/proto.h +++ b/library/cpp/messagebus/test/example/common/proto.h @@ -1,9 +1,9 @@ #pragma once -#include <library/cpp/messagebus/test/example/common/messages.pb.h> +#include <library/cpp/messagebus/test/example/common/messages.pb.h> -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/protobuf/ybusbuf.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/protobuf/ybusbuf.h> namespace NCalculator { typedef ::NBus::TBusBufferMessage<TRequestSumRecord, 1> TRequestSum; diff --git a/library/cpp/messagebus/test/example/common/ya.make b/library/cpp/messagebus/test/example/common/ya.make index c4f09a5470..4da16608fc 100644 --- a/library/cpp/messagebus/test/example/common/ya.make +++ b/library/cpp/messagebus/test/example/common/ya.make @@ -3,8 +3,8 @@ LIBRARY(messagebus_test_example_common) OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus - library/cpp/messagebus/protobuf + library/cpp/messagebus + library/cpp/messagebus/protobuf ) SRCS( diff --git a/library/cpp/messagebus/test/example/server/server.cpp b/library/cpp/messagebus/test/example/server/server.cpp index 8bbf2a2605..13e52d75f5 100644 --- a/library/cpp/messagebus/test/example/server/server.cpp +++ b/library/cpp/messagebus/test/example/server/server.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/messagebus/test/example/common/proto.h> +#include <library/cpp/messagebus/test/example/common/proto.h> using namespace NBus; using namespace NCalculator; diff --git a/library/cpp/messagebus/test/example/server/ya.make b/library/cpp/messagebus/test/example/server/ya.make index c5e96c9191..8cdd97cb12 100644 --- a/library/cpp/messagebus/test/example/server/ya.make +++ b/library/cpp/messagebus/test/example/server/ya.make @@ -3,7 +3,7 @@ PROGRAM(messagebus_example_server) OWNER(g:messagebus) PEERDIR( - library/cpp/messagebus/test/example/common + library/cpp/messagebus/test/example/common ) SRCS( diff --git a/library/cpp/messagebus/test/helper/example.h b/library/cpp/messagebus/test/helper/example.h index 402b39e652..26b7475308 100644 --- a/library/cpp/messagebus/test/helper/example.h +++ b/library/cpp/messagebus/test/helper/example.h @@ -5,8 +5,8 @@ #include "alloc_counter.h" #include "message_handler_error.h" -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/misc/test_sync.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/test/helper/example_module.h b/library/cpp/messagebus/test/helper/example_module.h index 6389224028..a0b295f613 100644 --- a/library/cpp/messagebus/test/helper/example_module.h +++ b/library/cpp/messagebus/test/helper/example_module.h @@ -2,7 +2,7 @@ #include "example.h" -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/oldmodule/module.h> namespace NBus { namespace NTest { diff --git a/library/cpp/messagebus/test/helper/hanging_server.h b/library/cpp/messagebus/test/helper/hanging_server.h index 1816198fe9..cc9fb274d8 100644 --- a/library/cpp/messagebus/test/helper/hanging_server.h +++ b/library/cpp/messagebus/test/helper/hanging_server.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/network.h> +#include <library/cpp/messagebus/network.h> #include <util/network/sock.h> diff --git a/library/cpp/messagebus/test/helper/message_handler_error.h b/library/cpp/messagebus/test/helper/message_handler_error.h index 1cfbd18d70..a314b10761 100644 --- a/library/cpp/messagebus/test/helper/message_handler_error.h +++ b/library/cpp/messagebus/test/helper/message_handler_error.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> namespace NBus { namespace NTest { diff --git a/library/cpp/messagebus/test/helper/object_count_check.h b/library/cpp/messagebus/test/helper/object_count_check.h index edcfe6c312..1c4756e58c 100644 --- a/library/cpp/messagebus/test/helper/object_count_check.h +++ b/library/cpp/messagebus/test/helper/object_count_check.h @@ -2,13 +2,13 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/remote_client_connection.h> -#include <library/cpp/messagebus/remote_client_session.h> -#include <library/cpp/messagebus/remote_server_connection.h> -#include <library/cpp/messagebus/remote_server_session.h> -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/oldmodule/module.h> -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/remote_client_connection.h> +#include <library/cpp/messagebus/remote_client_session.h> +#include <library/cpp/messagebus/remote_server_connection.h> +#include <library/cpp/messagebus/remote_server_session.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> #include <util/generic/object_counter.h> #include <util/system/type_name.h> diff --git a/library/cpp/messagebus/test/helper/ya.make b/library/cpp/messagebus/test/helper/ya.make index 567b6ded15..97bd45f573 100644 --- a/library/cpp/messagebus/test/helper/ya.make +++ b/library/cpp/messagebus/test/helper/ya.make @@ -11,7 +11,7 @@ SRCS( ) PEERDIR( - library/cpp/messagebus/oldmodule + library/cpp/messagebus/oldmodule ) END() diff --git a/library/cpp/messagebus/test/perftest/perftest.cpp b/library/cpp/messagebus/test/perftest/perftest.cpp index d09d745496..8489319278 100644 --- a/library/cpp/messagebus/test/perftest/perftest.cpp +++ b/library/cpp/messagebus/test/perftest/perftest.cpp @@ -1,19 +1,19 @@ #include "simple_proto.h" -#include <library/cpp/messagebus/test/perftest/messages.pb.h> +#include <library/cpp/messagebus/test/perftest/messages.pb.h> -#include <library/cpp/messagebus/text_utils.h> -#include <library/cpp/messagebus/thread_extra.h> -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/oldmodule/module.h> -#include <library/cpp/messagebus/protobuf/ybusbuf.h> -#include <library/cpp/messagebus/www/www.h> +#include <library/cpp/messagebus/text_utils.h> +#include <library/cpp/messagebus/thread_extra.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/protobuf/ybusbuf.h> +#include <library/cpp/messagebus/www/www.h> -#include <library/cpp/deprecated/threadable/threadable.h> -#include <library/cpp/execprofile/profile.h> +#include <library/cpp/deprecated/threadable/threadable.h> +#include <library/cpp/execprofile/profile.h> #include <library/cpp/getopt/opt.h> -#include <library/cpp/lwtrace/start.h> -#include <library/cpp/sighandler/async_signals_handler.h> +#include <library/cpp/lwtrace/start.h> +#include <library/cpp/sighandler/async_signals_handler.h> #include <library/cpp/threading/future/legacy_future.h> #include <util/generic/ptr.h> diff --git a/library/cpp/messagebus/test/perftest/simple_proto.h b/library/cpp/messagebus/test/perftest/simple_proto.h index fc958061b7..4a0cc08db3 100644 --- a/library/cpp/messagebus/test/perftest/simple_proto.h +++ b/library/cpp/messagebus/test/perftest/simple_proto.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/ybus.h> struct TSimpleMessage: public NBus::TBusMessage { ui32 Payload; diff --git a/library/cpp/messagebus/test/perftest/stackcollect.diff b/library/cpp/messagebus/test/perftest/stackcollect.diff index 0d1de3e973..658f0141b3 100644 --- a/library/cpp/messagebus/test/perftest/stackcollect.diff +++ b/library/cpp/messagebus/test/perftest/stackcollect.diff @@ -6,8 +6,8 @@ Index: test/perftest/CMakeLists.txt OWNER(nga) PEERDIR( -- library/cpp/execprofile +- library/cpp/execprofile + junk/davenger/stackcollect - library/cpp/messagebus - library/cpp/messagebus/protobuf - library/cpp/sighandler + library/cpp/messagebus + library/cpp/messagebus/protobuf + library/cpp/sighandler diff --git a/library/cpp/messagebus/test/perftest/ya.make b/library/cpp/messagebus/test/perftest/ya.make index 929d4cf685..24c2848ed5 100644 --- a/library/cpp/messagebus/test/perftest/ya.make +++ b/library/cpp/messagebus/test/perftest/ya.make @@ -3,15 +3,15 @@ PROGRAM(messagebus_perftest) OWNER(g:messagebus) PEERDIR( - library/cpp/deprecated/threadable - library/cpp/execprofile + library/cpp/deprecated/threadable + library/cpp/execprofile library/cpp/getopt - library/cpp/lwtrace - library/cpp/messagebus - library/cpp/messagebus/oldmodule - library/cpp/messagebus/protobuf - library/cpp/messagebus/www - library/cpp/sighandler + library/cpp/lwtrace + library/cpp/messagebus + library/cpp/messagebus/oldmodule + library/cpp/messagebus/protobuf + library/cpp/messagebus/www + library/cpp/sighandler library/cpp/threading/future ) diff --git a/library/cpp/messagebus/test/ut/locator_uniq_ut.cpp b/library/cpp/messagebus/test/ut/locator_uniq_ut.cpp index e282b457eb..3fdd175d73 100644 --- a/library/cpp/messagebus/test/ut/locator_uniq_ut.cpp +++ b/library/cpp/messagebus/test/ut/locator_uniq_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/test_utils.h> -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/test_utils.h> +#include <library/cpp/messagebus/ybus.h> class TLocatorRegisterUniqTest: public TTestBase { UNIT_TEST_SUITE(TLocatorRegisterUniqTest); diff --git a/library/cpp/messagebus/test/ut/messagebus_ut.cpp b/library/cpp/messagebus/test/ut/messagebus_ut.cpp index 980d2adc6c..040f9b7702 100644 --- a/library/cpp/messagebus/test/ut/messagebus_ut.cpp +++ b/library/cpp/messagebus/test/ut/messagebus_ut.cpp @@ -1,12 +1,12 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/fixed_port.h> -#include <library/cpp/messagebus/test/helper/hanging_server.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> -#include <library/cpp/messagebus/test/helper/wait_for.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/fixed_port.h> +#include <library/cpp/messagebus/test/helper/hanging_server.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/wait_for.h> -#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/misc/test_sync.h> #include <util/network/sock.h> diff --git a/library/cpp/messagebus/test/ut/module_client_one_way_ut.cpp b/library/cpp/messagebus/test/ut/module_client_one_way_ut.cpp index 23e7d41434..4083cf3b7b 100644 --- a/library/cpp/messagebus/test/ut/module_client_one_way_ut.cpp +++ b/library/cpp/messagebus/test/ut/module_client_one_way_ut.cpp @@ -1,10 +1,10 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/message_handler_error.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/message_handler_error.h> -#include <library/cpp/messagebus/misc/test_sync.h> -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/oldmodule/module.h> using namespace NBus; using namespace NBus::NTest; diff --git a/library/cpp/messagebus/test/ut/module_client_ut.cpp b/library/cpp/messagebus/test/ut/module_client_ut.cpp index 0c2b78c27e..ebfe185cc6 100644 --- a/library/cpp/messagebus/test/ut/module_client_ut.cpp +++ b/library/cpp/messagebus/test/ut/module_client_ut.cpp @@ -3,13 +3,13 @@ #include "count_down_latch.h" #include "moduletest.h" -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/example_module.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> -#include <library/cpp/messagebus/test/helper/wait_for.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/example_module.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/wait_for.h> -#include <library/cpp/messagebus/misc/test_sync.h> -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/misc/test_sync.h> +#include <library/cpp/messagebus/oldmodule/module.h> #include <util/generic/cast.h> #include <util/system/event.h> diff --git a/library/cpp/messagebus/test/ut/module_server_ut.cpp b/library/cpp/messagebus/test/ut/module_server_ut.cpp index 02e7e273a6..88fe1dd9b6 100644 --- a/library/cpp/messagebus/test/ut/module_server_ut.cpp +++ b/library/cpp/messagebus/test/ut/module_server_ut.cpp @@ -3,12 +3,12 @@ #include "count_down_latch.h" #include "moduletest.h" -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/example_module.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> -#include <library/cpp/messagebus/test/helper/wait_for.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/example_module.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/wait_for.h> -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/oldmodule/module.h> #include <util/generic/cast.h> diff --git a/library/cpp/messagebus/test/ut/moduletest.h b/library/cpp/messagebus/test/ut/moduletest.h index 192032e2f4..d5da72c0cb 100644 --- a/library/cpp/messagebus/test/ut/moduletest.h +++ b/library/cpp/messagebus/test/ut/moduletest.h @@ -4,12 +4,12 @@ /// \file /// \brief Example of using local session for communication. -#include <library/cpp/messagebus/test/helper/alloc_counter.h> -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/message_handler_error.h> +#include <library/cpp/messagebus/test/helper/alloc_counter.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/message_handler_error.h> -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/oldmodule/module.h> namespace NBus { namespace NTest { diff --git a/library/cpp/messagebus/test/ut/one_way_ut.cpp b/library/cpp/messagebus/test/ut/one_way_ut.cpp index a9b7e848b5..9c21227e2b 100644 --- a/library/cpp/messagebus/test/ut/one_way_ut.cpp +++ b/library/cpp/messagebus/test/ut/one_way_ut.cpp @@ -24,14 +24,14 @@ /// See example in NBus::NullServer::OnMessage(). /// Discard identity for reply message. -#include <library/cpp/messagebus/test/helper/alloc_counter.h> -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/hanging_server.h> -#include <library/cpp/messagebus/test/helper/message_handler_error.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> -#include <library/cpp/messagebus/test/helper/wait_for.h> - -#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/test/helper/alloc_counter.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/hanging_server.h> +#include <library/cpp/messagebus/test/helper/message_handler_error.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/wait_for.h> + +#include <library/cpp/messagebus/ybus.h> using namespace std; using namespace NBus; diff --git a/library/cpp/messagebus/test/ut/starter_ut.cpp b/library/cpp/messagebus/test/ut/starter_ut.cpp index 647f959d1e..dd4d3aaa5e 100644 --- a/library/cpp/messagebus/test/ut/starter_ut.cpp +++ b/library/cpp/messagebus/test/ut/starter_ut.cpp @@ -1,8 +1,8 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/messagebus/test/helper/example_module.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> -#include <library/cpp/messagebus/test/helper/wait_for.h> +#include <library/cpp/messagebus/test/helper/example_module.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/wait_for.h> using namespace NBus; using namespace NBus::NTest; diff --git a/library/cpp/messagebus/test/ut/sync_client_ut.cpp b/library/cpp/messagebus/test/ut/sync_client_ut.cpp index fc66955b1f..400128193f 100644 --- a/library/cpp/messagebus/test/ut/sync_client_ut.cpp +++ b/library/cpp/messagebus/test/ut/sync_client_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/messagebus/test/helper/example.h> -#include <library/cpp/messagebus/test/helper/object_count_check.h> +#include <library/cpp/messagebus/test/helper/example.h> +#include <library/cpp/messagebus/test/helper/object_count_check.h> namespace NBus { namespace NTest { diff --git a/library/cpp/messagebus/test/ut/ya.make b/library/cpp/messagebus/test/ut/ya.make index 99e40a0924..fe1b4961d6 100644 --- a/library/cpp/messagebus/test/ut/ya.make +++ b/library/cpp/messagebus/test/ut/ya.make @@ -1,6 +1,6 @@ OWNER(g:messagebus) -UNITTEST_FOR(library/cpp/messagebus) +UNITTEST_FOR(library/cpp/messagebus) TIMEOUT(1200) @@ -15,9 +15,9 @@ FORK_SUBTESTS() PEERDIR( library/cpp/testing/unittest_main - library/cpp/messagebus - library/cpp/messagebus/test/helper - library/cpp/messagebus/www + library/cpp/messagebus + library/cpp/messagebus/test/helper + library/cpp/messagebus/www ) SRCS( diff --git a/library/cpp/messagebus/thread_extra.h b/library/cpp/messagebus/thread_extra.h index dc78121752..2c79741e88 100644 --- a/library/cpp/messagebus/thread_extra.h +++ b/library/cpp/messagebus/thread_extra.h @@ -1,3 +1,3 @@ #pragma once -#include <library/cpp/messagebus/actor/thread_extra.h> +#include <library/cpp/messagebus/actor/thread_extra.h> diff --git a/library/cpp/messagebus/www/html_output.h b/library/cpp/messagebus/www/html_output.h index f8563102b1..27e77adefa 100644 --- a/library/cpp/messagebus/www/html_output.h +++ b/library/cpp/messagebus/www/html_output.h @@ -4,7 +4,7 @@ #include <util/generic/string.h> #include <util/stream/output.h> -#include <library/cpp/html/pcdata/pcdata.h> +#include <library/cpp/html/pcdata/pcdata.h> #include <util/system/tls.h> extern Y_POD_THREAD(IOutputStream*) HtmlOutputStreamPtr; diff --git a/library/cpp/messagebus/www/www.cpp b/library/cpp/messagebus/www/www.cpp index c86751f2a7..62ec241d85 100644 --- a/library/cpp/messagebus/www/www.cpp +++ b/library/cpp/messagebus/www/www.cpp @@ -3,15 +3,15 @@ #include "concat_strings.h" #include "html_output.h" -#include <library/cpp/messagebus/remote_connection_status.h> +#include <library/cpp/messagebus/remote_connection_status.h> #include <library/cpp/monlib/deprecated/json/writer.h> -#include <library/cpp/archive/yarchive.h> -#include <library/cpp/http/fetch/httpfsm.h> -#include <library/cpp/http/fetch/httpheader.h> -#include <library/cpp/http/server/http.h> -#include <library/cpp/json/writer/json.h> -#include <library/cpp/uri/http_url.h> +#include <library/cpp/archive/yarchive.h> +#include <library/cpp/http/fetch/httpfsm.h> +#include <library/cpp/http/fetch/httpheader.h> +#include <library/cpp/http/server/http.h> +#include <library/cpp/json/writer/json.h> +#include <library/cpp/uri/http_url.h> #include <util/string/cast.h> #include <util/string/printf.h> diff --git a/library/cpp/messagebus/www/www.h b/library/cpp/messagebus/www/www.h index 0e624786e4..6cd652b477 100644 --- a/library/cpp/messagebus/www/www.h +++ b/library/cpp/messagebus/www/www.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/oldmodule/module.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/oldmodule/module.h> #include <util/generic/ptr.h> #include <util/generic/string.h> diff --git a/library/cpp/messagebus/www/ya.make b/library/cpp/messagebus/www/ya.make index 9057ece4d8..972390cea3 100644 --- a/library/cpp/messagebus/www/ya.make +++ b/library/cpp/messagebus/www/ya.make @@ -14,16 +14,16 @@ ARCHIVE( ) PEERDIR( - library/cpp/archive + library/cpp/archive library/cpp/cgiparam - library/cpp/html/pcdata - library/cpp/http/fetch - library/cpp/http/server - library/cpp/json/writer - library/cpp/messagebus - library/cpp/messagebus/oldmodule + library/cpp/html/pcdata + library/cpp/http/fetch + library/cpp/http/server + library/cpp/json/writer + library/cpp/messagebus + library/cpp/messagebus/oldmodule library/cpp/monlib/deprecated/json - library/cpp/uri + library/cpp/uri ) END() diff --git a/library/cpp/messagebus/ya.make b/library/cpp/messagebus/ya.make index 9dd5e77297..e13cf06dea 100644 --- a/library/cpp/messagebus/ya.make +++ b/library/cpp/messagebus/ya.make @@ -53,14 +53,14 @@ SRCS( PEERDIR( contrib/libs/sparsehash - library/cpp/codecs - library/cpp/deprecated/enum_codegen + library/cpp/codecs + library/cpp/deprecated/enum_codegen library/cpp/getopt/small - library/cpp/lwtrace - library/cpp/messagebus/actor - library/cpp/messagebus/config - library/cpp/messagebus/monitoring - library/cpp/messagebus/scheduler + library/cpp/lwtrace + library/cpp/messagebus/actor + library/cpp/messagebus/config + library/cpp/messagebus/monitoring + library/cpp/messagebus/scheduler library/cpp/string_utils/indent_text library/cpp/threading/future ) diff --git a/library/cpp/messagebus/ybus.h b/library/cpp/messagebus/ybus.h index 810a0ec916..de21ad8521 100644 --- a/library/cpp/messagebus/ybus.h +++ b/library/cpp/messagebus/ybus.h @@ -18,10 +18,10 @@ #include "session_config.h" #include "socket_addr.h" -#include <library/cpp/messagebus/actor/executor.h> -#include <library/cpp/messagebus/scheduler/scheduler.h> +#include <library/cpp/messagebus/actor/executor.h> +#include <library/cpp/messagebus/scheduler/scheduler.h> -#include <library/cpp/codecs/codecs.h> +#include <library/cpp/codecs/codecs.h> #include <util/generic/array_ref.h> #include <util/generic/buffer.h> diff --git a/library/cpp/monlib/counters/histogram.h b/library/cpp/monlib/counters/histogram.h index f33aae885f..96361b0023 100644 --- a/library/cpp/monlib/counters/histogram.h +++ b/library/cpp/monlib/counters/histogram.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/histogram/hdr/histogram.h> +#include <library/cpp/histogram/hdr/histogram.h> #include <util/system/spinlock.h> #include <util/stream/output.h> diff --git a/library/cpp/monlib/counters/ya.make b/library/cpp/monlib/counters/ya.make index cbaa349912..aa1a671bf8 100644 --- a/library/cpp/monlib/counters/ya.make +++ b/library/cpp/monlib/counters/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/histogram/hdr + library/cpp/histogram/hdr ) END() diff --git a/library/cpp/monlib/deprecated/json/writer.h b/library/cpp/monlib/deprecated/json/writer.h index b365d30e59..183288143c 100644 --- a/library/cpp/monlib/deprecated/json/writer.h +++ b/library/cpp/monlib/deprecated/json/writer.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_writer.h> namespace NMonitoring { /** diff --git a/library/cpp/monlib/deprecated/json/ya.make b/library/cpp/monlib/deprecated/json/ya.make index 41c65c9cd0..0ca903ee62 100644 --- a/library/cpp/monlib/deprecated/json/ya.make +++ b/library/cpp/monlib/deprecated/json/ya.make @@ -18,7 +18,7 @@ SRCS( ) PEERDIR( - library/cpp/json + library/cpp/json ) END() diff --git a/library/cpp/monlib/encode/json/json_decoder.cpp b/library/cpp/monlib/encode/json/json_decoder.cpp index d7156fc8a9..d44ff5fd28 100644 --- a/library/cpp/monlib/encode/json/json_decoder.cpp +++ b/library/cpp/monlib/encode/json/json_decoder.cpp @@ -6,7 +6,7 @@ #include <library/cpp/monlib/metrics/labels.h> #include <library/cpp/monlib/metrics/metric_value.h> -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/datetime/base.h> #include <util/string/cast.h> diff --git a/library/cpp/monlib/encode/json/json_encoder.cpp b/library/cpp/monlib/encode/json/json_encoder.cpp index 940535c98a..20d2bb6283 100644 --- a/library/cpp/monlib/encode/json/json_encoder.cpp +++ b/library/cpp/monlib/encode/json/json_encoder.cpp @@ -7,7 +7,7 @@ #include <library/cpp/monlib/metrics/metric_value.h> #include <library/cpp/monlib/metrics/labels.h> -#include <library/cpp/json/writer/json.h> +#include <library/cpp/json/writer/json.h> #include <util/charset/utf8.h> #include <util/generic/algorithm.h> diff --git a/library/cpp/monlib/encode/json/json_ut.cpp b/library/cpp/monlib/encode/json/json_ut.cpp index d997d35f4e..09e7909289 100644 --- a/library/cpp/monlib/encode/json/json_ut.cpp +++ b/library/cpp/monlib/encode/json/json_ut.cpp @@ -3,8 +3,8 @@ #include <library/cpp/monlib/encode/protobuf/protobuf.h> #include <library/cpp/monlib/metrics/labels.h> -#include <library/cpp/json/json_reader.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/resource/resource.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/str.h> diff --git a/library/cpp/monlib/encode/json/ut/ya.make b/library/cpp/monlib/encode/json/ut/ya.make index 1aee416309..e50c4f4903 100644 --- a/library/cpp/monlib/encode/json/ut/ya.make +++ b/library/cpp/monlib/encode/json/ut/ya.make @@ -37,10 +37,10 @@ RESOURCE( ) PEERDIR( - library/cpp/json + library/cpp/json library/cpp/monlib/consumers library/cpp/monlib/encode/protobuf - library/cpp/resource + library/cpp/resource ) END() diff --git a/library/cpp/monlib/encode/json/ya.make b/library/cpp/monlib/encode/json/ya.make index 1df63238e3..a50fc412a9 100644 --- a/library/cpp/monlib/encode/json/ya.make +++ b/library/cpp/monlib/encode/json/ya.make @@ -14,8 +14,8 @@ PEERDIR( library/cpp/monlib/encode library/cpp/monlib/encode/buffered library/cpp/monlib/exception - library/cpp/json - library/cpp/json/writer + library/cpp/json + library/cpp/json/writer ) END() diff --git a/library/cpp/monlib/encode/unistat/unistat_decoder.cpp b/library/cpp/monlib/encode/unistat/unistat_decoder.cpp index 2198be0cd7..b2344b0905 100644 --- a/library/cpp/monlib/encode/unistat/unistat_decoder.cpp +++ b/library/cpp/monlib/encode/unistat/unistat_decoder.cpp @@ -6,7 +6,7 @@ #include <library/cpp/monlib/metrics/metric_value.h> #include <library/cpp/monlib/metrics/metric_consumer.h> -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/datetime/base.h> #include <util/string/split.h> diff --git a/library/cpp/monlib/encode/unistat/ya.make b/library/cpp/monlib/encode/unistat/ya.make index 3e7d887b1e..4ac2edadf4 100644 --- a/library/cpp/monlib/encode/unistat/ya.make +++ b/library/cpp/monlib/encode/unistat/ya.make @@ -7,7 +7,7 @@ OWNER( PEERDIR( contrib/libs/re2 - library/cpp/json + library/cpp/json library/cpp/monlib/metrics ) diff --git a/library/cpp/monlib/messagebus/mon_messagebus.cpp b/library/cpp/monlib/messagebus/mon_messagebus.cpp index c24a7e1d40..355b4386cd 100644 --- a/library/cpp/monlib/messagebus/mon_messagebus.cpp +++ b/library/cpp/monlib/messagebus/mon_messagebus.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/messagebus/www/www.h> +#include <library/cpp/messagebus/www/www.h> #include "mon_messagebus.h" diff --git a/library/cpp/monlib/messagebus/mon_messagebus.h b/library/cpp/monlib/messagebus/mon_messagebus.h index 65b59cfb01..e1fa73c69f 100644 --- a/library/cpp/monlib/messagebus/mon_messagebus.h +++ b/library/cpp/monlib/messagebus/mon_messagebus.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/messagebus/ybus.h> -#include <library/cpp/messagebus/www/www.h> +#include <library/cpp/messagebus/ybus.h> +#include <library/cpp/messagebus/www/www.h> #include <library/cpp/monlib/service/pages/mon_page.h> diff --git a/library/cpp/monlib/messagebus/ya.make b/library/cpp/monlib/messagebus/ya.make index bd68afd8d0..a0b5362296 100644 --- a/library/cpp/monlib/messagebus/ya.make +++ b/library/cpp/monlib/messagebus/ya.make @@ -8,8 +8,8 @@ SRCS( ) PEERDIR( - library/cpp/messagebus - library/cpp/messagebus/www + library/cpp/messagebus + library/cpp/messagebus/www library/cpp/monlib/dynamic_counters ) diff --git a/library/cpp/monlib/metrics/metric_registry_ut.cpp b/library/cpp/monlib/metrics/metric_registry_ut.cpp index 95e9c028d4..86d9a52ec0 100644 --- a/library/cpp/monlib/metrics/metric_registry_ut.cpp +++ b/library/cpp/monlib/metrics/metric_registry_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/monlib/encode/protobuf/protobuf.h> #include <library/cpp/monlib/encode/json/json.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/monlib/metrics/ut/ya.make b/library/cpp/monlib/metrics/ut/ya.make index fe622cd1e7..aec9974fbd 100644 --- a/library/cpp/monlib/metrics/ut/ya.make +++ b/library/cpp/monlib/metrics/ut/ya.make @@ -23,7 +23,7 @@ RESOURCE( ) PEERDIR( - library/cpp/resource + library/cpp/resource library/cpp/monlib/encode/protobuf library/cpp/monlib/encode/json library/cpp/threading/future diff --git a/library/cpp/monlib/service/monservice.cpp b/library/cpp/monlib/service/monservice.cpp index e8d29f1ac0..d1b9cda1d2 100644 --- a/library/cpp/monlib/service/monservice.cpp +++ b/library/cpp/monlib/service/monservice.cpp @@ -1,8 +1,8 @@ #include "monservice.h" -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/malloc/api/malloc.h> #include <library/cpp/string_utils/base64/base64.h> -#include <library/cpp/svnversion/svnversion.h> +#include <library/cpp/svnversion/svnversion.h> #include <util/generic/map.h> #include <util/generic/ptr.h> diff --git a/library/cpp/monlib/service/pages/resource_mon_page.h b/library/cpp/monlib/service/pages/resource_mon_page.h index 0b32f20deb..f6ab67200e 100644 --- a/library/cpp/monlib/service/pages/resource_mon_page.h +++ b/library/cpp/monlib/service/pages/resource_mon_page.h @@ -2,7 +2,7 @@ #include "mon_page.h" -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> namespace NMonitoring { struct TResourceMonPage: public IMonPage { diff --git a/library/cpp/monlib/service/pages/version_mon_page.cpp b/library/cpp/monlib/service/pages/version_mon_page.cpp index 85d8ba87d7..41e29417da 100644 --- a/library/cpp/monlib/service/pages/version_mon_page.cpp +++ b/library/cpp/monlib/service/pages/version_mon_page.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/svnversion/svnversion.h> -#include <library/cpp/build_info/build_info.h> -#include <library/cpp/malloc/api/malloc.h> +#include <library/cpp/svnversion/svnversion.h> +#include <library/cpp/build_info/build_info.h> +#include <library/cpp/malloc/api/malloc.h> #include "version_mon_page.h" diff --git a/library/cpp/monlib/service/pages/ya.make b/library/cpp/monlib/service/pages/ya.make index 8b11f9e698..48d44a0838 100644 --- a/library/cpp/monlib/service/pages/ya.make +++ b/library/cpp/monlib/service/pages/ya.make @@ -17,10 +17,10 @@ SRCS( ) PEERDIR( - library/cpp/build_info - library/cpp/malloc/api - library/cpp/svnversion - library/cpp/resource + library/cpp/build_info + library/cpp/malloc/api + library/cpp/svnversion + library/cpp/resource library/cpp/monlib/service library/cpp/monlib/encode/json library/cpp/monlib/encode/text diff --git a/library/cpp/monlib/service/service.cpp b/library/cpp/monlib/service/service.cpp index 3d257646af..929efbf816 100644 --- a/library/cpp/monlib/service/service.cpp +++ b/library/cpp/monlib/service/service.cpp @@ -1,10 +1,10 @@ #include "service.h" -#include <library/cpp/coroutine/engine/sockpool.h> -#include <library/cpp/http/io/stream.h> -#include <library/cpp/http/fetch/httpheader.h> -#include <library/cpp/http/fetch/httpfsm.h> -#include <library/cpp/uri/http_url.h> +#include <library/cpp/coroutine/engine/sockpool.h> +#include <library/cpp/http/io/stream.h> +#include <library/cpp/http/fetch/httpheader.h> +#include <library/cpp/http/fetch/httpfsm.h> +#include <library/cpp/uri/http_url.h> #include <util/generic/buffer.h> #include <util/stream/str.h> diff --git a/library/cpp/monlib/service/service.h b/library/cpp/monlib/service/service.h index 955bb714f8..2f66dddaf8 100644 --- a/library/cpp/monlib/service/service.h +++ b/library/cpp/monlib/service/service.h @@ -1,10 +1,10 @@ #pragma once -#include <library/cpp/coroutine/engine/impl.h> -#include <library/cpp/coroutine/listener/listen.h> -#include <library/cpp/http/fetch/httpheader.h> -#include <library/cpp/http/server/http.h> -#include <library/cpp/logger/all.h> +#include <library/cpp/coroutine/engine/impl.h> +#include <library/cpp/coroutine/listener/listen.h> +#include <library/cpp/http/fetch/httpheader.h> +#include <library/cpp/http/server/http.h> +#include <library/cpp/logger/all.h> #include <util/network/ip.h> #include <library/cpp/cgiparam/cgiparam.h> diff --git a/library/cpp/monlib/service/ya.make b/library/cpp/monlib/service/ya.make index 314eae87a6..ad088fc2c6 100644 --- a/library/cpp/monlib/service/ya.make +++ b/library/cpp/monlib/service/ya.make @@ -13,15 +13,15 @@ SRCS( PEERDIR( library/cpp/string_utils/base64 contrib/libs/protobuf - library/cpp/coroutine/engine - library/cpp/coroutine/listener - library/cpp/http/fetch - library/cpp/http/server - library/cpp/http/io - library/cpp/logger - library/cpp/malloc/api - library/cpp/svnversion - library/cpp/uri + library/cpp/coroutine/engine + library/cpp/coroutine/listener + library/cpp/http/fetch + library/cpp/http/server + library/cpp/http/io + library/cpp/logger + library/cpp/malloc/api + library/cpp/svnversion + library/cpp/uri library/cpp/cgiparam ) diff --git a/library/cpp/object_factory/object_factory_ut.cpp b/library/cpp/object_factory/object_factory_ut.cpp index 00dbce15e6..06fb0739ff 100644 --- a/library/cpp/object_factory/object_factory_ut.cpp +++ b/library/cpp/object_factory/object_factory_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/object_factory/object_factory.h> +#include <library/cpp/object_factory/object_factory.h> #include <library/cpp/testing/unittest/registar.h> #include <util/generic/noncopyable.h> diff --git a/library/cpp/object_factory/ut/ya.make b/library/cpp/object_factory/ut/ya.make index 287b5ec523..5a870072fc 100644 --- a/library/cpp/object_factory/ut/ya.make +++ b/library/cpp/object_factory/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(svshevtsov) PEERDIR( - ADDINCL library/cpp/object_factory + ADDINCL library/cpp/object_factory ) -SRCDIR(library/cpp/object_factory) +SRCDIR(library/cpp/object_factory) SRCS( object_factory_ut.cpp diff --git a/library/cpp/on_disk/chunks/ut/ya.make b/library/cpp/on_disk/chunks/ut/ya.make index 8529478d77..0190905cbe 100644 --- a/library/cpp/on_disk/chunks/ut/ya.make +++ b/library/cpp/on_disk/chunks/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/on_disk/chunks) +UNITTEST_FOR(library/cpp/on_disk/chunks) OWNER(g:util) diff --git a/library/cpp/on_disk/ya.make b/library/cpp/on_disk/ya.make index a8c7366fe8..42a79d37bd 100644 --- a/library/cpp/on_disk/ya.make +++ b/library/cpp/on_disk/ya.make @@ -1,31 +1,31 @@ RECURSE( - 2d_array - 2d_array/ut - 4d_array - 4d_array/ut - aho_corasick - aho_corasick/tool - aho_corasick/ut - chunks - chunks/ut - codec_trie - codec_trie/ut - coded_blob - coded_blob/common - coded_blob/keys - coded_blob/ut + 2d_array + 2d_array/ut + 4d_array + 4d_array/ut + aho_corasick + aho_corasick/tool + aho_corasick/ut + chunks + chunks/ut + codec_trie + codec_trie/ut + coded_blob + coded_blob/common + coded_blob/keys + coded_blob/ut file_with_header file_with_header/ut - fried_trie - head_ar - head_ar/ut - meta_trie - meta_trie/ut - mms - mms/ut - multi_blob + fried_trie + head_ar + head_ar/ut + meta_trie + meta_trie/ut + mms + mms/ut + multi_blob tar_archive tar_archive/ut - st_hash - st_hash/ut + st_hash + st_hash/ut ) diff --git a/library/cpp/openssl/holders/bio.h b/library/cpp/openssl/holders/bio.h index f1d8df6ed7..bcd6a7a9d6 100644 --- a/library/cpp/openssl/holders/bio.h +++ b/library/cpp/openssl/holders/bio.h @@ -2,7 +2,7 @@ #include <contrib/libs/openssl/include/openssl/bio.h> -#include <library/cpp/openssl/holders/holder.h> +#include <library/cpp/openssl/holders/holder.h> namespace NOpenSSL { diff --git a/library/cpp/openssl/holders/ut/ya.make b/library/cpp/openssl/holders/ut/ya.make index c303d63c6c..045cdc3566 100644 --- a/library/cpp/openssl/holders/ut/ya.make +++ b/library/cpp/openssl/holders/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/openssl/holders) +UNITTEST_FOR(library/cpp/openssl/holders) OWNER(somov deshevoy) diff --git a/library/cpp/openssl/holders/x509_vfy.h b/library/cpp/openssl/holders/x509_vfy.h index 6d472ae93d..b735d8a042 100644 --- a/library/cpp/openssl/holders/x509_vfy.h +++ b/library/cpp/openssl/holders/x509_vfy.h @@ -2,7 +2,7 @@ #include <contrib/libs/openssl/include/openssl/x509_vfy.h> -#include <library/cpp/openssl/holders/holder.h> +#include <library/cpp/openssl/holders/holder.h> namespace NOpenSSL { diff --git a/library/cpp/openssl/io/stream.cpp b/library/cpp/openssl/io/stream.cpp index 65a326c27f..0b4be38c0e 100644 --- a/library/cpp/openssl/io/stream.cpp +++ b/library/cpp/openssl/io/stream.cpp @@ -1,18 +1,18 @@ #include "stream.h" -#include <util/generic/deque.h> +#include <util/generic/deque.h> #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <library/cpp/openssl/init/init.h> -#include <library/cpp/openssl/method/io.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/openssl/init/init.h> +#include <library/cpp/openssl/method/io.h> +#include <library/cpp/resource/resource.h> #include <openssl/bio.h> #include <openssl/ssl.h> #include <openssl/err.h> -#include <openssl/tls1.h> -#include <openssl/x509v3.h> +#include <openssl/tls1.h> +#include <openssl/x509v3.h> using TOptions = TOpenSslClientIO::TOptions; @@ -55,19 +55,19 @@ namespace { static inline void Destroy(bio_st* bio) noexcept { BIO_free(bio); } - - static inline void Destroy(x509_st* x509) noexcept { - X509_free(x509); - } + + static inline void Destroy(x509_st* x509) noexcept { + X509_free(x509); + } }; template <class T> - using TSslHolderPtr = THolder<T, TSslDestroy>; + using TSslHolderPtr = THolder<T, TSslDestroy>; - using TSslContextPtr = TSslHolderPtr<ssl_ctx_st>; - using TSslPtr = TSslHolderPtr<ssl_st>; - using TBioPtr = TSslHolderPtr<bio_st>; - using TX509Ptr = TSslHolderPtr<x509_st>; + using TSslContextPtr = TSslHolderPtr<ssl_ctx_st>; + using TSslPtr = TSslHolderPtr<ssl_st>; + using TBioPtr = TSslHolderPtr<bio_st>; + using TX509Ptr = TSslHolderPtr<x509_st>; inline TSslContextPtr CreateSslCtx(const ssl_method_st* method) { TSslContextPtr ctx(SSL_CTX_new(method)); @@ -77,7 +77,7 @@ namespace { } SSL_CTX_set_options(ctx.Get(), SSL_OP_NO_SSLv2); - SSL_CTX_set_options(ctx.Get(), SSL_OP_NO_SSLv3); + SSL_CTX_set_options(ctx.Get(), SSL_OP_NO_SSLv3); SSL_CTX_set_options(ctx.Get(), SSL_OP_MICROSOFT_SESS_ID_BUG); SSL_CTX_set_options(ctx.Get(), SSL_OP_NETSCAPE_CHALLENGE_BUG); @@ -171,35 +171,35 @@ namespace { ythrow TSslError() << "SSL_new"; } - if (VerifyCert_) { - InitVerification(ssl.Get()); - } - + if (VerifyCert_) { + InitVerification(ssl.Get()); + } + BIO_up_ref(Io); // SSL_set_bio consumes only one reference if rbio and wbio are the same SSL_set_bio(ssl.Get(), Io, Io); return ssl; } - inline void InitVerification(ssl_st* ssl) { - X509_VERIFY_PARAM* param = SSL_get0_param(ssl); - X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); + inline void InitVerification(ssl_st* ssl) { + X509_VERIFY_PARAM* param = SSL_get0_param(ssl); + X509_VERIFY_PARAM_set_hostflags(param, X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS); Y_ENSURE(X509_VERIFY_PARAM_set1_host(param, VerifyCert_->Hostname_.data(), VerifyCert_->Hostname_.size())); SSL_set_tlsext_host_name(ssl, VerifyCert_->Hostname_.data()); // TLS extenstion: SNI - - SSL_CTX_set_cert_store(Ctx.Get(), GetBuiltinOpenSslX509Store().Release()); - - Y_ENSURE_EX(1 == SSL_CTX_set_default_verify_paths(Ctx.Get()), - TSslError()); - // it is OK to ignore result of SSL_CTX_load_verify_locations(): - // Dir "/etc/ssl/certs/" may be missing - SSL_CTX_load_verify_locations(Ctx.Get(), - "/etc/ssl/certs/ca-certificates.crt", - "/etc/ssl/certs/"); - - SSL_set_verify(ssl, SSL_VERIFY_PEER, nullptr); - } - + + SSL_CTX_set_cert_store(Ctx.Get(), GetBuiltinOpenSslX509Store().Release()); + + Y_ENSURE_EX(1 == SSL_CTX_set_default_verify_paths(Ctx.Get()), + TSslError()); + // it is OK to ignore result of SSL_CTX_load_verify_locations(): + // Dir "/etc/ssl/certs/" may be missing + SSL_CTX_load_verify_locations(Ctx.Get(), + "/etc/ssl/certs/ca-certificates.crt", + "/etc/ssl/certs/"); + + SSL_set_verify(ssl, SSL_VERIFY_PEER, nullptr); + } + inline void Connect() { if (SSL_connect(Ssl.Get()) != 1) { ythrow TSslError() << "SSL_connect"; @@ -270,60 +270,60 @@ void TOpenSslClientIO::DoWrite(const void* buf, size_t len) { size_t TOpenSslClientIO::DoRead(void* buf, size_t len) { return Impl_->Read(buf, len); } - -namespace NPrivate { - void TSslDestroy::Destroy(x509_store_st* x509) noexcept { - X509_STORE_free(x509); - } -} - -class TBuiltinCerts { -public: - TBuiltinCerts() { - TString c = NResource::Find("/builtin/cacert"); - + +namespace NPrivate { + void TSslDestroy::Destroy(x509_store_st* x509) noexcept { + X509_STORE_free(x509); + } +} + +class TBuiltinCerts { +public: + TBuiltinCerts() { + TString c = NResource::Find("/builtin/cacert"); + TBioPtr cbio(BIO_new_mem_buf(c.data(), c.size())); - Y_ENSURE_EX(cbio, TSslError() << "BIO_new_mem_buf"); - - while (true) { + Y_ENSURE_EX(cbio, TSslError() << "BIO_new_mem_buf"); + + while (true) { TX509Ptr cert(PEM_read_bio_X509(cbio.Get(), nullptr, nullptr, nullptr)); - if (!cert) { - break; - } - Certs.push_back(std::move(cert)); - } - - int err = GetLastSslError(); - if (!Certs.empty() && ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { - ERR_clear_error(); - } else { - ythrow TSslError() << "can't load provided bundle: " << ERR_reason_error_string(err); - } - - Y_ENSURE_EX(!Certs.empty(), TSslError()); - } - - TOpenSslX509StorePtr GetX509Store() const { + if (!cert) { + break; + } + Certs.push_back(std::move(cert)); + } + + int err = GetLastSslError(); + if (!Certs.empty() && ERR_GET_LIB(err) == ERR_LIB_PEM && ERR_GET_REASON(err) == PEM_R_NO_START_LINE) { + ERR_clear_error(); + } else { + ythrow TSslError() << "can't load provided bundle: " << ERR_reason_error_string(err); + } + + Y_ENSURE_EX(!Certs.empty(), TSslError()); + } + + TOpenSslX509StorePtr GetX509Store() const { TOpenSslX509StorePtr store(X509_STORE_new()); - - for (const TX509Ptr& c : Certs) { - if (0 == X509_STORE_add_cert(store.Get(), c.Get())) { - int err = GetLastSslError(); - if (ERR_GET_LIB(err) == ERR_LIB_X509 && ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE) { - ERR_clear_error(); - } else { - ythrow TSslError() << "can't load provided bundle: " << ERR_reason_error_string(err); - } - } - } - - return store; - } - -private: - TDeque<TX509Ptr> Certs; -}; - -TOpenSslX509StorePtr GetBuiltinOpenSslX509Store() { - return Singleton<TBuiltinCerts>()->GetX509Store(); -} + + for (const TX509Ptr& c : Certs) { + if (0 == X509_STORE_add_cert(store.Get(), c.Get())) { + int err = GetLastSslError(); + if (ERR_GET_LIB(err) == ERR_LIB_X509 && ERR_GET_REASON(err) == X509_R_CERT_ALREADY_IN_HASH_TABLE) { + ERR_clear_error(); + } else { + ythrow TSslError() << "can't load provided bundle: " << ERR_reason_error_string(err); + } + } + } + + return store; + } + +private: + TDeque<TX509Ptr> Certs; +}; + +TOpenSslX509StorePtr GetBuiltinOpenSslX509Store() { + return Singleton<TBuiltinCerts>()->GetX509Store(); +} diff --git a/library/cpp/openssl/io/stream.h b/library/cpp/openssl/io/stream.h index 5984bfbbc0..7bca8f80ef 100644 --- a/library/cpp/openssl/io/stream.h +++ b/library/cpp/openssl/io/stream.h @@ -1,6 +1,6 @@ #pragma once -#include <util/generic/maybe.h> +#include <util/generic/maybe.h> #include <util/generic/ptr.h> #include <util/stream/input.h> #include <util/stream/output.h> @@ -8,19 +8,19 @@ class TOpenSslClientIO: public IInputStream, public IOutputStream { public: struct TOptions { - struct TVerifyCert { - // Uses builtin certs. - // Also uses default CA path /etc/ssl/certs/ - can be provided with debian package: ca-certificates.deb. - // It can be expanded with ENV: SSL_CERT_DIR. - TString Hostname_; - }; + struct TVerifyCert { + // Uses builtin certs. + // Also uses default CA path /etc/ssl/certs/ - can be provided with debian package: ca-certificates.deb. + // It can be expanded with ENV: SSL_CERT_DIR. + TString Hostname_; + }; struct TClientCert { TString CertificateFile_; TString PrivateKeyFile_; TString PrivateKeyPassword_; }; - - TMaybe<TVerifyCert> VerifyCert_; + + TMaybe<TVerifyCert> VerifyCert_; TMaybe<TClientCert> ClientCert_; // TODO - keys, cyphers, etc }; @@ -37,14 +37,14 @@ private: struct TImpl; THolder<TImpl> Impl_; }; - -struct x509_store_st; - -namespace NPrivate { - struct TSslDestroy { - static void Destroy(x509_store_st* x509) noexcept; - }; -} - -using TOpenSslX509StorePtr = THolder<x509_store_st, NPrivate::TSslDestroy>; -TOpenSslX509StorePtr GetBuiltinOpenSslX509Store(); + +struct x509_store_st; + +namespace NPrivate { + struct TSslDestroy { + static void Destroy(x509_store_st* x509) noexcept; + }; +} + +using TOpenSslX509StorePtr = THolder<x509_store_st, NPrivate::TSslDestroy>; +TOpenSslX509StorePtr GetBuiltinOpenSslX509Store(); diff --git a/library/cpp/openssl/io/ut/builtin_ut.cpp b/library/cpp/openssl/io/ut/builtin_ut.cpp index 8254f8148a..987cd08492 100644 --- a/library/cpp/openssl/io/ut/builtin_ut.cpp +++ b/library/cpp/openssl/io/ut/builtin_ut.cpp @@ -1,9 +1,9 @@ -#include <library/cpp/openssl/io/stream.h> +#include <library/cpp/openssl/io/stream.h> #include <library/cpp/testing/unittest/registar.h> - -Y_UNIT_TEST_SUITE(Builtin) { - Y_UNIT_TEST(Init) { - UNIT_ASSERT_NO_EXCEPTION(GetBuiltinOpenSslX509Store()); - UNIT_ASSERT_NO_EXCEPTION(GetBuiltinOpenSslX509Store()); - } -} + +Y_UNIT_TEST_SUITE(Builtin) { + Y_UNIT_TEST(Init) { + UNIT_ASSERT_NO_EXCEPTION(GetBuiltinOpenSslX509Store()); + UNIT_ASSERT_NO_EXCEPTION(GetBuiltinOpenSslX509Store()); + } +} diff --git a/library/cpp/openssl/io/ut/ya.make b/library/cpp/openssl/io/ut/ya.make index eab282b4e9..b978a6c046 100644 --- a/library/cpp/openssl/io/ut/ya.make +++ b/library/cpp/openssl/io/ut/ya.make @@ -1,12 +1,12 @@ -UNITTEST_FOR(library/cpp/openssl/io) - +UNITTEST_FOR(library/cpp/openssl/io) + OWNER( pg cerevra ) - -SRCS( - builtin_ut.cpp -) - -END() + +SRCS( + builtin_ut.cpp +) + +END() diff --git a/library/cpp/openssl/io/ya.make b/library/cpp/openssl/io/ya.make index 885d490b1c..aaebba4011 100644 --- a/library/cpp/openssl/io/ya.make +++ b/library/cpp/openssl/io/ya.make @@ -3,10 +3,10 @@ LIBRARY() OWNER(pg) PEERDIR( - certs + certs contrib/libs/openssl - library/cpp/openssl/init - library/cpp/openssl/method + library/cpp/openssl/init + library/cpp/openssl/method ) SRCS( diff --git a/library/cpp/openssl/method/io.h b/library/cpp/openssl/method/io.h index 7d055d8feb..f1d3df978d 100644 --- a/library/cpp/openssl/method/io.h +++ b/library/cpp/openssl/method/io.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/openssl/holders/bio.h> +#include <library/cpp/openssl/holders/bio.h> namespace NOpenSSL { diff --git a/library/cpp/openssl/method/ut/io_ut.cpp b/library/cpp/openssl/method/ut/io_ut.cpp index 04e193273f..bff2b23d31 100644 --- a/library/cpp/openssl/method/ut/io_ut.cpp +++ b/library/cpp/openssl/method/ut/io_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/openssl/method/io.h> +#include <library/cpp/openssl/method/io.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/openssl/method/ut/ya.make b/library/cpp/openssl/method/ut/ya.make index 347aa9cb05..3645ad17e6 100644 --- a/library/cpp/openssl/method/ut/ya.make +++ b/library/cpp/openssl/method/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/openssl/method) +UNITTEST_FOR(library/cpp/openssl/method) OWNER(somov deshevoy) diff --git a/library/cpp/openssl/method/ya.make b/library/cpp/openssl/method/ya.make index c8c8946dcd..c8f6f18b6b 100644 --- a/library/cpp/openssl/method/ya.make +++ b/library/cpp/openssl/method/ya.make @@ -4,7 +4,7 @@ OWNER(somov deshevoy) PEERDIR( contrib/libs/openssl - library/cpp/openssl/holders + library/cpp/openssl/holders ) SRCS( diff --git a/library/cpp/openssl/ya.make b/library/cpp/openssl/ya.make index 2bdb9a60ce..7c10963e26 100644 --- a/library/cpp/openssl/ya.make +++ b/library/cpp/openssl/ya.make @@ -6,7 +6,7 @@ RECURSE( holders holders/ut io - io/ut + io/ut method method/ut init diff --git a/library/cpp/packedtypes/longs_ut.cpp b/library/cpp/packedtypes/longs_ut.cpp index 450326449a..8b06c934d2 100644 --- a/library/cpp/packedtypes/longs_ut.cpp +++ b/library/cpp/packedtypes/longs_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/digest/old_crc/crc.h> +#include <library/cpp/digest/old_crc/crc.h> #include <util/string/util.h> #include <util/stream/output.h> #include <util/system/hi_lo.h> diff --git a/library/cpp/packedtypes/packed.h b/library/cpp/packedtypes/packed.h index d569820c38..88cff26ae2 100644 --- a/library/cpp/packedtypes/packed.h +++ b/library/cpp/packedtypes/packed.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/streams/zc_memory_input/zc_memory_input.h> +#include <library/cpp/streams/zc_memory_input/zc_memory_input.h> #include <util/stream/output.h> #include <util/ysaveload.h> diff --git a/library/cpp/packedtypes/ut/ya.make b/library/cpp/packedtypes/ut/ya.make index 67ca44ccb5..a203115e71 100644 --- a/library/cpp/packedtypes/ut/ya.make +++ b/library/cpp/packedtypes/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/packedtypes) +UNITTEST_FOR(library/cpp/packedtypes) OWNER( akhropov @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/digest/old_crc + library/cpp/digest/old_crc ) SRCS( diff --git a/library/cpp/packedtypes/ya.make b/library/cpp/packedtypes/ya.make index a415949528..4c2c950619 100644 --- a/library/cpp/packedtypes/ya.make +++ b/library/cpp/packedtypes/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/streams/zc_memory_input + library/cpp/streams/zc_memory_input ) SRCS( diff --git a/library/cpp/packers/ut/proto_packer_ut.cpp b/library/cpp/packers/ut/proto_packer_ut.cpp index 1aaec07493..e4151ba68c 100644 --- a/library/cpp/packers/ut/proto_packer_ut.cpp +++ b/library/cpp/packers/ut/proto_packer_ut.cpp @@ -1,6 +1,6 @@ #include "proto_packer.h" -#include <library/cpp/packers/ut/test.pb.h> +#include <library/cpp/packers/ut/test.pb.h> #include <library/cpp/testing/unittest/registar.h> #include <util/generic/string.h> diff --git a/library/cpp/packers/ut/ya.make b/library/cpp/packers/ut/ya.make index 2f4a887ebc..1c024ffd94 100644 --- a/library/cpp/packers/ut/ya.make +++ b/library/cpp/packers/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/packers) +UNITTEST_FOR(library/cpp/packers) OWNER(velavokr) diff --git a/library/cpp/protobuf/interop/cast.cpp b/library/cpp/protobuf/interop/cast.cpp index 6036eb503b..c4cd59b417 100644 --- a/library/cpp/protobuf/interop/cast.cpp +++ b/library/cpp/protobuf/interop/cast.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/protobuf/interop/cast.h> +#include <library/cpp/protobuf/interop/cast.h> #include <google/protobuf/duration.pb.h> #include <google/protobuf/timestamp.pb.h> diff --git a/library/cpp/protobuf/interop/ut/cast_ut.cpp b/library/cpp/protobuf/interop/ut/cast_ut.cpp index bab31ff3d3..6ef055b651 100644 --- a/library/cpp/protobuf/interop/ut/cast_ut.cpp +++ b/library/cpp/protobuf/interop/ut/cast_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/protobuf/interop/cast.h> +#include <library/cpp/protobuf/interop/cast.h> #include <library/cpp/testing/unittest/registar.h> #include <google/protobuf/duration.pb.h> diff --git a/library/cpp/protobuf/interop/ut/ya.make b/library/cpp/protobuf/interop/ut/ya.make index 49b2a34640..b9c634cb6b 100644 --- a/library/cpp/protobuf/interop/ut/ya.make +++ b/library/cpp/protobuf/interop/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/protobuf/interop) +UNITTEST_FOR(library/cpp/protobuf/interop) OWNER( paxakor @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/protobuf/interop + library/cpp/protobuf/interop ) END() diff --git a/library/cpp/protobuf/json/inline.h b/library/cpp/protobuf/json/inline.h index bd62bb9635..e2d7bb6ef0 100644 --- a/library/cpp/protobuf/json/inline.h +++ b/library/cpp/protobuf/json/inline.h @@ -39,7 +39,7 @@ #include "proto2json_printer.h" #include "json_output_create.h" -#include <library/cpp/protobuf/util/simple_reflection.h> +#include <library/cpp/protobuf/util/simple_reflection.h> #include <util/generic/maybe.h> #include <util/generic/yexception.h> diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index 2284b6fb12..640c10f5a5 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -1,7 +1,7 @@ #include "json2proto.h" #include "util.h" -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_value.h> #include <google/protobuf/message.h> #include <google/protobuf/descriptor.h> diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h index 90f09eb53a..4c33498dfa 100644 --- a/library/cpp/protobuf/json/json2proto.h +++ b/library/cpp/protobuf/json/json2proto.h @@ -3,8 +3,8 @@ #include "string_transform.h" #include "name_generator.h" -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> #include <util/stream/input.h> #include <util/stream/str.h> diff --git a/library/cpp/protobuf/json/json_value_output.cpp b/library/cpp/protobuf/json/json_value_output.cpp index b74b37bb4f..d845cc1c74 100644 --- a/library/cpp/protobuf/json/json_value_output.cpp +++ b/library/cpp/protobuf/json/json_value_output.cpp @@ -1,6 +1,6 @@ #include "json_value_output.h" -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> namespace NProtobufJson { template <typename T> diff --git a/library/cpp/protobuf/json/json_value_output.h b/library/cpp/protobuf/json/json_value_output.h index 73fe502ba8..3fc6ff2ab0 100644 --- a/library/cpp/protobuf/json/json_value_output.h +++ b/library/cpp/protobuf/json/json_value_output.h @@ -2,7 +2,7 @@ #include "json_output.h" -#include <library/cpp/json/writer/json_value.h> +#include <library/cpp/json/writer/json_value.h> #include <util/generic/stack.h> diff --git a/library/cpp/protobuf/json/json_writer_output.h b/library/cpp/protobuf/json/json_writer_output.h index d36fcb987d..3d8a2daa56 100644 --- a/library/cpp/protobuf/json/json_writer_output.h +++ b/library/cpp/protobuf/json/json_writer_output.h @@ -3,7 +3,7 @@ #include "json_output.h" #include "config.h" -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_writer.h> #include <util/string/builder.h> #include <util/generic/store_policy.h> diff --git a/library/cpp/protobuf/json/proto2json.cpp b/library/cpp/protobuf/json/proto2json.cpp index 4254968fea..3d76a91686 100644 --- a/library/cpp/protobuf/json/proto2json.cpp +++ b/library/cpp/protobuf/json/proto2json.cpp @@ -3,9 +3,9 @@ #include "json_output_create.h" #include "proto2json_printer.h" -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_writer.h> #include <util/generic/ptr.h> #include <util/generic/strbuf.h> diff --git a/library/cpp/protobuf/json/ut/filter_ut.cpp b/library/cpp/protobuf/json/ut/filter_ut.cpp index 9c8893dfae..95c227666f 100644 --- a/library/cpp/protobuf/json/ut/filter_ut.cpp +++ b/library/cpp/protobuf/json/ut/filter_ut.cpp @@ -1,8 +1,8 @@ -#include <library/cpp/protobuf/json/ut/filter_ut.pb.h> +#include <library/cpp/protobuf/json/ut/filter_ut.pb.h> -#include <library/cpp/protobuf/json/filter.h> -#include <library/cpp/protobuf/json/field_option.h> -#include <library/cpp/protobuf/json/proto2json.h> +#include <library/cpp/protobuf/json/filter.h> +#include <library/cpp/protobuf/json/field_option.h> +#include <library/cpp/protobuf/json/proto2json.h> #include <library/cpp/testing/unittest/registar.h> using namespace NProtobufJson; diff --git a/library/cpp/protobuf/json/ut/inline_ut.cpp b/library/cpp/protobuf/json/ut/inline_ut.cpp index aabf79451d..c29ad32e7d 100644 --- a/library/cpp/protobuf/json/ut/inline_ut.cpp +++ b/library/cpp/protobuf/json/ut/inline_ut.cpp @@ -1,8 +1,8 @@ -#include <library/cpp/protobuf/json/ut/inline_ut.pb.h> +#include <library/cpp/protobuf/json/ut/inline_ut.pb.h> -#include <library/cpp/protobuf/json/inline.h> -#include <library/cpp/protobuf/json/field_option.h> -#include <library/cpp/protobuf/json/proto2json.h> +#include <library/cpp/protobuf/json/inline.h> +#include <library/cpp/protobuf/json/field_option.h> +#include <library/cpp/protobuf/json/proto2json.h> #include <library/cpp/testing/unittest/registar.h> #include <util/generic/string.h> diff --git a/library/cpp/protobuf/json/ut/json.h b/library/cpp/protobuf/json/ut/json.h index fe54840999..c1f108e6e4 100644 --- a/library/cpp/protobuf/json/ut/json.h +++ b/library/cpp/protobuf/json/ut/json.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/protobuf/json/ut/test.pb.h> +#include <library/cpp/protobuf/json/ut/test.pb.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_value.h> #include <cstdarg> diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 6fdbba4245..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -2,13 +2,13 @@ #include "proto.h" #include "proto2json.h" -#include <library/cpp/protobuf/json/ut/test.pb.h> +#include <library/cpp/protobuf/json/ut/test.pb.h> -#include <library/cpp/json/json_value.h> -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_writer.h> -#include <library/cpp/protobuf/json/json2proto.h> +#include <library/cpp/protobuf/json/json2proto.h> #include <library/cpp/testing/unittest/registar.h> @@ -92,7 +92,7 @@ Y_UNIT_TEST_SUITE(TJson2ProtoTest) { FillFlatProto(&modelProto, skippedField); \ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestFlatOptional @@ -114,7 +114,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); TFlatRequired proto; \ UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception); \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestFlatRequired @@ -153,7 +153,7 @@ Y_UNIT_TEST(TestFlatNoCheckRequired) { TFlatRequired proto; \ UNIT_ASSERT_NO_EXCEPTION(Json2Proto(json, proto, cfg)); \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestFlatNoCheckRequired @@ -178,7 +178,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); FillRepeatedProto(&modelProto, skippedField); \ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD } // TestFlatRepeated @@ -203,7 +203,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); FillCompositeProto(&modelProto, skippedField); \ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestCompositeOptional @@ -236,7 +236,7 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); } \ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestCompositeOptionalStringBuf @@ -289,7 +289,7 @@ Y_UNIT_TEST(TestCompositeRepeated) { modelProto.AddPart()->CopyFrom(partModelProto); \ array.AppendValue(CreateFlatJson(skippedField)); \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD NJson::TJsonValue json; @@ -462,7 +462,7 @@ Y_UNIT_TEST(TestFieldNameMode) { { // FIXME(CONTRIB-139): since protobuf 3.1, Def_upper json name is // "DefUpper", but until kernel/ugc/schema and yweb/yasap/pdb are - // updated, library/cpp/protobuf/json preserves compatibility with + // updated, library/cpp/protobuf/json preserves compatibility with // protobuf 3.0 by lowercasing default names, making it "defUpper". TString modelStr(R"_({"My-Upper":1,"my-lower":2,"defUpper":3,"defLower":4})_"); @@ -591,7 +591,7 @@ Y_UNIT_TEST(TestCastFromString) { NJson::TJsonValue json; #define DEFINE_FIELD(name, value) \ json.InsertValue(#name, ConvertToString(value)); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD TFlatOptional proto; @@ -618,7 +618,7 @@ Y_UNIT_TEST(TestCastFromString) { } \ json.InsertValue(#name, array); \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD TFlatRepeated proto; @@ -676,7 +676,7 @@ Y_UNIT_TEST(TestVectorizeScalars) { NJson::TJsonValue json; #define DEFINE_FIELD(name, value) \ json.InsertValue(#name, value); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD TFlatRepeated proto; @@ -686,7 +686,7 @@ Y_UNIT_TEST(TestVectorizeScalars) { #define DEFINE_FIELD(name, value) \ UNIT_ASSERT_VALUES_EQUAL(proto.Get ## name(0), value); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } diff --git a/library/cpp/protobuf/json/ut/proto.h b/library/cpp/protobuf/json/ut/proto.h index 715a51116c..8183bfc8e1 100644 --- a/library/cpp/protobuf/json/ut/proto.h +++ b/library/cpp/protobuf/json/ut/proto.h @@ -13,7 +13,7 @@ namespace NProtobufJsonTest { #define DEFINE_FIELD(name, value) \ if (skippedFields.find(#name) == skippedFields.end()) \ proto->Set##name(value); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } @@ -38,7 +38,7 @@ namespace NProtobufJsonTest { AddValue(proto->Mutable##name(), values[i]); \ } \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD } diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 2fb81cf184..07e52d7f2f 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -1,13 +1,13 @@ #include "json.h" #include "proto.h" -#include <library/cpp/protobuf/json/ut/test.pb.h> +#include <library/cpp/protobuf/json/ut/test.pb.h> -#include <library/cpp/json/json_value.h> -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_writer.h> -#include <library/cpp/protobuf/json/proto2json.h> +#include <library/cpp/protobuf/json/proto2json.h> #include <library/cpp/testing/unittest/registar.h> @@ -70,7 +70,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { break; \ } \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } @@ -137,7 +137,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) { UNIT_ASSERT_JSONS_EQUAL(json, modelJson); \ } \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestFlatOptional @@ -178,7 +178,7 @@ const NJson::TJsonValue& modelJson = CreateFlatJson(); UNIT_ASSERT_JSONS_EQUAL(json, modelJson); \ } \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestFlatRequired @@ -223,7 +223,7 @@ Y_UNIT_TEST(TestFlatRepeated) { UNIT_ASSERT_JSONS_EQUAL(json, modelJson); \ } \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD } // TestFlatRepeated @@ -264,7 +264,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson(); UNIT_ASSERT_JSONS_EQUAL(json, modelJson); \ } \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestCompositeOptional @@ -305,7 +305,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson(); UNIT_ASSERT_JSONS_EQUAL(json, modelJson); \ } \ } -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD } // TestCompositeRequired @@ -349,7 +349,7 @@ Y_UNIT_TEST(TestCompositeRepeated) { proto.AddPart()->CopyFrom(partProto); \ modelArray.AppendValue(CreateFlatJson(skippedField)); \ } -#include <library/cpp/protobuf/json/ut/repeated_fields.incl> +#include <library/cpp/protobuf/json/ut/repeated_fields.incl> #undef DEFINE_REPEATED_FIELD NJson::TJsonValue modelJson; @@ -454,7 +454,7 @@ Y_UNIT_TEST(TestMissingSingleKeyConfig) { NJson::TJsonValue modelJson; #define DEFINE_FIELD(name, value) \ modelJson.InsertValue(#name, NJson::TJsonValue(NJson::JSON_NULL)); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD TFlatOptional proto; @@ -540,7 +540,7 @@ Y_UNIT_TEST(TestMissingRepeatedKeyConfig) { NJson::TJsonValue modelJson; #define DEFINE_FIELD(name, value) \ modelJson.InsertValue(#name, NJson::TJsonValue(NJson::JSON_NULL)); -#include <library/cpp/protobuf/json/ut/fields.incl> +#include <library/cpp/protobuf/json/ut/fields.incl> #undef DEFINE_FIELD TFlatRepeated proto; diff --git a/library/cpp/protobuf/json/ut/string_transform_ut.cpp b/library/cpp/protobuf/json/ut/string_transform_ut.cpp index 64e2f71bb4..a31dabcb0f 100644 --- a/library/cpp/protobuf/json/ut/string_transform_ut.cpp +++ b/library/cpp/protobuf/json/ut/string_transform_ut.cpp @@ -1,7 +1,7 @@ #include "json.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/protobuf/json/proto2json.h> +#include <library/cpp/protobuf/json/proto2json.h> Y_UNIT_TEST_SUITE(TDoubleEscapeTransform) { Y_UNIT_TEST(TestEmptyString) { diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make index 8b9c9fd3bc..b60a6d3c17 100644 --- a/library/cpp/protobuf/json/ut/ya.make +++ b/library/cpp/protobuf/json/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/protobuf/json) +UNITTEST_FOR(library/cpp/protobuf/json) OWNER(avitella) @@ -17,7 +17,7 @@ SRCS( GENERATE_ENUM_SERIALIZATION(test.pb.h) PEERDIR( - library/cpp/protobuf/json + library/cpp/protobuf/json ) END() diff --git a/library/cpp/protobuf/json/ya.make b/library/cpp/protobuf/json/ya.make index 8b7104cf2a..2f2c75cfdb 100644 --- a/library/cpp/protobuf/json/ya.make +++ b/library/cpp/protobuf/json/ya.make @@ -17,8 +17,8 @@ SRCS( PEERDIR( contrib/libs/protobuf - library/cpp/json - library/cpp/protobuf/util + library/cpp/json + library/cpp/protobuf/util library/cpp/string_utils/relaxed_escaper ) diff --git a/library/cpp/protobuf/util/is_equal_ut.cpp b/library/cpp/protobuf/util/is_equal_ut.cpp index f8c8c28b45..3ca4c90dd5 100644 --- a/library/cpp/protobuf/util/is_equal_ut.cpp +++ b/library/cpp/protobuf/util/is_equal_ut.cpp @@ -1,5 +1,5 @@ #include "is_equal.h" -#include <library/cpp/protobuf/util/ut/sample_for_is_equal.pb.h> +#include <library/cpp/protobuf/util/ut/sample_for_is_equal.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/iterators_ut.cpp b/library/cpp/protobuf/util/iterators_ut.cpp index 0b15f1f276..9ebcff2963 100644 --- a/library/cpp/protobuf/util/iterators_ut.cpp +++ b/library/cpp/protobuf/util/iterators_ut.cpp @@ -1,6 +1,6 @@ #include "iterators.h" #include "simple_reflection.h" -#include <library/cpp/protobuf/util/ut/common_ut.pb.h> +#include <library/cpp/protobuf/util/ut/common_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/merge.cpp b/library/cpp/protobuf/util/merge.cpp index e2c8ab8e53..dc2b9cc806 100644 --- a/library/cpp/protobuf/util/merge.cpp +++ b/library/cpp/protobuf/util/merge.cpp @@ -3,7 +3,7 @@ #include <google/protobuf/message.h> -#include <library/cpp/protobuf/util/proto/merge.pb.h> +#include <library/cpp/protobuf/util/proto/merge.pb.h> namespace NProtoBuf { void RewriteMerge(const Message& src, Message& dst) { diff --git a/library/cpp/protobuf/util/merge_ut.cpp b/library/cpp/protobuf/util/merge_ut.cpp index a1d9b6b50a..22217db183 100644 --- a/library/cpp/protobuf/util/merge_ut.cpp +++ b/library/cpp/protobuf/util/merge_ut.cpp @@ -1,5 +1,5 @@ #include "merge.h" -#include <library/cpp/protobuf/util/ut/common_ut.pb.h> +#include <library/cpp/protobuf/util/ut/common_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp index 6e15748ca5..6270ee0624 100644 --- a/library/cpp/protobuf/util/pb_io.cpp +++ b/library/cpp/protobuf/util/pb_io.cpp @@ -1,6 +1,6 @@ #include "pb_io.h" -#include <library/cpp/binsaver/bin_saver.h> +#include <library/cpp/binsaver/bin_saver.h> #include <library/cpp/string_utils/base64/base64.h> #include <google/protobuf/message.h> diff --git a/library/cpp/protobuf/util/pb_io_ut.cpp b/library/cpp/protobuf/util/pb_io_ut.cpp index baade8a6ea..875d6dc602 100644 --- a/library/cpp/protobuf/util/pb_io_ut.cpp +++ b/library/cpp/protobuf/util/pb_io_ut.cpp @@ -2,7 +2,7 @@ #include "is_equal.h" -#include <library/cpp/protobuf/util/ut/common_ut.pb.h> +#include <library/cpp/protobuf/util/ut/common_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp index 1c9b717753..58aaaa9e12 100644 --- a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp +++ b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp @@ -1,5 +1,5 @@ #include "repeated_field_utils.h" -#include <library/cpp/protobuf/util/ut/common_ut.pb.h> +#include <library/cpp/protobuf/util/ut/common_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/simple_reflection_ut.cpp b/library/cpp/protobuf/util/simple_reflection_ut.cpp index ee41e0adb6..169d4703c9 100644 --- a/library/cpp/protobuf/util/simple_reflection_ut.cpp +++ b/library/cpp/protobuf/util/simple_reflection_ut.cpp @@ -1,6 +1,6 @@ #include "simple_reflection.h" -#include <library/cpp/protobuf/util/ut/sample_for_simple_reflection.pb.h> -#include <library/cpp/protobuf/util/ut/extensions.pb.h> +#include <library/cpp/protobuf/util/ut/sample_for_simple_reflection.pb.h> +#include <library/cpp/protobuf/util/ut/extensions.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/ut/common_ut.proto b/library/cpp/protobuf/util/ut/common_ut.proto index c1cf48b362..9cf803ffbf 100644 --- a/library/cpp/protobuf/util/ut/common_ut.proto +++ b/library/cpp/protobuf/util/ut/common_ut.proto @@ -1,5 +1,5 @@ import "google/protobuf/descriptor.proto"; -import "library/cpp/protobuf/util/proto/merge.proto"; +import "library/cpp/protobuf/util/proto/merge.proto"; package NProtobufUtilUt; diff --git a/library/cpp/protobuf/util/ut/extensions.proto b/library/cpp/protobuf/util/ut/extensions.proto index 6b2899370f..4944f0f5ca 100644 --- a/library/cpp/protobuf/util/ut/extensions.proto +++ b/library/cpp/protobuf/util/ut/extensions.proto @@ -1,6 +1,6 @@ package NExt; -import "library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto"; +import "library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto"; message TTestExt { extend TSample { diff --git a/library/cpp/protobuf/util/ut/ya.make b/library/cpp/protobuf/util/ut/ya.make index 0118af31ac..701ba9a8c8 100644 --- a/library/cpp/protobuf/util/ut/ya.make +++ b/library/cpp/protobuf/util/ut/ya.make @@ -1,6 +1,6 @@ OWNER(nga) -UNITTEST_FOR(library/cpp/protobuf/util) +UNITTEST_FOR(library/cpp/protobuf/util) SRCS( extensions.proto diff --git a/library/cpp/protobuf/util/walk_ut.cpp b/library/cpp/protobuf/util/walk_ut.cpp index 68738ad8e4..2ea6071b17 100644 --- a/library/cpp/protobuf/util/walk_ut.cpp +++ b/library/cpp/protobuf/util/walk_ut.cpp @@ -1,6 +1,6 @@ #include "walk.h" #include "simple_reflection.h" -#include <library/cpp/protobuf/util/ut/common_ut.pb.h> +#include <library/cpp/protobuf/util/ut/common_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/protobuf/util/ya.make b/library/cpp/protobuf/util/ya.make index cdeb3849ce..b62028af58 100644 --- a/library/cpp/protobuf/util/ya.make +++ b/library/cpp/protobuf/util/ya.make @@ -4,8 +4,8 @@ OWNER(mowgli) PEERDIR( contrib/libs/protobuf - library/cpp/binsaver - library/cpp/protobuf/util/proto + library/cpp/binsaver + library/cpp/protobuf/util/proto library/cpp/string_utils/base64 ) diff --git a/library/cpp/protobuf/ya.make b/library/cpp/protobuf/ya.make index 69c715c57a..618b542b4f 100644 --- a/library/cpp/protobuf/ya.make +++ b/library/cpp/protobuf/ya.make @@ -1,19 +1,19 @@ RECURSE( dynamic_prototype - from_xml - from_xml/ut - interop - interop/ut - json - json/ut - parser - parser/ut - protofile - protofile/ut - util - util/proto - yql - yql/ut + from_xml + from_xml/ut + interop + interop/ut + json + json/ut + parser + parser/ut + protofile + protofile/ut + util + util/proto + yql + yql/ut yandex_patches_ut - yt + yt ) diff --git a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp index 5dba5c0c87..9caa53f2e7 100644 --- a/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp +++ b/library/cpp/regex/hyperscan/ut/hyperscan_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/regex/hyperscan/hyperscan.h> +#include <library/cpp/regex/hyperscan/hyperscan.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/regex/pcre/regexp_ut.cpp b/library/cpp/regex/pcre/regexp_ut.cpp index 0e4b059bc4..5184e801cc 100644 --- a/library/cpp/regex/pcre/regexp_ut.cpp +++ b/library/cpp/regex/pcre/regexp_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/testing/unittest/registar.h> #include <util/string/strip.h> -#include <library/cpp/regex/pcre/regexp.h> +#include <library/cpp/regex/pcre/regexp.h> #include <util/stream/output.h> struct TRegTest { diff --git a/library/cpp/regex/pcre/ut/ya.make b/library/cpp/regex/pcre/ut/ya.make index 8ae340546f..0721ef87c2 100644 --- a/library/cpp/regex/pcre/ut/ya.make +++ b/library/cpp/regex/pcre/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/regex/pcre) +UNITTEST_FOR(library/cpp/regex/pcre) OWNER(g:util) diff --git a/library/cpp/regex/pire/extraencodings.cpp b/library/cpp/regex/pire/extraencodings.cpp index 5bc198651d..2e507e4b67 100644 --- a/library/cpp/regex/pire/extraencodings.cpp +++ b/library/cpp/regex/pire/extraencodings.cpp @@ -1,9 +1,9 @@ #include <util/system/defaults.h> #include <util/system/yassert.h> -#include <library/cpp/charset/codepage.h> +#include <library/cpp/charset/codepage.h> #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> #include "pire.h" diff --git a/library/cpp/regex/pire/inline/ya.make b/library/cpp/regex/pire/inline/ya.make index 5b4db7405c..d4850f7b45 100644 --- a/library/cpp/regex/pire/inline/ya.make +++ b/library/cpp/regex/pire/inline/ya.make @@ -8,7 +8,7 @@ OWNER( ) PEERDIR( - ADDINCL library/cpp/regex/pire + ADDINCL library/cpp/regex/pire ) SRCDIR( diff --git a/library/cpp/regex/pire/pire.h b/library/cpp/regex/pire/pire.h index c64d812bd0..286fecd693 100644 --- a/library/cpp/regex/pire/pire.h +++ b/library/cpp/regex/pire/pire.h @@ -7,7 +7,7 @@ #include <contrib/libs/pire/pire/pire.h> #include <contrib/libs/pire/pire/extra.h> -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> namespace NPire { using TChar = Pire::Char; diff --git a/library/cpp/regex/pire/regexp.h b/library/cpp/regex/pire/regexp.h index 3c4b3fe71c..94bba4064b 100644 --- a/library/cpp/regex/pire/regexp.h +++ b/library/cpp/regex/pire/regexp.h @@ -2,8 +2,8 @@ #include "pire.h" -#include <library/cpp/charset/doccodes.h> -#include <library/cpp/charset/recyr.hh> +#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/recyr.hh> #include <util/generic/maybe.h> #include <util/generic/strbuf.h> #include <util/generic/string.h> diff --git a/library/cpp/regex/pire/ut/regexp_ut.cpp b/library/cpp/regex/pire/ut/regexp_ut.cpp index 3f163f9b61..e7206de9ad 100644 --- a/library/cpp/regex/pire/ut/regexp_ut.cpp +++ b/library/cpp/regex/pire/ut/regexp_ut.cpp @@ -1,7 +1,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/regex/pire/regexp.h> -#include <library/cpp/regex/pire/pcre2pire.h> +#include <library/cpp/regex/pire/regexp.h> +#include <library/cpp/regex/pire/pcre2pire.h> Y_UNIT_TEST_SUITE(TRegExp) { using namespace NRegExp; diff --git a/library/cpp/regex/pire/ut/ya.make b/library/cpp/regex/pire/ut/ya.make index 86e4d5d2ce..8776695f40 100644 --- a/library/cpp/regex/pire/ut/ya.make +++ b/library/cpp/regex/pire/ut/ya.make @@ -12,7 +12,7 @@ SET(PIRETESTSDIR contrib/libs/pire/ut) CFLAGS(-DPIRE_NO_CONFIG) PEERDIR( - library/cpp/regex/pire + library/cpp/regex/pire ) SRCDIR( diff --git a/library/cpp/regex/pire/ya.make b/library/cpp/regex/pire/ya.make index e08af8eaf7..c857e6d18b 100644 --- a/library/cpp/regex/pire/ya.make +++ b/library/cpp/regex/pire/ya.make @@ -32,7 +32,7 @@ SRCS( ) PEERDIR( - library/cpp/charset + library/cpp/charset ) END() diff --git a/library/cpp/resource/README.md b/library/cpp/resource/README.md index 3878ad8402..b1e4961c1f 100644 --- a/library/cpp/resource/README.md +++ b/library/cpp/resource/README.md @@ -16,7 +16,7 @@ END() ### Example - access to a file content by a key: ```cpp -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> int main() { Cout << NResource::Find("/key/in/program/1") << Endl; Cout << NResource::Find("/key2") << Endl; diff --git a/library/cpp/resource/registry.cpp b/library/cpp/resource/registry.cpp index 13a996bfdb..66001c4769 100644 --- a/library/cpp/resource/registry.cpp +++ b/library/cpp/resource/registry.cpp @@ -1,6 +1,6 @@ #include "registry.h" -#include <library/cpp/blockcodecs/codecs.h> +#include <library/cpp/blockcodecs/codecs.h> #include <util/system/yassert.h> #include <util/generic/hash.h> diff --git a/library/cpp/resource/ut/resource_ut.cpp b/library/cpp/resource/ut/resource_ut.cpp index 8444444c8b..b6fa8e4df3 100644 --- a/library/cpp/resource/ut/resource_ut.cpp +++ b/library/cpp/resource/ut/resource_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TestResource) { diff --git a/library/cpp/resource/ut/ya.make b/library/cpp/resource/ut/ya.make index e95d69217c..d1ac9ed2ed 100644 --- a/library/cpp/resource/ut/ya.make +++ b/library/cpp/resource/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/resource/ut/lib) +UNITTEST_FOR(library/cpp/resource/ut/lib) OWNER(pg) diff --git a/library/cpp/resource/ya.make b/library/cpp/resource/ya.make index ac79137337..9c06df514f 100644 --- a/library/cpp/resource/ya.make +++ b/library/cpp/resource/ya.make @@ -3,8 +3,8 @@ LIBRARY() OWNER(pg) PEERDIR( - library/cpp/blockcodecs/core - library/cpp/blockcodecs/codecs/zstd + library/cpp/blockcodecs/core + library/cpp/blockcodecs/codecs/zstd ) SRCS( diff --git a/library/cpp/retry/retry.h b/library/cpp/retry/retry.h index d6ce9515c4..c47ff5070f 100644 --- a/library/cpp/retry/retry.h +++ b/library/cpp/retry/retry.h @@ -2,7 +2,7 @@ #include "utils.h" -#include <library/cpp/retry/protos/retry_options.pb.h> +#include <library/cpp/retry/protos/retry_options.pb.h> #include <util/datetime/base.h> #include <util/generic/maybe.h> diff --git a/library/cpp/retry/ut/ya.make b/library/cpp/retry/ut/ya.make index 38c3ef348d..ff8259bfdb 100644 --- a/library/cpp/retry/ut/ya.make +++ b/library/cpp/retry/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/retry) +UNITTEST_FOR(library/cpp/retry) OWNER( salmin diff --git a/library/cpp/retry/ya.make b/library/cpp/retry/ya.make index fa8d964354..31e0c6a259 100644 --- a/library/cpp/retry/ya.make +++ b/library/cpp/retry/ya.make @@ -11,7 +11,7 @@ SRCS( ) PEERDIR( - library/cpp/retry/protos + library/cpp/retry/protos ) END() diff --git a/library/cpp/scheme/scimpl_defs.h b/library/cpp/scheme/scimpl_defs.h index 2b25e76d4c..f3dd66b437 100644 --- a/library/cpp/scheme/scimpl_defs.h +++ b/library/cpp/scheme/scimpl_defs.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> #include <util/system/types.h> #include <util/memory/pool.h> diff --git a/library/cpp/scheme/scimpl_json_read.cpp b/library/cpp/scheme/scimpl_json_read.cpp index c7d2f297d4..8a29cc7739 100644 --- a/library/cpp/scheme/scimpl_json_read.cpp +++ b/library/cpp/scheme/scimpl_json_read.cpp @@ -1,6 +1,6 @@ #include "scimpl.h" -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/stream/output.h> #include <util/generic/maybe.h> diff --git a/library/cpp/scheme/scimpl_json_write.cpp b/library/cpp/scheme/scimpl_json_write.cpp index 7553544845..aadd7e6cd5 100644 --- a/library/cpp/scheme/scimpl_json_write.cpp +++ b/library/cpp/scheme/scimpl_json_write.cpp @@ -1,7 +1,7 @@ #include "scimpl.h" #include "scimpl_private.h" -#include <library/cpp/json/json_prettifier.h> +#include <library/cpp/json/json_prettifier.h> #include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h> #include <util/charset/utf8.h> diff --git a/library/cpp/scheme/scimpl_select.rl6 b/library/cpp/scheme/scimpl_select.rl6 index d9309fcfd8..11aa549b78 100644 --- a/library/cpp/scheme/scimpl_select.rl6 +++ b/library/cpp/scheme/scimpl_select.rl6 @@ -1,4 +1,4 @@ -#include <library/cpp/scheme/scimpl.h> +#include <library/cpp/scheme/scimpl.h> #include <util/string/cast.h> #include <util/string/escape.h> diff --git a/library/cpp/scheme/tests/fuzz_json/fuzz_json.cpp b/library/cpp/scheme/tests/fuzz_json/fuzz_json.cpp index f16d28a340..8d4c0fa8a0 100644 --- a/library/cpp/scheme/tests/fuzz_json/fuzz_json.cpp +++ b/library/cpp/scheme/tests/fuzz_json/fuzz_json.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.h> +#include <library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.h> extern "C" int LLVMFuzzerTestOneInput(const ui8* wireData, const size_t wireSize) { NSc::NUt::FuzzJson({(const char*)wireData, wireSize}); diff --git a/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp b/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp index 72d294ce96..7c16527c23 100644 --- a/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp +++ b/library/cpp/scheme/tests/fuzz_json/lib/fuzz_json.cpp @@ -1,7 +1,7 @@ #include "fuzz_json.h" #include "util/generic/fwd.h" -#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/scheme.h> #include <util/stream/null.h> namespace { diff --git a/library/cpp/scheme/tests/fuzz_json/lib/ya.make b/library/cpp/scheme/tests/fuzz_json/lib/ya.make index f0ff66a3aa..b30a6c9350 100644 --- a/library/cpp/scheme/tests/fuzz_json/lib/ya.make +++ b/library/cpp/scheme/tests/fuzz_json/lib/ya.make @@ -12,7 +12,7 @@ SRCS( ) PEERDIR( - library/cpp/scheme + library/cpp/scheme ) END() diff --git a/library/cpp/scheme/tests/fuzz_json/ya.make b/library/cpp/scheme/tests/fuzz_json/ya.make index 38a1bac3d2..0d91c70585 100644 --- a/library/cpp/scheme/tests/fuzz_json/ya.make +++ b/library/cpp/scheme/tests/fuzz_json/ya.make @@ -14,7 +14,7 @@ SRCS( ) PEERDIR( - library/cpp/scheme/tests/fuzz_json/lib + library/cpp/scheme/tests/fuzz_json/lib ) END() diff --git a/library/cpp/scheme/tests/fuzz_ops/fuzz_ops.cpp b/library/cpp/scheme/tests/fuzz_ops/fuzz_ops.cpp index 3b9b2ba8f9..facde50f5a 100644 --- a/library/cpp/scheme/tests/fuzz_ops/fuzz_ops.cpp +++ b/library/cpp/scheme/tests/fuzz_ops/fuzz_ops.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.h> +#include <library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.h> extern "C" int LLVMFuzzerTestOneInput(const ui8* wireData, const size_t wireSize) { NSc::NUt::FuzzOps({(const char*)wireData, wireSize}, false); diff --git a/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp b/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp index 3766b3fdef..8a7facba24 100644 --- a/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp +++ b/library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.cpp @@ -3,10 +3,10 @@ #include "vm_defs.h" #include "vm_parse.h" -#include <library/cpp/bit_io/bitinput.h> +#include <library/cpp/bit_io/bitinput.h> -#include <library/cpp/scheme/scheme.h> -#include <library/cpp/scheme/scimpl_private.h> +#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/scimpl_private.h> #include <util/generic/maybe.h> diff --git a/library/cpp/scheme/tests/fuzz_ops/lib/vm_defs.h b/library/cpp/scheme/tests/fuzz_ops/lib/vm_defs.h index 9019281895..9a0ddf7351 100644 --- a/library/cpp/scheme/tests/fuzz_ops/lib/vm_defs.h +++ b/library/cpp/scheme/tests/fuzz_ops/lib/vm_defs.h @@ -1,7 +1,7 @@ #pragma once -#include <library/cpp/bit_io/bitinput.h> -#include <library/cpp/scheme/scheme.h> +#include <library/cpp/bit_io/bitinput.h> +#include <library/cpp/scheme/scheme.h> #include <util/generic/deque.h> #include <util/generic/maybe.h> diff --git a/library/cpp/scheme/tests/fuzz_ops/lib/ya.make b/library/cpp/scheme/tests/fuzz_ops/lib/ya.make index a31d919acf..279a2ca2d4 100644 --- a/library/cpp/scheme/tests/fuzz_ops/lib/ya.make +++ b/library/cpp/scheme/tests/fuzz_ops/lib/ya.make @@ -17,7 +17,7 @@ SRCS( ) PEERDIR( - library/cpp/scheme + library/cpp/scheme ) END() diff --git a/library/cpp/scheme/tests/fuzz_ops/ut/vm_parse_ut.cpp b/library/cpp/scheme/tests/fuzz_ops/ut/vm_parse_ut.cpp index f34df2535c..ce3786a671 100644 --- a/library/cpp/scheme/tests/fuzz_ops/ut/vm_parse_ut.cpp +++ b/library/cpp/scheme/tests/fuzz_ops/ut/vm_parse_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/scheme/tests/fuzz_ops/lib/vm_parse.h> +#include <library/cpp/scheme/tests/fuzz_ops/lib/vm_parse.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TestParseNextAction) { diff --git a/library/cpp/scheme/tests/fuzz_ops/ut/ya.make b/library/cpp/scheme/tests/fuzz_ops/ut/ya.make index 1f6bf257aa..5c933518ea 100644 --- a/library/cpp/scheme/tests/fuzz_ops/ut/ya.make +++ b/library/cpp/scheme/tests/fuzz_ops/ut/ya.make @@ -4,8 +4,8 @@ OWNER(velavokr) PEERDIR( library/cpp/testing/unittest - library/cpp/scheme - library/cpp/scheme/tests/fuzz_ops/lib + library/cpp/scheme + library/cpp/scheme/tests/fuzz_ops/lib ) SRCS( diff --git a/library/cpp/scheme/tests/fuzz_ops/ya.make b/library/cpp/scheme/tests/fuzz_ops/ya.make index e7f3238c5f..025241ef20 100644 --- a/library/cpp/scheme/tests/fuzz_ops/ya.make +++ b/library/cpp/scheme/tests/fuzz_ops/ya.make @@ -12,7 +12,7 @@ SRCS( ) PEERDIR( - library/cpp/scheme/tests/fuzz_ops/lib + library/cpp/scheme/tests/fuzz_ops/lib ) END() diff --git a/library/cpp/scheme/tests/ut/fuzz_ops_found_bugs_ut.cpp b/library/cpp/scheme/tests/ut/fuzz_ops_found_bugs_ut.cpp index 9217615d3e..a445b0f87c 100644 --- a/library/cpp/scheme/tests/ut/fuzz_ops_found_bugs_ut.cpp +++ b/library/cpp/scheme/tests/ut/fuzz_ops_found_bugs_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scheme.h> -#include <library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.h> +#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/tests/fuzz_ops/lib/fuzz_ops.h> #include <library/cpp/testing/unittest/registar.h> #include <util/string/hex.h> diff --git a/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp b/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp index a4e0f09189..4f907157e9 100644 --- a/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_cast_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scheme.h> -#include <library/cpp/scheme/scheme_cast.h> +#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/scheme_cast.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/scheme/tests/ut/scheme_json_ut.cpp b/library/cpp/scheme/tests/ut/scheme_json_ut.cpp index cbd1840fd7..daeb2654f9 100644 --- a/library/cpp/scheme/tests/ut/scheme_json_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_json_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scimpl_private.h> -#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> +#include <library/cpp/scheme/scimpl_private.h> +#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/null.h> diff --git a/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp b/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp index e7c59e1edc..2a06cf110d 100644 --- a/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_merge_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scimpl_private.h> -#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> +#include <library/cpp/scheme/scimpl_private.h> +#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/null.h> diff --git a/library/cpp/scheme/tests/ut/scheme_path_ut.cpp b/library/cpp/scheme/tests/ut/scheme_path_ut.cpp index 743c0c7de8..0d4d79d483 100644 --- a/library/cpp/scheme/tests/ut/scheme_path_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_path_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scimpl_private.h> -#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> +#include <library/cpp/scheme/scimpl_private.h> +#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/null.h> diff --git a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp index abeda9d648..e711a0d092 100644 --- a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp @@ -1,6 +1,6 @@ -#include <library/cpp/protobuf/util/is_equal.h> -#include <library/cpp/scheme/scheme.h> -#include <library/cpp/scheme/tests/ut/scheme_ut.pb.h> +#include <library/cpp/protobuf/util/is_equal.h> +#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/tests/ut/scheme_ut.pb.h> #include <library/cpp/testing/unittest/registar.h> Y_UNIT_TEST_SUITE(TSchemeProtoTest) { diff --git a/library/cpp/scheme/tests/ut/scheme_ut.cpp b/library/cpp/scheme/tests/ut/scheme_ut.cpp index 93ba3207cd..1a5d07c31b 100644 --- a/library/cpp/scheme/tests/ut/scheme_ut.cpp +++ b/library/cpp/scheme/tests/ut/scheme_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/scheme/scimpl_private.h> -#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> +#include <library/cpp/scheme/scimpl_private.h> +#include <library/cpp/scheme/ut_utils/scheme_ut_utils.h> #include <library/cpp/testing/unittest/registar.h> #include <util/stream/null.h> diff --git a/library/cpp/scheme/tests/ut/ya.make b/library/cpp/scheme/tests/ut/ya.make index 5612fe1869..9f54791414 100644 --- a/library/cpp/scheme/tests/ut/ya.make +++ b/library/cpp/scheme/tests/ut/ya.make @@ -3,9 +3,9 @@ UNITTEST() OWNER(velavokr) PEERDIR( - library/cpp/protobuf/util - library/cpp/scheme/tests/fuzz_ops/lib - library/cpp/scheme/ut_utils + library/cpp/protobuf/util + library/cpp/scheme/tests/fuzz_ops/lib + library/cpp/scheme/ut_utils library/cpp/string_utils/quote library/cpp/testing/unittest ) diff --git a/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp index 22f2e99f26..0bbdab10e8 100644 --- a/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp +++ b/library/cpp/scheme/ut_utils/scheme_ut_utils.cpp @@ -1,6 +1,6 @@ #include "scheme_ut_utils.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/stream/str.h> diff --git a/library/cpp/scheme/ut_utils/scheme_ut_utils.h b/library/cpp/scheme/ut_utils/scheme_ut_utils.h index 025e69d54e..eb3ea15b2a 100644 --- a/library/cpp/scheme/ut_utils/scheme_ut_utils.h +++ b/library/cpp/scheme/ut_utils/scheme_ut_utils.h @@ -1,9 +1,9 @@ #pragma once -#include <library/cpp/json/json_prettifier.h> -#include <library/cpp/scheme/scheme.h> -#include <library/cpp/json/json_value.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_prettifier.h> +#include <library/cpp/scheme/scheme.h> +#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_writer.h> #include <library/cpp/testing/unittest/registar.h> #include <util/string/cast.h> diff --git a/library/cpp/scheme/ut_utils/ya.make b/library/cpp/scheme/ut_utils/ya.make index abb5dad24b..7661262e1b 100644 --- a/library/cpp/scheme/ut_utils/ya.make +++ b/library/cpp/scheme/ut_utils/ya.make @@ -7,9 +7,9 @@ SRCS( ) PEERDIR( - library/cpp/colorizer - library/cpp/json - library/cpp/scheme + library/cpp/colorizer + library/cpp/json + library/cpp/scheme library/cpp/testing/unittest ) diff --git a/library/cpp/scheme/util/scheme_holder.h b/library/cpp/scheme/util/scheme_holder.h index 61006ede10..f2fa16d1cd 100644 --- a/library/cpp/scheme/util/scheme_holder.h +++ b/library/cpp/scheme/util/scheme_holder.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/scheme.h> // Scheme adapter that holds referenced value diff --git a/library/cpp/scheme/util/utils.h b/library/cpp/scheme/util/utils.h index 6d38164dec..f7d666f67a 100644 --- a/library/cpp/scheme/util/utils.h +++ b/library/cpp/scheme/util/utils.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/scheme/scheme.h> +#include <library/cpp/scheme/scheme.h> #include <util/generic/strbuf.h> #include <util/ysaveload.h> diff --git a/library/cpp/scheme/ya.make b/library/cpp/scheme/ya.make index 54fcad05f4..bac08ba5a4 100644 --- a/library/cpp/scheme/ya.make +++ b/library/cpp/scheme/ya.make @@ -16,7 +16,7 @@ SRCS( PEERDIR( contrib/libs/protobuf - library/cpp/json + library/cpp/json library/cpp/string_utils/relaxed_escaper ) diff --git a/library/cpp/sliding_window/README.md b/library/cpp/sliding_window/README.md index fdf1e29425..47692da7d5 100644 --- a/library/cpp/sliding_window/README.md +++ b/library/cpp/sliding_window/README.md @@ -1,6 +1,6 @@ # TSlidingWindow - скользящее окно -[TSlidingWindow](/arc/trunk/arcadia/library/cpp/sliding_window/sliding_window.h) - класс скользящего окна, позволяющий поддерживать и обновлять определённое значение (максимум, сумму) в промежутке времени определённой длины. Разбивает общий временной промежуток на маленькие бакеты (число задаётся в конструкторе) и ротирует их, поддерживая значение за окно. Есть возможность также указать мьютекс или спинлок для синхронизации (по умолчанию TFakeMutex). Использование: +[TSlidingWindow](/arc/trunk/arcadia/library/cpp/sliding_window/sliding_window.h) - класс скользящего окна, позволяющий поддерживать и обновлять определённое значение (максимум, сумму) в промежутке времени определённой длины. Разбивает общий временной промежуток на маленькие бакеты (число задаётся в конструкторе) и ротирует их, поддерживая значение за окно. Есть возможность также указать мьютекс или спинлок для синхронизации (по умолчанию TFakeMutex). Использование: ``` // Создаём окно, вычисляющее максимум за последние пять минут, поддерживая 50 бакетов со значениями. diff --git a/library/cpp/sliding_window/ut/ya.make b/library/cpp/sliding_window/ut/ya.make index 9f280310c0..3839a8dadc 100644 --- a/library/cpp/sliding_window/ut/ya.make +++ b/library/cpp/sliding_window/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/sliding_window) +UNITTEST_FOR(library/cpp/sliding_window) OWNER(g:kikimr) diff --git a/library/cpp/streams/brotli/ut/ya.make b/library/cpp/streams/brotli/ut/ya.make index 5399b0d994..243462f1b2 100644 --- a/library/cpp/streams/brotli/ut/ya.make +++ b/library/cpp/streams/brotli/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/streams/brotli) +UNITTEST_FOR(library/cpp/streams/brotli) OWNER( levysotsky diff --git a/library/cpp/streams/bzip2/ut/ya.make b/library/cpp/streams/bzip2/ut/ya.make index 6fb70e3106..5ef91498ca 100644 --- a/library/cpp/streams/bzip2/ut/ya.make +++ b/library/cpp/streams/bzip2/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/streams/bzip2) +UNITTEST_FOR(library/cpp/streams/bzip2) OWNER( pg diff --git a/library/cpp/streams/lz/lz_ut.cpp b/library/cpp/streams/lz/lz_ut.cpp index 3c79bd1e10..6876f070fc 100644 --- a/library/cpp/streams/lz/lz_ut.cpp +++ b/library/cpp/streams/lz/lz_ut.cpp @@ -1,7 +1,7 @@ #include "lz.h" #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/resource/resource.h> +#include <library/cpp/resource/resource.h> #include <util/stream/file.h> #include <util/generic/vector.h> diff --git a/library/cpp/streams/lz/ut/ya.make b/library/cpp/streams/lz/ut/ya.make index aa004a021f..18288c8ac9 100644 --- a/library/cpp/streams/lz/ut/ya.make +++ b/library/cpp/streams/lz/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/streams/lz) +UNITTEST_FOR(library/cpp/streams/lz) OWNER( pg diff --git a/library/cpp/streams/lzma/ut/ya.make b/library/cpp/streams/lzma/ut/ya.make index 23b9df470f..01624f0259 100644 --- a/library/cpp/streams/lzma/ut/ya.make +++ b/library/cpp/streams/lzma/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/streams/lzma) +UNITTEST_FOR(library/cpp/streams/lzma) OWNER( pg diff --git a/library/cpp/streams/ya.make b/library/cpp/streams/ya.make index dfbc521940..7426a874ee 100644 --- a/library/cpp/streams/ya.make +++ b/library/cpp/streams/ya.make @@ -19,7 +19,7 @@ RECURSE( lzop/ut special special/ut - xz + xz zc_memory_input zstd zstd/ut diff --git a/library/cpp/streams/zstd/ut/ya.make b/library/cpp/streams/zstd/ut/ya.make index 5a311c3aaf..1b98f0ad5e 100644 --- a/library/cpp/streams/zstd/ut/ya.make +++ b/library/cpp/streams/zstd/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/streams/zstd) +UNITTEST_FOR(library/cpp/streams/zstd) OWNER( bulatman diff --git a/library/cpp/string_utils/ya.make b/library/cpp/string_utils/ya.make index d8c74c63ca..cd731bda95 100644 --- a/library/cpp/string_utils/ya.make +++ b/library/cpp/string_utils/ya.make @@ -20,7 +20,7 @@ RECURSE( parse_size/ut parse_vector parse_vector/ut - secret_string + secret_string quote quote/ut relaxed_escaper diff --git a/library/cpp/svnversion/test/main.cpp b/library/cpp/svnversion/test/main.cpp index 9c3304ed2b..3c8209047f 100644 --- a/library/cpp/svnversion/test/main.cpp +++ b/library/cpp/svnversion/test/main.cpp @@ -3,7 +3,7 @@ #include <util/system/compiler.h> #include <util/stream/output.h> -// ya make -DFORCE_VCS_INFO_UPDATE --vcs-file=<vcs.json> library/cpp/svnversion/test/ +// ya make -DFORCE_VCS_INFO_UPDATE --vcs-file=<vcs.json> library/cpp/svnversion/test/ // ./library/svnversion/test/test[.exe] int main() { Cout << "GetProgramSvnVersion(): " << GetProgramSvnVersion() << Endl; diff --git a/library/cpp/svnversion/test/ya.make b/library/cpp/svnversion/test/ya.make index 2a97a68598..59c0a2d970 100644 --- a/library/cpp/svnversion/test/ya.make +++ b/library/cpp/svnversion/test/ya.make @@ -1,6 +1,6 @@ OWNER(g:cpp-contrib) PROGRAM() -PEERDIR(library/cpp/svnversion) +PEERDIR(library/cpp/svnversion) SRCS(main.cpp) END() diff --git a/library/cpp/testing/benchmark/bench.cpp b/library/cpp/testing/benchmark/bench.cpp index 83f3a9b965..08d8708005 100644 --- a/library/cpp/testing/benchmark/bench.cpp +++ b/library/cpp/testing/benchmark/bench.cpp @@ -2,10 +2,10 @@ #include <contrib/libs/re2/re2/re2.h> -#include <library/cpp/colorizer/output.h> +#include <library/cpp/colorizer/output.h> #include <library/cpp/getopt/small/last_getopt.h> -#include <library/cpp/json/json_value.h> -#include <library/cpp/linear_regression/linear_regression.h> +#include <library/cpp/json/json_value.h> +#include <library/cpp/linear_regression/linear_regression.h> #include <library/cpp/threading/poor_man_openmp/thread_helper.h> #include <util/system/hp_timer.h> diff --git a/library/cpp/testing/benchmark/ya.make b/library/cpp/testing/benchmark/ya.make index 14b3592a22..f42be80698 100644 --- a/library/cpp/testing/benchmark/ya.make +++ b/library/cpp/testing/benchmark/ya.make @@ -12,10 +12,10 @@ SRCS( PEERDIR( contrib/libs/re2 - library/cpp/colorizer + library/cpp/colorizer library/cpp/getopt/small - library/cpp/json - library/cpp/linear_regression + library/cpp/json + library/cpp/linear_regression library/cpp/threading/poor_man_openmp ) diff --git a/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp b/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp index 072093ff01..97f19050e4 100644 --- a/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp +++ b/library/cpp/testing/gmock_in_unittest/example_ut/example_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/testing/gmock_in_unittest/gmock.h> +#include <library/cpp/testing/gmock_in_unittest/gmock.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/testing/gmock_in_unittest/example_ut/ya.make b/library/cpp/testing/gmock_in_unittest/example_ut/ya.make index 21e880565f..d2e5ee5d2a 100644 --- a/library/cpp/testing/gmock_in_unittest/example_ut/ya.make +++ b/library/cpp/testing/gmock_in_unittest/example_ut/ya.make @@ -3,7 +3,7 @@ UNITTEST() OWNER(galaxycrab) PEERDIR( - library/cpp/testing/gmock_in_unittest + library/cpp/testing/gmock_in_unittest ) SRCS( diff --git a/library/cpp/testing/unittest/registar.cpp b/library/cpp/testing/unittest/registar.cpp index 7c1c471e37..3679b768ed 100644 --- a/library/cpp/testing/unittest/registar.cpp +++ b/library/cpp/testing/unittest/registar.cpp @@ -1,7 +1,7 @@ #include "registar.h" #include <library/cpp/diff/diff.h> -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> #include <util/generic/bt_exception.h> #include <util/random/fast.h> diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index da68f91963..44517a0092 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/dbg_output/dump.h> +#include <library/cpp/dbg_output/dump.h> #include <util/generic/bt_exception.h> #include <util/generic/hash.h> diff --git a/library/cpp/testing/unittest/utmain.cpp b/library/cpp/testing/unittest/utmain.cpp index 31dd23cb0b..305bc6b40f 100644 --- a/library/cpp/testing/unittest/utmain.cpp +++ b/library/cpp/testing/unittest/utmain.cpp @@ -2,10 +2,10 @@ #include "registar.h" #include "utmain.h" -#include <library/cpp/colorizer/colors.h> +#include <library/cpp/colorizer/colors.h> -#include <library/cpp/json/writer/json.h> -#include <library/cpp/json/writer/json_value.h> +#include <library/cpp/json/writer/json.h> +#include <library/cpp/json/writer/json_value.h> #include <library/cpp/testing/common/env.h> #include <library/cpp/testing/hook/hook.h> diff --git a/library/cpp/testing/unittest/ya.make b/library/cpp/testing/unittest/ya.make index 965e601e9c..aaa4f2ba85 100644 --- a/library/cpp/testing/unittest/ya.make +++ b/library/cpp/testing/unittest/ya.make @@ -8,10 +8,10 @@ OWNER( ) PEERDIR( - library/cpp/colorizer - library/cpp/dbg_output + library/cpp/colorizer + library/cpp/dbg_output library/cpp/diff - library/cpp/json/writer + library/cpp/json/writer library/cpp/testing/common library/cpp/testing/hook ) diff --git a/library/cpp/testing/ya.make b/library/cpp/testing/ya.make index 313de61ef7..6a57ac2ee6 100644 --- a/library/cpp/testing/ya.make +++ b/library/cpp/testing/ya.make @@ -1,4 +1,4 @@ -RECURSE( +RECURSE( common benchmark benchmark/examples @@ -9,16 +9,16 @@ RECURSE( dump_clang_coverage gbenchmark_main gmock - gmock_in_unittest - gmock_in_unittest/example_ut + gmock_in_unittest + gmock_in_unittest/example_ut gtest gtest_boost_extensions gtest_extensions gtest_main gtest_protobuf hook - mock_server + mock_server unittest unittest_main - urlnorm -) + urlnorm +) diff --git a/library/cpp/threading/light_rw_lock/bench/lightrwlock_test.cpp b/library/cpp/threading/light_rw_lock/bench/lightrwlock_test.cpp index 8255a6e7fb..c3027ea544 100644 --- a/library/cpp/threading/light_rw_lock/bench/lightrwlock_test.cpp +++ b/library/cpp/threading/light_rw_lock/bench/lightrwlock_test.cpp @@ -13,7 +13,7 @@ using namespace NS_LightRWLock; #define LIGHT #ifdef RWSPINLOCK -#include <library/cpp/lwtrace/rwspinlock.h> +#include <library/cpp/lwtrace/rwspinlock.h> #endif #define CHECK_LOGIC 1 diff --git a/library/cpp/threading/skip_list/perf/main.cpp b/library/cpp/threading/skip_list/perf/main.cpp index b5f8a1a61a..4ad52049e7 100644 --- a/library/cpp/threading/skip_list/perf/main.cpp +++ b/library/cpp/threading/skip_list/perf/main.cpp @@ -2,7 +2,7 @@ #include <library/cpp/getopt/small/last_getopt.h> -#include <library/cpp/charset/ci_string.h> +#include <library/cpp/charset/ci_string.h> #include <util/datetime/base.h> #include <util/generic/map.h> #include <util/generic/vector.h> diff --git a/library/cpp/threading/skip_list/perf/ya.make b/library/cpp/threading/skip_list/perf/ya.make index 2dd32a882c..01bfafa404 100644 --- a/library/cpp/threading/skip_list/perf/ya.make +++ b/library/cpp/threading/skip_list/perf/ya.make @@ -3,7 +3,7 @@ PROGRAM(skiplist-perf) OWNER(g:rtmr) PEERDIR( - library/cpp/charset + library/cpp/charset library/cpp/getopt/small library/cpp/threading/skip_list ) diff --git a/library/cpp/timezone_conversion/README.md b/library/cpp/timezone_conversion/README.md index 6b7950a29c..828f1880bc 100644 --- a/library/cpp/timezone_conversion/README.md +++ b/library/cpp/timezone_conversion/README.md @@ -11,7 +11,7 @@ See [contrib/libs/cctz/README][update] if you think zone database is outdated. Quick start: ============ ``` -#include <library/cpp/timezone_conversion/convert.h> +#include <library/cpp/timezone_conversion/convert.h> // NDatetime::{GetLocalTimeZone(),GetUtcTimeZone()} are also available. NDatetime::TTimeZone msk = NDatetime::GetTimeZone("Europe/Moscow"); diff --git a/library/cpp/timezone_conversion/ut/civil_ut.cpp b/library/cpp/timezone_conversion/ut/civil_ut.cpp index 0a4d9a56d6..a21bd4bd7d 100644 --- a/library/cpp/timezone_conversion/ut/civil_ut.cpp +++ b/library/cpp/timezone_conversion/ut/civil_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/timezone_conversion/civil.h> +#include <library/cpp/timezone_conversion/civil.h> #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> diff --git a/library/cpp/timezone_conversion/ut/convert_ut.cpp b/library/cpp/timezone_conversion/ut/convert_ut.cpp index 086cafea29..bbf9e9b826 100644 --- a/library/cpp/timezone_conversion/ut/convert_ut.cpp +++ b/library/cpp/timezone_conversion/ut/convert_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/timezone_conversion/convert.h> +#include <library/cpp/timezone_conversion/convert.h> #include <library/cpp/testing/unittest/gtest.h> using namespace NDatetime; diff --git a/library/cpp/timezone_conversion/ut/ya.make b/library/cpp/timezone_conversion/ut/ya.make index 0b25e58ea7..781a57da9f 100644 --- a/library/cpp/timezone_conversion/ut/ya.make +++ b/library/cpp/timezone_conversion/ut/ya.make @@ -4,7 +4,7 @@ OWNER(dfyz) PEERDIR( library/cpp/testing/unittest - library/cpp/timezone_conversion + library/cpp/timezone_conversion ) SRCS( diff --git a/library/cpp/tld/tld.cpp b/library/cpp/tld/tld.cpp index a5c7715584..e31f3f0322 100644 --- a/library/cpp/tld/tld.cpp +++ b/library/cpp/tld/tld.cpp @@ -1,13 +1,13 @@ #include "tld.h" -#include <library/cpp/digest/lower_case/hash_ops.h> +#include <library/cpp/digest/lower_case/hash_ops.h> #include <util/generic/hash_set.h> #include <util/generic/singleton.h> namespace NTld { namespace { -#include <library/cpp/tld/tld.inc> +#include <library/cpp/tld/tld.inc> using TCiHash = THashSet<TStringBuf, TCIOps, TCIOps>; diff --git a/library/cpp/tld/tld_ut.cpp b/library/cpp/tld/tld_ut.cpp index 6ff1d74f24..733200f2b5 100644 --- a/library/cpp/tld/tld_ut.cpp +++ b/library/cpp/tld/tld_ut.cpp @@ -2,7 +2,7 @@ #include <library/cpp/testing/unittest/registar.h> -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> using namespace NTld; diff --git a/library/cpp/tld/ut/ya.make b/library/cpp/tld/ut/ya.make index 749d3f1f8b..0bc5b40b2f 100644 --- a/library/cpp/tld/ut/ya.make +++ b/library/cpp/tld/ut/ya.make @@ -3,10 +3,10 @@ UNITTEST() OWNER(abolkhovityanov) PEERDIR( - ADDINCL library/cpp/tld + ADDINCL library/cpp/tld ) -SRCDIR(library/cpp/tld) +SRCDIR(library/cpp/tld) SRCS( tld_ut.cpp diff --git a/library/cpp/tld/ya.make b/library/cpp/tld/ya.make index abd230d4c2..aeabbfeebf 100644 --- a/library/cpp/tld/ya.make +++ b/library/cpp/tld/ya.make @@ -13,7 +13,7 @@ SRCS( ) PEERDIR( - library/cpp/digest/lower_case + library/cpp/digest/lower_case ) END() diff --git a/library/cpp/tvmauth/README.md b/library/cpp/tvmauth/README.md index 85aec480d9..ec64bbbcdb 100644 --- a/library/cpp/tvmauth/README.md +++ b/library/cpp/tvmauth/README.md @@ -1,2 +1,2 @@ -This part of library contains primitives for TVM operation. -Please use high-level [TTvmClient](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/README.md). +This part of library contains primitives for TVM operation. +Please use high-level [TTvmClient](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/README.md). diff --git a/library/cpp/tvmauth/a.yaml b/library/cpp/tvmauth/a.yaml index 3d5d4b06fa..7f1e1b8fd8 100644 --- a/library/cpp/tvmauth/a.yaml +++ b/library/cpp/tvmauth/a.yaml @@ -1,23 +1,23 @@ -service: passport_infra -title: tvmauth (c++) - -ci: +service: passport_infra +title: tvmauth (c++) + +ci: release-title-source: flow - autocheck: - fast-targets: - - library/c/tvmauth - - library/cpp/tvmauth - - library/go/yandex/ticket_parser2 - - library/java/ticket_parser2 - - library/java/tvmauth - - library/python/deprecated/ticket_parser2 - - library/python/tvmauth - - passport - strong: true - -arcanum: - auto_merge: - enabled: true - requirements: - - system: arcanum - type: comment_issues_closed + autocheck: + fast-targets: + - library/c/tvmauth + - library/cpp/tvmauth + - library/go/yandex/ticket_parser2 + - library/java/ticket_parser2 + - library/java/tvmauth + - library/python/deprecated/ticket_parser2 + - library/python/tvmauth + - passport + strong: true + +arcanum: + auto_merge: + enabled: true + requirements: + - system: arcanum + type: comment_issues_closed diff --git a/library/cpp/tvmauth/checked_service_ticket.h b/library/cpp/tvmauth/checked_service_ticket.h index 30e42e7190..cf4c5c43e3 100644 --- a/library/cpp/tvmauth/checked_service_ticket.h +++ b/library/cpp/tvmauth/checked_service_ticket.h @@ -1,71 +1,71 @@ -#pragma once - -#include "ticket_status.h" -#include "type.h" -#include "utils.h" - -#include <util/generic/ptr.h> - -namespace NTvmAuth::NInternal { - class TCanningKnife; -} - -namespace NTvmAuth { - class TCheckedServiceTicket { - public: - class TImpl; - - TCheckedServiceTicket(THolder<TImpl> impl); - TCheckedServiceTicket(TCheckedServiceTicket&& o); - ~TCheckedServiceTicket(); - - TCheckedServiceTicket& operator=(TCheckedServiceTicket&&); - - /*! - * @return True value if ticket parsed and checked successfully - */ - explicit operator bool() const; - - /*! - * You should check src with your ACL - * @return TvmId of request source - */ - TTvmId GetSrc() const; - - /*! - * @return Ticket check status - */ - ETicketStatus GetStatus() const; - - /*! - * DebugInfo is human readable data for debug purposes - * @return Serialized ticket - */ - TString DebugInfo() const; - - /*! - * IssuerUID is UID of developer who is debuging something, - * so he(she) issued ServiceTicket with his(her) ssh-sign: - * it is grant_type=sshkey in tvm-api. - * https://wiki.yandex-team.ru/passport/tvm2/debug/#sxoditvapizakrytoeserviceticketami - * @return uid - */ - TMaybe<TUid> GetIssuerUid() const; - - public: // for python binding - TCheckedServiceTicket() = default; - - private: - THolder<TImpl> Impl_; - friend class NInternal::TCanningKnife; - }; - - namespace NBlackboxTvmId { - const TStringBuf Prod = "222"; - const TStringBuf Test = "224"; - const TStringBuf ProdYateam = "223"; - const TStringBuf TestYateam = "225"; - const TStringBuf Stress = "226"; - const TStringBuf Mimino = "239"; - } -} +#pragma once + +#include "ticket_status.h" +#include "type.h" +#include "utils.h" + +#include <util/generic/ptr.h> + +namespace NTvmAuth::NInternal { + class TCanningKnife; +} + +namespace NTvmAuth { + class TCheckedServiceTicket { + public: + class TImpl; + + TCheckedServiceTicket(THolder<TImpl> impl); + TCheckedServiceTicket(TCheckedServiceTicket&& o); + ~TCheckedServiceTicket(); + + TCheckedServiceTicket& operator=(TCheckedServiceTicket&&); + + /*! + * @return True value if ticket parsed and checked successfully + */ + explicit operator bool() const; + + /*! + * You should check src with your ACL + * @return TvmId of request source + */ + TTvmId GetSrc() const; + + /*! + * @return Ticket check status + */ + ETicketStatus GetStatus() const; + + /*! + * DebugInfo is human readable data for debug purposes + * @return Serialized ticket + */ + TString DebugInfo() const; + + /*! + * IssuerUID is UID of developer who is debuging something, + * so he(she) issued ServiceTicket with his(her) ssh-sign: + * it is grant_type=sshkey in tvm-api. + * https://wiki.yandex-team.ru/passport/tvm2/debug/#sxoditvapizakrytoeserviceticketami + * @return uid + */ + TMaybe<TUid> GetIssuerUid() const; + + public: // for python binding + TCheckedServiceTicket() = default; + + private: + THolder<TImpl> Impl_; + friend class NInternal::TCanningKnife; + }; + + namespace NBlackboxTvmId { + const TStringBuf Prod = "222"; + const TStringBuf Test = "224"; + const TStringBuf ProdYateam = "223"; + const TStringBuf TestYateam = "225"; + const TStringBuf Stress = "226"; + const TStringBuf Mimino = "239"; + } +} diff --git a/library/cpp/tvmauth/checked_user_ticket.h b/library/cpp/tvmauth/checked_user_ticket.h index 2c3d712e27..16a2a6dc30 100644 --- a/library/cpp/tvmauth/checked_user_ticket.h +++ b/library/cpp/tvmauth/checked_user_ticket.h @@ -1,91 +1,91 @@ -#pragma once - -#include "ticket_status.h" -#include "type.h" -#include "utils.h" - -#include <util/generic/ptr.h> - -namespace NTvmAuth::NInternal { - class TCanningKnife; -} - -namespace NTvmAuth { - /*! - * BlackboxEnv describes environment of Passport: - * https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#0-opredeljaemsjasokruzhenijami - */ - enum class EBlackboxEnv: ui8 { - Prod, - Test, - ProdYateam, - TestYateam, - Stress - }; - - /*! - * UserTicket contains only valid users. - * Details: https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#chtoestvusertickete - */ - class TCheckedUserTicket { - public: - class TImpl; - - TCheckedUserTicket(THolder<TImpl> impl); - TCheckedUserTicket(TCheckedUserTicket&&); - ~TCheckedUserTicket(); - - TCheckedUserTicket& operator=(TCheckedUserTicket&&); - - /*! - * @return True value if ticket parsed and checked successfully - */ - explicit operator bool() const; - - /*! - * Never empty - * @return UIDs of users listed in ticket - */ - const TUids& GetUids() const; - - /*! - * Maybe 0 - * @return Default user in ticket - */ - TUid GetDefaultUid() const; - - /*! - * Scopes inherited from credential - never empty - * @return Newly constructed vector of scopes - */ - const TScopes& GetScopes() const; - - /*! - * Check if scope presented in ticket - */ - bool HasScope(TStringBuf scopeName) const; - - /*! - * @return Ticket check status - */ - ETicketStatus GetStatus() const; - - /*! - * DebugInfo is human readable data for debug purposes - * @return Serialized ticket - */ - TString DebugInfo() const; - - /*! - * Env of user - */ - EBlackboxEnv GetEnv() const; - - public: // for python binding - TCheckedUserTicket() = default; - - private: - THolder<TImpl> Impl_; - friend class NInternal::TCanningKnife; - }; -} +#pragma once + +#include "ticket_status.h" +#include "type.h" +#include "utils.h" + +#include <util/generic/ptr.h> + +namespace NTvmAuth::NInternal { + class TCanningKnife; +} + +namespace NTvmAuth { + /*! + * BlackboxEnv describes environment of Passport: + * https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#0-opredeljaemsjasokruzhenijami + */ + enum class EBlackboxEnv: ui8 { + Prod, + Test, + ProdYateam, + TestYateam, + Stress + }; + + /*! + * UserTicket contains only valid users. + * Details: https://wiki.yandex-team.ru/passport/tvm2/user-ticket/#chtoestvusertickete + */ + class TCheckedUserTicket { + public: + class TImpl; + + TCheckedUserTicket(THolder<TImpl> impl); + TCheckedUserTicket(TCheckedUserTicket&&); + ~TCheckedUserTicket(); + + TCheckedUserTicket& operator=(TCheckedUserTicket&&); + + /*! + * @return True value if ticket parsed and checked successfully + */ + explicit operator bool() const; + + /*! + * Never empty + * @return UIDs of users listed in ticket + */ + const TUids& GetUids() const; + + /*! + * Maybe 0 + * @return Default user in ticket + */ + TUid GetDefaultUid() const; + + /*! + * Scopes inherited from credential - never empty + * @return Newly constructed vector of scopes + */ + const TScopes& GetScopes() const; + + /*! + * Check if scope presented in ticket + */ + bool HasScope(TStringBuf scopeName) const; + + /*! + * @return Ticket check status + */ + ETicketStatus GetStatus() const; + + /*! + * DebugInfo is human readable data for debug purposes + * @return Serialized ticket + */ + TString DebugInfo() const; + + /*! + * Env of user + */ + EBlackboxEnv GetEnv() const; + + public: // for python binding + TCheckedUserTicket() = default; + + private: + THolder<TImpl> Impl_; + friend class NInternal::TCanningKnife; + }; +} diff --git a/library/cpp/tvmauth/client/README.md b/library/cpp/tvmauth/client/README.md index 5686eb5c07..239f55de7a 100644 --- a/library/cpp/tvmauth/client/README.md +++ b/library/cpp/tvmauth/client/README.md @@ -1,56 +1,56 @@ -Overview -=== -This library provides ability to operate with TVM. Library is fast enough to get or check tickets for every request without burning CPU. - -[Home page of project](https://wiki.yandex-team.ru/passport/tvm2/) -You can find some examples in [here](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/examples). - -You can ask questions: [PASSPORTDUTY](https://st.yandex-team.ru/createTicket?queue=PASSPORTDUTY&_form=77618) - -TvmClient -=== -Don't forget to collect logs from client. -___ -`TvmClient` allowes: -1. `GetServiceTicketFor()` - to fetch ServiceTicket for outgoing request -2. `CheckServiceTicket()` - to check ServiceTicket from incoming request -3. `CheckUserTicket()` - to check UserTicket from incoming request - -All methods are thread-safe. - -You should check status of `CheckedServiceTicket` or `CheckedUserTicket` for equality 'Ok'. You can get ticket fields (src/uids/scopes) only for correct ticket. Otherwise exception will be thrown. -___ -You should check status of client with `GetStatus()`: -* `OK` - nothing to do here -* `Warning` - **you should trigger your monitoring alert** - - Normal operation of TvmClient is still possible but there are problems with refreshing cache, so it is expiring. - Is tvm-api.yandex.net accessible? - Have you changed your TVM-secret or your backend (dst) deleted its TVM-client? - -* `Error` - **you should trigger your monitoring alert and close this instance for user-traffic** - - TvmClient's cache is already invalid (expired) or soon will be: you can't check valid ServiceTicket or be authenticated by your backends (dsts) - -___ -Constructor creates system thread for refreshing cache - so do not fork your proccess after creating `TTvmClient` instance. Constructor leads to network I/O. Other methods always use memory. - -Exceptions maybe thrown from constructor: -* `TRetriableException` - maybe some network trouble: you can try to create client one more time. -* `TNonRetriableException` - settings are bad: fix them. -___ -You can choose way for fetching data for your service operation: -* http://localhost:{port}/tvm - recomended way -* https://tvm-api.yandex.net - -TvmTool ------------- -`TTvmClient` uses local http-interface to get state. This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). -See more: https://wiki.yandex-team.ru/passport/tvm2/tvm-daemon/. - -`TTvmClient` fetches configuration from tvmtool, so you need only to tell client how to connect to it and tell which alias of tvm id should be used for this `TvmClient` instance. - -TvmApi ------------- -First of all: please use `SetDiskCacheDir()` - it provides reliability for your service and for tvm-api. -Please check restrictions of this method. +Overview +=== +This library provides ability to operate with TVM. Library is fast enough to get or check tickets for every request without burning CPU. + +[Home page of project](https://wiki.yandex-team.ru/passport/tvm2/) +You can find some examples in [here](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/examples). + +You can ask questions: [PASSPORTDUTY](https://st.yandex-team.ru/createTicket?queue=PASSPORTDUTY&_form=77618) + +TvmClient +=== +Don't forget to collect logs from client. +___ +`TvmClient` allowes: +1. `GetServiceTicketFor()` - to fetch ServiceTicket for outgoing request +2. `CheckServiceTicket()` - to check ServiceTicket from incoming request +3. `CheckUserTicket()` - to check UserTicket from incoming request + +All methods are thread-safe. + +You should check status of `CheckedServiceTicket` or `CheckedUserTicket` for equality 'Ok'. You can get ticket fields (src/uids/scopes) only for correct ticket. Otherwise exception will be thrown. +___ +You should check status of client with `GetStatus()`: +* `OK` - nothing to do here +* `Warning` - **you should trigger your monitoring alert** + + Normal operation of TvmClient is still possible but there are problems with refreshing cache, so it is expiring. + Is tvm-api.yandex.net accessible? + Have you changed your TVM-secret or your backend (dst) deleted its TVM-client? + +* `Error` - **you should trigger your monitoring alert and close this instance for user-traffic** + + TvmClient's cache is already invalid (expired) or soon will be: you can't check valid ServiceTicket or be authenticated by your backends (dsts) + +___ +Constructor creates system thread for refreshing cache - so do not fork your proccess after creating `TTvmClient` instance. Constructor leads to network I/O. Other methods always use memory. + +Exceptions maybe thrown from constructor: +* `TRetriableException` - maybe some network trouble: you can try to create client one more time. +* `TNonRetriableException` - settings are bad: fix them. +___ +You can choose way for fetching data for your service operation: +* http://localhost:{port}/tvm - recomended way +* https://tvm-api.yandex.net + +TvmTool +------------ +`TTvmClient` uses local http-interface to get state. This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). +See more: https://wiki.yandex-team.ru/passport/tvm2/tvm-daemon/. + +`TTvmClient` fetches configuration from tvmtool, so you need only to tell client how to connect to it and tell which alias of tvm id should be used for this `TvmClient` instance. + +TvmApi +------------ +First of all: please use `SetDiskCacheDir()` - it provides reliability for your service and for tvm-api. +Please check restrictions of this method. diff --git a/library/cpp/tvmauth/client/client_status.cpp b/library/cpp/tvmauth/client/client_status.cpp index 861dfb9737..eca35ba22b 100644 --- a/library/cpp/tvmauth/client/client_status.cpp +++ b/library/cpp/tvmauth/client/client_status.cpp @@ -1,6 +1,6 @@ -#include "client_status.h" - -template <> -void Out<NTvmAuth::TClientStatus>(IOutputStream& out, const NTvmAuth::TClientStatus& s) { - out << s.GetCode() << ": " << s.GetLastError(); -} +#include "client_status.h" + +template <> +void Out<NTvmAuth::TClientStatus>(IOutputStream& out, const NTvmAuth::TClientStatus& s) { + out << s.GetCode() << ": " << s.GetLastError(); +} diff --git a/library/cpp/tvmauth/client/client_status.h b/library/cpp/tvmauth/client/client_status.h index 139fb109f6..bbaf29d289 100644 --- a/library/cpp/tvmauth/client/client_status.h +++ b/library/cpp/tvmauth/client/client_status.h @@ -1,82 +1,82 @@ -#pragma once - -#include <util/generic/string.h> -#include <util/string/builder.h> - -namespace NTvmAuth { - class TClientStatus { - public: - enum ECode { - Ok, - Warning, - Error, +#pragma once + +#include <util/generic/string.h> +#include <util/string/builder.h> + +namespace NTvmAuth { + class TClientStatus { + public: + enum ECode { + Ok, + Warning, + Error, IncompleteTicketsSet, - }; - - TClientStatus(ECode state, TString&& lastError) - : Code_(state) - , LastError_(std::move(lastError)) - { - } - - TClientStatus() = default; - TClientStatus(const TClientStatus&) = default; - TClientStatus(TClientStatus&&) = default; - - TClientStatus& operator=(const TClientStatus&) = default; - TClientStatus& operator=(TClientStatus&&) = default; - - ECode GetCode() const { - return Code_; - } - - const TString& GetLastError() const { - return LastError_; - } - - TString CreateJugglerMessage() const { + }; + + TClientStatus(ECode state, TString&& lastError) + : Code_(state) + , LastError_(std::move(lastError)) + { + } + + TClientStatus() = default; + TClientStatus(const TClientStatus&) = default; + TClientStatus(TClientStatus&&) = default; + + TClientStatus& operator=(const TClientStatus&) = default; + TClientStatus& operator=(TClientStatus&&) = default; + + ECode GetCode() const { + return Code_; + } + + const TString& GetLastError() const { + return LastError_; + } + + TString CreateJugglerMessage() const { return TStringBuilder() << GetJugglerCode() << ";TvmClient: " << LastError_ << "\n"; - } - - private: + } + + private: int32_t GetJugglerCode() const { switch (Code_) { case ECode::Ok: - return 0; // OK juggler check state + return 0; // OK juggler check state case ECode::Warning: case ECode::IncompleteTicketsSet: - return 1; // WARN juggler check state + return 1; // WARN juggler check state case ECode::Error: - return 2; // CRIT juggler check state + return 2; // CRIT juggler check state } return 2; // This should not happen, so set check state as CRIT. } - ECode Code_ = Ok; - TString LastError_; - }; - - static inline bool operator==(const TClientStatus& l, const TClientStatus& r) noexcept { - return l.GetCode() == r.GetCode() && l.GetLastError() == r.GetLastError(); - } - - static inline bool operator==(const TClientStatus& l, const TClientStatus::ECode r) noexcept { - return l.GetCode() == r; - } - - static inline bool operator==(const TClientStatus::ECode l, const TClientStatus& r) noexcept { - return r.GetCode() == l; - } - - static inline bool operator!=(const TClientStatus& l, const TClientStatus& r) noexcept { - return !(l == r); - } - - static inline bool operator!=(const TClientStatus& l, const TClientStatus::ECode r) noexcept { - return !(l == r); - } - - static inline bool operator!=(const TClientStatus::ECode l, const TClientStatus& r) noexcept { - return !(l == r); - } -} + ECode Code_ = Ok; + TString LastError_; + }; + + static inline bool operator==(const TClientStatus& l, const TClientStatus& r) noexcept { + return l.GetCode() == r.GetCode() && l.GetLastError() == r.GetLastError(); + } + + static inline bool operator==(const TClientStatus& l, const TClientStatus::ECode r) noexcept { + return l.GetCode() == r; + } + + static inline bool operator==(const TClientStatus::ECode l, const TClientStatus& r) noexcept { + return r.GetCode() == l; + } + + static inline bool operator!=(const TClientStatus& l, const TClientStatus& r) noexcept { + return !(l == r); + } + + static inline bool operator!=(const TClientStatus& l, const TClientStatus::ECode r) noexcept { + return !(l == r); + } + + static inline bool operator!=(const TClientStatus::ECode l, const TClientStatus& r) noexcept { + return !(l == r); + } +} diff --git a/library/cpp/tvmauth/client/examples/create_with_tvmapi/create.cpp b/library/cpp/tvmauth/client/examples/create_with_tvmapi/create.cpp index dfcd81377b..c03a7a032f 100644 --- a/library/cpp/tvmauth/client/examples/create_with_tvmapi/create.cpp +++ b/library/cpp/tvmauth/client/examples/create_with_tvmapi/create.cpp @@ -1,102 +1,102 @@ -#include <library/cpp/tvmauth/client/facade.h> - -namespace NExample { - NTvmAuth::TTvmClient CreateClientForCheckingAllTicketsAndFetchingServiceTickets() { - NTvmAuth::NTvmApi::TClientSettings setts{ - .DiskCacheDir = "/var/cache/my_service/tvm/", - .SelfTvmId = 11, - .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", - .FetchServiceTicketsForDstsWithAliases = { - {"bb", 224}, - {"datasync", 2000060}, - }, - .CheckServiceTickets = true, - .CheckUserTicketsWithBbEnv = NTvmAuth::EBlackboxEnv::Test, - }; - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - // c.CheckServiceTicket("some service ticket") - // c.CheckUserTicket("some user ticket") - // c.GetServiceTicketFor("bb") - // c.GetServiceTicketFor(224) - - return c; - } - - NTvmAuth::TTvmClient CreateClientForCheckingAllTickets() { - NTvmAuth::NTvmApi::TClientSettings setts{ - .DiskCacheDir = "/var/cache/my_service/tvm/", - .SelfTvmId = 11, - .CheckServiceTickets = true, - .CheckUserTicketsWithBbEnv = NTvmAuth::EBlackboxEnv::Test, - }; - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - // c.CheckServiceTicket("some service ticket") - // c.CheckUserTicket("some user ticket") - - return c; - } - - NTvmAuth::TTvmClient CreateClientForFetchingServiceTickets() { - NTvmAuth::NTvmApi::TClientSettings setts{ - .DiskCacheDir = "/var/cache/my_service/tvm/", - .SelfTvmId = 11, - .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", - .FetchServiceTicketsForDstsWithAliases = { - {"bb", 224}, - {"datasync", 2000060}, - }, - }; - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - // c.GetServiceTicketFor("bb") - // c.GetServiceTicketFor(224) - - return c; - } - - NTvmAuth::TTvmClient CreateClientForCheckingServiceTickets() { - NTvmAuth::NTvmApi::TClientSettings setts{ - .DiskCacheDir = "/var/cache/my_service/tvm/", - .SelfTvmId = 11, - .CheckServiceTickets = true, - }; - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - // c.CheckServiceTicket("some service ticket") - - return c; - } - - NTvmAuth::TTvmClient CreateClientForCheckingServiceTicketsWithRoles() { - NTvmAuth::NTvmApi::TClientSettings setts{ - .DiskCacheDir = "/var/cache/my_service/tvm/", - .SelfTvmId = 11, - .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", - .CheckServiceTickets = true, - .FetchRolesForIdmSystemSlug = "passporttestservice", - }; - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - // auto t = c.CheckServiceTicket("some service ticket") - // c.GetRoles()->CheckServiceRole(t, "some role"); - - return c; - } -} +#include <library/cpp/tvmauth/client/facade.h> + +namespace NExample { + NTvmAuth::TTvmClient CreateClientForCheckingAllTicketsAndFetchingServiceTickets() { + NTvmAuth::NTvmApi::TClientSettings setts{ + .DiskCacheDir = "/var/cache/my_service/tvm/", + .SelfTvmId = 11, + .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", + .FetchServiceTicketsForDstsWithAliases = { + {"bb", 224}, + {"datasync", 2000060}, + }, + .CheckServiceTickets = true, + .CheckUserTicketsWithBbEnv = NTvmAuth::EBlackboxEnv::Test, + }; + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + // c.CheckServiceTicket("some service ticket") + // c.CheckUserTicket("some user ticket") + // c.GetServiceTicketFor("bb") + // c.GetServiceTicketFor(224) + + return c; + } + + NTvmAuth::TTvmClient CreateClientForCheckingAllTickets() { + NTvmAuth::NTvmApi::TClientSettings setts{ + .DiskCacheDir = "/var/cache/my_service/tvm/", + .SelfTvmId = 11, + .CheckServiceTickets = true, + .CheckUserTicketsWithBbEnv = NTvmAuth::EBlackboxEnv::Test, + }; + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + // c.CheckServiceTicket("some service ticket") + // c.CheckUserTicket("some user ticket") + + return c; + } + + NTvmAuth::TTvmClient CreateClientForFetchingServiceTickets() { + NTvmAuth::NTvmApi::TClientSettings setts{ + .DiskCacheDir = "/var/cache/my_service/tvm/", + .SelfTvmId = 11, + .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", + .FetchServiceTicketsForDstsWithAliases = { + {"bb", 224}, + {"datasync", 2000060}, + }, + }; + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + // c.GetServiceTicketFor("bb") + // c.GetServiceTicketFor(224) + + return c; + } + + NTvmAuth::TTvmClient CreateClientForCheckingServiceTickets() { + NTvmAuth::NTvmApi::TClientSettings setts{ + .DiskCacheDir = "/var/cache/my_service/tvm/", + .SelfTvmId = 11, + .CheckServiceTickets = true, + }; + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + // c.CheckServiceTicket("some service ticket") + + return c; + } + + NTvmAuth::TTvmClient CreateClientForCheckingServiceTicketsWithRoles() { + NTvmAuth::NTvmApi::TClientSettings setts{ + .DiskCacheDir = "/var/cache/my_service/tvm/", + .SelfTvmId = 11, + .Secret = (TStringBuf) "AAAAAAAAAAAAAAAAAAAAAA", + .CheckServiceTickets = true, + .FetchRolesForIdmSystemSlug = "passporttestservice", + }; + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + // auto t = c.CheckServiceTicket("some service ticket") + // c.GetRoles()->CheckServiceRole(t, "some role"); + + return c; + } +} diff --git a/library/cpp/tvmauth/client/examples/create_with_tvmapi/ya.make b/library/cpp/tvmauth/client/examples/create_with_tvmapi/ya.make index 497094e0d0..fc69a06dbd 100644 --- a/library/cpp/tvmauth/client/examples/create_with_tvmapi/ya.make +++ b/library/cpp/tvmauth/client/examples/create_with_tvmapi/ya.make @@ -1,13 +1,13 @@ -LIBRARY() - -OWNER(g:passport_infra) - -PEERDIR( - library/cpp/tvmauth/client -) - -SRCS( - create.cpp -) - -END() +LIBRARY() + +OWNER(g:passport_infra) + +PEERDIR( + library/cpp/tvmauth/client +) + +SRCS( + create.cpp +) + +END() diff --git a/library/cpp/tvmauth/client/examples/create_with_tvmtool/create.cpp b/library/cpp/tvmauth/client/examples/create_with_tvmtool/create.cpp index 606c165be5..a87d3e705d 100644 --- a/library/cpp/tvmauth/client/examples/create_with_tvmtool/create.cpp +++ b/library/cpp/tvmauth/client/examples/create_with_tvmtool/create.cpp @@ -1,34 +1,34 @@ -#include <library/cpp/tvmauth/client/facade.h> - -namespace NExample { - // Possibility of using functions depends on config of tvmtool - // CheckServiceTicket - // CheckUserTicket - // GetServiceTicketFor - - NTvmAuth::TTvmClient CreateClientInQloudOrYandexDeploy() { - NTvmAuth::NTvmTool::TClientSettings setts( - "my_service" // specified in Qloud/YP/tvmtool interface - ); - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - return c; - } - - NTvmAuth::TTvmClient CreateClientForDevOrTests() { - NTvmAuth::NTvmTool::TClientSettings setts( - "my_service" // specified in Qloud/YP/tvmtool interface - ); - setts.SetPort(18080); - setts.SetAuthToken("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); - - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - NTvmAuth::TTvmClient c(setts, log); - - return c; - } -} +#include <library/cpp/tvmauth/client/facade.h> + +namespace NExample { + // Possibility of using functions depends on config of tvmtool + // CheckServiceTicket + // CheckUserTicket + // GetServiceTicketFor + + NTvmAuth::TTvmClient CreateClientInQloudOrYandexDeploy() { + NTvmAuth::NTvmTool::TClientSettings setts( + "my_service" // specified in Qloud/YP/tvmtool interface + ); + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + return c; + } + + NTvmAuth::TTvmClient CreateClientForDevOrTests() { + NTvmAuth::NTvmTool::TClientSettings setts( + "my_service" // specified in Qloud/YP/tvmtool interface + ); + setts.SetPort(18080); + setts.SetAuthToken("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"); + + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + NTvmAuth::TTvmClient c(setts, log); + + return c; + } +} diff --git a/library/cpp/tvmauth/client/examples/create_with_tvmtool/ya.make b/library/cpp/tvmauth/client/examples/create_with_tvmtool/ya.make index 497094e0d0..fc69a06dbd 100644 --- a/library/cpp/tvmauth/client/examples/create_with_tvmtool/ya.make +++ b/library/cpp/tvmauth/client/examples/create_with_tvmtool/ya.make @@ -1,13 +1,13 @@ -LIBRARY() - -OWNER(g:passport_infra) - -PEERDIR( - library/cpp/tvmauth/client -) - -SRCS( - create.cpp -) - -END() +LIBRARY() + +OWNER(g:passport_infra) + +PEERDIR( + library/cpp/tvmauth/client +) + +SRCS( + create.cpp +) + +END() diff --git a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.cpp b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.cpp index f471f7068a..075bf0bded 100644 --- a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.cpp +++ b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.cpp @@ -1,84 +1,84 @@ -#include "service.h" - -#include <library/cpp/tvmauth/client/facade.h> - +#include "service.h" + +#include <library/cpp/tvmauth/client/facade.h> + #include <library/cpp/cgiparam/cgiparam.h> -#include <library/cpp/http/server/response.h> -#include <library/cpp/http/simple/http_client.h> -#include <library/cpp/json/json_reader.h> - -namespace NExample { - static const TString BACK_C = "BACK_C"; - - TSomeService::TSomeService(const TConfig& cfg) - : Config_(cfg) - { - NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); - - Tvm_ = MakeHolder<NTvmAuth::TTvmClient>( - NTvmAuth::NTvmTool::TClientSettings( - "my_service" // specified in Qloud/YP/tvmtool interface - ), - log); - } - - TSomeService::~TSomeService() { - } - - void TSomeService::HandleRequest(THttpInput& in, THttpOutput& out) { - auto servIt = std::find_if(in.Headers().Begin(), - in.Headers().End(), - [](const auto& h) { return h.Name() == "X-Ya-Service-Ticket"; }); - auto userIt = std::find_if(in.Headers().Begin(), - in.Headers().End(), - [](const auto& h) { return h.Name() == "X-Ya-User-Ticket"; }); - try { - if (servIt == in.Headers().End() || userIt == in.Headers().End()) { - ythrow yexception() << "Need tickets"; - } - - // WARNING: См. Здесь - NTvmAuth::TCheckedServiceTicket st = Tvm_->CheckServiceTicket(servIt->Value()); - NTvmAuth::TCheckedUserTicket ut = Tvm_->CheckUserTicket(userIt->Value()); - if (!st || !ut) { - ythrow yexception() << "Invalid tickets"; - } - - // WARNING: См. Здесь - // Ждём ABC - после их релиза эти три строки можно будет удалить - if (Config_.AllowedTvmIds.find(st.GetSrc()) == Config_.AllowedTvmIds.end()) { - ythrow yexception() << "Consumer is not allowed"; - } - - // WARNING: См. Здесь - if (!ut.HasScope("some_service:allow_secret_data")) { - ythrow yexception() << "UserTicket does not have scopes for secret data"; - } - - // Access-log - Cout << "Data fetched for: " << ut.GetDefaultUid() << Endl; - - THttpResponse resp(HTTP_OK); - resp.SetContent(GetDataFromBackendC(userIt->Value()), "text/plain"); - resp.OutTo(out); - } catch (...) { - THttpResponse resp(HTTP_BAD_REQUEST); - resp.SetContent("Request can not be performed", "text/plain"); - resp.OutTo(out); - } - - out.Finish(); - } - - TString TSomeService::GetDataFromBackendC(const TString& userTicket) { - TSimpleHttpClient cl("my_backend", // specified in Qloud/YP/tvmtool interface - 80); - TStringStream s; - cl.DoGet("/api?", - &s, - // WARNING: См. Здесь - {{"X-Ya-Service-Ticket", Tvm_->GetServiceTicketFor(BACK_C)}, - {"X-Ya-User-Ticket", userTicket}}); - return s.Str(); - } -} +#include <library/cpp/http/server/response.h> +#include <library/cpp/http/simple/http_client.h> +#include <library/cpp/json/json_reader.h> + +namespace NExample { + static const TString BACK_C = "BACK_C"; + + TSomeService::TSomeService(const TConfig& cfg) + : Config_(cfg) + { + NTvmAuth::TLoggerPtr log = MakeIntrusive<NTvmAuth::TCerrLogger>(7); + + Tvm_ = MakeHolder<NTvmAuth::TTvmClient>( + NTvmAuth::NTvmTool::TClientSettings( + "my_service" // specified in Qloud/YP/tvmtool interface + ), + log); + } + + TSomeService::~TSomeService() { + } + + void TSomeService::HandleRequest(THttpInput& in, THttpOutput& out) { + auto servIt = std::find_if(in.Headers().Begin(), + in.Headers().End(), + [](const auto& h) { return h.Name() == "X-Ya-Service-Ticket"; }); + auto userIt = std::find_if(in.Headers().Begin(), + in.Headers().End(), + [](const auto& h) { return h.Name() == "X-Ya-User-Ticket"; }); + try { + if (servIt == in.Headers().End() || userIt == in.Headers().End()) { + ythrow yexception() << "Need tickets"; + } + + // WARNING: См. Здесь + NTvmAuth::TCheckedServiceTicket st = Tvm_->CheckServiceTicket(servIt->Value()); + NTvmAuth::TCheckedUserTicket ut = Tvm_->CheckUserTicket(userIt->Value()); + if (!st || !ut) { + ythrow yexception() << "Invalid tickets"; + } + + // WARNING: См. Здесь + // Ждём ABC - после их релиза эти три строки можно будет удалить + if (Config_.AllowedTvmIds.find(st.GetSrc()) == Config_.AllowedTvmIds.end()) { + ythrow yexception() << "Consumer is not allowed"; + } + + // WARNING: См. Здесь + if (!ut.HasScope("some_service:allow_secret_data")) { + ythrow yexception() << "UserTicket does not have scopes for secret data"; + } + + // Access-log + Cout << "Data fetched for: " << ut.GetDefaultUid() << Endl; + + THttpResponse resp(HTTP_OK); + resp.SetContent(GetDataFromBackendC(userIt->Value()), "text/plain"); + resp.OutTo(out); + } catch (...) { + THttpResponse resp(HTTP_BAD_REQUEST); + resp.SetContent("Request can not be performed", "text/plain"); + resp.OutTo(out); + } + + out.Finish(); + } + + TString TSomeService::GetDataFromBackendC(const TString& userTicket) { + TSimpleHttpClient cl("my_backend", // specified in Qloud/YP/tvmtool interface + 80); + TStringStream s; + cl.DoGet("/api?", + &s, + // WARNING: См. Здесь + {{"X-Ya-Service-Ticket", Tvm_->GetServiceTicketFor(BACK_C)}, + {"X-Ya-User-Ticket", userTicket}}); + return s.Str(); + } +} diff --git a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.h b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.h index 761fd0f248..8ff948334e 100644 --- a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.h +++ b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/service.h @@ -1,35 +1,35 @@ -#pragma once - -#include <library/cpp/http/io/stream.h> - -#include <util/generic/ptr.h> - -#include <unordered_set> - -namespace NTvmAuth { - class TTvmClient; -} - -namespace NExample { - struct TConfig { - using TAllowedTvmIds = std::unordered_set<ui32>; - - TAllowedTvmIds AllowedTvmIds; - }; - - class TSomeService { - public: - TSomeService(const TConfig& cfg); - ~TSomeService(); - - void HandleRequest(THttpInput& in, THttpOutput& out); - - private: - TString GetDataFromBackendC(const TString& userTicket); - - private: - // WARNING: См. Здесь - TConfig Config_; - THolder<NTvmAuth::TTvmClient> Tvm_; - }; -} +#pragma once + +#include <library/cpp/http/io/stream.h> + +#include <util/generic/ptr.h> + +#include <unordered_set> + +namespace NTvmAuth { + class TTvmClient; +} + +namespace NExample { + struct TConfig { + using TAllowedTvmIds = std::unordered_set<ui32>; + + TAllowedTvmIds AllowedTvmIds; + }; + + class TSomeService { + public: + TSomeService(const TConfig& cfg); + ~TSomeService(); + + void HandleRequest(THttpInput& in, THttpOutput& out); + + private: + TString GetDataFromBackendC(const TString& userTicket); + + private: + // WARNING: См. Здесь + TConfig Config_; + THolder<NTvmAuth::TTvmClient> Tvm_; + }; +} diff --git a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/ya.make b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/ya.make index 8d82901738..dde9e7a00d 100644 --- a/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/ya.make +++ b/library/cpp/tvmauth/client/examples/service_using_tvmtool_client/ya.make @@ -1,15 +1,15 @@ -LIBRARY() - -OWNER(g:passport_infra) - -PEERDIR( +LIBRARY() + +OWNER(g:passport_infra) + +PEERDIR( library/cpp/cgiparam - library/cpp/http/simple - library/cpp/tvmauth/client -) - -SRCS( - service.cpp -) - -END() + library/cpp/http/simple + library/cpp/tvmauth/client +) + +SRCS( + service.cpp +) + +END() diff --git a/library/cpp/tvmauth/client/examples/ya.make b/library/cpp/tvmauth/client/examples/ya.make index 2bd58586d1..cd17e550a6 100644 --- a/library/cpp/tvmauth/client/examples/ya.make +++ b/library/cpp/tvmauth/client/examples/ya.make @@ -1,5 +1,5 @@ -RECURSE( - create_with_tvmapi - create_with_tvmtool - service_using_tvmtool_client -) +RECURSE( + create_with_tvmapi + create_with_tvmtool + service_using_tvmtool_client +) diff --git a/library/cpp/tvmauth/client/exception.h b/library/cpp/tvmauth/client/exception.h index aaa5827752..7639467671 100644 --- a/library/cpp/tvmauth/client/exception.h +++ b/library/cpp/tvmauth/client/exception.h @@ -1,23 +1,23 @@ -#pragma once - -#include <library/cpp/tvmauth/exception.h> - -namespace NTvmAuth { - class TClientException: public TTvmException { - }; - - class TRetriableException: public TClientException { - }; - class TNonRetriableException: public TClientException { - }; - - class TIllegalUsage: public TNonRetriableException { - }; - - class TBrokenTvmClientSettings: public TIllegalUsage { - }; - class TMissingServiceTicket: public TNonRetriableException { - }; - class TPermissionDenied: public TNonRetriableException { - }; -} +#pragma once + +#include <library/cpp/tvmauth/exception.h> + +namespace NTvmAuth { + class TClientException: public TTvmException { + }; + + class TRetriableException: public TClientException { + }; + class TNonRetriableException: public TClientException { + }; + + class TIllegalUsage: public TNonRetriableException { + }; + + class TBrokenTvmClientSettings: public TIllegalUsage { + }; + class TMissingServiceTicket: public TNonRetriableException { + }; + class TPermissionDenied: public TNonRetriableException { + }; +} diff --git a/library/cpp/tvmauth/client/facade.cpp b/library/cpp/tvmauth/client/facade.cpp index 786bab493c..6e77569441 100644 --- a/library/cpp/tvmauth/client/facade.cpp +++ b/library/cpp/tvmauth/client/facade.cpp @@ -1,131 +1,131 @@ -#include "facade.h" - -#include "misc/checker.h" -#include "misc/default_uid_checker.h" -#include "misc/getter.h" -#include "misc/src_checker.h" -#include "misc/api/threaded_updater.h" -#include "misc/tool/threaded_updater.h" - -namespace NTvmAuth { - TTvmClient::TTvmClient(const NTvmTool::TClientSettings& settings, TLoggerPtr logger) - : Updater_(NTvmTool::TThreadedUpdater::Create(settings, std::move(logger))) - , Service_(MakeHolder<TServiceTicketChecker>(Updater_)) - , User_(MakeHolder<TUserTicketChecker>(Updater_)) - { - if (Updater_->GetCachedServiceTickets()) { - Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); - } - } - - TTvmClient::TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) - : Updater_(NTvmApi::TThreadedUpdater::Create(settings, std::move(logger))) - { - if (settings.IsServiceTicketFetchingRequired()) { - Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); - } - if (settings.IsServiceTicketCheckingRequired()) { - Service_ = MakeHolder<TServiceTicketChecker>(Updater_); - } - if (settings.IsUserTicketCheckingRequired()) { - User_ = MakeHolder<TUserTicketChecker>(Updater_); - } - if (settings.IsRolesFetchingEnabled() && settings.ShouldCheckSrc) { - SrcChecker_ = MakeHolder<TSrcChecker>(Updater_); - } - if (settings.IsRolesFetchingEnabled() && settings.ShouldCheckDefaultUid) { - DefaultUidChecker_ = MakeHolder<TDefaultUidChecker>(Updater_); - } - } - - TTvmClient::TTvmClient(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - if (Updater_->GetCachedServiceTickets()) { - Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); - } - if (Updater_->GetCachedServiceContext()) { - Service_ = MakeHolder<TServiceTicketChecker>(Updater_); - } - if (Updater_->GetCachedUserContext()) { - User_ = MakeHolder<TUserTicketChecker>(Updater_); - } - - try { - if (Updater_->GetRoles()) { - SrcChecker_ = MakeHolder<TSrcChecker>(Updater_); - DefaultUidChecker_ = MakeHolder<TDefaultUidChecker>(Updater_); - } - } catch (const TIllegalUsage&) { - // it is a test probably - } - } - - TTvmClient::TTvmClient(TTvmClient&& o) = default; - TTvmClient::~TTvmClient() = default; - TTvmClient& TTvmClient::operator=(TTvmClient&& o) = default; - - TClientStatus TTvmClient::GetStatus() const { - Y_ENSURE(Updater_); - return Updater_->GetStatus(); - } - - TInstant TTvmClient::GetUpdateTimeOfPublicKeys() const { - Y_ENSURE(Updater_); - return Updater_->GetUpdateTimeOfPublicKeys(); - } - - TInstant TTvmClient::GetUpdateTimeOfServiceTickets() const { - Y_ENSURE(Updater_); - return Updater_->GetUpdateTimeOfServiceTickets(); - } - - TInstant TTvmClient::GetInvalidationTimeOfPublicKeys() const { - Y_ENSURE(Updater_); - return Updater_->GetInvalidationTimeOfPublicKeys(); - } - - TInstant TTvmClient::GetInvalidationTimeOfServiceTickets() const { - Y_ENSURE(Updater_); - return Updater_->GetInvalidationTimeOfServiceTickets(); - } - - TString TTvmClient::GetServiceTicketFor(const TClientSettings::TAlias& dst) const { - Y_ENSURE_EX(Tickets_, TBrokenTvmClientSettings() - << "Need to enable ServiceTickets fetching"); - return Tickets_->GetTicket(dst); - } - - TString TTvmClient::GetServiceTicketFor(const TTvmId dst) const { - Y_ENSURE_EX(Tickets_, TBrokenTvmClientSettings() - << "Need to enable ServiceTickets fetching"); - return Tickets_->GetTicket(dst); - } - - TCheckedServiceTicket TTvmClient::CheckServiceTicket(TStringBuf ticket) const { - Y_ENSURE_EX(Service_, TBrokenTvmClientSettings() - << "Need to use TClientSettings::EnableServiceTicketChecking()"); - - TCheckedServiceTicket res = Service_->Check(ticket); - if (SrcChecker_ && res) { - return SrcChecker_->Check(std::move(res)); - } - return res; - } - - TCheckedUserTicket TTvmClient::CheckUserTicket(TStringBuf ticket, TMaybe<EBlackboxEnv> overrideEnv) const { - Y_ENSURE_EX(User_, TBrokenTvmClientSettings() - << "Need to use TClientSettings::EnableUserTicketChecking()"); - - TCheckedUserTicket res = User_->Check(ticket, overrideEnv); - if (DefaultUidChecker_ && res) { - return DefaultUidChecker_->Check(std::move(res)); - } - return User_->Check(ticket, overrideEnv); - } - - NRoles::TRolesPtr TTvmClient::GetRoles() const { - Y_ENSURE(Updater_); - return Updater_->GetRoles(); - } -} +#include "facade.h" + +#include "misc/checker.h" +#include "misc/default_uid_checker.h" +#include "misc/getter.h" +#include "misc/src_checker.h" +#include "misc/api/threaded_updater.h" +#include "misc/tool/threaded_updater.h" + +namespace NTvmAuth { + TTvmClient::TTvmClient(const NTvmTool::TClientSettings& settings, TLoggerPtr logger) + : Updater_(NTvmTool::TThreadedUpdater::Create(settings, std::move(logger))) + , Service_(MakeHolder<TServiceTicketChecker>(Updater_)) + , User_(MakeHolder<TUserTicketChecker>(Updater_)) + { + if (Updater_->GetCachedServiceTickets()) { + Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); + } + } + + TTvmClient::TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) + : Updater_(NTvmApi::TThreadedUpdater::Create(settings, std::move(logger))) + { + if (settings.IsServiceTicketFetchingRequired()) { + Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); + } + if (settings.IsServiceTicketCheckingRequired()) { + Service_ = MakeHolder<TServiceTicketChecker>(Updater_); + } + if (settings.IsUserTicketCheckingRequired()) { + User_ = MakeHolder<TUserTicketChecker>(Updater_); + } + if (settings.IsRolesFetchingEnabled() && settings.ShouldCheckSrc) { + SrcChecker_ = MakeHolder<TSrcChecker>(Updater_); + } + if (settings.IsRolesFetchingEnabled() && settings.ShouldCheckDefaultUid) { + DefaultUidChecker_ = MakeHolder<TDefaultUidChecker>(Updater_); + } + } + + TTvmClient::TTvmClient(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + if (Updater_->GetCachedServiceTickets()) { + Tickets_ = MakeHolder<TServiceTicketGetter>(Updater_); + } + if (Updater_->GetCachedServiceContext()) { + Service_ = MakeHolder<TServiceTicketChecker>(Updater_); + } + if (Updater_->GetCachedUserContext()) { + User_ = MakeHolder<TUserTicketChecker>(Updater_); + } + + try { + if (Updater_->GetRoles()) { + SrcChecker_ = MakeHolder<TSrcChecker>(Updater_); + DefaultUidChecker_ = MakeHolder<TDefaultUidChecker>(Updater_); + } + } catch (const TIllegalUsage&) { + // it is a test probably + } + } + + TTvmClient::TTvmClient(TTvmClient&& o) = default; + TTvmClient::~TTvmClient() = default; + TTvmClient& TTvmClient::operator=(TTvmClient&& o) = default; + + TClientStatus TTvmClient::GetStatus() const { + Y_ENSURE(Updater_); + return Updater_->GetStatus(); + } + + TInstant TTvmClient::GetUpdateTimeOfPublicKeys() const { + Y_ENSURE(Updater_); + return Updater_->GetUpdateTimeOfPublicKeys(); + } + + TInstant TTvmClient::GetUpdateTimeOfServiceTickets() const { + Y_ENSURE(Updater_); + return Updater_->GetUpdateTimeOfServiceTickets(); + } + + TInstant TTvmClient::GetInvalidationTimeOfPublicKeys() const { + Y_ENSURE(Updater_); + return Updater_->GetInvalidationTimeOfPublicKeys(); + } + + TInstant TTvmClient::GetInvalidationTimeOfServiceTickets() const { + Y_ENSURE(Updater_); + return Updater_->GetInvalidationTimeOfServiceTickets(); + } + + TString TTvmClient::GetServiceTicketFor(const TClientSettings::TAlias& dst) const { + Y_ENSURE_EX(Tickets_, TBrokenTvmClientSettings() + << "Need to enable ServiceTickets fetching"); + return Tickets_->GetTicket(dst); + } + + TString TTvmClient::GetServiceTicketFor(const TTvmId dst) const { + Y_ENSURE_EX(Tickets_, TBrokenTvmClientSettings() + << "Need to enable ServiceTickets fetching"); + return Tickets_->GetTicket(dst); + } + + TCheckedServiceTicket TTvmClient::CheckServiceTicket(TStringBuf ticket) const { + Y_ENSURE_EX(Service_, TBrokenTvmClientSettings() + << "Need to use TClientSettings::EnableServiceTicketChecking()"); + + TCheckedServiceTicket res = Service_->Check(ticket); + if (SrcChecker_ && res) { + return SrcChecker_->Check(std::move(res)); + } + return res; + } + + TCheckedUserTicket TTvmClient::CheckUserTicket(TStringBuf ticket, TMaybe<EBlackboxEnv> overrideEnv) const { + Y_ENSURE_EX(User_, TBrokenTvmClientSettings() + << "Need to use TClientSettings::EnableUserTicketChecking()"); + + TCheckedUserTicket res = User_->Check(ticket, overrideEnv); + if (DefaultUidChecker_ && res) { + return DefaultUidChecker_->Check(std::move(res)); + } + return User_->Check(ticket, overrideEnv); + } + + NRoles::TRolesPtr TTvmClient::GetRoles() const { + Y_ENSURE(Updater_); + return Updater_->GetRoles(); + } +} diff --git a/library/cpp/tvmauth/client/facade.h b/library/cpp/tvmauth/client/facade.h index be606d4953..34d4b11a00 100644 --- a/library/cpp/tvmauth/client/facade.h +++ b/library/cpp/tvmauth/client/facade.h @@ -1,119 +1,119 @@ -#pragma once - -#include "misc/async_updater.h" -#include "misc/api/settings.h" -#include "misc/tool/settings.h" - -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/checked_user_ticket.h> - -namespace NTvmAuth::NInternal { - class TClientCaningKnife; -} - -namespace NTvmAuth { - class TDefaultUidChecker; - class TServiceTicketGetter; - class TServiceTicketChecker; - class TSrcChecker; - class TUserTicketChecker; - - /*! - * Long lived thread-safe object for interacting with TVM. - * In 99% cases TvmClient shoud be created at service startup and live for the whole process lifetime. - */ - class TTvmClient { - public: - /*! - * Uses local http-interface to get state: http://localhost/tvm/. - * This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). - * See more: https://wiki.yandex-team.ru/passport/tvm2/tvm-daemon/. - * - * Starts thread for updating of in-memory cache in background - * @param settings - * @param logger is usefull for monitoring and debuging - */ - TTvmClient(const NTvmTool::TClientSettings& settings, TLoggerPtr logger); - - /*! - * Uses general way to get state: https://tvm-api.yandex.net. - * It is not recomended for Qloud/YP. - * - * Starts thread for updating of in-memory cache in background - * Reads cache from disk if specified - * @param settings - * @param logger is usefull for monitoring and debuging - */ - TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); - - /*! - * Feel free to use custom updating logic in tests - */ - TTvmClient(TAsyncUpdaterPtr updater); - - TTvmClient(TTvmClient&&); - ~TTvmClient(); - TTvmClient& operator=(TTvmClient&&); - - /*! - * You should trigger your monitoring if status is not Ok. - * It will be unable to operate if status is Error. - * Description: https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/README.md#high-level-interface - * @return Current status of client. - */ - TClientStatus GetStatus() const; - - /*! - * Some tools for monitoring - */ - - TInstant GetUpdateTimeOfPublicKeys() const; - TInstant GetUpdateTimeOfServiceTickets() const; - TInstant GetInvalidationTimeOfPublicKeys() const; - TInstant GetInvalidationTimeOfServiceTickets() const; - - /*! - * Requires fetchinig options (from TClientSettings or Qloud/YP/tvmtool settings) - * Can throw exception if cache is invalid or wrong config - * - * Alias is local label for TvmID - * which can be used to avoid this number in every checking case in code. - * @param dst - */ - TString GetServiceTicketFor(const TClientSettings::TAlias& dst) const; - TString GetServiceTicketFor(const TTvmId dst) const; - - /*! - * For TTvmApi::TClientSettings: checking must be enabled in TClientSettings - * Can throw exception if checking was not enabled in settings - * - * ServiceTicket contains src: you should check it by yourself with ACL - * @param ticket - */ - TCheckedServiceTicket CheckServiceTicket(TStringBuf ticket) const; - - /*! - * Requires blackbox enviroment (from TClientSettings or Qloud/YP/tvmtool settings) - * Can throw exception if checking was not enabled in settings - * @param ticket - * @param overrideEnv allowes you to override env from settings - */ - TCheckedUserTicket CheckUserTicket(TStringBuf ticket, TMaybe<EBlackboxEnv> overrideEnv = {}) const; - - /*! - * Under construction now. It is unusable. - * PASSP-30283 - */ - NRoles::TRolesPtr GetRoles() const; - - private: - TAsyncUpdaterPtr Updater_; - THolder<TServiceTicketGetter> Tickets_; - THolder<TServiceTicketChecker> Service_; - THolder<TUserTicketChecker> User_; - THolder<TSrcChecker> SrcChecker_; - THolder<TDefaultUidChecker> DefaultUidChecker_; - - friend class NInternal::TClientCaningKnife; - }; -} +#pragma once + +#include "misc/async_updater.h" +#include "misc/api/settings.h" +#include "misc/tool/settings.h" + +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/checked_user_ticket.h> + +namespace NTvmAuth::NInternal { + class TClientCaningKnife; +} + +namespace NTvmAuth { + class TDefaultUidChecker; + class TServiceTicketGetter; + class TServiceTicketChecker; + class TSrcChecker; + class TUserTicketChecker; + + /*! + * Long lived thread-safe object for interacting with TVM. + * In 99% cases TvmClient shoud be created at service startup and live for the whole process lifetime. + */ + class TTvmClient { + public: + /*! + * Uses local http-interface to get state: http://localhost/tvm/. + * This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). + * See more: https://wiki.yandex-team.ru/passport/tvm2/tvm-daemon/. + * + * Starts thread for updating of in-memory cache in background + * @param settings + * @param logger is usefull for monitoring and debuging + */ + TTvmClient(const NTvmTool::TClientSettings& settings, TLoggerPtr logger); + + /*! + * Uses general way to get state: https://tvm-api.yandex.net. + * It is not recomended for Qloud/YP. + * + * Starts thread for updating of in-memory cache in background + * Reads cache from disk if specified + * @param settings + * @param logger is usefull for monitoring and debuging + */ + TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); + + /*! + * Feel free to use custom updating logic in tests + */ + TTvmClient(TAsyncUpdaterPtr updater); + + TTvmClient(TTvmClient&&); + ~TTvmClient(); + TTvmClient& operator=(TTvmClient&&); + + /*! + * You should trigger your monitoring if status is not Ok. + * It will be unable to operate if status is Error. + * Description: https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/client/README.md#high-level-interface + * @return Current status of client. + */ + TClientStatus GetStatus() const; + + /*! + * Some tools for monitoring + */ + + TInstant GetUpdateTimeOfPublicKeys() const; + TInstant GetUpdateTimeOfServiceTickets() const; + TInstant GetInvalidationTimeOfPublicKeys() const; + TInstant GetInvalidationTimeOfServiceTickets() const; + + /*! + * Requires fetchinig options (from TClientSettings or Qloud/YP/tvmtool settings) + * Can throw exception if cache is invalid or wrong config + * + * Alias is local label for TvmID + * which can be used to avoid this number in every checking case in code. + * @param dst + */ + TString GetServiceTicketFor(const TClientSettings::TAlias& dst) const; + TString GetServiceTicketFor(const TTvmId dst) const; + + /*! + * For TTvmApi::TClientSettings: checking must be enabled in TClientSettings + * Can throw exception if checking was not enabled in settings + * + * ServiceTicket contains src: you should check it by yourself with ACL + * @param ticket + */ + TCheckedServiceTicket CheckServiceTicket(TStringBuf ticket) const; + + /*! + * Requires blackbox enviroment (from TClientSettings or Qloud/YP/tvmtool settings) + * Can throw exception if checking was not enabled in settings + * @param ticket + * @param overrideEnv allowes you to override env from settings + */ + TCheckedUserTicket CheckUserTicket(TStringBuf ticket, TMaybe<EBlackboxEnv> overrideEnv = {}) const; + + /*! + * Under construction now. It is unusable. + * PASSP-30283 + */ + NRoles::TRolesPtr GetRoles() const; + + private: + TAsyncUpdaterPtr Updater_; + THolder<TServiceTicketGetter> Tickets_; + THolder<TServiceTicketChecker> Service_; + THolder<TUserTicketChecker> User_; + THolder<TSrcChecker> SrcChecker_; + THolder<TDefaultUidChecker> DefaultUidChecker_; + + friend class NInternal::TClientCaningKnife; + }; +} diff --git a/library/cpp/tvmauth/client/logger.cpp b/library/cpp/tvmauth/client/logger.cpp index 007f696433..bd63773cdf 100644 --- a/library/cpp/tvmauth/client/logger.cpp +++ b/library/cpp/tvmauth/client/logger.cpp @@ -1,12 +1,12 @@ -#include "logger.h" - -#include <util/datetime/base.h> -#include <util/generic/string.h> - -namespace NTvmAuth { - void TCerrLogger::Log(int lvl, const TString& msg) { - if (lvl > Level_) - return; - Cerr << TInstant::Now().ToStringLocal() << " lvl=" << lvl << " msg: " << msg << "\n"; - } -} +#include "logger.h" + +#include <util/datetime/base.h> +#include <util/generic/string.h> + +namespace NTvmAuth { + void TCerrLogger::Log(int lvl, const TString& msg) { + if (lvl > Level_) + return; + Cerr << TInstant::Now().ToStringLocal() << " lvl=" << lvl << " msg: " << msg << "\n"; + } +} diff --git a/library/cpp/tvmauth/client/logger.h b/library/cpp/tvmauth/client/logger.h index 5d095d6b19..6f3718a2aa 100644 --- a/library/cpp/tvmauth/client/logger.h +++ b/library/cpp/tvmauth/client/logger.h @@ -1,59 +1,59 @@ -#pragma once - -#include <util/generic/ptr.h> - -namespace NTvmAuth { - class ILogger: public TAtomicRefCount<ILogger> { - public: - virtual ~ILogger() = default; - - void Debug(const TString& msg) { - Log(7, msg); - } - - void Info(const TString& msg) { - Log(6, msg); - } - - void Warning(const TString& msg) { - Log(4, msg); - } - - void Error(const TString& msg) { - Log(3, msg); - } - - protected: - /*! - * Log event - * @param lvl is syslog level: 0(Emergency) ... 7(Debug) - * @param msg - */ - virtual void Log(int lvl, const TString& msg) = 0; - }; - - class TCerrLogger: public ILogger { - public: - TCerrLogger(int level) - : Level_(level) - { - } - - void Log(int lvl, const TString& msg) override; - - private: - const int Level_; - }; - - using TLoggerPtr = TIntrusivePtr<ILogger>; - - class TDevNullLogger: public ILogger { - public: - static TLoggerPtr IAmBrave() { - return MakeIntrusive<TDevNullLogger>(); - } - - void Log(int, const TString&) override { - } - }; -} +#pragma once + +#include <util/generic/ptr.h> + +namespace NTvmAuth { + class ILogger: public TAtomicRefCount<ILogger> { + public: + virtual ~ILogger() = default; + + void Debug(const TString& msg) { + Log(7, msg); + } + + void Info(const TString& msg) { + Log(6, msg); + } + + void Warning(const TString& msg) { + Log(4, msg); + } + + void Error(const TString& msg) { + Log(3, msg); + } + + protected: + /*! + * Log event + * @param lvl is syslog level: 0(Emergency) ... 7(Debug) + * @param msg + */ + virtual void Log(int lvl, const TString& msg) = 0; + }; + + class TCerrLogger: public ILogger { + public: + TCerrLogger(int level) + : Level_(level) + { + } + + void Log(int lvl, const TString& msg) override; + + private: + const int Level_; + }; + + using TLoggerPtr = TIntrusivePtr<ILogger>; + + class TDevNullLogger: public ILogger { + public: + static TLoggerPtr IAmBrave() { + return MakeIntrusive<TDevNullLogger>(); + } + + void Log(int, const TString&) override { + } + }; +} diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp index dee9b05d1f..6ec15c0e88 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.cpp @@ -1,126 +1,126 @@ -#include "tvm_client.h" - -#include <util/string/builder.h> - -namespace NTvmAuth::NDynamicClient { - TAsyncUpdaterPtr TTvmClient::Create(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) { - Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); - THolder<TTvmClient> p(new TTvmClient(settings, std::move(logger))); - p->Init(); - p->StartWorker(); - return p.Release(); - } - - NThreading::TFuture<TAddResponse> TTvmClient::Add(TDsts&& dsts) { - if (dsts.empty()) { - LogDebug("Adding dst: got empty task"); - return NThreading::MakeFuture<TAddResponse>(TAddResponse{}); - } - - const size_t size = dsts.size(); - const ui64 id = ++TaskIds_; - NThreading::TPromise<TAddResponse> promise = NThreading::NewPromise<TAddResponse>(); - - TaskQueue_.Enqueue(TTask{id, promise, std::move(dsts)}); - - LogDebug(TStringBuilder() << "Adding dst: got task #" << id << " with " << size << " dsts"); - return promise.GetFuture(); - } - - std::optional<TString> TTvmClient::GetOptionalServiceTicketFor(const TTvmId dst) { - TServiceTicketsPtr tickets = GetCachedServiceTickets(); - Y_ENSURE_EX(tickets, - TBrokenTvmClientSettings() - << "Need to enable fetching of service tickets in settings"); - - auto it = tickets->TicketsById.find(dst); - if (it != tickets->TicketsById.end()) { - return it->second; - } - - it = tickets->ErrorsById.find(dst); - if (it != tickets->ErrorsById.end()) { - ythrow TMissingServiceTicket() - << "Failed to get ticket for '" << dst << "': " - << it->second; - } - - return {}; - } - - TTvmClient::TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) - : TBase(settings, logger) - { - } - +#include "tvm_client.h" + +#include <util/string/builder.h> + +namespace NTvmAuth::NDynamicClient { + TAsyncUpdaterPtr TTvmClient::Create(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) { + Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); + THolder<TTvmClient> p(new TTvmClient(settings, std::move(logger))); + p->Init(); + p->StartWorker(); + return p.Release(); + } + + NThreading::TFuture<TAddResponse> TTvmClient::Add(TDsts&& dsts) { + if (dsts.empty()) { + LogDebug("Adding dst: got empty task"); + return NThreading::MakeFuture<TAddResponse>(TAddResponse{}); + } + + const size_t size = dsts.size(); + const ui64 id = ++TaskIds_; + NThreading::TPromise<TAddResponse> promise = NThreading::NewPromise<TAddResponse>(); + + TaskQueue_.Enqueue(TTask{id, promise, std::move(dsts)}); + + LogDebug(TStringBuilder() << "Adding dst: got task #" << id << " with " << size << " dsts"); + return promise.GetFuture(); + } + + std::optional<TString> TTvmClient::GetOptionalServiceTicketFor(const TTvmId dst) { + TServiceTicketsPtr tickets = GetCachedServiceTickets(); + Y_ENSURE_EX(tickets, + TBrokenTvmClientSettings() + << "Need to enable fetching of service tickets in settings"); + + auto it = tickets->TicketsById.find(dst); + if (it != tickets->TicketsById.end()) { + return it->second; + } + + it = tickets->ErrorsById.find(dst); + if (it != tickets->ErrorsById.end()) { + ythrow TMissingServiceTicket() + << "Failed to get ticket for '" << dst << "': " + << it->second; + } + + return {}; + } + + TTvmClient::TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger) + : TBase(settings, logger) + { + } + TTvmClient::~TTvmClient() { TBase::StopWorker(); } - void TTvmClient::Worker() { - TBase::Worker(); - ProcessTasks(); - } - - void TTvmClient::ProcessTasks() { - TaskQueue_.DequeueAll(&Tasks_); - if (Tasks_.empty()) { - return; - } - - TDsts required; - for (const TTask& task : Tasks_) { - for (const auto& dst : task.Dsts) { - required.insert(dst); - } - } - - TServiceTicketsPtr cache = UpdateMissingServiceTickets(required); - - for (TTask& task : Tasks_) { - try { - SetResponseForTask(task, *cache); - } catch (const std::exception& e) { - LogError(TStringBuilder() - << "Adding dst: task #" << task.Id << ": exception: " << e.what()); - } catch (...) { - LogError(TStringBuilder() - << "Adding dst: task #" << task.Id << ": exception: " << CurrentExceptionMessage()); - } - } - - Tasks_.clear(); - } - - static const TString UNKNOWN = "Unknown reason"; - void TTvmClient::SetResponseForTask(TTvmClient::TTask& task, const TServiceTickets& cache) { - if (task.Promise.HasValue()) { - LogWarning(TStringBuilder() << "Adding dst: task #" << task.Id << " already has value"); - return; - } - - TAddResponse response; - - for (const auto& dst : task.Dsts) { - if (cache.TicketsById.contains(dst.Id)) { - AddDstToSettings(dst); - response.emplace(dst, TDstResponse{EDstStatus::Success, TString()}); - - LogDebug(TStringBuilder() << "Adding dst: task #" << task.Id - << ": dst=" << dst.Id << " got ticket"); - continue; - } - - auto it = cache.ErrorsById.find(dst.Id); - const TString& error = it == cache.ErrorsById.end() ? UNKNOWN : it->second; - response.emplace(dst, TDstResponse{EDstStatus::Fail, error}); - - LogWarning(TStringBuilder() << "Adding dst: task #" << task.Id - << ": dst=" << dst.Id - << " failed to get ticket: " << error); - } - - LogDebug(TStringBuilder() << "Adding dst: task #" << task.Id << ": set value"); - task.Promise.SetValue(std::move(response)); - } -} + void TTvmClient::Worker() { + TBase::Worker(); + ProcessTasks(); + } + + void TTvmClient::ProcessTasks() { + TaskQueue_.DequeueAll(&Tasks_); + if (Tasks_.empty()) { + return; + } + + TDsts required; + for (const TTask& task : Tasks_) { + for (const auto& dst : task.Dsts) { + required.insert(dst); + } + } + + TServiceTicketsPtr cache = UpdateMissingServiceTickets(required); + + for (TTask& task : Tasks_) { + try { + SetResponseForTask(task, *cache); + } catch (const std::exception& e) { + LogError(TStringBuilder() + << "Adding dst: task #" << task.Id << ": exception: " << e.what()); + } catch (...) { + LogError(TStringBuilder() + << "Adding dst: task #" << task.Id << ": exception: " << CurrentExceptionMessage()); + } + } + + Tasks_.clear(); + } + + static const TString UNKNOWN = "Unknown reason"; + void TTvmClient::SetResponseForTask(TTvmClient::TTask& task, const TServiceTickets& cache) { + if (task.Promise.HasValue()) { + LogWarning(TStringBuilder() << "Adding dst: task #" << task.Id << " already has value"); + return; + } + + TAddResponse response; + + for (const auto& dst : task.Dsts) { + if (cache.TicketsById.contains(dst.Id)) { + AddDstToSettings(dst); + response.emplace(dst, TDstResponse{EDstStatus::Success, TString()}); + + LogDebug(TStringBuilder() << "Adding dst: task #" << task.Id + << ": dst=" << dst.Id << " got ticket"); + continue; + } + + auto it = cache.ErrorsById.find(dst.Id); + const TString& error = it == cache.ErrorsById.end() ? UNKNOWN : it->second; + response.emplace(dst, TDstResponse{EDstStatus::Fail, error}); + + LogWarning(TStringBuilder() << "Adding dst: task #" << task.Id + << ": dst=" << dst.Id + << " failed to get ticket: " << error); + } + + LogDebug(TStringBuilder() << "Adding dst: task #" << task.Id << ": set value"); + task.Promise.SetValue(std::move(response)); + } +} diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h index a3aed7210a..58ed953b63 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h @@ -1,60 +1,60 @@ -#pragma once - -#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> - +#pragma once + +#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> + #include <library/cpp/threading/future/future.h> - -#include <util/generic/map.h> -#include <util/thread/lfqueue.h> - -#include <optional> - -namespace NTvmAuth::NDynamicClient { - enum class EDstStatus { - Success, - Fail, - }; - - struct TDstResponse { - EDstStatus Status = EDstStatus::Fail; - TString Error; - - bool operator==(const TDstResponse& o) const { - return Status == o.Status && Error == o.Error; - } - }; - - using TDsts = NTvmApi::TDstSet; - using TAddResponse = TMap<NTvmApi::TClientSettings::TDst, TDstResponse>; - - class TTvmClient: public NTvmApi::TThreadedUpdater { - public: - static TAsyncUpdaterPtr Create(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); + +#include <util/generic/map.h> +#include <util/thread/lfqueue.h> + +#include <optional> + +namespace NTvmAuth::NDynamicClient { + enum class EDstStatus { + Success, + Fail, + }; + + struct TDstResponse { + EDstStatus Status = EDstStatus::Fail; + TString Error; + + bool operator==(const TDstResponse& o) const { + return Status == o.Status && Error == o.Error; + } + }; + + using TDsts = NTvmApi::TDstSet; + using TAddResponse = TMap<NTvmApi::TClientSettings::TDst, TDstResponse>; + + class TTvmClient: public NTvmApi::TThreadedUpdater { + public: + static TAsyncUpdaterPtr Create(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); virtual ~TTvmClient(); - - NThreading::TFuture<TAddResponse> Add(TDsts&& dsts); - std::optional<TString> GetOptionalServiceTicketFor(const TTvmId dst); - - protected: // for tests - struct TTask { - ui64 Id = 0; - NThreading::TPromise<TAddResponse> Promise; - TDsts Dsts; - }; - - using TBase = NTvmApi::TThreadedUpdater; - - protected: // for tests - TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); - - void Worker() override; - void ProcessTasks(); - - void SetResponseForTask(TTask& task, const TServiceTickets& cache); - - private: - std::atomic<ui64> TaskIds_ = {0}; - TLockFreeQueue<TTask> TaskQueue_; - TVector<TTask> Tasks_; - }; -} + + NThreading::TFuture<TAddResponse> Add(TDsts&& dsts); + std::optional<TString> GetOptionalServiceTicketFor(const TTvmId dst); + + protected: // for tests + struct TTask { + ui64 Id = 0; + NThreading::TPromise<TAddResponse> Promise; + TDsts Dsts; + }; + + using TBase = NTvmApi::TThreadedUpdater; + + protected: // for tests + TTvmClient(const NTvmApi::TClientSettings& settings, TLoggerPtr logger); + + void Worker() override; + void ProcessTasks(); + + void SetResponseForTask(TTask& task, const TServiceTickets& cache); + + private: + std::atomic<ui64> TaskIds_ = {0}; + TLockFreeQueue<TTask> TaskQueue_; + TVector<TTask> Tasks_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp index e0b4562a31..89403c15e4 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/tvm_client_ut.cpp @@ -1,119 +1,119 @@ -#include <library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h> - -#include <library/cpp/tvmauth/client/misc/disk_cache.h> - -#include <library/cpp/tvmauth/unittest.h> - +#include <library/cpp/tvmauth/client/misc/api/dynamic_dst/tvm_client.h> + +#include <library/cpp/tvmauth/client/misc/disk_cache.h> + +#include <library/cpp/tvmauth/unittest.h> + #include <library/cpp/testing/unittest/registar.h> - -#include <util/stream/file.h> -#include <util/system/fs.h> - -#include <regex> - -using namespace NTvmAuth; -using namespace NTvmAuth::NDynamicClient; - -Y_UNIT_TEST_SUITE(DynamicClient) { - static const std::regex TIME_REGEX(R"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}Z)"); - static const TString CACHE_DIR = "./tmp/"; - - static void WriteFile(TString name, TStringBuf body, TInstant time) { - NFs::Remove(CACHE_DIR + name); - TFileOutput f(CACHE_DIR + name); - f << TDiskWriter::PrepareData(time, body); - } - - static void CleanCache() { - NFs::RemoveRecursive(CACHE_DIR); - NFs::MakeDirectoryRecursive(CACHE_DIR); - } - - class TLogger: public NTvmAuth::ILogger { - public: - void Log(int lvl, const TString& msg) override { - Cout << TInstant::Now() << " lvl=" << lvl << " msg: " << msg << "\n"; - Stream << lvl << ": " << msg << Endl; - } - - TStringStream Stream; - }; - - class TOfflineUpdater: public NDynamicClient::TTvmClient { - public: - TOfflineUpdater(const NTvmApi::TClientSettings& settings, - TIntrusivePtr<TLogger> l, - bool fail = true, - std::vector<TString> tickets = {}) - : TTvmClient(settings, l) - , Fail(fail) - , Tickets(std::move(tickets)) - { - Init(); - ExpBackoff_.SetEnabled(false); - } - - NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString& req) const override { - if (Fail) { - throw yexception() << "tickets: alarm"; - } - - TString response; - if (!Tickets.empty()) { - response = Tickets.front(); - Tickets.erase(Tickets.begin()); - } - - Cout << "*** FetchServiceTicketsFromHttp. request: " << req << ". response: " << response << Endl; - return {200, {}, "/2/ticket", response, ""}; - } - - NUtils::TFetchResult FetchPublicKeysFromHttp() const override { - if (Fail) { - throw yexception() << "keysalarm"; - } - Cout << "*** FetchPublicKeysFromHttp" << Endl; - return {200, {}, "/2/keys", PublicKeys, ""}; - } - - using TTvmClient::GetDsts; - using TTvmClient::ProcessTasks; - using TTvmClient::SetResponseForTask; - using TTvmClient::Worker; - - bool Fail = true; - TString PublicKeys = NUnittest::TVMKNIFE_PUBLIC_KEYS; - mutable std::vector<TString> Tickets; - }; - + +#include <util/stream/file.h> +#include <util/system/fs.h> + +#include <regex> + +using namespace NTvmAuth; +using namespace NTvmAuth::NDynamicClient; + +Y_UNIT_TEST_SUITE(DynamicClient) { + static const std::regex TIME_REGEX(R"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}Z)"); + static const TString CACHE_DIR = "./tmp/"; + + static void WriteFile(TString name, TStringBuf body, TInstant time) { + NFs::Remove(CACHE_DIR + name); + TFileOutput f(CACHE_DIR + name); + f << TDiskWriter::PrepareData(time, body); + } + + static void CleanCache() { + NFs::RemoveRecursive(CACHE_DIR); + NFs::MakeDirectoryRecursive(CACHE_DIR); + } + + class TLogger: public NTvmAuth::ILogger { + public: + void Log(int lvl, const TString& msg) override { + Cout << TInstant::Now() << " lvl=" << lvl << " msg: " << msg << "\n"; + Stream << lvl << ": " << msg << Endl; + } + + TStringStream Stream; + }; + + class TOfflineUpdater: public NDynamicClient::TTvmClient { + public: + TOfflineUpdater(const NTvmApi::TClientSettings& settings, + TIntrusivePtr<TLogger> l, + bool fail = true, + std::vector<TString> tickets = {}) + : TTvmClient(settings, l) + , Fail(fail) + , Tickets(std::move(tickets)) + { + Init(); + ExpBackoff_.SetEnabled(false); + } + + NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString& req) const override { + if (Fail) { + throw yexception() << "tickets: alarm"; + } + + TString response; + if (!Tickets.empty()) { + response = Tickets.front(); + Tickets.erase(Tickets.begin()); + } + + Cout << "*** FetchServiceTicketsFromHttp. request: " << req << ". response: " << response << Endl; + return {200, {}, "/2/ticket", response, ""}; + } + + NUtils::TFetchResult FetchPublicKeysFromHttp() const override { + if (Fail) { + throw yexception() << "keysalarm"; + } + Cout << "*** FetchPublicKeysFromHttp" << Endl; + return {200, {}, "/2/keys", PublicKeys, ""}; + } + + using TTvmClient::GetDsts; + using TTvmClient::ProcessTasks; + using TTvmClient::SetResponseForTask; + using TTvmClient::Worker; + + bool Fail = true; + TString PublicKeys = NUnittest::TVMKNIFE_PUBLIC_KEYS; + mutable std::vector<TString> Tickets; + }; + Y_UNIT_TEST(StartWithIncompleteTicketsSet) { - TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); + TInstant now = TInstant::Now(); + CleanCache(); + WriteFile("./service_tickets", + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}, false); s.SetDiskCacheDir(CACHE_DIR); auto l = MakeIntrusive<TLogger>(); { - TOfflineUpdater client(s, - l, - false, - { - R"({"213" : { "error" : "some error"}})", - R"({"123" : { "ticket" : "service_ticket_3"}})", - }); + TOfflineUpdater client(s, + l, + false, + { + R"({"213" : { "error" : "some error"}})", + R"({"123" : { "ticket" : "service_ticket_3"}})", + }); UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); NThreading::TFuture<TAddResponse> fut = client.Add({123}); UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); @@ -121,12 +121,12 @@ Y_UNIT_TEST_SUITE(DynamicClient) { client.Worker(); UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); UNIT_ASSERT(fut.HasValue()); TAddResponse resp{ @@ -134,7 +134,7 @@ Y_UNIT_TEST_SUITE(DynamicClient) { }; UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - UNIT_ASSERT(client.Tickets.empty()); + UNIT_ASSERT(client.Tickets.empty()); TDsts dsts{19, 123, 213}; UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); @@ -144,7 +144,7 @@ Y_UNIT_TEST_SUITE(DynamicClient) { } Y_UNIT_TEST(StartWithEmptyTicketsSet) { - CleanCache(); + CleanCache(); NTvmApi::TClientSettings s; s.SetSelfTvmId(100500); @@ -154,16 +154,16 @@ Y_UNIT_TEST_SUITE(DynamicClient) { auto l = MakeIntrusive<TLogger>(); { - TOfflineUpdater client(s, - l, - false, - { - R"({"213" : { "error" : "some error"}})", - R"({"123" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEHs:CcafYQH-FF5XaXMuJrgLZj98bIC54cs1ZkcFS9VV_9YM9iOM_0PXCtMkdg85rFjxE_BMpg7bE8ZuoqNfdw0FPt0BAKNeISwlydj4o0IjY82--LZBpP8CRn-EpAnkRaDShdlfrcF2pk1SSmEX8xdyZVQEnkUPY0cHGlFnu231vnE"}})", - }); + TOfflineUpdater client(s, + l, + false, + { + R"({"213" : { "error" : "some error"}})", + R"({"123" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEHs:CcafYQH-FF5XaXMuJrgLZj98bIC54cs1ZkcFS9VV_9YM9iOM_0PXCtMkdg85rFjxE_BMpg7bE8ZuoqNfdw0FPt0BAKNeISwlydj4o0IjY82--LZBpP8CRn-EpAnkRaDShdlfrcF2pk1SSmEX8xdyZVQEnkUPY0cHGlFnu231vnE"}})", + }); UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(213), TMissingServiceTicket, "some error"); NThreading::TFuture<TAddResponse> fut = client.Add({123}); @@ -172,10 +172,10 @@ Y_UNIT_TEST_SUITE(DynamicClient) { client.Worker(); UNIT_ASSERT_VALUES_EQUAL(TClientStatus::IncompleteTicketsSet, client.GetStatus()); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); UNIT_ASSERT(fut.HasValue()); TAddResponse resp{ @@ -183,7 +183,7 @@ Y_UNIT_TEST_SUITE(DynamicClient) { }; UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - UNIT_ASSERT(client.Tickets.empty()); + UNIT_ASSERT(client.Tickets.empty()); TDsts dsts{123, 213}; UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); @@ -193,443 +193,443 @@ Y_UNIT_TEST_SUITE(DynamicClient) { }; Y_UNIT_TEST(StartWithIncompleteCacheAndAdd) { TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", + CleanCache(); + WriteFile("./service_tickets", R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" "\t100500", now); NTvmApi::TClientSettings s; s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry: ServiceTickets: tickets: alarm"); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "4: Failed to get ServiceTickets: tickets: alarm\n" - << "4: Failed to get ServiceTickets: tickets: alarm\n" - << "4: Failed to get ServiceTickets: tickets: alarm\n" - << "4: Failed to update service tickets: tickets: alarm\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - l->Stream.Str().clear(); - - { - TOfflineUpdater client(s, - l, - false, - { - R"({"213" : { "ticket" : "service_ticket_2"}})", - R"({"123" : { "ticket" : "service_ticket_3"}})", - }); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - - NThreading::TFuture<TAddResponse> fut = client.Add({123}); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - - UNIT_ASSERT(fut.HasValue()); - TAddResponse resp{ - {123, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - - UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" - << "6: Cache was partly updated with 1 service ticket(s). total: 2\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: got task #1 with 1 dsts\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" - << "6: Cache was partly updated with 1 service ticket(s). total: 3\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: task #1: dst=123 got ticket\n" - << "7: Adding dst: task #1: set value\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithCacheAndAdd) { - TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater client(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - - client.Fail = false; - client.Tickets = { - R"({"123" : { "ticket" : "service_ticket_3"}, "213" : { "ticket" : "service_ticket_2"}})", - }; - NThreading::TFuture<TAddResponse> fut = client.Add({123, 213}); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - - UNIT_ASSERT(fut.HasValue()); - TAddResponse resp{ - {123, {EDstStatus::Success, ""}}, - {213, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); - - UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Adding dst: got task #1 with 2 dsts\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: task #1: dst=123 got ticket\n" - << "7: Adding dst: task #1: dst=213 got ticket\n" - << "7: Adding dst: task #1: set value\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithCacheAndAddSeveral) { - TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater client(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - - client.Fail = false; - client.Tickets = { - R"({"123" : { "ticket" : "service_ticket_3"}, "213" : { "ticket" : "service_ticket_2"}})", - }; - NThreading::TFuture<TAddResponse> fut1 = client.Add({123}); - NThreading::TFuture<TAddResponse> fut2 = client.Add({213}); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - - UNIT_ASSERT(fut1.HasValue()); - TAddResponse resp1{ - {123, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); - - UNIT_ASSERT(fut2.HasValue()); - TAddResponse resp2{ - {213, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); - - UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Adding dst: got task #1 with 1 dsts\n" - << "7: Adding dst: got task #2 with 1 dsts\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: task #1: dst=123 got ticket\n" - << "7: Adding dst: task #1: set value\n" - << "7: Adding dst: task #2: dst=213 got ticket\n" - << "7: Adding dst: task #2: set value\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithCacheAndAddSeveralWithErrors) { - TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater client(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - - UNIT_ASSERT(client.GetOptionalServiceTicketFor(19)); - UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", - *client.GetOptionalServiceTicketFor(19)); - UNIT_ASSERT(!client.GetOptionalServiceTicketFor(456)); - - client.Fail = false; - client.Tickets = { - R"({ - "123" : { "ticket" : "service_ticket_3"}, - "213" : { "ticket" : "service_ticket_2"}, - "456" : { "error" : "error_3"} - })", - }; - NThreading::TFuture<TAddResponse> fut1 = client.Add({123, 213}); - NThreading::TFuture<TAddResponse> fut2 = client.Add({213, 456}); - - client.Worker(); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(456)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(456)); - - UNIT_ASSERT(client.GetOptionalServiceTicketFor(19)); - UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", - *client.GetOptionalServiceTicketFor(19)); - UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(456), - TMissingServiceTicket, - "Failed to get ticket for '456': error_3"); - - UNIT_ASSERT(fut1.HasValue()); - TAddResponse resp1{ - {123, {EDstStatus::Success, ""}}, - {213, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); - - UNIT_ASSERT(fut2.HasValue()); - TAddResponse resp2{ - {213, {EDstStatus::Success, ""}}, - {456, {EDstStatus::Fail, "error_3"}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); - - UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Adding dst: got task #1 with 2 dsts\n" - << "7: Adding dst: got task #2 with 2 dsts\n" - << "7: Response with service tickets for 3 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 3 destination(s)\n" - << "3: Failed to get service ticket for dst=456: error_3\n" - << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: task #1: dst=123 got ticket\n" - << "7: Adding dst: task #1: dst=213 got ticket\n" - << "7: Adding dst: task #1: set value\n" - << "7: Adding dst: task #2: dst=213 got ticket\n" - << "4: Adding dst: task #2: dst=456 failed to get ticket: error_3\n" - << "7: Adding dst: task #2: set value\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(WithException) { - TInstant now = TInstant::Now(); - CleanCache(); - WriteFile("./service_tickets", - R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" - "\t100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater client(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - - client.Fail = false; - client.Tickets = { - R"({ - "123" : { "ticket" : "service_ticket_3"}, - "213" : { "ticket" : "service_ticket_2"}, - "456" : { "error" : "error_3"}, - "789" : { "ticket" : "service_ticket_4"} - })", - }; - NThreading::TFuture<TAddResponse> fut1 = client.Add({123, 213}); - NThreading::TFuture<TAddResponse> fut2 = client.Add({213, 456}); - NThreading::TFuture<TAddResponse> fut3 = client.Add({789}); - - fut2.Subscribe([](const auto&) { - throw yexception() << "planed exc"; - }); - fut3.Subscribe([](const auto&) { - throw 5; - }); - - UNIT_ASSERT_NO_EXCEPTION(client.Worker()); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); - - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); - UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(456)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); - UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); - UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(456)); - - UNIT_ASSERT(fut1.HasValue()); - TAddResponse resp1{ - {123, {EDstStatus::Success, ""}}, - {213, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); - - UNIT_ASSERT(fut2.HasValue()); - TAddResponse resp2{ - {213, {EDstStatus::Success, ""}}, - {456, {EDstStatus::Fail, "error_3"}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); - - UNIT_ASSERT(fut3.HasValue()); - TAddResponse resp3{ - {789, {EDstStatus::Success, ""}}, - }; - UNIT_ASSERT_VALUES_EQUAL(resp3, fut3.GetValue()); - - UNIT_ASSERT(client.Tickets.empty()); - - TDsts dsts{19, 123, 213, 789}; - UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Adding dst: got task #1 with 2 dsts\n" - << "7: Adding dst: got task #2 with 2 dsts\n" - << "7: Adding dst: got task #3 with 1 dsts\n" - << "7: Response with service tickets for 4 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 4 destination(s)\n" - << "3: Failed to get service ticket for dst=456: error_3\n" - << "6: Cache was partly updated with 3 service ticket(s). total: 4\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Adding dst: task #1: dst=123 got ticket\n" - << "7: Adding dst: task #1: dst=213 got ticket\n" - << "7: Adding dst: task #1: set value\n" - << "7: Adding dst: task #2: dst=213 got ticket\n" - << "4: Adding dst: task #2: dst=456 failed to get ticket: error_3\n" - << "7: Adding dst: task #2: set value\n" - << "3: Adding dst: task #2: exception: planed exc\n" - << "7: Adding dst: task #3: dst=789 got ticket\n" - << "7: Adding dst: task #3: set value\n" - << "3: Adding dst: task #3: exception: unknown error\n", - l->Stream.Str()); - } -} - -template <> -void Out<NTvmAuth::NDynamicClient::TDstResponse>(IOutputStream& out, const NTvmAuth::NDynamicClient::TDstResponse& m) { - out << m.Status << " (" << m.Error << ")"; -} - -template <> -void Out<NTvmAuth::NTvmApi::TClientSettings::TDst>(IOutputStream& out, const NTvmAuth::NTvmApi::TClientSettings::TDst& m) { - out << m.Id; -} + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry: ServiceTickets: tickets: alarm"); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "4: Failed to get ServiceTickets: tickets: alarm\n" + << "4: Failed to get ServiceTickets: tickets: alarm\n" + << "4: Failed to get ServiceTickets: tickets: alarm\n" + << "4: Failed to update service tickets: tickets: alarm\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + l->Stream.Str().clear(); + + { + TOfflineUpdater client(s, + l, + false, + { + R"({"213" : { "ticket" : "service_ticket_2"}})", + R"({"123" : { "ticket" : "service_ticket_3"}})", + }); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + + NThreading::TFuture<TAddResponse> fut = client.Add({123}); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + + UNIT_ASSERT(fut.HasValue()); + TAddResponse resp{ + {123, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); + + UNIT_ASSERT(client.Tickets.empty()); + + TDsts dsts{19, 123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" + << "6: Cache was partly updated with 1 service ticket(s). total: 2\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: got task #1 with 1 dsts\n" + << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" + << "6: Cache was partly updated with 1 service ticket(s). total: 3\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: task #1: dst=123 got ticket\n" + << "7: Adding dst: task #1: set value\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithCacheAndAdd) { + TInstant now = TInstant::Now(); + CleanCache(); + WriteFile("./service_tickets", + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater client(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + + client.Fail = false; + client.Tickets = { + R"({"123" : { "ticket" : "service_ticket_3"}, "213" : { "ticket" : "service_ticket_2"}})", + }; + NThreading::TFuture<TAddResponse> fut = client.Add({123, 213}); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + + UNIT_ASSERT(fut.HasValue()); + TAddResponse resp{ + {123, {EDstStatus::Success, ""}}, + {213, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp, fut.GetValue()); + + UNIT_ASSERT(client.Tickets.empty()); + + TDsts dsts{19, 123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Adding dst: got task #1 with 2 dsts\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: task #1: dst=123 got ticket\n" + << "7: Adding dst: task #1: dst=213 got ticket\n" + << "7: Adding dst: task #1: set value\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithCacheAndAddSeveral) { + TInstant now = TInstant::Now(); + CleanCache(); + WriteFile("./service_tickets", + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater client(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + + client.Fail = false; + client.Tickets = { + R"({"123" : { "ticket" : "service_ticket_3"}, "213" : { "ticket" : "service_ticket_2"}})", + }; + NThreading::TFuture<TAddResponse> fut1 = client.Add({123}); + NThreading::TFuture<TAddResponse> fut2 = client.Add({213}); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + + UNIT_ASSERT(fut1.HasValue()); + TAddResponse resp1{ + {123, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); + + UNIT_ASSERT(fut2.HasValue()); + TAddResponse resp2{ + {213, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); + + UNIT_ASSERT(client.Tickets.empty()); + + TDsts dsts{19, 123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Adding dst: got task #1 with 1 dsts\n" + << "7: Adding dst: got task #2 with 1 dsts\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: task #1: dst=123 got ticket\n" + << "7: Adding dst: task #1: set value\n" + << "7: Adding dst: task #2: dst=213 got ticket\n" + << "7: Adding dst: task #2: set value\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithCacheAndAddSeveralWithErrors) { + TInstant now = TInstant::Now(); + CleanCache(); + WriteFile("./service_tickets", + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater client(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + + UNIT_ASSERT(client.GetOptionalServiceTicketFor(19)); + UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", + *client.GetOptionalServiceTicketFor(19)); + UNIT_ASSERT(!client.GetOptionalServiceTicketFor(456)); + + client.Fail = false; + client.Tickets = { + R"({ + "123" : { "ticket" : "service_ticket_3"}, + "213" : { "ticket" : "service_ticket_2"}, + "456" : { "error" : "error_3"} + })", + }; + NThreading::TFuture<TAddResponse> fut1 = client.Add({123, 213}); + NThreading::TFuture<TAddResponse> fut2 = client.Add({213, 456}); + + client.Worker(); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(456)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(456)); + + UNIT_ASSERT(client.GetOptionalServiceTicketFor(19)); + UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", + *client.GetOptionalServiceTicketFor(19)); + UNIT_ASSERT_EXCEPTION_CONTAINS(client.GetOptionalServiceTicketFor(456), + TMissingServiceTicket, + "Failed to get ticket for '456': error_3"); + + UNIT_ASSERT(fut1.HasValue()); + TAddResponse resp1{ + {123, {EDstStatus::Success, ""}}, + {213, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); + + UNIT_ASSERT(fut2.HasValue()); + TAddResponse resp2{ + {213, {EDstStatus::Success, ""}}, + {456, {EDstStatus::Fail, "error_3"}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); + + UNIT_ASSERT(client.Tickets.empty()); + + TDsts dsts{19, 123, 213}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Adding dst: got task #1 with 2 dsts\n" + << "7: Adding dst: got task #2 with 2 dsts\n" + << "7: Response with service tickets for 3 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 3 destination(s)\n" + << "3: Failed to get service ticket for dst=456: error_3\n" + << "6: Cache was partly updated with 2 service ticket(s). total: 3\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: task #1: dst=123 got ticket\n" + << "7: Adding dst: task #1: dst=213 got ticket\n" + << "7: Adding dst: task #1: set value\n" + << "7: Adding dst: task #2: dst=213 got ticket\n" + << "4: Adding dst: task #2: dst=456 failed to get ticket: error_3\n" + << "7: Adding dst: task #2: set value\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(WithException) { + TInstant now = TInstant::Now(); + CleanCache(); + WriteFile("./service_tickets", + R"({"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})" + "\t100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater client(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + + client.Fail = false; + client.Tickets = { + R"({ + "123" : { "ticket" : "service_ticket_3"}, + "213" : { "ticket" : "service_ticket_2"}, + "456" : { "error" : "error_3"}, + "789" : { "ticket" : "service_ticket_4"} + })", + }; + NThreading::TFuture<TAddResponse> fut1 = client.Add({123, 213}); + NThreading::TFuture<TAddResponse> fut2 = client.Add({213, 456}); + NThreading::TFuture<TAddResponse> fut3 = client.Add({789}); + + fut2.Subscribe([](const auto&) { + throw yexception() << "planed exc"; + }); + fut3.Subscribe([](const auto&) { + throw 5; + }); + + UNIT_ASSERT_NO_EXCEPTION(client.Worker()); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, client.GetStatus()); + + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(19)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(213)); + UNIT_ASSERT(client.GetCachedServiceTickets()->TicketsById.contains(123)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->TicketsById.contains(456)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(19)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(213)); + UNIT_ASSERT(!client.GetCachedServiceTickets()->ErrorsById.contains(123)); + UNIT_ASSERT(client.GetCachedServiceTickets()->ErrorsById.contains(456)); + + UNIT_ASSERT(fut1.HasValue()); + TAddResponse resp1{ + {123, {EDstStatus::Success, ""}}, + {213, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp1, fut1.GetValue()); + + UNIT_ASSERT(fut2.HasValue()); + TAddResponse resp2{ + {213, {EDstStatus::Success, ""}}, + {456, {EDstStatus::Fail, "error_3"}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp2, fut2.GetValue()); + + UNIT_ASSERT(fut3.HasValue()); + TAddResponse resp3{ + {789, {EDstStatus::Success, ""}}, + }; + UNIT_ASSERT_VALUES_EQUAL(resp3, fut3.GetValue()); + + UNIT_ASSERT(client.Tickets.empty()); + + TDsts dsts{19, 123, 213, 789}; + UNIT_ASSERT_VALUES_EQUAL(dsts, client.GetDsts()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Adding dst: got task #1 with 2 dsts\n" + << "7: Adding dst: got task #2 with 2 dsts\n" + << "7: Adding dst: got task #3 with 1 dsts\n" + << "7: Response with service tickets for 4 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 4 destination(s)\n" + << "3: Failed to get service ticket for dst=456: error_3\n" + << "6: Cache was partly updated with 3 service ticket(s). total: 4\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Adding dst: task #1: dst=123 got ticket\n" + << "7: Adding dst: task #1: dst=213 got ticket\n" + << "7: Adding dst: task #1: set value\n" + << "7: Adding dst: task #2: dst=213 got ticket\n" + << "4: Adding dst: task #2: dst=456 failed to get ticket: error_3\n" + << "7: Adding dst: task #2: set value\n" + << "3: Adding dst: task #2: exception: planed exc\n" + << "7: Adding dst: task #3: dst=789 got ticket\n" + << "7: Adding dst: task #3: set value\n" + << "3: Adding dst: task #3: exception: unknown error\n", + l->Stream.Str()); + } +} + +template <> +void Out<NTvmAuth::NDynamicClient::TDstResponse>(IOutputStream& out, const NTvmAuth::NDynamicClient::TDstResponse& m) { + out << m.Status << " (" << m.Error << ")"; +} + +template <> +void Out<NTvmAuth::NTvmApi::TClientSettings::TDst>(IOutputStream& out, const NTvmAuth::NTvmApi::TClientSettings::TDst& m) { + out << m.Id; +} diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make index 12290a32bd..5d01ffaad8 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ut/ya.make @@ -1,11 +1,11 @@ -UNITTEST_FOR(library/cpp/tvmauth/client/misc/api/dynamic_dst) - -OWNER(g:passport_infra) - -SRCS( - tvm_client_ut.cpp -) - +UNITTEST_FOR(library/cpp/tvmauth/client/misc/api/dynamic_dst) + +OWNER(g:passport_infra) + +SRCS( + tvm_client_ut.cpp +) + ENV(YA_TEST_SHORTEN_WINE_PATH=1) -END() +END() diff --git a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ya.make b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ya.make index 2caadae017..f3858e602f 100644 --- a/library/cpp/tvmauth/client/misc/api/dynamic_dst/ya.make +++ b/library/cpp/tvmauth/client/misc/api/dynamic_dst/ya.make @@ -1,20 +1,20 @@ -LIBRARY() - -OWNER(g:passport_infra) - -PEERDIR( +LIBRARY() + +OWNER(g:passport_infra) + +PEERDIR( library/cpp/threading/future - library/cpp/tvmauth/client -) - -SRCS( - tvm_client.cpp -) - -GENERATE_ENUM_SERIALIZATION(tvm_client.h) - -END() - -RECURSE_FOR_TESTS( - ut -) + library/cpp/tvmauth/client +) + +SRCS( + tvm_client.cpp +) + +GENERATE_ENUM_SERIALIZATION(tvm_client.h) + +END() + +RECURSE_FOR_TESTS( + ut +) diff --git a/library/cpp/tvmauth/client/misc/api/retry_settings.h b/library/cpp/tvmauth/client/misc/api/retry_settings.h index 8e379e9f56..607b230811 100644 --- a/library/cpp/tvmauth/client/misc/api/retry_settings.h +++ b/library/cpp/tvmauth/client/misc/api/retry_settings.h @@ -1,33 +1,33 @@ -#pragma once - -#include <library/cpp/tvmauth/client/misc/exponential_backoff.h> - -namespace NTvmAuth::NTvmApi { - struct TRetrySettings { - TExponentialBackoff::TSettings BackoffSettings = { - TDuration::Seconds(0), - TDuration::Minutes(1), - 2, - 0.5, - }; - TDuration MaxRandomSleepDefault = TDuration::Seconds(5); - TDuration MaxRandomSleepWhenOk = TDuration::Minutes(1); - ui32 RetriesOnStart = 3; - ui32 RetriesInBackground = 2; - TDuration WorkerAwakingPeriod = TDuration::Seconds(10); - ui32 DstsLimit = 300; - TDuration RolesUpdatePeriod = TDuration::Minutes(10); - TDuration RolesWarnPeriod = TDuration::Minutes(20); - - bool operator==(const TRetrySettings& o) const { - return BackoffSettings == o.BackoffSettings && - MaxRandomSleepDefault == o.MaxRandomSleepDefault && - MaxRandomSleepWhenOk == o.MaxRandomSleepWhenOk && - RetriesOnStart == o.RetriesOnStart && - WorkerAwakingPeriod == o.WorkerAwakingPeriod && - DstsLimit == o.DstsLimit && - RolesUpdatePeriod == o.RolesUpdatePeriod && - RolesWarnPeriod == o.RolesWarnPeriod; - } - }; -} +#pragma once + +#include <library/cpp/tvmauth/client/misc/exponential_backoff.h> + +namespace NTvmAuth::NTvmApi { + struct TRetrySettings { + TExponentialBackoff::TSettings BackoffSettings = { + TDuration::Seconds(0), + TDuration::Minutes(1), + 2, + 0.5, + }; + TDuration MaxRandomSleepDefault = TDuration::Seconds(5); + TDuration MaxRandomSleepWhenOk = TDuration::Minutes(1); + ui32 RetriesOnStart = 3; + ui32 RetriesInBackground = 2; + TDuration WorkerAwakingPeriod = TDuration::Seconds(10); + ui32 DstsLimit = 300; + TDuration RolesUpdatePeriod = TDuration::Minutes(10); + TDuration RolesWarnPeriod = TDuration::Minutes(20); + + bool operator==(const TRetrySettings& o) const { + return BackoffSettings == o.BackoffSettings && + MaxRandomSleepDefault == o.MaxRandomSleepDefault && + MaxRandomSleepWhenOk == o.MaxRandomSleepWhenOk && + RetriesOnStart == o.RetriesOnStart && + WorkerAwakingPeriod == o.WorkerAwakingPeriod && + DstsLimit == o.DstsLimit && + RolesUpdatePeriod == o.RolesUpdatePeriod && + RolesWarnPeriod == o.RolesWarnPeriod; + } + }; +} diff --git a/library/cpp/tvmauth/client/misc/api/roles_fetcher.cpp b/library/cpp/tvmauth/client/misc/api/roles_fetcher.cpp index 6d0afb95b4..b46595207c 100644 --- a/library/cpp/tvmauth/client/misc/api/roles_fetcher.cpp +++ b/library/cpp/tvmauth/client/misc/api/roles_fetcher.cpp @@ -1,163 +1,163 @@ -#include "roles_fetcher.h" - -#include <library/cpp/tvmauth/client/misc/disk_cache.h> -#include <library/cpp/tvmauth/client/misc/roles/decoder.h> -#include <library/cpp/tvmauth/client/misc/roles/parser.h> - -#include <library/cpp/string_utils/quote/quote.h> - -#include <util/string/builder.h> -#include <util/string/join.h> - -namespace NTvmAuth::NTvmApi { - static TString CreatePath(const TString& dir, const TString& file) { - return dir.EndsWith("/") - ? dir + file - : dir + "/" + file; - } - - TRolesFetcher::TRolesFetcher(const TRolesFetcherSettings& settings, TLoggerPtr logger) - : Settings_(settings) - , Logger_(logger) - , CacheFilePath_(CreatePath(Settings_.CacheDir, "roles")) - { - Client_ = std::make_unique<TKeepAliveHttpClient>( - Settings_.TiroleHost, - Settings_.TirolePort, - Settings_.Timeout, - Settings_.Timeout); - } - - TInstant TRolesFetcher::ReadFromDisk() { - TDiskReader dr(CacheFilePath_, Logger_.Get()); - if (!dr.Read()) { - return {}; - } - - std::pair<TString, TString> data = ParseDiskFormat(dr.Data()); - if (data.second != Settings_.IdmSystemSlug) { - Logger_->Warning( - TStringBuilder() << "Roles in disk cache are for another slug (" << data.second - << "). Self=" << Settings_.IdmSystemSlug); - return {}; - } - - CurrentRoles_.Set(NRoles::TParser::Parse(std::make_shared<TString>(std::move(data.first)))); - Logger_->Debug( - TStringBuilder() << "Succeed to read roles with revision " - << CurrentRoles_.Get()->GetMeta().Revision - << " from " << CacheFilePath_); - - return dr.Time(); - } - - bool TRolesFetcher::AreRolesOk() const { - return bool(GetCurrentRoles()); - } - - bool TRolesFetcher::IsTimeToUpdate(const TRetrySettings& settings, TDuration sinceUpdate) { - return settings.RolesUpdatePeriod < sinceUpdate; - } - - bool TRolesFetcher::ShouldWarn(const TRetrySettings& settings, TDuration sinceUpdate) { - return settings.RolesWarnPeriod < sinceUpdate; - } - - NUtils::TFetchResult TRolesFetcher::FetchActualRoles(const TString& serviceTicket) { - TStringStream out; - THttpHeaders outHeaders; - - TRequest req = CreateTiroleRequest(serviceTicket); - TKeepAliveHttpClient::THttpCode code = Client_->DoGet( - req.Url, - &out, - req.Headers, - &outHeaders); - - const THttpInputHeader* reqId = outHeaders.FindHeader("X-Request-Id"); - - Logger_->Debug( - TStringBuilder() << "Succeed to perform request for roles to " << Settings_.TiroleHost - << " (request_id=" << (reqId ? reqId->Value() : "") - << "). code=" << code); - - return {code, std::move(outHeaders), "/v1/get_actual_roles", out.Str(), {}}; - } - - void TRolesFetcher::Update(NUtils::TFetchResult&& fetchResult, TInstant now) { - if (fetchResult.Code == 304) { - Y_ENSURE(CurrentRoles_.Get(), - "tirole did not return any roles because current roles are actual," - " but there are no roles in memory - this should never happen"); - return; - } - - Y_ENSURE(fetchResult.Code == 200, - "Unexpected code from tirole: " << fetchResult.Code << ". " << fetchResult.Response); - - const THttpInputHeader* codec = fetchResult.Headers.FindHeader("X-Tirole-Compression"); - const TStringBuf codecBuf = codec ? codec->Value() : ""; - - NRoles::TRawPtr blob; - try { - blob = std::make_shared<TString>(NRoles::TDecoder::Decode( - codecBuf, - std::move(fetchResult.Response))); - } catch (const std::exception& e) { - throw yexception() << "Failed to decode blob with codec '" << codecBuf - << "': " << e.what(); - } - - CurrentRoles_.Set(NRoles::TParser::Parse(blob)); - - Logger_->Debug( - TStringBuilder() << "Succeed to update roles with revision " - << CurrentRoles_.Get()->GetMeta().Revision); - - TDiskWriter dw(CacheFilePath_, Logger_.Get()); - dw.Write(PrepareDiskFormat(*blob, Settings_.IdmSystemSlug), now); - } - - NTvmAuth::NRoles::TRolesPtr TRolesFetcher::GetCurrentRoles() const { - return CurrentRoles_.Get(); - } - - void TRolesFetcher::ResetConnection() { - Client_->ResetConnection(); - } - - static const char DELIMETER = '\t'; - - std::pair<TString, TString> TRolesFetcher::ParseDiskFormat(TStringBuf filebody) { - TStringBuf slug = filebody.RNextTok(DELIMETER); - return {TString(filebody), CGIUnescapeRet(slug)}; - } - - TString TRolesFetcher::PrepareDiskFormat(TStringBuf roles, TStringBuf slug) { - TStringStream res; - res.Reserve(roles.size() + 1 + slug.size()); - res << roles << DELIMETER << CGIEscapeRet(slug); - return res.Str(); - } - - TRolesFetcher::TRequest TRolesFetcher::CreateTiroleRequest(const TString& serviceTicket) const { - TRolesFetcher::TRequest res; - - TStringStream url; - url.Reserve(512); - url << "/v1/get_actual_roles?"; - url << "system_slug=" << CGIEscapeRet(Settings_.IdmSystemSlug) << "&"; - Settings_.ProcInfo.AddToRequest(url); - res.Url = std::move(url.Str()); - - res.Headers.reserve(2); - res.Headers.emplace(XYaServiceTicket_, serviceTicket); - - NRoles::TRolesPtr roles = CurrentRoles_.Get(); - if (roles) { - res.Headers.emplace(IfNoneMatch_, Join("", "\"", roles->GetMeta().Revision, "\"")); - } - - return res; - } -} +#include "roles_fetcher.h" + +#include <library/cpp/tvmauth/client/misc/disk_cache.h> +#include <library/cpp/tvmauth/client/misc/roles/decoder.h> +#include <library/cpp/tvmauth/client/misc/roles/parser.h> + +#include <library/cpp/string_utils/quote/quote.h> + +#include <util/string/builder.h> +#include <util/string/join.h> + +namespace NTvmAuth::NTvmApi { + static TString CreatePath(const TString& dir, const TString& file) { + return dir.EndsWith("/") + ? dir + file + : dir + "/" + file; + } + + TRolesFetcher::TRolesFetcher(const TRolesFetcherSettings& settings, TLoggerPtr logger) + : Settings_(settings) + , Logger_(logger) + , CacheFilePath_(CreatePath(Settings_.CacheDir, "roles")) + { + Client_ = std::make_unique<TKeepAliveHttpClient>( + Settings_.TiroleHost, + Settings_.TirolePort, + Settings_.Timeout, + Settings_.Timeout); + } + + TInstant TRolesFetcher::ReadFromDisk() { + TDiskReader dr(CacheFilePath_, Logger_.Get()); + if (!dr.Read()) { + return {}; + } + + std::pair<TString, TString> data = ParseDiskFormat(dr.Data()); + if (data.second != Settings_.IdmSystemSlug) { + Logger_->Warning( + TStringBuilder() << "Roles in disk cache are for another slug (" << data.second + << "). Self=" << Settings_.IdmSystemSlug); + return {}; + } + + CurrentRoles_.Set(NRoles::TParser::Parse(std::make_shared<TString>(std::move(data.first)))); + Logger_->Debug( + TStringBuilder() << "Succeed to read roles with revision " + << CurrentRoles_.Get()->GetMeta().Revision + << " from " << CacheFilePath_); + + return dr.Time(); + } + + bool TRolesFetcher::AreRolesOk() const { + return bool(GetCurrentRoles()); + } + + bool TRolesFetcher::IsTimeToUpdate(const TRetrySettings& settings, TDuration sinceUpdate) { + return settings.RolesUpdatePeriod < sinceUpdate; + } + + bool TRolesFetcher::ShouldWarn(const TRetrySettings& settings, TDuration sinceUpdate) { + return settings.RolesWarnPeriod < sinceUpdate; + } + + NUtils::TFetchResult TRolesFetcher::FetchActualRoles(const TString& serviceTicket) { + TStringStream out; + THttpHeaders outHeaders; + + TRequest req = CreateTiroleRequest(serviceTicket); + TKeepAliveHttpClient::THttpCode code = Client_->DoGet( + req.Url, + &out, + req.Headers, + &outHeaders); + + const THttpInputHeader* reqId = outHeaders.FindHeader("X-Request-Id"); + + Logger_->Debug( + TStringBuilder() << "Succeed to perform request for roles to " << Settings_.TiroleHost + << " (request_id=" << (reqId ? reqId->Value() : "") + << "). code=" << code); + + return {code, std::move(outHeaders), "/v1/get_actual_roles", out.Str(), {}}; + } + + void TRolesFetcher::Update(NUtils::TFetchResult&& fetchResult, TInstant now) { + if (fetchResult.Code == 304) { + Y_ENSURE(CurrentRoles_.Get(), + "tirole did not return any roles because current roles are actual," + " but there are no roles in memory - this should never happen"); + return; + } + + Y_ENSURE(fetchResult.Code == 200, + "Unexpected code from tirole: " << fetchResult.Code << ". " << fetchResult.Response); + + const THttpInputHeader* codec = fetchResult.Headers.FindHeader("X-Tirole-Compression"); + const TStringBuf codecBuf = codec ? codec->Value() : ""; + + NRoles::TRawPtr blob; + try { + blob = std::make_shared<TString>(NRoles::TDecoder::Decode( + codecBuf, + std::move(fetchResult.Response))); + } catch (const std::exception& e) { + throw yexception() << "Failed to decode blob with codec '" << codecBuf + << "': " << e.what(); + } + + CurrentRoles_.Set(NRoles::TParser::Parse(blob)); + + Logger_->Debug( + TStringBuilder() << "Succeed to update roles with revision " + << CurrentRoles_.Get()->GetMeta().Revision); + + TDiskWriter dw(CacheFilePath_, Logger_.Get()); + dw.Write(PrepareDiskFormat(*blob, Settings_.IdmSystemSlug), now); + } + + NTvmAuth::NRoles::TRolesPtr TRolesFetcher::GetCurrentRoles() const { + return CurrentRoles_.Get(); + } + + void TRolesFetcher::ResetConnection() { + Client_->ResetConnection(); + } + + static const char DELIMETER = '\t'; + + std::pair<TString, TString> TRolesFetcher::ParseDiskFormat(TStringBuf filebody) { + TStringBuf slug = filebody.RNextTok(DELIMETER); + return {TString(filebody), CGIUnescapeRet(slug)}; + } + + TString TRolesFetcher::PrepareDiskFormat(TStringBuf roles, TStringBuf slug) { + TStringStream res; + res.Reserve(roles.size() + 1 + slug.size()); + res << roles << DELIMETER << CGIEscapeRet(slug); + return res.Str(); + } + + TRolesFetcher::TRequest TRolesFetcher::CreateTiroleRequest(const TString& serviceTicket) const { + TRolesFetcher::TRequest res; + + TStringStream url; + url.Reserve(512); + url << "/v1/get_actual_roles?"; + url << "system_slug=" << CGIEscapeRet(Settings_.IdmSystemSlug) << "&"; + Settings_.ProcInfo.AddToRequest(url); + res.Url = std::move(url.Str()); + + res.Headers.reserve(2); + res.Headers.emplace(XYaServiceTicket_, serviceTicket); + + NRoles::TRolesPtr roles = CurrentRoles_.Get(); + if (roles) { + res.Headers.emplace(IfNoneMatch_, Join("", "\"", roles->GetMeta().Revision, "\"")); + } + + return res; + } +} diff --git a/library/cpp/tvmauth/client/misc/api/roles_fetcher.h b/library/cpp/tvmauth/client/misc/api/roles_fetcher.h index 36655a8fcf..63691223b5 100644 --- a/library/cpp/tvmauth/client/misc/api/roles_fetcher.h +++ b/library/cpp/tvmauth/client/misc/api/roles_fetcher.h @@ -1,63 +1,63 @@ -#pragma once - -#include "retry_settings.h" - -#include <library/cpp/tvmauth/client/misc/fetch_result.h> -#include <library/cpp/tvmauth/client/misc/proc_info.h> -#include <library/cpp/tvmauth/client/misc/utils.h> -#include <library/cpp/tvmauth/client/misc/roles/roles.h> - -#include <library/cpp/tvmauth/client/logger.h> - -#include <library/cpp/http/simple/http_client.h> - -namespace NTvmAuth::NTvmApi { - struct TRolesFetcherSettings { - TString TiroleHost; - ui16 TirolePort = 0; - TString CacheDir; - NUtils::TProcInfo ProcInfo; - TTvmId SelfTvmId = 0; - TString IdmSystemSlug; - TDuration Timeout = TDuration::Seconds(30); - }; - - class TRolesFetcher { - public: - TRolesFetcher(const TRolesFetcherSettings& settings, TLoggerPtr logger); - - TInstant ReadFromDisk(); - - bool AreRolesOk() const; - static bool IsTimeToUpdate(const TRetrySettings& settings, TDuration sinceUpdate); - static bool ShouldWarn(const TRetrySettings& settings, TDuration sinceUpdate); - - NUtils::TFetchResult FetchActualRoles(const TString& serviceTicket); - void Update(NUtils::TFetchResult&& fetchResult, TInstant now = TInstant::Now()); - - NTvmAuth::NRoles::TRolesPtr GetCurrentRoles() const; - - void ResetConnection(); - - public: - static std::pair<TString, TString> ParseDiskFormat(TStringBuf filebody); - static TString PrepareDiskFormat(TStringBuf roles, TStringBuf slug); - - struct TRequest { - TString Url; - TKeepAliveHttpClient::THeaders Headers; - }; - TRequest CreateTiroleRequest(const TString& serviceTicket) const; - - private: - const TRolesFetcherSettings Settings_; - const TLoggerPtr Logger_; - const TString CacheFilePath_; - const TString XYaServiceTicket_ = "X-Ya-Service-Ticket"; - const TString IfNoneMatch_ = "If-None-Match"; - - NUtils::TProtectedValue<NTvmAuth::NRoles::TRolesPtr> CurrentRoles_; - - std::unique_ptr<TKeepAliveHttpClient> Client_; - }; -} +#pragma once + +#include "retry_settings.h" + +#include <library/cpp/tvmauth/client/misc/fetch_result.h> +#include <library/cpp/tvmauth/client/misc/proc_info.h> +#include <library/cpp/tvmauth/client/misc/utils.h> +#include <library/cpp/tvmauth/client/misc/roles/roles.h> + +#include <library/cpp/tvmauth/client/logger.h> + +#include <library/cpp/http/simple/http_client.h> + +namespace NTvmAuth::NTvmApi { + struct TRolesFetcherSettings { + TString TiroleHost; + ui16 TirolePort = 0; + TString CacheDir; + NUtils::TProcInfo ProcInfo; + TTvmId SelfTvmId = 0; + TString IdmSystemSlug; + TDuration Timeout = TDuration::Seconds(30); + }; + + class TRolesFetcher { + public: + TRolesFetcher(const TRolesFetcherSettings& settings, TLoggerPtr logger); + + TInstant ReadFromDisk(); + + bool AreRolesOk() const; + static bool IsTimeToUpdate(const TRetrySettings& settings, TDuration sinceUpdate); + static bool ShouldWarn(const TRetrySettings& settings, TDuration sinceUpdate); + + NUtils::TFetchResult FetchActualRoles(const TString& serviceTicket); + void Update(NUtils::TFetchResult&& fetchResult, TInstant now = TInstant::Now()); + + NTvmAuth::NRoles::TRolesPtr GetCurrentRoles() const; + + void ResetConnection(); + + public: + static std::pair<TString, TString> ParseDiskFormat(TStringBuf filebody); + static TString PrepareDiskFormat(TStringBuf roles, TStringBuf slug); + + struct TRequest { + TString Url; + TKeepAliveHttpClient::THeaders Headers; + }; + TRequest CreateTiroleRequest(const TString& serviceTicket) const; + + private: + const TRolesFetcherSettings Settings_; + const TLoggerPtr Logger_; + const TString CacheFilePath_; + const TString XYaServiceTicket_ = "X-Ya-Service-Ticket"; + const TString IfNoneMatch_ = "If-None-Match"; + + NUtils::TProtectedValue<NTvmAuth::NRoles::TRolesPtr> CurrentRoles_; + + std::unique_ptr<TKeepAliveHttpClient> Client_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/api/settings.cpp b/library/cpp/tvmauth/client/misc/api/settings.cpp index 2a54834a5a..71aad75998 100644 --- a/library/cpp/tvmauth/client/misc/api/settings.cpp +++ b/library/cpp/tvmauth/client/misc/api/settings.cpp @@ -1,89 +1,89 @@ -#include "settings.h" - -#include <util/datetime/base.h> -#include <util/stream/file.h> -#include <util/system/fs.h> - -#include <set> - -namespace NTvmAuth::NTvmApi { - void TClientSettings::CheckPermissions(const TString& dir) { - const TString name = dir + "/check.tmp"; - - try { - NFs::EnsureExists(dir); - - TFile file(name, CreateAlways | RdWr); - - NFs::Remove(name); - } catch (const std::exception& e) { - NFs::Remove(name); - ythrow TPermissionDenied() << "Permission denied to disk cache directory: " << e.what(); - } - } - - void TClientSettings::CheckValid() const { - if (DiskCacheDir) { - CheckPermissions(DiskCacheDir); - } - - if (TStringBuf(Secret)) { - Y_ENSURE_EX(NeedServiceTicketsFetching(), - TBrokenTvmClientSettings() << "Secret is present but destinations list is empty. It makes no sense"); - } - if (NeedServiceTicketsFetching()) { - Y_ENSURE_EX(SelfTvmId != 0, - TBrokenTvmClientSettings() << "SelfTvmId cannot be 0 if fetching of Service Tickets required"); - Y_ENSURE_EX((TStringBuf)Secret, - TBrokenTvmClientSettings() << "Secret is required for fetching of Service Tickets"); - } - - if (CheckServiceTickets) { - Y_ENSURE_EX(SelfTvmId != 0, - TBrokenTvmClientSettings() << "SelfTvmId cannot be 0 if checking of Service Tickets required"); - } - - if (FetchRolesForIdmSystemSlug) { - Y_ENSURE_EX(DiskCacheDir, - TBrokenTvmClientSettings() << "Disk cache must be enabled to use roles: " - "they can be heavy"); - } - - bool needSmth = NeedServiceTicketsFetching() || - IsServiceTicketCheckingRequired() || - IsUserTicketCheckingRequired(); - Y_ENSURE_EX(needSmth, TBrokenTvmClientSettings() << "Invalid settings: nothing to do"); - - // Useless now: keep it here to avoid forgetting check from TDst. TODO: PASSP-35377 - for (const auto& dst : FetchServiceTicketsForDsts) { - Y_ENSURE_EX(dst.Id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); - } - // TODO: check only FetchServiceTicketsForDsts_ - // Python binding checks settings before normalization - for (const auto& [alias, dst] : FetchServiceTicketsForDstsWithAliases) { - Y_ENSURE_EX(dst.Id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); - } - Y_ENSURE_EX(TiroleTvmId != 0, TBrokenTvmClientSettings() << "TiroleTvmId cannot be 0"); - } - - TClientSettings TClientSettings::CloneNormalized() const { - TClientSettings res = *this; - - std::set<TTvmId> allDsts; - for (const auto& tvmid : res.FetchServiceTicketsForDsts) { - allDsts.insert(tvmid.Id); - } - for (const auto& [alias, tvmid] : res.FetchServiceTicketsForDstsWithAliases) { - allDsts.insert(tvmid.Id); - } - if (FetchRolesForIdmSystemSlug) { - allDsts.insert(res.TiroleTvmId); - } - - res.FetchServiceTicketsForDsts = {allDsts.begin(), allDsts.end()}; - - res.CheckValid(); - - return res; - } -} +#include "settings.h" + +#include <util/datetime/base.h> +#include <util/stream/file.h> +#include <util/system/fs.h> + +#include <set> + +namespace NTvmAuth::NTvmApi { + void TClientSettings::CheckPermissions(const TString& dir) { + const TString name = dir + "/check.tmp"; + + try { + NFs::EnsureExists(dir); + + TFile file(name, CreateAlways | RdWr); + + NFs::Remove(name); + } catch (const std::exception& e) { + NFs::Remove(name); + ythrow TPermissionDenied() << "Permission denied to disk cache directory: " << e.what(); + } + } + + void TClientSettings::CheckValid() const { + if (DiskCacheDir) { + CheckPermissions(DiskCacheDir); + } + + if (TStringBuf(Secret)) { + Y_ENSURE_EX(NeedServiceTicketsFetching(), + TBrokenTvmClientSettings() << "Secret is present but destinations list is empty. It makes no sense"); + } + if (NeedServiceTicketsFetching()) { + Y_ENSURE_EX(SelfTvmId != 0, + TBrokenTvmClientSettings() << "SelfTvmId cannot be 0 if fetching of Service Tickets required"); + Y_ENSURE_EX((TStringBuf)Secret, + TBrokenTvmClientSettings() << "Secret is required for fetching of Service Tickets"); + } + + if (CheckServiceTickets) { + Y_ENSURE_EX(SelfTvmId != 0, + TBrokenTvmClientSettings() << "SelfTvmId cannot be 0 if checking of Service Tickets required"); + } + + if (FetchRolesForIdmSystemSlug) { + Y_ENSURE_EX(DiskCacheDir, + TBrokenTvmClientSettings() << "Disk cache must be enabled to use roles: " + "they can be heavy"); + } + + bool needSmth = NeedServiceTicketsFetching() || + IsServiceTicketCheckingRequired() || + IsUserTicketCheckingRequired(); + Y_ENSURE_EX(needSmth, TBrokenTvmClientSettings() << "Invalid settings: nothing to do"); + + // Useless now: keep it here to avoid forgetting check from TDst. TODO: PASSP-35377 + for (const auto& dst : FetchServiceTicketsForDsts) { + Y_ENSURE_EX(dst.Id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); + } + // TODO: check only FetchServiceTicketsForDsts_ + // Python binding checks settings before normalization + for (const auto& [alias, dst] : FetchServiceTicketsForDstsWithAliases) { + Y_ENSURE_EX(dst.Id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); + } + Y_ENSURE_EX(TiroleTvmId != 0, TBrokenTvmClientSettings() << "TiroleTvmId cannot be 0"); + } + + TClientSettings TClientSettings::CloneNormalized() const { + TClientSettings res = *this; + + std::set<TTvmId> allDsts; + for (const auto& tvmid : res.FetchServiceTicketsForDsts) { + allDsts.insert(tvmid.Id); + } + for (const auto& [alias, tvmid] : res.FetchServiceTicketsForDstsWithAliases) { + allDsts.insert(tvmid.Id); + } + if (FetchRolesForIdmSystemSlug) { + allDsts.insert(res.TiroleTvmId); + } + + res.FetchServiceTicketsForDsts = {allDsts.begin(), allDsts.end()}; + + res.CheckValid(); + + return res; + } +} diff --git a/library/cpp/tvmauth/client/misc/api/settings.h b/library/cpp/tvmauth/client/misc/api/settings.h index 9f254859bf..715ab3e02c 100644 --- a/library/cpp/tvmauth/client/misc/api/settings.h +++ b/library/cpp/tvmauth/client/misc/api/settings.h @@ -1,302 +1,302 @@ -#pragma once - -#include <library/cpp/tvmauth/client/misc/settings.h> - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/checked_user_ticket.h> -#include <library/cpp/tvmauth/type.h> - -#include <library/cpp/string_utils/secret_string/secret_string.h> - +#pragma once + +#include <library/cpp/tvmauth/client/misc/settings.h> + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/checked_user_ticket.h> +#include <library/cpp/tvmauth/type.h> + +#include <library/cpp/string_utils/secret_string/secret_string.h> + #include <util/datetime/base.h> -#include <util/generic/hash.h> -#include <util/generic/maybe.h> - -namespace NTvmAuth::NTvmApi { - /** - * Settings for TVM client. Uses https://tvm-api.yandex.net to get state. - * At least one of them is required: - * FetchServiceTicketsForDsts_/FetchServiceTicketsForDstsWithAliases_ - * CheckServiceTickets_ - * CheckUserTicketsWithBbEnv_ - */ - class TClientSettings: public NTvmAuth::TClientSettings { - public: - class TDst; - - /** - * Alias is an internal name for destinations within your code. - * You can associate a name with an tvm_id once in your code and use the name as an alias for - * tvm_id to each calling point. Useful for several environments: prod/test/etc. - * @example: - * // init - * static const TString MY_BACKEND = "my backend"; - * TDstMap map = {{MY_BACKEND, TDst(config.get("my_back_tvm_id"))}}; - * ... - * // per request - * TString t = tvmClient.GetServiceTicket(MY_BACKEND); - */ - using TDstMap = THashMap<TAlias, TDst>; - using TDstVector = TVector<TDst>; - - public: - /*! - * NOTE: Please use this option: it provides the best reliability - * NOTE: Client requires read/write permissions - * WARNING: The same directory can be used only: - * - for TVM clients with the same settings - * OR - * - for new client replacing previous - with another config. - * System user must be the same for processes with these clients inside. - * Implementation doesn't provide other scenarios. - */ - TString DiskCacheDir; - - // Required for Service Ticket fetching or checking - TTvmId SelfTvmId = 0; - - // Options for Service Tickets fetching - NSecretString::TSecretString Secret; - /*! - * Client will process both attrs: - * FetchServiceTicketsForDsts_, FetchServiceTicketsForDstsWithAliases_ - * WARNING: It is not way to provide authorization for incoming ServiceTickets! - * It is way only to send your ServiceTickets to your backend! - */ - TDstVector FetchServiceTicketsForDsts; - TDstMap FetchServiceTicketsForDstsWithAliases; - bool IsIncompleteTicketsSetAnError = true; - - // Options for Service Tickets checking - bool CheckServiceTickets = false; - - // Options for User Tickets checking - TMaybe<EBlackboxEnv> CheckUserTicketsWithBbEnv; - - // Options for roles fetching - TString FetchRolesForIdmSystemSlug; - /*! - * By default client checks src from ServiceTicket or default uid from UserTicket - - * to prevent you from forgetting to check it yourself. - * It does binary checks only: - * ticket gets status NoRoles, if there is no role for src or default uid. - * You need to check roles on your own if you have a non-binary role system or - * you have disabled ShouldCheckSrc/ShouldCheckDefaultUid - * - * You may need to disable this check in the following cases: - * - You use GetRoles() to provide verbose message (with revision). - * Double check may be inconsistent: - * binary check inside client uses revision of roles X - i.e. src 100500 has no role, - * exact check in your code uses revision of roles Y - i.e. src 100500 has some roles. - */ - bool ShouldCheckSrc = true; - bool ShouldCheckDefaultUid = true; - - // Options for tests - TString TvmHost = "https://tvm-api.yandex.net"; - ui16 TvmPort = 443; - TString TiroleHost = "https://tirole-api.yandex.net"; - TDuration TvmSocketTimeout = TDuration::Seconds(5); - TDuration TvmConnectTimeout = TDuration::Seconds(30); - ui16 TirolePort = 443; - TTvmId TiroleTvmId = TIROLE_TVMID; - - // for debug purposes - TString LibVersionPrefix; - - void CheckValid() const; - TClientSettings CloneNormalized() const; - - static inline const TTvmId TIROLE_TVMID = 2028120; - static inline const TTvmId TIROLE_TVMID_TEST = 2026536; - - // DEPRECATED API - // TODO: get rid of it: PASSP-35377 - public: - // Deprecated: set attributes directly - void SetSelfTvmId(TTvmId selfTvmId) { - SelfTvmId = selfTvmId; - } - - // Deprecated: set attributes directly - void EnableServiceTicketChecking() { - CheckServiceTickets = true; - } - - // Deprecated: set attributes directly - void EnableUserTicketChecking(EBlackboxEnv env) { - CheckUserTicketsWithBbEnv = env; - } - - // Deprecated: set attributes directly - void SetTvmHostPort(const TString& host, ui16 port) { - TvmHost = host; - TvmPort = port; +#include <util/generic/hash.h> +#include <util/generic/maybe.h> + +namespace NTvmAuth::NTvmApi { + /** + * Settings for TVM client. Uses https://tvm-api.yandex.net to get state. + * At least one of them is required: + * FetchServiceTicketsForDsts_/FetchServiceTicketsForDstsWithAliases_ + * CheckServiceTickets_ + * CheckUserTicketsWithBbEnv_ + */ + class TClientSettings: public NTvmAuth::TClientSettings { + public: + class TDst; + + /** + * Alias is an internal name for destinations within your code. + * You can associate a name with an tvm_id once in your code and use the name as an alias for + * tvm_id to each calling point. Useful for several environments: prod/test/etc. + * @example: + * // init + * static const TString MY_BACKEND = "my backend"; + * TDstMap map = {{MY_BACKEND, TDst(config.get("my_back_tvm_id"))}}; + * ... + * // per request + * TString t = tvmClient.GetServiceTicket(MY_BACKEND); + */ + using TDstMap = THashMap<TAlias, TDst>; + using TDstVector = TVector<TDst>; + + public: + /*! + * NOTE: Please use this option: it provides the best reliability + * NOTE: Client requires read/write permissions + * WARNING: The same directory can be used only: + * - for TVM clients with the same settings + * OR + * - for new client replacing previous - with another config. + * System user must be the same for processes with these clients inside. + * Implementation doesn't provide other scenarios. + */ + TString DiskCacheDir; + + // Required for Service Ticket fetching or checking + TTvmId SelfTvmId = 0; + + // Options for Service Tickets fetching + NSecretString::TSecretString Secret; + /*! + * Client will process both attrs: + * FetchServiceTicketsForDsts_, FetchServiceTicketsForDstsWithAliases_ + * WARNING: It is not way to provide authorization for incoming ServiceTickets! + * It is way only to send your ServiceTickets to your backend! + */ + TDstVector FetchServiceTicketsForDsts; + TDstMap FetchServiceTicketsForDstsWithAliases; + bool IsIncompleteTicketsSetAnError = true; + + // Options for Service Tickets checking + bool CheckServiceTickets = false; + + // Options for User Tickets checking + TMaybe<EBlackboxEnv> CheckUserTicketsWithBbEnv; + + // Options for roles fetching + TString FetchRolesForIdmSystemSlug; + /*! + * By default client checks src from ServiceTicket or default uid from UserTicket - + * to prevent you from forgetting to check it yourself. + * It does binary checks only: + * ticket gets status NoRoles, if there is no role for src or default uid. + * You need to check roles on your own if you have a non-binary role system or + * you have disabled ShouldCheckSrc/ShouldCheckDefaultUid + * + * You may need to disable this check in the following cases: + * - You use GetRoles() to provide verbose message (with revision). + * Double check may be inconsistent: + * binary check inside client uses revision of roles X - i.e. src 100500 has no role, + * exact check in your code uses revision of roles Y - i.e. src 100500 has some roles. + */ + bool ShouldCheckSrc = true; + bool ShouldCheckDefaultUid = true; + + // Options for tests + TString TvmHost = "https://tvm-api.yandex.net"; + ui16 TvmPort = 443; + TString TiroleHost = "https://tirole-api.yandex.net"; + TDuration TvmSocketTimeout = TDuration::Seconds(5); + TDuration TvmConnectTimeout = TDuration::Seconds(30); + ui16 TirolePort = 443; + TTvmId TiroleTvmId = TIROLE_TVMID; + + // for debug purposes + TString LibVersionPrefix; + + void CheckValid() const; + TClientSettings CloneNormalized() const; + + static inline const TTvmId TIROLE_TVMID = 2028120; + static inline const TTvmId TIROLE_TVMID_TEST = 2026536; + + // DEPRECATED API + // TODO: get rid of it: PASSP-35377 + public: + // Deprecated: set attributes directly + void SetSelfTvmId(TTvmId selfTvmId) { + SelfTvmId = selfTvmId; } - // Deprecated: set attributes directly - void SetTiroleHostPort(const TString& host, ui16 port) { - TiroleHost = host; - TirolePort = port; - } - - // Deprecated: set attributes directly - void EnableRolesFetching(const TString& systemSlug, TTvmId tiroleTvmId = TIROLE_TVMID) { - TiroleTvmId = tiroleTvmId; - FetchRolesForIdmSystemSlug = systemSlug; - } - - // Deprecated: set attributes directly - void DoNotCheckSrcByDefault() { - ShouldCheckSrc = false; - } - - // Deprecated: set attributes directly - void DoNotCheckDefaultUidByDefault() { - ShouldCheckDefaultUid = false; - } - - // Deprecated: set attributes directly - void SetDiskCacheDir(const TString& dir) { - DiskCacheDir = dir; - } - - // Deprecated: set attributes directly + // Deprecated: set attributes directly + void EnableServiceTicketChecking() { + CheckServiceTickets = true; + } + + // Deprecated: set attributes directly + void EnableUserTicketChecking(EBlackboxEnv env) { + CheckUserTicketsWithBbEnv = env; + } + + // Deprecated: set attributes directly + void SetTvmHostPort(const TString& host, ui16 port) { + TvmHost = host; + TvmPort = port; + } + + // Deprecated: set attributes directly + void SetTiroleHostPort(const TString& host, ui16 port) { + TiroleHost = host; + TirolePort = port; + } + + // Deprecated: set attributes directly + void EnableRolesFetching(const TString& systemSlug, TTvmId tiroleTvmId = TIROLE_TVMID) { + TiroleTvmId = tiroleTvmId; + FetchRolesForIdmSystemSlug = systemSlug; + } + + // Deprecated: set attributes directly + void DoNotCheckSrcByDefault() { + ShouldCheckSrc = false; + } + + // Deprecated: set attributes directly + void DoNotCheckDefaultUidByDefault() { + ShouldCheckDefaultUid = false; + } + + // Deprecated: set attributes directly + void SetDiskCacheDir(const TString& dir) { + DiskCacheDir = dir; + } + + // Deprecated: set attributes directly void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, TDstMap&& dsts, const bool considerIncompleteTicketsSetAsError = true) { - IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; - Secret = selfSecret; - - FetchServiceTicketsForDsts = TDstVector{}; - FetchServiceTicketsForDsts.reserve(dsts.size()); - for (const auto& pair : dsts) { - FetchServiceTicketsForDsts.push_back(pair.second); - } - - FetchServiceTicketsForDstsWithAliases = std::move(dsts); - } - - // Deprecated: set attributes directly + IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; + Secret = selfSecret; + + FetchServiceTicketsForDsts = TDstVector{}; + FetchServiceTicketsForDsts.reserve(dsts.size()); + for (const auto& pair : dsts) { + FetchServiceTicketsForDsts.push_back(pair.second); + } + + FetchServiceTicketsForDstsWithAliases = std::move(dsts); + } + + // Deprecated: set attributes directly void EnableServiceTicketsFetchOptions(const TStringBuf selfSecret, TDstVector&& dsts, const bool considerIncompleteTicketsSetAsError = true) { - IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; - Secret = selfSecret; - FetchServiceTicketsForDsts = std::move(dsts); - } - - public: - bool IsServiceTicketFetchingRequired() const { - return bool(Secret.Value()); - } - - const TStringBuf GetSelfSecret() const { - return Secret; - } - - bool HasDstAliases() const { - return !FetchServiceTicketsForDstsWithAliases.empty(); - } - - const TDstMap& GetDstAliases() const { - return FetchServiceTicketsForDstsWithAliases; - } - - const TDstVector& GetDestinations() const { - return FetchServiceTicketsForDsts; - } - - bool IsUserTicketCheckingRequired() const { - return bool(CheckUserTicketsWithBbEnv); - } - - EBlackboxEnv GetEnvForUserTickets() const { - return *CheckUserTicketsWithBbEnv; - } - - bool IsServiceTicketCheckingRequired() const { - return CheckServiceTickets; - } - - bool IsDiskCacheUsed() const { - return bool(DiskCacheDir); - } - - TString GetDiskCacheDir() const { - return DiskCacheDir; - } - - TTvmId GetSelfTvmId() const { - return SelfTvmId; - } - - const TString& GetLibVersionPrefix() const { - return LibVersionPrefix; - } - - const TString& GetTvmHost() const { - return TvmHost; + IsIncompleteTicketsSetAnError = considerIncompleteTicketsSetAsError; + Secret = selfSecret; + FetchServiceTicketsForDsts = std::move(dsts); } - ui16 GetTvmPort() const { - return TvmPort; + public: + bool IsServiceTicketFetchingRequired() const { + return bool(Secret.Value()); } - bool IsRolesFetchingEnabled() const { - return bool(FetchRolesForIdmSystemSlug); - } - - TTvmId GetTiroleTvmId() const { - return TiroleTvmId; - } - - const TString& GetIdmSystemSlug() const { - return FetchRolesForIdmSystemSlug; - } - - const TString& GetTiroleHost() const { - return TiroleHost; - } - - ui16 GetTirolePort() const { - return TirolePort; - } - - bool NeedServiceTicketsFetching() const { - return !FetchServiceTicketsForDsts.empty() || - !FetchServiceTicketsForDstsWithAliases.empty() || - FetchRolesForIdmSystemSlug; - } - - // TODO: get rid of TDst: PASSP-35377 - class TDst { - public: - TDst(TTvmId id) - : Id(id) - { - Y_ENSURE_EX(id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); - } - - TTvmId Id; - - bool operator==(const TDst& o) const { - return Id == o.Id; - } - - bool operator<(const TDst& o) const { - return Id < o.Id; - } - - public: // for python binding - TDst() - : Id(0) - { - } - }; - - public: - static void CheckPermissions(const TString& dir); - }; -} + const TStringBuf GetSelfSecret() const { + return Secret; + } + + bool HasDstAliases() const { + return !FetchServiceTicketsForDstsWithAliases.empty(); + } + + const TDstMap& GetDstAliases() const { + return FetchServiceTicketsForDstsWithAliases; + } + + const TDstVector& GetDestinations() const { + return FetchServiceTicketsForDsts; + } + + bool IsUserTicketCheckingRequired() const { + return bool(CheckUserTicketsWithBbEnv); + } + + EBlackboxEnv GetEnvForUserTickets() const { + return *CheckUserTicketsWithBbEnv; + } + + bool IsServiceTicketCheckingRequired() const { + return CheckServiceTickets; + } + + bool IsDiskCacheUsed() const { + return bool(DiskCacheDir); + } + + TString GetDiskCacheDir() const { + return DiskCacheDir; + } + + TTvmId GetSelfTvmId() const { + return SelfTvmId; + } + + const TString& GetLibVersionPrefix() const { + return LibVersionPrefix; + } + + const TString& GetTvmHost() const { + return TvmHost; + } + + ui16 GetTvmPort() const { + return TvmPort; + } + + bool IsRolesFetchingEnabled() const { + return bool(FetchRolesForIdmSystemSlug); + } + + TTvmId GetTiroleTvmId() const { + return TiroleTvmId; + } + + const TString& GetIdmSystemSlug() const { + return FetchRolesForIdmSystemSlug; + } + + const TString& GetTiroleHost() const { + return TiroleHost; + } + + ui16 GetTirolePort() const { + return TirolePort; + } + + bool NeedServiceTicketsFetching() const { + return !FetchServiceTicketsForDsts.empty() || + !FetchServiceTicketsForDstsWithAliases.empty() || + FetchRolesForIdmSystemSlug; + } + + // TODO: get rid of TDst: PASSP-35377 + class TDst { + public: + TDst(TTvmId id) + : Id(id) + { + Y_ENSURE_EX(id != 0, TBrokenTvmClientSettings() << "TvmId cannot be 0"); + } + + TTvmId Id; + + bool operator==(const TDst& o) const { + return Id == o.Id; + } + + bool operator<(const TDst& o) const { + return Id < o.Id; + } + + public: // for python binding + TDst() + : Id(0) + { + } + }; + + public: + static void CheckPermissions(const TString& dir); + }; +} diff --git a/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp b/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp index c437e892dc..a7df49c05d 100644 --- a/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp +++ b/library/cpp/tvmauth/client/misc/api/threaded_updater.cpp @@ -1,954 +1,954 @@ -#include "threaded_updater.h" - -#include <library/cpp/tvmauth/client/misc/disk_cache.h> -#include <library/cpp/tvmauth/client/misc/utils.h> -#include <library/cpp/tvmauth/client/misc/retry_settings/v1/settings.pb.h> - -#include <library/cpp/tvmauth/client/logger.h> - -#include <library/cpp/json/json_reader.h> - -#include <util/stream/str.h> -#include <util/string/builder.h> -#include <util/string/cast.h> -#include <util/system/thread.h> - -namespace NTvmAuth::NTvmApi { - static TString CreatePublicKeysUrl(const TClientSettings& settings, - const NUtils::TProcInfo& procInfo) { - TStringStream s; - s << "/2/keys"; - s << "?"; - procInfo.AddToRequest(s); - - s << "&get_retry_settings=yes"; - - if (settings.GetSelfTvmId() != 0) { - s << "&src=" << settings.GetSelfTvmId(); - } - - if (settings.IsUserTicketCheckingRequired()) { - s << "&env=" << static_cast<int>(settings.GetEnvForUserTickets()); - } - - return s.Str(); - } - - TAsyncUpdaterPtr TThreadedUpdater::Create(const TClientSettings& settings, TLoggerPtr logger) { - Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); - THolder<TThreadedUpdater> p(new TThreadedUpdater(settings, std::move(logger))); - p->Init(); - p->StartWorker(); - return p.Release(); - } - - TThreadedUpdater::~TThreadedUpdater() { - ExpBackoff_.SetEnabled(false); - ExpBackoff_.Interrupt(); - StopWorker(); // Required here to avoid using of deleted members - } - - TClientStatus TThreadedUpdater::GetStatus() const { - const TClientStatus::ECode state = GetState(); +#include "threaded_updater.h" + +#include <library/cpp/tvmauth/client/misc/disk_cache.h> +#include <library/cpp/tvmauth/client/misc/utils.h> +#include <library/cpp/tvmauth/client/misc/retry_settings/v1/settings.pb.h> + +#include <library/cpp/tvmauth/client/logger.h> + +#include <library/cpp/json/json_reader.h> + +#include <util/stream/str.h> +#include <util/string/builder.h> +#include <util/string/cast.h> +#include <util/system/thread.h> + +namespace NTvmAuth::NTvmApi { + static TString CreatePublicKeysUrl(const TClientSettings& settings, + const NUtils::TProcInfo& procInfo) { + TStringStream s; + s << "/2/keys"; + s << "?"; + procInfo.AddToRequest(s); + + s << "&get_retry_settings=yes"; + + if (settings.GetSelfTvmId() != 0) { + s << "&src=" << settings.GetSelfTvmId(); + } + + if (settings.IsUserTicketCheckingRequired()) { + s << "&env=" << static_cast<int>(settings.GetEnvForUserTickets()); + } + + return s.Str(); + } + + TAsyncUpdaterPtr TThreadedUpdater::Create(const TClientSettings& settings, TLoggerPtr logger) { + Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); + THolder<TThreadedUpdater> p(new TThreadedUpdater(settings, std::move(logger))); + p->Init(); + p->StartWorker(); + return p.Release(); + } + + TThreadedUpdater::~TThreadedUpdater() { + ExpBackoff_.SetEnabled(false); + ExpBackoff_.Interrupt(); + StopWorker(); // Required here to avoid using of deleted members + } + + TClientStatus TThreadedUpdater::GetStatus() const { + const TClientStatus::ECode state = GetState(); return TClientStatus(state, GetLastError(state == TClientStatus::Ok || state == TClientStatus::IncompleteTicketsSet)); - } - - NRoles::TRolesPtr TThreadedUpdater::GetRoles() const { - Y_ENSURE_EX(RolesFetcher_, - TBrokenTvmClientSettings() << "Roles were not configured in settings"); - return RolesFetcher_->GetCurrentRoles(); - } - - TClientStatus::ECode TThreadedUpdater::GetState() const { - const TInstant now = TInstant::Now(); - - if (Settings_.IsServiceTicketFetchingRequired()) { - if (AreServiceTicketsInvalid(now)) { - return TClientStatus::Error; - } - auto tickets = GetCachedServiceTickets(); - if (!tickets) { - return TClientStatus::Error; - } - if (tickets->TicketsById.size() < Destinations_.size()) { - if (Settings_.IsIncompleteTicketsSetAnError) { + } + + NRoles::TRolesPtr TThreadedUpdater::GetRoles() const { + Y_ENSURE_EX(RolesFetcher_, + TBrokenTvmClientSettings() << "Roles were not configured in settings"); + return RolesFetcher_->GetCurrentRoles(); + } + + TClientStatus::ECode TThreadedUpdater::GetState() const { + const TInstant now = TInstant::Now(); + + if (Settings_.IsServiceTicketFetchingRequired()) { + if (AreServiceTicketsInvalid(now)) { + return TClientStatus::Error; + } + auto tickets = GetCachedServiceTickets(); + if (!tickets) { + return TClientStatus::Error; + } + if (tickets->TicketsById.size() < Destinations_.size()) { + if (Settings_.IsIncompleteTicketsSetAnError) { return TClientStatus::Error; } else { return TClientStatus::IncompleteTicketsSet; } - } - } - if ((Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) && ArePublicKeysInvalid(now)) { - return TClientStatus::Error; - } - - const TDuration sincePublicKeysUpdate = now - GetUpdateTimeOfPublicKeys(); - const TDuration sinceServiceTicketsUpdate = now - GetUpdateTimeOfServiceTickets(); - const TDuration sinceRolesUpdate = now - GetUpdateTimeOfRoles(); - - if (Settings_.IsServiceTicketFetchingRequired() && sinceServiceTicketsUpdate > ServiceTicketsDurations_.Expiring) { - return TClientStatus::Warning; - } - if ((Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) && - sincePublicKeysUpdate > PublicKeysDurations_.Expiring) - { - return TClientStatus::Warning; - } - if (RolesFetcher_ && TRolesFetcher::ShouldWarn(RetrySettings_, sinceRolesUpdate)) { - return TClientStatus::Warning; - } - - return TClientStatus::Ok; - } - - TThreadedUpdater::TThreadedUpdater(const TClientSettings& settings, TLoggerPtr logger) + } + } + if ((Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) && ArePublicKeysInvalid(now)) { + return TClientStatus::Error; + } + + const TDuration sincePublicKeysUpdate = now - GetUpdateTimeOfPublicKeys(); + const TDuration sinceServiceTicketsUpdate = now - GetUpdateTimeOfServiceTickets(); + const TDuration sinceRolesUpdate = now - GetUpdateTimeOfRoles(); + + if (Settings_.IsServiceTicketFetchingRequired() && sinceServiceTicketsUpdate > ServiceTicketsDurations_.Expiring) { + return TClientStatus::Warning; + } + if ((Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) && + sincePublicKeysUpdate > PublicKeysDurations_.Expiring) + { + return TClientStatus::Warning; + } + if (RolesFetcher_ && TRolesFetcher::ShouldWarn(RetrySettings_, sinceRolesUpdate)) { + return TClientStatus::Warning; + } + + return TClientStatus::Ok; + } + + TThreadedUpdater::TThreadedUpdater(const TClientSettings& settings, TLoggerPtr logger) : TThreadedUpdaterBase( - TRetrySettings{}.WorkerAwakingPeriod, - std::move(logger), - settings.GetTvmHost(), - settings.GetTvmPort(), - settings.TvmSocketTimeout, - settings.TvmConnectTimeout) - , ExpBackoff_(RetrySettings_.BackoffSettings) - , Settings_(settings.CloneNormalized()) - , ProcInfo_(NUtils::TProcInfo::Create(Settings_.GetLibVersionPrefix())) - , PublicKeysUrl_(CreatePublicKeysUrl(Settings_, ProcInfo_)) - , DstAliases_(MakeAliasMap(Settings_)) - , Headers_({{"Content-Type", "application/x-www-form-urlencoded"}}) - , Random_(TInstant::Now().MicroSeconds()) - { - if (Settings_.IsServiceTicketFetchingRequired()) { - SigningContext_ = TServiceContext::SigningFactory(Settings_.GetSelfSecret()); - } - - if (Settings_.IsServiceTicketFetchingRequired()) { - Destinations_ = {Settings_.GetDestinations().begin(), Settings_.GetDestinations().end()}; - } - - PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); - ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); - - if (Settings_.IsUserTicketCheckingRequired()) { - SetBbEnv(Settings_.GetEnvForUserTickets()); - } - - if (Settings_.IsRolesFetchingEnabled()) { - RolesFetcher_ = std::make_unique<TRolesFetcher>( - TRolesFetcherSettings{ - Settings_.GetTiroleHost(), - Settings_.GetTirolePort(), - Settings_.GetDiskCacheDir(), - ProcInfo_, - Settings_.GetSelfTvmId(), - Settings_.GetIdmSystemSlug(), - }, - Logger_); - } - - if (Settings_.IsDiskCacheUsed()) { - TString path = Settings_.GetDiskCacheDir(); - if (path.back() != '/') { - path.push_back('/'); - } - - if (Settings_.IsServiceTicketFetchingRequired()) { - ServiceTicketsFilepath_ = path; - ServiceTicketsFilepath_.append("service_tickets"); - } - - if (Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) { - PublicKeysFilepath_ = path; - PublicKeysFilepath_.append("public_keys"); - } - - RetrySettingsFilepath_ = path + "retry_settings"; + TRetrySettings{}.WorkerAwakingPeriod, + std::move(logger), + settings.GetTvmHost(), + settings.GetTvmPort(), + settings.TvmSocketTimeout, + settings.TvmConnectTimeout) + , ExpBackoff_(RetrySettings_.BackoffSettings) + , Settings_(settings.CloneNormalized()) + , ProcInfo_(NUtils::TProcInfo::Create(Settings_.GetLibVersionPrefix())) + , PublicKeysUrl_(CreatePublicKeysUrl(Settings_, ProcInfo_)) + , DstAliases_(MakeAliasMap(Settings_)) + , Headers_({{"Content-Type", "application/x-www-form-urlencoded"}}) + , Random_(TInstant::Now().MicroSeconds()) + { + if (Settings_.IsServiceTicketFetchingRequired()) { + SigningContext_ = TServiceContext::SigningFactory(Settings_.GetSelfSecret()); + } + + if (Settings_.IsServiceTicketFetchingRequired()) { + Destinations_ = {Settings_.GetDestinations().begin(), Settings_.GetDestinations().end()}; + } + + PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); + ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); + + if (Settings_.IsUserTicketCheckingRequired()) { + SetBbEnv(Settings_.GetEnvForUserTickets()); + } + + if (Settings_.IsRolesFetchingEnabled()) { + RolesFetcher_ = std::make_unique<TRolesFetcher>( + TRolesFetcherSettings{ + Settings_.GetTiroleHost(), + Settings_.GetTirolePort(), + Settings_.GetDiskCacheDir(), + ProcInfo_, + Settings_.GetSelfTvmId(), + Settings_.GetIdmSystemSlug(), + }, + Logger_); + } + + if (Settings_.IsDiskCacheUsed()) { + TString path = Settings_.GetDiskCacheDir(); + if (path.back() != '/') { + path.push_back('/'); + } + + if (Settings_.IsServiceTicketFetchingRequired()) { + ServiceTicketsFilepath_ = path; + ServiceTicketsFilepath_.append("service_tickets"); + } + + if (Settings_.IsServiceTicketCheckingRequired() || Settings_.IsUserTicketCheckingRequired()) { + PublicKeysFilepath_ = path; + PublicKeysFilepath_.append("public_keys"); + } + + RetrySettingsFilepath_ = path + "retry_settings"; } else { LogInfo("Disk cache disabled. Please set disk cache directory in settings for best reliability"); - } - } - - void TThreadedUpdater::Init() { - ReadStateFromDisk(); - ClearErrors(); - ExpBackoff_.SetEnabled(false); - - // First of all try to get tickets: there are a lot of reasons to fail this request. - // As far as disk cache usually disabled, client will not fetch keys before fail on every ctor call. - UpdateServiceTickets(); - if (!AreServicesTicketsOk()) { - ThrowLastError(); - } - - UpdatePublicKeys(); - if (!IsServiceContextOk() || !IsUserContextOk()) { - ThrowLastError(); - } - - UpdateRoles(); - if (RolesFetcher_ && !RolesFetcher_->AreRolesOk()) { - ThrowLastError(); - } - - Inited_ = true; - ExpBackoff_.SetEnabled(true); - } - - void TThreadedUpdater::UpdateServiceTickets() { - if (!Settings_.IsServiceTicketFetchingRequired()) { - return; - } - - TInstant stut = GetUpdateTimeOfServiceTickets(); - try { - if (IsTimeToUpdateServiceTickets(stut)) { - UpdateAllServiceTickets(); - NeedFetchMissingServiceTickets_ = false; - } else if (NeedFetchMissingServiceTickets_ && GetCachedServiceTickets()->TicketsById.size() < Destinations_.size()) { - UpdateMissingServiceTickets(Destinations_); - NeedFetchMissingServiceTickets_ = false; - } - if (AreServicesTicketsOk()) { - ClearError(EScope::ServiceTickets); - } - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::ServiceTickets, e.what()); - LogWarning(TStringBuilder() << "Failed to update service tickets: " << e.what()); - if (TInstant::Now() - stut > ServiceTicketsDurations_.Expiring) { - LogError("Service tickets have not been refreshed for too long period"); - } - } - } - - void TThreadedUpdater::UpdateAllServiceTickets() { - THttpResult st = GetServiceTicketsFromHttp(Destinations_, RetrySettings_.DstsLimit); - - auto oldCache = GetCachedServiceTickets(); - if (oldCache) { - for (const auto& pair : oldCache->ErrorsById) { - st.TicketsWithErrors.Errors.insert(pair); - } - } - - UpdateServiceTicketsCache(std::move(st.TicketsWithErrors), TInstant::Now()); - if (ServiceTicketsFilepath_) { - DiskCacheServiceTickets_ = CreateJsonArray(st.Responses); - TDiskWriter w(ServiceTicketsFilepath_, Logger_.Get()); - w.Write(PrepareTicketsForDisk(DiskCacheServiceTickets_, Settings_.GetSelfTvmId())); - } - } - - TServiceTicketsPtr TThreadedUpdater::UpdateMissingServiceTickets(const TDstSet& required) { - TServiceTicketsPtr cache = GetCachedServiceTickets(); - TClientSettings::TDstVector dsts = FindMissingDsts(cache, required); - - if (dsts.empty()) { - return cache; - } - - THttpResult st = GetServiceTicketsFromHttp(dsts, RetrySettings_.DstsLimit); - - size_t gotTickets = st.TicketsWithErrors.Tickets.size(); - - for (const auto& pair : cache->TicketsById) { - st.TicketsWithErrors.Tickets.insert(pair); - } - for (const auto& pair : cache->ErrorsById) { - st.TicketsWithErrors.Errors.insert(pair); - } - for (const auto& pair : st.TicketsWithErrors.Tickets) { - st.TicketsWithErrors.Errors.erase(pair.first); - } - - TServiceTicketsPtr c = UpdateServiceTicketsCachePartly( - std::move(st.TicketsWithErrors), - gotTickets); - if (!c) { - LogWarning("UpdateMissingServiceTickets: new cache is NULL. BUG?"); - c = cache; - } - - if (!ServiceTicketsFilepath_) { - return c; - } - - DiskCacheServiceTickets_ = AppendToJsonArray(DiskCacheServiceTickets_, st.Responses); - - TDiskWriter w(ServiceTicketsFilepath_, Logger_.Get()); - w.Write(PrepareTicketsForDisk(DiskCacheServiceTickets_, Settings_.GetSelfTvmId())); - - return c; - } - - void TThreadedUpdater::UpdatePublicKeys() { - if (!Settings_.IsServiceTicketCheckingRequired() && !Settings_.IsUserTicketCheckingRequired()) { - return; - } - - TInstant pkut = GetUpdateTimeOfPublicKeys(); - if (!IsTimeToUpdatePublicKeys(pkut)) { - return; - } - - try { - TString publicKeys = GetPublicKeysFromHttp(); - - UpdatePublicKeysCache(publicKeys, TInstant::Now()); - if (PublicKeysFilepath_) { - TDiskWriter w(PublicKeysFilepath_, Logger_.Get()); - w.Write(publicKeys); - } - if (IsServiceContextOk() && IsUserContextOk()) { - ClearError(EScope::PublicKeys); - } - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::PublicKeys, e.what()); - LogWarning(TStringBuilder() << "Failed to update public keys: " << e.what()); - if (TInstant::Now() - pkut > PublicKeysDurations_.Expiring) { - LogError("Public keys have not been refreshed for too long period"); - } - } - } - - void TThreadedUpdater::UpdateRoles() { - if (!RolesFetcher_) { - return; - } - - TInstant rut = GetUpdateTimeOfRoles(); - if (!TRolesFetcher::IsTimeToUpdate(RetrySettings_, TInstant::Now() - rut)) { - return; - } - - struct TCloser { - TRolesFetcher* Fetcher; - ~TCloser() { - Fetcher->ResetConnection(); - } - } closer{RolesFetcher_.get()}; - - try { - TServiceTicketsPtr st = GetCachedServiceTickets(); - Y_ENSURE(st, "No one service ticket in memory: how it possible?"); - auto it = st->TicketsById.find(Settings_.GetTiroleTvmId()); - Y_ENSURE(it != st->TicketsById.end(), - "Missing tvmid for tirole in cache: " << Settings_.GetTiroleTvmId()); - - RolesFetcher_->Update( - FetchWithRetries( - [&]() { return RolesFetcher_->FetchActualRoles(it->second); }, - EScope::Roles)); - SetUpdateTimeOfRoles(TInstant::Now()); - - if (RolesFetcher_->AreRolesOk()) { - ClearError(EScope::Roles); - } - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::Roles, e.what()); - LogWarning(TStringBuilder() << "Failed to update roles: " << e.what()); - if (TRolesFetcher::ShouldWarn(RetrySettings_, TInstant::Now() - rut)) { - LogError("Roles have not been refreshed for too long period"); - } - } - } - - TServiceTicketsPtr TThreadedUpdater::UpdateServiceTicketsCachePartly( - TAsyncUpdaterBase::TPairTicketsErrors&& tickets, - size_t got) { - size_t count = tickets.Tickets.size(); - TServiceTicketsPtr c = MakeIntrusiveConst<TServiceTickets>(std::move(tickets.Tickets), - std::move(tickets.Errors), - DstAliases_); - SetServiceTickets(c); - - LogInfo(TStringBuilder() - << "Cache was partly updated with " << got - << " service ticket(s). total: " << count); - - return c; - } - - void TThreadedUpdater::UpdateServiceTicketsCache(TPairTicketsErrors&& tickets, TInstant time) { - size_t count = tickets.Tickets.size(); - SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(std::move(tickets.Tickets), - std::move(tickets.Errors), - DstAliases_)); - - SetUpdateTimeOfServiceTickets(time); - + } + } + + void TThreadedUpdater::Init() { + ReadStateFromDisk(); + ClearErrors(); + ExpBackoff_.SetEnabled(false); + + // First of all try to get tickets: there are a lot of reasons to fail this request. + // As far as disk cache usually disabled, client will not fetch keys before fail on every ctor call. + UpdateServiceTickets(); + if (!AreServicesTicketsOk()) { + ThrowLastError(); + } + + UpdatePublicKeys(); + if (!IsServiceContextOk() || !IsUserContextOk()) { + ThrowLastError(); + } + + UpdateRoles(); + if (RolesFetcher_ && !RolesFetcher_->AreRolesOk()) { + ThrowLastError(); + } + + Inited_ = true; + ExpBackoff_.SetEnabled(true); + } + + void TThreadedUpdater::UpdateServiceTickets() { + if (!Settings_.IsServiceTicketFetchingRequired()) { + return; + } + + TInstant stut = GetUpdateTimeOfServiceTickets(); + try { + if (IsTimeToUpdateServiceTickets(stut)) { + UpdateAllServiceTickets(); + NeedFetchMissingServiceTickets_ = false; + } else if (NeedFetchMissingServiceTickets_ && GetCachedServiceTickets()->TicketsById.size() < Destinations_.size()) { + UpdateMissingServiceTickets(Destinations_); + NeedFetchMissingServiceTickets_ = false; + } + if (AreServicesTicketsOk()) { + ClearError(EScope::ServiceTickets); + } + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::ServiceTickets, e.what()); + LogWarning(TStringBuilder() << "Failed to update service tickets: " << e.what()); + if (TInstant::Now() - stut > ServiceTicketsDurations_.Expiring) { + LogError("Service tickets have not been refreshed for too long period"); + } + } + } + + void TThreadedUpdater::UpdateAllServiceTickets() { + THttpResult st = GetServiceTicketsFromHttp(Destinations_, RetrySettings_.DstsLimit); + + auto oldCache = GetCachedServiceTickets(); + if (oldCache) { + for (const auto& pair : oldCache->ErrorsById) { + st.TicketsWithErrors.Errors.insert(pair); + } + } + + UpdateServiceTicketsCache(std::move(st.TicketsWithErrors), TInstant::Now()); + if (ServiceTicketsFilepath_) { + DiskCacheServiceTickets_ = CreateJsonArray(st.Responses); + TDiskWriter w(ServiceTicketsFilepath_, Logger_.Get()); + w.Write(PrepareTicketsForDisk(DiskCacheServiceTickets_, Settings_.GetSelfTvmId())); + } + } + + TServiceTicketsPtr TThreadedUpdater::UpdateMissingServiceTickets(const TDstSet& required) { + TServiceTicketsPtr cache = GetCachedServiceTickets(); + TClientSettings::TDstVector dsts = FindMissingDsts(cache, required); + + if (dsts.empty()) { + return cache; + } + + THttpResult st = GetServiceTicketsFromHttp(dsts, RetrySettings_.DstsLimit); + + size_t gotTickets = st.TicketsWithErrors.Tickets.size(); + + for (const auto& pair : cache->TicketsById) { + st.TicketsWithErrors.Tickets.insert(pair); + } + for (const auto& pair : cache->ErrorsById) { + st.TicketsWithErrors.Errors.insert(pair); + } + for (const auto& pair : st.TicketsWithErrors.Tickets) { + st.TicketsWithErrors.Errors.erase(pair.first); + } + + TServiceTicketsPtr c = UpdateServiceTicketsCachePartly( + std::move(st.TicketsWithErrors), + gotTickets); + if (!c) { + LogWarning("UpdateMissingServiceTickets: new cache is NULL. BUG?"); + c = cache; + } + + if (!ServiceTicketsFilepath_) { + return c; + } + + DiskCacheServiceTickets_ = AppendToJsonArray(DiskCacheServiceTickets_, st.Responses); + + TDiskWriter w(ServiceTicketsFilepath_, Logger_.Get()); + w.Write(PrepareTicketsForDisk(DiskCacheServiceTickets_, Settings_.GetSelfTvmId())); + + return c; + } + + void TThreadedUpdater::UpdatePublicKeys() { + if (!Settings_.IsServiceTicketCheckingRequired() && !Settings_.IsUserTicketCheckingRequired()) { + return; + } + + TInstant pkut = GetUpdateTimeOfPublicKeys(); + if (!IsTimeToUpdatePublicKeys(pkut)) { + return; + } + + try { + TString publicKeys = GetPublicKeysFromHttp(); + + UpdatePublicKeysCache(publicKeys, TInstant::Now()); + if (PublicKeysFilepath_) { + TDiskWriter w(PublicKeysFilepath_, Logger_.Get()); + w.Write(publicKeys); + } + if (IsServiceContextOk() && IsUserContextOk()) { + ClearError(EScope::PublicKeys); + } + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::PublicKeys, e.what()); + LogWarning(TStringBuilder() << "Failed to update public keys: " << e.what()); + if (TInstant::Now() - pkut > PublicKeysDurations_.Expiring) { + LogError("Public keys have not been refreshed for too long period"); + } + } + } + + void TThreadedUpdater::UpdateRoles() { + if (!RolesFetcher_) { + return; + } + + TInstant rut = GetUpdateTimeOfRoles(); + if (!TRolesFetcher::IsTimeToUpdate(RetrySettings_, TInstant::Now() - rut)) { + return; + } + + struct TCloser { + TRolesFetcher* Fetcher; + ~TCloser() { + Fetcher->ResetConnection(); + } + } closer{RolesFetcher_.get()}; + + try { + TServiceTicketsPtr st = GetCachedServiceTickets(); + Y_ENSURE(st, "No one service ticket in memory: how it possible?"); + auto it = st->TicketsById.find(Settings_.GetTiroleTvmId()); + Y_ENSURE(it != st->TicketsById.end(), + "Missing tvmid for tirole in cache: " << Settings_.GetTiroleTvmId()); + + RolesFetcher_->Update( + FetchWithRetries( + [&]() { return RolesFetcher_->FetchActualRoles(it->second); }, + EScope::Roles)); + SetUpdateTimeOfRoles(TInstant::Now()); + + if (RolesFetcher_->AreRolesOk()) { + ClearError(EScope::Roles); + } + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::Roles, e.what()); + LogWarning(TStringBuilder() << "Failed to update roles: " << e.what()); + if (TRolesFetcher::ShouldWarn(RetrySettings_, TInstant::Now() - rut)) { + LogError("Roles have not been refreshed for too long period"); + } + } + } + + TServiceTicketsPtr TThreadedUpdater::UpdateServiceTicketsCachePartly( + TAsyncUpdaterBase::TPairTicketsErrors&& tickets, + size_t got) { + size_t count = tickets.Tickets.size(); + TServiceTicketsPtr c = MakeIntrusiveConst<TServiceTickets>(std::move(tickets.Tickets), + std::move(tickets.Errors), + DstAliases_); + SetServiceTickets(c); + + LogInfo(TStringBuilder() + << "Cache was partly updated with " << got + << " service ticket(s). total: " << count); + + return c; + } + + void TThreadedUpdater::UpdateServiceTicketsCache(TPairTicketsErrors&& tickets, TInstant time) { + size_t count = tickets.Tickets.size(); + SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(std::move(tickets.Tickets), + std::move(tickets.Errors), + DstAliases_)); + + SetUpdateTimeOfServiceTickets(time); + if (count > 0) { LogInfo(TStringBuilder() << "Cache was updated with " << count << " service ticket(s): " << time); } - } - - void TThreadedUpdater::UpdatePublicKeysCache(const TString& publicKeys, TInstant time) { - if (publicKeys.empty()) { - return; - } - - if (Settings_.IsServiceTicketCheckingRequired()) { - SetServiceContext(MakeIntrusiveConst<TServiceContext>( - TServiceContext::CheckingFactory(Settings_.GetSelfTvmId(), - publicKeys))); - } - - if (Settings_.IsUserTicketCheckingRequired()) { - SetUserContext(publicKeys); - } - - SetUpdateTimeOfPublicKeys(time); - - LogInfo(TStringBuilder() << "Cache was updated with public keys: " << time); - } - - void TThreadedUpdater::ReadStateFromDisk() { - try { - TServiceTicketsFromDisk st = ReadServiceTicketsFromDisk(); - UpdateServiceTicketsCache(std::move(st.TicketsWithErrors), st.BornDate); - DiskCacheServiceTickets_ = st.FileBody; - } catch (const std::exception& e) { - LogWarning(TStringBuilder() << "Failed to read service tickets from disk: " << e.what()); - } - - try { - std::pair<TString, TInstant> pk = ReadPublicKeysFromDisk(); - UpdatePublicKeysCache(pk.first, pk.second); - } catch (const std::exception& e) { - LogWarning(TStringBuilder() << "Failed to read public keys from disk: " << e.what()); - } - - try { - TString rs = ReadRetrySettingsFromDisk(); - UpdateRetrySettings(rs); - } catch (const std::exception& e) { - LogWarning(TStringBuilder() << "Failed to read retry settings from disk: " << e.what()); - } - - try { - if (RolesFetcher_) { - SetUpdateTimeOfRoles(RolesFetcher_->ReadFromDisk()); - } - } catch (const std::exception& e) { - LogWarning(TStringBuilder() << "Failed to read roles from disk: " << e.what()); - } - } - - TThreadedUpdater::TServiceTicketsFromDisk TThreadedUpdater::ReadServiceTicketsFromDisk() const { - if (!ServiceTicketsFilepath_) { - return {}; - } - - TDiskReader r(ServiceTicketsFilepath_, Logger_.Get()); - if (!r.Read()) { - return {}; - } - - std::pair<TStringBuf, TTvmId> data = ParseTicketsFromDisk(r.Data()); - if (data.second != Settings_.GetSelfTvmId()) { - TStringStream s; - s << "Disk cache is for another tvmId (" << data.second << "). "; - s << "Self=" << Settings_.GetSelfTvmId(); - LogWarning(s.Str()); - return {}; - } - - TPairTicketsErrors res; - ParseTicketsFromResponse(data.first, Destinations_, res); - if (IsInvalid(TServiceTickets::GetInvalidationTime(res.Tickets), TInstant::Now())) { - LogWarning("Disk cache (service tickets) is too old"); - return {}; - } - - LogInfo(TStringBuilder() << "Got " << res.Tickets.size() << " service ticket(s) from disk"); - return {std::move(res), r.Time(), TString(data.first)}; - } - - std::pair<TString, TInstant> TThreadedUpdater::ReadPublicKeysFromDisk() const { - if (!PublicKeysFilepath_) { - return {}; - } - - TDiskReader r(PublicKeysFilepath_, Logger_.Get()); - if (!r.Read()) { - return {}; - } - - if (TInstant::Now() - r.Time() > PublicKeysDurations_.Invalid) { - LogWarning("Disk cache (public keys) is too old"); - return {}; - } - - return {r.Data(), r.Time()}; - } - - TString TThreadedUpdater::ReadRetrySettingsFromDisk() const { - if (!RetrySettingsFilepath_) { - return {}; - } - - TDiskReader r(RetrySettingsFilepath_, Logger_.Get()); - if (!r.Read()) { - return {}; - } - - return r.Data(); - } - - template <class Dsts> - TThreadedUpdater::THttpResult TThreadedUpdater::GetServiceTicketsFromHttp(const Dsts& dsts, const size_t dstLimit) const { - Y_ENSURE(SigningContext_, "Internal error"); - - TClientSettings::TDstVector part; - part.reserve(dstLimit); - THttpResult res; - res.TicketsWithErrors.Tickets.reserve(dsts.size()); - res.Responses.reserve(dsts.size() / dstLimit + 1); - - for (auto it = dsts.begin(); it != dsts.end();) { - part.clear(); - for (size_t count = 0; it != dsts.end() && count < dstLimit; ++count, ++it) { - part.push_back(*it); - } - - TString response = - FetchWithRetries( - [this, &part]() { - // create request here to keep 'ts' actual - return FetchServiceTicketsFromHttp(PrepareRequestForServiceTickets( - Settings_.GetSelfTvmId(), - *SigningContext_, - part, - ProcInfo_)); - }, - EScope::ServiceTickets) - .Response; - ParseTicketsFromResponse(response, part, res.TicketsWithErrors); - LogDebug(TStringBuilder() - << "Response with service tickets for " << part.size() - << " destination(s) was successfully fetched from " << TvmUrl_); - - res.Responses.push_back(response); - } - - LogDebug(TStringBuilder() - << "Got responses with service tickets with " << res.Responses.size() << " pages for " - << dsts.size() << " destination(s)"); - for (const auto& p : res.TicketsWithErrors.Errors) { - LogError(TStringBuilder() - << "Failed to get service ticket for dst=" << p.first << ": " << p.second); - } - - return res; - } - - TString TThreadedUpdater::GetPublicKeysFromHttp() const { - TString publicKeys = - FetchWithRetries( - [this]() { return FetchPublicKeysFromHttp(); }, - EScope::PublicKeys) - .Response; - - LogDebug("Public keys were successfully fetched from " + TvmUrl_); - - return publicKeys; - } - - NUtils::TFetchResult TThreadedUpdater::FetchServiceTicketsFromHttp(const TString& body) const { - TStringStream s; - - THttpHeaders outHeaders; - TKeepAliveHttpClient::THttpCode code = GetClient().DoPost("/2/ticket", body, &s, Headers_, &outHeaders); - - const THttpInputHeader* settings = outHeaders.FindHeader("X-Ya-Retry-Settings"); - - return {code, {}, "/2/ticket", s.Str(), settings ? settings->Value() : ""}; - } - - NUtils::TFetchResult TThreadedUpdater::FetchPublicKeysFromHttp() const { - TStringStream s; - - THttpHeaders outHeaders; - TKeepAliveHttpClient::THttpCode code = GetClient().DoGet(PublicKeysUrl_, &s, {}, &outHeaders); - - const THttpInputHeader* settings = outHeaders.FindHeader("X-Ya-Retry-Settings"); - - return {code, {}, "/2/keys", s.Str(), settings ? settings->Value() : ""}; - } - - bool TThreadedUpdater::UpdateRetrySettings(const TString& header) const { - if (header.empty()) { - // Probably it is some kind of test? - return false; - } - - try { - TString raw = NUtils::Base64url2bin(header); - Y_ENSURE(raw, "Invalid base64url in settings"); - - retry_settings::v1::Settings proto; - Y_ENSURE(proto.ParseFromString(raw), "Invalid proto"); - - // This ugly hack helps to process these settings in any case - TThreadedUpdater& this_ = *const_cast<TThreadedUpdater*>(this); - TRetrySettings& res = this_.RetrySettings_; - - TStringStream diff; - auto update = [&diff](auto& l, const auto& r, TStringBuf desc) { - if (l != r) { - diff << desc << ":" << l << "->" << r << ";"; - l = r; - } - }; - - if (proto.has_exponential_backoff_min_sec()) { - update(res.BackoffSettings.Min, - TDuration::Seconds(proto.exponential_backoff_min_sec()), - "exponential_backoff_min"); - } - if (proto.has_exponential_backoff_max_sec()) { - update(res.BackoffSettings.Max, - TDuration::Seconds(proto.exponential_backoff_max_sec()), - "exponential_backoff_max"); - } - if (proto.has_exponential_backoff_factor()) { - update(res.BackoffSettings.Factor, - proto.exponential_backoff_factor(), - "exponential_backoff_factor"); - } - if (proto.has_exponential_backoff_jitter()) { - update(res.BackoffSettings.Jitter, - proto.exponential_backoff_jitter(), - "exponential_backoff_jitter"); - } - this_.ExpBackoff_.UpdateSettings(res.BackoffSettings); - - if (proto.has_max_random_sleep_default()) { - update(res.MaxRandomSleepDefault, - TDuration::MilliSeconds(proto.max_random_sleep_default()), - "max_random_sleep_default"); - } - if (proto.has_max_random_sleep_when_ok()) { - update(res.MaxRandomSleepWhenOk, - TDuration::MilliSeconds(proto.max_random_sleep_when_ok()), - "max_random_sleep_when_ok"); - } - if (proto.has_retries_on_start()) { - Y_ENSURE(proto.retries_on_start(), "retries_on_start==0"); - update(res.RetriesOnStart, - proto.retries_on_start(), - "retries_on_start"); - } - if (proto.has_retries_in_background()) { - Y_ENSURE(proto.retries_in_background(), "retries_in_background==0"); - update(res.RetriesInBackground, - proto.retries_in_background(), - "retries_in_background"); - } - if (proto.has_worker_awaking_period_sec()) { - update(res.WorkerAwakingPeriod, - TDuration::Seconds(proto.worker_awaking_period_sec()), - "worker_awaking_period"); - this_.WorkerAwakingPeriod_ = res.WorkerAwakingPeriod; - } - if (proto.has_dsts_limit()) { - Y_ENSURE(proto.dsts_limit(), "dsts_limit==0"); - update(res.DstsLimit, - proto.dsts_limit(), - "dsts_limit"); - } - - if (proto.has_roles_update_period_sec()) { - Y_ENSURE(proto.roles_update_period_sec(), "roles_update_period==0"); - update(res.RolesUpdatePeriod, - TDuration::Seconds(proto.roles_update_period_sec()), - "roles_update_period_sec"); - } - if (proto.has_roles_warn_period_sec()) { - Y_ENSURE(proto.roles_warn_period_sec(), "roles_warn_period_sec==0"); - update(res.RolesWarnPeriod, - TDuration::Seconds(proto.roles_warn_period_sec()), - "roles_warn_period_sec"); - } - - if (diff.empty()) { - return false; - } - - LogDebug("Retry settings were updated: " + diff.Str()); - return true; - } catch (const std::exception& e) { - LogWarning(TStringBuilder() - << "Failed to update retry settings from server, header '" - << header << "': " - << e.what()); - } - - return false; - } - - template <typename Func> - NUtils::TFetchResult TThreadedUpdater::FetchWithRetries(Func func, EScope scope) const { - const ui32 tries = Inited_ ? RetrySettings_.RetriesInBackground - : RetrySettings_.RetriesOnStart; - - for (size_t idx = 1;; ++idx) { - RandomSleep(); - - try { - NUtils::TFetchResult result = func(); - - if (UpdateRetrySettings(result.RetrySettings) && RetrySettingsFilepath_) { - TDiskWriter w(RetrySettingsFilepath_, Logger_.Get()); - w.Write(result.RetrySettings); - } - - if (400 <= result.Code && result.Code <= 499) { - throw TNonRetriableException() << ProcessHttpError(scope, result.Path, result.Code, result.Response); - } - if (result.Code < 200 || result.Code >= 399) { - throw yexception() << ProcessHttpError(scope, result.Path, result.Code, result.Response); - } - - ExpBackoff_.Decrease(); - return result; - } catch (const TNonRetriableException& e) { - LogWarning(TStringBuilder() << "Failed to get " << scope << ": " << e.what()); - ExpBackoff_.Increase(); - throw; - } catch (const std::exception& e) { - LogWarning(TStringBuilder() << "Failed to get " << scope << ": " << e.what()); - ExpBackoff_.Increase(); - if (idx >= tries) { - throw; - } - } - } - - throw yexception() << "unreachable"; - } - - void TThreadedUpdater::RandomSleep() const { - const TDuration maxSleep = TClientStatus::ECode::Ok == GetState() - ? RetrySettings_.MaxRandomSleepWhenOk - : RetrySettings_.MaxRandomSleepDefault; - - if (maxSleep) { - ui32 toSleep = Random_.GenRand() % maxSleep.MilliSeconds(); - ExpBackoff_.Sleep(TDuration::MilliSeconds(toSleep)); - } - } - - TString TThreadedUpdater::PrepareRequestForServiceTickets(TTvmId src, - const TServiceContext& ctx, - const TClientSettings::TDstVector& dsts, - const NUtils::TProcInfo& procInfo, - time_t now) { - TStringStream s; - - const TString ts = IntToString<10>(now); - TStringStream dst; - dst.Reserve(10 * dsts.size()); - for (const TClientSettings::TDst& d : dsts) { - if (dst.Str()) { - dst << ','; - } - dst << d.Id; - } - - s << "grant_type=client_credentials"; - s << "&src=" << src; - s << "&dst=" << dst.Str(); - s << "&ts=" << ts; - s << "&sign=" << ctx.SignCgiParamsForTvm(ts, dst.Str()); - s << "&get_retry_settings=yes"; - - s << "&"; - procInfo.AddToRequest(s); - - return s.Str(); - } - - template <class Dsts> - void TThreadedUpdater::ParseTicketsFromResponse(TStringBuf resp, - const Dsts& dsts, - TPairTicketsErrors& out) const { - NJson::TJsonValue doc; - Y_ENSURE(NJson::ReadJsonTree(resp, &doc), "Invalid json from tvm-api: " << resp); - - const NJson::TJsonValue* currentResp = doc.IsMap() ? &doc : nullptr; - auto find = [¤tResp, &doc](TTvmId id, NJson::TJsonValue& obj) -> bool { - const TString idStr = IntToString<10>(id); - if (currentResp && currentResp->GetValue(idStr, &obj)) { - return true; - } - - for (const NJson::TJsonValue& val : doc.GetArray()) { - currentResp = &val; - if (currentResp->GetValue(idStr, &obj)) { - return true; - } - } - - return false; - }; - - for (const TClientSettings::TDst& d : dsts) { - NJson::TJsonValue obj; - NJson::TJsonValue val; - - if (!find(d.Id, obj) || !obj.GetValue("ticket", &val)) { - TString err; - if (obj.GetValue("error", &val)) { - err = val.GetString(); - } else { - err = "Missing tvm_id in response, should never happend: " + IntToString<10>(d.Id); - } - - TStringStream s; - s << "Failed to get ServiceTicket for " << d.Id << ": " << err; - ProcessError(EType::NonRetriable, EScope::ServiceTickets, s.Str()); - - out.Errors.insert({d.Id, std::move(err)}); - continue; - } - - out.Tickets.insert({d.Id, val.GetString()}); - } - } - - static const char DELIMETER = '\t'; - TString TThreadedUpdater::PrepareTicketsForDisk(TStringBuf tvmResponse, TTvmId selfId) { - TStringStream s; - s << tvmResponse << DELIMETER << selfId; - return s.Str(); - } - - std::pair<TStringBuf, TTvmId> TThreadedUpdater::ParseTicketsFromDisk(TStringBuf data) { - TStringBuf tvmId = data.RNextTok(DELIMETER); - return {data, IntFromString<TTvmId, 10>(tvmId)}; - } - - const TDstSet& TThreadedUpdater::GetDsts() const { - return Destinations_; - } - - void TThreadedUpdater::AddDstToSettings(const TClientSettings::TDst& dst) { - Destinations_.insert(dst); - } - - bool TThreadedUpdater::IsTimeToUpdateServiceTickets(TInstant lastUpdate) const { - return TInstant::Now() - lastUpdate > ServiceTicketsDurations_.RefreshPeriod; - } - - bool TThreadedUpdater::IsTimeToUpdatePublicKeys(TInstant lastUpdate) const { - return TInstant::Now() - lastUpdate > PublicKeysDurations_.RefreshPeriod; - } - - bool TThreadedUpdater::AreServicesTicketsOk() const { - if (!Settings_.IsServiceTicketFetchingRequired()) { - return true; - } - auto c = GetCachedServiceTickets(); - return c && (!Settings_.IsIncompleteTicketsSetAnError || c->TicketsById.size() == Destinations_.size()); - } - - bool TThreadedUpdater::IsServiceContextOk() const { - if (!Settings_.IsServiceTicketCheckingRequired()) { - return true; - } - - return bool(GetCachedServiceContext()); - } - - bool TThreadedUpdater::IsUserContextOk() const { - if (!Settings_.IsUserTicketCheckingRequired()) { - return true; - } - return bool(GetCachedUserContext()); - } - - void TThreadedUpdater::Worker() { - UpdateServiceTickets(); - UpdatePublicKeys(); - UpdateRoles(); - } - - TServiceTickets::TMapAliasId TThreadedUpdater::MakeAliasMap(const TClientSettings& settings) { - TServiceTickets::TMapAliasId res; - - if (settings.HasDstAliases()) { - for (const auto& pair : settings.GetDstAliases()) { - res.insert({pair.first, pair.second.Id}); - } - } - - return res; - } - - TClientSettings::TDstVector TThreadedUpdater::FindMissingDsts(TServiceTicketsPtr available, const TDstSet& required) { - Y_ENSURE(available); - TDstSet set; - // available->TicketsById is not sorted - for (const auto& pair : available->TicketsById) { - set.insert(pair.first); - } - return FindMissingDsts(set, required); - } - - TClientSettings::TDstVector TThreadedUpdater::FindMissingDsts(const TDstSet& available, const TDstSet& required) { - TClientSettings::TDstVector res; - std::set_difference(required.begin(), required.end(), - available.begin(), available.end(), - std::inserter(res, res.begin())); - return res; - } - - TString TThreadedUpdater::CreateJsonArray(const TSmallVec<TString>& responses) { - if (responses.empty()) { - return "[]"; - } - - size_t size = 0; - for (const TString& r : responses) { - size += r.size() + 1; - } - - TString res; - res.reserve(size + 2); - - res.push_back('['); - for (const TString& r : responses) { - res.append(r).push_back(','); - } - res.back() = ']'; - - return res; - } - - TString TThreadedUpdater::AppendToJsonArray(const TString& json, const TSmallVec<TString>& responses) { - Y_ENSURE(json, "previous body required"); - - size_t size = 0; - for (const TString& r : responses) { - size += r.size() + 1; - } - - TString res; - res.reserve(size + 2 + json.size()); - - res.push_back('['); - if (json.StartsWith('[')) { - Y_ENSURE(json.EndsWith(']'), "array is broken:" << json); - res.append(TStringBuf(json).Chop(1).Skip(1)); - } else { - res.append(json); - } - - res.push_back(','); - for (const TString& r : responses) { - res.append(r).push_back(','); - } - res.back() = ']'; - - return res; - } -} + } + + void TThreadedUpdater::UpdatePublicKeysCache(const TString& publicKeys, TInstant time) { + if (publicKeys.empty()) { + return; + } + + if (Settings_.IsServiceTicketCheckingRequired()) { + SetServiceContext(MakeIntrusiveConst<TServiceContext>( + TServiceContext::CheckingFactory(Settings_.GetSelfTvmId(), + publicKeys))); + } + + if (Settings_.IsUserTicketCheckingRequired()) { + SetUserContext(publicKeys); + } + + SetUpdateTimeOfPublicKeys(time); + + LogInfo(TStringBuilder() << "Cache was updated with public keys: " << time); + } + + void TThreadedUpdater::ReadStateFromDisk() { + try { + TServiceTicketsFromDisk st = ReadServiceTicketsFromDisk(); + UpdateServiceTicketsCache(std::move(st.TicketsWithErrors), st.BornDate); + DiskCacheServiceTickets_ = st.FileBody; + } catch (const std::exception& e) { + LogWarning(TStringBuilder() << "Failed to read service tickets from disk: " << e.what()); + } + + try { + std::pair<TString, TInstant> pk = ReadPublicKeysFromDisk(); + UpdatePublicKeysCache(pk.first, pk.second); + } catch (const std::exception& e) { + LogWarning(TStringBuilder() << "Failed to read public keys from disk: " << e.what()); + } + + try { + TString rs = ReadRetrySettingsFromDisk(); + UpdateRetrySettings(rs); + } catch (const std::exception& e) { + LogWarning(TStringBuilder() << "Failed to read retry settings from disk: " << e.what()); + } + + try { + if (RolesFetcher_) { + SetUpdateTimeOfRoles(RolesFetcher_->ReadFromDisk()); + } + } catch (const std::exception& e) { + LogWarning(TStringBuilder() << "Failed to read roles from disk: " << e.what()); + } + } + + TThreadedUpdater::TServiceTicketsFromDisk TThreadedUpdater::ReadServiceTicketsFromDisk() const { + if (!ServiceTicketsFilepath_) { + return {}; + } + + TDiskReader r(ServiceTicketsFilepath_, Logger_.Get()); + if (!r.Read()) { + return {}; + } + + std::pair<TStringBuf, TTvmId> data = ParseTicketsFromDisk(r.Data()); + if (data.second != Settings_.GetSelfTvmId()) { + TStringStream s; + s << "Disk cache is for another tvmId (" << data.second << "). "; + s << "Self=" << Settings_.GetSelfTvmId(); + LogWarning(s.Str()); + return {}; + } + + TPairTicketsErrors res; + ParseTicketsFromResponse(data.first, Destinations_, res); + if (IsInvalid(TServiceTickets::GetInvalidationTime(res.Tickets), TInstant::Now())) { + LogWarning("Disk cache (service tickets) is too old"); + return {}; + } + + LogInfo(TStringBuilder() << "Got " << res.Tickets.size() << " service ticket(s) from disk"); + return {std::move(res), r.Time(), TString(data.first)}; + } + + std::pair<TString, TInstant> TThreadedUpdater::ReadPublicKeysFromDisk() const { + if (!PublicKeysFilepath_) { + return {}; + } + + TDiskReader r(PublicKeysFilepath_, Logger_.Get()); + if (!r.Read()) { + return {}; + } + + if (TInstant::Now() - r.Time() > PublicKeysDurations_.Invalid) { + LogWarning("Disk cache (public keys) is too old"); + return {}; + } + + return {r.Data(), r.Time()}; + } + + TString TThreadedUpdater::ReadRetrySettingsFromDisk() const { + if (!RetrySettingsFilepath_) { + return {}; + } + + TDiskReader r(RetrySettingsFilepath_, Logger_.Get()); + if (!r.Read()) { + return {}; + } + + return r.Data(); + } + + template <class Dsts> + TThreadedUpdater::THttpResult TThreadedUpdater::GetServiceTicketsFromHttp(const Dsts& dsts, const size_t dstLimit) const { + Y_ENSURE(SigningContext_, "Internal error"); + + TClientSettings::TDstVector part; + part.reserve(dstLimit); + THttpResult res; + res.TicketsWithErrors.Tickets.reserve(dsts.size()); + res.Responses.reserve(dsts.size() / dstLimit + 1); + + for (auto it = dsts.begin(); it != dsts.end();) { + part.clear(); + for (size_t count = 0; it != dsts.end() && count < dstLimit; ++count, ++it) { + part.push_back(*it); + } + + TString response = + FetchWithRetries( + [this, &part]() { + // create request here to keep 'ts' actual + return FetchServiceTicketsFromHttp(PrepareRequestForServiceTickets( + Settings_.GetSelfTvmId(), + *SigningContext_, + part, + ProcInfo_)); + }, + EScope::ServiceTickets) + .Response; + ParseTicketsFromResponse(response, part, res.TicketsWithErrors); + LogDebug(TStringBuilder() + << "Response with service tickets for " << part.size() + << " destination(s) was successfully fetched from " << TvmUrl_); + + res.Responses.push_back(response); + } + + LogDebug(TStringBuilder() + << "Got responses with service tickets with " << res.Responses.size() << " pages for " + << dsts.size() << " destination(s)"); + for (const auto& p : res.TicketsWithErrors.Errors) { + LogError(TStringBuilder() + << "Failed to get service ticket for dst=" << p.first << ": " << p.second); + } + + return res; + } + + TString TThreadedUpdater::GetPublicKeysFromHttp() const { + TString publicKeys = + FetchWithRetries( + [this]() { return FetchPublicKeysFromHttp(); }, + EScope::PublicKeys) + .Response; + + LogDebug("Public keys were successfully fetched from " + TvmUrl_); + + return publicKeys; + } + + NUtils::TFetchResult TThreadedUpdater::FetchServiceTicketsFromHttp(const TString& body) const { + TStringStream s; + + THttpHeaders outHeaders; + TKeepAliveHttpClient::THttpCode code = GetClient().DoPost("/2/ticket", body, &s, Headers_, &outHeaders); + + const THttpInputHeader* settings = outHeaders.FindHeader("X-Ya-Retry-Settings"); + + return {code, {}, "/2/ticket", s.Str(), settings ? settings->Value() : ""}; + } + + NUtils::TFetchResult TThreadedUpdater::FetchPublicKeysFromHttp() const { + TStringStream s; + + THttpHeaders outHeaders; + TKeepAliveHttpClient::THttpCode code = GetClient().DoGet(PublicKeysUrl_, &s, {}, &outHeaders); + + const THttpInputHeader* settings = outHeaders.FindHeader("X-Ya-Retry-Settings"); + + return {code, {}, "/2/keys", s.Str(), settings ? settings->Value() : ""}; + } + + bool TThreadedUpdater::UpdateRetrySettings(const TString& header) const { + if (header.empty()) { + // Probably it is some kind of test? + return false; + } + + try { + TString raw = NUtils::Base64url2bin(header); + Y_ENSURE(raw, "Invalid base64url in settings"); + + retry_settings::v1::Settings proto; + Y_ENSURE(proto.ParseFromString(raw), "Invalid proto"); + + // This ugly hack helps to process these settings in any case + TThreadedUpdater& this_ = *const_cast<TThreadedUpdater*>(this); + TRetrySettings& res = this_.RetrySettings_; + + TStringStream diff; + auto update = [&diff](auto& l, const auto& r, TStringBuf desc) { + if (l != r) { + diff << desc << ":" << l << "->" << r << ";"; + l = r; + } + }; + + if (proto.has_exponential_backoff_min_sec()) { + update(res.BackoffSettings.Min, + TDuration::Seconds(proto.exponential_backoff_min_sec()), + "exponential_backoff_min"); + } + if (proto.has_exponential_backoff_max_sec()) { + update(res.BackoffSettings.Max, + TDuration::Seconds(proto.exponential_backoff_max_sec()), + "exponential_backoff_max"); + } + if (proto.has_exponential_backoff_factor()) { + update(res.BackoffSettings.Factor, + proto.exponential_backoff_factor(), + "exponential_backoff_factor"); + } + if (proto.has_exponential_backoff_jitter()) { + update(res.BackoffSettings.Jitter, + proto.exponential_backoff_jitter(), + "exponential_backoff_jitter"); + } + this_.ExpBackoff_.UpdateSettings(res.BackoffSettings); + + if (proto.has_max_random_sleep_default()) { + update(res.MaxRandomSleepDefault, + TDuration::MilliSeconds(proto.max_random_sleep_default()), + "max_random_sleep_default"); + } + if (proto.has_max_random_sleep_when_ok()) { + update(res.MaxRandomSleepWhenOk, + TDuration::MilliSeconds(proto.max_random_sleep_when_ok()), + "max_random_sleep_when_ok"); + } + if (proto.has_retries_on_start()) { + Y_ENSURE(proto.retries_on_start(), "retries_on_start==0"); + update(res.RetriesOnStart, + proto.retries_on_start(), + "retries_on_start"); + } + if (proto.has_retries_in_background()) { + Y_ENSURE(proto.retries_in_background(), "retries_in_background==0"); + update(res.RetriesInBackground, + proto.retries_in_background(), + "retries_in_background"); + } + if (proto.has_worker_awaking_period_sec()) { + update(res.WorkerAwakingPeriod, + TDuration::Seconds(proto.worker_awaking_period_sec()), + "worker_awaking_period"); + this_.WorkerAwakingPeriod_ = res.WorkerAwakingPeriod; + } + if (proto.has_dsts_limit()) { + Y_ENSURE(proto.dsts_limit(), "dsts_limit==0"); + update(res.DstsLimit, + proto.dsts_limit(), + "dsts_limit"); + } + + if (proto.has_roles_update_period_sec()) { + Y_ENSURE(proto.roles_update_period_sec(), "roles_update_period==0"); + update(res.RolesUpdatePeriod, + TDuration::Seconds(proto.roles_update_period_sec()), + "roles_update_period_sec"); + } + if (proto.has_roles_warn_period_sec()) { + Y_ENSURE(proto.roles_warn_period_sec(), "roles_warn_period_sec==0"); + update(res.RolesWarnPeriod, + TDuration::Seconds(proto.roles_warn_period_sec()), + "roles_warn_period_sec"); + } + + if (diff.empty()) { + return false; + } + + LogDebug("Retry settings were updated: " + diff.Str()); + return true; + } catch (const std::exception& e) { + LogWarning(TStringBuilder() + << "Failed to update retry settings from server, header '" + << header << "': " + << e.what()); + } + + return false; + } + + template <typename Func> + NUtils::TFetchResult TThreadedUpdater::FetchWithRetries(Func func, EScope scope) const { + const ui32 tries = Inited_ ? RetrySettings_.RetriesInBackground + : RetrySettings_.RetriesOnStart; + + for (size_t idx = 1;; ++idx) { + RandomSleep(); + + try { + NUtils::TFetchResult result = func(); + + if (UpdateRetrySettings(result.RetrySettings) && RetrySettingsFilepath_) { + TDiskWriter w(RetrySettingsFilepath_, Logger_.Get()); + w.Write(result.RetrySettings); + } + + if (400 <= result.Code && result.Code <= 499) { + throw TNonRetriableException() << ProcessHttpError(scope, result.Path, result.Code, result.Response); + } + if (result.Code < 200 || result.Code >= 399) { + throw yexception() << ProcessHttpError(scope, result.Path, result.Code, result.Response); + } + + ExpBackoff_.Decrease(); + return result; + } catch (const TNonRetriableException& e) { + LogWarning(TStringBuilder() << "Failed to get " << scope << ": " << e.what()); + ExpBackoff_.Increase(); + throw; + } catch (const std::exception& e) { + LogWarning(TStringBuilder() << "Failed to get " << scope << ": " << e.what()); + ExpBackoff_.Increase(); + if (idx >= tries) { + throw; + } + } + } + + throw yexception() << "unreachable"; + } + + void TThreadedUpdater::RandomSleep() const { + const TDuration maxSleep = TClientStatus::ECode::Ok == GetState() + ? RetrySettings_.MaxRandomSleepWhenOk + : RetrySettings_.MaxRandomSleepDefault; + + if (maxSleep) { + ui32 toSleep = Random_.GenRand() % maxSleep.MilliSeconds(); + ExpBackoff_.Sleep(TDuration::MilliSeconds(toSleep)); + } + } + + TString TThreadedUpdater::PrepareRequestForServiceTickets(TTvmId src, + const TServiceContext& ctx, + const TClientSettings::TDstVector& dsts, + const NUtils::TProcInfo& procInfo, + time_t now) { + TStringStream s; + + const TString ts = IntToString<10>(now); + TStringStream dst; + dst.Reserve(10 * dsts.size()); + for (const TClientSettings::TDst& d : dsts) { + if (dst.Str()) { + dst << ','; + } + dst << d.Id; + } + + s << "grant_type=client_credentials"; + s << "&src=" << src; + s << "&dst=" << dst.Str(); + s << "&ts=" << ts; + s << "&sign=" << ctx.SignCgiParamsForTvm(ts, dst.Str()); + s << "&get_retry_settings=yes"; + + s << "&"; + procInfo.AddToRequest(s); + + return s.Str(); + } + + template <class Dsts> + void TThreadedUpdater::ParseTicketsFromResponse(TStringBuf resp, + const Dsts& dsts, + TPairTicketsErrors& out) const { + NJson::TJsonValue doc; + Y_ENSURE(NJson::ReadJsonTree(resp, &doc), "Invalid json from tvm-api: " << resp); + + const NJson::TJsonValue* currentResp = doc.IsMap() ? &doc : nullptr; + auto find = [¤tResp, &doc](TTvmId id, NJson::TJsonValue& obj) -> bool { + const TString idStr = IntToString<10>(id); + if (currentResp && currentResp->GetValue(idStr, &obj)) { + return true; + } + + for (const NJson::TJsonValue& val : doc.GetArray()) { + currentResp = &val; + if (currentResp->GetValue(idStr, &obj)) { + return true; + } + } + + return false; + }; + + for (const TClientSettings::TDst& d : dsts) { + NJson::TJsonValue obj; + NJson::TJsonValue val; + + if (!find(d.Id, obj) || !obj.GetValue("ticket", &val)) { + TString err; + if (obj.GetValue("error", &val)) { + err = val.GetString(); + } else { + err = "Missing tvm_id in response, should never happend: " + IntToString<10>(d.Id); + } + + TStringStream s; + s << "Failed to get ServiceTicket for " << d.Id << ": " << err; + ProcessError(EType::NonRetriable, EScope::ServiceTickets, s.Str()); + + out.Errors.insert({d.Id, std::move(err)}); + continue; + } + + out.Tickets.insert({d.Id, val.GetString()}); + } + } + + static const char DELIMETER = '\t'; + TString TThreadedUpdater::PrepareTicketsForDisk(TStringBuf tvmResponse, TTvmId selfId) { + TStringStream s; + s << tvmResponse << DELIMETER << selfId; + return s.Str(); + } + + std::pair<TStringBuf, TTvmId> TThreadedUpdater::ParseTicketsFromDisk(TStringBuf data) { + TStringBuf tvmId = data.RNextTok(DELIMETER); + return {data, IntFromString<TTvmId, 10>(tvmId)}; + } + + const TDstSet& TThreadedUpdater::GetDsts() const { + return Destinations_; + } + + void TThreadedUpdater::AddDstToSettings(const TClientSettings::TDst& dst) { + Destinations_.insert(dst); + } + + bool TThreadedUpdater::IsTimeToUpdateServiceTickets(TInstant lastUpdate) const { + return TInstant::Now() - lastUpdate > ServiceTicketsDurations_.RefreshPeriod; + } + + bool TThreadedUpdater::IsTimeToUpdatePublicKeys(TInstant lastUpdate) const { + return TInstant::Now() - lastUpdate > PublicKeysDurations_.RefreshPeriod; + } + + bool TThreadedUpdater::AreServicesTicketsOk() const { + if (!Settings_.IsServiceTicketFetchingRequired()) { + return true; + } + auto c = GetCachedServiceTickets(); + return c && (!Settings_.IsIncompleteTicketsSetAnError || c->TicketsById.size() == Destinations_.size()); + } + + bool TThreadedUpdater::IsServiceContextOk() const { + if (!Settings_.IsServiceTicketCheckingRequired()) { + return true; + } + + return bool(GetCachedServiceContext()); + } + + bool TThreadedUpdater::IsUserContextOk() const { + if (!Settings_.IsUserTicketCheckingRequired()) { + return true; + } + return bool(GetCachedUserContext()); + } + + void TThreadedUpdater::Worker() { + UpdateServiceTickets(); + UpdatePublicKeys(); + UpdateRoles(); + } + + TServiceTickets::TMapAliasId TThreadedUpdater::MakeAliasMap(const TClientSettings& settings) { + TServiceTickets::TMapAliasId res; + + if (settings.HasDstAliases()) { + for (const auto& pair : settings.GetDstAliases()) { + res.insert({pair.first, pair.second.Id}); + } + } + + return res; + } + + TClientSettings::TDstVector TThreadedUpdater::FindMissingDsts(TServiceTicketsPtr available, const TDstSet& required) { + Y_ENSURE(available); + TDstSet set; + // available->TicketsById is not sorted + for (const auto& pair : available->TicketsById) { + set.insert(pair.first); + } + return FindMissingDsts(set, required); + } + + TClientSettings::TDstVector TThreadedUpdater::FindMissingDsts(const TDstSet& available, const TDstSet& required) { + TClientSettings::TDstVector res; + std::set_difference(required.begin(), required.end(), + available.begin(), available.end(), + std::inserter(res, res.begin())); + return res; + } + + TString TThreadedUpdater::CreateJsonArray(const TSmallVec<TString>& responses) { + if (responses.empty()) { + return "[]"; + } + + size_t size = 0; + for (const TString& r : responses) { + size += r.size() + 1; + } + + TString res; + res.reserve(size + 2); + + res.push_back('['); + for (const TString& r : responses) { + res.append(r).push_back(','); + } + res.back() = ']'; + + return res; + } + + TString TThreadedUpdater::AppendToJsonArray(const TString& json, const TSmallVec<TString>& responses) { + Y_ENSURE(json, "previous body required"); + + size_t size = 0; + for (const TString& r : responses) { + size += r.size() + 1; + } + + TString res; + res.reserve(size + 2 + json.size()); + + res.push_back('['); + if (json.StartsWith('[')) { + Y_ENSURE(json.EndsWith(']'), "array is broken:" << json); + res.append(TStringBuf(json).Chop(1).Skip(1)); + } else { + res.append(json); + } + + res.push_back(','); + for (const TString& r : responses) { + res.append(r).push_back(','); + } + res.back() = ']'; + + return res; + } +} diff --git a/library/cpp/tvmauth/client/misc/api/threaded_updater.h b/library/cpp/tvmauth/client/misc/api/threaded_updater.h index 9983c49e6d..e546bbe030 100644 --- a/library/cpp/tvmauth/client/misc/api/threaded_updater.h +++ b/library/cpp/tvmauth/client/misc/api/threaded_updater.h @@ -1,140 +1,140 @@ -#pragma once - -#include "retry_settings.h" -#include "roles_fetcher.h" -#include "settings.h" - -#include <library/cpp/tvmauth/client/misc/async_updater.h> -#include <library/cpp/tvmauth/client/misc/threaded_updater.h> - -#include <util/generic/set.h> -#include <util/random/fast.h> - -namespace NTvmAuth::NTvmApi { - using TDstSet = TSet<TClientSettings::TDst>; - - class TThreadedUpdater: public TThreadedUpdaterBase { - public: - /*! - * Starts thread for updating of in-memory cache in background - * Reads cache from disk if specified - * @param settings - * @param logger is usefull for monitoring and debuging - */ - static TAsyncUpdaterPtr Create(const TClientSettings& settings, TLoggerPtr logger); - ~TThreadedUpdater(); - - TClientStatus GetStatus() const override; - NRoles::TRolesPtr GetRoles() const override; - - protected: // for tests - TClientStatus::ECode GetState() const; - - TThreadedUpdater(const TClientSettings& settings, TLoggerPtr logger); - void Init(); - - void UpdateServiceTickets(); - void UpdateAllServiceTickets(); - TServiceTicketsPtr UpdateMissingServiceTickets(const TDstSet& required); - void UpdatePublicKeys(); - void UpdateRoles(); - - TServiceTicketsPtr UpdateServiceTicketsCachePartly(TPairTicketsErrors&& tickets, size_t got); - void UpdateServiceTicketsCache(TPairTicketsErrors&& tickets, TInstant time); - void UpdatePublicKeysCache(const TString& publicKeys, TInstant time); - - void ReadStateFromDisk(); - - struct TServiceTicketsFromDisk { - TPairTicketsErrors TicketsWithErrors; - TInstant BornDate; - TString FileBody; - }; - - TServiceTicketsFromDisk ReadServiceTicketsFromDisk() const; - std::pair<TString, TInstant> ReadPublicKeysFromDisk() const; - TString ReadRetrySettingsFromDisk() const; - - struct THttpResult { - TPairTicketsErrors TicketsWithErrors; - TSmallVec<TString> Responses; - }; - - template <class Dsts> - THttpResult GetServiceTicketsFromHttp(const Dsts& dsts, const size_t dstLimit) const; - TString GetPublicKeysFromHttp() const; - - virtual NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString& body) const; - virtual NUtils::TFetchResult FetchPublicKeysFromHttp() const; - - bool UpdateRetrySettings(const TString& header) const; - - template <typename Func> - NUtils::TFetchResult FetchWithRetries(Func func, EScope scope) const; - void RandomSleep() const; - - static TString PrepareRequestForServiceTickets(TTvmId src, - const TServiceContext& ctx, - const TClientSettings::TDstVector& dsts, - const NUtils::TProcInfo& procInfo, - time_t now = time(nullptr)); - template <class Dsts> - void ParseTicketsFromResponse(TStringBuf resp, - const Dsts& dsts, - TPairTicketsErrors& out) const; - - static TString PrepareTicketsForDisk(TStringBuf tvmResponse, TTvmId selfId); - static std::pair<TStringBuf, TTvmId> ParseTicketsFromDisk(TStringBuf data); - - const TDstSet& GetDsts() const; - void AddDstToSettings(const TClientSettings::TDst& dst); - - bool IsTimeToUpdateServiceTickets(TInstant lastUpdate) const; - bool IsTimeToUpdatePublicKeys(TInstant lastUpdate) const; - - bool AreServicesTicketsOk() const; - bool IsServiceContextOk() const; - bool IsUserContextOk() const; - - void Worker() override; - - static TServiceTickets::TMapAliasId MakeAliasMap(const TClientSettings& settings); - static TClientSettings::TDstVector FindMissingDsts(TServiceTicketsPtr available, const TDstSet& required); - static TClientSettings::TDstVector FindMissingDsts(const TDstSet& available, const TDstSet& required); - - static TString CreateJsonArray(const TSmallVec<TString>& responses); - static TString AppendToJsonArray(const TString& json, const TSmallVec<TString>& responses); - - private: - TRetrySettings RetrySettings_; - - protected: - mutable TExponentialBackoff ExpBackoff_; - - private: - const TClientSettings Settings_; - - const NUtils::TProcInfo ProcInfo_; - - const TString PublicKeysUrl_; - - const TServiceTickets::TMapAliasId DstAliases_; - - const TKeepAliveHttpClient::THeaders Headers_; - TMaybe<TServiceContext> SigningContext_; - - TDstSet Destinations_; - TString DiskCacheServiceTickets_; - bool NeedFetchMissingServiceTickets_ = true; - - TString PublicKeysFilepath_; - TString ServiceTicketsFilepath_; - TString RetrySettingsFilepath_; - - std::unique_ptr<TRolesFetcher> RolesFetcher_; - - mutable TReallyFastRng32 Random_; - - bool Inited_ = false; - }; -} +#pragma once + +#include "retry_settings.h" +#include "roles_fetcher.h" +#include "settings.h" + +#include <library/cpp/tvmauth/client/misc/async_updater.h> +#include <library/cpp/tvmauth/client/misc/threaded_updater.h> + +#include <util/generic/set.h> +#include <util/random/fast.h> + +namespace NTvmAuth::NTvmApi { + using TDstSet = TSet<TClientSettings::TDst>; + + class TThreadedUpdater: public TThreadedUpdaterBase { + public: + /*! + * Starts thread for updating of in-memory cache in background + * Reads cache from disk if specified + * @param settings + * @param logger is usefull for monitoring and debuging + */ + static TAsyncUpdaterPtr Create(const TClientSettings& settings, TLoggerPtr logger); + ~TThreadedUpdater(); + + TClientStatus GetStatus() const override; + NRoles::TRolesPtr GetRoles() const override; + + protected: // for tests + TClientStatus::ECode GetState() const; + + TThreadedUpdater(const TClientSettings& settings, TLoggerPtr logger); + void Init(); + + void UpdateServiceTickets(); + void UpdateAllServiceTickets(); + TServiceTicketsPtr UpdateMissingServiceTickets(const TDstSet& required); + void UpdatePublicKeys(); + void UpdateRoles(); + + TServiceTicketsPtr UpdateServiceTicketsCachePartly(TPairTicketsErrors&& tickets, size_t got); + void UpdateServiceTicketsCache(TPairTicketsErrors&& tickets, TInstant time); + void UpdatePublicKeysCache(const TString& publicKeys, TInstant time); + + void ReadStateFromDisk(); + + struct TServiceTicketsFromDisk { + TPairTicketsErrors TicketsWithErrors; + TInstant BornDate; + TString FileBody; + }; + + TServiceTicketsFromDisk ReadServiceTicketsFromDisk() const; + std::pair<TString, TInstant> ReadPublicKeysFromDisk() const; + TString ReadRetrySettingsFromDisk() const; + + struct THttpResult { + TPairTicketsErrors TicketsWithErrors; + TSmallVec<TString> Responses; + }; + + template <class Dsts> + THttpResult GetServiceTicketsFromHttp(const Dsts& dsts, const size_t dstLimit) const; + TString GetPublicKeysFromHttp() const; + + virtual NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString& body) const; + virtual NUtils::TFetchResult FetchPublicKeysFromHttp() const; + + bool UpdateRetrySettings(const TString& header) const; + + template <typename Func> + NUtils::TFetchResult FetchWithRetries(Func func, EScope scope) const; + void RandomSleep() const; + + static TString PrepareRequestForServiceTickets(TTvmId src, + const TServiceContext& ctx, + const TClientSettings::TDstVector& dsts, + const NUtils::TProcInfo& procInfo, + time_t now = time(nullptr)); + template <class Dsts> + void ParseTicketsFromResponse(TStringBuf resp, + const Dsts& dsts, + TPairTicketsErrors& out) const; + + static TString PrepareTicketsForDisk(TStringBuf tvmResponse, TTvmId selfId); + static std::pair<TStringBuf, TTvmId> ParseTicketsFromDisk(TStringBuf data); + + const TDstSet& GetDsts() const; + void AddDstToSettings(const TClientSettings::TDst& dst); + + bool IsTimeToUpdateServiceTickets(TInstant lastUpdate) const; + bool IsTimeToUpdatePublicKeys(TInstant lastUpdate) const; + + bool AreServicesTicketsOk() const; + bool IsServiceContextOk() const; + bool IsUserContextOk() const; + + void Worker() override; + + static TServiceTickets::TMapAliasId MakeAliasMap(const TClientSettings& settings); + static TClientSettings::TDstVector FindMissingDsts(TServiceTicketsPtr available, const TDstSet& required); + static TClientSettings::TDstVector FindMissingDsts(const TDstSet& available, const TDstSet& required); + + static TString CreateJsonArray(const TSmallVec<TString>& responses); + static TString AppendToJsonArray(const TString& json, const TSmallVec<TString>& responses); + + private: + TRetrySettings RetrySettings_; + + protected: + mutable TExponentialBackoff ExpBackoff_; + + private: + const TClientSettings Settings_; + + const NUtils::TProcInfo ProcInfo_; + + const TString PublicKeysUrl_; + + const TServiceTickets::TMapAliasId DstAliases_; + + const TKeepAliveHttpClient::THeaders Headers_; + TMaybe<TServiceContext> SigningContext_; + + TDstSet Destinations_; + TString DiskCacheServiceTickets_; + bool NeedFetchMissingServiceTickets_ = true; + + TString PublicKeysFilepath_; + TString ServiceTicketsFilepath_; + TString RetrySettingsFilepath_; + + std::unique_ptr<TRolesFetcher> RolesFetcher_; + + mutable TReallyFastRng32 Random_; + + bool Inited_ = false; + }; +} diff --git a/library/cpp/tvmauth/client/misc/async_updater.cpp b/library/cpp/tvmauth/client/misc/async_updater.cpp index 47bc889ef5..9cb0332ed4 100644 --- a/library/cpp/tvmauth/client/misc/async_updater.cpp +++ b/library/cpp/tvmauth/client/misc/async_updater.cpp @@ -1,152 +1,152 @@ -#include "async_updater.h" - -#include "utils.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <util/string/builder.h> -#include <util/system/spin_wait.h> - -namespace NTvmAuth { - TAsyncUpdaterBase::TAsyncUpdaterBase() { - ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); - ServiceTicketsDurations_.Expiring = TDuration::Hours(2); - ServiceTicketsDurations_.Invalid = TDuration::Hours(11); - - PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); - PublicKeysDurations_.Expiring = TDuration::Days(2); - PublicKeysDurations_.Invalid = TDuration::Days(6); - } - - NRoles::TRolesPtr TAsyncUpdaterBase::GetRoles() const { - ythrow TIllegalUsage() << "not implemented"; - } - - TInstant TAsyncUpdaterBase::GetUpdateTimeOfPublicKeys() const { - return PublicKeysTime_.Get(); - } - - TInstant TAsyncUpdaterBase::GetUpdateTimeOfServiceTickets() const { - return ServiceTicketsTime_.Get(); - } - - TInstant TAsyncUpdaterBase::GetUpdateTimeOfRoles() const { - return RolesTime_.Get(); - } - - TInstant TAsyncUpdaterBase::GetInvalidationTimeOfPublicKeys() const { - TInstant ins = GetUpdateTimeOfPublicKeys(); - return ins == TInstant() ? TInstant() : ins + PublicKeysDurations_.Invalid; - } - - TInstant TAsyncUpdaterBase::GetInvalidationTimeOfServiceTickets() const { - TServiceTicketsPtr c = GetCachedServiceTickets(); - return c ? c->InvalidationTime : TInstant(); - } - - bool TAsyncUpdaterBase::ArePublicKeysInvalid(TInstant now) const { - return IsInvalid(GetInvalidationTimeOfPublicKeys(), now); - } - - bool TAsyncUpdaterBase::AreServiceTicketsInvalid(TInstant now) const { +#include "async_updater.h" + +#include "utils.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <util/string/builder.h> +#include <util/system/spin_wait.h> + +namespace NTvmAuth { + TAsyncUpdaterBase::TAsyncUpdaterBase() { + ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); + ServiceTicketsDurations_.Expiring = TDuration::Hours(2); + ServiceTicketsDurations_.Invalid = TDuration::Hours(11); + + PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); + PublicKeysDurations_.Expiring = TDuration::Days(2); + PublicKeysDurations_.Invalid = TDuration::Days(6); + } + + NRoles::TRolesPtr TAsyncUpdaterBase::GetRoles() const { + ythrow TIllegalUsage() << "not implemented"; + } + + TInstant TAsyncUpdaterBase::GetUpdateTimeOfPublicKeys() const { + return PublicKeysTime_.Get(); + } + + TInstant TAsyncUpdaterBase::GetUpdateTimeOfServiceTickets() const { + return ServiceTicketsTime_.Get(); + } + + TInstant TAsyncUpdaterBase::GetUpdateTimeOfRoles() const { + return RolesTime_.Get(); + } + + TInstant TAsyncUpdaterBase::GetInvalidationTimeOfPublicKeys() const { + TInstant ins = GetUpdateTimeOfPublicKeys(); + return ins == TInstant() ? TInstant() : ins + PublicKeysDurations_.Invalid; + } + + TInstant TAsyncUpdaterBase::GetInvalidationTimeOfServiceTickets() const { + TServiceTicketsPtr c = GetCachedServiceTickets(); + return c ? c->InvalidationTime : TInstant(); + } + + bool TAsyncUpdaterBase::ArePublicKeysInvalid(TInstant now) const { + return IsInvalid(GetInvalidationTimeOfPublicKeys(), now); + } + + bool TAsyncUpdaterBase::AreServiceTicketsInvalid(TInstant now) const { TServiceTicketsPtr c = GetCachedServiceTickets(); // Empty set of tickets is allways valid. - return c && !c->TicketsById.empty() && IsInvalid(GetInvalidationTimeOfServiceTickets(), now); - } - - bool TAsyncUpdaterBase::IsInvalid(TInstant invTime, TInstant now) { - return invTime - - TDuration::Minutes(1) // lag for closing from balancer - < now; - } - - void TAsyncUpdaterBase::SetBbEnv(EBlackboxEnv original, TMaybe<EBlackboxEnv> overrided) { - if (overrided) { - Y_ENSURE_EX(NUtils::CheckBbEnvOverriding(original, *overrided), - TBrokenTvmClientSettings() << "Overriding of BlackboxEnv is illegal: " - << original << " -> " << *overrided); - } - - Envs_.store({original, overrided}, std::memory_order_relaxed); - } - - TServiceTicketsPtr TAsyncUpdaterBase::GetCachedServiceTickets() const { - return ServiceTickets_.Get(); - } - - TServiceContextPtr TAsyncUpdaterBase::GetCachedServiceContext() const { - return ServiceContext_.Get(); - } - - TUserContextPtr TAsyncUpdaterBase::GetCachedUserContext(TMaybe<EBlackboxEnv> overridenEnv) const { - TAllUserContextsPtr ctx = AllUserContexts_.Get(); - if (!ctx) { - return nullptr; - } - - const TEnvs envs = Envs_.load(std::memory_order_relaxed); - if (!envs.Original) { - return nullptr; - } - - EBlackboxEnv env = *envs.Original; - - if (overridenEnv) { - Y_ENSURE_EX(NUtils::CheckBbEnvOverriding(*envs.Original, *overridenEnv), - TBrokenTvmClientSettings() << "Overriding of BlackboxEnv is illegal: " - << *envs.Original << " -> " << *overridenEnv); - env = *overridenEnv; - } else if (envs.Overrided) { - env = *envs.Overrided; - } - - return ctx->Get(env); - } - - void TAsyncUpdaterBase::SetServiceTickets(TServiceTicketsPtr c) { - ServiceTickets_.Set(std::move(c)); - } - - void TAsyncUpdaterBase::SetServiceContext(TServiceContextPtr c) { - ServiceContext_.Set(std::move(c)); - } - - void TAsyncUpdaterBase::SetUserContext(TStringBuf publicKeys) { - AllUserContexts_.Set(MakeIntrusiveConst<TAllUserContexts>(publicKeys)); - } - - void TAsyncUpdaterBase::SetUpdateTimeOfPublicKeys(TInstant ins) { - PublicKeysTime_.Set(ins); - } - - void TAsyncUpdaterBase::SetUpdateTimeOfServiceTickets(TInstant ins) { - ServiceTicketsTime_.Set(ins); - } - - void TAsyncUpdaterBase::SetUpdateTimeOfRoles(TInstant ins) { - RolesTime_.Set(ins); - } - - bool TAsyncUpdaterBase::IsServiceTicketMapOk(TServiceTicketsPtr c, size_t expectedTicketCount, bool strict) { - return c && - (strict - ? c->TicketsById.size() == expectedTicketCount - : !c->TicketsById.empty()); - } - - TAllUserContexts::TAllUserContexts(TStringBuf publicKeys) { - auto add = [&, this](EBlackboxEnv env) { - Ctx_[(size_t)env] = MakeIntrusiveConst<TUserContext>(env, publicKeys); - }; - - add(EBlackboxEnv::Prod); - add(EBlackboxEnv::Test); - add(EBlackboxEnv::ProdYateam); - add(EBlackboxEnv::TestYateam); - add(EBlackboxEnv::Stress); - } - - TUserContextPtr TAllUserContexts::Get(EBlackboxEnv env) const { - return Ctx_[(size_t)env]; - } -} + return c && !c->TicketsById.empty() && IsInvalid(GetInvalidationTimeOfServiceTickets(), now); + } + + bool TAsyncUpdaterBase::IsInvalid(TInstant invTime, TInstant now) { + return invTime - + TDuration::Minutes(1) // lag for closing from balancer + < now; + } + + void TAsyncUpdaterBase::SetBbEnv(EBlackboxEnv original, TMaybe<EBlackboxEnv> overrided) { + if (overrided) { + Y_ENSURE_EX(NUtils::CheckBbEnvOverriding(original, *overrided), + TBrokenTvmClientSettings() << "Overriding of BlackboxEnv is illegal: " + << original << " -> " << *overrided); + } + + Envs_.store({original, overrided}, std::memory_order_relaxed); + } + + TServiceTicketsPtr TAsyncUpdaterBase::GetCachedServiceTickets() const { + return ServiceTickets_.Get(); + } + + TServiceContextPtr TAsyncUpdaterBase::GetCachedServiceContext() const { + return ServiceContext_.Get(); + } + + TUserContextPtr TAsyncUpdaterBase::GetCachedUserContext(TMaybe<EBlackboxEnv> overridenEnv) const { + TAllUserContextsPtr ctx = AllUserContexts_.Get(); + if (!ctx) { + return nullptr; + } + + const TEnvs envs = Envs_.load(std::memory_order_relaxed); + if (!envs.Original) { + return nullptr; + } + + EBlackboxEnv env = *envs.Original; + + if (overridenEnv) { + Y_ENSURE_EX(NUtils::CheckBbEnvOverriding(*envs.Original, *overridenEnv), + TBrokenTvmClientSettings() << "Overriding of BlackboxEnv is illegal: " + << *envs.Original << " -> " << *overridenEnv); + env = *overridenEnv; + } else if (envs.Overrided) { + env = *envs.Overrided; + } + + return ctx->Get(env); + } + + void TAsyncUpdaterBase::SetServiceTickets(TServiceTicketsPtr c) { + ServiceTickets_.Set(std::move(c)); + } + + void TAsyncUpdaterBase::SetServiceContext(TServiceContextPtr c) { + ServiceContext_.Set(std::move(c)); + } + + void TAsyncUpdaterBase::SetUserContext(TStringBuf publicKeys) { + AllUserContexts_.Set(MakeIntrusiveConst<TAllUserContexts>(publicKeys)); + } + + void TAsyncUpdaterBase::SetUpdateTimeOfPublicKeys(TInstant ins) { + PublicKeysTime_.Set(ins); + } + + void TAsyncUpdaterBase::SetUpdateTimeOfServiceTickets(TInstant ins) { + ServiceTicketsTime_.Set(ins); + } + + void TAsyncUpdaterBase::SetUpdateTimeOfRoles(TInstant ins) { + RolesTime_.Set(ins); + } + + bool TAsyncUpdaterBase::IsServiceTicketMapOk(TServiceTicketsPtr c, size_t expectedTicketCount, bool strict) { + return c && + (strict + ? c->TicketsById.size() == expectedTicketCount + : !c->TicketsById.empty()); + } + + TAllUserContexts::TAllUserContexts(TStringBuf publicKeys) { + auto add = [&, this](EBlackboxEnv env) { + Ctx_[(size_t)env] = MakeIntrusiveConst<TUserContext>(env, publicKeys); + }; + + add(EBlackboxEnv::Prod); + add(EBlackboxEnv::Test); + add(EBlackboxEnv::ProdYateam); + add(EBlackboxEnv::TestYateam); + add(EBlackboxEnv::Stress); + } + + TUserContextPtr TAllUserContexts::Get(EBlackboxEnv env) const { + return Ctx_[(size_t)env]; + } +} diff --git a/library/cpp/tvmauth/client/misc/async_updater.h b/library/cpp/tvmauth/client/misc/async_updater.h index 1ad6c209f8..7b556d7a38 100644 --- a/library/cpp/tvmauth/client/misc/async_updater.h +++ b/library/cpp/tvmauth/client/misc/async_updater.h @@ -1,183 +1,183 @@ -#pragma once - -#include "last_error.h" -#include "settings.h" -#include "roles/roles.h" - -#include <library/cpp/tvmauth/client/client_status.h> -#include <library/cpp/tvmauth/client/logger.h> - -#include <library/cpp/tvmauth/deprecated/service_context.h> -#include <library/cpp/tvmauth/deprecated/user_context.h> -#include <library/cpp/tvmauth/src/utils.h> - -#include <util/datetime/base.h> -#include <util/generic/hash.h> -#include <util/generic/maybe.h> -#include <util/generic/noncopyable.h> -#include <util/generic/ptr.h> - -#include <array> +#pragma once + +#include "last_error.h" +#include "settings.h" +#include "roles/roles.h" + +#include <library/cpp/tvmauth/client/client_status.h> +#include <library/cpp/tvmauth/client/logger.h> + +#include <library/cpp/tvmauth/deprecated/service_context.h> +#include <library/cpp/tvmauth/deprecated/user_context.h> +#include <library/cpp/tvmauth/src/utils.h> + +#include <util/datetime/base.h> +#include <util/generic/hash.h> +#include <util/generic/maybe.h> +#include <util/generic/noncopyable.h> +#include <util/generic/ptr.h> + +#include <array> #include <atomic> - -namespace NTvmAuth::NInternal { - class TClientCaningKnife; -} - -namespace NTvmAuth { - class TServiceTickets: public TAtomicRefCount<TServiceTickets> { - public: - using TMapAliasStr = THashMap<TClientSettings::TAlias, TString>; - using TMapIdStr = THashMap<TTvmId, TString>; + +namespace NTvmAuth::NInternal { + class TClientCaningKnife; +} + +namespace NTvmAuth { + class TServiceTickets: public TAtomicRefCount<TServiceTickets> { + public: + using TMapAliasStr = THashMap<TClientSettings::TAlias, TString>; + using TMapIdStr = THashMap<TTvmId, TString>; using TIdSet = THashSet<TTvmId>; using TAliasSet = THashSet<TClientSettings::TAlias>; - using TMapAliasId = THashMap<TClientSettings::TAlias, TTvmId>; - - TServiceTickets(TMapIdStr&& tickets, TMapIdStr&& errors, const TMapAliasId& dstMap) - : TicketsById(std::move(tickets)) - , ErrorsById(std::move(errors)) - { + using TMapAliasId = THashMap<TClientSettings::TAlias, TTvmId>; + + TServiceTickets(TMapIdStr&& tickets, TMapIdStr&& errors, const TMapAliasId& dstMap) + : TicketsById(std::move(tickets)) + , ErrorsById(std::move(errors)) + { InitAliasesAndUnfetchedIds(dstMap); - InitInvalidationTime(); - } - - static TInstant GetInvalidationTime(const TMapIdStr& ticketsById) { - TInstant res; - - for (const auto& pair : ticketsById) { - TMaybe<TInstant> t = NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(pair.second); - if (!t) { - continue; - } - - res = res == TInstant() ? *t : std::min(res, *t); - } - - return res; - } - - public: - TMapIdStr TicketsById; - TMapIdStr ErrorsById; - TMapAliasStr TicketsByAlias; - TMapAliasStr ErrorsByAlias; - TInstant InvalidationTime; - TIdSet UnfetchedIds; - TAliasSet UnfetchedAliases; - - private: + InitInvalidationTime(); + } + + static TInstant GetInvalidationTime(const TMapIdStr& ticketsById) { + TInstant res; + + for (const auto& pair : ticketsById) { + TMaybe<TInstant> t = NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(pair.second); + if (!t) { + continue; + } + + res = res == TInstant() ? *t : std::min(res, *t); + } + + return res; + } + + public: + TMapIdStr TicketsById; + TMapIdStr ErrorsById; + TMapAliasStr TicketsByAlias; + TMapAliasStr ErrorsByAlias; + TInstant InvalidationTime; + TIdSet UnfetchedIds; + TAliasSet UnfetchedAliases; + + private: void InitAliasesAndUnfetchedIds(const TMapAliasId& dstMap) { - for (const auto& pair : dstMap) { - auto it = TicketsById.find(pair.second); - auto errIt = ErrorsById.find(pair.second); - - if (it == TicketsById.end()) { - if (errIt != ErrorsById.end()) { - Y_ENSURE(ErrorsByAlias.insert({pair.first, errIt->second}).second, + for (const auto& pair : dstMap) { + auto it = TicketsById.find(pair.second); + auto errIt = ErrorsById.find(pair.second); + + if (it == TicketsById.end()) { + if (errIt != ErrorsById.end()) { + Y_ENSURE(ErrorsByAlias.insert({pair.first, errIt->second}).second, "failed to add: " << pair.first); } else { - UnfetchedAliases.insert(pair.first); - UnfetchedIds.insert(pair.second); + UnfetchedAliases.insert(pair.first); + UnfetchedIds.insert(pair.second); } - } else { - Y_ENSURE(TicketsByAlias.insert({pair.first, it->second}).second, - "failed to add: " << pair.first); - } - } - } - - void InitInvalidationTime() { - InvalidationTime = GetInvalidationTime(TicketsById); - } - }; - using TServiceTicketsPtr = TIntrusiveConstPtr<TServiceTickets>; - - class TAllUserContexts: public TAtomicRefCount<TAllUserContexts> { - public: - TAllUserContexts(TStringBuf publicKeys); - - TUserContextPtr Get(EBlackboxEnv env) const; - - private: - std::array<TUserContextPtr, 5> Ctx_; - }; - using TAllUserContextsPtr = TIntrusiveConstPtr<TAllUserContexts>; - - class TAsyncUpdaterBase: public TAtomicRefCount<TAsyncUpdaterBase>, protected TLastError, TNonCopyable { - public: - TAsyncUpdaterBase(); - virtual ~TAsyncUpdaterBase() = default; - - virtual TClientStatus GetStatus() const = 0; - virtual NRoles::TRolesPtr GetRoles() const; - - TServiceTicketsPtr GetCachedServiceTickets() const; - TServiceContextPtr GetCachedServiceContext() const; - TUserContextPtr GetCachedUserContext(TMaybe<EBlackboxEnv> overridenEnv = {}) const; - - TInstant GetUpdateTimeOfPublicKeys() const; - TInstant GetUpdateTimeOfServiceTickets() const; - TInstant GetUpdateTimeOfRoles() const; - TInstant GetInvalidationTimeOfPublicKeys() const; - TInstant GetInvalidationTimeOfServiceTickets() const; - - bool ArePublicKeysInvalid(TInstant now) const; - bool AreServiceTicketsInvalid(TInstant now) const; - static bool IsInvalid(TInstant invTime, TInstant now); - - protected: - void SetBbEnv(EBlackboxEnv original, TMaybe<EBlackboxEnv> overrided = {}); - - void SetServiceTickets(TServiceTicketsPtr c); - void SetServiceContext(TServiceContextPtr c); - void SetUserContext(TStringBuf publicKeys); - void SetUpdateTimeOfPublicKeys(TInstant ins); - void SetUpdateTimeOfServiceTickets(TInstant ins); - void SetUpdateTimeOfRoles(TInstant ins); - - static bool IsServiceTicketMapOk(TServiceTicketsPtr c, size_t expectedTicketCount, bool strict); - - protected: - struct TPairTicketsErrors { - TServiceTickets::TMapIdStr Tickets; - TServiceTickets::TMapIdStr Errors; - - bool operator==(const TPairTicketsErrors& o) const { - return Tickets == o.Tickets && Errors == o.Errors; - } - }; - - struct TStateDurations { - TDuration RefreshPeriod; - TDuration Expiring; - TDuration Invalid; - }; - - TStateDurations ServiceTicketsDurations_; - TStateDurations PublicKeysDurations_; - - protected: - virtual void StartTvmClientStopping() const { - } - virtual bool IsTvmClientStopped() const { - return true; - } - friend class NTvmAuth::NInternal::TClientCaningKnife; - - private: - struct TEnvs { - TMaybe<EBlackboxEnv> Original; - TMaybe<EBlackboxEnv> Overrided; - }; - static_assert(sizeof(TEnvs) <= 8, "Small struct is easy to store as atomic"); - std::atomic<TEnvs> Envs_ = {{}}; - - NUtils::TProtectedValue<TServiceTicketsPtr> ServiceTickets_; - NUtils::TProtectedValue<TServiceContextPtr> ServiceContext_; - NUtils::TProtectedValue<TAllUserContextsPtr> AllUserContexts_; - NUtils::TProtectedValue<TInstant> PublicKeysTime_; - NUtils::TProtectedValue<TInstant> ServiceTicketsTime_; - NUtils::TProtectedValue<TInstant> RolesTime_; - }; - using TAsyncUpdaterPtr = TIntrusiveConstPtr<TAsyncUpdaterBase>; -} + } else { + Y_ENSURE(TicketsByAlias.insert({pair.first, it->second}).second, + "failed to add: " << pair.first); + } + } + } + + void InitInvalidationTime() { + InvalidationTime = GetInvalidationTime(TicketsById); + } + }; + using TServiceTicketsPtr = TIntrusiveConstPtr<TServiceTickets>; + + class TAllUserContexts: public TAtomicRefCount<TAllUserContexts> { + public: + TAllUserContexts(TStringBuf publicKeys); + + TUserContextPtr Get(EBlackboxEnv env) const; + + private: + std::array<TUserContextPtr, 5> Ctx_; + }; + using TAllUserContextsPtr = TIntrusiveConstPtr<TAllUserContexts>; + + class TAsyncUpdaterBase: public TAtomicRefCount<TAsyncUpdaterBase>, protected TLastError, TNonCopyable { + public: + TAsyncUpdaterBase(); + virtual ~TAsyncUpdaterBase() = default; + + virtual TClientStatus GetStatus() const = 0; + virtual NRoles::TRolesPtr GetRoles() const; + + TServiceTicketsPtr GetCachedServiceTickets() const; + TServiceContextPtr GetCachedServiceContext() const; + TUserContextPtr GetCachedUserContext(TMaybe<EBlackboxEnv> overridenEnv = {}) const; + + TInstant GetUpdateTimeOfPublicKeys() const; + TInstant GetUpdateTimeOfServiceTickets() const; + TInstant GetUpdateTimeOfRoles() const; + TInstant GetInvalidationTimeOfPublicKeys() const; + TInstant GetInvalidationTimeOfServiceTickets() const; + + bool ArePublicKeysInvalid(TInstant now) const; + bool AreServiceTicketsInvalid(TInstant now) const; + static bool IsInvalid(TInstant invTime, TInstant now); + + protected: + void SetBbEnv(EBlackboxEnv original, TMaybe<EBlackboxEnv> overrided = {}); + + void SetServiceTickets(TServiceTicketsPtr c); + void SetServiceContext(TServiceContextPtr c); + void SetUserContext(TStringBuf publicKeys); + void SetUpdateTimeOfPublicKeys(TInstant ins); + void SetUpdateTimeOfServiceTickets(TInstant ins); + void SetUpdateTimeOfRoles(TInstant ins); + + static bool IsServiceTicketMapOk(TServiceTicketsPtr c, size_t expectedTicketCount, bool strict); + + protected: + struct TPairTicketsErrors { + TServiceTickets::TMapIdStr Tickets; + TServiceTickets::TMapIdStr Errors; + + bool operator==(const TPairTicketsErrors& o) const { + return Tickets == o.Tickets && Errors == o.Errors; + } + }; + + struct TStateDurations { + TDuration RefreshPeriod; + TDuration Expiring; + TDuration Invalid; + }; + + TStateDurations ServiceTicketsDurations_; + TStateDurations PublicKeysDurations_; + + protected: + virtual void StartTvmClientStopping() const { + } + virtual bool IsTvmClientStopped() const { + return true; + } + friend class NTvmAuth::NInternal::TClientCaningKnife; + + private: + struct TEnvs { + TMaybe<EBlackboxEnv> Original; + TMaybe<EBlackboxEnv> Overrided; + }; + static_assert(sizeof(TEnvs) <= 8, "Small struct is easy to store as atomic"); + std::atomic<TEnvs> Envs_ = {{}}; + + NUtils::TProtectedValue<TServiceTicketsPtr> ServiceTickets_; + NUtils::TProtectedValue<TServiceContextPtr> ServiceContext_; + NUtils::TProtectedValue<TAllUserContextsPtr> AllUserContexts_; + NUtils::TProtectedValue<TInstant> PublicKeysTime_; + NUtils::TProtectedValue<TInstant> ServiceTicketsTime_; + NUtils::TProtectedValue<TInstant> RolesTime_; + }; + using TAsyncUpdaterPtr = TIntrusiveConstPtr<TAsyncUpdaterBase>; +} diff --git a/library/cpp/tvmauth/client/misc/checker.h b/library/cpp/tvmauth/client/misc/checker.h index 608b7a2f39..e8ed2f5503 100644 --- a/library/cpp/tvmauth/client/misc/checker.h +++ b/library/cpp/tvmauth/client/misc/checker.h @@ -1,67 +1,67 @@ -#pragma once - -#include "async_updater.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/checked_user_ticket.h> - -namespace NTvmAuth { - class TServiceTicketChecker { - public: - TServiceTicketChecker(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - Y_ENSURE(Updater_); - GetCache(); - } - - /*! - * Checking must be enabled in TClientSettings - * Can throw exception if cache is out of date or wrong config - * @param ticket - */ - TCheckedServiceTicket Check(TStringBuf ticket) const { - return GetCache()->Check(ticket); - } - - private: - TServiceContextPtr GetCache() const { - TServiceContextPtr c = Updater_->GetCachedServiceContext(); - Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableServiceTicketChecking()"); - return c; - } - - private: - TAsyncUpdaterPtr Updater_; - }; - - class TUserTicketChecker { - public: - TUserTicketChecker(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - Y_ENSURE(Updater_); - GetCache({}); - } - - /*! - * Blackbox enviroment must be cofingured in TClientSettings - * Can throw exception if cache is out of date or wrong config - */ - TCheckedUserTicket Check(TStringBuf ticket, TMaybe<EBlackboxEnv> overridenEnv) const { - return GetCache(overridenEnv)->Check(ticket); - } - - private: - TUserContextPtr GetCache(TMaybe<EBlackboxEnv> overridenEnv) const { - TUserContextPtr c = Updater_->GetCachedUserContext(overridenEnv); - Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableUserTicketChecking()"); - return c; - } - - private: - TAsyncUpdaterPtr Updater_; - }; -} +#pragma once + +#include "async_updater.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/checked_user_ticket.h> + +namespace NTvmAuth { + class TServiceTicketChecker { + public: + TServiceTicketChecker(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + Y_ENSURE(Updater_); + GetCache(); + } + + /*! + * Checking must be enabled in TClientSettings + * Can throw exception if cache is out of date or wrong config + * @param ticket + */ + TCheckedServiceTicket Check(TStringBuf ticket) const { + return GetCache()->Check(ticket); + } + + private: + TServiceContextPtr GetCache() const { + TServiceContextPtr c = Updater_->GetCachedServiceContext(); + Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableServiceTicketChecking()"); + return c; + } + + private: + TAsyncUpdaterPtr Updater_; + }; + + class TUserTicketChecker { + public: + TUserTicketChecker(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + Y_ENSURE(Updater_); + GetCache({}); + } + + /*! + * Blackbox enviroment must be cofingured in TClientSettings + * Can throw exception if cache is out of date or wrong config + */ + TCheckedUserTicket Check(TStringBuf ticket, TMaybe<EBlackboxEnv> overridenEnv) const { + return GetCache(overridenEnv)->Check(ticket); + } + + private: + TUserContextPtr GetCache(TMaybe<EBlackboxEnv> overridenEnv) const { + TUserContextPtr c = Updater_->GetCachedUserContext(overridenEnv); + Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableUserTicketChecking()"); + return c; + } + + private: + TAsyncUpdaterPtr Updater_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/default_uid_checker.h b/library/cpp/tvmauth/client/misc/default_uid_checker.h index 10c8df82c0..1594f826bd 100644 --- a/library/cpp/tvmauth/client/misc/default_uid_checker.h +++ b/library/cpp/tvmauth/client/misc/default_uid_checker.h @@ -1,46 +1,46 @@ -#pragma once - -#include "async_updater.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/checked_user_ticket.h> -#include <library/cpp/tvmauth/src/user_impl.h> - -namespace NTvmAuth { - class TDefaultUidChecker { - public: - TDefaultUidChecker(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - Y_ENSURE(Updater_); - GetCache(); - } - - /*! - * Checking must be enabled in TClientSettings - * Can throw exception if cache is out of date or wrong config - * @param ticket - */ - TCheckedUserTicket Check(TCheckedUserTicket ticket) const { - NRoles::TConsumerRolesPtr roles = GetCache()->GetRolesForUser(ticket); - if (roles) { - return ticket; - } - - TUserTicketImplPtr impl = THolder(NInternal::TCanningKnife::GetU(ticket)); - impl->SetStatus(ETicketStatus::NoRoles); - return TCheckedUserTicket(std::move(impl)); - } - - private: - NRoles::TRolesPtr GetCache() const { - NRoles::TRolesPtr c = Updater_->GetRoles(); - Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableRolesFetching()"); - return c; - } - - private: - TAsyncUpdaterPtr Updater_; - }; -} +#pragma once + +#include "async_updater.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/checked_user_ticket.h> +#include <library/cpp/tvmauth/src/user_impl.h> + +namespace NTvmAuth { + class TDefaultUidChecker { + public: + TDefaultUidChecker(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + Y_ENSURE(Updater_); + GetCache(); + } + + /*! + * Checking must be enabled in TClientSettings + * Can throw exception if cache is out of date or wrong config + * @param ticket + */ + TCheckedUserTicket Check(TCheckedUserTicket ticket) const { + NRoles::TConsumerRolesPtr roles = GetCache()->GetRolesForUser(ticket); + if (roles) { + return ticket; + } + + TUserTicketImplPtr impl = THolder(NInternal::TCanningKnife::GetU(ticket)); + impl->SetStatus(ETicketStatus::NoRoles); + return TCheckedUserTicket(std::move(impl)); + } + + private: + NRoles::TRolesPtr GetCache() const { + NRoles::TRolesPtr c = Updater_->GetRoles(); + Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableRolesFetching()"); + return c; + } + + private: + TAsyncUpdaterPtr Updater_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/disk_cache.cpp b/library/cpp/tvmauth/client/misc/disk_cache.cpp index da266bc29e..3c01be4a83 100644 --- a/library/cpp/tvmauth/client/misc/disk_cache.cpp +++ b/library/cpp/tvmauth/client/misc/disk_cache.cpp @@ -1,165 +1,165 @@ -#include "disk_cache.h" - -#include <library/cpp/tvmauth/client/logger.h> - -#include <contrib/libs/openssl/include/openssl/evp.h> -#include <contrib/libs/openssl/include/openssl/hmac.h> -#include <contrib/libs/openssl/include/openssl/sha.h> - -#include <util/folder/path.h> -#include <util/stream/file.h> -#include <util/stream/str.h> -#include <util/system/fs.h> +#include "disk_cache.h" + +#include <library/cpp/tvmauth/client/logger.h> + +#include <contrib/libs/openssl/include/openssl/evp.h> +#include <contrib/libs/openssl/include/openssl/hmac.h> +#include <contrib/libs/openssl/include/openssl/sha.h> + +#include <util/folder/path.h> +#include <util/stream/file.h> +#include <util/stream/str.h> +#include <util/system/fs.h> #include <util/system/sysstat.h> #include <util/system/tempfile.h> - -#include <exception> - -namespace NTvmAuth { - static const size_t HASH_SIZE = 32; - static const size_t TIMESTAMP_SIZE = sizeof(time_t); - - TDiskReader::TDiskReader(const TString& filename, ILogger* logger) - : Filename_(filename) - , Logger_(logger) - { - } - - bool TDiskReader::Read() { - TStringStream s; - - try { - if (!NFs::Exists(Filename_)) { - if (Logger_) { - s << "File '" << Filename_ << "' does not exist"; - Logger_->Debug(s.Str()); - } - return false; - } - - TFile file(Filename_, OpenExisting | RdOnly | Seq); - file.Flock(LOCK_SH | LOCK_NB); - - TFileInput input(file); - return ParseData(input.ReadAll()); - } catch (const std::exception& e) { - if (Logger_) { - s << "Failed to read '" << Filename_ << "': " << e.what(); - Logger_->Error(s.Str()); - } - } - - return false; - } - - bool TDiskReader::ParseData(TStringBuf buf) { - TStringStream s; - - if (buf.size() <= HASH_SIZE + TIMESTAMP_SIZE) { - if (Logger_) { - s << "File '" << Filename_ << "' is too small"; - Logger_->Warning(s.Str()); - } - return false; - } - - TStringBuf hash = buf.SubStr(0, HASH_SIZE); - if (hash != GetHash(buf.Skip(HASH_SIZE))) { - if (Logger_) { - s << "Content of '" << Filename_ << "' was incorrectly changed"; - Logger_->Warning(s.Str()); - } - return false; - } - - Time_ = TInstant::Seconds(GetTimestamp(buf.substr(0, TIMESTAMP_SIZE))); - Data_ = buf.Skip(TIMESTAMP_SIZE); - - if (Logger_) { - s << "File '" << Filename_ << "' was successfully read"; - Logger_->Info(s.Str()); - } - return true; - } - - TString TDiskReader::GetHash(TStringBuf data) { - TString value(EVP_MAX_MD_SIZE, 0); - unsigned macLen = 0; - if (!::HMAC(EVP_sha256(), - "", - 0, - (unsigned char*)data.data(), - data.size(), - (unsigned char*)value.data(), - &macLen)) { - return {}; - } - - if (macLen != EVP_MAX_MD_SIZE) { - value.resize(macLen); - } - - return value; - } - - time_t TDiskReader::GetTimestamp(TStringBuf data) { - time_t time = 0; - for (int idx = TIMESTAMP_SIZE - 1; idx >= 0; --idx) { - time <<= 8; - time |= static_cast<unsigned char>(data.at(idx)); - } - return time; - } - - TDiskWriter::TDiskWriter(const TString& filename, ILogger* logger) - : Filename_(filename) - , Logger_(logger) - { - } - - bool TDiskWriter::Write(TStringBuf data, TInstant now) { - TStringStream s; - - try { - { + +#include <exception> + +namespace NTvmAuth { + static const size_t HASH_SIZE = 32; + static const size_t TIMESTAMP_SIZE = sizeof(time_t); + + TDiskReader::TDiskReader(const TString& filename, ILogger* logger) + : Filename_(filename) + , Logger_(logger) + { + } + + bool TDiskReader::Read() { + TStringStream s; + + try { + if (!NFs::Exists(Filename_)) { + if (Logger_) { + s << "File '" << Filename_ << "' does not exist"; + Logger_->Debug(s.Str()); + } + return false; + } + + TFile file(Filename_, OpenExisting | RdOnly | Seq); + file.Flock(LOCK_SH | LOCK_NB); + + TFileInput input(file); + return ParseData(input.ReadAll()); + } catch (const std::exception& e) { + if (Logger_) { + s << "Failed to read '" << Filename_ << "': " << e.what(); + Logger_->Error(s.Str()); + } + } + + return false; + } + + bool TDiskReader::ParseData(TStringBuf buf) { + TStringStream s; + + if (buf.size() <= HASH_SIZE + TIMESTAMP_SIZE) { + if (Logger_) { + s << "File '" << Filename_ << "' is too small"; + Logger_->Warning(s.Str()); + } + return false; + } + + TStringBuf hash = buf.SubStr(0, HASH_SIZE); + if (hash != GetHash(buf.Skip(HASH_SIZE))) { + if (Logger_) { + s << "Content of '" << Filename_ << "' was incorrectly changed"; + Logger_->Warning(s.Str()); + } + return false; + } + + Time_ = TInstant::Seconds(GetTimestamp(buf.substr(0, TIMESTAMP_SIZE))); + Data_ = buf.Skip(TIMESTAMP_SIZE); + + if (Logger_) { + s << "File '" << Filename_ << "' was successfully read"; + Logger_->Info(s.Str()); + } + return true; + } + + TString TDiskReader::GetHash(TStringBuf data) { + TString value(EVP_MAX_MD_SIZE, 0); + unsigned macLen = 0; + if (!::HMAC(EVP_sha256(), + "", + 0, + (unsigned char*)data.data(), + data.size(), + (unsigned char*)value.data(), + &macLen)) { + return {}; + } + + if (macLen != EVP_MAX_MD_SIZE) { + value.resize(macLen); + } + + return value; + } + + time_t TDiskReader::GetTimestamp(TStringBuf data) { + time_t time = 0; + for (int idx = TIMESTAMP_SIZE - 1; idx >= 0; --idx) { + time <<= 8; + time |= static_cast<unsigned char>(data.at(idx)); + } + return time; + } + + TDiskWriter::TDiskWriter(const TString& filename, ILogger* logger) + : Filename_(filename) + , Logger_(logger) + { + } + + bool TDiskWriter::Write(TStringBuf data, TInstant now) { + TStringStream s; + + try { + { if (NFs::Exists(Filename_)) { Chmod(Filename_.c_str(), S_IRUSR | S_IWUSR); // 600 } TFile file(Filename_, CreateAlways | WrOnly | Seq | AWUser | ARUser); - file.Flock(LOCK_EX | LOCK_NB); - - TFileOutput output(file); - output << PrepareData(now, data); - } - - if (Logger_) { - s << "File '" << Filename_ << "' was successfully written"; - Logger_->Info(s.Str()); - } - return true; - } catch (const std::exception& e) { - if (Logger_) { - s << "Failed to write '" << Filename_ << "': " << e.what(); - Logger_->Error(s.Str()); - } - } - - return false; - } - - TString TDiskWriter::PrepareData(TInstant time, TStringBuf data) { - TString toHash = WriteTimestamp(time.TimeT()) + data; - return TDiskReader::GetHash(toHash) + toHash; - } - - TString TDiskWriter::WriteTimestamp(time_t time) { - TString res(TIMESTAMP_SIZE, 0); - for (size_t idx = 0; idx < TIMESTAMP_SIZE; ++idx) { - res[idx] = time & 0xFF; - time >>= 8; - } - return res; - } -} + file.Flock(LOCK_EX | LOCK_NB); + + TFileOutput output(file); + output << PrepareData(now, data); + } + + if (Logger_) { + s << "File '" << Filename_ << "' was successfully written"; + Logger_->Info(s.Str()); + } + return true; + } catch (const std::exception& e) { + if (Logger_) { + s << "Failed to write '" << Filename_ << "': " << e.what(); + Logger_->Error(s.Str()); + } + } + + return false; + } + + TString TDiskWriter::PrepareData(TInstant time, TStringBuf data) { + TString toHash = WriteTimestamp(time.TimeT()) + data; + return TDiskReader::GetHash(toHash) + toHash; + } + + TString TDiskWriter::WriteTimestamp(time_t time) { + TString res(TIMESTAMP_SIZE, 0); + for (size_t idx = 0; idx < TIMESTAMP_SIZE; ++idx) { + res[idx] = time & 0xFF; + time >>= 8; + } + return res; + } +} diff --git a/library/cpp/tvmauth/client/misc/disk_cache.h b/library/cpp/tvmauth/client/misc/disk_cache.h index 91be2634aa..9e77556f86 100644 --- a/library/cpp/tvmauth/client/misc/disk_cache.h +++ b/library/cpp/tvmauth/client/misc/disk_cache.h @@ -1,50 +1,50 @@ -#pragma once - -#include <util/datetime/base.h> -#include <util/generic/string.h> - -namespace NTvmAuth { - class ILogger; - - class TDiskReader { - public: - TDiskReader(const TString& filename, ILogger* logger = nullptr); - - bool Read(); - - const TString& Data() const { - return Data_; - } - - TInstant Time() const { - return Time_; - } - - public: // for tests - bool ParseData(TStringBuf buf); - - static TString GetHash(TStringBuf data); - static time_t GetTimestamp(TStringBuf data); - - private: - TString Filename_; - ILogger* Logger_; - TInstant Time_; - TString Data_; - }; - - class TDiskWriter { - public: - TDiskWriter(const TString& filename, ILogger* logger = nullptr); - - bool Write(TStringBuf data, TInstant now = TInstant::Now()); - - public: // for tests - static TString PrepareData(TInstant time, TStringBuf data); - static TString WriteTimestamp(time_t time); - - private: - TString Filename_; - ILogger* Logger_; - }; -} +#pragma once + +#include <util/datetime/base.h> +#include <util/generic/string.h> + +namespace NTvmAuth { + class ILogger; + + class TDiskReader { + public: + TDiskReader(const TString& filename, ILogger* logger = nullptr); + + bool Read(); + + const TString& Data() const { + return Data_; + } + + TInstant Time() const { + return Time_; + } + + public: // for tests + bool ParseData(TStringBuf buf); + + static TString GetHash(TStringBuf data); + static time_t GetTimestamp(TStringBuf data); + + private: + TString Filename_; + ILogger* Logger_; + TInstant Time_; + TString Data_; + }; + + class TDiskWriter { + public: + TDiskWriter(const TString& filename, ILogger* logger = nullptr); + + bool Write(TStringBuf data, TInstant now = TInstant::Now()); + + public: // for tests + static TString PrepareData(TInstant time, TStringBuf data); + static TString WriteTimestamp(time_t time); + + private: + TString Filename_; + ILogger* Logger_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/exponential_backoff.h b/library/cpp/tvmauth/client/misc/exponential_backoff.h index af77520c6e..89a7a3c8ad 100644 --- a/library/cpp/tvmauth/client/misc/exponential_backoff.h +++ b/library/cpp/tvmauth/client/misc/exponential_backoff.h @@ -1,94 +1,94 @@ -#pragma once - -#include <util/datetime/base.h> -#include <util/random/normal.h> -#include <util/system/event.h> - +#pragma once + +#include <util/datetime/base.h> +#include <util/random/normal.h> +#include <util/system/event.h> + #include <atomic> -namespace NTvmAuth { - // https://habr.com/ru/post/227225/ - class TExponentialBackoff { - public: - struct TSettings { - TDuration Min; - TDuration Max; - double Factor = 1.001; - double Jitter = 0; - - bool operator==(const TSettings& o) const { - return Min == o.Min && - Max == o.Max && - Factor == o.Factor && - Jitter == o.Jitter; - } - }; - - TExponentialBackoff(const TSettings& settings, bool isEnabled = true) - : CurrentValue_(settings.Min) - , IsEnabled_(isEnabled) - { - UpdateSettings(settings); - } - - void UpdateSettings(const TSettings& settings) { - Y_ENSURE(settings.Factor > 1, "factor=" << settings.Factor << ". Should be > 1"); - Y_ENSURE(settings.Jitter >= 0 && settings.Jitter < 1, "jitter should be in range [0, 1)"); - - Min_ = settings.Min; - Max_ = settings.Max; - Factor_ = settings.Factor; - Jitter_ = settings.Jitter; - } - - TDuration Increase() { - CurrentValue_ = std::min(CurrentValue_ * Factor_, Max_); - - double rnd = StdNormalRandom<double>(); - const bool isNegative = rnd < 0; - rnd = std::abs(rnd); - - const TDuration diff = rnd * Jitter_ * CurrentValue_; - if (isNegative) { - CurrentValue_ -= diff; - } else { - CurrentValue_ += diff; - } - - return CurrentValue_; - } - - TDuration Decrease() { - CurrentValue_ = std::max(CurrentValue_ / Factor_, Min_); - return CurrentValue_; - } - - void Sleep(TDuration add = TDuration()) { - if (IsEnabled_.load(std::memory_order_relaxed)) { - Ev_.WaitT(CurrentValue_ + add); - } - } - - void Interrupt() { - Ev_.Signal(); - } - - TDuration GetCurrentValue() const { - return CurrentValue_; - } - - void SetEnabled(bool val) { - IsEnabled_.store(val); - } - - private: - TDuration Min_; - TDuration Max_; - double Factor_; - double Jitter_; - TDuration CurrentValue_; - std::atomic_bool IsEnabled_; - - TAutoEvent Ev_; - }; -} +namespace NTvmAuth { + // https://habr.com/ru/post/227225/ + class TExponentialBackoff { + public: + struct TSettings { + TDuration Min; + TDuration Max; + double Factor = 1.001; + double Jitter = 0; + + bool operator==(const TSettings& o) const { + return Min == o.Min && + Max == o.Max && + Factor == o.Factor && + Jitter == o.Jitter; + } + }; + + TExponentialBackoff(const TSettings& settings, bool isEnabled = true) + : CurrentValue_(settings.Min) + , IsEnabled_(isEnabled) + { + UpdateSettings(settings); + } + + void UpdateSettings(const TSettings& settings) { + Y_ENSURE(settings.Factor > 1, "factor=" << settings.Factor << ". Should be > 1"); + Y_ENSURE(settings.Jitter >= 0 && settings.Jitter < 1, "jitter should be in range [0, 1)"); + + Min_ = settings.Min; + Max_ = settings.Max; + Factor_ = settings.Factor; + Jitter_ = settings.Jitter; + } + + TDuration Increase() { + CurrentValue_ = std::min(CurrentValue_ * Factor_, Max_); + + double rnd = StdNormalRandom<double>(); + const bool isNegative = rnd < 0; + rnd = std::abs(rnd); + + const TDuration diff = rnd * Jitter_ * CurrentValue_; + if (isNegative) { + CurrentValue_ -= diff; + } else { + CurrentValue_ += diff; + } + + return CurrentValue_; + } + + TDuration Decrease() { + CurrentValue_ = std::max(CurrentValue_ / Factor_, Min_); + return CurrentValue_; + } + + void Sleep(TDuration add = TDuration()) { + if (IsEnabled_.load(std::memory_order_relaxed)) { + Ev_.WaitT(CurrentValue_ + add); + } + } + + void Interrupt() { + Ev_.Signal(); + } + + TDuration GetCurrentValue() const { + return CurrentValue_; + } + + void SetEnabled(bool val) { + IsEnabled_.store(val); + } + + private: + TDuration Min_; + TDuration Max_; + double Factor_; + double Jitter_; + TDuration CurrentValue_; + std::atomic_bool IsEnabled_; + + TAutoEvent Ev_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/fetch_result.h b/library/cpp/tvmauth/client/misc/fetch_result.h index c454499477..4b0774e92f 100644 --- a/library/cpp/tvmauth/client/misc/fetch_result.h +++ b/library/cpp/tvmauth/client/misc/fetch_result.h @@ -1,13 +1,13 @@ -#pragma once - -#include <library/cpp/http/simple/http_client.h> - -namespace NTvmAuth::NUtils { - struct TFetchResult { - TKeepAliveHttpClient::THttpCode Code; - THttpHeaders Headers; - TStringBuf Path; - TString Response; - TString RetrySettings; - }; -} +#pragma once + +#include <library/cpp/http/simple/http_client.h> + +namespace NTvmAuth::NUtils { + struct TFetchResult { + TKeepAliveHttpClient::THttpCode Code; + THttpHeaders Headers; + TStringBuf Path; + TString Response; + TString RetrySettings; + }; +} diff --git a/library/cpp/tvmauth/client/misc/getter.h b/library/cpp/tvmauth/client/misc/getter.h index a2bde9de7c..b0327d69e9 100644 --- a/library/cpp/tvmauth/client/misc/getter.h +++ b/library/cpp/tvmauth/client/misc/getter.h @@ -1,66 +1,66 @@ -#pragma once - -#include "checker.h" - -namespace NTvmAuth { - class TServiceTicketGetter { - public: - TServiceTicketGetter(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - Y_ENSURE(Updater_); - GetCache(); - } - - /*! - * Fetching must enabled in TClientSettings - * Can throw exception if cache is invalid or wrong config - * @param dst - */ - TString GetTicket(const TClientSettings::TAlias& dst) const { - TServiceTicketsPtr c = GetCache(); - return GetTicketImpl(dst, c->TicketsByAlias, c->ErrorsByAlias, c->UnfetchedAliases); - } - - TString GetTicket(const TTvmId dst) const { - TServiceTicketsPtr c = GetCache(); - return GetTicketImpl(dst, c->TicketsById, c->ErrorsById, c->UnfetchedIds); - } - - private: +#pragma once + +#include "checker.h" + +namespace NTvmAuth { + class TServiceTicketGetter { + public: + TServiceTicketGetter(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + Y_ENSURE(Updater_); + GetCache(); + } + + /*! + * Fetching must enabled in TClientSettings + * Can throw exception if cache is invalid or wrong config + * @param dst + */ + TString GetTicket(const TClientSettings::TAlias& dst) const { + TServiceTicketsPtr c = GetCache(); + return GetTicketImpl(dst, c->TicketsByAlias, c->ErrorsByAlias, c->UnfetchedAliases); + } + + TString GetTicket(const TTvmId dst) const { + TServiceTicketsPtr c = GetCache(); + return GetTicketImpl(dst, c->TicketsById, c->ErrorsById, c->UnfetchedIds); + } + + private: template <class Key, class Cont, class UnfetchedCont> TString GetTicketImpl(const Key& dst, const Cont& tickets, const Cont& errors, const UnfetchedCont& unfetched) const { - auto it = tickets.find(dst); - if (it != tickets.end()) { - return it->second; - } - - it = errors.find(dst); - if (it != errors.end()) { - ythrow TMissingServiceTicket() - << "Failed to get ticket for '" << dst << "': " - << it->second; - } - + auto it = tickets.find(dst); + if (it != tickets.end()) { + return it->second; + } + + it = errors.find(dst); + if (it != errors.end()) { + ythrow TMissingServiceTicket() + << "Failed to get ticket for '" << dst << "': " + << it->second; + } + if (unfetched.contains(dst)) { ythrow TMissingServiceTicket() << "Failed to get ticket for '" << dst << "': this dst was not fetched yet."; } - ythrow TBrokenTvmClientSettings() - << "Destination '" << dst << "' was not specified in settings. " - << "Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"; - } - - private: - TServiceTicketsPtr GetCache() const { - TServiceTicketsPtr c = Updater_->GetCachedServiceTickets(); - Y_ENSURE_EX(c, TBrokenTvmClientSettings() - << "Need to use TClientSettings::EnableServiceTicketsFetchOptions()"); - return c; - } - - private: - TAsyncUpdaterPtr Updater_; - }; -} + ythrow TBrokenTvmClientSettings() + << "Destination '" << dst << "' was not specified in settings. " + << "Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"; + } + + private: + TServiceTicketsPtr GetCache() const { + TServiceTicketsPtr c = Updater_->GetCachedServiceTickets(); + Y_ENSURE_EX(c, TBrokenTvmClientSettings() + << "Need to use TClientSettings::EnableServiceTicketsFetchOptions()"); + return c; + } + + private: + TAsyncUpdaterPtr Updater_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/last_error.cpp b/library/cpp/tvmauth/client/misc/last_error.cpp index b71f4d5bbb..a6279bb1ef 100644 --- a/library/cpp/tvmauth/client/misc/last_error.cpp +++ b/library/cpp/tvmauth/client/misc/last_error.cpp @@ -1,115 +1,115 @@ -#include "last_error.h" - -#include <util/string/builder.h> - -namespace NTvmAuth { - TLastError::TLastError() - : LastErrors_(MakeIntrusiveConst<TLastErrors>()) - { - } - - TString TLastError::GetLastError(bool isOk, EType* type) const { - if (isOk) { - return OK_; - } - - const TLastErrorsPtr ptr = LastErrors_.Get(); - - for (const TLastErr& err : ptr->Errors) { - if (err && err->first == EType::NonRetriable) { - if (type) { - *type = EType::NonRetriable; - } - return err->second; - } - } - - for (const TLastErr& err : ptr->Errors) { - if (err) { - if (type) { - *type = EType::Retriable; - } - return err->second; - } - } - - if (type) { - *type = EType::NonRetriable; - } - return "Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru"; - } - - TString TLastError::ProcessHttpError(TLastError::EScope scope, - TStringBuf path, - int code, - const TString& msg) const { - TString err = TStringBuilder() << "Path:" << path << ".Code=" << code << ": " << msg; - - ProcessError(code >= 400 && code < 500 ? EType::NonRetriable - : EType::Retriable, - scope, - err); - - return err; - } - - void TLastError::ProcessError(TLastError::EType type, TLastError::EScope scope, const TStringBuf msg) const { - Update(scope, [&](TLastErr& lastError) { - if (lastError && lastError->first == EType::NonRetriable && type == EType::Retriable) { - return false; - } - - TString err = TStringBuilder() << scope << ": " << msg; - err.erase(std::remove(err.begin(), err.vend(), '\r'), err.vend()); - std::replace(err.begin(), err.vend(), '\n', ' '); - - lastError = {type, std::move(err)}; - return true; - }); - } - - void TLastError::ClearError(TLastError::EScope scope) { - Update(scope, [&](TLastErr& lastError) { - if (!lastError) { - return false; - } - - lastError.Clear(); - return true; - }); - } - - void TLastError::ClearErrors() { - for (size_t idx = 0; idx < (size_t)EScope::COUNT; ++idx) { - ClearError((EScope)idx); - } - } - - void TLastError::ThrowLastError() { - EType type; - TString err = GetLastError(false, &type); - - switch (type) { - case EType::NonRetriable: - ythrow TNonRetriableException() - << "Failed to start TvmClient. Do not retry: " - << err; - case EType::Retriable: - ythrow TRetriableException() - << "Failed to start TvmClient. You can retry: " - << err; - } - } - - template <typename Func> - void TLastError::Update(TLastError::EScope scope, Func func) const { - Y_VERIFY(scope != EScope::COUNT); - - TLastErrors errs = *LastErrors_.Get(); - TLastErr& lastError = errs.Errors[(size_t)scope]; - - if (func(lastError)) { - LastErrors_.Set(MakeIntrusiveConst<TLastErrors>(std::move(errs))); - } - } -} +#include "last_error.h" + +#include <util/string/builder.h> + +namespace NTvmAuth { + TLastError::TLastError() + : LastErrors_(MakeIntrusiveConst<TLastErrors>()) + { + } + + TString TLastError::GetLastError(bool isOk, EType* type) const { + if (isOk) { + return OK_; + } + + const TLastErrorsPtr ptr = LastErrors_.Get(); + + for (const TLastErr& err : ptr->Errors) { + if (err && err->first == EType::NonRetriable) { + if (type) { + *type = EType::NonRetriable; + } + return err->second; + } + } + + for (const TLastErr& err : ptr->Errors) { + if (err) { + if (type) { + *type = EType::Retriable; + } + return err->second; + } + } + + if (type) { + *type = EType::NonRetriable; + } + return "Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru"; + } + + TString TLastError::ProcessHttpError(TLastError::EScope scope, + TStringBuf path, + int code, + const TString& msg) const { + TString err = TStringBuilder() << "Path:" << path << ".Code=" << code << ": " << msg; + + ProcessError(code >= 400 && code < 500 ? EType::NonRetriable + : EType::Retriable, + scope, + err); + + return err; + } + + void TLastError::ProcessError(TLastError::EType type, TLastError::EScope scope, const TStringBuf msg) const { + Update(scope, [&](TLastErr& lastError) { + if (lastError && lastError->first == EType::NonRetriable && type == EType::Retriable) { + return false; + } + + TString err = TStringBuilder() << scope << ": " << msg; + err.erase(std::remove(err.begin(), err.vend(), '\r'), err.vend()); + std::replace(err.begin(), err.vend(), '\n', ' '); + + lastError = {type, std::move(err)}; + return true; + }); + } + + void TLastError::ClearError(TLastError::EScope scope) { + Update(scope, [&](TLastErr& lastError) { + if (!lastError) { + return false; + } + + lastError.Clear(); + return true; + }); + } + + void TLastError::ClearErrors() { + for (size_t idx = 0; idx < (size_t)EScope::COUNT; ++idx) { + ClearError((EScope)idx); + } + } + + void TLastError::ThrowLastError() { + EType type; + TString err = GetLastError(false, &type); + + switch (type) { + case EType::NonRetriable: + ythrow TNonRetriableException() + << "Failed to start TvmClient. Do not retry: " + << err; + case EType::Retriable: + ythrow TRetriableException() + << "Failed to start TvmClient. You can retry: " + << err; + } + } + + template <typename Func> + void TLastError::Update(TLastError::EScope scope, Func func) const { + Y_VERIFY(scope != EScope::COUNT); + + TLastErrors errs = *LastErrors_.Get(); + TLastErr& lastError = errs.Errors[(size_t)scope]; + + if (func(lastError)) { + LastErrors_.Set(MakeIntrusiveConst<TLastErrors>(std::move(errs))); + } + } +} diff --git a/library/cpp/tvmauth/client/misc/last_error.h b/library/cpp/tvmauth/client/misc/last_error.h index 7d650a9b12..b0ad33611f 100644 --- a/library/cpp/tvmauth/client/misc/last_error.h +++ b/library/cpp/tvmauth/client/misc/last_error.h @@ -1,51 +1,51 @@ -#pragma once - -#include "utils.h" - -#include <array> - -namespace NTvmAuth { - class TLastError { - public: - enum class EType { - NonRetriable, - Retriable, - }; - - enum class EScope { - ServiceTickets, - PublicKeys, - Roles, - TvmtoolConfig, - - COUNT, - }; - - using TLastErr = TMaybe<std::pair<EType, TString>>; - - struct TLastErrors: public TAtomicRefCount<TLastErrors> { - std::array<TLastErr, (int)EScope::COUNT> Errors; - }; - using TLastErrorsPtr = TIntrusiveConstPtr<TLastErrors>; - - public: - TLastError(); - - TString GetLastError(bool isOk, EType* type = nullptr) const; - - TString ProcessHttpError(EScope scope, TStringBuf path, int code, const TString& msg) const; - void ProcessError(EType type, EScope scope, const TStringBuf msg) const; - void ClearError(EScope scope); - void ClearErrors(); - void ThrowLastError(); - - private: - template <typename Func> - void Update(EScope scope, Func func) const; - - private: - const TString OK_ = "OK"; - - mutable NUtils::TProtectedValue<TLastErrorsPtr> LastErrors_; - }; -} +#pragma once + +#include "utils.h" + +#include <array> + +namespace NTvmAuth { + class TLastError { + public: + enum class EType { + NonRetriable, + Retriable, + }; + + enum class EScope { + ServiceTickets, + PublicKeys, + Roles, + TvmtoolConfig, + + COUNT, + }; + + using TLastErr = TMaybe<std::pair<EType, TString>>; + + struct TLastErrors: public TAtomicRefCount<TLastErrors> { + std::array<TLastErr, (int)EScope::COUNT> Errors; + }; + using TLastErrorsPtr = TIntrusiveConstPtr<TLastErrors>; + + public: + TLastError(); + + TString GetLastError(bool isOk, EType* type = nullptr) const; + + TString ProcessHttpError(EScope scope, TStringBuf path, int code, const TString& msg) const; + void ProcessError(EType type, EScope scope, const TStringBuf msg) const; + void ClearError(EScope scope); + void ClearErrors(); + void ThrowLastError(); + + private: + template <typename Func> + void Update(EScope scope, Func func) const; + + private: + const TString OK_ = "OK"; + + mutable NUtils::TProtectedValue<TLastErrorsPtr> LastErrors_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/proc_info.cpp b/library/cpp/tvmauth/client/misc/proc_info.cpp index 0d4535b47f..e2e5ec15b9 100644 --- a/library/cpp/tvmauth/client/misc/proc_info.cpp +++ b/library/cpp/tvmauth/client/misc/proc_info.cpp @@ -1,53 +1,53 @@ -#include "proc_info.h" - -#include <library/cpp/tvmauth/version.h> - -#include <library/cpp/string_utils/quote/quote.h> - -#include <util/stream/file.h> -#include <util/string/cast.h> -#include <util/system/getpid.h> - -namespace NTvmAuth::NUtils { - void TProcInfo::AddToRequest(IOutputStream& out) const { - out << "_pid=" << Pid; - if (ProcessName) { - out << "&_procces_name=" << *ProcessName; - } - out << "&lib_version=client_" << VersionPrefix << LibVersion(); - } - - TProcInfo TProcInfo::Create(const TString& versionPrefix) { - TProcInfo res; - res.Pid = IntToString<10>(GetPID()); - res.ProcessName = GetProcessName(); - res.VersionPrefix = versionPrefix; - return res; - } - - std::optional<TString> TProcInfo::GetProcessName() { - try { - // works only for linux - TFileInput proc("/proc/self/status"); - - TString line; - while (proc.ReadLine(line)) { - TStringBuf buf(line); - if (!buf.SkipPrefix("Name:")) { - continue; - } - - while (buf && isspace(buf.front())) { - buf.Skip(1); - } - - TString res(buf); - CGIEscape(res); - return res; - } - } catch (...) { - } - - return {}; - } -} +#include "proc_info.h" + +#include <library/cpp/tvmauth/version.h> + +#include <library/cpp/string_utils/quote/quote.h> + +#include <util/stream/file.h> +#include <util/string/cast.h> +#include <util/system/getpid.h> + +namespace NTvmAuth::NUtils { + void TProcInfo::AddToRequest(IOutputStream& out) const { + out << "_pid=" << Pid; + if (ProcessName) { + out << "&_procces_name=" << *ProcessName; + } + out << "&lib_version=client_" << VersionPrefix << LibVersion(); + } + + TProcInfo TProcInfo::Create(const TString& versionPrefix) { + TProcInfo res; + res.Pid = IntToString<10>(GetPID()); + res.ProcessName = GetProcessName(); + res.VersionPrefix = versionPrefix; + return res; + } + + std::optional<TString> TProcInfo::GetProcessName() { + try { + // works only for linux + TFileInput proc("/proc/self/status"); + + TString line; + while (proc.ReadLine(line)) { + TStringBuf buf(line); + if (!buf.SkipPrefix("Name:")) { + continue; + } + + while (buf && isspace(buf.front())) { + buf.Skip(1); + } + + TString res(buf); + CGIEscape(res); + return res; + } + } catch (...) { + } + + return {}; + } +} diff --git a/library/cpp/tvmauth/client/misc/proc_info.h b/library/cpp/tvmauth/client/misc/proc_info.h index 8595f23a76..b1526e5c47 100644 --- a/library/cpp/tvmauth/client/misc/proc_info.h +++ b/library/cpp/tvmauth/client/misc/proc_info.h @@ -1,18 +1,18 @@ -#pragma once - -#include <util/generic/string.h> - -#include <optional> - -namespace NTvmAuth::NUtils { - struct TProcInfo { - TString Pid; - std::optional<TString> ProcessName; - TString VersionPrefix; - - void AddToRequest(IOutputStream& out) const; - - static TProcInfo Create(const TString& versionPrefix); - static std::optional<TString> GetProcessName(); - }; -} +#pragma once + +#include <util/generic/string.h> + +#include <optional> + +namespace NTvmAuth::NUtils { + struct TProcInfo { + TString Pid; + std::optional<TString> ProcessName; + TString VersionPrefix; + + void AddToRequest(IOutputStream& out) const; + + static TProcInfo Create(const TString& versionPrefix); + static std::optional<TString> GetProcessName(); + }; +} diff --git a/library/cpp/tvmauth/client/misc/retry_settings/v1/settings.proto b/library/cpp/tvmauth/client/misc/retry_settings/v1/settings.proto index 840a4d0c7b..72817847a6 100644 --- a/library/cpp/tvmauth/client/misc/retry_settings/v1/settings.proto +++ b/library/cpp/tvmauth/client/misc/retry_settings/v1/settings.proto @@ -1,21 +1,21 @@ -syntax = "proto2"; - -package retry_settings.v1; - -option cc_enable_arenas = true; -option go_package = "a.yandex-team.ru/library/cpp/tvmauth/client/misc/retry_settings/v1"; - -message Settings { - optional uint32 exponential_backoff_min_sec = 1; - optional uint32 exponential_backoff_max_sec = 2; - optional double exponential_backoff_factor = 3; - optional double exponential_backoff_jitter = 4; - optional uint32 max_random_sleep_default = 5; - optional uint32 max_random_sleep_when_ok = 12; - optional uint32 retries_on_start = 6; - optional uint32 worker_awaking_period_sec = 7; - optional uint32 dsts_limit = 8; - optional uint32 retries_in_background = 9; - optional uint32 roles_update_period_sec = 10; - optional uint32 roles_warn_period_sec = 11; -} +syntax = "proto2"; + +package retry_settings.v1; + +option cc_enable_arenas = true; +option go_package = "a.yandex-team.ru/library/cpp/tvmauth/client/misc/retry_settings/v1"; + +message Settings { + optional uint32 exponential_backoff_min_sec = 1; + optional uint32 exponential_backoff_max_sec = 2; + optional double exponential_backoff_factor = 3; + optional double exponential_backoff_jitter = 4; + optional uint32 max_random_sleep_default = 5; + optional uint32 max_random_sleep_when_ok = 12; + optional uint32 retries_on_start = 6; + optional uint32 worker_awaking_period_sec = 7; + optional uint32 dsts_limit = 8; + optional uint32 retries_in_background = 9; + optional uint32 roles_update_period_sec = 10; + optional uint32 roles_warn_period_sec = 11; +} diff --git a/library/cpp/tvmauth/client/misc/retry_settings/v1/ya.make b/library/cpp/tvmauth/client/misc/retry_settings/v1/ya.make index 0e1453fd98..226bf7cea7 100644 --- a/library/cpp/tvmauth/client/misc/retry_settings/v1/ya.make +++ b/library/cpp/tvmauth/client/misc/retry_settings/v1/ya.make @@ -1,15 +1,15 @@ -PROTO_LIBRARY() - -OWNER(g:passport_infra) - -EXCLUDE_TAGS( - JAVA_PROTO - PY_PROTO - PY3_PROTO -) - -SRCS( - settings.proto -) - -END() +PROTO_LIBRARY() + +OWNER(g:passport_infra) + +EXCLUDE_TAGS( + JAVA_PROTO + PY_PROTO + PY3_PROTO +) + +SRCS( + settings.proto +) + +END() diff --git a/library/cpp/tvmauth/client/misc/roles/decoder.cpp b/library/cpp/tvmauth/client/misc/roles/decoder.cpp index 98905e97e3..6337fb91c2 100644 --- a/library/cpp/tvmauth/client/misc/roles/decoder.cpp +++ b/library/cpp/tvmauth/client/misc/roles/decoder.cpp @@ -1,93 +1,93 @@ -#include "decoder.h" - -#include <library/cpp/tvmauth/client/misc/utils.h> - -#include <library/cpp/openssl/crypto/sha.h> -#include <library/cpp/streams/brotli/brotli.h> -#include <library/cpp/streams/zstd/zstd.h> - -#include <util/generic/yexception.h> -#include <util/stream/zlib.h> -#include <util/string/ascii.h> - -namespace NTvmAuth::NRoles { - TString TDecoder::Decode(const TStringBuf codec, TString&& blob) { - if (codec.empty()) { - return std::move(blob); - } - - const TCodecInfo info = ParseCodec(codec); - TString decoded = DecodeImpl(info.Type, blob); - - VerifySize(decoded, info.Size); - VerifyChecksum(decoded, info.Sha256); - - return decoded; - } - - TDecoder::TCodecInfo TDecoder::ParseCodec(TStringBuf codec) { - const char delim = ':'; - - const TStringBuf version = codec.NextTok(delim); - Y_ENSURE(version == "1", - "unknown codec format version; known: 1; got: " << version); - - TCodecInfo res; - res.Type = codec.NextTok(delim); - Y_ENSURE(res.Type, "codec type is empty"); - - const TStringBuf size = codec.NextTok(delim); - Y_ENSURE(TryIntFromString<10>(size, res.Size), - "decoded blob size is not number"); - - res.Sha256 = codec; - const size_t expectedSha256Size = 2 * NOpenSsl::NSha256::DIGEST_LENGTH; - Y_ENSURE(res.Sha256.size() == expectedSha256Size, - "sha256 of decoded blob has invalid length: expected " - << expectedSha256Size << ", got " << res.Sha256.size()); - - return res; - } - - TString TDecoder::DecodeImpl(TStringBuf codec, const TString& blob) { - if (AsciiEqualsIgnoreCase(codec, "brotli")) { - return DecodeBrolti(blob); - } else if (AsciiEqualsIgnoreCase(codec, "gzip")) { - return DecodeGzip(blob); - } else if (AsciiEqualsIgnoreCase(codec, "zstd")) { - return DecodeZstd(blob); - } - - ythrow yexception() << "unknown codec: '" << codec << "'"; - } - - TString TDecoder::DecodeBrolti(const TString& blob) { - TStringInput in(blob); - return TBrotliDecompress(&in).ReadAll(); - } - - TString TDecoder::DecodeGzip(const TString& blob) { - TStringInput in(blob); - return TZLibDecompress(&in).ReadAll(); - } - - TString TDecoder::DecodeZstd(const TString& blob) { - TStringInput in(blob); - return TZstdDecompress(&in).ReadAll(); - } - - void TDecoder::VerifySize(const TStringBuf decoded, size_t expected) { - Y_ENSURE(expected == decoded.size(), - "Decoded blob has bad size: expected " << expected << ", actual " << decoded.size()); - } - - void TDecoder::VerifyChecksum(const TStringBuf decoded, const TStringBuf expected) { - using namespace NOpenSsl::NSha256; - - const TDigest dig = Calc(decoded); - const TString actual = NUtils::ToHex(TStringBuf((char*)dig.data(), dig.size())); - - Y_ENSURE(AsciiEqualsIgnoreCase(actual, expected), - "Decoded blob has bad sha256: expected=" << expected << ", actual=" << actual); - } -} +#include "decoder.h" + +#include <library/cpp/tvmauth/client/misc/utils.h> + +#include <library/cpp/openssl/crypto/sha.h> +#include <library/cpp/streams/brotli/brotli.h> +#include <library/cpp/streams/zstd/zstd.h> + +#include <util/generic/yexception.h> +#include <util/stream/zlib.h> +#include <util/string/ascii.h> + +namespace NTvmAuth::NRoles { + TString TDecoder::Decode(const TStringBuf codec, TString&& blob) { + if (codec.empty()) { + return std::move(blob); + } + + const TCodecInfo info = ParseCodec(codec); + TString decoded = DecodeImpl(info.Type, blob); + + VerifySize(decoded, info.Size); + VerifyChecksum(decoded, info.Sha256); + + return decoded; + } + + TDecoder::TCodecInfo TDecoder::ParseCodec(TStringBuf codec) { + const char delim = ':'; + + const TStringBuf version = codec.NextTok(delim); + Y_ENSURE(version == "1", + "unknown codec format version; known: 1; got: " << version); + + TCodecInfo res; + res.Type = codec.NextTok(delim); + Y_ENSURE(res.Type, "codec type is empty"); + + const TStringBuf size = codec.NextTok(delim); + Y_ENSURE(TryIntFromString<10>(size, res.Size), + "decoded blob size is not number"); + + res.Sha256 = codec; + const size_t expectedSha256Size = 2 * NOpenSsl::NSha256::DIGEST_LENGTH; + Y_ENSURE(res.Sha256.size() == expectedSha256Size, + "sha256 of decoded blob has invalid length: expected " + << expectedSha256Size << ", got " << res.Sha256.size()); + + return res; + } + + TString TDecoder::DecodeImpl(TStringBuf codec, const TString& blob) { + if (AsciiEqualsIgnoreCase(codec, "brotli")) { + return DecodeBrolti(blob); + } else if (AsciiEqualsIgnoreCase(codec, "gzip")) { + return DecodeGzip(blob); + } else if (AsciiEqualsIgnoreCase(codec, "zstd")) { + return DecodeZstd(blob); + } + + ythrow yexception() << "unknown codec: '" << codec << "'"; + } + + TString TDecoder::DecodeBrolti(const TString& blob) { + TStringInput in(blob); + return TBrotliDecompress(&in).ReadAll(); + } + + TString TDecoder::DecodeGzip(const TString& blob) { + TStringInput in(blob); + return TZLibDecompress(&in).ReadAll(); + } + + TString TDecoder::DecodeZstd(const TString& blob) { + TStringInput in(blob); + return TZstdDecompress(&in).ReadAll(); + } + + void TDecoder::VerifySize(const TStringBuf decoded, size_t expected) { + Y_ENSURE(expected == decoded.size(), + "Decoded blob has bad size: expected " << expected << ", actual " << decoded.size()); + } + + void TDecoder::VerifyChecksum(const TStringBuf decoded, const TStringBuf expected) { + using namespace NOpenSsl::NSha256; + + const TDigest dig = Calc(decoded); + const TString actual = NUtils::ToHex(TStringBuf((char*)dig.data(), dig.size())); + + Y_ENSURE(AsciiEqualsIgnoreCase(actual, expected), + "Decoded blob has bad sha256: expected=" << expected << ", actual=" << actual); + } +} diff --git a/library/cpp/tvmauth/client/misc/roles/decoder.h b/library/cpp/tvmauth/client/misc/roles/decoder.h index ef77cab56d..de5cdb37e0 100644 --- a/library/cpp/tvmauth/client/misc/roles/decoder.h +++ b/library/cpp/tvmauth/client/misc/roles/decoder.h @@ -1,32 +1,32 @@ -#pragma once - -#include <util/generic/string.h> - -namespace NTvmAuth::NRoles { - class TDecoder { - public: - static TString Decode(const TStringBuf codec, TString&& blob); - - public: - struct TCodecInfo { - TStringBuf Type; - size_t Size = 0; - TStringBuf Sha256; - - bool operator==(const TCodecInfo& o) const { - return Type == o.Type && - Size == o.Size && - Sha256 == o.Sha256; - } - }; - - static TCodecInfo ParseCodec(TStringBuf codec); - static TString DecodeImpl(TStringBuf codec, const TString& blob); - static TString DecodeBrolti(const TString& blob); - static TString DecodeGzip(const TString& blob); - static TString DecodeZstd(const TString& blob); - - static void VerifySize(const TStringBuf decoded, size_t expected); - static void VerifyChecksum(const TStringBuf decoded, const TStringBuf expected); - }; -} +#pragma once + +#include <util/generic/string.h> + +namespace NTvmAuth::NRoles { + class TDecoder { + public: + static TString Decode(const TStringBuf codec, TString&& blob); + + public: + struct TCodecInfo { + TStringBuf Type; + size_t Size = 0; + TStringBuf Sha256; + + bool operator==(const TCodecInfo& o) const { + return Type == o.Type && + Size == o.Size && + Sha256 == o.Sha256; + } + }; + + static TCodecInfo ParseCodec(TStringBuf codec); + static TString DecodeImpl(TStringBuf codec, const TString& blob); + static TString DecodeBrolti(const TString& blob); + static TString DecodeGzip(const TString& blob); + static TString DecodeZstd(const TString& blob); + + static void VerifySize(const TStringBuf decoded, size_t expected); + static void VerifyChecksum(const TStringBuf decoded, const TStringBuf expected); + }; +} diff --git a/library/cpp/tvmauth/client/misc/roles/entities_index.cpp b/library/cpp/tvmauth/client/misc/roles/entities_index.cpp index 2a9e4ab7b9..c9b72c3a17 100644 --- a/library/cpp/tvmauth/client/misc/roles/entities_index.cpp +++ b/library/cpp/tvmauth/client/misc/roles/entities_index.cpp @@ -1,114 +1,114 @@ -#include "entities_index.h" - -#include <util/stream/str.h> - -#include <set> - -namespace NTvmAuth::NRoles { - TEntitiesIndex::TStage::TStage(const std::set<TString>& k) - : Keys_(k.begin(), k.end()) - { - } - - // TODO TStringBuf - bool TEntitiesIndex::TStage::GetNextKeySet(std::vector<TString>& out) { - out.clear(); - out.reserve(Keys_.size()); - - ++Id_; - for (size_t idx = 0; idx < Keys_.size(); ++idx) { - bool need = (Id_ >> idx) & 0x01; - - if (need) { - out.push_back(Keys_[idx]); - } - } - - return !out.empty(); - } - - TEntitiesIndex::TEntitiesIndex(const std::vector<TEntityPtr>& entities) { - const std::set<TString> uniqueKeys = GetUniqueSortedKeys(entities); - Idx_.Entities = entities; - Idx_.SubTree.reserve(uniqueKeys.size() * entities.size()); - - TStage stage(uniqueKeys); - std::vector<TString> keyset; - while (stage.GetNextKeySet(keyset)) { - for (const TEntityPtr& e : entities) { - TSubTree* currentBranch = &Idx_; - - for (const TString& key : keyset) { - auto it = e->find(key); - if (it == e->end()) { - continue; - } - - auto [i, ok] = currentBranch->SubTree.emplace( - TKeyValue{it->first, it->second}, - TSubTree()); - - currentBranch = &i->second; - currentBranch->Entities.push_back(e); - } - } - } - - MakeUnique(Idx_); - } - - std::set<TString> TEntitiesIndex::GetUniqueSortedKeys(const std::vector<TEntityPtr>& entities) { - std::set<TString> res; - - for (const TEntityPtr& e : entities) { - for (const auto& [key, value] : *e) { - res.insert(key); - } - } - - return res; - } - - void TEntitiesIndex::MakeUnique(TSubTree& branch) { - auto& vec = branch.Entities; - std::sort(vec.begin(), vec.end()); - vec.erase(std::unique(vec.begin(), vec.end()), vec.end()); - - for (auto& [_, restPart] : branch.SubTree) { - MakeUnique(restPart); - } - } - - static void Print(const TEntitiesIndex::TSubTree& part, IOutputStream& out, size_t offset = 0) { - std::vector<std::pair<TKeyValue, const TEntitiesIndex::TSubTree*>> vec; - vec.reserve(part.SubTree.size()); - - for (const auto& [key, value] : part.SubTree) { - vec.push_back({key, &value}); - } - - std::sort(vec.begin(), vec.end(), [](const auto& l, const auto& r) { - if (l.first.Key < r.first.Key) { - return true; - } - if (l.first.Value < r.first.Value) { - return true; - } - return false; - }); - - for (const auto& [key, value] : vec) { - out << TString(offset, ' ') << "\"" << key.Key << "/" << key.Value << "\"" << Endl; - Print(*value, out, offset + 4); - } - } - - TString TEntitiesIndex::PrintDebugString() const { - TStringStream res; - res << Endl; - - Print(Idx_, res); - - return res.Str(); - } -} +#include "entities_index.h" + +#include <util/stream/str.h> + +#include <set> + +namespace NTvmAuth::NRoles { + TEntitiesIndex::TStage::TStage(const std::set<TString>& k) + : Keys_(k.begin(), k.end()) + { + } + + // TODO TStringBuf + bool TEntitiesIndex::TStage::GetNextKeySet(std::vector<TString>& out) { + out.clear(); + out.reserve(Keys_.size()); + + ++Id_; + for (size_t idx = 0; idx < Keys_.size(); ++idx) { + bool need = (Id_ >> idx) & 0x01; + + if (need) { + out.push_back(Keys_[idx]); + } + } + + return !out.empty(); + } + + TEntitiesIndex::TEntitiesIndex(const std::vector<TEntityPtr>& entities) { + const std::set<TString> uniqueKeys = GetUniqueSortedKeys(entities); + Idx_.Entities = entities; + Idx_.SubTree.reserve(uniqueKeys.size() * entities.size()); + + TStage stage(uniqueKeys); + std::vector<TString> keyset; + while (stage.GetNextKeySet(keyset)) { + for (const TEntityPtr& e : entities) { + TSubTree* currentBranch = &Idx_; + + for (const TString& key : keyset) { + auto it = e->find(key); + if (it == e->end()) { + continue; + } + + auto [i, ok] = currentBranch->SubTree.emplace( + TKeyValue{it->first, it->second}, + TSubTree()); + + currentBranch = &i->second; + currentBranch->Entities.push_back(e); + } + } + } + + MakeUnique(Idx_); + } + + std::set<TString> TEntitiesIndex::GetUniqueSortedKeys(const std::vector<TEntityPtr>& entities) { + std::set<TString> res; + + for (const TEntityPtr& e : entities) { + for (const auto& [key, value] : *e) { + res.insert(key); + } + } + + return res; + } + + void TEntitiesIndex::MakeUnique(TSubTree& branch) { + auto& vec = branch.Entities; + std::sort(vec.begin(), vec.end()); + vec.erase(std::unique(vec.begin(), vec.end()), vec.end()); + + for (auto& [_, restPart] : branch.SubTree) { + MakeUnique(restPart); + } + } + + static void Print(const TEntitiesIndex::TSubTree& part, IOutputStream& out, size_t offset = 0) { + std::vector<std::pair<TKeyValue, const TEntitiesIndex::TSubTree*>> vec; + vec.reserve(part.SubTree.size()); + + for (const auto& [key, value] : part.SubTree) { + vec.push_back({key, &value}); + } + + std::sort(vec.begin(), vec.end(), [](const auto& l, const auto& r) { + if (l.first.Key < r.first.Key) { + return true; + } + if (l.first.Value < r.first.Value) { + return true; + } + return false; + }); + + for (const auto& [key, value] : vec) { + out << TString(offset, ' ') << "\"" << key.Key << "/" << key.Value << "\"" << Endl; + Print(*value, out, offset + 4); + } + } + + TString TEntitiesIndex::PrintDebugString() const { + TStringStream res; + res << Endl; + + Print(Idx_, res); + + return res.Str(); + } +} diff --git a/library/cpp/tvmauth/client/misc/roles/entities_index.h b/library/cpp/tvmauth/client/misc/roles/entities_index.h index 50ecacd77f..bf42750d52 100644 --- a/library/cpp/tvmauth/client/misc/roles/entities_index.h +++ b/library/cpp/tvmauth/client/misc/roles/entities_index.h @@ -1,107 +1,107 @@ -#pragma once - -#include "types.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <set> -#include <vector> - -namespace NTvmAuth::NRoles { - class TEntitiesIndex: TMoveOnly { - public: - struct TSubTree; - using TIdxByAttrs = THashMap<TKeyValue, TSubTree>; - - struct TSubTree { - std::vector<TEntityPtr> Entities; - TIdxByAttrs SubTree; - }; - - class TStage { - public: - TStage(const std::set<TString>& k); - - bool GetNextKeySet(std::vector<TString>& out); - - private: - std::vector<TString> Keys_; - size_t Id_ = 0; - }; - - public: - TEntitiesIndex(const std::vector<TEntityPtr>& entities); - - /** - * Iterators must be to sorted unique key/value - */ - template <typename Iterator> - bool ContainsExactEntity(Iterator begin, Iterator end) const; - - /** - * Iterators must be to sorted unique key/value - */ - template <typename Iterator> - const std::vector<TEntityPtr>& GetEntitiesWithAttrs(Iterator begin, Iterator end) const; - - public: // for tests - static std::set<TString> GetUniqueSortedKeys(const std::vector<TEntityPtr>& entities); - static void MakeUnique(TEntitiesIndex::TSubTree& branch); - - TString PrintDebugString() const; - - private: - template <typename Iterator> - const TSubTree* FindSubtree(Iterator begin, Iterator end, size_t& size) const; - - private: - TSubTree Idx_; - std::vector<TEntityPtr> EmptyResult_; - }; - - template <typename Iterator> - bool TEntitiesIndex::ContainsExactEntity(Iterator begin, Iterator end) const { - size_t size = 0; - const TSubTree* subtree = FindSubtree(begin, end, size); - if (!subtree) { - return false; - } - - auto res = std::find_if( - subtree->Entities.begin(), - subtree->Entities.end(), - [size](const auto& e) { return size == e->size(); }); - return res != subtree->Entities.end(); - } - - template <typename Iterator> - const std::vector<TEntityPtr>& TEntitiesIndex::GetEntitiesWithAttrs(Iterator begin, Iterator end) const { - size_t size = 0; - const TSubTree* subtree = FindSubtree(begin, end, size); - if (!subtree) { - return EmptyResult_; - } - - return subtree->Entities; - } - - template <typename Iterator> - const TEntitiesIndex::TSubTree* TEntitiesIndex::FindSubtree(Iterator begin, - Iterator end, - size_t& size) const { - const TSubTree* subtree = &Idx_; - size = 0; - - for (auto attr = begin; attr != end; ++attr) { - auto it = subtree->SubTree.find(TKeyValueView{attr->first, attr->second}); - if (it == subtree->SubTree.end()) { - return nullptr; - } - - ++size; - subtree = &it->second; - } - - return subtree; - } -} +#pragma once + +#include "types.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <set> +#include <vector> + +namespace NTvmAuth::NRoles { + class TEntitiesIndex: TMoveOnly { + public: + struct TSubTree; + using TIdxByAttrs = THashMap<TKeyValue, TSubTree>; + + struct TSubTree { + std::vector<TEntityPtr> Entities; + TIdxByAttrs SubTree; + }; + + class TStage { + public: + TStage(const std::set<TString>& k); + + bool GetNextKeySet(std::vector<TString>& out); + + private: + std::vector<TString> Keys_; + size_t Id_ = 0; + }; + + public: + TEntitiesIndex(const std::vector<TEntityPtr>& entities); + + /** + * Iterators must be to sorted unique key/value + */ + template <typename Iterator> + bool ContainsExactEntity(Iterator begin, Iterator end) const; + + /** + * Iterators must be to sorted unique key/value + */ + template <typename Iterator> + const std::vector<TEntityPtr>& GetEntitiesWithAttrs(Iterator begin, Iterator end) const; + + public: // for tests + static std::set<TString> GetUniqueSortedKeys(const std::vector<TEntityPtr>& entities); + static void MakeUnique(TEntitiesIndex::TSubTree& branch); + + TString PrintDebugString() const; + + private: + template <typename Iterator> + const TSubTree* FindSubtree(Iterator begin, Iterator end, size_t& size) const; + + private: + TSubTree Idx_; + std::vector<TEntityPtr> EmptyResult_; + }; + + template <typename Iterator> + bool TEntitiesIndex::ContainsExactEntity(Iterator begin, Iterator end) const { + size_t size = 0; + const TSubTree* subtree = FindSubtree(begin, end, size); + if (!subtree) { + return false; + } + + auto res = std::find_if( + subtree->Entities.begin(), + subtree->Entities.end(), + [size](const auto& e) { return size == e->size(); }); + return res != subtree->Entities.end(); + } + + template <typename Iterator> + const std::vector<TEntityPtr>& TEntitiesIndex::GetEntitiesWithAttrs(Iterator begin, Iterator end) const { + size_t size = 0; + const TSubTree* subtree = FindSubtree(begin, end, size); + if (!subtree) { + return EmptyResult_; + } + + return subtree->Entities; + } + + template <typename Iterator> + const TEntitiesIndex::TSubTree* TEntitiesIndex::FindSubtree(Iterator begin, + Iterator end, + size_t& size) const { + const TSubTree* subtree = &Idx_; + size = 0; + + for (auto attr = begin; attr != end; ++attr) { + auto it = subtree->SubTree.find(TKeyValueView{attr->first, attr->second}); + if (it == subtree->SubTree.end()) { + return nullptr; + } + + ++size; + subtree = &it->second; + } + + return subtree; + } +} diff --git a/library/cpp/tvmauth/client/misc/roles/parser.cpp b/library/cpp/tvmauth/client/misc/roles/parser.cpp index 0d040bade6..eb991b5716 100644 --- a/library/cpp/tvmauth/client/misc/roles/parser.cpp +++ b/library/cpp/tvmauth/client/misc/roles/parser.cpp @@ -1,149 +1,149 @@ -#include "parser.h" - -#include <library/cpp/json/json_reader.h> - -#include <util/string/cast.h> - -namespace NTvmAuth::NRoles { - static void GetRequiredValue(const NJson::TJsonValue& doc, - TStringBuf key, - NJson::TJsonValue& obj) { - Y_ENSURE(doc.GetValue(key, &obj), "Missing '" << key << "'"); - } - - static ui64 GetRequiredUInt(const NJson::TJsonValue& doc, - TStringBuf key) { - NJson::TJsonValue obj; - GetRequiredValue(doc, key, obj); - Y_ENSURE(obj.IsUInteger(), "key '" << key << "' must be uint"); - return obj.GetUInteger(); - } - - static bool GetOptionalMap(const NJson::TJsonValue& doc, - TStringBuf key, - NJson::TJsonValue& obj) { - if (!doc.GetValue(key, &obj)) { - return false; - } - - Y_ENSURE(obj.IsMap(), "'" << key << "' must be object"); - return true; - } - - TRolesPtr TParser::Parse(TRawPtr decodedBlob) { - try { - return ParseImpl(decodedBlob); - } catch (const std::exception& e) { - throw yexception() << "Failed to parse roles from tirole: " << e.what() - << ". '" << *decodedBlob << "'"; - } - } - - TRolesPtr TParser::ParseImpl(TRawPtr decodedBlob) { - NJson::TJsonValue doc; - Y_ENSURE(NJson::ReadJsonTree(*decodedBlob, &doc), "Invalid json"); - Y_ENSURE(doc.IsMap(), "Json must be object"); - - TRoles::TTvmConsumers tvm = GetConsumers<TTvmId>(doc, "tvm"); - TRoles::TUserConsumers user = GetConsumers<TUid>(doc, "user"); - - // fetch it last to provide more correct apply instant - TRoles::TMeta meta = GetMeta(doc); - - return std::make_shared<TRoles>( - std::move(meta), - std::move(tvm), - std::move(user), - std::move(decodedBlob)); - } - - TRoles::TMeta TParser::GetMeta(const NJson::TJsonValue& doc) { - TRoles::TMeta res; - - NJson::TJsonValue obj; - GetRequiredValue(doc, "revision", obj); - if (obj.IsString()) { - res.Revision = obj.GetString(); - } else if (obj.IsUInteger()) { - res.Revision = ToString(obj.GetUInteger()); - } else { - ythrow yexception() << "'revision' has unexpected type: " << obj.GetType(); - } - - res.BornTime = TInstant::Seconds(GetRequiredUInt(doc, "born_date")); - - return res; - } - - template <typename Id> - THashMap<Id, TConsumerRolesPtr> TParser::GetConsumers(const NJson::TJsonValue& doc, - TStringBuf type) { - THashMap<Id, TConsumerRolesPtr> res; - - NJson::TJsonValue obj; - if (!GetOptionalMap(doc, type, obj)) { - return res; - } - - for (const auto& [key, value] : obj.GetMap()) { - Y_ENSURE(value.IsMap(), - "roles for consumer must be map: '" << key << "' is " << value.GetType()); - - Id id = 0; - Y_ENSURE(TryIntFromString<10>(key, id), - "id must be valid positive number of proper size for " - << type << ". got '" - << key << "'"); - - Y_ENSURE(res.emplace(id, GetConsumer(value, key)).second, - "consumer duplicate detected: '" << key << "' for " << type); - } - - return res; - } - - TConsumerRolesPtr TParser::GetConsumer(const NJson::TJsonValue& obj, TStringBuf consumer) { - THashMap<TString, TEntitiesPtr> entities; - - for (const auto& [key, value] : obj.GetMap()) { - Y_ENSURE(value.IsArray(), - "entities for roles must be array: '" << key << "' is " << value.GetType()); - - entities.emplace(key, GetEntities(value, consumer, key)); - } - - return std::make_shared<TConsumerRoles>(std::move(entities)); - } - - TEntitiesPtr TParser::GetEntities(const NJson::TJsonValue& obj, - TStringBuf consumer, - TStringBuf role) { - std::vector<TEntityPtr> entities; - entities.reserve(obj.GetArray().size()); - - for (const NJson::TJsonValue& e : obj.GetArray()) { - Y_ENSURE(e.IsMap(), - "role entity for role must be map: consumer '" - << consumer << "' with role '" << role << "' has " << e.GetType()); - - entities.push_back(GetEntity(e, consumer, role)); - } - - return std::make_shared<TEntities>(TEntities(entities)); - } - - TEntityPtr TParser::GetEntity(const NJson::TJsonValue& obj, TStringBuf consumer, TStringBuf role) { - TEntityPtr res = std::make_shared<TEntity>(); - - for (const auto& [key, value] : obj.GetMap()) { - Y_ENSURE(value.IsString(), - "entity is map (str->str), got value " - << value.GetType() << ". consumer '" - << consumer << "' with role '" << role << "'"); - - res->emplace(key, value.GetString()); - } - - return res; - } -} +#include "parser.h" + +#include <library/cpp/json/json_reader.h> + +#include <util/string/cast.h> + +namespace NTvmAuth::NRoles { + static void GetRequiredValue(const NJson::TJsonValue& doc, + TStringBuf key, + NJson::TJsonValue& obj) { + Y_ENSURE(doc.GetValue(key, &obj), "Missing '" << key << "'"); + } + + static ui64 GetRequiredUInt(const NJson::TJsonValue& doc, + TStringBuf key) { + NJson::TJsonValue obj; + GetRequiredValue(doc, key, obj); + Y_ENSURE(obj.IsUInteger(), "key '" << key << "' must be uint"); + return obj.GetUInteger(); + } + + static bool GetOptionalMap(const NJson::TJsonValue& doc, + TStringBuf key, + NJson::TJsonValue& obj) { + if (!doc.GetValue(key, &obj)) { + return false; + } + + Y_ENSURE(obj.IsMap(), "'" << key << "' must be object"); + return true; + } + + TRolesPtr TParser::Parse(TRawPtr decodedBlob) { + try { + return ParseImpl(decodedBlob); + } catch (const std::exception& e) { + throw yexception() << "Failed to parse roles from tirole: " << e.what() + << ". '" << *decodedBlob << "'"; + } + } + + TRolesPtr TParser::ParseImpl(TRawPtr decodedBlob) { + NJson::TJsonValue doc; + Y_ENSURE(NJson::ReadJsonTree(*decodedBlob, &doc), "Invalid json"); + Y_ENSURE(doc.IsMap(), "Json must be object"); + + TRoles::TTvmConsumers tvm = GetConsumers<TTvmId>(doc, "tvm"); + TRoles::TUserConsumers user = GetConsumers<TUid>(doc, "user"); + + // fetch it last to provide more correct apply instant + TRoles::TMeta meta = GetMeta(doc); + + return std::make_shared<TRoles>( + std::move(meta), + std::move(tvm), + std::move(user), + std::move(decodedBlob)); + } + + TRoles::TMeta TParser::GetMeta(const NJson::TJsonValue& doc) { + TRoles::TMeta res; + + NJson::TJsonValue obj; + GetRequiredValue(doc, "revision", obj); + if (obj.IsString()) { + res.Revision = obj.GetString(); + } else if (obj.IsUInteger()) { + res.Revision = ToString(obj.GetUInteger()); + } else { + ythrow yexception() << "'revision' has unexpected type: " << obj.GetType(); + } + + res.BornTime = TInstant::Seconds(GetRequiredUInt(doc, "born_date")); + + return res; + } + + template <typename Id> + THashMap<Id, TConsumerRolesPtr> TParser::GetConsumers(const NJson::TJsonValue& doc, + TStringBuf type) { + THashMap<Id, TConsumerRolesPtr> res; + + NJson::TJsonValue obj; + if (!GetOptionalMap(doc, type, obj)) { + return res; + } + + for (const auto& [key, value] : obj.GetMap()) { + Y_ENSURE(value.IsMap(), + "roles for consumer must be map: '" << key << "' is " << value.GetType()); + + Id id = 0; + Y_ENSURE(TryIntFromString<10>(key, id), + "id must be valid positive number of proper size for " + << type << ". got '" + << key << "'"); + + Y_ENSURE(res.emplace(id, GetConsumer(value, key)).second, + "consumer duplicate detected: '" << key << "' for " << type); + } + + return res; + } + + TConsumerRolesPtr TParser::GetConsumer(const NJson::TJsonValue& obj, TStringBuf consumer) { + THashMap<TString, TEntitiesPtr> entities; + + for (const auto& [key, value] : obj.GetMap()) { + Y_ENSURE(value.IsArray(), + "entities for roles must be array: '" << key << "' is " << value.GetType()); + + entities.emplace(key, GetEntities(value, consumer, key)); + } + + return std::make_shared<TConsumerRoles>(std::move(entities)); + } + + TEntitiesPtr TParser::GetEntities(const NJson::TJsonValue& obj, + TStringBuf consumer, + TStringBuf role) { + std::vector<TEntityPtr> entities; + entities.reserve(obj.GetArray().size()); + + for (const NJson::TJsonValue& e : obj.GetArray()) { + Y_ENSURE(e.IsMap(), + "role entity for role must be map: consumer '" + << consumer << "' with role '" << role << "' has " << e.GetType()); + + entities.push_back(GetEntity(e, consumer, role)); + } + + return std::make_shared<TEntities>(TEntities(entities)); + } + + TEntityPtr TParser::GetEntity(const NJson::TJsonValue& obj, TStringBuf consumer, TStringBuf role) { + TEntityPtr res = std::make_shared<TEntity>(); + + for (const auto& [key, value] : obj.GetMap()) { + Y_ENSURE(value.IsString(), + "entity is map (str->str), got value " + << value.GetType() << ". consumer '" + << consumer << "' with role '" << role << "'"); + + res->emplace(key, value.GetString()); + } + + return res; + } +} diff --git a/library/cpp/tvmauth/client/misc/roles/parser.h b/library/cpp/tvmauth/client/misc/roles/parser.h index 7cf1d01f47..0982ba78c6 100644 --- a/library/cpp/tvmauth/client/misc/roles/parser.h +++ b/library/cpp/tvmauth/client/misc/roles/parser.h @@ -1,36 +1,36 @@ -#pragma once - -#include "roles.h" -#include "types.h" - -namespace NJson { - class TJsonValue; -} - -namespace NTvmAuth::NRoles { - class TParser { - public: - static TRolesPtr Parse(TRawPtr decodedBlob); - - public: - static TRolesPtr ParseImpl(TRawPtr decodedBlob); - static TRoles::TMeta GetMeta(const NJson::TJsonValue& doc); - - template <typename Id> - static THashMap<Id, TConsumerRolesPtr> GetConsumers( - const NJson::TJsonValue& doc, - TStringBuf key); - - static TConsumerRolesPtr GetConsumer( - const NJson::TJsonValue& obj, - TStringBuf consumer); - static TEntitiesPtr GetEntities( - const NJson::TJsonValue& obj, - TStringBuf consumer, - TStringBuf role); - static TEntityPtr GetEntity( - const NJson::TJsonValue& obj, - TStringBuf consumer, - TStringBuf role); - }; -} +#pragma once + +#include "roles.h" +#include "types.h" + +namespace NJson { + class TJsonValue; +} + +namespace NTvmAuth::NRoles { + class TParser { + public: + static TRolesPtr Parse(TRawPtr decodedBlob); + + public: + static TRolesPtr ParseImpl(TRawPtr decodedBlob); + static TRoles::TMeta GetMeta(const NJson::TJsonValue& doc); + + template <typename Id> + static THashMap<Id, TConsumerRolesPtr> GetConsumers( + const NJson::TJsonValue& doc, + TStringBuf key); + + static TConsumerRolesPtr GetConsumer( + const NJson::TJsonValue& obj, + TStringBuf consumer); + static TEntitiesPtr GetEntities( + const NJson::TJsonValue& obj, + TStringBuf consumer, + TStringBuf role); + static TEntityPtr GetEntity( + const NJson::TJsonValue& obj, + TStringBuf consumer, + TStringBuf role); + }; +} diff --git a/library/cpp/tvmauth/client/misc/roles/roles.cpp b/library/cpp/tvmauth/client/misc/roles/roles.cpp index a2663df392..f412558b99 100644 --- a/library/cpp/tvmauth/client/misc/roles/roles.cpp +++ b/library/cpp/tvmauth/client/misc/roles/roles.cpp @@ -1,101 +1,101 @@ -#include "roles.h" - -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/checked_user_ticket.h> - -namespace NTvmAuth::NRoles { - TRoles::TRoles(TMeta&& meta, - TTvmConsumers tvm, - TUserConsumers user, - TRawPtr raw) - : Meta_(std::move(meta)) - , TvmIds_(std::move(tvm)) - , Users_(std::move(user)) - , Raw_(std::move(raw)) - { - Y_ENSURE(Raw_); - } - - TConsumerRolesPtr TRoles::GetRolesForService(const TCheckedServiceTicket& t) const { - Y_ENSURE_EX(t, - TIllegalUsage() << "Service ticket must be valid, got: " << t.GetStatus()); - auto it = TvmIds_.find(t.GetSrc()); - return it == TvmIds_.end() ? TConsumerRolesPtr() : it->second; - } - - TConsumerRolesPtr TRoles::GetRolesForUser(const TCheckedUserTicket& t, - std::optional<TUid> selectedUid) const { - Y_ENSURE_EX(t, - TIllegalUsage() << "User ticket must be valid, got: " << t.GetStatus()); - Y_ENSURE_EX(t.GetEnv() == EBlackboxEnv::ProdYateam, - TIllegalUsage() << "User ticket must be from ProdYateam, got from " << t.GetEnv()); - - TUid uid = t.GetDefaultUid(); - if (selectedUid) { - auto it = std::find(t.GetUids().begin(), t.GetUids().end(), *selectedUid); - Y_ENSURE_EX(it != t.GetUids().end(), - TIllegalUsage() << "selectedUid must be in user ticket but it's not: " - << *selectedUid); - uid = *selectedUid; - } - - auto it = Users_.find(uid); - return it == Users_.end() ? TConsumerRolesPtr() : it->second; - } - - const TRoles::TMeta& TRoles::GetMeta() const { - return Meta_; - } - - const TString& TRoles::GetRaw() const { - return *Raw_; - } - - bool TRoles::CheckServiceRole(const TCheckedServiceTicket& t, - const TStringBuf roleName) const { - TConsumerRolesPtr c = GetRolesForService(t); - return c ? c->HasRole(roleName) : false; - } - - bool TRoles::CheckUserRole(const TCheckedUserTicket& t, - const TStringBuf roleName, - std::optional<TUid> selectedUid) const { - TConsumerRolesPtr c = GetRolesForUser(t, selectedUid); - return c ? c->HasRole(roleName) : false; - } - - bool TRoles::CheckServiceRoleForExactEntity(const TCheckedServiceTicket& t, - const TStringBuf roleName, - const TEntity& exactEntity) const { - TConsumerRolesPtr c = GetRolesForService(t); - return c ? c->CheckRoleForExactEntity(roleName, exactEntity) : false; - } - - bool TRoles::CheckUserRoleForExactEntity(const TCheckedUserTicket& t, - const TStringBuf roleName, - const TEntity& exactEntity, - std::optional<TUid> selectedUid) const { - TConsumerRolesPtr c = GetRolesForUser(t, selectedUid); - return c ? c->CheckRoleForExactEntity(roleName, exactEntity) : false; - } - - TConsumerRoles::TConsumerRoles(THashMap<TString, TEntitiesPtr> roles) - : Roles_(std::move(roles)) - { - } - - bool TConsumerRoles::CheckRoleForExactEntity(const TStringBuf roleName, - const TEntity& exactEntity) const { - auto it = Roles_.find(roleName); - if (it == Roles_.end()) { - return false; - } - - return it->second->Contains(exactEntity); - } - - TEntities::TEntities(TEntitiesIndex idx) - : Idx_(std::move(idx)) - { - } -} +#include "roles.h" + +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/checked_user_ticket.h> + +namespace NTvmAuth::NRoles { + TRoles::TRoles(TMeta&& meta, + TTvmConsumers tvm, + TUserConsumers user, + TRawPtr raw) + : Meta_(std::move(meta)) + , TvmIds_(std::move(tvm)) + , Users_(std::move(user)) + , Raw_(std::move(raw)) + { + Y_ENSURE(Raw_); + } + + TConsumerRolesPtr TRoles::GetRolesForService(const TCheckedServiceTicket& t) const { + Y_ENSURE_EX(t, + TIllegalUsage() << "Service ticket must be valid, got: " << t.GetStatus()); + auto it = TvmIds_.find(t.GetSrc()); + return it == TvmIds_.end() ? TConsumerRolesPtr() : it->second; + } + + TConsumerRolesPtr TRoles::GetRolesForUser(const TCheckedUserTicket& t, + std::optional<TUid> selectedUid) const { + Y_ENSURE_EX(t, + TIllegalUsage() << "User ticket must be valid, got: " << t.GetStatus()); + Y_ENSURE_EX(t.GetEnv() == EBlackboxEnv::ProdYateam, + TIllegalUsage() << "User ticket must be from ProdYateam, got from " << t.GetEnv()); + + TUid uid = t.GetDefaultUid(); + if (selectedUid) { + auto it = std::find(t.GetUids().begin(), t.GetUids().end(), *selectedUid); + Y_ENSURE_EX(it != t.GetUids().end(), + TIllegalUsage() << "selectedUid must be in user ticket but it's not: " + << *selectedUid); + uid = *selectedUid; + } + + auto it = Users_.find(uid); + return it == Users_.end() ? TConsumerRolesPtr() : it->second; + } + + const TRoles::TMeta& TRoles::GetMeta() const { + return Meta_; + } + + const TString& TRoles::GetRaw() const { + return *Raw_; + } + + bool TRoles::CheckServiceRole(const TCheckedServiceTicket& t, + const TStringBuf roleName) const { + TConsumerRolesPtr c = GetRolesForService(t); + return c ? c->HasRole(roleName) : false; + } + + bool TRoles::CheckUserRole(const TCheckedUserTicket& t, + const TStringBuf roleName, + std::optional<TUid> selectedUid) const { + TConsumerRolesPtr c = GetRolesForUser(t, selectedUid); + return c ? c->HasRole(roleName) : false; + } + + bool TRoles::CheckServiceRoleForExactEntity(const TCheckedServiceTicket& t, + const TStringBuf roleName, + const TEntity& exactEntity) const { + TConsumerRolesPtr c = GetRolesForService(t); + return c ? c->CheckRoleForExactEntity(roleName, exactEntity) : false; + } + + bool TRoles::CheckUserRoleForExactEntity(const TCheckedUserTicket& t, + const TStringBuf roleName, + const TEntity& exactEntity, + std::optional<TUid> selectedUid) const { + TConsumerRolesPtr c = GetRolesForUser(t, selectedUid); + return c ? c->CheckRoleForExactEntity(roleName, exactEntity) : false; + } + + TConsumerRoles::TConsumerRoles(THashMap<TString, TEntitiesPtr> roles) + : Roles_(std::move(roles)) + { + } + + bool TConsumerRoles::CheckRoleForExactEntity(const TStringBuf roleName, + const TEntity& exactEntity) const { + auto it = Roles_.find(roleName); + if (it == Roles_.end()) { + return false; + } + + return it->second->Contains(exactEntity); + } + + TEntities::TEntities(TEntitiesIndex idx) + : Idx_(std::move(idx)) + { + } +} diff --git a/library/cpp/tvmauth/client/misc/roles/roles.h b/library/cpp/tvmauth/client/misc/roles/roles.h index 344702b539..00ffb7e070 100644 --- a/library/cpp/tvmauth/client/misc/roles/roles.h +++ b/library/cpp/tvmauth/client/misc/roles/roles.h @@ -1,182 +1,182 @@ -#pragma once - -#include "entities_index.h" -#include "types.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/type.h> - -#include <util/datetime/base.h> -#include <util/generic/array_ref.h> -#include <util/generic/hash.h> - -#include <vector> - -namespace NTvmAuth { - class TCheckedServiceTicket; - class TCheckedUserTicket; -} - -namespace NTvmAuth::NRoles { - class TRoles { - public: - struct TMeta { - TString Revision; - TInstant BornTime; - TInstant Applied = TInstant::Now(); - }; - - using TTvmConsumers = THashMap<TTvmId, TConsumerRolesPtr>; - using TUserConsumers = THashMap<TUid, TConsumerRolesPtr>; - - TRoles(TMeta&& meta, - TTvmConsumers tvm, - TUserConsumers user, - TRawPtr raw); - - /** - * @return ptr to roles. It will be nullptr if there are no roles - */ - TConsumerRolesPtr GetRolesForService(const TCheckedServiceTicket& t) const; - - /** - * @return ptr to roles. It will be nullptr if there are no roles - */ - TConsumerRolesPtr GetRolesForUser(const TCheckedUserTicket& t, - std::optional<TUid> selectedUid = {}) const; - - const TMeta& GetMeta() const; - const TString& GetRaw() const; - - public: // shortcuts - /** - * @brief CheckServiceRole() is shortcut for simple role checking - for any possible entity - */ - bool CheckServiceRole( - const TCheckedServiceTicket& t, - const TStringBuf roleName) const; - - /** - * @brief CheckUserRole() is shortcut for simple role checking - for any possible entity - */ - bool CheckUserRole( - const TCheckedUserTicket& t, - const TStringBuf roleName, - std::optional<TUid> selectedUid = {}) const; - - /** - * @brief CheckServiceRoleForExactEntity() is shortcut for simple role checking for exact entity - */ - bool CheckServiceRoleForExactEntity( - const TCheckedServiceTicket& t, - const TStringBuf roleName, - const TEntity& exactEntity) const; - - /** - * @brief CheckUserRoleForExactEntity() is shortcut for simple role checking for exact entity - */ - bool CheckUserRoleForExactEntity( - const TCheckedUserTicket& t, - const TStringBuf roleName, - const TEntity& exactEntity, - std::optional<TUid> selectedUid = {}) const; - - private: - TMeta Meta_; - TTvmConsumers TvmIds_; - TUserConsumers Users_; - TRawPtr Raw_; - }; - - class TConsumerRoles { - public: - TConsumerRoles(THashMap<TString, TEntitiesPtr> roles); - - bool HasRole(const TStringBuf roleName) const { - return Roles_.contains(roleName); - } - - /** - * @return ptr to entries. It will be nullptr if there is no role - */ - TEntitiesPtr GetEntitiesForRole(const TStringBuf roleName) const { - auto it = Roles_.find(roleName); - return it == Roles_.end() ? TEntitiesPtr() : it->second; - } - - /** - * @brief CheckRoleForExactEntity() is shortcut for simple role checking for exact entity - */ - bool CheckRoleForExactEntity(const TStringBuf roleName, - const TEntity& exactEntity) const; - - private: - THashMap<TString, TEntitiesPtr> Roles_; - }; - - class TEntities { - public: - TEntities(TEntitiesIndex idx); - - /** - * @brief Contains() provides info about entity presence - */ - bool Contains(const TEntity& exactEntity) const { - return Idx_.ContainsExactEntity(exactEntity.begin(), exactEntity.end()); - } - - /** - * @brief The same as Contains() - * It checks span for sorted and unique properties. - */ - template <class StrKey = TString, class StrValue = TString> - bool ContainsSortedUnique( - const TArrayRef<const std::pair<StrKey, StrValue>>& exactEntity) const { - CheckSpan(exactEntity); - return Idx_.ContainsExactEntity(exactEntity.begin(), exactEntity.end()); - } - - /** - * @brief GetEntitiesWithAttrs() collects entities with ALL attributes from `attrs` - */ - template <class StrKey = TString, class StrValue = TString> - const std::vector<TEntityPtr>& GetEntitiesWithAttrs( - const std::map<StrKey, StrValue>& attrs) const { - return Idx_.GetEntitiesWithAttrs(attrs.begin(), attrs.end()); - } - - /** - * @brief The same as GetEntitiesWithAttrs() - * It checks span for sorted and unique properties. - */ - template <class StrKey = TString, class StrValue = TString> - const std::vector<TEntityPtr>& GetEntitiesWithSortedUniqueAttrs( - const TArrayRef<const std::pair<StrKey, StrValue>>& attrs) const { - CheckSpan(attrs); - return Idx_.GetEntitiesWithAttrs(attrs.begin(), attrs.end()); - } - - private: - template <class StrKey, class StrValue> - static void CheckSpan(const TArrayRef<const std::pair<StrKey, StrValue>>& attrs) { - if (attrs.empty()) { - return; - } - - auto prev = attrs.begin(); - for (auto it = prev + 1; it != attrs.end(); ++it) { - Y_ENSURE_EX(prev->first != it->first, - TIllegalUsage() << "attrs are not unique: '" << it->first << "'"); - Y_ENSURE_EX(prev->first < it->first, - TIllegalUsage() << "attrs are not sorted: '" << prev->first - << "' before '" << it->first << "'"); - - prev = it; - } - } - - private: - TEntitiesIndex Idx_; - }; -} +#pragma once + +#include "entities_index.h" +#include "types.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/type.h> + +#include <util/datetime/base.h> +#include <util/generic/array_ref.h> +#include <util/generic/hash.h> + +#include <vector> + +namespace NTvmAuth { + class TCheckedServiceTicket; + class TCheckedUserTicket; +} + +namespace NTvmAuth::NRoles { + class TRoles { + public: + struct TMeta { + TString Revision; + TInstant BornTime; + TInstant Applied = TInstant::Now(); + }; + + using TTvmConsumers = THashMap<TTvmId, TConsumerRolesPtr>; + using TUserConsumers = THashMap<TUid, TConsumerRolesPtr>; + + TRoles(TMeta&& meta, + TTvmConsumers tvm, + TUserConsumers user, + TRawPtr raw); + + /** + * @return ptr to roles. It will be nullptr if there are no roles + */ + TConsumerRolesPtr GetRolesForService(const TCheckedServiceTicket& t) const; + + /** + * @return ptr to roles. It will be nullptr if there are no roles + */ + TConsumerRolesPtr GetRolesForUser(const TCheckedUserTicket& t, + std::optional<TUid> selectedUid = {}) const; + + const TMeta& GetMeta() const; + const TString& GetRaw() const; + + public: // shortcuts + /** + * @brief CheckServiceRole() is shortcut for simple role checking - for any possible entity + */ + bool CheckServiceRole( + const TCheckedServiceTicket& t, + const TStringBuf roleName) const; + + /** + * @brief CheckUserRole() is shortcut for simple role checking - for any possible entity + */ + bool CheckUserRole( + const TCheckedUserTicket& t, + const TStringBuf roleName, + std::optional<TUid> selectedUid = {}) const; + + /** + * @brief CheckServiceRoleForExactEntity() is shortcut for simple role checking for exact entity + */ + bool CheckServiceRoleForExactEntity( + const TCheckedServiceTicket& t, + const TStringBuf roleName, + const TEntity& exactEntity) const; + + /** + * @brief CheckUserRoleForExactEntity() is shortcut for simple role checking for exact entity + */ + bool CheckUserRoleForExactEntity( + const TCheckedUserTicket& t, + const TStringBuf roleName, + const TEntity& exactEntity, + std::optional<TUid> selectedUid = {}) const; + + private: + TMeta Meta_; + TTvmConsumers TvmIds_; + TUserConsumers Users_; + TRawPtr Raw_; + }; + + class TConsumerRoles { + public: + TConsumerRoles(THashMap<TString, TEntitiesPtr> roles); + + bool HasRole(const TStringBuf roleName) const { + return Roles_.contains(roleName); + } + + /** + * @return ptr to entries. It will be nullptr if there is no role + */ + TEntitiesPtr GetEntitiesForRole(const TStringBuf roleName) const { + auto it = Roles_.find(roleName); + return it == Roles_.end() ? TEntitiesPtr() : it->second; + } + + /** + * @brief CheckRoleForExactEntity() is shortcut for simple role checking for exact entity + */ + bool CheckRoleForExactEntity(const TStringBuf roleName, + const TEntity& exactEntity) const; + + private: + THashMap<TString, TEntitiesPtr> Roles_; + }; + + class TEntities { + public: + TEntities(TEntitiesIndex idx); + + /** + * @brief Contains() provides info about entity presence + */ + bool Contains(const TEntity& exactEntity) const { + return Idx_.ContainsExactEntity(exactEntity.begin(), exactEntity.end()); + } + + /** + * @brief The same as Contains() + * It checks span for sorted and unique properties. + */ + template <class StrKey = TString, class StrValue = TString> + bool ContainsSortedUnique( + const TArrayRef<const std::pair<StrKey, StrValue>>& exactEntity) const { + CheckSpan(exactEntity); + return Idx_.ContainsExactEntity(exactEntity.begin(), exactEntity.end()); + } + + /** + * @brief GetEntitiesWithAttrs() collects entities with ALL attributes from `attrs` + */ + template <class StrKey = TString, class StrValue = TString> + const std::vector<TEntityPtr>& GetEntitiesWithAttrs( + const std::map<StrKey, StrValue>& attrs) const { + return Idx_.GetEntitiesWithAttrs(attrs.begin(), attrs.end()); + } + + /** + * @brief The same as GetEntitiesWithAttrs() + * It checks span for sorted and unique properties. + */ + template <class StrKey = TString, class StrValue = TString> + const std::vector<TEntityPtr>& GetEntitiesWithSortedUniqueAttrs( + const TArrayRef<const std::pair<StrKey, StrValue>>& attrs) const { + CheckSpan(attrs); + return Idx_.GetEntitiesWithAttrs(attrs.begin(), attrs.end()); + } + + private: + template <class StrKey, class StrValue> + static void CheckSpan(const TArrayRef<const std::pair<StrKey, StrValue>>& attrs) { + if (attrs.empty()) { + return; + } + + auto prev = attrs.begin(); + for (auto it = prev + 1; it != attrs.end(); ++it) { + Y_ENSURE_EX(prev->first != it->first, + TIllegalUsage() << "attrs are not unique: '" << it->first << "'"); + Y_ENSURE_EX(prev->first < it->first, + TIllegalUsage() << "attrs are not sorted: '" << prev->first + << "' before '" << it->first << "'"); + + prev = it; + } + } + + private: + TEntitiesIndex Idx_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/roles/types.h b/library/cpp/tvmauth/client/misc/roles/types.h index 79a01950b6..e7614bf637 100644 --- a/library/cpp/tvmauth/client/misc/roles/types.h +++ b/library/cpp/tvmauth/client/misc/roles/types.h @@ -1,68 +1,68 @@ -#pragma once - -#include <util/generic/hash_set.h> - -#include <map> -#include <memory> - -namespace NTvmAuth::NRoles { - using TEntity = std::map<TString, TString>; - using TEntityPtr = std::shared_ptr<TEntity>; - - class TEntities; - using TEntitiesPtr = std::shared_ptr<TEntities>; - - class TConsumerRoles; - using TConsumerRolesPtr = std::shared_ptr<TConsumerRoles>; - - class TRoles; - using TRolesPtr = std::shared_ptr<TRoles>; - - using TRawPtr = std::shared_ptr<TString>; - - template <class T> - struct TKeyValueBase { - T Key; - T Value; - - template <typename U> - bool operator==(const TKeyValueBase<U>& o) const { - return Key == o.Key && Value == o.Value; - } - }; - - using TKeyValue = TKeyValueBase<TString>; - using TKeyValueView = TKeyValueBase<TStringBuf>; -} - -// Traits - -template <> -struct THash<NTvmAuth::NRoles::TKeyValue> { - std::size_t operator()(const NTvmAuth::NRoles::TKeyValue& e) const { - return std::hash<std::string_view>()(e.Key) + std::hash<std::string_view>()(e.Value); - } - - std::size_t operator()(const NTvmAuth::NRoles::TKeyValueView& e) const { - return std::hash<std::string_view>()(e.Key) + std::hash<std::string_view>()(e.Value); - } -}; - -template <> -struct TEqualTo<NTvmAuth::NRoles::TKeyValue> { - using is_transparent = std::true_type; - - template <typename T, typename U> - bool operator()(const NTvmAuth::NRoles::TKeyValueBase<T>& l, - const NTvmAuth::NRoles::TKeyValueBase<U>& r) { - return l == r; - } -}; - -inline bool operator<(const NTvmAuth::NRoles::TEntityPtr& l, const NTvmAuth::NRoles::TEntityPtr& r) { - return *l < *r; -} - -inline bool operator==(const NTvmAuth::NRoles::TEntityPtr& l, const NTvmAuth::NRoles::TEntityPtr& r) { - return *l == *r; -} +#pragma once + +#include <util/generic/hash_set.h> + +#include <map> +#include <memory> + +namespace NTvmAuth::NRoles { + using TEntity = std::map<TString, TString>; + using TEntityPtr = std::shared_ptr<TEntity>; + + class TEntities; + using TEntitiesPtr = std::shared_ptr<TEntities>; + + class TConsumerRoles; + using TConsumerRolesPtr = std::shared_ptr<TConsumerRoles>; + + class TRoles; + using TRolesPtr = std::shared_ptr<TRoles>; + + using TRawPtr = std::shared_ptr<TString>; + + template <class T> + struct TKeyValueBase { + T Key; + T Value; + + template <typename U> + bool operator==(const TKeyValueBase<U>& o) const { + return Key == o.Key && Value == o.Value; + } + }; + + using TKeyValue = TKeyValueBase<TString>; + using TKeyValueView = TKeyValueBase<TStringBuf>; +} + +// Traits + +template <> +struct THash<NTvmAuth::NRoles::TKeyValue> { + std::size_t operator()(const NTvmAuth::NRoles::TKeyValue& e) const { + return std::hash<std::string_view>()(e.Key) + std::hash<std::string_view>()(e.Value); + } + + std::size_t operator()(const NTvmAuth::NRoles::TKeyValueView& e) const { + return std::hash<std::string_view>()(e.Key) + std::hash<std::string_view>()(e.Value); + } +}; + +template <> +struct TEqualTo<NTvmAuth::NRoles::TKeyValue> { + using is_transparent = std::true_type; + + template <typename T, typename U> + bool operator()(const NTvmAuth::NRoles::TKeyValueBase<T>& l, + const NTvmAuth::NRoles::TKeyValueBase<U>& r) { + return l == r; + } +}; + +inline bool operator<(const NTvmAuth::NRoles::TEntityPtr& l, const NTvmAuth::NRoles::TEntityPtr& r) { + return *l < *r; +} + +inline bool operator==(const NTvmAuth::NRoles::TEntityPtr& l, const NTvmAuth::NRoles::TEntityPtr& r) { + return *l == *r; +} diff --git a/library/cpp/tvmauth/client/misc/settings.h b/library/cpp/tvmauth/client/misc/settings.h index 6d63ab5bf7..8fae6c34d3 100644 --- a/library/cpp/tvmauth/client/misc/settings.h +++ b/library/cpp/tvmauth/client/misc/settings.h @@ -1,13 +1,13 @@ -#pragma once - -#include <util/generic/fwd.h> - -namespace NTvmAuth { - class TClientSettings { - public: - /*! - * Look at description in relevant settings: NTvmApi::TClientSettings or NTvmTool::TClientSettings - */ - using TAlias = TString; - }; -} +#pragma once + +#include <util/generic/fwd.h> + +namespace NTvmAuth { + class TClientSettings { + public: + /*! + * Look at description in relevant settings: NTvmApi::TClientSettings or NTvmTool::TClientSettings + */ + using TAlias = TString; + }; +} diff --git a/library/cpp/tvmauth/client/misc/src_checker.h b/library/cpp/tvmauth/client/misc/src_checker.h index 2b9f7e98f9..25e8e72602 100644 --- a/library/cpp/tvmauth/client/misc/src_checker.h +++ b/library/cpp/tvmauth/client/misc/src_checker.h @@ -1,46 +1,46 @@ -#pragma once - -#include "async_updater.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/src/service_impl.h> - -namespace NTvmAuth { - class TSrcChecker { - public: - TSrcChecker(TAsyncUpdaterPtr updater) - : Updater_(std::move(updater)) - { - Y_ENSURE(Updater_); - GetCache(); - } - - /*! - * Checking must be enabled in TClientSettings - * Can throw exception if cache is out of date or wrong config - * @param ticket - */ - TCheckedServiceTicket Check(TCheckedServiceTicket ticket) const { - NRoles::TConsumerRolesPtr roles = GetCache()->GetRolesForService(ticket); - if (roles) { - return ticket; - } - +#pragma once + +#include "async_updater.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/src/service_impl.h> + +namespace NTvmAuth { + class TSrcChecker { + public: + TSrcChecker(TAsyncUpdaterPtr updater) + : Updater_(std::move(updater)) + { + Y_ENSURE(Updater_); + GetCache(); + } + + /*! + * Checking must be enabled in TClientSettings + * Can throw exception if cache is out of date or wrong config + * @param ticket + */ + TCheckedServiceTicket Check(TCheckedServiceTicket ticket) const { + NRoles::TConsumerRolesPtr roles = GetCache()->GetRolesForService(ticket); + if (roles) { + return ticket; + } + TServiceTicketImplPtr impl = THolder(NInternal::TCanningKnife::GetS(ticket)); - impl->SetStatus(ETicketStatus::NoRoles); - return TCheckedServiceTicket(std::move(impl)); - } - - private: - NRoles::TRolesPtr GetCache() const { - NRoles::TRolesPtr c = Updater_->GetRoles(); - Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableRolesFetching()"); - return c; - } - - private: - TAsyncUpdaterPtr Updater_; - }; -} + impl->SetStatus(ETicketStatus::NoRoles); + return TCheckedServiceTicket(std::move(impl)); + } + + private: + NRoles::TRolesPtr GetCache() const { + NRoles::TRolesPtr c = Updater_->GetRoles(); + Y_ENSURE_EX(c, TBrokenTvmClientSettings() << "Need to use TClientSettings::EnableRolesFetching()"); + return c; + } + + private: + TAsyncUpdaterPtr Updater_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/threaded_updater.cpp b/library/cpp/tvmauth/client/misc/threaded_updater.cpp index 0e6f9dbd66..5d21ce67a7 100644 --- a/library/cpp/tvmauth/client/misc/threaded_updater.cpp +++ b/library/cpp/tvmauth/client/misc/threaded_updater.cpp @@ -1,111 +1,111 @@ -#include "threaded_updater.h" - -#include <library/cpp/tvmauth/client/exception.h> - -#include <util/string/builder.h> -#include <util/system/spin_wait.h> +#include "threaded_updater.h" + +#include <library/cpp/tvmauth/client/exception.h> + +#include <util/string/builder.h> +#include <util/system/spin_wait.h> #include <util/system/thread.h> - -namespace NTvmAuth { - TThreadedUpdaterBase::TThreadedUpdaterBase(TDuration workerAwakingPeriod, - TLoggerPtr logger, - const TString& url, + +namespace NTvmAuth { + TThreadedUpdaterBase::TThreadedUpdaterBase(TDuration workerAwakingPeriod, + TLoggerPtr logger, + const TString& url, ui16 port, TDuration socketTimeout, TDuration connectTimeout) - : WorkerAwakingPeriod_(workerAwakingPeriod) - , Logger_(std::move(logger)) - , TvmUrl_(url) - , TvmPort_(port) + : WorkerAwakingPeriod_(workerAwakingPeriod) + , Logger_(std::move(logger)) + , TvmUrl_(url) + , TvmPort_(port) , TvmSocketTimeout_(socketTimeout) , TvmConnectTimeout_(connectTimeout) - , IsStopped_(true) - { - Y_ENSURE_EX(Logger_, TNonRetriableException() << "Logger is required"); - - ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); - ServiceTicketsDurations_.Expiring = TDuration::Hours(2); - ServiceTicketsDurations_.Invalid = TDuration::Hours(11); - - PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); - PublicKeysDurations_.Expiring = TDuration::Days(2); - PublicKeysDurations_.Invalid = TDuration::Days(6); - } - - TThreadedUpdaterBase::~TThreadedUpdaterBase() { - StopWorker(); - } - - void TThreadedUpdaterBase::StartWorker() { - if (HttpClient_) { - HttpClient_->ResetConnection(); - } - Thread_ = MakeHolder<TThread>(WorkerWrap, this); - Thread_->Start(); - Started_.Wait(); - IsStopped_ = false; - } - - void TThreadedUpdaterBase::StopWorker() { - Event_.Signal(); - if (Thread_) { - Thread_.Reset(); - } - } - - TKeepAliveHttpClient& TThreadedUpdaterBase::GetClient() const { - if (!HttpClient_) { + , IsStopped_(true) + { + Y_ENSURE_EX(Logger_, TNonRetriableException() << "Logger is required"); + + ServiceTicketsDurations_.RefreshPeriod = TDuration::Hours(1); + ServiceTicketsDurations_.Expiring = TDuration::Hours(2); + ServiceTicketsDurations_.Invalid = TDuration::Hours(11); + + PublicKeysDurations_.RefreshPeriod = TDuration::Days(1); + PublicKeysDurations_.Expiring = TDuration::Days(2); + PublicKeysDurations_.Invalid = TDuration::Days(6); + } + + TThreadedUpdaterBase::~TThreadedUpdaterBase() { + StopWorker(); + } + + void TThreadedUpdaterBase::StartWorker() { + if (HttpClient_) { + HttpClient_->ResetConnection(); + } + Thread_ = MakeHolder<TThread>(WorkerWrap, this); + Thread_->Start(); + Started_.Wait(); + IsStopped_ = false; + } + + void TThreadedUpdaterBase::StopWorker() { + Event_.Signal(); + if (Thread_) { + Thread_.Reset(); + } + } + + TKeepAliveHttpClient& TThreadedUpdaterBase::GetClient() const { + if (!HttpClient_) { HttpClient_ = MakeHolder<TKeepAliveHttpClient>(TvmUrl_, TvmPort_, TvmSocketTimeout_, TvmConnectTimeout_); - } - - return *HttpClient_; - } - - void TThreadedUpdaterBase::LogDebug(const TString& msg) const { - if (Logger_) { - Logger_->Debug(msg); - } - } - - void TThreadedUpdaterBase::LogInfo(const TString& msg) const { - if (Logger_) { - Logger_->Info(msg); - } - } - - void TThreadedUpdaterBase::LogWarning(const TString& msg) const { - if (Logger_) { - Logger_->Warning(msg); - } - } - - void TThreadedUpdaterBase::LogError(const TString& msg) const { - if (Logger_) { - Logger_->Error(msg); - } - } - - void* TThreadedUpdaterBase::WorkerWrap(void* arg) { + } + + return *HttpClient_; + } + + void TThreadedUpdaterBase::LogDebug(const TString& msg) const { + if (Logger_) { + Logger_->Debug(msg); + } + } + + void TThreadedUpdaterBase::LogInfo(const TString& msg) const { + if (Logger_) { + Logger_->Info(msg); + } + } + + void TThreadedUpdaterBase::LogWarning(const TString& msg) const { + if (Logger_) { + Logger_->Warning(msg); + } + } + + void TThreadedUpdaterBase::LogError(const TString& msg) const { + if (Logger_) { + Logger_->Error(msg); + } + } + + void* TThreadedUpdaterBase::WorkerWrap(void* arg) { TThread::SetCurrentThreadName("TicketParserUpd"); - TThreadedUpdaterBase& this_ = *reinterpret_cast<TThreadedUpdaterBase*>(arg); - this_.Started_.Signal(); - this_.LogDebug("Thread-worker started"); - - while (true) { - if (this_.Event_.WaitT(this_.WorkerAwakingPeriod_)) { - break; - } - - try { - this_.Worker(); - this_.GetClient().ResetConnection(); - } catch (const std::exception& e) { // impossible now - this_.LogError(TStringBuilder() << "Failed to generate new cache: " << e.what()); - } - } - - this_.LogDebug("Thread-worker stopped"); - this_.IsStopped_ = true; - return nullptr; - } -} + TThreadedUpdaterBase& this_ = *reinterpret_cast<TThreadedUpdaterBase*>(arg); + this_.Started_.Signal(); + this_.LogDebug("Thread-worker started"); + + while (true) { + if (this_.Event_.WaitT(this_.WorkerAwakingPeriod_)) { + break; + } + + try { + this_.Worker(); + this_.GetClient().ResetConnection(); + } catch (const std::exception& e) { // impossible now + this_.LogError(TStringBuilder() << "Failed to generate new cache: " << e.what()); + } + } + + this_.LogDebug("Thread-worker stopped"); + this_.IsStopped_ = true; + return nullptr; + } +} diff --git a/library/cpp/tvmauth/client/misc/threaded_updater.h b/library/cpp/tvmauth/client/misc/threaded_updater.h index d6b251b4ed..783684ba3b 100644 --- a/library/cpp/tvmauth/client/misc/threaded_updater.h +++ b/library/cpp/tvmauth/client/misc/threaded_updater.h @@ -1,76 +1,76 @@ -#pragma once - -#include "async_updater.h" -#include "settings.h" - -#include <library/cpp/tvmauth/client/logger.h> - -#include <library/cpp/http/simple/http_client.h> - -#include <util/datetime/base.h> -#include <util/generic/ptr.h> -#include <util/system/event.h> -#include <util/system/thread.h> - -class TKeepAliveHttpClient; - -namespace NTvmAuth::NInternal { - class TClientCaningKnife; -} -namespace NTvmAuth { - class TThreadedUpdaterBase: public TAsyncUpdaterBase { - public: +#pragma once + +#include "async_updater.h" +#include "settings.h" + +#include <library/cpp/tvmauth/client/logger.h> + +#include <library/cpp/http/simple/http_client.h> + +#include <util/datetime/base.h> +#include <util/generic/ptr.h> +#include <util/system/event.h> +#include <util/system/thread.h> + +class TKeepAliveHttpClient; + +namespace NTvmAuth::NInternal { + class TClientCaningKnife; +} +namespace NTvmAuth { + class TThreadedUpdaterBase: public TAsyncUpdaterBase { + public: TThreadedUpdaterBase(TDuration workerAwakingPeriod, TLoggerPtr logger, const TString& url, ui16 port, TDuration socketTimeout, TDuration connectTimeout); - virtual ~TThreadedUpdaterBase(); - - protected: - void StartWorker(); - void StopWorker(); - - virtual void Worker() { - } - - TKeepAliveHttpClient& GetClient() const; - - void LogDebug(const TString& msg) const; - void LogInfo(const TString& msg) const; - void LogWarning(const TString& msg) const; - void LogError(const TString& msg) const; - - protected: - TDuration WorkerAwakingPeriod_; - - const TLoggerPtr Logger_; - - protected: - const TString TvmUrl_; - - private: - static void* WorkerWrap(void* arg); - - void StartTvmClientStopping() const override { - Event_.Signal(); - } - - bool IsTvmClientStopped() const override { - return IsStopped_; - } - - private: - mutable THolder<TKeepAliveHttpClient> HttpClient_; - - const ui32 TvmPort_; + virtual ~TThreadedUpdaterBase(); + + protected: + void StartWorker(); + void StopWorker(); + + virtual void Worker() { + } + + TKeepAliveHttpClient& GetClient() const; + + void LogDebug(const TString& msg) const; + void LogInfo(const TString& msg) const; + void LogWarning(const TString& msg) const; + void LogError(const TString& msg) const; + + protected: + TDuration WorkerAwakingPeriod_; + + const TLoggerPtr Logger_; + + protected: + const TString TvmUrl_; + + private: + static void* WorkerWrap(void* arg); + + void StartTvmClientStopping() const override { + Event_.Signal(); + } + + bool IsTvmClientStopped() const override { + return IsStopped_; + } + + private: + mutable THolder<TKeepAliveHttpClient> HttpClient_; + + const ui32 TvmPort_; const TDuration TvmSocketTimeout_; const TDuration TvmConnectTimeout_; - - mutable TAutoEvent Event_; - mutable TAutoEvent Started_; - std::atomic_bool IsStopped_; - THolder<TThread> Thread_; - }; -} + + mutable TAutoEvent Event_; + mutable TAutoEvent Started_; + std::atomic_bool IsStopped_; + THolder<TThread> Thread_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/tool/meta_info.cpp b/library/cpp/tvmauth/client/misc/tool/meta_info.cpp index c99151ec6e..5d905b0cb8 100644 --- a/library/cpp/tvmauth/client/misc/tool/meta_info.cpp +++ b/library/cpp/tvmauth/client/misc/tool/meta_info.cpp @@ -1,200 +1,200 @@ -#include "meta_info.h" - -#include <library/cpp/json/json_reader.h> - -#include <util/string/builder.h> - -namespace NTvmAuth::NTvmTool { - TString TMetaInfo::TConfig::ToString() const { - TStringStream s; - s << "self_tvm_id=" << SelfTvmId << ", " - << "bb_env=" << BbEnv << ", " - << "dsts=["; - - for (const auto& pair : DstAliases) { - s << "(" << pair.first << ":" << pair.second << ")"; - } - - s << "]"; - - return std::move(s.Str()); - } - - TMetaInfo::TMetaInfo(TLoggerPtr logger) - : Logger_(std::move(logger)) - { - } - - TMetaInfo::TConfigPtr TMetaInfo::Init(TKeepAliveHttpClient& client, - const TClientSettings& settings) { - ApplySettings(settings); - - TryPing(client); - const TString metaString = Fetch(client); - if (Logger_) { - TStringStream s; - s << "Meta info fetched from " << settings.GetHostname() << ":" << settings.GetPort(); - Logger_->Debug(s.Str()); - } - - try { - Config_.Set(ParseMetaString(metaString, SelfAlias_)); - } catch (const yexception& e) { - ythrow TNonRetriableException() << "Malformed json from tvmtool: " << e.what(); - } - TConfigPtr cfg = Config_.Get(); - Y_ENSURE_EX(cfg, TNonRetriableException() << "Alias '" << SelfAlias_ << "' not found in meta info"); - - if (Logger_) { - Logger_->Info("Meta: " + cfg->ToString()); - } - - return cfg; - } - - TString TMetaInfo::GetRequestForTickets(const TConfig& config) { - Y_ENSURE(!config.DstAliases.empty()); - - TStringStream s; - s << "/tvm/tickets" - << "?src=" << config.SelfTvmId - << "&dsts="; - - for (const auto& pair : config.DstAliases) { - s << pair.second << ","; // avoid aliases - url-encoding required - } - s.Str().pop_back(); - - return s.Str(); - } - - bool TMetaInfo::TryUpdateConfig(TKeepAliveHttpClient& client) { - const TString metaString = Fetch(client); - - TConfigPtr config; - try { - config = ParseMetaString(metaString, SelfAlias_); - } catch (const yexception& e) { - ythrow TNonRetriableException() << "Malformed json from tvmtool: " << e.what(); - } - Y_ENSURE_EX(config, TNonRetriableException() << "Alias '" << SelfAlias_ << "' not found in meta info"); - - TConfigPtr oldConfig = Config_.Get(); - if (*config == *oldConfig) { - return false; - } - - if (Logger_) { - Logger_->Info(TStringBuilder() - << "Meta was updated. Old: (" << oldConfig->ToString() - << "). New: (" << config->ToString() << ")"); - } - - Config_ = config; - return true; - } - - void TMetaInfo::TryPing(TKeepAliveHttpClient& client) { - try { - TStringStream s; - TKeepAliveHttpClient::THttpCode code = client.DoGet("/tvm/ping", &s); - if (code < 200 || 300 <= code) { - throw yexception() << "(" << code << ") " << s.Str(); - } - } catch (const std::exception& e) { - ythrow TNonRetriableException() << "Failed to connect to tvmtool: " << e.what(); - } - } - - TString TMetaInfo::Fetch(TKeepAliveHttpClient& client) const { - TStringStream res; - TKeepAliveHttpClient::THttpCode code; - try { - code = client.DoGet("/tvm/private_api/__meta__", &res, AuthHeader_); - } catch (const std::exception& e) { - ythrow TRetriableException() << "Failed to fetch meta data from tvmtool: " << e.what(); - } - - if (code != 200) { - Y_ENSURE_EX(code != 404, - TNonRetriableException() << "Library does not support so old tvmtool. You need tvmtool>=1.1.0"); - - TStringStream err; - err << "Failed to fetch meta from tvmtool: " << client.GetHost() << ":" << client.GetPort() - << " (" << code << "): " << res.Str(); - Y_ENSURE_EX(!(500 <= code && code < 600), TRetriableException() << err.Str()); - ythrow TNonRetriableException() << err.Str(); - } - - return res.Str(); - } - - static TMetaInfo::TDstAliases::value_type ParsePair(const NJson::TJsonValue& val, const TString& meta) { - NJson::TJsonValue jAlias; - Y_ENSURE(val.GetValue("alias", &jAlias), meta); - Y_ENSURE(jAlias.IsString(), meta); - - NJson::TJsonValue jClientId; - Y_ENSURE(val.GetValue("client_id", &jClientId), meta); - Y_ENSURE(jClientId.IsInteger(), meta); - - return {jAlias.GetString(), jClientId.GetInteger()}; - } - - TMetaInfo::TConfigPtr TMetaInfo::ParseMetaString(const TString& meta, const TString& self) { - NJson::TJsonValue jDoc; - Y_ENSURE(NJson::ReadJsonTree(meta, &jDoc), meta); - - NJson::TJsonValue jEnv; - Y_ENSURE(jDoc.GetValue("bb_env", &jEnv), meta); - - NJson::TJsonValue jTenants; - Y_ENSURE(jDoc.GetValue("tenants", &jTenants), meta); - Y_ENSURE(jTenants.IsArray(), meta); - - for (const NJson::TJsonValue& jTen : jTenants.GetArray()) { - NJson::TJsonValue jSelf; - Y_ENSURE(jTen.GetValue("self", &jSelf), meta); - auto selfPair = ParsePair(jSelf, meta); - if (selfPair.first != self) { - continue; - } - - TConfigPtr config = std::make_shared<TConfig>(); - config->SelfTvmId = selfPair.second; - config->BbEnv = BbEnvFromString(jEnv.GetString(), meta); - - NJson::TJsonValue jDsts; - Y_ENSURE(jTen.GetValue("dsts", &jDsts), meta); - Y_ENSURE(jDsts.IsArray(), meta); - for (const NJson::TJsonValue& jDst : jDsts.GetArray()) { - config->DstAliases.insert(ParsePair(jDst, meta)); - } - - return config; - } - - return {}; - } - - void TMetaInfo::ApplySettings(const TClientSettings& settings) { - AuthHeader_ = {{"Authorization", settings.GetAuthToken()}}; - SelfAlias_ = settings.GetSelfAlias(); - } - - EBlackboxEnv TMetaInfo::BbEnvFromString(const TString& env, const TString& meta) { - if (env == "Prod") { - return EBlackboxEnv::Prod; - } else if (env == "Test") { - return EBlackboxEnv::Test; - } else if (env == "ProdYaTeam") { - return EBlackboxEnv::ProdYateam; - } else if (env == "TestYaTeam") { - return EBlackboxEnv::TestYateam; - } else if (env == "Stress") { - return EBlackboxEnv::Stress; - } - - ythrow yexception() << "'bb_env'=='" << env << "'. " << meta; - } -} +#include "meta_info.h" + +#include <library/cpp/json/json_reader.h> + +#include <util/string/builder.h> + +namespace NTvmAuth::NTvmTool { + TString TMetaInfo::TConfig::ToString() const { + TStringStream s; + s << "self_tvm_id=" << SelfTvmId << ", " + << "bb_env=" << BbEnv << ", " + << "dsts=["; + + for (const auto& pair : DstAliases) { + s << "(" << pair.first << ":" << pair.second << ")"; + } + + s << "]"; + + return std::move(s.Str()); + } + + TMetaInfo::TMetaInfo(TLoggerPtr logger) + : Logger_(std::move(logger)) + { + } + + TMetaInfo::TConfigPtr TMetaInfo::Init(TKeepAliveHttpClient& client, + const TClientSettings& settings) { + ApplySettings(settings); + + TryPing(client); + const TString metaString = Fetch(client); + if (Logger_) { + TStringStream s; + s << "Meta info fetched from " << settings.GetHostname() << ":" << settings.GetPort(); + Logger_->Debug(s.Str()); + } + + try { + Config_.Set(ParseMetaString(metaString, SelfAlias_)); + } catch (const yexception& e) { + ythrow TNonRetriableException() << "Malformed json from tvmtool: " << e.what(); + } + TConfigPtr cfg = Config_.Get(); + Y_ENSURE_EX(cfg, TNonRetriableException() << "Alias '" << SelfAlias_ << "' not found in meta info"); + + if (Logger_) { + Logger_->Info("Meta: " + cfg->ToString()); + } + + return cfg; + } + + TString TMetaInfo::GetRequestForTickets(const TConfig& config) { + Y_ENSURE(!config.DstAliases.empty()); + + TStringStream s; + s << "/tvm/tickets" + << "?src=" << config.SelfTvmId + << "&dsts="; + + for (const auto& pair : config.DstAliases) { + s << pair.second << ","; // avoid aliases - url-encoding required + } + s.Str().pop_back(); + + return s.Str(); + } + + bool TMetaInfo::TryUpdateConfig(TKeepAliveHttpClient& client) { + const TString metaString = Fetch(client); + + TConfigPtr config; + try { + config = ParseMetaString(metaString, SelfAlias_); + } catch (const yexception& e) { + ythrow TNonRetriableException() << "Malformed json from tvmtool: " << e.what(); + } + Y_ENSURE_EX(config, TNonRetriableException() << "Alias '" << SelfAlias_ << "' not found in meta info"); + + TConfigPtr oldConfig = Config_.Get(); + if (*config == *oldConfig) { + return false; + } + + if (Logger_) { + Logger_->Info(TStringBuilder() + << "Meta was updated. Old: (" << oldConfig->ToString() + << "). New: (" << config->ToString() << ")"); + } + + Config_ = config; + return true; + } + + void TMetaInfo::TryPing(TKeepAliveHttpClient& client) { + try { + TStringStream s; + TKeepAliveHttpClient::THttpCode code = client.DoGet("/tvm/ping", &s); + if (code < 200 || 300 <= code) { + throw yexception() << "(" << code << ") " << s.Str(); + } + } catch (const std::exception& e) { + ythrow TNonRetriableException() << "Failed to connect to tvmtool: " << e.what(); + } + } + + TString TMetaInfo::Fetch(TKeepAliveHttpClient& client) const { + TStringStream res; + TKeepAliveHttpClient::THttpCode code; + try { + code = client.DoGet("/tvm/private_api/__meta__", &res, AuthHeader_); + } catch (const std::exception& e) { + ythrow TRetriableException() << "Failed to fetch meta data from tvmtool: " << e.what(); + } + + if (code != 200) { + Y_ENSURE_EX(code != 404, + TNonRetriableException() << "Library does not support so old tvmtool. You need tvmtool>=1.1.0"); + + TStringStream err; + err << "Failed to fetch meta from tvmtool: " << client.GetHost() << ":" << client.GetPort() + << " (" << code << "): " << res.Str(); + Y_ENSURE_EX(!(500 <= code && code < 600), TRetriableException() << err.Str()); + ythrow TNonRetriableException() << err.Str(); + } + + return res.Str(); + } + + static TMetaInfo::TDstAliases::value_type ParsePair(const NJson::TJsonValue& val, const TString& meta) { + NJson::TJsonValue jAlias; + Y_ENSURE(val.GetValue("alias", &jAlias), meta); + Y_ENSURE(jAlias.IsString(), meta); + + NJson::TJsonValue jClientId; + Y_ENSURE(val.GetValue("client_id", &jClientId), meta); + Y_ENSURE(jClientId.IsInteger(), meta); + + return {jAlias.GetString(), jClientId.GetInteger()}; + } + + TMetaInfo::TConfigPtr TMetaInfo::ParseMetaString(const TString& meta, const TString& self) { + NJson::TJsonValue jDoc; + Y_ENSURE(NJson::ReadJsonTree(meta, &jDoc), meta); + + NJson::TJsonValue jEnv; + Y_ENSURE(jDoc.GetValue("bb_env", &jEnv), meta); + + NJson::TJsonValue jTenants; + Y_ENSURE(jDoc.GetValue("tenants", &jTenants), meta); + Y_ENSURE(jTenants.IsArray(), meta); + + for (const NJson::TJsonValue& jTen : jTenants.GetArray()) { + NJson::TJsonValue jSelf; + Y_ENSURE(jTen.GetValue("self", &jSelf), meta); + auto selfPair = ParsePair(jSelf, meta); + if (selfPair.first != self) { + continue; + } + + TConfigPtr config = std::make_shared<TConfig>(); + config->SelfTvmId = selfPair.second; + config->BbEnv = BbEnvFromString(jEnv.GetString(), meta); + + NJson::TJsonValue jDsts; + Y_ENSURE(jTen.GetValue("dsts", &jDsts), meta); + Y_ENSURE(jDsts.IsArray(), meta); + for (const NJson::TJsonValue& jDst : jDsts.GetArray()) { + config->DstAliases.insert(ParsePair(jDst, meta)); + } + + return config; + } + + return {}; + } + + void TMetaInfo::ApplySettings(const TClientSettings& settings) { + AuthHeader_ = {{"Authorization", settings.GetAuthToken()}}; + SelfAlias_ = settings.GetSelfAlias(); + } + + EBlackboxEnv TMetaInfo::BbEnvFromString(const TString& env, const TString& meta) { + if (env == "Prod") { + return EBlackboxEnv::Prod; + } else if (env == "Test") { + return EBlackboxEnv::Test; + } else if (env == "ProdYaTeam") { + return EBlackboxEnv::ProdYateam; + } else if (env == "TestYaTeam") { + return EBlackboxEnv::TestYateam; + } else if (env == "Stress") { + return EBlackboxEnv::Stress; + } + + ythrow yexception() << "'bb_env'=='" << env << "'. " << meta; + } +} diff --git a/library/cpp/tvmauth/client/misc/tool/meta_info.h b/library/cpp/tvmauth/client/misc/tool/meta_info.h index 659c8f677f..c4b9688e39 100644 --- a/library/cpp/tvmauth/client/misc/tool/meta_info.h +++ b/library/cpp/tvmauth/client/misc/tool/meta_info.h @@ -1,67 +1,67 @@ -#pragma once - -#include "settings.h" - -#include <library/cpp/tvmauth/client/misc/utils.h> - -#include <library/cpp/tvmauth/client/logger.h> - -#include <library/cpp/http/simple/http_client.h> - -namespace NTvmAuth::NTvmTool { - class TMetaInfo { - public: - using TDstAliases = THashMap<TClientSettings::TAlias, TTvmId>; - - struct TConfig { - TTvmId SelfTvmId = 0; - EBlackboxEnv BbEnv = EBlackboxEnv::Prod; - TDstAliases DstAliases; - - bool AreTicketsRequired() const { - return !DstAliases.empty(); - } - - TString ToString() const; - - bool operator==(const TConfig& c) const { - return SelfTvmId == c.SelfTvmId && - BbEnv == c.BbEnv && - DstAliases == c.DstAliases; - } - }; - using TConfigPtr = std::shared_ptr<TConfig>; - - public: - TMetaInfo(TLoggerPtr logger); - - TConfigPtr Init(TKeepAliveHttpClient& client, - const TClientSettings& settings); - - static TString GetRequestForTickets(const TMetaInfo::TConfig& config); - - const TKeepAliveHttpClient::THeaders& GetAuthHeader() const { - return AuthHeader_; - } - - TConfigPtr GetConfig() const { - return Config_.Get(); - } - - bool TryUpdateConfig(TKeepAliveHttpClient& client); - - protected: - void TryPing(TKeepAliveHttpClient& client); - TString Fetch(TKeepAliveHttpClient& client) const; - static TConfigPtr ParseMetaString(const TString& meta, const TString& self); - void ApplySettings(const TClientSettings& settings); - static EBlackboxEnv BbEnvFromString(const TString& env, const TString& meta); - - protected: - NUtils::TProtectedValue<TConfigPtr> Config_; - TKeepAliveHttpClient::THeaders AuthHeader_; - - TLoggerPtr Logger_; - TString SelfAlias_; - }; -} +#pragma once + +#include "settings.h" + +#include <library/cpp/tvmauth/client/misc/utils.h> + +#include <library/cpp/tvmauth/client/logger.h> + +#include <library/cpp/http/simple/http_client.h> + +namespace NTvmAuth::NTvmTool { + class TMetaInfo { + public: + using TDstAliases = THashMap<TClientSettings::TAlias, TTvmId>; + + struct TConfig { + TTvmId SelfTvmId = 0; + EBlackboxEnv BbEnv = EBlackboxEnv::Prod; + TDstAliases DstAliases; + + bool AreTicketsRequired() const { + return !DstAliases.empty(); + } + + TString ToString() const; + + bool operator==(const TConfig& c) const { + return SelfTvmId == c.SelfTvmId && + BbEnv == c.BbEnv && + DstAliases == c.DstAliases; + } + }; + using TConfigPtr = std::shared_ptr<TConfig>; + + public: + TMetaInfo(TLoggerPtr logger); + + TConfigPtr Init(TKeepAliveHttpClient& client, + const TClientSettings& settings); + + static TString GetRequestForTickets(const TMetaInfo::TConfig& config); + + const TKeepAliveHttpClient::THeaders& GetAuthHeader() const { + return AuthHeader_; + } + + TConfigPtr GetConfig() const { + return Config_.Get(); + } + + bool TryUpdateConfig(TKeepAliveHttpClient& client); + + protected: + void TryPing(TKeepAliveHttpClient& client); + TString Fetch(TKeepAliveHttpClient& client) const; + static TConfigPtr ParseMetaString(const TString& meta, const TString& self); + void ApplySettings(const TClientSettings& settings); + static EBlackboxEnv BbEnvFromString(const TString& env, const TString& meta); + + protected: + NUtils::TProtectedValue<TConfigPtr> Config_; + TKeepAliveHttpClient::THeaders AuthHeader_; + + TLoggerPtr Logger_; + TString SelfAlias_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/tool/settings.cpp b/library/cpp/tvmauth/client/misc/tool/settings.cpp index 174a8ef4e8..894501f19d 100644 --- a/library/cpp/tvmauth/client/misc/tool/settings.cpp +++ b/library/cpp/tvmauth/client/misc/tool/settings.cpp @@ -1,37 +1,37 @@ -#include "settings.h" - -#include <library/cpp/string_utils/url/url.h> - -#include <util/system/env.h> - -namespace NTvmAuth::NTvmTool { - TClientSettings::TClientSettings(const TAlias& selfAias) - : SelfAias_(selfAias) - , Hostname_("localhost") - , Port_(1) +#include "settings.h" + +#include <library/cpp/string_utils/url/url.h> + +#include <util/system/env.h> + +namespace NTvmAuth::NTvmTool { + TClientSettings::TClientSettings(const TAlias& selfAias) + : SelfAias_(selfAias) + , Hostname_("localhost") + , Port_(1) , SocketTimeout_(TDuration::Seconds(5)) , ConnectTimeout_(TDuration::Seconds(30)) - { - AuthToken_ = GetEnv("TVMTOOL_LOCAL_AUTHTOKEN"); - if (!AuthToken_) { - AuthToken_ = GetEnv("QLOUD_TVM_TOKEN"); - } - TStringBuf auth(AuthToken_); - FixSpaces(auth); - AuthToken_ = auth; - - const TString url = GetEnv("DEPLOY_TVM_TOOL_URL"); - if (url) { - TStringBuf scheme, host; - TryGetSchemeHostAndPort(url, scheme, host, Port_); - } - - Y_ENSURE_EX(SelfAias_, TBrokenTvmClientSettings() << "Alias for your TVM client cannot be empty"); - } - - void TClientSettings::FixSpaces(TStringBuf& str) { - while (str && isspace(str.back())) { - str.Chop(1); - } - } -} + { + AuthToken_ = GetEnv("TVMTOOL_LOCAL_AUTHTOKEN"); + if (!AuthToken_) { + AuthToken_ = GetEnv("QLOUD_TVM_TOKEN"); + } + TStringBuf auth(AuthToken_); + FixSpaces(auth); + AuthToken_ = auth; + + const TString url = GetEnv("DEPLOY_TVM_TOOL_URL"); + if (url) { + TStringBuf scheme, host; + TryGetSchemeHostAndPort(url, scheme, host, Port_); + } + + Y_ENSURE_EX(SelfAias_, TBrokenTvmClientSettings() << "Alias for your TVM client cannot be empty"); + } + + void TClientSettings::FixSpaces(TStringBuf& str) { + while (str && isspace(str.back())) { + str.Chop(1); + } + } +} diff --git a/library/cpp/tvmauth/client/misc/tool/settings.h b/library/cpp/tvmauth/client/misc/tool/settings.h index 0510c8b52e..63255ed090 100644 --- a/library/cpp/tvmauth/client/misc/tool/settings.h +++ b/library/cpp/tvmauth/client/misc/tool/settings.h @@ -1,58 +1,58 @@ -#pragma once - -#include <library/cpp/tvmauth/client/misc/settings.h> - -#include <library/cpp/tvmauth/client/exception.h> - -#include <library/cpp/tvmauth/checked_user_ticket.h> - +#pragma once + +#include <library/cpp/tvmauth/client/misc/settings.h> + +#include <library/cpp/tvmauth/client/exception.h> + +#include <library/cpp/tvmauth/checked_user_ticket.h> + #include <util/datetime/base.h> -#include <util/generic/maybe.h> - -namespace NTvmAuth::NTvmTool { - /** - * Uses local http-interface to get state: http://localhost/tvm/. - * This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). - * See more: https://wiki.yandex-team.ru/passport/tvm2/qloud/. - * - * Most part of settings will be fetched from tvmtool on start of client. - * You need to use aliases for TVM-clients (src and dst) which you specified in tvmtool or Qloud/YP interface - */ - class TClientSettings: public NTvmAuth::TClientSettings { - public: - /*! - * Sets default values: - * - hostname == "localhost" - * - port detected with env["DEPLOY_TVM_TOOL_URL"] (provided with Yandex.Deploy), - * otherwise port == 1 (it is ok for Qloud) - * - authToken: env["TVMTOOL_LOCAL_AUTHTOKEN"] (provided with Yandex.Deploy), - * otherwise env["QLOUD_TVM_TOKEN"] (provided with Qloud) - * - * AuthToken is protection from SSRF. - * - * @param selfAias - alias for your TVM client, which you specified in tvmtool or YD interface - */ - TClientSettings(const TAlias& selfAias); - - /*! - * Look at comment for ctor - * @param port - */ - TClientSettings& SetPort(ui16 port) { - Port_ = port; - return *this; - } - - /*! - * Default value: hostname == "localhost" - * @param hostname - */ - TClientSettings& SetHostname(const TString& hostname) { - Y_ENSURE_EX(hostname, TBrokenTvmClientSettings() << "Hostname cannot be empty"); - Hostname_ = hostname; - return *this; - } - +#include <util/generic/maybe.h> + +namespace NTvmAuth::NTvmTool { + /** + * Uses local http-interface to get state: http://localhost/tvm/. + * This interface can be provided with tvmtool (local daemon) or Qloud/YP (local http api in container). + * See more: https://wiki.yandex-team.ru/passport/tvm2/qloud/. + * + * Most part of settings will be fetched from tvmtool on start of client. + * You need to use aliases for TVM-clients (src and dst) which you specified in tvmtool or Qloud/YP interface + */ + class TClientSettings: public NTvmAuth::TClientSettings { + public: + /*! + * Sets default values: + * - hostname == "localhost" + * - port detected with env["DEPLOY_TVM_TOOL_URL"] (provided with Yandex.Deploy), + * otherwise port == 1 (it is ok for Qloud) + * - authToken: env["TVMTOOL_LOCAL_AUTHTOKEN"] (provided with Yandex.Deploy), + * otherwise env["QLOUD_TVM_TOKEN"] (provided with Qloud) + * + * AuthToken is protection from SSRF. + * + * @param selfAias - alias for your TVM client, which you specified in tvmtool or YD interface + */ + TClientSettings(const TAlias& selfAias); + + /*! + * Look at comment for ctor + * @param port + */ + TClientSettings& SetPort(ui16 port) { + Port_ = port; + return *this; + } + + /*! + * Default value: hostname == "localhost" + * @param hostname + */ + TClientSettings& SetHostname(const TString& hostname) { + Y_ENSURE_EX(hostname, TBrokenTvmClientSettings() << "Hostname cannot be empty"); + Hostname_ = hostname; + return *this; + } + TClientSettings& SetSocketTimeout(TDuration socketTimeout) { SocketTimeout_ = socketTimeout; return *this; @@ -63,46 +63,46 @@ namespace NTvmAuth::NTvmTool { return *this; } - /*! - * Look at comment for ctor - * @param token - */ - TClientSettings& SetAuthToken(TStringBuf token) { - FixSpaces(token); - Y_ENSURE_EX(token, TBrokenTvmClientSettings() << "Auth token cannot be empty"); - AuthToken_ = token; - return *this; - } - - /*! - * Blackbox environmet is provided by tvmtool for client. - * You can override it for your purpose with limitations: - * (env from tvmtool) -> (override) - * - Prod/ProdYateam -> Prod/ProdYateam - * - Test/TestYateam -> Test/TestYateam - * - Stress -> Stress - * - * You can contact tvm-dev@yandex-team.ru if limitations are too strict - * @param env - */ - TClientSettings& OverrideBlackboxEnv(EBlackboxEnv env) { - BbEnv_ = env; - return *this; - } - - public: // for TAsyncUpdaterBase - const TAlias& GetSelfAlias() const { - return SelfAias_; - } - - const TString& GetHostname() const { - return Hostname_; - } - - ui16 GetPort() const { - return Port_; - } - + /*! + * Look at comment for ctor + * @param token + */ + TClientSettings& SetAuthToken(TStringBuf token) { + FixSpaces(token); + Y_ENSURE_EX(token, TBrokenTvmClientSettings() << "Auth token cannot be empty"); + AuthToken_ = token; + return *this; + } + + /*! + * Blackbox environmet is provided by tvmtool for client. + * You can override it for your purpose with limitations: + * (env from tvmtool) -> (override) + * - Prod/ProdYateam -> Prod/ProdYateam + * - Test/TestYateam -> Test/TestYateam + * - Stress -> Stress + * + * You can contact tvm-dev@yandex-team.ru if limitations are too strict + * @param env + */ + TClientSettings& OverrideBlackboxEnv(EBlackboxEnv env) { + BbEnv_ = env; + return *this; + } + + public: // for TAsyncUpdaterBase + const TAlias& GetSelfAlias() const { + return SelfAias_; + } + + const TString& GetHostname() const { + return Hostname_; + } + + ui16 GetPort() const { + return Port_; + } + TDuration GetSocketTimeout() const { return SocketTimeout_; } @@ -111,27 +111,27 @@ namespace NTvmAuth::NTvmTool { return ConnectTimeout_; } - const TString& GetAuthToken() const { - Y_ENSURE_EX(AuthToken_, TBrokenTvmClientSettings() - << "Auth token cannot be empty. " - << "Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); - return AuthToken_; - } - - TMaybe<EBlackboxEnv> GetOverridedBlackboxEnv() const { - return BbEnv_; - } - - private: - void FixSpaces(TStringBuf& str); - - private: - TAlias SelfAias_; - TString Hostname_; - ui16 Port_; + const TString& GetAuthToken() const { + Y_ENSURE_EX(AuthToken_, TBrokenTvmClientSettings() + << "Auth token cannot be empty. " + << "Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); + return AuthToken_; + } + + TMaybe<EBlackboxEnv> GetOverridedBlackboxEnv() const { + return BbEnv_; + } + + private: + void FixSpaces(TStringBuf& str); + + private: + TAlias SelfAias_; + TString Hostname_; + ui16 Port_; TDuration SocketTimeout_; TDuration ConnectTimeout_; - TString AuthToken_; - TMaybe<EBlackboxEnv> BbEnv_; - }; -} + TString AuthToken_; + TMaybe<EBlackboxEnv> BbEnv_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/tool/threaded_updater.cpp b/library/cpp/tvmauth/client/misc/tool/threaded_updater.cpp index c811e2a52e..8490f7ab54 100644 --- a/library/cpp/tvmauth/client/misc/tool/threaded_updater.cpp +++ b/library/cpp/tvmauth/client/misc/tool/threaded_updater.cpp @@ -1,331 +1,331 @@ -#include "threaded_updater.h" - -#include <library/cpp/tvmauth/client/misc/utils.h> - -#include <library/cpp/json/json_reader.h> - -#include <util/generic/hash_set.h> -#include <util/stream/str.h> -#include <util/string/ascii.h> -#include <util/string/builder.h> -#include <util/string/cast.h> - -namespace NTvmAuth::NTvmTool { - TAsyncUpdaterPtr TThreadedUpdater::Create(const TClientSettings& settings, TLoggerPtr logger) { - Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); - THolder<TThreadedUpdater> p(new TThreadedUpdater( - settings.GetHostname(), - settings.GetPort(), - settings.GetSocketTimeout(), - settings.GetConnectTimeout(), - std::move(logger))); - p->Init(settings); - p->StartWorker(); - return p.Release(); - } - - TThreadedUpdater::~TThreadedUpdater() { - StopWorker(); // Required here to avoid using of deleted members - } - - TClientStatus TThreadedUpdater::GetStatus() const { - const TClientStatus::ECode state = GetState(); - return TClientStatus(state, GetLastError(state == TClientStatus::Ok)); - } - - TClientStatus::ECode TThreadedUpdater::GetState() const { - const TInstant now = TInstant::Now(); - const TMetaInfo::TConfigPtr config = MetaInfo_.GetConfig(); - - if ((config->AreTicketsRequired() && AreServiceTicketsInvalid(now)) || ArePublicKeysInvalid(now)) { - return TClientStatus::Error; - } - - if (config->AreTicketsRequired()) { - if (!GetCachedServiceTickets() || config->DstAliases.size() > GetCachedServiceTickets()->TicketsByAlias.size()) { - return TClientStatus::Error; - } - } - - const TDuration st = now - GetUpdateTimeOfServiceTickets(); - const TDuration pk = now - GetUpdateTimeOfPublicKeys(); - - if ((config->AreTicketsRequired() && st > ServiceTicketsDurations_.Expiring) || pk > PublicKeysDurations_.Expiring) { - return TClientStatus::Warning; - } - - if (IsConfigWarnTime()) { - return TClientStatus::Warning; - } - - return TClientStatus::Ok; - } - +#include "threaded_updater.h" + +#include <library/cpp/tvmauth/client/misc/utils.h> + +#include <library/cpp/json/json_reader.h> + +#include <util/generic/hash_set.h> +#include <util/stream/str.h> +#include <util/string/ascii.h> +#include <util/string/builder.h> +#include <util/string/cast.h> + +namespace NTvmAuth::NTvmTool { + TAsyncUpdaterPtr TThreadedUpdater::Create(const TClientSettings& settings, TLoggerPtr logger) { + Y_ENSURE_EX(logger, TNonRetriableException() << "Logger is required"); + THolder<TThreadedUpdater> p(new TThreadedUpdater( + settings.GetHostname(), + settings.GetPort(), + settings.GetSocketTimeout(), + settings.GetConnectTimeout(), + std::move(logger))); + p->Init(settings); + p->StartWorker(); + return p.Release(); + } + + TThreadedUpdater::~TThreadedUpdater() { + StopWorker(); // Required here to avoid using of deleted members + } + + TClientStatus TThreadedUpdater::GetStatus() const { + const TClientStatus::ECode state = GetState(); + return TClientStatus(state, GetLastError(state == TClientStatus::Ok)); + } + + TClientStatus::ECode TThreadedUpdater::GetState() const { + const TInstant now = TInstant::Now(); + const TMetaInfo::TConfigPtr config = MetaInfo_.GetConfig(); + + if ((config->AreTicketsRequired() && AreServiceTicketsInvalid(now)) || ArePublicKeysInvalid(now)) { + return TClientStatus::Error; + } + + if (config->AreTicketsRequired()) { + if (!GetCachedServiceTickets() || config->DstAliases.size() > GetCachedServiceTickets()->TicketsByAlias.size()) { + return TClientStatus::Error; + } + } + + const TDuration st = now - GetUpdateTimeOfServiceTickets(); + const TDuration pk = now - GetUpdateTimeOfPublicKeys(); + + if ((config->AreTicketsRequired() && st > ServiceTicketsDurations_.Expiring) || pk > PublicKeysDurations_.Expiring) { + return TClientStatus::Warning; + } + + if (IsConfigWarnTime()) { + return TClientStatus::Warning; + } + + return TClientStatus::Ok; + } + TThreadedUpdater::TThreadedUpdater(const TString& host, ui16 port, TDuration socketTimeout, TDuration connectTimeout, TLoggerPtr logger) - : TThreadedUpdaterBase(TDuration::Seconds(5), logger, host, port, socketTimeout, connectTimeout) - , MetaInfo_(logger) - , ConfigWarnDelay_(TDuration::Seconds(30)) - { - ServiceTicketsDurations_.RefreshPeriod = TDuration::Minutes(10); - PublicKeysDurations_.RefreshPeriod = TDuration::Minutes(10); - } - - void TThreadedUpdater::Init(const TClientSettings& settings) { - const TMetaInfo::TConfigPtr config = MetaInfo_.Init(GetClient(), settings); - LastVisitForConfig_ = TInstant::Now(); - - SetBbEnv(config->BbEnv, settings.GetOverridedBlackboxEnv()); - if (settings.GetOverridedBlackboxEnv()) { - LogInfo(TStringBuilder() - << "Meta: override blackbox env: " << config->BbEnv - << "->" << *settings.GetOverridedBlackboxEnv()); - } - - ui8 tries = 3; - do { - UpdateState(); - } while (!IsEverythingOk(*config) && --tries > 0); - - if (!IsEverythingOk(*config)) { - ThrowLastError(); - } - } - - void TThreadedUpdater::UpdateState() { - bool wasUpdated = false; - try { - wasUpdated = MetaInfo_.TryUpdateConfig(GetClient()); - LastVisitForConfig_ = TInstant::Now(); - ClearError(EScope::TvmtoolConfig); - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::TvmtoolConfig, e.what()); - LogWarning(TStringBuilder() << "Error while fetching of tvmtool config: " << e.what()); - } - if (IsConfigWarnTime()) { - LogError(TStringBuilder() << "Tvmtool config have not been refreshed for too long period"); - } - - TMetaInfo::TConfigPtr config = MetaInfo_.GetConfig(); - - if (wasUpdated || IsTimeToUpdateServiceTickets(*config, LastVisitForServiceTickets_)) { - try { - const TInstant updateTime = UpdateServiceTickets(*config); - SetUpdateTimeOfServiceTickets(updateTime); - LastVisitForServiceTickets_ = TInstant::Now(); - - if (AreServiceTicketsOk(*config)) { - ClearError(EScope::ServiceTickets); - } - LogDebug(TStringBuilder() << "Tickets fetched from tvmtool: " << updateTime); - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::ServiceTickets, e.what()); - LogWarning(TStringBuilder() << "Error while fetching of tickets: " << e.what()); - } - - if (TInstant::Now() - GetUpdateTimeOfServiceTickets() > ServiceTicketsDurations_.Expiring) { - LogError("Service tickets have not been refreshed for too long period"); - } - } - - if (wasUpdated || IsTimeToUpdatePublicKeys(LastVisitForPublicKeys_)) { - try { - const TInstant updateTime = UpdateKeys(*config); - SetUpdateTimeOfPublicKeys(updateTime); - LastVisitForPublicKeys_ = TInstant::Now(); - - if (ArePublicKeysOk()) { - ClearError(EScope::PublicKeys); - } - LogDebug(TStringBuilder() << "Public keys fetched from tvmtool: " << updateTime); - } catch (const std::exception& e) { - ProcessError(EType::Retriable, EScope::PublicKeys, e.what()); - LogWarning(TStringBuilder() << "Error while fetching of public keys: " << e.what()); - } - - if (TInstant::Now() - GetUpdateTimeOfPublicKeys() > PublicKeysDurations_.Expiring) { - LogError("Public keys have not been refreshed for too long period"); - } - } - } - - TInstant TThreadedUpdater::UpdateServiceTickets(const TMetaInfo::TConfig& config) { - const std::pair<TString, TInstant> tickets = FetchServiceTickets(config); - - if (TInstant::Now() - tickets.second >= ServiceTicketsDurations_.Invalid) { - throw yexception() << "Service tickets are too old: " << tickets.second; - } - - TPairTicketsErrors p = ParseFetchTicketsResponse(tickets.first, config.DstAliases); - SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(std::move(p.Tickets), - std::move(p.Errors), - config.DstAliases)); - return tickets.second; - } - - std::pair<TString, TInstant> TThreadedUpdater::FetchServiceTickets(const TMetaInfo::TConfig& config) const { - TStringStream s; - THttpHeaders headers; - - const TString request = TMetaInfo::GetRequestForTickets(config); - auto code = GetClient().DoGet(request, &s, MetaInfo_.GetAuthHeader(), &headers); - Y_ENSURE(code == 200, ProcessHttpError(EScope::ServiceTickets, request, code, s.Str())); - - return {s.Str(), GetBirthTimeFromResponse(headers, "tickets")}; - } - - static THashSet<TTvmId> GetAllTvmIds(const TMetaInfo::TDstAliases& dsts) { - THashSet<TTvmId> res; - res.reserve(dsts.size()); - - for (const auto& pair : dsts) { - res.insert(pair.second); - } - - return res; - } - - TAsyncUpdaterBase::TPairTicketsErrors TThreadedUpdater::ParseFetchTicketsResponse(const TString& resp, - const TMetaInfo::TDstAliases& dsts) const { - const THashSet<TTvmId> allTvmIds = GetAllTvmIds(dsts); - - TServiceTickets::TMapIdStr tickets; - TServiceTickets::TMapIdStr errors; - - auto procErr = [this](const TString& msg) { - ProcessError(EType::NonRetriable, EScope::ServiceTickets, msg); - LogError(msg); - }; - - NJson::TJsonValue doc; - Y_ENSURE(NJson::ReadJsonTree(resp, &doc), "Invalid json from tvmtool: " << resp); - - for (const auto& pair : doc.GetMap()) { - NJson::TJsonValue tvmId; - unsigned long long tvmIdNum = 0; - - if (!pair.second.GetValue("tvm_id", &tvmId) || - !tvmId.GetUInteger(&tvmIdNum)) { - procErr(TStringBuilder() - << "Failed to get 'tvm_id' from key, should never happend '" - << pair.first << "': " << resp); - continue; - } - - if (!allTvmIds.contains(tvmIdNum)) { - continue; - } - - NJson::TJsonValue val; - if (!pair.second.GetValue("ticket", &val)) { - TString err; - if (pair.second.GetValue("error", &val)) { - err = val.GetString(); - } else { - err = "Failed to get 'ticket' and 'error', should never happend: " + pair.first; - } - - procErr(TStringBuilder() - << "Failed to get ServiceTicket for " << pair.first - << " (" << tvmIdNum << "): " << err); - - errors.insert({tvmIdNum, std::move(err)}); - continue; - } - - tickets.insert({tvmIdNum, val.GetString()}); - } - - // This work-around is required because of bug in old verions of tvmtool: PASSP-24829 - for (const auto& pair : dsts) { - if (!tickets.contains(pair.second) && !errors.contains(pair.second)) { - TString err = "Missing tvm_id in response, should never happend: " + pair.first; - - procErr(TStringBuilder() - << "Failed to get ServiceTicket for " << pair.first - << " (" << pair.second << "): " << err); - - errors.emplace(pair.second, std::move(err)); - } - } - - return {std::move(tickets), std::move(errors)}; - } - - TInstant TThreadedUpdater::UpdateKeys(const TMetaInfo::TConfig& config) { - const std::pair<TString, TInstant> keys = FetchPublicKeys(); - - if (TInstant::Now() - keys.second >= PublicKeysDurations_.Invalid) { - throw yexception() << "Public keys are too old: " << keys.second; - } - - SetServiceContext(MakeIntrusiveConst<TServiceContext>( - TServiceContext::CheckingFactory(config.SelfTvmId, keys.first))); - SetUserContext(keys.first); - - return keys.second; - } - - std::pair<TString, TInstant> TThreadedUpdater::FetchPublicKeys() const { - TStringStream s; - THttpHeaders headers; - - auto code = GetClient().DoGet("/tvm/keys", &s, MetaInfo_.GetAuthHeader(), &headers); - Y_ENSURE(code == 200, ProcessHttpError(EScope::PublicKeys, "/tvm/keys", code, s.Str())); - - return {s.Str(), GetBirthTimeFromResponse(headers, "public keys")}; - } - - TInstant TThreadedUpdater::GetBirthTimeFromResponse(const THttpHeaders& headers, TStringBuf errMsg) { - auto it = std::find_if(headers.begin(), - headers.end(), - [](const THttpInputHeader& h) { - return AsciiEqualsIgnoreCase(h.Name(), "X-Ya-Tvmtool-Data-Birthtime"); - }); - Y_ENSURE(it != headers.end(), "Failed to fetch bithtime of " << errMsg << " from tvmtool"); - - ui64 time = 0; - Y_ENSURE(TryIntFromString<10>(it->Value(), time), - "Bithtime of " << errMsg << " from tvmtool must be unixtime. Got: " << it->Value()); - - return TInstant::Seconds(time); - } - - bool TThreadedUpdater::IsTimeToUpdateServiceTickets(const TMetaInfo::TConfig& config, - TInstant lastUpdate) const { - return config.AreTicketsRequired() && - TInstant::Now() - lastUpdate > ServiceTicketsDurations_.RefreshPeriod; - } - - bool TThreadedUpdater::IsTimeToUpdatePublicKeys(TInstant lastUpdate) const { - return TInstant::Now() - lastUpdate > PublicKeysDurations_.RefreshPeriod; - } - - bool TThreadedUpdater::IsEverythingOk(const TMetaInfo::TConfig& config) const { - return AreServiceTicketsOk(config) && ArePublicKeysOk(); - } - - bool TThreadedUpdater::AreServiceTicketsOk(const TMetaInfo::TConfig& config) const { - return AreServiceTicketsOk(config.DstAliases.size()); - } - - bool TThreadedUpdater::AreServiceTicketsOk(size_t requiredCount) const { - if (requiredCount == 0) { - return true; - } - - auto c = GetCachedServiceTickets(); - return c && c->TicketsByAlias.size() == requiredCount; - } - - bool TThreadedUpdater::ArePublicKeysOk() const { - return GetCachedServiceContext() && GetCachedUserContext(); - } - - bool TThreadedUpdater::IsConfigWarnTime() const { - return LastVisitForConfig_ + ConfigWarnDelay_ < TInstant::Now(); - } - - void TThreadedUpdater::Worker() { - UpdateState(); - } -} + : TThreadedUpdaterBase(TDuration::Seconds(5), logger, host, port, socketTimeout, connectTimeout) + , MetaInfo_(logger) + , ConfigWarnDelay_(TDuration::Seconds(30)) + { + ServiceTicketsDurations_.RefreshPeriod = TDuration::Minutes(10); + PublicKeysDurations_.RefreshPeriod = TDuration::Minutes(10); + } + + void TThreadedUpdater::Init(const TClientSettings& settings) { + const TMetaInfo::TConfigPtr config = MetaInfo_.Init(GetClient(), settings); + LastVisitForConfig_ = TInstant::Now(); + + SetBbEnv(config->BbEnv, settings.GetOverridedBlackboxEnv()); + if (settings.GetOverridedBlackboxEnv()) { + LogInfo(TStringBuilder() + << "Meta: override blackbox env: " << config->BbEnv + << "->" << *settings.GetOverridedBlackboxEnv()); + } + + ui8 tries = 3; + do { + UpdateState(); + } while (!IsEverythingOk(*config) && --tries > 0); + + if (!IsEverythingOk(*config)) { + ThrowLastError(); + } + } + + void TThreadedUpdater::UpdateState() { + bool wasUpdated = false; + try { + wasUpdated = MetaInfo_.TryUpdateConfig(GetClient()); + LastVisitForConfig_ = TInstant::Now(); + ClearError(EScope::TvmtoolConfig); + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::TvmtoolConfig, e.what()); + LogWarning(TStringBuilder() << "Error while fetching of tvmtool config: " << e.what()); + } + if (IsConfigWarnTime()) { + LogError(TStringBuilder() << "Tvmtool config have not been refreshed for too long period"); + } + + TMetaInfo::TConfigPtr config = MetaInfo_.GetConfig(); + + if (wasUpdated || IsTimeToUpdateServiceTickets(*config, LastVisitForServiceTickets_)) { + try { + const TInstant updateTime = UpdateServiceTickets(*config); + SetUpdateTimeOfServiceTickets(updateTime); + LastVisitForServiceTickets_ = TInstant::Now(); + + if (AreServiceTicketsOk(*config)) { + ClearError(EScope::ServiceTickets); + } + LogDebug(TStringBuilder() << "Tickets fetched from tvmtool: " << updateTime); + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::ServiceTickets, e.what()); + LogWarning(TStringBuilder() << "Error while fetching of tickets: " << e.what()); + } + + if (TInstant::Now() - GetUpdateTimeOfServiceTickets() > ServiceTicketsDurations_.Expiring) { + LogError("Service tickets have not been refreshed for too long period"); + } + } + + if (wasUpdated || IsTimeToUpdatePublicKeys(LastVisitForPublicKeys_)) { + try { + const TInstant updateTime = UpdateKeys(*config); + SetUpdateTimeOfPublicKeys(updateTime); + LastVisitForPublicKeys_ = TInstant::Now(); + + if (ArePublicKeysOk()) { + ClearError(EScope::PublicKeys); + } + LogDebug(TStringBuilder() << "Public keys fetched from tvmtool: " << updateTime); + } catch (const std::exception& e) { + ProcessError(EType::Retriable, EScope::PublicKeys, e.what()); + LogWarning(TStringBuilder() << "Error while fetching of public keys: " << e.what()); + } + + if (TInstant::Now() - GetUpdateTimeOfPublicKeys() > PublicKeysDurations_.Expiring) { + LogError("Public keys have not been refreshed for too long period"); + } + } + } + + TInstant TThreadedUpdater::UpdateServiceTickets(const TMetaInfo::TConfig& config) { + const std::pair<TString, TInstant> tickets = FetchServiceTickets(config); + + if (TInstant::Now() - tickets.second >= ServiceTicketsDurations_.Invalid) { + throw yexception() << "Service tickets are too old: " << tickets.second; + } + + TPairTicketsErrors p = ParseFetchTicketsResponse(tickets.first, config.DstAliases); + SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(std::move(p.Tickets), + std::move(p.Errors), + config.DstAliases)); + return tickets.second; + } + + std::pair<TString, TInstant> TThreadedUpdater::FetchServiceTickets(const TMetaInfo::TConfig& config) const { + TStringStream s; + THttpHeaders headers; + + const TString request = TMetaInfo::GetRequestForTickets(config); + auto code = GetClient().DoGet(request, &s, MetaInfo_.GetAuthHeader(), &headers); + Y_ENSURE(code == 200, ProcessHttpError(EScope::ServiceTickets, request, code, s.Str())); + + return {s.Str(), GetBirthTimeFromResponse(headers, "tickets")}; + } + + static THashSet<TTvmId> GetAllTvmIds(const TMetaInfo::TDstAliases& dsts) { + THashSet<TTvmId> res; + res.reserve(dsts.size()); + + for (const auto& pair : dsts) { + res.insert(pair.second); + } + + return res; + } + + TAsyncUpdaterBase::TPairTicketsErrors TThreadedUpdater::ParseFetchTicketsResponse(const TString& resp, + const TMetaInfo::TDstAliases& dsts) const { + const THashSet<TTvmId> allTvmIds = GetAllTvmIds(dsts); + + TServiceTickets::TMapIdStr tickets; + TServiceTickets::TMapIdStr errors; + + auto procErr = [this](const TString& msg) { + ProcessError(EType::NonRetriable, EScope::ServiceTickets, msg); + LogError(msg); + }; + + NJson::TJsonValue doc; + Y_ENSURE(NJson::ReadJsonTree(resp, &doc), "Invalid json from tvmtool: " << resp); + + for (const auto& pair : doc.GetMap()) { + NJson::TJsonValue tvmId; + unsigned long long tvmIdNum = 0; + + if (!pair.second.GetValue("tvm_id", &tvmId) || + !tvmId.GetUInteger(&tvmIdNum)) { + procErr(TStringBuilder() + << "Failed to get 'tvm_id' from key, should never happend '" + << pair.first << "': " << resp); + continue; + } + + if (!allTvmIds.contains(tvmIdNum)) { + continue; + } + + NJson::TJsonValue val; + if (!pair.second.GetValue("ticket", &val)) { + TString err; + if (pair.second.GetValue("error", &val)) { + err = val.GetString(); + } else { + err = "Failed to get 'ticket' and 'error', should never happend: " + pair.first; + } + + procErr(TStringBuilder() + << "Failed to get ServiceTicket for " << pair.first + << " (" << tvmIdNum << "): " << err); + + errors.insert({tvmIdNum, std::move(err)}); + continue; + } + + tickets.insert({tvmIdNum, val.GetString()}); + } + + // This work-around is required because of bug in old verions of tvmtool: PASSP-24829 + for (const auto& pair : dsts) { + if (!tickets.contains(pair.second) && !errors.contains(pair.second)) { + TString err = "Missing tvm_id in response, should never happend: " + pair.first; + + procErr(TStringBuilder() + << "Failed to get ServiceTicket for " << pair.first + << " (" << pair.second << "): " << err); + + errors.emplace(pair.second, std::move(err)); + } + } + + return {std::move(tickets), std::move(errors)}; + } + + TInstant TThreadedUpdater::UpdateKeys(const TMetaInfo::TConfig& config) { + const std::pair<TString, TInstant> keys = FetchPublicKeys(); + + if (TInstant::Now() - keys.second >= PublicKeysDurations_.Invalid) { + throw yexception() << "Public keys are too old: " << keys.second; + } + + SetServiceContext(MakeIntrusiveConst<TServiceContext>( + TServiceContext::CheckingFactory(config.SelfTvmId, keys.first))); + SetUserContext(keys.first); + + return keys.second; + } + + std::pair<TString, TInstant> TThreadedUpdater::FetchPublicKeys() const { + TStringStream s; + THttpHeaders headers; + + auto code = GetClient().DoGet("/tvm/keys", &s, MetaInfo_.GetAuthHeader(), &headers); + Y_ENSURE(code == 200, ProcessHttpError(EScope::PublicKeys, "/tvm/keys", code, s.Str())); + + return {s.Str(), GetBirthTimeFromResponse(headers, "public keys")}; + } + + TInstant TThreadedUpdater::GetBirthTimeFromResponse(const THttpHeaders& headers, TStringBuf errMsg) { + auto it = std::find_if(headers.begin(), + headers.end(), + [](const THttpInputHeader& h) { + return AsciiEqualsIgnoreCase(h.Name(), "X-Ya-Tvmtool-Data-Birthtime"); + }); + Y_ENSURE(it != headers.end(), "Failed to fetch bithtime of " << errMsg << " from tvmtool"); + + ui64 time = 0; + Y_ENSURE(TryIntFromString<10>(it->Value(), time), + "Bithtime of " << errMsg << " from tvmtool must be unixtime. Got: " << it->Value()); + + return TInstant::Seconds(time); + } + + bool TThreadedUpdater::IsTimeToUpdateServiceTickets(const TMetaInfo::TConfig& config, + TInstant lastUpdate) const { + return config.AreTicketsRequired() && + TInstant::Now() - lastUpdate > ServiceTicketsDurations_.RefreshPeriod; + } + + bool TThreadedUpdater::IsTimeToUpdatePublicKeys(TInstant lastUpdate) const { + return TInstant::Now() - lastUpdate > PublicKeysDurations_.RefreshPeriod; + } + + bool TThreadedUpdater::IsEverythingOk(const TMetaInfo::TConfig& config) const { + return AreServiceTicketsOk(config) && ArePublicKeysOk(); + } + + bool TThreadedUpdater::AreServiceTicketsOk(const TMetaInfo::TConfig& config) const { + return AreServiceTicketsOk(config.DstAliases.size()); + } + + bool TThreadedUpdater::AreServiceTicketsOk(size_t requiredCount) const { + if (requiredCount == 0) { + return true; + } + + auto c = GetCachedServiceTickets(); + return c && c->TicketsByAlias.size() == requiredCount; + } + + bool TThreadedUpdater::ArePublicKeysOk() const { + return GetCachedServiceContext() && GetCachedUserContext(); + } + + bool TThreadedUpdater::IsConfigWarnTime() const { + return LastVisitForConfig_ + ConfigWarnDelay_ < TInstant::Now(); + } + + void TThreadedUpdater::Worker() { + UpdateState(); + } +} diff --git a/library/cpp/tvmauth/client/misc/tool/threaded_updater.h b/library/cpp/tvmauth/client/misc/tool/threaded_updater.h index 656beff6dd..7fe88adfae 100644 --- a/library/cpp/tvmauth/client/misc/tool/threaded_updater.h +++ b/library/cpp/tvmauth/client/misc/tool/threaded_updater.h @@ -1,55 +1,55 @@ -#pragma once - -#include "meta_info.h" - -#include <library/cpp/tvmauth/client/misc/async_updater.h> -#include <library/cpp/tvmauth/client/misc/threaded_updater.h> - -#include <atomic> - -namespace NTvmAuth::NTvmTool { - class TThreadedUpdater: public TThreadedUpdaterBase { - public: - static TAsyncUpdaterPtr Create(const TClientSettings& settings, TLoggerPtr logger); - ~TThreadedUpdater(); - - TClientStatus GetStatus() const override; - - protected: // for tests - TClientStatus::ECode GetState() const; - +#pragma once + +#include "meta_info.h" + +#include <library/cpp/tvmauth/client/misc/async_updater.h> +#include <library/cpp/tvmauth/client/misc/threaded_updater.h> + +#include <atomic> + +namespace NTvmAuth::NTvmTool { + class TThreadedUpdater: public TThreadedUpdaterBase { + public: + static TAsyncUpdaterPtr Create(const TClientSettings& settings, TLoggerPtr logger); + ~TThreadedUpdater(); + + TClientStatus GetStatus() const override; + + protected: // for tests + TClientStatus::ECode GetState() const; + TThreadedUpdater(const TString& host, ui16 port, TDuration socketTimeout, TDuration connectTimeout, TLoggerPtr logger); - - void Init(const TClientSettings& settings); - void UpdateState(); - - TInstant UpdateServiceTickets(const TMetaInfo::TConfig& config); - std::pair<TString, TInstant> FetchServiceTickets(const TMetaInfo::TConfig& config) const; - TPairTicketsErrors ParseFetchTicketsResponse(const TString& resp, - const TMetaInfo::TDstAliases& dsts) const; - - TInstant UpdateKeys(const TMetaInfo::TConfig& config); - std::pair<TString, TInstant> FetchPublicKeys() const; - - static TInstant GetBirthTimeFromResponse(const THttpHeaders& headers, TStringBuf errMsg); - - bool IsTimeToUpdateServiceTickets(const TMetaInfo::TConfig& config, TInstant lastUpdate) const; - bool IsTimeToUpdatePublicKeys(TInstant lastUpdate) const; - - bool IsEverythingOk(const TMetaInfo::TConfig& config) const; - bool AreServiceTicketsOk(const TMetaInfo::TConfig& config) const; - bool AreServiceTicketsOk(size_t requiredCount) const; - bool ArePublicKeysOk() const; - bool IsConfigWarnTime() const; - - private: - void Worker() override; - - protected: - TMetaInfo MetaInfo_; - TInstant LastVisitForServiceTickets_; - TInstant LastVisitForPublicKeys_; - TInstant LastVisitForConfig_; - TDuration ConfigWarnDelay_; - }; -} + + void Init(const TClientSettings& settings); + void UpdateState(); + + TInstant UpdateServiceTickets(const TMetaInfo::TConfig& config); + std::pair<TString, TInstant> FetchServiceTickets(const TMetaInfo::TConfig& config) const; + TPairTicketsErrors ParseFetchTicketsResponse(const TString& resp, + const TMetaInfo::TDstAliases& dsts) const; + + TInstant UpdateKeys(const TMetaInfo::TConfig& config); + std::pair<TString, TInstant> FetchPublicKeys() const; + + static TInstant GetBirthTimeFromResponse(const THttpHeaders& headers, TStringBuf errMsg); + + bool IsTimeToUpdateServiceTickets(const TMetaInfo::TConfig& config, TInstant lastUpdate) const; + bool IsTimeToUpdatePublicKeys(TInstant lastUpdate) const; + + bool IsEverythingOk(const TMetaInfo::TConfig& config) const; + bool AreServiceTicketsOk(const TMetaInfo::TConfig& config) const; + bool AreServiceTicketsOk(size_t requiredCount) const; + bool ArePublicKeysOk() const; + bool IsConfigWarnTime() const; + + private: + void Worker() override; + + protected: + TMetaInfo MetaInfo_; + TInstant LastVisitForServiceTickets_; + TInstant LastVisitForPublicKeys_; + TInstant LastVisitForConfig_; + TDuration ConfigWarnDelay_; + }; +} diff --git a/library/cpp/tvmauth/client/misc/utils.cpp b/library/cpp/tvmauth/client/misc/utils.cpp index 508215c294..a124c7b11c 100644 --- a/library/cpp/tvmauth/client/misc/utils.cpp +++ b/library/cpp/tvmauth/client/misc/utils.cpp @@ -1,46 +1,46 @@ -#include "utils.h" - -#include <library/cpp/tvmauth/client/facade.h> - -#include <util/stream/format.h> - -namespace NTvmAuth::NInternal { - void TClientCaningKnife::StartTvmClientStopping(TTvmClient* c) { - if (c && c->Updater_) { - c->Updater_->StartTvmClientStopping(); - } - } - - bool TClientCaningKnife::IsTvmClientStopped(TTvmClient* c) { - return c && c->Updater_ ? c->Updater_->IsTvmClientStopped() : true; - } -} - -namespace NTvmAuth::NUtils { - TString ToHex(const TStringBuf s) { - TStringStream res; - res.Reserve(2 * s.size()); - - for (char c : s) { - res << Hex(c, HF_FULL); - } - - return std::move(res.Str()); - } - - bool CheckBbEnvOverriding(EBlackboxEnv original, EBlackboxEnv override) noexcept { - switch (original) { - case EBlackboxEnv::Prod: - case EBlackboxEnv::ProdYateam: - return override == EBlackboxEnv::Prod || override == EBlackboxEnv::ProdYateam; - case EBlackboxEnv::Test: - return true; - case EBlackboxEnv::TestYateam: - return override == EBlackboxEnv::Test || override == EBlackboxEnv::TestYateam; - case EBlackboxEnv::Stress: - return override == EBlackboxEnv::Stress; - } - - return false; - } -} +#include "utils.h" + +#include <library/cpp/tvmauth/client/facade.h> + +#include <util/stream/format.h> + +namespace NTvmAuth::NInternal { + void TClientCaningKnife::StartTvmClientStopping(TTvmClient* c) { + if (c && c->Updater_) { + c->Updater_->StartTvmClientStopping(); + } + } + + bool TClientCaningKnife::IsTvmClientStopped(TTvmClient* c) { + return c && c->Updater_ ? c->Updater_->IsTvmClientStopped() : true; + } +} + +namespace NTvmAuth::NUtils { + TString ToHex(const TStringBuf s) { + TStringStream res; + res.Reserve(2 * s.size()); + + for (char c : s) { + res << Hex(c, HF_FULL); + } + + return std::move(res.Str()); + } + + bool CheckBbEnvOverriding(EBlackboxEnv original, EBlackboxEnv override) noexcept { + switch (original) { + case EBlackboxEnv::Prod: + case EBlackboxEnv::ProdYateam: + return override == EBlackboxEnv::Prod || override == EBlackboxEnv::ProdYateam; + case EBlackboxEnv::Test: + return true; + case EBlackboxEnv::TestYateam: + return override == EBlackboxEnv::Test || override == EBlackboxEnv::TestYateam; + case EBlackboxEnv::Stress: + return override == EBlackboxEnv::Stress; + } + + return false; + } +} diff --git a/library/cpp/tvmauth/client/misc/utils.h b/library/cpp/tvmauth/client/misc/utils.h index d2333b16fc..1aa5e61bf1 100644 --- a/library/cpp/tvmauth/client/misc/utils.h +++ b/library/cpp/tvmauth/client/misc/utils.h @@ -1,95 +1,95 @@ -#pragma once - -#include "api/settings.h" -#include "tool/settings.h" - -#include <util/string/cast.h> -#include <util/system/spinlock.h> - -#include <optional> - -namespace NTvmAuth { - class TTvmClient; -} - -namespace NTvmAuth::NInternal { - class TClientCaningKnife { - public: - static void StartTvmClientStopping(TTvmClient* c); - static bool IsTvmClientStopped(TTvmClient* c); - }; -} - -namespace NTvmAuth::NUtils { - TString ToHex(const TStringBuf s); - - inline NTvmAuth::NTvmApi::TClientSettings::TDstMap ParseDstMap(TStringBuf dsts) { - NTvmAuth::NTvmApi::TClientSettings::TDstMap res; - - while (dsts) { - TStringBuf pair = dsts.NextTok(';'); - TStringBuf alias = pair.NextTok(':'); - res.insert(decltype(res)::value_type( - alias, - IntFromString<TTvmId, 10>(pair))); - } - - return res; - } - - inline NTvmAuth::NTvmApi::TClientSettings::TDstVector ParseDstVector(TStringBuf dsts) { - NTvmAuth::NTvmApi::TClientSettings::TDstVector res; - - while (dsts) { - res.push_back(IntFromString<TTvmId, 10>(dsts.NextTok(';'))); - } - - return res; - } - - bool CheckBbEnvOverriding(EBlackboxEnv original, EBlackboxEnv override) noexcept; - - template <class T> - class TProtectedValue { - class TAssignOp { - public: - static void Assign(T& l, const T& r) { - l = r; - } - - template <typename U> - static void Assign(std::shared_ptr<U>& l, std::shared_ptr<U>& r) { - l.swap(r); - } - - template <typename U> - static void Assign(TIntrusiveConstPtr<U>& l, TIntrusiveConstPtr<U>& r) { - l.Swap(r); - } - }; - - public: - TProtectedValue() = default; - - TProtectedValue(T value) - : Value_(value) - { - } - - T Get() const { - with_lock (Lock_) { - return Value_; - } - } - - void Set(T o) { - with_lock (Lock_) { - TAssignOp::Assign(Value_, o); - } - } - - private: - T Value_; - mutable TAdaptiveLock Lock_; - }; -} +#pragma once + +#include "api/settings.h" +#include "tool/settings.h" + +#include <util/string/cast.h> +#include <util/system/spinlock.h> + +#include <optional> + +namespace NTvmAuth { + class TTvmClient; +} + +namespace NTvmAuth::NInternal { + class TClientCaningKnife { + public: + static void StartTvmClientStopping(TTvmClient* c); + static bool IsTvmClientStopped(TTvmClient* c); + }; +} + +namespace NTvmAuth::NUtils { + TString ToHex(const TStringBuf s); + + inline NTvmAuth::NTvmApi::TClientSettings::TDstMap ParseDstMap(TStringBuf dsts) { + NTvmAuth::NTvmApi::TClientSettings::TDstMap res; + + while (dsts) { + TStringBuf pair = dsts.NextTok(';'); + TStringBuf alias = pair.NextTok(':'); + res.insert(decltype(res)::value_type( + alias, + IntFromString<TTvmId, 10>(pair))); + } + + return res; + } + + inline NTvmAuth::NTvmApi::TClientSettings::TDstVector ParseDstVector(TStringBuf dsts) { + NTvmAuth::NTvmApi::TClientSettings::TDstVector res; + + while (dsts) { + res.push_back(IntFromString<TTvmId, 10>(dsts.NextTok(';'))); + } + + return res; + } + + bool CheckBbEnvOverriding(EBlackboxEnv original, EBlackboxEnv override) noexcept; + + template <class T> + class TProtectedValue { + class TAssignOp { + public: + static void Assign(T& l, const T& r) { + l = r; + } + + template <typename U> + static void Assign(std::shared_ptr<U>& l, std::shared_ptr<U>& r) { + l.swap(r); + } + + template <typename U> + static void Assign(TIntrusiveConstPtr<U>& l, TIntrusiveConstPtr<U>& r) { + l.Swap(r); + } + }; + + public: + TProtectedValue() = default; + + TProtectedValue(T value) + : Value_(value) + { + } + + T Get() const { + with_lock (Lock_) { + return Value_; + } + } + + void Set(T o) { + with_lock (Lock_) { + TAssignOp::Assign(Value_, o); + } + } + + private: + T Value_; + mutable TAdaptiveLock Lock_; + }; +} diff --git a/library/cpp/tvmauth/client/mocked_updater.cpp b/library/cpp/tvmauth/client/mocked_updater.cpp index 6da02c43d1..54f94bc92a 100644 --- a/library/cpp/tvmauth/client/mocked_updater.cpp +++ b/library/cpp/tvmauth/client/mocked_updater.cpp @@ -1,60 +1,60 @@ -#include "mocked_updater.h" - -#include <library/cpp/tvmauth/unittest.h> - -namespace NTvmAuth { - TMockedUpdater::TSettings TMockedUpdater::TSettings::CreateDeafult() { - TMockedUpdater::TSettings res; - - res.SelfTvmId = 100500; - - res.Backends = { - { - /*.Alias_ = */ "my_dest", - /*.Id_ = */ 42, - /*.Value_ = */ "3:serv:CBAQ__________9_IgYIlJEGECo:O9-vbod_8czkKrpwJAZCI8UgOIhNr2xKPcS-LWALrVC224jga2nIT6vLiw6q3d6pAT60g9K7NB39LEmh7vMuePtUMjzuZuL-uJg17BsH2iTLCZSxDjWxbU9piA2T6u607jiSyiy-FI74pEPqkz7KKJ28aPsefuC1VUweGkYFzNY", - }, - }; - - res.BadBackends = { - { - /*.Alias_ = */ "my_bad_dest", - /*.Id_ = */ 43, - /*.Value_ = */ "Dst is not found", - }, - }; - - return res; - } - - TMockedUpdater::TMockedUpdater(const TSettings& settings) - : Roles_(settings.Roles) - { - SetServiceContext(MakeIntrusiveConst<TServiceContext>(TServiceContext::CheckingFactory( - settings.SelfTvmId, - NUnittest::TVMKNIFE_PUBLIC_KEYS))); - - SetBbEnv(settings.UserTicketEnv); - SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); - - TServiceTickets::TMapIdStr tickets, errors; - TServiceTickets::TMapAliasId aliases; - - for (const TSettings::TTuple& t : settings.Backends) { - tickets[t.Id] = t.Value; - aliases[t.Alias] = t.Id; - } - for (const TSettings::TTuple& t : settings.BadBackends) { - errors[t.Id] = t.Value; - aliases[t.Alias] = t.Id; - } - - SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - std::move(tickets), - std::move(errors), - std::move(aliases))); - - SetUpdateTimeOfPublicKeys(TInstant::Now()); - SetUpdateTimeOfServiceTickets(TInstant::Now()); - } -} +#include "mocked_updater.h" + +#include <library/cpp/tvmauth/unittest.h> + +namespace NTvmAuth { + TMockedUpdater::TSettings TMockedUpdater::TSettings::CreateDeafult() { + TMockedUpdater::TSettings res; + + res.SelfTvmId = 100500; + + res.Backends = { + { + /*.Alias_ = */ "my_dest", + /*.Id_ = */ 42, + /*.Value_ = */ "3:serv:CBAQ__________9_IgYIlJEGECo:O9-vbod_8czkKrpwJAZCI8UgOIhNr2xKPcS-LWALrVC224jga2nIT6vLiw6q3d6pAT60g9K7NB39LEmh7vMuePtUMjzuZuL-uJg17BsH2iTLCZSxDjWxbU9piA2T6u607jiSyiy-FI74pEPqkz7KKJ28aPsefuC1VUweGkYFzNY", + }, + }; + + res.BadBackends = { + { + /*.Alias_ = */ "my_bad_dest", + /*.Id_ = */ 43, + /*.Value_ = */ "Dst is not found", + }, + }; + + return res; + } + + TMockedUpdater::TMockedUpdater(const TSettings& settings) + : Roles_(settings.Roles) + { + SetServiceContext(MakeIntrusiveConst<TServiceContext>(TServiceContext::CheckingFactory( + settings.SelfTvmId, + NUnittest::TVMKNIFE_PUBLIC_KEYS))); + + SetBbEnv(settings.UserTicketEnv); + SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); + + TServiceTickets::TMapIdStr tickets, errors; + TServiceTickets::TMapAliasId aliases; + + for (const TSettings::TTuple& t : settings.Backends) { + tickets[t.Id] = t.Value; + aliases[t.Alias] = t.Id; + } + for (const TSettings::TTuple& t : settings.BadBackends) { + errors[t.Id] = t.Value; + aliases[t.Alias] = t.Id; + } + + SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + std::move(tickets), + std::move(errors), + std::move(aliases))); + + SetUpdateTimeOfPublicKeys(TInstant::Now()); + SetUpdateTimeOfServiceTickets(TInstant::Now()); + } +} diff --git a/library/cpp/tvmauth/client/mocked_updater.h b/library/cpp/tvmauth/client/mocked_updater.h index d20cf5f53f..f8a6394f5f 100644 --- a/library/cpp/tvmauth/client/mocked_updater.h +++ b/library/cpp/tvmauth/client/mocked_updater.h @@ -1,43 +1,43 @@ -#pragma once - -#include "misc/async_updater.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 { - return Roles_; - } - - using TAsyncUpdaterBase::SetServiceContext; - using TAsyncUpdaterBase::SetServiceTickets; - using TAsyncUpdaterBase::SetUpdateTimeOfPublicKeys; - using TAsyncUpdaterBase::SetUpdateTimeOfServiceTickets; - using TAsyncUpdaterBase::SetUserContext; - - protected: - NRoles::TRolesPtr Roles_; - }; -} +#pragma once + +#include "misc/async_updater.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 { + return Roles_; + } + + using TAsyncUpdaterBase::SetServiceContext; + using TAsyncUpdaterBase::SetServiceTickets; + using TAsyncUpdaterBase::SetUpdateTimeOfPublicKeys; + using TAsyncUpdaterBase::SetUpdateTimeOfServiceTickets; + using TAsyncUpdaterBase::SetUserContext; + + protected: + NRoles::TRolesPtr Roles_; + }; +} diff --git a/library/cpp/tvmauth/client/ut/async_updater_ut.cpp b/library/cpp/tvmauth/client/ut/async_updater_ut.cpp index 7bbe035225..1c1e8cbaae 100644 --- a/library/cpp/tvmauth/client/ut/async_updater_ut.cpp +++ b/library/cpp/tvmauth/client/ut/async_updater_ut.cpp @@ -1,165 +1,165 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/misc/async_updater.h> - -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(AsyncUpdater) { - static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; - 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"; - - class TTestUpdater: public TAsyncUpdaterBase { - public: - using TAsyncUpdaterBase::SetBbEnv; - using TAsyncUpdaterBase::SetUserContext; - - TClientStatus GetStatus() const override { - return TClientStatus(); - } - }; - - Y_UNIT_TEST(User) { - TTestUpdater u; - - UNIT_ASSERT(!u.GetCachedUserContext()); - - u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); - UNIT_ASSERT(!u.GetCachedUserContext()); - - UNIT_ASSERT_NO_EXCEPTION(u.SetBbEnv(EBlackboxEnv::Prod)); - UNIT_ASSERT(u.GetCachedUserContext()); - UNIT_ASSERT(u.GetCachedUserContext()->Check(PROD_TICKET)); - UNIT_ASSERT_NO_EXCEPTION(u.GetCachedUserContext(EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(u.GetCachedUserContext(EBlackboxEnv::ProdYateam)->Check(PROD_YATEAM_TICKET)); - - UNIT_ASSERT_EXCEPTION_CONTAINS(u.SetBbEnv(EBlackboxEnv::Prod, EBlackboxEnv::Test), - TBrokenTvmClientSettings, - "Overriding of BlackboxEnv is illegal: Prod -> Test"); - UNIT_ASSERT_EXCEPTION_CONTAINS(u.GetCachedUserContext(EBlackboxEnv::Test), - TBrokenTvmClientSettings, - "Overriding of BlackboxEnv is illegal: Prod -> Test"); - - UNIT_ASSERT(u.GetCachedUserContext()); - UNIT_ASSERT(u.GetCachedUserContext()->Check(PROD_TICKET)); - } - - class DummyUpdater: public TAsyncUpdaterBase { - public: - TClientStatus GetStatus() const override { - return TClientStatus(); - } - - using TAsyncUpdaterBase::SetServiceContext; - using TAsyncUpdaterBase::SetServiceTickets; - using TAsyncUpdaterBase::SetUserContext; - }; - - Y_UNIT_TEST(Cache) { - DummyUpdater d; - - UNIT_ASSERT(!d.GetCachedServiceTickets()); - TServiceTicketsPtr st = MakeIntrusiveConst<TServiceTickets>(TServiceTickets::TMapIdStr(), - TServiceTickets::TMapIdStr(), - TServiceTickets::TMapAliasId()); - d.SetServiceTickets(st); - UNIT_ASSERT_EQUAL(st.Get(), d.GetCachedServiceTickets().Get()); - - UNIT_ASSERT(!d.GetCachedServiceContext()); - TServiceContextPtr sc = MakeIntrusiveConst<TServiceContext>(TServiceContext::SigningFactory("kjndfadfndsfafdasd")); - d.SetServiceContext(sc); - UNIT_ASSERT_EQUAL(sc.Get(), d.GetCachedServiceContext().Get()); - - UNIT_ASSERT(!d.GetCachedUserContext()); - d.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); - } - - Y_UNIT_TEST(ServiceTickets_Aliases) { - using TId = TServiceTickets::TMapIdStr; +#include "common.h" + +#include <library/cpp/tvmauth/client/misc/async_updater.h> + +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(AsyncUpdater) { + static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; + 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"; + + class TTestUpdater: public TAsyncUpdaterBase { + public: + using TAsyncUpdaterBase::SetBbEnv; + using TAsyncUpdaterBase::SetUserContext; + + TClientStatus GetStatus() const override { + return TClientStatus(); + } + }; + + Y_UNIT_TEST(User) { + TTestUpdater u; + + UNIT_ASSERT(!u.GetCachedUserContext()); + + u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); + UNIT_ASSERT(!u.GetCachedUserContext()); + + UNIT_ASSERT_NO_EXCEPTION(u.SetBbEnv(EBlackboxEnv::Prod)); + UNIT_ASSERT(u.GetCachedUserContext()); + UNIT_ASSERT(u.GetCachedUserContext()->Check(PROD_TICKET)); + UNIT_ASSERT_NO_EXCEPTION(u.GetCachedUserContext(EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(u.GetCachedUserContext(EBlackboxEnv::ProdYateam)->Check(PROD_YATEAM_TICKET)); + + UNIT_ASSERT_EXCEPTION_CONTAINS(u.SetBbEnv(EBlackboxEnv::Prod, EBlackboxEnv::Test), + TBrokenTvmClientSettings, + "Overriding of BlackboxEnv is illegal: Prod -> Test"); + UNIT_ASSERT_EXCEPTION_CONTAINS(u.GetCachedUserContext(EBlackboxEnv::Test), + TBrokenTvmClientSettings, + "Overriding of BlackboxEnv is illegal: Prod -> Test"); + + UNIT_ASSERT(u.GetCachedUserContext()); + UNIT_ASSERT(u.GetCachedUserContext()->Check(PROD_TICKET)); + } + + class DummyUpdater: public TAsyncUpdaterBase { + public: + TClientStatus GetStatus() const override { + return TClientStatus(); + } + + using TAsyncUpdaterBase::SetServiceContext; + using TAsyncUpdaterBase::SetServiceTickets; + using TAsyncUpdaterBase::SetUserContext; + }; + + Y_UNIT_TEST(Cache) { + DummyUpdater d; + + UNIT_ASSERT(!d.GetCachedServiceTickets()); + TServiceTicketsPtr st = MakeIntrusiveConst<TServiceTickets>(TServiceTickets::TMapIdStr(), + TServiceTickets::TMapIdStr(), + TServiceTickets::TMapAliasId()); + d.SetServiceTickets(st); + UNIT_ASSERT_EQUAL(st.Get(), d.GetCachedServiceTickets().Get()); + + UNIT_ASSERT(!d.GetCachedServiceContext()); + TServiceContextPtr sc = MakeIntrusiveConst<TServiceContext>(TServiceContext::SigningFactory("kjndfadfndsfafdasd")); + d.SetServiceContext(sc); + UNIT_ASSERT_EQUAL(sc.Get(), d.GetCachedServiceContext().Get()); + + UNIT_ASSERT(!d.GetCachedUserContext()); + d.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); + } + + Y_UNIT_TEST(ServiceTickets_Aliases) { + using TId = TServiceTickets::TMapIdStr; using TUnfetchedId = TServiceTickets::TIdSet; - using TStr = TServiceTickets::TMapAliasStr; + using TStr = TServiceTickets::TMapAliasStr; using TUnfetchedAlias = TServiceTickets::TAliasSet; - using TAls = TServiceTickets::TMapAliasId; - TServiceTickets t(TId{}, TId{}, TAls{}); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, "t1"}, {2, "t2"}}), - TId({{3, "e1"}}), - TAls())); - UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); - UNIT_ASSERT_EQUAL(TId({{3, "e1"}}), t.ErrorsById); - UNIT_ASSERT_EQUAL(TStr(), t.TicketsByAlias); - UNIT_ASSERT_EQUAL(TStr(), t.ErrorsByAlias); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, "t1"}, {2, "t2"}}), - TId({{3, "e1"}}), - TAls({{"1", 1}, {"2", 2}, {"3", 3}}))); - UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); - UNIT_ASSERT_EQUAL(TId({{3, "e1"}}), t.ErrorsById); - UNIT_ASSERT_EQUAL(TUnfetchedId(), t.UnfetchedIds); - UNIT_ASSERT_EQUAL(TStr({{"1", "t1"}, {"2", "t2"}}), t.TicketsByAlias); - UNIT_ASSERT_EQUAL(TStr({{"3", "e1"}}), t.ErrorsByAlias); - UNIT_ASSERT_EQUAL(TUnfetchedAlias({}), t.UnfetchedAliases); + using TAls = TServiceTickets::TMapAliasId; + TServiceTickets t(TId{}, TId{}, TAls{}); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, "t1"}, {2, "t2"}}), + TId({{3, "e1"}}), + TAls())); + UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); + UNIT_ASSERT_EQUAL(TId({{3, "e1"}}), t.ErrorsById); + UNIT_ASSERT_EQUAL(TStr(), t.TicketsByAlias); + UNIT_ASSERT_EQUAL(TStr(), t.ErrorsByAlias); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, "t1"}, {2, "t2"}}), + TId({{3, "e1"}}), + TAls({{"1", 1}, {"2", 2}, {"3", 3}}))); + UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); + UNIT_ASSERT_EQUAL(TId({{3, "e1"}}), t.ErrorsById); + UNIT_ASSERT_EQUAL(TUnfetchedId(), t.UnfetchedIds); + UNIT_ASSERT_EQUAL(TStr({{"1", "t1"}, {"2", "t2"}}), t.TicketsByAlias); + UNIT_ASSERT_EQUAL(TStr({{"3", "e1"}}), t.ErrorsByAlias); + UNIT_ASSERT_EQUAL(TUnfetchedAlias({}), t.UnfetchedAliases); } - + Y_UNIT_TEST(ServiceTickets_UnfetchedIds) { using TId = TServiceTickets::TMapIdStr; using TUnfetchedId = TServiceTickets::TIdSet; using TStr = TServiceTickets::TMapAliasStr; using TUnfetchedAlias = TServiceTickets::TAliasSet; using TAls = TServiceTickets::TMapAliasId; - TServiceTickets t(TId({{1, "t1"}, {2, "t2"}}), - TId(), - TAls({{"1", 1}, {"2", 2}, {"3", 3}})); - - UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); - UNIT_ASSERT_EQUAL(TId({}), t.ErrorsById); - UNIT_ASSERT_EQUAL(TUnfetchedId({3}), t.UnfetchedIds); - UNIT_ASSERT_EQUAL(TUnfetchedAlias({{"3"}}), t.UnfetchedAliases); - UNIT_ASSERT_EQUAL(TStr({{"1", "t1"}, {"2", "t2"}}), t.TicketsByAlias); - UNIT_ASSERT_EQUAL(TStr(), t.ErrorsByAlias); - } - - Y_UNIT_TEST(ServiceTickets_InvalidationTime) { - using TId = TServiceTickets::TMapIdStr; - using TAls = TServiceTickets::TMapAliasId; - - TServiceTickets t(TId{}, TId{}, TAls{}); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), t.InvalidationTime); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, SRV_TICKET}}), - TId(), - TAls())); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), t.InvalidationTime); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ - {1, SRV_TICKET}, - {2, "serv"}, - }), - TId(), - TAls())); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), t.InvalidationTime); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ - {2, "serv"}, - }), - TId(), - TAls())); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), t.InvalidationTime); - - UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ - {1, SRV_TICKET}, - {2, "serv"}, - {3, "3:serv:CBAQeyIECAMQAw:TiZjG2Ut9j-9n0zcqxGW8xiYmnFa-i10-dbA0FKIInKzeDuueovWVEBcgbQHndblzRCxoIBMgbotOf7ALk2xoSBnRbOKomAIEtiTBL77GByL5O8K_HUGNYb-ygqnmZlIuLalgeRQAdsKstgUwQzufnOQyekipmamwo7EVQhr8Ug"}, - }), - TId(), - TAls())); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(123), t.InvalidationTime); - } -} + TServiceTickets t(TId({{1, "t1"}, {2, "t2"}}), + TId(), + TAls({{"1", 1}, {"2", 2}, {"3", 3}})); + + UNIT_ASSERT_EQUAL(TId({{1, "t1"}, {2, "t2"}}), t.TicketsById); + UNIT_ASSERT_EQUAL(TId({}), t.ErrorsById); + UNIT_ASSERT_EQUAL(TUnfetchedId({3}), t.UnfetchedIds); + UNIT_ASSERT_EQUAL(TUnfetchedAlias({{"3"}}), t.UnfetchedAliases); + UNIT_ASSERT_EQUAL(TStr({{"1", "t1"}, {"2", "t2"}}), t.TicketsByAlias); + UNIT_ASSERT_EQUAL(TStr(), t.ErrorsByAlias); + } + + Y_UNIT_TEST(ServiceTickets_InvalidationTime) { + using TId = TServiceTickets::TMapIdStr; + using TAls = TServiceTickets::TMapAliasId; + + TServiceTickets t(TId{}, TId{}, TAls{}); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), t.InvalidationTime); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({{1, SRV_TICKET}}), + TId(), + TAls())); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), t.InvalidationTime); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ + {1, SRV_TICKET}, + {2, "serv"}, + }), + TId(), + TAls())); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), t.InvalidationTime); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ + {2, "serv"}, + }), + TId(), + TAls())); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), t.InvalidationTime); + + UNIT_ASSERT_NO_EXCEPTION(t = TServiceTickets(TId({ + {1, SRV_TICKET}, + {2, "serv"}, + {3, "3:serv:CBAQeyIECAMQAw:TiZjG2Ut9j-9n0zcqxGW8xiYmnFa-i10-dbA0FKIInKzeDuueovWVEBcgbQHndblzRCxoIBMgbotOf7ALk2xoSBnRbOKomAIEtiTBL77GByL5O8K_HUGNYb-ygqnmZlIuLalgeRQAdsKstgUwQzufnOQyekipmamwo7EVQhr8Ug"}, + }), + TId(), + TAls())); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(123), t.InvalidationTime); + } +} diff --git a/library/cpp/tvmauth/client/ut/checker_ut.cpp b/library/cpp/tvmauth/client/ut/checker_ut.cpp index 21d303f649..54a25974c1 100644 --- a/library/cpp/tvmauth/client/ut/checker_ut.cpp +++ b/library/cpp/tvmauth/client/ut/checker_ut.cpp @@ -1,176 +1,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 "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; - + +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"; - + 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, {})); - } - } - + 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()); - } - + 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"); - } -} + 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"); + } +} diff --git a/library/cpp/tvmauth/client/ut/client_status_ut.cpp b/library/cpp/tvmauth/client/ut/client_status_ut.cpp index 53d0dc3cf9..a1c3ae74ce 100644 --- a/library/cpp/tvmauth/client/ut/client_status_ut.cpp +++ b/library/cpp/tvmauth/client/ut/client_status_ut.cpp @@ -1,18 +1,18 @@ -#include <library/cpp/tvmauth/client/client_status.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(ClientStatus) { - Y_UNIT_TEST(Common) { - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, TClientStatus().GetCode()); - UNIT_ASSERT_VALUES_EQUAL("", TClientStatus().GetLastError()); - - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, TClientStatus(TClientStatus::Warning, "kek")); - UNIT_ASSERT_VALUES_EQUAL("kek", - TClientStatus(TClientStatus::Warning, "kek").GetLastError()); - UNIT_ASSERT_VALUES_EQUAL("2;TvmClient: kek\n", - TClientStatus(TClientStatus::Error, "kek").CreateJugglerMessage()); - } -} +#include <library/cpp/tvmauth/client/client_status.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(ClientStatus) { + Y_UNIT_TEST(Common) { + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, TClientStatus().GetCode()); + UNIT_ASSERT_VALUES_EQUAL("", TClientStatus().GetLastError()); + + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, TClientStatus(TClientStatus::Warning, "kek")); + UNIT_ASSERT_VALUES_EQUAL("kek", + TClientStatus(TClientStatus::Warning, "kek").GetLastError()); + UNIT_ASSERT_VALUES_EQUAL("2;TvmClient: kek\n", + TClientStatus(TClientStatus::Error, "kek").CreateJugglerMessage()); + } +} diff --git a/library/cpp/tvmauth/client/ut/common.h b/library/cpp/tvmauth/client/ut/common.h index c2f577d72d..5dddc182b5 100644 --- a/library/cpp/tvmauth/client/ut/common.h +++ b/library/cpp/tvmauth/client/ut/common.h @@ -1,232 +1,232 @@ -#pragma once - -#include <library/cpp/tvmauth/client/logger.h> -#include <library/cpp/tvmauth/client/misc/disk_cache.h> -#include <library/cpp/tvmauth/client/misc/roles/entities_index.h> - -#include <library/cpp/tvmauth/unittest.h> - +#pragma once + +#include <library/cpp/tvmauth/client/logger.h> +#include <library/cpp/tvmauth/client/misc/disk_cache.h> +#include <library/cpp/tvmauth/client/misc/roles/entities_index.h> + +#include <library/cpp/tvmauth/unittest.h> + #include <library/cpp/cgiparam/cgiparam.h> -#include <library/cpp/testing/mock_server/server.h> +#include <library/cpp/testing/mock_server/server.h> #include <library/cpp/testing/unittest/env.h> #include <library/cpp/testing/unittest/tests_data.h> - -#include <util/stream/str.h> -#include <util/system/fs.h> - -class TLogger: public NTvmAuth::ILogger { -public: - void Log(int lvl, const TString& msg) override { - Cout << TInstant::Now() << " lvl=" << lvl << " msg: " << msg << "\n"; - Stream << lvl << ": " << msg << Endl; - } - - TStringStream Stream; -}; - -static inline TString GetFilePath(const char* name) { - return ArcadiaSourceRoot() + "/library/cpp/tvmauth/client/ut/files/" + name; -} - -static inline TString GetCachePath(const TString& dir = {}) { - if (dir) { - Y_ENSURE(NFs::MakeDirectoryRecursive("./" + dir)); - } - - auto wr = [](const TString& p, const TStringBuf body) { - NTvmAuth::TDiskWriter w(p); - Y_ENSURE(w.Write(body, TInstant::ParseIso8601("2050-01-01T00:00:00.000000Z"))); - }; - wr("./" + dir + "/public_keys", NTvmAuth::NUnittest::TVMKNIFE_PUBLIC_KEYS); - wr("./" + dir + "/service_tickets", - R"({ - "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - "213" : { "ticket" : "service_ticket_2"}, - "234" : { "error" : "Dst is not found" }, - "185" : { "ticket" : "service_ticket_3"} -} 100500)"); - - return "./" + dir; -} - -static const TString AUTH_TOKEN = "strong_token"; -static const TString META = R"( -{ -"bb_env" : "ProdYaTeam", -"tenants" : [ - { - "self": { - "alias" : "me", - "client_id": 100500 - }, - "dsts" : [ - { - "alias" : "bbox", - "client_id": 242 - }, - { - "alias" : "pass_likers", - "client_id": 11 - } - ] - }, - { - "self": { - "alias" : "push-client", - "client_id": 100501 - }, - "dsts" : [ - { - "alias" : "pass_likers", - "client_id": 100502 - } - ] - }, - { - "self": { - "alias" : "multi_names_for_dst", - "client_id": 100599 - }, - "dsts" : [ - { - "alias" : "pass_likers", - "client_id": 100502 - }, - { - "alias" : "pass_haters", - "client_id": 100502 - } - ] - }, - { - "self": { - "alias" : "something_else", - "client_id": 100503 - }, - "dsts" : [ - ] - } -] -})"; - -static const TString TICKETS_ME = - R"({ - "pass_likers": { - "ticket": "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8", - "tvm_id": 11 - }, - "bbox": { - "ticket": "3:serv:CBAQ__________9_IgcIlJEGEPIB:N7luw0_rVmBosTTI130jwDbQd0-cMmqJeEl0ma4ZlIo_mHXjBzpOuMQ3A9YagbmOBOt8TZ_gzGvVSegWZkEeB24gM22acw0w-RcHaQKrzSOA5Zq8WLNIC8QUa4_WGTlAsb7R7eC4KTAGgouIquNAgMBdTuGOuZHnMLvZyLnOMKc", - "tvm_id": 242 - } - })"; - -static const TString SERVICE_TICKET_PC = "3:serv:CBAQ__________9_IggIlpEGEJaRBg:BAxaQJCdK4eFuJ6i_egqPwvJgWtlh0enDQRPr84Nx2phZ_8QtxKAUCwEa7KOU_jVvIBQIC5-ETTl2vjBt7UyygF8frdK4ab6zJoWj4n07np6vbmWd385l8KvzztLt4QkBrPiE7U46dK3pL0U8tfBkSXE8rvUIsl3RvvgSNH2J3c"; -static const TString TICKETS_PC = - R"({ - "pass_likers": { - "ticket": "3:serv:CBAQ__________9_IggIlpEGEJaRBg:BAxaQJCdK4eFuJ6i_egqPwvJgWtlh0enDQRPr84Nx2phZ_8QtxKAUCwEa7KOU_jVvIBQIC5-ETTl2vjBt7UyygF8frdK4ab6zJoWj4n07np6vbmWd385l8KvzztLt4QkBrPiE7U46dK3pL0U8tfBkSXE8rvUIsl3RvvgSNH2J3c", - "tvm_id": 100502 - } - })"; - -static const TString TICKETS_MANY_DSTS = - R"({ - "pass_likers": { - "ticket": "3:serv:CBAQ__________9_IggI95EGEJaRBg:D0MOLDhKQyI-OhC0ON9gYukz2hOctUipu1yXsvkw6NRuLhcBfvGayyUqF4ILrqepjz9GtPWIR_wO6oLSW35Z0YaFn60QWp5tG6IcAnr80lm_OnLHJt4kmEoLtGg1V0aWBT0YyouzGB2-QFNOVO86G7sYzU8FC6-V3Iyc4X7XTNc", - "tvm_id": 100502 - }, - "who_are_you??": { - "ticket": "kek", - "tvm_id": 100503 - }, - "pass_haters": { - "ticket": "3:serv:CBAQ__________9_IggI95EGEJaRBg:D0MOLDhKQyI-OhC0ON9gYukz2hOctUipu1yXsvkw6NRuLhcBfvGayyUqF4ILrqepjz9GtPWIR_wO6oLSW35Z0YaFn60QWp5tG6IcAnr80lm_OnLHJt4kmEoLtGg1V0aWBT0YyouzGB2-QFNOVO86G7sYzU8FC6-V3Iyc4X7XTNc", - "tvm_id": 100502 - } - })"; - -static const TString TICKETS_SE = R"({})"; - -static const TInstant BIRTHTIME = TInstant::Seconds(14380887840); -class TTvmTool: public TRequestReplier { -public: - TString Meta; - HttpCodes Code; - TInstant Birthtime; - - TTvmTool() - : Meta(META) - , Code(HTTP_OK) - , Birthtime(BIRTHTIME) - { - } - - bool DoReply(const TReplyParams& params) override { - const TParsedHttpFull http(params.Input.FirstLine()); - if (http.Path == "/tvm/ping") { - THttpResponse resp(HTTP_OK); - resp.SetContent("OK"); - resp.OutTo(params.Output); - return true; - } - - auto it = std::find_if(params.Input.Headers().begin(), - params.Input.Headers().end(), - [](const THttpInputHeader& h) { return h.Name() == "Authorization"; }); - if (it == params.Input.Headers().end() || it->Value() != AUTH_TOKEN) { - THttpResponse resp(HTTP_UNAUTHORIZED); - resp.SetContent("pong"); - resp.OutTo(params.Output); - return true; - } - - THttpResponse resp(Code); - if (http.Path == "/tvm/keys") { - resp.SetContent(NTvmAuth::NUnittest::TVMKNIFE_PUBLIC_KEYS); - } else if (http.Path == "/tvm/tickets") { - TCgiParameters cg; - cg.ScanAddAll(http.Cgi); - if (cg.Get("src") == "100500") { - resp.SetContent(TICKETS_ME); - } else if (cg.Get("src") == "100501") { - resp.SetContent(TICKETS_PC); - } else if (cg.Get("src") == "100599") { - resp.SetContent(TICKETS_MANY_DSTS); - } - } else if (http.Path == "/tvm/private_api/__meta__") { - resp.SetContent(Meta); - } - resp.AddHeader("X-Ya-Tvmtool-Data-Birthtime", IntToString<10>(Birthtime.Seconds())); - resp.OutTo(params.Output); - - return true; - } -}; - -static inline NTvmAuth::NRoles::TEntitiesIndex CreateEntitiesIndex() { - using namespace NTvmAuth::NRoles; - - TEntitiesIndex index( - { - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }), - }); - - return index; -} + +#include <util/stream/str.h> +#include <util/system/fs.h> + +class TLogger: public NTvmAuth::ILogger { +public: + void Log(int lvl, const TString& msg) override { + Cout << TInstant::Now() << " lvl=" << lvl << " msg: " << msg << "\n"; + Stream << lvl << ": " << msg << Endl; + } + + TStringStream Stream; +}; + +static inline TString GetFilePath(const char* name) { + return ArcadiaSourceRoot() + "/library/cpp/tvmauth/client/ut/files/" + name; +} + +static inline TString GetCachePath(const TString& dir = {}) { + if (dir) { + Y_ENSURE(NFs::MakeDirectoryRecursive("./" + dir)); + } + + auto wr = [](const TString& p, const TStringBuf body) { + NTvmAuth::TDiskWriter w(p); + Y_ENSURE(w.Write(body, TInstant::ParseIso8601("2050-01-01T00:00:00.000000Z"))); + }; + wr("./" + dir + "/public_keys", NTvmAuth::NUnittest::TVMKNIFE_PUBLIC_KEYS); + wr("./" + dir + "/service_tickets", + R"({ + "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + "213" : { "ticket" : "service_ticket_2"}, + "234" : { "error" : "Dst is not found" }, + "185" : { "ticket" : "service_ticket_3"} +} 100500)"); + + return "./" + dir; +} + +static const TString AUTH_TOKEN = "strong_token"; +static const TString META = R"( +{ +"bb_env" : "ProdYaTeam", +"tenants" : [ + { + "self": { + "alias" : "me", + "client_id": 100500 + }, + "dsts" : [ + { + "alias" : "bbox", + "client_id": 242 + }, + { + "alias" : "pass_likers", + "client_id": 11 + } + ] + }, + { + "self": { + "alias" : "push-client", + "client_id": 100501 + }, + "dsts" : [ + { + "alias" : "pass_likers", + "client_id": 100502 + } + ] + }, + { + "self": { + "alias" : "multi_names_for_dst", + "client_id": 100599 + }, + "dsts" : [ + { + "alias" : "pass_likers", + "client_id": 100502 + }, + { + "alias" : "pass_haters", + "client_id": 100502 + } + ] + }, + { + "self": { + "alias" : "something_else", + "client_id": 100503 + }, + "dsts" : [ + ] + } +] +})"; + +static const TString TICKETS_ME = + R"({ + "pass_likers": { + "ticket": "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8", + "tvm_id": 11 + }, + "bbox": { + "ticket": "3:serv:CBAQ__________9_IgcIlJEGEPIB:N7luw0_rVmBosTTI130jwDbQd0-cMmqJeEl0ma4ZlIo_mHXjBzpOuMQ3A9YagbmOBOt8TZ_gzGvVSegWZkEeB24gM22acw0w-RcHaQKrzSOA5Zq8WLNIC8QUa4_WGTlAsb7R7eC4KTAGgouIquNAgMBdTuGOuZHnMLvZyLnOMKc", + "tvm_id": 242 + } + })"; + +static const TString SERVICE_TICKET_PC = "3:serv:CBAQ__________9_IggIlpEGEJaRBg:BAxaQJCdK4eFuJ6i_egqPwvJgWtlh0enDQRPr84Nx2phZ_8QtxKAUCwEa7KOU_jVvIBQIC5-ETTl2vjBt7UyygF8frdK4ab6zJoWj4n07np6vbmWd385l8KvzztLt4QkBrPiE7U46dK3pL0U8tfBkSXE8rvUIsl3RvvgSNH2J3c"; +static const TString TICKETS_PC = + R"({ + "pass_likers": { + "ticket": "3:serv:CBAQ__________9_IggIlpEGEJaRBg:BAxaQJCdK4eFuJ6i_egqPwvJgWtlh0enDQRPr84Nx2phZ_8QtxKAUCwEa7KOU_jVvIBQIC5-ETTl2vjBt7UyygF8frdK4ab6zJoWj4n07np6vbmWd385l8KvzztLt4QkBrPiE7U46dK3pL0U8tfBkSXE8rvUIsl3RvvgSNH2J3c", + "tvm_id": 100502 + } + })"; + +static const TString TICKETS_MANY_DSTS = + R"({ + "pass_likers": { + "ticket": "3:serv:CBAQ__________9_IggI95EGEJaRBg:D0MOLDhKQyI-OhC0ON9gYukz2hOctUipu1yXsvkw6NRuLhcBfvGayyUqF4ILrqepjz9GtPWIR_wO6oLSW35Z0YaFn60QWp5tG6IcAnr80lm_OnLHJt4kmEoLtGg1V0aWBT0YyouzGB2-QFNOVO86G7sYzU8FC6-V3Iyc4X7XTNc", + "tvm_id": 100502 + }, + "who_are_you??": { + "ticket": "kek", + "tvm_id": 100503 + }, + "pass_haters": { + "ticket": "3:serv:CBAQ__________9_IggI95EGEJaRBg:D0MOLDhKQyI-OhC0ON9gYukz2hOctUipu1yXsvkw6NRuLhcBfvGayyUqF4ILrqepjz9GtPWIR_wO6oLSW35Z0YaFn60QWp5tG6IcAnr80lm_OnLHJt4kmEoLtGg1V0aWBT0YyouzGB2-QFNOVO86G7sYzU8FC6-V3Iyc4X7XTNc", + "tvm_id": 100502 + } + })"; + +static const TString TICKETS_SE = R"({})"; + +static const TInstant BIRTHTIME = TInstant::Seconds(14380887840); +class TTvmTool: public TRequestReplier { +public: + TString Meta; + HttpCodes Code; + TInstant Birthtime; + + TTvmTool() + : Meta(META) + , Code(HTTP_OK) + , Birthtime(BIRTHTIME) + { + } + + bool DoReply(const TReplyParams& params) override { + const TParsedHttpFull http(params.Input.FirstLine()); + if (http.Path == "/tvm/ping") { + THttpResponse resp(HTTP_OK); + resp.SetContent("OK"); + resp.OutTo(params.Output); + return true; + } + + auto it = std::find_if(params.Input.Headers().begin(), + params.Input.Headers().end(), + [](const THttpInputHeader& h) { return h.Name() == "Authorization"; }); + if (it == params.Input.Headers().end() || it->Value() != AUTH_TOKEN) { + THttpResponse resp(HTTP_UNAUTHORIZED); + resp.SetContent("pong"); + resp.OutTo(params.Output); + return true; + } + + THttpResponse resp(Code); + if (http.Path == "/tvm/keys") { + resp.SetContent(NTvmAuth::NUnittest::TVMKNIFE_PUBLIC_KEYS); + } else if (http.Path == "/tvm/tickets") { + TCgiParameters cg; + cg.ScanAddAll(http.Cgi); + if (cg.Get("src") == "100500") { + resp.SetContent(TICKETS_ME); + } else if (cg.Get("src") == "100501") { + resp.SetContent(TICKETS_PC); + } else if (cg.Get("src") == "100599") { + resp.SetContent(TICKETS_MANY_DSTS); + } + } else if (http.Path == "/tvm/private_api/__meta__") { + resp.SetContent(Meta); + } + resp.AddHeader("X-Ya-Tvmtool-Data-Birthtime", IntToString<10>(Birthtime.Seconds())); + resp.OutTo(params.Output); + + return true; + } +}; + +static inline NTvmAuth::NRoles::TEntitiesIndex CreateEntitiesIndex() { + using namespace NTvmAuth::NRoles; + + TEntitiesIndex index( + { + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }), + }); + + return index; +} diff --git a/library/cpp/tvmauth/client/ut/default_uid_checker_ut.cpp b/library/cpp/tvmauth/client/ut/default_uid_checker_ut.cpp index 57b96dfd9e..a92530cab1 100644 --- a/library/cpp/tvmauth/client/ut/default_uid_checker_ut.cpp +++ b/library/cpp/tvmauth/client/ut/default_uid_checker_ut.cpp @@ -1,52 +1,52 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/mocked_updater.h> -#include <library/cpp/tvmauth/client/misc/default_uid_checker.h> -#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> - -#include <library/cpp/tvmauth/type.h> -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(DefaultUidChecker) { - Y_UNIT_TEST(Ctor) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDefaultUidChecker(new TMockedUpdater), - TBrokenTvmClientSettings, - "Need to use TClientSettings::EnableRolesFetching"); - } - - Y_UNIT_TEST(Check) { - NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( - NRoles::TRoles::TMeta{}, - NRoles::TRoles::TTvmConsumers{}, - NRoles::TRoles::TUserConsumers{ - {12345, std::make_shared<NRoles::TConsumerRoles>( - THashMap<TString, NRoles::TEntitiesPtr>())}, - }, - std::make_shared<TString>()); - const TDefaultUidChecker checker(new TMockedUpdater({.Roles = roles})); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Expired, 12345, {})), - TIllegalUsage, - "User ticket must be valid"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 12345, {}, {}, EBlackboxEnv::Test)), - TIllegalUsage, - "User ticket must be from ProdYateam, got from Test"); - - TCheckedUserTicket ticket; - UNIT_ASSERT_NO_EXCEPTION( - ticket = checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 12345, {}, {}, EBlackboxEnv::ProdYateam))); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); - - UNIT_ASSERT_NO_EXCEPTION( - ticket = checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 9999, {}, {}, EBlackboxEnv::ProdYateam))); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, ticket.GetStatus()); - } -} +#include "common.h" + +#include <library/cpp/tvmauth/client/mocked_updater.h> +#include <library/cpp/tvmauth/client/misc/default_uid_checker.h> +#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> + +#include <library/cpp/tvmauth/type.h> +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(DefaultUidChecker) { + Y_UNIT_TEST(Ctor) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDefaultUidChecker(new TMockedUpdater), + TBrokenTvmClientSettings, + "Need to use TClientSettings::EnableRolesFetching"); + } + + Y_UNIT_TEST(Check) { + NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( + NRoles::TRoles::TMeta{}, + NRoles::TRoles::TTvmConsumers{}, + NRoles::TRoles::TUserConsumers{ + {12345, std::make_shared<NRoles::TConsumerRoles>( + THashMap<TString, NRoles::TEntitiesPtr>())}, + }, + std::make_shared<TString>()); + const TDefaultUidChecker checker(new TMockedUpdater({.Roles = roles})); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Expired, 12345, {})), + TIllegalUsage, + "User ticket must be valid"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 12345, {}, {}, EBlackboxEnv::Test)), + TIllegalUsage, + "User ticket must be from ProdYateam, got from Test"); + + TCheckedUserTicket ticket; + UNIT_ASSERT_NO_EXCEPTION( + ticket = checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 12345, {}, {}, EBlackboxEnv::ProdYateam))); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); + + UNIT_ASSERT_NO_EXCEPTION( + ticket = checker.Check(NUnittest::CreateUserTicket(ETicketStatus::Ok, 9999, {}, {}, EBlackboxEnv::ProdYateam))); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, ticket.GetStatus()); + } +} diff --git a/library/cpp/tvmauth/client/ut/disk_cache_ut.cpp b/library/cpp/tvmauth/client/ut/disk_cache_ut.cpp index 5d99927c6c..7dd851c9b3 100644 --- a/library/cpp/tvmauth/client/ut/disk_cache_ut.cpp +++ b/library/cpp/tvmauth/client/ut/disk_cache_ut.cpp @@ -1,204 +1,204 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/logger.h> -#include <library/cpp/tvmauth/client/misc/disk_cache.h> - -#include <library/cpp/tvmauth/src/utils.h> - +#include "common.h" + +#include <library/cpp/tvmauth/client/logger.h> +#include <library/cpp/tvmauth/client/misc/disk_cache.h> + +#include <library/cpp/tvmauth/src/utils.h> + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> - -#include <util/stream/file.h> -#include <util/system/fs.h> -#include <util/system/sysstat.h> - -#include <thread> - -using namespace NTvmAuth; - + +#include <util/stream/file.h> +#include <util/system/fs.h> +#include <util/system/sysstat.h> + +#include <thread> + +using namespace NTvmAuth; + Y_UNIT_TEST_SUITE(ClientDisk) { Y_UNIT_TEST(Hash) { - TString hash = TDiskReader::GetHash("asd"); - UNIT_ASSERT(hash); - UNIT_ASSERT_VALUES_EQUAL(32, hash.size()); + TString hash = TDiskReader::GetHash("asd"); + UNIT_ASSERT(hash); + UNIT_ASSERT_VALUES_EQUAL(32, hash.size()); UNIT_ASSERT_VALUES_EQUAL("Zj5_qYg31bPlqjBW76z8IV0rCsHmv-iN-McV6ybS1-g", NUtils::Bin2base64url(hash)); - } - + } + Y_UNIT_TEST(Timestamp) { - time_t t = 100500; - - TString s = TDiskWriter::WriteTimestamp(t); + time_t t = 100500; + + TString s = TDiskWriter::WriteTimestamp(t); UNIT_ASSERT_VALUES_EQUAL("lIgBAAAAAAA", NUtils::Bin2base64url(s)); - UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); - - t = 123123123213089; - s = TDiskWriter::WriteTimestamp(t); + UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); + + t = 123123123213089; + s = TDiskWriter::WriteTimestamp(t); UNIT_ASSERT_VALUES_EQUAL("IdMF1vpvAAA", NUtils::Bin2base64url(s)); - UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); - - t = time(nullptr); - s = TDiskWriter::WriteTimestamp(t); - UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); - } - - const TInstant TIME = TInstant::Seconds(100500); - const TString DATA = "oiweuhn \n vw3ut hweoi uhgewproritjhwequtherwoiughfdsv 8ty34q01u 34 1=3"; - + UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); + + t = time(nullptr); + s = TDiskWriter::WriteTimestamp(t); + UNIT_ASSERT_VALUES_EQUAL(t, TDiskReader::GetTimestamp(s)); + } + + const TInstant TIME = TInstant::Seconds(100500); + const TString DATA = "oiweuhn \n vw3ut hweoi uhgewproritjhwequtherwoiughfdsv 8ty34q01u 34 1=3"; + Y_UNIT_TEST(ParseData_Ok) { - TLogger l; - - const TInstant time = TInstant::Seconds(1523446554789); - - TString toFile = TDiskWriter::PrepareData(time, DATA); - UNIT_ASSERT_VALUES_EQUAL(113, toFile.size()); - UNIT_ASSERT_VALUES_EQUAL("T8BnRIMoC6mlMXexPg9cV5jYxeFtgDWk97JTajHDunCloH20YgEAAG9pd2V1aG4gCiB2dzN1dCBod2VvaSB1aGdld3Byb3JpdGpod2VxdXRoZXJ3b2l1Z2hmZHN2IDh0eTM0cTAxdSAgIDM0ICAxPTM", - NUtils::Bin2base64url(toFile)); - - TDiskReader r("qwerty", &l); - UNIT_ASSERT(r.ParseData(toFile)); + TLogger l; + + const TInstant time = TInstant::Seconds(1523446554789); + + TString toFile = TDiskWriter::PrepareData(time, DATA); + UNIT_ASSERT_VALUES_EQUAL(113, toFile.size()); + UNIT_ASSERT_VALUES_EQUAL("T8BnRIMoC6mlMXexPg9cV5jYxeFtgDWk97JTajHDunCloH20YgEAAG9pd2V1aG4gCiB2dzN1dCBod2VvaSB1aGdld3Byb3JpdGpod2VxdXRoZXJ3b2l1Z2hmZHN2IDh0eTM0cTAxdSAgIDM0ICAxPTM", + NUtils::Bin2base64url(toFile)); + + TDiskReader r("qwerty", &l); + UNIT_ASSERT(r.ParseData(toFile)); UNIT_ASSERT_VALUES_EQUAL(DATA, r.Data()); - UNIT_ASSERT_VALUES_EQUAL(time, r.Time()); + UNIT_ASSERT_VALUES_EQUAL(time, r.Time()); UNIT_ASSERT_VALUES_EQUAL("6: File 'qwerty' was successfully read\n", - l.Stream.Str()); - } - + l.Stream.Str()); + } + Y_UNIT_TEST(ParseData_SmallFile) { - TLogger l; - - TString toFile = TDiskWriter::PrepareData(TIME, DATA); - TDiskReader r("qwerty", &l); - UNIT_ASSERT(!r.ParseData(toFile.substr(0, 17))); + TLogger l; + + TString toFile = TDiskWriter::PrepareData(TIME, DATA); + TDiskReader r("qwerty", &l); + UNIT_ASSERT(!r.ParseData(toFile.substr(0, 17))); UNIT_ASSERT_VALUES_EQUAL("4: File 'qwerty' is too small\n", - l.Stream.Str()); - } - + l.Stream.Str()); + } + Y_UNIT_TEST(ParseData_Changed) { - TLogger l; - - TString toFile = TDiskWriter::PrepareData(TIME, DATA); - toFile[17] = toFile[17] + 1; - TDiskReader r("qwerty", &l); - UNIT_ASSERT(!r.ParseData(toFile)); + TLogger l; + + TString toFile = TDiskWriter::PrepareData(TIME, DATA); + toFile[17] = toFile[17] + 1; + TDiskReader r("qwerty", &l); + UNIT_ASSERT(!r.ParseData(toFile)); UNIT_ASSERT_VALUES_EQUAL("4: Content of 'qwerty' was incorrectly changed\n", - l.Stream.Str()); - } - + l.Stream.Str()); + } + Y_UNIT_TEST(Read_Ok) { - TLogger l; - - TDiskReader r(GetFilePath("ok.cache"), &l); - UNIT_ASSERT(r.Read()); + TLogger l; + + TDiskReader r(GetFilePath("ok.cache"), &l); + UNIT_ASSERT(r.Read()); UNIT_ASSERT_VALUES_EQUAL(DATA, r.Data()); - UNIT_ASSERT_VALUES_EQUAL(TIME, r.Time()); - UNIT_ASSERT_C(l.Stream.Str().find("was successfully read") != TString::npos, l.Stream.Str()); - } - + UNIT_ASSERT_VALUES_EQUAL(TIME, r.Time()); + UNIT_ASSERT_C(l.Stream.Str().find("was successfully read") != TString::npos, l.Stream.Str()); + } + Y_UNIT_TEST(Read_NoFile) { - TLogger l; - - TDiskReader r("missing", &l); - UNIT_ASSERT(!r.Read()); + TLogger l; + + TDiskReader r("missing", &l); + UNIT_ASSERT(!r.Read()); UNIT_ASSERT_VALUES_EQUAL("7: File 'missing' does not exist\n", - l.Stream.Str()); - } - -#ifdef _unix_ + l.Stream.Str()); + } + +#ifdef _unix_ Y_UNIT_TEST(Read_NoPermitions) { - TLogger l; - - const TString path = GetWorkPath() + "/123"; - { - TFileOutput output(path); - } - Chmod(path.data(), S_IWUSR); - - TDiskReader r(path, &l); - UNIT_ASSERT(!r.Read()); - UNIT_ASSERT_C(l.Stream.Str().find("Permission denied") != TString::npos, l.Stream.Str()); - - Chmod(path.data(), S_IRWXU); - NFs::Remove(path); - } -#endif - + TLogger l; + + const TString path = GetWorkPath() + "/123"; + { + TFileOutput output(path); + } + Chmod(path.data(), S_IWUSR); + + TDiskReader r(path, &l); + UNIT_ASSERT(!r.Read()); + UNIT_ASSERT_C(l.Stream.Str().find("Permission denied") != TString::npos, l.Stream.Str()); + + Chmod(path.data(), S_IRWXU); + NFs::Remove(path); + } +#endif + Y_UNIT_TEST(Write_Ok) { - TLogger l; - - const TString path = "./tmp_file"; - TDiskWriter w(path, &l); - UNIT_ASSERT_C(w.Write(DATA), l.Stream.Str()); - UNIT_ASSERT_C(l.Stream.Str().find("was successfully written") != TString::npos, l.Stream.Str()); - l.Stream.Clear(); - - TDiskReader r(path, &l); - UNIT_ASSERT_C(r.Read(), l.Stream.Str()); + TLogger l; + + const TString path = "./tmp_file"; + TDiskWriter w(path, &l); + UNIT_ASSERT_C(w.Write(DATA), l.Stream.Str()); + UNIT_ASSERT_C(l.Stream.Str().find("was successfully written") != TString::npos, l.Stream.Str()); + l.Stream.Clear(); + + TDiskReader r(path, &l); + UNIT_ASSERT_C(r.Read(), l.Stream.Str()); UNIT_ASSERT_VALUES_EQUAL(DATA, r.Data()); - UNIT_ASSERT(TInstant::Now() - r.Time() < TDuration::Minutes(5)); - UNIT_ASSERT_C(l.Stream.Str().find("was successfully read") != TString::npos, l.Stream.Str()); - - NFs::Remove(path); - } - + UNIT_ASSERT(TInstant::Now() - r.Time() < TDuration::Minutes(5)); + UNIT_ASSERT_C(l.Stream.Str().find("was successfully read") != TString::npos, l.Stream.Str()); + + NFs::Remove(path); + } + Y_UNIT_TEST(Write_NoPermitions) { - TLogger l; - - TDiskWriter w("/some_file", &l); - UNIT_ASSERT(!w.Write(DATA)); - UNIT_ASSERT_C(l.Stream.Str().Contains("3: Failed to write '/some_file': ("), l.Stream.Str()); - UNIT_ASSERT_C(l.Stream.Str().Contains("denied"), l.Stream.Str()); - } - - Y_UNIT_TEST(race) { - const TString path = "./tmp_file"; - const TString data = "ejufhsadkjfvbhsaoicnaofssdahfasdfhasdofdsaf"; - NFs::Remove(path); - - std::atomic<bool> fail = false; - std::vector<std::thread> thrs; - for (size_t idx = 0; idx < 16; ++idx) { - thrs.push_back(std::thread([&fail, data, path]() { - TDiskWriter w(path); - for (size_t k = 0; k < 1000; ++k) { - if (!w.Write(data)) { - fail = true; - } - } - })); - } - for (std::thread& t : thrs) { - t.join(); - } - thrs.clear(); - UNIT_ASSERT(fail); - { - TDiskWriter w(path); - UNIT_ASSERT(w.Write(data)); // checks unlocked flock - } - - fail = false; - - for (size_t idx = 0; idx < 4; ++idx) { - thrs.push_back(std::thread([&fail, data, path]() { - TLogger l; - TDiskReader r(path, &l); - for (size_t k = 0; k < 100; ++k) { - if (!r.Read()) { - Cerr << l.Stream.Str() << Flush; - fail = true; - return; - } - if (r.Data() != data) { - Cerr << (TStringBuilder() << "'" << data << "' vs '" << r.Data() << "'" << Endl) << Flush; - fail = true; - return; - } - } - })); - } - for (std::thread& t : thrs) { - t.join(); - } - thrs.clear(); - UNIT_ASSERT(!fail); - } -} + TLogger l; + + TDiskWriter w("/some_file", &l); + UNIT_ASSERT(!w.Write(DATA)); + UNIT_ASSERT_C(l.Stream.Str().Contains("3: Failed to write '/some_file': ("), l.Stream.Str()); + UNIT_ASSERT_C(l.Stream.Str().Contains("denied"), l.Stream.Str()); + } + + Y_UNIT_TEST(race) { + const TString path = "./tmp_file"; + const TString data = "ejufhsadkjfvbhsaoicnaofssdahfasdfhasdofdsaf"; + NFs::Remove(path); + + std::atomic<bool> fail = false; + std::vector<std::thread> thrs; + for (size_t idx = 0; idx < 16; ++idx) { + thrs.push_back(std::thread([&fail, data, path]() { + TDiskWriter w(path); + for (size_t k = 0; k < 1000; ++k) { + if (!w.Write(data)) { + fail = true; + } + } + })); + } + for (std::thread& t : thrs) { + t.join(); + } + thrs.clear(); + UNIT_ASSERT(fail); + { + TDiskWriter w(path); + UNIT_ASSERT(w.Write(data)); // checks unlocked flock + } + + fail = false; + + for (size_t idx = 0; idx < 4; ++idx) { + thrs.push_back(std::thread([&fail, data, path]() { + TLogger l; + TDiskReader r(path, &l); + for (size_t k = 0; k < 100; ++k) { + if (!r.Read()) { + Cerr << l.Stream.Str() << Flush; + fail = true; + return; + } + if (r.Data() != data) { + Cerr << (TStringBuilder() << "'" << data << "' vs '" << r.Data() << "'" << Endl) << Flush; + fail = true; + return; + } + } + })); + } + for (std::thread& t : thrs) { + t.join(); + } + thrs.clear(); + UNIT_ASSERT(!fail); + } +} diff --git a/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp b/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp index 11e735f836..3dcbe6ad49 100644 --- a/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp +++ b/library/cpp/tvmauth/client/ut/exponential_backoff_ut.cpp @@ -1,44 +1,44 @@ -#include <library/cpp/tvmauth/client/misc/exponential_backoff.h> - +#include <library/cpp/tvmauth/client/misc/exponential_backoff.h> + #include <library/cpp/testing/unittest/registar.h> - -#include <thread> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(PasspUtilsExpBackoff) { - Y_UNIT_TEST(common) { - TExponentialBackoff b({TDuration::Seconds(1), TDuration::Seconds(60), 2, 0.01}); - - UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(1), b.GetCurrentValue()); - - TDuration dur = b.GetCurrentValue(); - for (size_t idx = 0; idx < 6; ++idx) { - TDuration newValue = b.Increase(); - UNIT_ASSERT_LT(dur, newValue); - dur = newValue; - } - - UNIT_ASSERT_LT(TDuration::Seconds(60) - TDuration::Seconds(3), dur); - UNIT_ASSERT_LT(dur, TDuration::Seconds(60) + TDuration::Seconds(3)); - } - - Y_UNIT_TEST(sleep) { - TExponentialBackoff b({TDuration::Seconds(60), TDuration::Seconds(600), 2, 0.01}); - - const TInstant start = TInstant::Now(); - - TAutoEvent started; - std::thread t([&b, &started]() { - started.Signal(); - b.Sleep(); - }); - - started.WaitT(TDuration::Seconds(30)); - b.Interrupt(); - t.join(); - TDuration dur = TInstant::Now() - start; - - UNIT_ASSERT_LT(dur, TDuration::Seconds(60)); - } -} + +#include <thread> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(PasspUtilsExpBackoff) { + Y_UNIT_TEST(common) { + TExponentialBackoff b({TDuration::Seconds(1), TDuration::Seconds(60), 2, 0.01}); + + UNIT_ASSERT_VALUES_EQUAL(TDuration::Seconds(1), b.GetCurrentValue()); + + TDuration dur = b.GetCurrentValue(); + for (size_t idx = 0; idx < 6; ++idx) { + TDuration newValue = b.Increase(); + UNIT_ASSERT_LT(dur, newValue); + dur = newValue; + } + + UNIT_ASSERT_LT(TDuration::Seconds(60) - TDuration::Seconds(3), dur); + UNIT_ASSERT_LT(dur, TDuration::Seconds(60) + TDuration::Seconds(3)); + } + + Y_UNIT_TEST(sleep) { + TExponentialBackoff b({TDuration::Seconds(60), TDuration::Seconds(600), 2, 0.01}); + + const TInstant start = TInstant::Now(); + + TAutoEvent started; + std::thread t([&b, &started]() { + started.Signal(); + b.Sleep(); + }); + + started.WaitT(TDuration::Seconds(30)); + b.Interrupt(); + t.join(); + TDuration dur = TInstant::Now() - start; + + UNIT_ASSERT_LT(dur, TDuration::Seconds(60)); + } +} diff --git a/library/cpp/tvmauth/client/ut/facade_ut.cpp b/library/cpp/tvmauth/client/ut/facade_ut.cpp index d3d33e8b81..62e8e6c731 100644 --- a/library/cpp/tvmauth/client/ut/facade_ut.cpp +++ b/library/cpp/tvmauth/client/ut/facade_ut.cpp @@ -1,167 +1,167 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/facade.h> -#include <library/cpp/tvmauth/client/mocked_updater.h> - +#include "common.h" + +#include <library/cpp/tvmauth/client/facade.h> +#include <library/cpp/tvmauth/client/mocked_updater.h> + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/vector.h> - -using namespace NTvmAuth; - + +#include <util/generic/vector.h> + +using namespace NTvmAuth; + Y_UNIT_TEST_SUITE(ClientFacade) { - static const TTvmId OK_CLIENT = 100500; - static const TString SRV_TICKET_123 = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; - static const TString SRV_TICKET_456 = "3:serv:CBAQ__________9_IgcIyAMQlJEG:VrnqRhpoiDnJeAQbySJluJ1moQ5Kemic99iWzOrHLGfuh7iTw_xMT7KewRAmZMUwDKzE6otj7V86Xsnxbv5xZl8746wbvNcyUXu-nGWmbByZjO7xpSIcY07sISqEhP9n9C_yMSvqDP7ho_PRIfpGCDMXxKlFZ_BhBLLp0kHEvw4"; - 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"; - - TTvmClient GetClient(const NTvmApi::TClientSettings& s) { - auto l = MakeIntrusive<TLogger>(); - TTvmClient f(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, f.GetStatus()); - Sleep(TDuration::MilliSeconds(300)); - TString logs = l->Stream.Str(); - UNIT_ASSERT_C(logs.find("was successfully read") != TString::npos, logs); - UNIT_ASSERT_C(logs.find("was successfully fetched") == TString::npos, logs); - return f; - } - + static const TTvmId OK_CLIENT = 100500; + static const TString SRV_TICKET_123 = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; + static const TString SRV_TICKET_456 = "3:serv:CBAQ__________9_IgcIyAMQlJEG:VrnqRhpoiDnJeAQbySJluJ1moQ5Kemic99iWzOrHLGfuh7iTw_xMT7KewRAmZMUwDKzE6otj7V86Xsnxbv5xZl8746wbvNcyUXu-nGWmbByZjO7xpSIcY07sISqEhP9n9C_yMSvqDP7ho_PRIfpGCDMXxKlFZ_BhBLLp0kHEvw4"; + 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"; + + TTvmClient GetClient(const NTvmApi::TClientSettings& s) { + auto l = MakeIntrusive<TLogger>(); + TTvmClient f(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, f.GetStatus()); + Sleep(TDuration::MilliSeconds(300)); + TString logs = l->Stream.Str(); + UNIT_ASSERT_C(logs.find("was successfully read") != TString::npos, logs); + UNIT_ASSERT_C(logs.find("was successfully fetched") == TString::npos, logs); + return f; + } + Y_UNIT_TEST(Service) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(OK_CLIENT); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(GetCachePath()); - TTvmClient f = GetClient(s); - - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(2524608000), f.GetUpdateTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetUpdateTimeOfServiceTickets()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(2525126400), f.GetInvalidationTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetInvalidationTimeOfServiceTickets()); - - UNIT_ASSERT(f.CheckServiceTicket(SRV_TICKET_123)); - UNIT_ASSERT_EXCEPTION(f.CheckUserTicket(PROD_TICKET), yexception); - UNIT_ASSERT_EXCEPTION(f.CheckUserTicket(TEST_TICKET), yexception); - } - + NTvmApi::TClientSettings s; + s.SetSelfTvmId(OK_CLIENT); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(GetCachePath()); + TTvmClient f = GetClient(s); + + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(2524608000), f.GetUpdateTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetUpdateTimeOfServiceTickets()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(2525126400), f.GetInvalidationTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetInvalidationTimeOfServiceTickets()); + + UNIT_ASSERT(f.CheckServiceTicket(SRV_TICKET_123)); + UNIT_ASSERT_EXCEPTION(f.CheckUserTicket(PROD_TICKET), yexception); + UNIT_ASSERT_EXCEPTION(f.CheckUserTicket(TEST_TICKET), yexception); + } + Y_UNIT_TEST(User) { - NTvmApi::TClientSettings s; - s.EnableUserTicketChecking(EBlackboxEnv::Prod); - s.SetDiskCacheDir(GetCachePath()); - - TTvmClient f = GetClient(s); - UNIT_ASSERT_EXCEPTION(f.CheckServiceTicket(SRV_TICKET_123), yexception); - UNIT_ASSERT(f.CheckUserTicket(PROD_TICKET)); - UNIT_ASSERT(!f.CheckUserTicket(TEST_TICKET)); - } - + NTvmApi::TClientSettings s; + s.EnableUserTicketChecking(EBlackboxEnv::Prod); + s.SetDiskCacheDir(GetCachePath()); + + TTvmClient f = GetClient(s); + UNIT_ASSERT_EXCEPTION(f.CheckServiceTicket(SRV_TICKET_123), yexception); + UNIT_ASSERT(f.CheckUserTicket(PROD_TICKET)); + UNIT_ASSERT(!f.CheckUserTicket(TEST_TICKET)); + } + Y_UNIT_TEST(Ctors) { - NTvmApi::TClientSettings s; - s.EnableUserTicketChecking(EBlackboxEnv::Prod); - s.SetDiskCacheDir(GetCachePath()); - - TTvmClient f = GetClient(s); - f = GetClient(s); - - TVector<TTvmClient> v; - v.push_back(std::move(f)); - v.front() = std::move(*v.begin()); - } - + NTvmApi::TClientSettings s; + s.EnableUserTicketChecking(EBlackboxEnv::Prod); + s.SetDiskCacheDir(GetCachePath()); + + TTvmClient f = GetClient(s); + f = GetClient(s); + + TVector<TTvmClient> v; + v.push_back(std::move(f)); + v.front() = std::move(*v.begin()); + } + Y_UNIT_TEST(Tickets) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(OK_CLIENT); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(GetCachePath()); - TTvmClient f = GetClient(s); - - UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetUpdateTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::ParseIso8601("2050-01-01T00:00:00.000000Z"), f.GetUpdateTimeOfServiceTickets()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetInvalidationTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<size_t>::max()), f.GetInvalidationTimeOfServiceTickets()); - - UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", f.GetServiceTicketFor("blackbox")); - UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", f.GetServiceTicketFor(19)); - UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor("blackbox2"), - TBrokenTvmClientSettings, - "Destination 'blackbox2' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); - UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor(20), - TBrokenTvmClientSettings, - "Destination '20' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); - } - - Y_UNIT_TEST(Tool) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - - NTvmTool::TClientSettings s("push-client"); - s.SetPort(port); - s.SetAuthToken(AUTH_TOKEN); - auto l = MakeIntrusive<TLogger>(); - { - TTvmClient f(s, l); - - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14380887840), f.GetUpdateTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14380887840), f.GetUpdateTimeOfServiceTickets()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14381406240), f.GetInvalidationTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), f.GetInvalidationTimeOfServiceTickets()); - - UNIT_ASSERT_VALUES_EQUAL(SERVICE_TICKET_PC, f.GetServiceTicketFor("pass_likers")); - UNIT_ASSERT_VALUES_EQUAL(SERVICE_TICKET_PC, f.GetServiceTicketFor(100502)); - UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor("blackbox"), - TBrokenTvmClientSettings, - "Destination 'blackbox' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); - UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor(242), - TBrokenTvmClientSettings, - "Destination '242' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100501, bb_env=ProdYateam, dsts=[(pass_likers:100502)]\n" - << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(CheckRoles) { - { // roles not configured - TTvmClient f(new TMockedUpdater(TMockedUpdater::TSettings{ - .SelfTvmId = OK_CLIENT, - })); - - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, - f.CheckServiceTicket(SRV_TICKET_123).GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, - f.CheckServiceTicket(SRV_TICKET_456).GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Malformed, - f.CheckServiceTicket("asdfg").GetStatus()); - } - - { // roles configured - NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( - NRoles::TRoles::TMeta{}, - NRoles::TRoles::TTvmConsumers{ - {123, std::make_shared<NRoles::TConsumerRoles>( - THashMap<TString, NRoles::TEntitiesPtr>())}, - }, - NRoles::TRoles::TUserConsumers{}, - std::make_shared<TString>()); - TTvmClient f(new TMockedUpdater(TMockedUpdater::TSettings{ - .SelfTvmId = OK_CLIENT, - .Roles = roles, - })); - - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, - f.CheckServiceTicket(SRV_TICKET_123).GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, - f.CheckServiceTicket(SRV_TICKET_456).GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Malformed, - f.CheckServiceTicket("asdfg").GetStatus()); - } - } -} + NTvmApi::TClientSettings s; + s.SetSelfTvmId(OK_CLIENT); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(GetCachePath()); + TTvmClient f = GetClient(s); + + UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetUpdateTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::ParseIso8601("2050-01-01T00:00:00.000000Z"), f.GetUpdateTimeOfServiceTickets()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), f.GetInvalidationTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<size_t>::max()), f.GetInvalidationTimeOfServiceTickets()); + + UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", f.GetServiceTicketFor("blackbox")); + UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIKhCUkQY:CX", f.GetServiceTicketFor(19)); + UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor("blackbox2"), + TBrokenTvmClientSettings, + "Destination 'blackbox2' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); + UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor(20), + TBrokenTvmClientSettings, + "Destination '20' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); + } + + Y_UNIT_TEST(Tool) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + + NTvmTool::TClientSettings s("push-client"); + s.SetPort(port); + s.SetAuthToken(AUTH_TOKEN); + auto l = MakeIntrusive<TLogger>(); + { + TTvmClient f(s, l); + + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14380887840), f.GetUpdateTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14380887840), f.GetUpdateTimeOfServiceTickets()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(14381406240), f.GetInvalidationTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), f.GetInvalidationTimeOfServiceTickets()); + + UNIT_ASSERT_VALUES_EQUAL(SERVICE_TICKET_PC, f.GetServiceTicketFor("pass_likers")); + UNIT_ASSERT_VALUES_EQUAL(SERVICE_TICKET_PC, f.GetServiceTicketFor(100502)); + UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor("blackbox"), + TBrokenTvmClientSettings, + "Destination 'blackbox' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); + UNIT_ASSERT_EXCEPTION_CONTAINS(f.GetServiceTicketFor(242), + TBrokenTvmClientSettings, + "Destination '242' was not specified in settings. Check your settings (if you use Qloud/YP/tvmtool - check it's settings)"); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100501, bb_env=ProdYateam, dsts=[(pass_likers:100502)]\n" + << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(CheckRoles) { + { // roles not configured + TTvmClient f(new TMockedUpdater(TMockedUpdater::TSettings{ + .SelfTvmId = OK_CLIENT, + })); + + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, + f.CheckServiceTicket(SRV_TICKET_123).GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, + f.CheckServiceTicket(SRV_TICKET_456).GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Malformed, + f.CheckServiceTicket("asdfg").GetStatus()); + } + + { // roles configured + NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( + NRoles::TRoles::TMeta{}, + NRoles::TRoles::TTvmConsumers{ + {123, std::make_shared<NRoles::TConsumerRoles>( + THashMap<TString, NRoles::TEntitiesPtr>())}, + }, + NRoles::TRoles::TUserConsumers{}, + std::make_shared<TString>()); + TTvmClient f(new TMockedUpdater(TMockedUpdater::TSettings{ + .SelfTvmId = OK_CLIENT, + .Roles = roles, + })); + + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, + f.CheckServiceTicket(SRV_TICKET_123).GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, + f.CheckServiceTicket(SRV_TICKET_456).GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Malformed, + f.CheckServiceTicket("asdfg").GetStatus()); + } + } +} diff --git a/library/cpp/tvmauth/client/ut/files/public_keys b/library/cpp/tvmauth/client/ut/files/public_keys Binary files differnew file mode 100644 index 0000000000..fa683d18f3 --- /dev/null +++ b/library/cpp/tvmauth/client/ut/files/public_keys diff --git a/library/cpp/tvmauth/client/ut/last_error_ut.cpp b/library/cpp/tvmauth/client/ut/last_error_ut.cpp index 9d4f951762..6751e78be7 100644 --- a/library/cpp/tvmauth/client/ut/last_error_ut.cpp +++ b/library/cpp/tvmauth/client/ut/last_error_ut.cpp @@ -1,56 +1,56 @@ -#include <library/cpp/tvmauth/client/misc/last_error.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(LastError) { - Y_UNIT_TEST(common) { - TLastError le; - - UNIT_ASSERT_VALUES_EQUAL("OK", - le.GetLastError(true)); - UNIT_ASSERT_VALUES_EQUAL("Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru", - le.GetLastError(false)); - - UNIT_ASSERT_EXCEPTION_CONTAINS(le.ThrowLastError(), - TNonRetriableException, - "Internal client error: failed to collect last useful error message"); - - le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#1"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_re#1", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#2"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_re#2", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::PublicKeys, "err_nonre#3"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#3", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::PublicKeys, "err_nonre#4"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#5"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", - le.GetLastError(false)); - UNIT_ASSERT_EXCEPTION_CONTAINS(le.ThrowLastError(), - TNonRetriableException, - "Failed to start TvmClient. Do not retry: PublicKeys: err_nonre#4"); - - le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::ServiceTickets, "err_re#6"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::ServiceTickets, "err_re#7"); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", - le.GetLastError(false)); - le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::ServiceTickets, "err_nonre#8"); - UNIT_ASSERT_VALUES_EQUAL("ServiceTickets: err_nonre#8", - le.GetLastError(false)); - - le.ClearError(TLastError::EScope::ServiceTickets); - UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", - le.GetLastError(false)); - le.ClearError(TLastError::EScope::PublicKeys); - UNIT_ASSERT_VALUES_EQUAL("Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru", - le.GetLastError(false)); - } -} +#include <library/cpp/tvmauth/client/misc/last_error.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(LastError) { + Y_UNIT_TEST(common) { + TLastError le; + + UNIT_ASSERT_VALUES_EQUAL("OK", + le.GetLastError(true)); + UNIT_ASSERT_VALUES_EQUAL("Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru", + le.GetLastError(false)); + + UNIT_ASSERT_EXCEPTION_CONTAINS(le.ThrowLastError(), + TNonRetriableException, + "Internal client error: failed to collect last useful error message"); + + le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#1"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_re#1", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#2"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_re#2", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::PublicKeys, "err_nonre#3"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#3", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::PublicKeys, "err_nonre#4"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::PublicKeys, "err_re#5"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", + le.GetLastError(false)); + UNIT_ASSERT_EXCEPTION_CONTAINS(le.ThrowLastError(), + TNonRetriableException, + "Failed to start TvmClient. Do not retry: PublicKeys: err_nonre#4"); + + le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::ServiceTickets, "err_re#6"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::Retriable, TLastError::EScope::ServiceTickets, "err_re#7"); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", + le.GetLastError(false)); + le.ProcessError(TLastError::EType::NonRetriable, TLastError::EScope::ServiceTickets, "err_nonre#8"); + UNIT_ASSERT_VALUES_EQUAL("ServiceTickets: err_nonre#8", + le.GetLastError(false)); + + le.ClearError(TLastError::EScope::ServiceTickets); + UNIT_ASSERT_VALUES_EQUAL("PublicKeys: err_nonre#4", + le.GetLastError(false)); + le.ClearError(TLastError::EScope::PublicKeys); + UNIT_ASSERT_VALUES_EQUAL("Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru", + le.GetLastError(false)); + } +} diff --git a/library/cpp/tvmauth/client/ut/logger_ut.cpp b/library/cpp/tvmauth/client/ut/logger_ut.cpp index e84a123c79..76236e8913 100644 --- a/library/cpp/tvmauth/client/ut/logger_ut.cpp +++ b/library/cpp/tvmauth/client/ut/logger_ut.cpp @@ -1,43 +1,43 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/logger.h> - +#include "common.h" + +#include <library/cpp/tvmauth/client/logger.h> + #include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - + +using namespace NTvmAuth; + Y_UNIT_TEST_SUITE(ClientLogger) { - int i = 0; - + int i = 0; + Y_UNIT_TEST(Debug) { - TLogger l; - l.Debug("qwerty"); - UNIT_ASSERT_VALUES_EQUAL("7: qwerty\n", l.Stream.Str()); - } - + TLogger l; + l.Debug("qwerty"); + UNIT_ASSERT_VALUES_EQUAL("7: qwerty\n", l.Stream.Str()); + } + Y_UNIT_TEST(Info) { - TLogger l; - l.Info("qwerty"); - UNIT_ASSERT_VALUES_EQUAL("6: qwerty\n", l.Stream.Str()); - } - + TLogger l; + l.Info("qwerty"); + UNIT_ASSERT_VALUES_EQUAL("6: qwerty\n", l.Stream.Str()); + } + Y_UNIT_TEST(Warning) { - TLogger l; - l.Warning("qwerty"); - UNIT_ASSERT_VALUES_EQUAL("4: qwerty\n", l.Stream.Str()); - } - + TLogger l; + l.Warning("qwerty"); + UNIT_ASSERT_VALUES_EQUAL("4: qwerty\n", l.Stream.Str()); + } + Y_UNIT_TEST(Error) { - TLogger l; - l.Error("qwerty"); - UNIT_ASSERT_VALUES_EQUAL("3: qwerty\n", l.Stream.Str()); - } - -#ifdef _unix_ + TLogger l; + l.Error("qwerty"); + UNIT_ASSERT_VALUES_EQUAL("3: qwerty\n", l.Stream.Str()); + } + +#ifdef _unix_ Y_UNIT_TEST(Cerr_) { - TCerrLogger l(5); - l.Error("hit"); - l.Debug("miss"); - } -#endif -} + TCerrLogger l(5); + l.Error("hit"); + l.Debug("miss"); + } +#endif +} diff --git a/library/cpp/tvmauth/client/ut/roles/decoder_ut.cpp b/library/cpp/tvmauth/client/ut/roles/decoder_ut.cpp index 28984bc1d5..0ee5fc7cb7 100644 --- a/library/cpp/tvmauth/client/ut/roles/decoder_ut.cpp +++ b/library/cpp/tvmauth/client/ut/roles/decoder_ut.cpp @@ -1,163 +1,163 @@ -#include <library/cpp/tvmauth/client/exception.h> -#include <library/cpp/tvmauth/client/misc/roles/decoder.h> - -#include <library/cpp/tvmauth/unittest.h> -#include <library/cpp/tvmauth/src/utils.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; -using namespace NTvmAuth::NRoles; - -Y_UNIT_TEST_SUITE(Decoder) { - const TString BROTLI = NUtils::Base64url2bin("GyMAAAR0Y6ku58ObclAQzDweUSUwbdqc5yOOKgI"); - const TString GZIP = NUtils::Base64url2bin("H4sIAAAAAAAA_yrOz01VKEstqkTGCpm5BflFJYl5JQpJOflJgAAAAP__MbeeiSQAAAA"); - const TString ZSTD = NUtils::Base64url2bin("KLUv_QBY9AAAwHNvbWUgdmVyeSBpbXBvcnRhbnQgYmxvYgEAc-4IAQAA"); - - Y_UNIT_TEST(Decode) { - // Errs - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::Decode( - "1:brotli:10000:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", - TString(BROTLI)), - yexception, - "Decoded blob has bad size: expected 10000, actual 36"); - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::Decode( - "1:brotli:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF0000", - TString(BROTLI)), - yexception, - "Decoded blob has bad sha256"); - - // OK - TString decoded; - UNIT_ASSERT_NO_EXCEPTION( - decoded = TDecoder::Decode("", "some veryveryveryvery important blob")); - UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); - - UNIT_ASSERT_NO_EXCEPTION( - decoded = TDecoder::Decode( - "1:brotli:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", - TString(BROTLI))); - UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); - - UNIT_ASSERT_NO_EXCEPTION( - decoded = TDecoder::Decode( - "1:gzip:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", - TString(GZIP))); - UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); - - UNIT_ASSERT_NO_EXCEPTION( - decoded = TDecoder::Decode( - "1:zstd:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", - TString(ZSTD))); - UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); - } - - Y_UNIT_TEST(UnknownCodecs) { - for (const TStringBuf codec : {"lz", "lzma", "kek"}) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::DecodeImpl(codec, ""), - yexception, - TStringBuilder() << "unknown codec: '" << codec << "'"); - } - } - - Y_UNIT_TEST(ParseCodec) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::ParseCodec("2:kek"), - yexception, - "unknown codec format version; known: 1; got: 2"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::ParseCodec("1:::"), - yexception, - "codec type is empty"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::ParseCodec("1:some_codec:asd:"), - yexception, - "decoded blob size is not number"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::ParseCodec("1:some_codec:789:qwe"), - yexception, - "sha256 of decoded blob has invalid length: expected 64, got 3"); - - TDecoder::TCodecInfo info; - UNIT_ASSERT_NO_EXCEPTION( - info = TDecoder::ParseCodec("1:some_codec:789:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); - - UNIT_ASSERT_VALUES_EQUAL("some_codec", info.Type); - UNIT_ASSERT_VALUES_EQUAL(789, info.Size); - UNIT_ASSERT_VALUES_EQUAL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - info.Sha256); - } - - Y_UNIT_TEST(DecodeBrolti) { - UNIT_ASSERT_EXCEPTION( - TDecoder::DecodeBrolti(""), - yexception); - - TString blob; - UNIT_ASSERT_NO_EXCEPTION( - blob = TDecoder::DecodeBrolti( - TString(BROTLI))); - - UNIT_ASSERT_VALUES_EQUAL( - "some veryveryveryvery important blob", - blob); - } - - Y_UNIT_TEST(DecodeGzip) { - TString blob; - UNIT_ASSERT_NO_EXCEPTION(blob = TDecoder::DecodeGzip("")); - UNIT_ASSERT_VALUES_EQUAL("", blob); - - UNIT_ASSERT_NO_EXCEPTION( - blob = TDecoder::DecodeGzip( - TString(GZIP))); - - UNIT_ASSERT_VALUES_EQUAL( - "some veryveryveryvery important blob", - blob); - } - - Y_UNIT_TEST(DecodeZstd) { - TString blob; - UNIT_ASSERT_NO_EXCEPTION(blob = TDecoder::DecodeZstd("")); - UNIT_ASSERT_VALUES_EQUAL("", blob); - - UNIT_ASSERT_NO_EXCEPTION( - blob = TDecoder::DecodeZstd( - TString(ZSTD))); - - UNIT_ASSERT_VALUES_EQUAL( - "some veryveryveryvery important blob", - blob); - } - - Y_UNIT_TEST(VerifySize) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::VerifySize("qwerty", 100), - yexception, - TStringBuilder() << "Decoded blob has bad size: expected 100, actual 6"); - - UNIT_ASSERT_NO_EXCEPTION(TDecoder::VerifySize("qwert", 5)); - } - - Y_UNIT_TEST(VerifyChecksum) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TDecoder::VerifyChecksum("qwerty", "zzzz"), - yexception, - "Decoded blob has bad sha256: expected=zzzz," - " actual=65E84BE33532FB784C48129675F9EFF3A682B27168C0EA744B2CF58EE02337C5"); - - UNIT_ASSERT_NO_EXCEPTION( - TDecoder::VerifyChecksum("qwerty", - "65E84BE33532FB784C48129675F9EFF3A682B27168C0EA744B2CF58EE02337C5")); - UNIT_ASSERT_NO_EXCEPTION( - TDecoder::VerifyChecksum("qwerty", - "65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5")); - } -} +#include <library/cpp/tvmauth/client/exception.h> +#include <library/cpp/tvmauth/client/misc/roles/decoder.h> + +#include <library/cpp/tvmauth/unittest.h> +#include <library/cpp/tvmauth/src/utils.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; +using namespace NTvmAuth::NRoles; + +Y_UNIT_TEST_SUITE(Decoder) { + const TString BROTLI = NUtils::Base64url2bin("GyMAAAR0Y6ku58ObclAQzDweUSUwbdqc5yOOKgI"); + const TString GZIP = NUtils::Base64url2bin("H4sIAAAAAAAA_yrOz01VKEstqkTGCpm5BflFJYl5JQpJOflJgAAAAP__MbeeiSQAAAA"); + const TString ZSTD = NUtils::Base64url2bin("KLUv_QBY9AAAwHNvbWUgdmVyeSBpbXBvcnRhbnQgYmxvYgEAc-4IAQAA"); + + Y_UNIT_TEST(Decode) { + // Errs + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::Decode( + "1:brotli:10000:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", + TString(BROTLI)), + yexception, + "Decoded blob has bad size: expected 10000, actual 36"); + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::Decode( + "1:brotli:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF0000", + TString(BROTLI)), + yexception, + "Decoded blob has bad sha256"); + + // OK + TString decoded; + UNIT_ASSERT_NO_EXCEPTION( + decoded = TDecoder::Decode("", "some veryveryveryvery important blob")); + UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); + + UNIT_ASSERT_NO_EXCEPTION( + decoded = TDecoder::Decode( + "1:brotli:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", + TString(BROTLI))); + UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); + + UNIT_ASSERT_NO_EXCEPTION( + decoded = TDecoder::Decode( + "1:gzip:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", + TString(GZIP))); + UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); + + UNIT_ASSERT_NO_EXCEPTION( + decoded = TDecoder::Decode( + "1:zstd:36:88839244E8C7C426B20729AF1A13AD792C5FA83C7F2FB6ADCFC60DA1B5EF9603", + TString(ZSTD))); + UNIT_ASSERT_VALUES_EQUAL(decoded, "some veryveryveryvery important blob"); + } + + Y_UNIT_TEST(UnknownCodecs) { + for (const TStringBuf codec : {"lz", "lzma", "kek"}) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::DecodeImpl(codec, ""), + yexception, + TStringBuilder() << "unknown codec: '" << codec << "'"); + } + } + + Y_UNIT_TEST(ParseCodec) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::ParseCodec("2:kek"), + yexception, + "unknown codec format version; known: 1; got: 2"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::ParseCodec("1:::"), + yexception, + "codec type is empty"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::ParseCodec("1:some_codec:asd:"), + yexception, + "decoded blob size is not number"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::ParseCodec("1:some_codec:789:qwe"), + yexception, + "sha256 of decoded blob has invalid length: expected 64, got 3"); + + TDecoder::TCodecInfo info; + UNIT_ASSERT_NO_EXCEPTION( + info = TDecoder::ParseCodec("1:some_codec:789:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")); + + UNIT_ASSERT_VALUES_EQUAL("some_codec", info.Type); + UNIT_ASSERT_VALUES_EQUAL(789, info.Size); + UNIT_ASSERT_VALUES_EQUAL("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + info.Sha256); + } + + Y_UNIT_TEST(DecodeBrolti) { + UNIT_ASSERT_EXCEPTION( + TDecoder::DecodeBrolti(""), + yexception); + + TString blob; + UNIT_ASSERT_NO_EXCEPTION( + blob = TDecoder::DecodeBrolti( + TString(BROTLI))); + + UNIT_ASSERT_VALUES_EQUAL( + "some veryveryveryvery important blob", + blob); + } + + Y_UNIT_TEST(DecodeGzip) { + TString blob; + UNIT_ASSERT_NO_EXCEPTION(blob = TDecoder::DecodeGzip("")); + UNIT_ASSERT_VALUES_EQUAL("", blob); + + UNIT_ASSERT_NO_EXCEPTION( + blob = TDecoder::DecodeGzip( + TString(GZIP))); + + UNIT_ASSERT_VALUES_EQUAL( + "some veryveryveryvery important blob", + blob); + } + + Y_UNIT_TEST(DecodeZstd) { + TString blob; + UNIT_ASSERT_NO_EXCEPTION(blob = TDecoder::DecodeZstd("")); + UNIT_ASSERT_VALUES_EQUAL("", blob); + + UNIT_ASSERT_NO_EXCEPTION( + blob = TDecoder::DecodeZstd( + TString(ZSTD))); + + UNIT_ASSERT_VALUES_EQUAL( + "some veryveryveryvery important blob", + blob); + } + + Y_UNIT_TEST(VerifySize) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::VerifySize("qwerty", 100), + yexception, + TStringBuilder() << "Decoded blob has bad size: expected 100, actual 6"); + + UNIT_ASSERT_NO_EXCEPTION(TDecoder::VerifySize("qwert", 5)); + } + + Y_UNIT_TEST(VerifyChecksum) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TDecoder::VerifyChecksum("qwerty", "zzzz"), + yexception, + "Decoded blob has bad sha256: expected=zzzz," + " actual=65E84BE33532FB784C48129675F9EFF3A682B27168C0EA744B2CF58EE02337C5"); + + UNIT_ASSERT_NO_EXCEPTION( + TDecoder::VerifyChecksum("qwerty", + "65E84BE33532FB784C48129675F9EFF3A682B27168C0EA744B2CF58EE02337C5")); + UNIT_ASSERT_NO_EXCEPTION( + TDecoder::VerifyChecksum("qwerty", + "65e84be33532fb784c48129675f9eff3a682b27168c0ea744b2cf58ee02337c5")); + } +} diff --git a/library/cpp/tvmauth/client/ut/roles/entities_index_ut.cpp b/library/cpp/tvmauth/client/ut/roles/entities_index_ut.cpp index 14ed9b79cf..7e62a87b64 100644 --- a/library/cpp/tvmauth/client/ut/roles/entities_index_ut.cpp +++ b/library/cpp/tvmauth/client/ut/roles/entities_index_ut.cpp @@ -1,358 +1,358 @@ -#include <library/cpp/tvmauth/client/ut/common.h> - -#include <library/cpp/tvmauth/client/misc/roles/entities_index.h> - -#include <library/cpp/testing/unittest/registar.h> - -#include <array> - -using namespace NTvmAuth::NRoles; - -Y_UNIT_TEST_SUITE(RolesEntitiesIndex) { - Y_UNIT_TEST(Stage) { - TEntitiesIndex::TStage stage({ - "key#1", - "key#2", - "key#3", - "key#4", - }); - - const std::vector<std::vector<TString>> results = { - {"key#1"}, - {"key#2"}, - {"key#1", "key#2"}, - {"key#3"}, - {"key#1", "key#3"}, - {"key#2", "key#3"}, - {"key#1", "key#2", "key#3"}, - {"key#4"}, - {"key#1", "key#4"}, - {"key#2", "key#4"}, - {"key#1", "key#2", "key#4"}, - {"key#3", "key#4"}, - {"key#1", "key#3", "key#4"}, - {"key#2", "key#3", "key#4"}, - {"key#1", "key#2", "key#3", "key#4"}, - }; - - std::vector<TString> keys; - for (const std::vector<TString>& res : results) { - UNIT_ASSERT(stage.GetNextKeySet(keys)); - UNIT_ASSERT_VALUES_EQUAL(keys, res); - } - - UNIT_ASSERT_C(!stage.GetNextKeySet(keys), keys); - } - - Y_UNIT_TEST(GetUniqueSortedKeys) { - std::vector<TEntityPtr> entities; - - UNIT_ASSERT_VALUES_EQUAL(std::set<TString>(), - TEntitiesIndex::GetUniqueSortedKeys(entities)); - - entities = { - std::make_shared<TEntity>(), - }; - UNIT_ASSERT_VALUES_EQUAL(std::set<TString>(), - TEntitiesIndex::GetUniqueSortedKeys(entities)); - - entities = { - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#1"}, - }), - }; - UNIT_ASSERT_VALUES_EQUAL(std::set<TString>({ - "key#1", - }), - TEntitiesIndex::GetUniqueSortedKeys(entities)); - - entities = { - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#1"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - }), - }; - UNIT_ASSERT_VALUES_EQUAL(std::set<TString>({ - "key#1", - "key#2", - }), - TEntitiesIndex::GetUniqueSortedKeys(entities)); - } - - Y_UNIT_TEST(MakeUnique) { - const TEntityPtr entityA = std::make_shared<TEntity>(TEntity{{"key#1", "aaaa"}}); - const TEntityPtr entityA2 = std::make_shared<TEntity>(TEntity{{"key#1", "aaaa"}}); - const TEntityPtr entityB = std::make_shared<TEntity>(TEntity{{"key#1", "bbbb"}}); - - TEntitiesIndex::TSubTree idx = { - std::vector<TEntityPtr>{ - entityA, - entityA, - }, - TEntitiesIndex::TIdxByAttrs{ - { - TKeyValue{"key#1", "value#11"}, - TEntitiesIndex::TSubTree{ - std::vector<TEntityPtr>{ - entityA, - entityB, - entityA, - }, - TEntitiesIndex::TIdxByAttrs{ - { - TKeyValue{"key#2", "value#21"}, - TEntitiesIndex::TSubTree{ - std::vector<TEntityPtr>{ - entityA, - entityB, - entityA, - }, - TEntitiesIndex::TIdxByAttrs{}, - }, - }, - }, - }, - }, - { - TKeyValue{"key#1", "value#12"}, - TEntitiesIndex::TSubTree{ - std::vector<TEntityPtr>{ - entityA, - entityB, - entityA2, - }, - TEntitiesIndex::TIdxByAttrs{}, - }, - }, - }, - }; - - TEntitiesIndex::MakeUnique(idx); - - UNIT_ASSERT_VALUES_EQUAL(idx.Entities.size(), 1); - - auto it = idx.SubTree.find(TKeyValue{"key#1", "value#12"}); - UNIT_ASSERT(it != idx.SubTree.end()); - UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); - - it = idx.SubTree.find(TKeyValue{"key#1", "value#11"}); - UNIT_ASSERT(it != idx.SubTree.end()); - UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); - - it = it->second.SubTree.find(TKeyValue{"key#2", "value#21"}); - UNIT_ASSERT(it != it->second.SubTree.end()); - UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); - } - - Y_UNIT_TEST(GetByAttrs) { - const TEntitiesIndex index = CreateEntitiesIndex(); - - UNIT_ASSERT_STRINGS_EQUAL( - index.PrintDebugString(), - R"( -"key#1/value#11" - "key#2/value#22" - "key#3/value#33" - "key#2/value#23" - "key#3/value#33" - "key#3/value#33" -"key#1/value#13" - "key#3/value#33" -"key#2/value#22" - "key#3/value#33" -"key#2/value#23" - "key#3/value#33" -"key#3/value#33" -)"); - - struct TCase { - TEntity AttrsToFind; - std::vector<TEntity> Result; - }; - - std::vector<TCase> cases = { - { - TEntity{}, - std::vector<TEntity>{ - TEntity{ - {"key#1", "value#11"}, - }, - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }, - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }, - TEntity{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }, - }, - }, - { - TEntity{ - {"key#1", "value#11"}, - }, - std::vector<TEntity>{ - TEntity{ - {"key#1", "value#11"}, - }, - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }, - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }, - }, - }, - { - TEntity{ - {"key#1", "value#13"}, - }, - std::vector<TEntity>{ - TEntity{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }, - }, - }, - { - TEntity{ - {"key#1", "value#14"}, - }, - std::vector<TEntity>{}, - }, - { - TEntity{ - {"key#2", "value#22"}, - }, - std::vector<TEntity>{ - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }, - }, - }, - { - TEntity{ - {"key#3", "value#33"}, - }, - std::vector<TEntity>{ - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }, - TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }, - TEntity{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }, - }, - }, - }; - - for (const TCase& c : cases) { - std::vector<TEntityPtr> expected; - for (const TEntity& e : c.Result) { - expected.push_back(std::make_shared<TEntity>(e)); - } - - UNIT_ASSERT_VALUES_EQUAL_C( - index.GetEntitiesWithAttrs(c.AttrsToFind.begin(), c.AttrsToFind.end()), - expected, - "'" << c.AttrsToFind << "'"); - } - } - - Y_UNIT_TEST(Contains) { - const TEntitiesIndex index = CreateEntitiesIndex(); - - struct TCase { - TEntity Exact; - bool Result = false; - }; - - std::vector<TCase> cases = { - { - TEntity{}, - false, - }, - { - TEntity{ - {"key#1", "value#11"}, - }, - true, - }, - { - TEntity{ - {"key#1", "value#13"}, - }, - false, - }, - { - TEntity{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }, - true, - }, - }; - - for (const TCase& c : cases) { - UNIT_ASSERT_VALUES_EQUAL_C( - index.ContainsExactEntity(c.Exact.begin(), c.Exact.end()), - c.Result, - "'" << c.Exact << "'"); - } - } -} - -template <> -void Out<std::vector<TString>>(IOutputStream& o, const std::vector<TString>& s) { - for (const auto& key : s) { - o << key << ","; - } -} - -template <> -void Out<std::set<TString>>(IOutputStream& o, const std::set<TString>& s) { - for (const auto& key : s) { - o << key << ","; - } -} - -template <> -void Out<std::vector<TEntityPtr>>(IOutputStream& o, const std::vector<TEntityPtr>& v) { - for (const TEntityPtr& p : v) { - o << *p << Endl; - } -} - -template <> -void Out<TEntityPtr>(IOutputStream& o, const TEntityPtr& v) { - o << *v; -} - -template <> -void Out<TEntity>(IOutputStream& o, const TEntity& v) { - for (const auto& [key, value] : v) { - o << key << "->" << value << Endl; - } -} +#include <library/cpp/tvmauth/client/ut/common.h> + +#include <library/cpp/tvmauth/client/misc/roles/entities_index.h> + +#include <library/cpp/testing/unittest/registar.h> + +#include <array> + +using namespace NTvmAuth::NRoles; + +Y_UNIT_TEST_SUITE(RolesEntitiesIndex) { + Y_UNIT_TEST(Stage) { + TEntitiesIndex::TStage stage({ + "key#1", + "key#2", + "key#3", + "key#4", + }); + + const std::vector<std::vector<TString>> results = { + {"key#1"}, + {"key#2"}, + {"key#1", "key#2"}, + {"key#3"}, + {"key#1", "key#3"}, + {"key#2", "key#3"}, + {"key#1", "key#2", "key#3"}, + {"key#4"}, + {"key#1", "key#4"}, + {"key#2", "key#4"}, + {"key#1", "key#2", "key#4"}, + {"key#3", "key#4"}, + {"key#1", "key#3", "key#4"}, + {"key#2", "key#3", "key#4"}, + {"key#1", "key#2", "key#3", "key#4"}, + }; + + std::vector<TString> keys; + for (const std::vector<TString>& res : results) { + UNIT_ASSERT(stage.GetNextKeySet(keys)); + UNIT_ASSERT_VALUES_EQUAL(keys, res); + } + + UNIT_ASSERT_C(!stage.GetNextKeySet(keys), keys); + } + + Y_UNIT_TEST(GetUniqueSortedKeys) { + std::vector<TEntityPtr> entities; + + UNIT_ASSERT_VALUES_EQUAL(std::set<TString>(), + TEntitiesIndex::GetUniqueSortedKeys(entities)); + + entities = { + std::make_shared<TEntity>(), + }; + UNIT_ASSERT_VALUES_EQUAL(std::set<TString>(), + TEntitiesIndex::GetUniqueSortedKeys(entities)); + + entities = { + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#1"}, + }), + }; + UNIT_ASSERT_VALUES_EQUAL(std::set<TString>({ + "key#1", + }), + TEntitiesIndex::GetUniqueSortedKeys(entities)); + + entities = { + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#1"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + }), + }; + UNIT_ASSERT_VALUES_EQUAL(std::set<TString>({ + "key#1", + "key#2", + }), + TEntitiesIndex::GetUniqueSortedKeys(entities)); + } + + Y_UNIT_TEST(MakeUnique) { + const TEntityPtr entityA = std::make_shared<TEntity>(TEntity{{"key#1", "aaaa"}}); + const TEntityPtr entityA2 = std::make_shared<TEntity>(TEntity{{"key#1", "aaaa"}}); + const TEntityPtr entityB = std::make_shared<TEntity>(TEntity{{"key#1", "bbbb"}}); + + TEntitiesIndex::TSubTree idx = { + std::vector<TEntityPtr>{ + entityA, + entityA, + }, + TEntitiesIndex::TIdxByAttrs{ + { + TKeyValue{"key#1", "value#11"}, + TEntitiesIndex::TSubTree{ + std::vector<TEntityPtr>{ + entityA, + entityB, + entityA, + }, + TEntitiesIndex::TIdxByAttrs{ + { + TKeyValue{"key#2", "value#21"}, + TEntitiesIndex::TSubTree{ + std::vector<TEntityPtr>{ + entityA, + entityB, + entityA, + }, + TEntitiesIndex::TIdxByAttrs{}, + }, + }, + }, + }, + }, + { + TKeyValue{"key#1", "value#12"}, + TEntitiesIndex::TSubTree{ + std::vector<TEntityPtr>{ + entityA, + entityB, + entityA2, + }, + TEntitiesIndex::TIdxByAttrs{}, + }, + }, + }, + }; + + TEntitiesIndex::MakeUnique(idx); + + UNIT_ASSERT_VALUES_EQUAL(idx.Entities.size(), 1); + + auto it = idx.SubTree.find(TKeyValue{"key#1", "value#12"}); + UNIT_ASSERT(it != idx.SubTree.end()); + UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); + + it = idx.SubTree.find(TKeyValue{"key#1", "value#11"}); + UNIT_ASSERT(it != idx.SubTree.end()); + UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); + + it = it->second.SubTree.find(TKeyValue{"key#2", "value#21"}); + UNIT_ASSERT(it != it->second.SubTree.end()); + UNIT_ASSERT_VALUES_EQUAL(it->second.Entities.size(), 2); + } + + Y_UNIT_TEST(GetByAttrs) { + const TEntitiesIndex index = CreateEntitiesIndex(); + + UNIT_ASSERT_STRINGS_EQUAL( + index.PrintDebugString(), + R"( +"key#1/value#11" + "key#2/value#22" + "key#3/value#33" + "key#2/value#23" + "key#3/value#33" + "key#3/value#33" +"key#1/value#13" + "key#3/value#33" +"key#2/value#22" + "key#3/value#33" +"key#2/value#23" + "key#3/value#33" +"key#3/value#33" +)"); + + struct TCase { + TEntity AttrsToFind; + std::vector<TEntity> Result; + }; + + std::vector<TCase> cases = { + { + TEntity{}, + std::vector<TEntity>{ + TEntity{ + {"key#1", "value#11"}, + }, + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }, + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }, + TEntity{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }, + }, + }, + { + TEntity{ + {"key#1", "value#11"}, + }, + std::vector<TEntity>{ + TEntity{ + {"key#1", "value#11"}, + }, + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }, + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }, + }, + }, + { + TEntity{ + {"key#1", "value#13"}, + }, + std::vector<TEntity>{ + TEntity{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }, + }, + }, + { + TEntity{ + {"key#1", "value#14"}, + }, + std::vector<TEntity>{}, + }, + { + TEntity{ + {"key#2", "value#22"}, + }, + std::vector<TEntity>{ + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }, + }, + }, + { + TEntity{ + {"key#3", "value#33"}, + }, + std::vector<TEntity>{ + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }, + TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }, + TEntity{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }, + }, + }, + }; + + for (const TCase& c : cases) { + std::vector<TEntityPtr> expected; + for (const TEntity& e : c.Result) { + expected.push_back(std::make_shared<TEntity>(e)); + } + + UNIT_ASSERT_VALUES_EQUAL_C( + index.GetEntitiesWithAttrs(c.AttrsToFind.begin(), c.AttrsToFind.end()), + expected, + "'" << c.AttrsToFind << "'"); + } + } + + Y_UNIT_TEST(Contains) { + const TEntitiesIndex index = CreateEntitiesIndex(); + + struct TCase { + TEntity Exact; + bool Result = false; + }; + + std::vector<TCase> cases = { + { + TEntity{}, + false, + }, + { + TEntity{ + {"key#1", "value#11"}, + }, + true, + }, + { + TEntity{ + {"key#1", "value#13"}, + }, + false, + }, + { + TEntity{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }, + true, + }, + }; + + for (const TCase& c : cases) { + UNIT_ASSERT_VALUES_EQUAL_C( + index.ContainsExactEntity(c.Exact.begin(), c.Exact.end()), + c.Result, + "'" << c.Exact << "'"); + } + } +} + +template <> +void Out<std::vector<TString>>(IOutputStream& o, const std::vector<TString>& s) { + for (const auto& key : s) { + o << key << ","; + } +} + +template <> +void Out<std::set<TString>>(IOutputStream& o, const std::set<TString>& s) { + for (const auto& key : s) { + o << key << ","; + } +} + +template <> +void Out<std::vector<TEntityPtr>>(IOutputStream& o, const std::vector<TEntityPtr>& v) { + for (const TEntityPtr& p : v) { + o << *p << Endl; + } +} + +template <> +void Out<TEntityPtr>(IOutputStream& o, const TEntityPtr& v) { + o << *v; +} + +template <> +void Out<TEntity>(IOutputStream& o, const TEntity& v) { + for (const auto& [key, value] : v) { + o << key << "->" << value << Endl; + } +} diff --git a/library/cpp/tvmauth/client/ut/roles/parser_ut.cpp b/library/cpp/tvmauth/client/ut/roles/parser_ut.cpp index df866501b5..87f8ade267 100644 --- a/library/cpp/tvmauth/client/ut/roles/parser_ut.cpp +++ b/library/cpp/tvmauth/client/ut/roles/parser_ut.cpp @@ -1,160 +1,160 @@ -#include <library/cpp/tvmauth/client/misc/roles/parser.h> - -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/json/json_reader.h> -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; -using namespace NTvmAuth::NRoles; - -Y_UNIT_TEST_SUITE(Parser) { - static NJson::TJsonValue ToJsonValue(TStringBuf body) { - NJson::TJsonValue doc; - UNIT_ASSERT(NJson::ReadJsonTree(body, &doc)); - return doc; - } - - Y_UNIT_TEST(GetEntity) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetEntity(ToJsonValue(R"({"scope": false})"), - "cons", - "read"), - yexception, - "entity is map (str->str), got value Boolean. consumer 'cons' with role 'read'"); - - TEntityPtr en; - UNIT_ASSERT_NO_EXCEPTION( - en = TParser::GetEntity(ToJsonValue(R"({})"), - "cons", - "read")); - UNIT_ASSERT_VALUES_EQUAL(en->size(), 0); - - UNIT_ASSERT_NO_EXCEPTION( - en = TParser::GetEntity(ToJsonValue(R"({"key1": "val1", "key2": "val2"})"), - "cons", - "read")); - UNIT_ASSERT_VALUES_EQUAL(en->size(), 2); - } - - Y_UNIT_TEST(GetEntities) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetEntities(ToJsonValue(R"([{},[]])"), - "cons", - "read"), - yexception, - "role entity for role must be map: consumer 'cons' with role 'read' has Array"); - - TEntitiesPtr en; - UNIT_ASSERT_NO_EXCEPTION( - en = TParser::GetEntities(ToJsonValue(R"([])"), - "cons", - "read")); - UNIT_ASSERT(!en->Contains({})); - - UNIT_ASSERT_NO_EXCEPTION( - en = TParser::GetEntities(ToJsonValue(R"([{}])"), - "cons", - "read")); - UNIT_ASSERT(en->Contains({})); - } - - Y_UNIT_TEST(GetConsumer) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumer(ToJsonValue(R"({"role1": [],"role2": {}})"), - "cons"), - yexception, - "entities for roles must be array: 'role2' is Map"); - - TConsumerRolesPtr c; - UNIT_ASSERT_NO_EXCEPTION( - c = TParser::GetConsumer(ToJsonValue(R"({"role1": [],"role2": []})"), - "cons")); - UNIT_ASSERT(c->HasRole("role1")); - UNIT_ASSERT(c->HasRole("role2")); - UNIT_ASSERT(!c->HasRole("role3")); - } - - Y_UNIT_TEST(GetConsumers) { - TRoles::TTvmConsumers cons; - UNIT_ASSERT_NO_EXCEPTION( - cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({})"), - "tvm")); - UNIT_ASSERT_VALUES_EQUAL(0, cons.size()); - - UNIT_ASSERT_NO_EXCEPTION( - cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {}})"), - "tvm")); - UNIT_ASSERT_VALUES_EQUAL(0, cons.size()); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": []})"), - "tvm"), - yexception, - "'tvm' must be object"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"asd": []}})"), - "tvm"), - yexception, - "roles for consumer must be map: 'asd' is Array"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"asd": {}}})"), - "tvm"), - yexception, - "id must be valid positive number of proper size for tvm. got 'asd'"); - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"1120000000001062": {}}})"), - "tvm"), - yexception, - "id must be valid positive number of proper size for tvm. got '1120000000001062'"); - UNIT_ASSERT_NO_EXCEPTION( - TParser::GetConsumers<TUid>(ToJsonValue(R"({"user": {"1120000000001062": {}}})"), - "user")); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"42": {}, "042": {}}})"), - "tvm"), - yexception, - "consumer duplicate detected: '42' for tvm"); - - UNIT_ASSERT_NO_EXCEPTION( - cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"42": {}}})"), - "tvm")); - UNIT_ASSERT_VALUES_EQUAL(1, cons.size()); - } - - Y_UNIT_TEST(GetMeta) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetMeta(ToJsonValue(R"({})")), - yexception, - "Missing 'revision'"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetMeta(ToJsonValue(R"({"revision": null})")), - yexception, - "'revision' has unexpected type: Null"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetMeta(ToJsonValue(R"({"revision": 100500})")), - yexception, - "Missing 'born_date'"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - TParser::GetMeta(ToJsonValue(R"({"revision": 100500, "born_date": false})")), - yexception, - "key 'born_date' must be uint"); - - TRoles::TMeta meta; - UNIT_ASSERT_NO_EXCEPTION( - meta = TParser::GetMeta(ToJsonValue(R"({"revision": 100500, "born_date": 42})"))); - UNIT_ASSERT_VALUES_EQUAL("100500", meta.Revision); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(42), meta.BornTime); - - UNIT_ASSERT_NO_EXCEPTION( - meta = TParser::GetMeta(ToJsonValue(R"({"revision": "100501", "born_date": 42})"))); - UNIT_ASSERT_VALUES_EQUAL("100501", meta.Revision); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(42), meta.BornTime); - } -} +#include <library/cpp/tvmauth/client/misc/roles/parser.h> + +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/json/json_reader.h> +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; +using namespace NTvmAuth::NRoles; + +Y_UNIT_TEST_SUITE(Parser) { + static NJson::TJsonValue ToJsonValue(TStringBuf body) { + NJson::TJsonValue doc; + UNIT_ASSERT(NJson::ReadJsonTree(body, &doc)); + return doc; + } + + Y_UNIT_TEST(GetEntity) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetEntity(ToJsonValue(R"({"scope": false})"), + "cons", + "read"), + yexception, + "entity is map (str->str), got value Boolean. consumer 'cons' with role 'read'"); + + TEntityPtr en; + UNIT_ASSERT_NO_EXCEPTION( + en = TParser::GetEntity(ToJsonValue(R"({})"), + "cons", + "read")); + UNIT_ASSERT_VALUES_EQUAL(en->size(), 0); + + UNIT_ASSERT_NO_EXCEPTION( + en = TParser::GetEntity(ToJsonValue(R"({"key1": "val1", "key2": "val2"})"), + "cons", + "read")); + UNIT_ASSERT_VALUES_EQUAL(en->size(), 2); + } + + Y_UNIT_TEST(GetEntities) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetEntities(ToJsonValue(R"([{},[]])"), + "cons", + "read"), + yexception, + "role entity for role must be map: consumer 'cons' with role 'read' has Array"); + + TEntitiesPtr en; + UNIT_ASSERT_NO_EXCEPTION( + en = TParser::GetEntities(ToJsonValue(R"([])"), + "cons", + "read")); + UNIT_ASSERT(!en->Contains({})); + + UNIT_ASSERT_NO_EXCEPTION( + en = TParser::GetEntities(ToJsonValue(R"([{}])"), + "cons", + "read")); + UNIT_ASSERT(en->Contains({})); + } + + Y_UNIT_TEST(GetConsumer) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumer(ToJsonValue(R"({"role1": [],"role2": {}})"), + "cons"), + yexception, + "entities for roles must be array: 'role2' is Map"); + + TConsumerRolesPtr c; + UNIT_ASSERT_NO_EXCEPTION( + c = TParser::GetConsumer(ToJsonValue(R"({"role1": [],"role2": []})"), + "cons")); + UNIT_ASSERT(c->HasRole("role1")); + UNIT_ASSERT(c->HasRole("role2")); + UNIT_ASSERT(!c->HasRole("role3")); + } + + Y_UNIT_TEST(GetConsumers) { + TRoles::TTvmConsumers cons; + UNIT_ASSERT_NO_EXCEPTION( + cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({})"), + "tvm")); + UNIT_ASSERT_VALUES_EQUAL(0, cons.size()); + + UNIT_ASSERT_NO_EXCEPTION( + cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {}})"), + "tvm")); + UNIT_ASSERT_VALUES_EQUAL(0, cons.size()); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": []})"), + "tvm"), + yexception, + "'tvm' must be object"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"asd": []}})"), + "tvm"), + yexception, + "roles for consumer must be map: 'asd' is Array"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"asd": {}}})"), + "tvm"), + yexception, + "id must be valid positive number of proper size for tvm. got 'asd'"); + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"1120000000001062": {}}})"), + "tvm"), + yexception, + "id must be valid positive number of proper size for tvm. got '1120000000001062'"); + UNIT_ASSERT_NO_EXCEPTION( + TParser::GetConsumers<TUid>(ToJsonValue(R"({"user": {"1120000000001062": {}}})"), + "user")); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"42": {}, "042": {}}})"), + "tvm"), + yexception, + "consumer duplicate detected: '42' for tvm"); + + UNIT_ASSERT_NO_EXCEPTION( + cons = TParser::GetConsumers<TTvmId>(ToJsonValue(R"({"tvm": {"42": {}}})"), + "tvm")); + UNIT_ASSERT_VALUES_EQUAL(1, cons.size()); + } + + Y_UNIT_TEST(GetMeta) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetMeta(ToJsonValue(R"({})")), + yexception, + "Missing 'revision'"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetMeta(ToJsonValue(R"({"revision": null})")), + yexception, + "'revision' has unexpected type: Null"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetMeta(ToJsonValue(R"({"revision": 100500})")), + yexception, + "Missing 'born_date'"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + TParser::GetMeta(ToJsonValue(R"({"revision": 100500, "born_date": false})")), + yexception, + "key 'born_date' must be uint"); + + TRoles::TMeta meta; + UNIT_ASSERT_NO_EXCEPTION( + meta = TParser::GetMeta(ToJsonValue(R"({"revision": 100500, "born_date": 42})"))); + UNIT_ASSERT_VALUES_EQUAL("100500", meta.Revision); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(42), meta.BornTime); + + UNIT_ASSERT_NO_EXCEPTION( + meta = TParser::GetMeta(ToJsonValue(R"({"revision": "100501", "born_date": 42})"))); + UNIT_ASSERT_VALUES_EQUAL("100501", meta.Revision); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(42), meta.BornTime); + } +} diff --git a/library/cpp/tvmauth/client/ut/roles/roles_ut.cpp b/library/cpp/tvmauth/client/ut/roles/roles_ut.cpp index 924a77b3af..5ba28d5435 100644 --- a/library/cpp/tvmauth/client/ut/roles/roles_ut.cpp +++ b/library/cpp/tvmauth/client/ut/roles/roles_ut.cpp @@ -1,415 +1,415 @@ -#include <library/cpp/tvmauth/client/ut/common.h> - -#include <library/cpp/tvmauth/client/exception.h> -#include <library/cpp/tvmauth/client/misc/roles/roles.h> - -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/testing/unittest/registar.h> - -#include <array> - -using namespace NTvmAuth; -using namespace NTvmAuth::NRoles; - -Y_UNIT_TEST_SUITE(Roles) { - Y_UNIT_TEST(EntContains) { - TEntities ent(CreateEntitiesIndex()); - - UNIT_ASSERT(ent.Contains({{"key#1", "value#11"}})); - UNIT_ASSERT(ent.Contains({ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - })); - UNIT_ASSERT(!ent.Contains({{"key#111", "value#11"}})); - UNIT_ASSERT(!ent.Contains({ - {"key#111", "value#13"}, - {"key#3", "value#33"}, - })); - - // valid calls - { - std::array<const std::pair<TStringBuf, TString>, 1> arr = {{{"key#1", "value#11"}}}; - UNIT_ASSERT(ent.ContainsSortedUnique<TStringBuf>({arr.begin(), arr.end()})); - } - { - std::array<const std::pair<TString, TStringBuf>, 2> arr = {{ - {"key#1", "value#13"}, - {"key#3", "value#33"}, - }}; - bool res = ent.ContainsSortedUnique<TString, TStringBuf>({arr.begin(), arr.end()}); - UNIT_ASSERT(res); - } - { - std::array<const std::pair<TStringBuf, TStringBuf>, 1> arr = {{{"key#111", "value#11"}}}; - bool res = ent.ContainsSortedUnique<TStringBuf, TStringBuf>({arr.begin(), arr.end()}); - UNIT_ASSERT(!res); - } - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#111", "value#13"}, - {"key#3", "value#33"}, - }}; - UNIT_ASSERT(!ent.ContainsSortedUnique({arr.begin(), arr.end()})); - } - - // invalid calls - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#3", "value#33"}, - {"key#1", "value#13"}, - }}; - UNIT_ASSERT_EXCEPTION_CONTAINS( - ent.ContainsSortedUnique({arr.begin(), arr.end()}), - TIllegalUsage, - "attrs are not sorted: 'key#3' before 'key#1'"); - } - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#1", "value#13"}, - {"key#1", "value#13"}, - }}; - UNIT_ASSERT_EXCEPTION_CONTAINS( - ent.ContainsSortedUnique({arr.begin(), arr.end()}), - TIllegalUsage, - "attrs are not unique: 'key#1'"); - } - } - - Y_UNIT_TEST(EntWithAttrs) { - TEntities ent(CreateEntitiesIndex()); - - UNIT_ASSERT_VALUES_EQUAL( - ent.GetEntitiesWithAttrs({{"key#1", "value#11"}}), - std::vector<TEntityPtr>({ - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }), - })); - UNIT_ASSERT_VALUES_EQUAL( - ent.GetEntitiesWithAttrs({{"key#111", "value#11"}}), - std::vector<TEntityPtr>()); - - // valid calls - { - std::array<const std::pair<TStringBuf, TString>, 2> arr = {{ - {"key#1", "value#11"}, - {"key#3", "value#33"}, - }}; - auto vec = ent.GetEntitiesWithSortedUniqueAttrs<TStringBuf>({arr.begin(), arr.end()}); - UNIT_ASSERT_VALUES_EQUAL( - vec, - std::vector<TEntityPtr>({ - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#22"}, - {"key#3", "value#33"}, - }), - std::make_shared<TEntity>(TEntity{ - {"key#1", "value#11"}, - {"key#2", "value#23"}, - {"key#3", "value#33"}, - }), - })); - } - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#111", "value#13"}, - {"key#3", "value#33"}, - }}; - UNIT_ASSERT_VALUES_EQUAL( - ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), - std::vector<TEntityPtr>()); - } - - // invalid calls - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#3", "value#33"}, - {"key#1", "value#13"}, - }}; - UNIT_ASSERT_EXCEPTION_CONTAINS( - ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), - TIllegalUsage, - "attrs are not sorted: 'key#3' before 'key#1'"); - } - { - std::array<const std::pair<TString, TString>, 2> arr = {{ - {"key#1", "value#13"}, - {"key#1", "value#13"}, - }}; - UNIT_ASSERT_EXCEPTION_CONTAINS( - ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), - TIllegalUsage, - "attrs are not unique: 'key#1'"); - } - } - - Y_UNIT_TEST(Consumer) { - TConsumerRoles c({ - {"read", std::make_shared<TEntities>(CreateEntitiesIndex())}, - {"write", std::make_shared<TEntities>(CreateEntitiesIndex())}, - }); - - UNIT_ASSERT(c.HasRole("read")); - UNIT_ASSERT(c.HasRole("write")); - UNIT_ASSERT(!c.HasRole("access")); - - UNIT_ASSERT_EQUAL(nullptr, c.GetEntitiesForRole("access")); - - TEntitiesPtr ent = c.GetEntitiesForRole("read"); - UNIT_ASSERT_UNEQUAL(nullptr, ent); - UNIT_ASSERT(ent->Contains({{"key#1", "value#11"}})); - UNIT_ASSERT(!ent->Contains({{"key#111", "value#11"}})); - - UNIT_ASSERT(c.CheckRoleForExactEntity("read", {{"key#1", "value#11"}})); - UNIT_ASSERT(!c.CheckRoleForExactEntity("acess", {{"key#1", "value#11"}})); - UNIT_ASSERT(!c.CheckRoleForExactEntity("read", {{"key#111", "value#11"}})); - UNIT_ASSERT(!c.CheckRoleForExactEntity("read", {})); - } - - Y_UNIT_TEST(RolesService) { - TRoles r( - {}, - { - {100500, std::make_shared<TConsumerRoles>(THashMap<TString, TEntitiesPtr>{ - {"write", std::make_shared<TEntities>(CreateEntitiesIndex())}, - })}, - }, - {}, - std::make_shared<TString>()); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - r.GetRolesForService(NUnittest::CreateServiceTicket( - ETicketStatus::InvalidDst, - 100500)), - TIllegalUsage, - "Service ticket must be valid, got: InvalidDst"); - - TConsumerRolesPtr cons; - UNIT_ASSERT_NO_EXCEPTION( - cons = r.GetRolesForService(NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100501))); - UNIT_ASSERT_EQUAL(nullptr, cons); - - cons = r.GetRolesForService(NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500)); - UNIT_ASSERT_UNEQUAL(nullptr, cons); - UNIT_ASSERT(!cons->HasRole("read")); - UNIT_ASSERT(cons->HasRole("write")); - - ////shortcuts - // no tvmid - UNIT_ASSERT(!r.CheckServiceRole( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100501), - "write")); - - // no role - UNIT_ASSERT(!r.CheckServiceRole( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500), - "read")); - - // success - UNIT_ASSERT(r.CheckServiceRole( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500), - "write")); - - // no tvmid - UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100501), - "write", - {{"key#1", "value#11"}})); - - // no role - UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500), - "read", - {{"key#1", "value#11"}})); - - // no entity - UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500), - "write", - {{"key#111", "value#11"}})); - - // success - UNIT_ASSERT(r.CheckServiceRoleForExactEntity( - NUnittest::CreateServiceTicket( - ETicketStatus::Ok, - 100500), - "write", - {{"key#1", "value#11"}})); - } - - Y_UNIT_TEST(RolesUser) { - TRoles r( - {}, - {}, - { - {789654, std::make_shared<TConsumerRoles>(THashMap<TString, TEntitiesPtr>{ - {"read", std::make_shared<TEntities>(CreateEntitiesIndex())}, - })}, - }, - std::make_shared<TString>("some roles")); - - UNIT_ASSERT_VALUES_EQUAL("some roles", r.GetRaw()); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Malformed, - 789654, - {})), - TIllegalUsage, - "User ticket must be valid, got: Malformed"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}), - 789123), - TIllegalUsage, - "User ticket must be from ProdYateam, got from Test"); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - 789123), - TIllegalUsage, - "selectedUid must be in user ticket but it's not: 789123"); - - TConsumerRolesPtr cons; - UNIT_ASSERT_NO_EXCEPTION( - cons = r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789123, - {}, - {}, - EBlackboxEnv::ProdYateam))); - UNIT_ASSERT_EQUAL(nullptr, cons); - - cons = r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam)); - UNIT_ASSERT_UNEQUAL(nullptr, cons); - UNIT_ASSERT(cons->HasRole("read")); - UNIT_ASSERT(!cons->HasRole("write")); - - cons = r.GetRolesForUser(NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789123, - {}, - {789654, 789741}, - EBlackboxEnv::ProdYateam), - 789654); - UNIT_ASSERT_UNEQUAL(nullptr, cons); - UNIT_ASSERT(cons->HasRole("read")); - UNIT_ASSERT(!cons->HasRole("write")); - - ////shortcuts - // no uid - UNIT_ASSERT(!r.CheckUserRole( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789123, - {}, - {}, - EBlackboxEnv::ProdYateam), - "read")); - - // no role - UNIT_ASSERT(!r.CheckUserRole( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - "wrire")); - - // success - UNIT_ASSERT(r.CheckUserRole( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - "read")); - - // no uid - UNIT_ASSERT(!r.CheckUserRoleForExactEntity( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789123, - {}, - {}, - EBlackboxEnv::ProdYateam), - "read", - {{"key#1", "value#11"}})); - - // no role - UNIT_ASSERT(!r.CheckUserRoleForExactEntity( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - "wrire", - {{"key#1", "value#11"}})); - - // no entity - UNIT_ASSERT(!r.CheckUserRoleForExactEntity( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - "read", - {{"key#111", "value#11"}})); - - // success - UNIT_ASSERT(r.CheckUserRoleForExactEntity( - NUnittest::CreateUserTicket( - ETicketStatus::Ok, - 789654, - {}, - {}, - EBlackboxEnv::ProdYateam), - "read", - {{"key#1", "value#11"}})); - } -} +#include <library/cpp/tvmauth/client/ut/common.h> + +#include <library/cpp/tvmauth/client/exception.h> +#include <library/cpp/tvmauth/client/misc/roles/roles.h> + +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/testing/unittest/registar.h> + +#include <array> + +using namespace NTvmAuth; +using namespace NTvmAuth::NRoles; + +Y_UNIT_TEST_SUITE(Roles) { + Y_UNIT_TEST(EntContains) { + TEntities ent(CreateEntitiesIndex()); + + UNIT_ASSERT(ent.Contains({{"key#1", "value#11"}})); + UNIT_ASSERT(ent.Contains({ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + })); + UNIT_ASSERT(!ent.Contains({{"key#111", "value#11"}})); + UNIT_ASSERT(!ent.Contains({ + {"key#111", "value#13"}, + {"key#3", "value#33"}, + })); + + // valid calls + { + std::array<const std::pair<TStringBuf, TString>, 1> arr = {{{"key#1", "value#11"}}}; + UNIT_ASSERT(ent.ContainsSortedUnique<TStringBuf>({arr.begin(), arr.end()})); + } + { + std::array<const std::pair<TString, TStringBuf>, 2> arr = {{ + {"key#1", "value#13"}, + {"key#3", "value#33"}, + }}; + bool res = ent.ContainsSortedUnique<TString, TStringBuf>({arr.begin(), arr.end()}); + UNIT_ASSERT(res); + } + { + std::array<const std::pair<TStringBuf, TStringBuf>, 1> arr = {{{"key#111", "value#11"}}}; + bool res = ent.ContainsSortedUnique<TStringBuf, TStringBuf>({arr.begin(), arr.end()}); + UNIT_ASSERT(!res); + } + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#111", "value#13"}, + {"key#3", "value#33"}, + }}; + UNIT_ASSERT(!ent.ContainsSortedUnique({arr.begin(), arr.end()})); + } + + // invalid calls + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#3", "value#33"}, + {"key#1", "value#13"}, + }}; + UNIT_ASSERT_EXCEPTION_CONTAINS( + ent.ContainsSortedUnique({arr.begin(), arr.end()}), + TIllegalUsage, + "attrs are not sorted: 'key#3' before 'key#1'"); + } + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#1", "value#13"}, + {"key#1", "value#13"}, + }}; + UNIT_ASSERT_EXCEPTION_CONTAINS( + ent.ContainsSortedUnique({arr.begin(), arr.end()}), + TIllegalUsage, + "attrs are not unique: 'key#1'"); + } + } + + Y_UNIT_TEST(EntWithAttrs) { + TEntities ent(CreateEntitiesIndex()); + + UNIT_ASSERT_VALUES_EQUAL( + ent.GetEntitiesWithAttrs({{"key#1", "value#11"}}), + std::vector<TEntityPtr>({ + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }), + })); + UNIT_ASSERT_VALUES_EQUAL( + ent.GetEntitiesWithAttrs({{"key#111", "value#11"}}), + std::vector<TEntityPtr>()); + + // valid calls + { + std::array<const std::pair<TStringBuf, TString>, 2> arr = {{ + {"key#1", "value#11"}, + {"key#3", "value#33"}, + }}; + auto vec = ent.GetEntitiesWithSortedUniqueAttrs<TStringBuf>({arr.begin(), arr.end()}); + UNIT_ASSERT_VALUES_EQUAL( + vec, + std::vector<TEntityPtr>({ + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#22"}, + {"key#3", "value#33"}, + }), + std::make_shared<TEntity>(TEntity{ + {"key#1", "value#11"}, + {"key#2", "value#23"}, + {"key#3", "value#33"}, + }), + })); + } + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#111", "value#13"}, + {"key#3", "value#33"}, + }}; + UNIT_ASSERT_VALUES_EQUAL( + ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), + std::vector<TEntityPtr>()); + } + + // invalid calls + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#3", "value#33"}, + {"key#1", "value#13"}, + }}; + UNIT_ASSERT_EXCEPTION_CONTAINS( + ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), + TIllegalUsage, + "attrs are not sorted: 'key#3' before 'key#1'"); + } + { + std::array<const std::pair<TString, TString>, 2> arr = {{ + {"key#1", "value#13"}, + {"key#1", "value#13"}, + }}; + UNIT_ASSERT_EXCEPTION_CONTAINS( + ent.GetEntitiesWithSortedUniqueAttrs({arr.begin(), arr.end()}), + TIllegalUsage, + "attrs are not unique: 'key#1'"); + } + } + + Y_UNIT_TEST(Consumer) { + TConsumerRoles c({ + {"read", std::make_shared<TEntities>(CreateEntitiesIndex())}, + {"write", std::make_shared<TEntities>(CreateEntitiesIndex())}, + }); + + UNIT_ASSERT(c.HasRole("read")); + UNIT_ASSERT(c.HasRole("write")); + UNIT_ASSERT(!c.HasRole("access")); + + UNIT_ASSERT_EQUAL(nullptr, c.GetEntitiesForRole("access")); + + TEntitiesPtr ent = c.GetEntitiesForRole("read"); + UNIT_ASSERT_UNEQUAL(nullptr, ent); + UNIT_ASSERT(ent->Contains({{"key#1", "value#11"}})); + UNIT_ASSERT(!ent->Contains({{"key#111", "value#11"}})); + + UNIT_ASSERT(c.CheckRoleForExactEntity("read", {{"key#1", "value#11"}})); + UNIT_ASSERT(!c.CheckRoleForExactEntity("acess", {{"key#1", "value#11"}})); + UNIT_ASSERT(!c.CheckRoleForExactEntity("read", {{"key#111", "value#11"}})); + UNIT_ASSERT(!c.CheckRoleForExactEntity("read", {})); + } + + Y_UNIT_TEST(RolesService) { + TRoles r( + {}, + { + {100500, std::make_shared<TConsumerRoles>(THashMap<TString, TEntitiesPtr>{ + {"write", std::make_shared<TEntities>(CreateEntitiesIndex())}, + })}, + }, + {}, + std::make_shared<TString>()); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + r.GetRolesForService(NUnittest::CreateServiceTicket( + ETicketStatus::InvalidDst, + 100500)), + TIllegalUsage, + "Service ticket must be valid, got: InvalidDst"); + + TConsumerRolesPtr cons; + UNIT_ASSERT_NO_EXCEPTION( + cons = r.GetRolesForService(NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100501))); + UNIT_ASSERT_EQUAL(nullptr, cons); + + cons = r.GetRolesForService(NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500)); + UNIT_ASSERT_UNEQUAL(nullptr, cons); + UNIT_ASSERT(!cons->HasRole("read")); + UNIT_ASSERT(cons->HasRole("write")); + + ////shortcuts + // no tvmid + UNIT_ASSERT(!r.CheckServiceRole( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100501), + "write")); + + // no role + UNIT_ASSERT(!r.CheckServiceRole( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500), + "read")); + + // success + UNIT_ASSERT(r.CheckServiceRole( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500), + "write")); + + // no tvmid + UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100501), + "write", + {{"key#1", "value#11"}})); + + // no role + UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500), + "read", + {{"key#1", "value#11"}})); + + // no entity + UNIT_ASSERT(!r.CheckServiceRoleForExactEntity( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500), + "write", + {{"key#111", "value#11"}})); + + // success + UNIT_ASSERT(r.CheckServiceRoleForExactEntity( + NUnittest::CreateServiceTicket( + ETicketStatus::Ok, + 100500), + "write", + {{"key#1", "value#11"}})); + } + + Y_UNIT_TEST(RolesUser) { + TRoles r( + {}, + {}, + { + {789654, std::make_shared<TConsumerRoles>(THashMap<TString, TEntitiesPtr>{ + {"read", std::make_shared<TEntities>(CreateEntitiesIndex())}, + })}, + }, + std::make_shared<TString>("some roles")); + + UNIT_ASSERT_VALUES_EQUAL("some roles", r.GetRaw()); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Malformed, + 789654, + {})), + TIllegalUsage, + "User ticket must be valid, got: Malformed"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}), + 789123), + TIllegalUsage, + "User ticket must be from ProdYateam, got from Test"); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + 789123), + TIllegalUsage, + "selectedUid must be in user ticket but it's not: 789123"); + + TConsumerRolesPtr cons; + UNIT_ASSERT_NO_EXCEPTION( + cons = r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789123, + {}, + {}, + EBlackboxEnv::ProdYateam))); + UNIT_ASSERT_EQUAL(nullptr, cons); + + cons = r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam)); + UNIT_ASSERT_UNEQUAL(nullptr, cons); + UNIT_ASSERT(cons->HasRole("read")); + UNIT_ASSERT(!cons->HasRole("write")); + + cons = r.GetRolesForUser(NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789123, + {}, + {789654, 789741}, + EBlackboxEnv::ProdYateam), + 789654); + UNIT_ASSERT_UNEQUAL(nullptr, cons); + UNIT_ASSERT(cons->HasRole("read")); + UNIT_ASSERT(!cons->HasRole("write")); + + ////shortcuts + // no uid + UNIT_ASSERT(!r.CheckUserRole( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789123, + {}, + {}, + EBlackboxEnv::ProdYateam), + "read")); + + // no role + UNIT_ASSERT(!r.CheckUserRole( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + "wrire")); + + // success + UNIT_ASSERT(r.CheckUserRole( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + "read")); + + // no uid + UNIT_ASSERT(!r.CheckUserRoleForExactEntity( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789123, + {}, + {}, + EBlackboxEnv::ProdYateam), + "read", + {{"key#1", "value#11"}})); + + // no role + UNIT_ASSERT(!r.CheckUserRoleForExactEntity( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + "wrire", + {{"key#1", "value#11"}})); + + // no entity + UNIT_ASSERT(!r.CheckUserRoleForExactEntity( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + "read", + {{"key#111", "value#11"}})); + + // success + UNIT_ASSERT(r.CheckUserRoleForExactEntity( + NUnittest::CreateUserTicket( + ETicketStatus::Ok, + 789654, + {}, + {}, + EBlackboxEnv::ProdYateam), + "read", + {{"key#1", "value#11"}})); + } +} diff --git a/library/cpp/tvmauth/client/ut/roles/tvmapi_roles_fetcher_ut.cpp b/library/cpp/tvmauth/client/ut/roles/tvmapi_roles_fetcher_ut.cpp index 635bb8ca9e..7eaf611e82 100644 --- a/library/cpp/tvmauth/client/ut/roles/tvmapi_roles_fetcher_ut.cpp +++ b/library/cpp/tvmauth/client/ut/roles/tvmapi_roles_fetcher_ut.cpp @@ -1,197 +1,197 @@ -#include <library/cpp/tvmauth/client/ut/common.h> - -#include <library/cpp/tvmauth/client/misc/disk_cache.h> -#include <library/cpp/tvmauth/client/misc/api/roles_fetcher.h> - -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/testing/unittest/registar.h> - -#include <util/stream/file.h> -#include <util/system/fs.h> - -using namespace NTvmAuth; -using namespace NTvmAuth::NTvmApi; - -Y_UNIT_TEST_SUITE(TvmApiRolesFetcher) { - static const TString ROLES = R"({"revision": "100501", "born_date": 42})"; - - static const TString CACHE_DIR = "./tmp/"; - - static void CleanCache() { - NFs::RemoveRecursive(CACHE_DIR); - NFs::MakeDirectoryRecursive(CACHE_DIR); - } - - Y_UNIT_TEST(ReadFromDisk) { - CleanCache(); - auto logger = MakeIntrusive<TLogger>(); - - TRolesFetcherSettings s; - s.CacheDir = CACHE_DIR; - s.SelfTvmId = 111111; - s.IdmSystemSlug = "fem\tida"; - TRolesFetcher fetcher(s, logger); - - UNIT_ASSERT(!fetcher.AreRolesOk()); - - UNIT_ASSERT_VALUES_EQUAL(TInstant(), fetcher.ReadFromDisk()); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: File './tmp/roles' does not exist\n", - logger->Stream.Str()); - logger->Stream.clear(); - - const TInstant now = TInstant::Seconds(TInstant::Now().Seconds()); - - TDiskWriter wr(CACHE_DIR + "roles"); - UNIT_ASSERT(wr.Write("kek", now)); - UNIT_ASSERT_NO_EXCEPTION(fetcher.ReadFromDisk()); - UNIT_ASSERT(!fetcher.AreRolesOk()); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/roles' was successfully read\n" - << "4: Roles in disk cache are for another slug (kek). Self=fem\tida\n", - logger->Stream.Str()); - logger->Stream.clear(); - - UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat(ROLES, "femida_test"), now)); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), fetcher.ReadFromDisk()); - UNIT_ASSERT(!fetcher.AreRolesOk()); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/roles' was successfully read\n" - "4: Roles in disk cache are for another slug (femida_test). Self=fem\tida\n", - logger->Stream.Str()); - logger->Stream.clear(); - - UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat(ROLES, "fem\tida"), now)); - UNIT_ASSERT_VALUES_EQUAL(now, fetcher.ReadFromDisk()); - UNIT_ASSERT(fetcher.AreRolesOk()); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/roles' was successfully read\n" - "7: Succeed to read roles with revision 100501 from ./tmp/roles\n", - logger->Stream.Str()); - logger->Stream.clear(); - } - - Y_UNIT_TEST(IsTimeToUpdate) { - TRetrySettings settings; - settings.RolesUpdatePeriod = TDuration::Minutes(123); - - UNIT_ASSERT(!TRolesFetcher::IsTimeToUpdate(settings, TDuration::Seconds(5))); - UNIT_ASSERT(TRolesFetcher::IsTimeToUpdate(settings, TDuration::Hours(5))); - } - - Y_UNIT_TEST(ShouldWarn) { - TRetrySettings settings; - settings.RolesWarnPeriod = TDuration::Minutes(123); - - UNIT_ASSERT(!TRolesFetcher::ShouldWarn(settings, TDuration::Seconds(5))); - UNIT_ASSERT(TRolesFetcher::ShouldWarn(settings, TDuration::Hours(5))); - } - - Y_UNIT_TEST(Update) { - CleanCache(); - auto logger = MakeIntrusive<TLogger>(); - - TRolesFetcherSettings s; - s.CacheDir = CACHE_DIR; - s.SelfTvmId = 111111; - TRolesFetcher fetcher(s, logger); - - UNIT_ASSERT(!fetcher.AreRolesOk()); - - NUtils::TFetchResult fetchResult; - fetchResult.Code = 304; - - UNIT_ASSERT_EXCEPTION_CONTAINS( - fetcher.Update(NUtils::TFetchResult(fetchResult)), - yexception, - "tirole did not return any roles because current roles are actual, but there are no roles in memory"); - UNIT_ASSERT(!fetcher.AreRolesOk()); - UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); - - fetchResult.Code = 206; - UNIT_ASSERT_EXCEPTION_CONTAINS( - fetcher.Update(NUtils::TFetchResult(fetchResult)), - yexception, - "Unexpected code from tirole: 206."); - UNIT_ASSERT(!fetcher.AreRolesOk()); - UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); - - fetchResult.Code = 200; - fetchResult.Response = "kek"; - UNIT_ASSERT_EXCEPTION_CONTAINS( - fetcher.Update(NUtils::TFetchResult(fetchResult)), - yexception, - "Invalid json. 'kek'"); - UNIT_ASSERT(!fetcher.AreRolesOk()); - UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); - - fetchResult.Response = ROLES; - UNIT_ASSERT_NO_EXCEPTION(fetcher.Update(NUtils::TFetchResult(fetchResult))); - UNIT_ASSERT(fetcher.AreRolesOk()); - UNIT_ASSERT(NFs::Exists(CACHE_DIR + "roles")); - { - TFileInput f(CACHE_DIR + "roles"); - TString body = f.ReadAll(); - UNIT_ASSERT_C(body.Contains(ROLES), "got body: '" << body << "'"); - } - - fetchResult.Code = 304; - fetchResult.Response.clear(); - UNIT_ASSERT_NO_EXCEPTION(fetcher.Update(NUtils::TFetchResult(fetchResult))); - UNIT_ASSERT(fetcher.AreRolesOk()); - UNIT_ASSERT(NFs::Exists(CACHE_DIR + "roles")); - - fetchResult.Code = 200; - fetchResult.Headers.AddHeader("X-Tirole-Compression", "kek"); - UNIT_ASSERT_EXCEPTION_CONTAINS( - fetcher.Update(NUtils::TFetchResult(fetchResult)), - yexception, - "unknown codec format version; known: 1; got: kek"); - } - - Y_UNIT_TEST(CreateTiroleRequest) { - CleanCache(); - auto logger = MakeIntrusive<TLogger>(); - - TRolesFetcherSettings s; - s.CacheDir = CACHE_DIR; - s.SelfTvmId = 111111; - s.IdmSystemSlug = "some sys"; - TRolesFetcher fetcher(s, logger); - - TRolesFetcher::TRequest req = fetcher.CreateTiroleRequest("some_ticket"); - UNIT_ASSERT_VALUES_EQUAL( - "/v1/get_actual_roles?system_slug=some+sys&_pid=&lib_version=client_", - TStringBuf(req.Url).Chop(5)); - UNIT_ASSERT_VALUES_EQUAL( - TKeepAliveHttpClient::THeaders({ - {"X-Ya-Service-Ticket", "some_ticket"}, - }), - req.Headers); - - TDiskWriter wr(CACHE_DIR + "roles"); - UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat( - R"({"revision": "asd&qwe", "born_date": 42})", - "some sys"))); - UNIT_ASSERT_NO_EXCEPTION(fetcher.ReadFromDisk()); - - req = fetcher.CreateTiroleRequest("some_ticket"); - UNIT_ASSERT_VALUES_EQUAL( - "/v1/get_actual_roles?system_slug=some+sys&_pid=&lib_version=client_", - TStringBuf(req.Url).Chop(5)); - UNIT_ASSERT_VALUES_EQUAL( - TKeepAliveHttpClient::THeaders({ - {"If-None-Match", R"("asd&qwe")"}, - {"X-Ya-Service-Ticket", "some_ticket"}, - }), - req.Headers); - } -} +#include <library/cpp/tvmauth/client/ut/common.h> + +#include <library/cpp/tvmauth/client/misc/disk_cache.h> +#include <library/cpp/tvmauth/client/misc/api/roles_fetcher.h> + +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/testing/unittest/registar.h> + +#include <util/stream/file.h> +#include <util/system/fs.h> + +using namespace NTvmAuth; +using namespace NTvmAuth::NTvmApi; + +Y_UNIT_TEST_SUITE(TvmApiRolesFetcher) { + static const TString ROLES = R"({"revision": "100501", "born_date": 42})"; + + static const TString CACHE_DIR = "./tmp/"; + + static void CleanCache() { + NFs::RemoveRecursive(CACHE_DIR); + NFs::MakeDirectoryRecursive(CACHE_DIR); + } + + Y_UNIT_TEST(ReadFromDisk) { + CleanCache(); + auto logger = MakeIntrusive<TLogger>(); + + TRolesFetcherSettings s; + s.CacheDir = CACHE_DIR; + s.SelfTvmId = 111111; + s.IdmSystemSlug = "fem\tida"; + TRolesFetcher fetcher(s, logger); + + UNIT_ASSERT(!fetcher.AreRolesOk()); + + UNIT_ASSERT_VALUES_EQUAL(TInstant(), fetcher.ReadFromDisk()); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: File './tmp/roles' does not exist\n", + logger->Stream.Str()); + logger->Stream.clear(); + + const TInstant now = TInstant::Seconds(TInstant::Now().Seconds()); + + TDiskWriter wr(CACHE_DIR + "roles"); + UNIT_ASSERT(wr.Write("kek", now)); + UNIT_ASSERT_NO_EXCEPTION(fetcher.ReadFromDisk()); + UNIT_ASSERT(!fetcher.AreRolesOk()); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/roles' was successfully read\n" + << "4: Roles in disk cache are for another slug (kek). Self=fem\tida\n", + logger->Stream.Str()); + logger->Stream.clear(); + + UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat(ROLES, "femida_test"), now)); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), fetcher.ReadFromDisk()); + UNIT_ASSERT(!fetcher.AreRolesOk()); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/roles' was successfully read\n" + "4: Roles in disk cache are for another slug (femida_test). Self=fem\tida\n", + logger->Stream.Str()); + logger->Stream.clear(); + + UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat(ROLES, "fem\tida"), now)); + UNIT_ASSERT_VALUES_EQUAL(now, fetcher.ReadFromDisk()); + UNIT_ASSERT(fetcher.AreRolesOk()); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/roles' was successfully read\n" + "7: Succeed to read roles with revision 100501 from ./tmp/roles\n", + logger->Stream.Str()); + logger->Stream.clear(); + } + + Y_UNIT_TEST(IsTimeToUpdate) { + TRetrySettings settings; + settings.RolesUpdatePeriod = TDuration::Minutes(123); + + UNIT_ASSERT(!TRolesFetcher::IsTimeToUpdate(settings, TDuration::Seconds(5))); + UNIT_ASSERT(TRolesFetcher::IsTimeToUpdate(settings, TDuration::Hours(5))); + } + + Y_UNIT_TEST(ShouldWarn) { + TRetrySettings settings; + settings.RolesWarnPeriod = TDuration::Minutes(123); + + UNIT_ASSERT(!TRolesFetcher::ShouldWarn(settings, TDuration::Seconds(5))); + UNIT_ASSERT(TRolesFetcher::ShouldWarn(settings, TDuration::Hours(5))); + } + + Y_UNIT_TEST(Update) { + CleanCache(); + auto logger = MakeIntrusive<TLogger>(); + + TRolesFetcherSettings s; + s.CacheDir = CACHE_DIR; + s.SelfTvmId = 111111; + TRolesFetcher fetcher(s, logger); + + UNIT_ASSERT(!fetcher.AreRolesOk()); + + NUtils::TFetchResult fetchResult; + fetchResult.Code = 304; + + UNIT_ASSERT_EXCEPTION_CONTAINS( + fetcher.Update(NUtils::TFetchResult(fetchResult)), + yexception, + "tirole did not return any roles because current roles are actual, but there are no roles in memory"); + UNIT_ASSERT(!fetcher.AreRolesOk()); + UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); + + fetchResult.Code = 206; + UNIT_ASSERT_EXCEPTION_CONTAINS( + fetcher.Update(NUtils::TFetchResult(fetchResult)), + yexception, + "Unexpected code from tirole: 206."); + UNIT_ASSERT(!fetcher.AreRolesOk()); + UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); + + fetchResult.Code = 200; + fetchResult.Response = "kek"; + UNIT_ASSERT_EXCEPTION_CONTAINS( + fetcher.Update(NUtils::TFetchResult(fetchResult)), + yexception, + "Invalid json. 'kek'"); + UNIT_ASSERT(!fetcher.AreRolesOk()); + UNIT_ASSERT(!NFs::Exists(CACHE_DIR + "roles")); + + fetchResult.Response = ROLES; + UNIT_ASSERT_NO_EXCEPTION(fetcher.Update(NUtils::TFetchResult(fetchResult))); + UNIT_ASSERT(fetcher.AreRolesOk()); + UNIT_ASSERT(NFs::Exists(CACHE_DIR + "roles")); + { + TFileInput f(CACHE_DIR + "roles"); + TString body = f.ReadAll(); + UNIT_ASSERT_C(body.Contains(ROLES), "got body: '" << body << "'"); + } + + fetchResult.Code = 304; + fetchResult.Response.clear(); + UNIT_ASSERT_NO_EXCEPTION(fetcher.Update(NUtils::TFetchResult(fetchResult))); + UNIT_ASSERT(fetcher.AreRolesOk()); + UNIT_ASSERT(NFs::Exists(CACHE_DIR + "roles")); + + fetchResult.Code = 200; + fetchResult.Headers.AddHeader("X-Tirole-Compression", "kek"); + UNIT_ASSERT_EXCEPTION_CONTAINS( + fetcher.Update(NUtils::TFetchResult(fetchResult)), + yexception, + "unknown codec format version; known: 1; got: kek"); + } + + Y_UNIT_TEST(CreateTiroleRequest) { + CleanCache(); + auto logger = MakeIntrusive<TLogger>(); + + TRolesFetcherSettings s; + s.CacheDir = CACHE_DIR; + s.SelfTvmId = 111111; + s.IdmSystemSlug = "some sys"; + TRolesFetcher fetcher(s, logger); + + TRolesFetcher::TRequest req = fetcher.CreateTiroleRequest("some_ticket"); + UNIT_ASSERT_VALUES_EQUAL( + "/v1/get_actual_roles?system_slug=some+sys&_pid=&lib_version=client_", + TStringBuf(req.Url).Chop(5)); + UNIT_ASSERT_VALUES_EQUAL( + TKeepAliveHttpClient::THeaders({ + {"X-Ya-Service-Ticket", "some_ticket"}, + }), + req.Headers); + + TDiskWriter wr(CACHE_DIR + "roles"); + UNIT_ASSERT(wr.Write(TRolesFetcher::PrepareDiskFormat( + R"({"revision": "asd&qwe", "born_date": 42})", + "some sys"))); + UNIT_ASSERT_NO_EXCEPTION(fetcher.ReadFromDisk()); + + req = fetcher.CreateTiroleRequest("some_ticket"); + UNIT_ASSERT_VALUES_EQUAL( + "/v1/get_actual_roles?system_slug=some+sys&_pid=&lib_version=client_", + TStringBuf(req.Url).Chop(5)); + UNIT_ASSERT_VALUES_EQUAL( + TKeepAliveHttpClient::THeaders({ + {"If-None-Match", R"("asd&qwe")"}, + {"X-Ya-Service-Ticket", "some_ticket"}, + }), + req.Headers); + } +} diff --git a/library/cpp/tvmauth/client/ut/settings_ut.cpp b/library/cpp/tvmauth/client/ut/settings_ut.cpp index caa93c6a21..76c9542442 100644 --- a/library/cpp/tvmauth/client/ut/settings_ut.cpp +++ b/library/cpp/tvmauth/client/ut/settings_ut.cpp @@ -1,169 +1,169 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/misc/api/settings.h> - +#include "common.h" + +#include <library/cpp/tvmauth/client/misc/api/settings.h> + #include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - + +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 = { +#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, - .FetchServiceTicketsForDsts = {42}, - }, - .Err = "Secret is required for fetching of Service Tickets", - }, - TTestCase{ - .Name = "correct service tickets fetching", - .Settings = { - .SelfTvmId = 43, - .Secret = TStringBuf("foobar"), + .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"); - } - - Y_UNIT_TEST(Fetching) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(125); - - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - UNIT_ASSERT_NO_EXCEPTION(s.CheckValid()); - - UNIT_ASSERT_VALUES_EQUAL(s.FetchServiceTicketsForDsts.size(), 1); - UNIT_ASSERT_VALUES_EQUAL(s.FetchServiceTicketsForDsts[0], 19); - } -} + }, + .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"); + } + + Y_UNIT_TEST(Fetching) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(125); + + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + UNIT_ASSERT_NO_EXCEPTION(s.CheckValid()); + + UNIT_ASSERT_VALUES_EQUAL(s.FetchServiceTicketsForDsts.size(), 1); + UNIT_ASSERT_VALUES_EQUAL(s.FetchServiceTicketsForDsts[0], 19); + } +} diff --git a/library/cpp/tvmauth/client/ut/src_checker_ut.cpp b/library/cpp/tvmauth/client/ut/src_checker_ut.cpp index 30a3577aff..bd1646d6b9 100644 --- a/library/cpp/tvmauth/client/ut/src_checker_ut.cpp +++ b/library/cpp/tvmauth/client/ut/src_checker_ut.cpp @@ -1,47 +1,47 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/mocked_updater.h> -#include <library/cpp/tvmauth/client/misc/src_checker.h> -#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> - -#include <library/cpp/tvmauth/type.h> -#include <library/cpp/tvmauth/unittest.h> - -#include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(SrcChecker) { - Y_UNIT_TEST(Ctor) { - UNIT_ASSERT_EXCEPTION_CONTAINS( - TSrcChecker(new TMockedUpdater), - TBrokenTvmClientSettings, - "Need to use TClientSettings::EnableRolesFetching"); - } - - Y_UNIT_TEST(Check) { - NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( - NRoles::TRoles::TMeta{}, - NRoles::TRoles::TTvmConsumers{ - {12345, std::make_shared<NRoles::TConsumerRoles>( - THashMap<TString, NRoles::TEntitiesPtr>())}, - }, - NRoles::TRoles::TUserConsumers{}, - std::make_shared<TString>()); - const TSrcChecker checker(new TMockedUpdater({.Roles = roles})); - - UNIT_ASSERT_EXCEPTION_CONTAINS( - checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Expired, 12345)), - TIllegalUsage, - "Service ticket must be valid"); - - TCheckedServiceTicket ticket; - UNIT_ASSERT_NO_EXCEPTION( - ticket = checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Ok, 12345))); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); - - UNIT_ASSERT_NO_EXCEPTION( - ticket = checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Ok, 9999))); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, ticket.GetStatus()); - } -} +#include "common.h" + +#include <library/cpp/tvmauth/client/mocked_updater.h> +#include <library/cpp/tvmauth/client/misc/src_checker.h> +#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> + +#include <library/cpp/tvmauth/type.h> +#include <library/cpp/tvmauth/unittest.h> + +#include <library/cpp/testing/unittest/registar.h> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(SrcChecker) { + Y_UNIT_TEST(Ctor) { + UNIT_ASSERT_EXCEPTION_CONTAINS( + TSrcChecker(new TMockedUpdater), + TBrokenTvmClientSettings, + "Need to use TClientSettings::EnableRolesFetching"); + } + + Y_UNIT_TEST(Check) { + NRoles::TRolesPtr roles = std::make_shared<NRoles::TRoles>( + NRoles::TRoles::TMeta{}, + NRoles::TRoles::TTvmConsumers{ + {12345, std::make_shared<NRoles::TConsumerRoles>( + THashMap<TString, NRoles::TEntitiesPtr>())}, + }, + NRoles::TRoles::TUserConsumers{}, + std::make_shared<TString>()); + const TSrcChecker checker(new TMockedUpdater({.Roles = roles})); + + UNIT_ASSERT_EXCEPTION_CONTAINS( + checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Expired, 12345)), + TIllegalUsage, + "Service ticket must be valid"); + + TCheckedServiceTicket ticket; + UNIT_ASSERT_NO_EXCEPTION( + ticket = checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Ok, 12345))); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); + + UNIT_ASSERT_NO_EXCEPTION( + ticket = checker.Check(NUnittest::CreateServiceTicket(ETicketStatus::Ok, 9999))); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::NoRoles, ticket.GetStatus()); + } +} diff --git a/library/cpp/tvmauth/client/ut/tvmapi_updater_ut.cpp b/library/cpp/tvmauth/client/ut/tvmapi_updater_ut.cpp index 31650941c2..4cf449711b 100644 --- a/library/cpp/tvmauth/client/ut/tvmapi_updater_ut.cpp +++ b/library/cpp/tvmauth/client/ut/tvmapi_updater_ut.cpp @@ -1,1237 +1,1237 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/mocked_updater.h> -#include <library/cpp/tvmauth/client/misc/disk_cache.h> -#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> - +#include "common.h" + +#include <library/cpp/tvmauth/client/mocked_updater.h> +#include <library/cpp/tvmauth/client/misc/disk_cache.h> +#include <library/cpp/tvmauth/client/misc/api/threaded_updater.h> + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> - -#include <util/stream/file.h> -#include <util/string/subst.h> -#include <util/system/fs.h> - -#include <regex> - -using namespace NTvmAuth; -static const std::regex TIME_REGEX(R"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}Z)"); - -Y_UNIT_TEST_SUITE(ApiUpdater) { - static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; - static const TString TEST_TICKET = "3:user:CA0Q__________9_Gg4KAgh7EHsg0oXYzAQoAQ:FSADps3wNGm92Vyb1E9IVq5M6ZygdGdt1vafWWEhfDDeCLoVA-sJesxMl2pGW4OxJ8J1r_MfpG3ZoBk8rLVMHUFrPa6HheTbeXFAWl8quEniauXvKQe4VyrpA1SPgtRoFqi5upSDIJzEAe1YRJjq1EClQ_slMt8R0kA_JjKUX54"; - static const TString TVM_RESPONSE = - R"({ - "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - "213" : { "ticket" : "service_ticket_2"}, - "234" : { "error" : "Dst is not found" }, - "185" : { "ticket" : "service_ticket_3"}, - "deprecated" : { "ticket" : "deprecated_ticket" } - })"; - - static const TString CACHE_DIR = "./tmp/"; - - static void CleanCache() { - NFs::RemoveRecursive(CACHE_DIR); - NFs::MakeDirectoryRecursive(CACHE_DIR); - } - - Y_UNIT_TEST(MockedUpdater) { - TMockedUpdater m; - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, m.GetStatus()); - UNIT_ASSERT(m.GetCachedServiceContext()->Check(SRV_TICKET)); - UNIT_ASSERT(m.GetCachedUserContext()->Check(TEST_TICKET)); - } - - Y_UNIT_TEST(Updater) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(GetCachePath()); - - auto l = MakeIntrusive<TLogger>(); - { - auto u = NTvmApi::TThreadedUpdater::Create(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); - } - - UNIT_ASSERT_C(l->Stream.Str().find("was successfully read") != TString::npos, l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") == TString::npos, l->Stream.Str()); - } - - Y_UNIT_TEST(Updater_badConfig) { - NTvmApi::TClientSettings s; - UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); - s.SetSelfTvmId(100500); - UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); - s.SetDiskCacheDir(GetCachePath()); - UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); - } - - class TOfflineUpdater: public NTvmApi::TThreadedUpdater { - bool Enabled_; - TString PublicKeys_; - - public: - TOfflineUpdater(const NTvmApi::TClientSettings& settings, - TIntrusivePtr<TLogger> l, - bool enabled = false, - TString keys = NUnittest::TVMKNIFE_PUBLIC_KEYS) - : NTvmApi::TThreadedUpdater(settings, l) - , Enabled_(enabled) - , PublicKeys_(keys) - { - Init(); - StartWorker(); - } - - NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString&) const override { - if (!Enabled_) { - throw yexception() << "alarm"; - } - return {200, {}, "/2/ticket", TVM_RESPONSE, ""}; - } - - NUtils::TFetchResult FetchPublicKeysFromHttp() const override { - if (!Enabled_) { - throw yexception() << "alarm"; - } - return {200, {}, "/2/keys", PublicKeys_, ""}; - } - }; - - Y_UNIT_TEST(StartWithoutCache) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.EnableServiceTicketChecking(); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry:"); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() + +#include <util/stream/file.h> +#include <util/string/subst.h> +#include <util/system/fs.h> + +#include <regex> + +using namespace NTvmAuth; +static const std::regex TIME_REGEX(R"(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d.\d{6}Z)"); + +Y_UNIT_TEST_SUITE(ApiUpdater) { + static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; + static const TString TEST_TICKET = "3:user:CA0Q__________9_Gg4KAgh7EHsg0oXYzAQoAQ:FSADps3wNGm92Vyb1E9IVq5M6ZygdGdt1vafWWEhfDDeCLoVA-sJesxMl2pGW4OxJ8J1r_MfpG3ZoBk8rLVMHUFrPa6HheTbeXFAWl8quEniauXvKQe4VyrpA1SPgtRoFqi5upSDIJzEAe1YRJjq1EClQ_slMt8R0kA_JjKUX54"; + static const TString TVM_RESPONSE = + R"({ + "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + "213" : { "ticket" : "service_ticket_2"}, + "234" : { "error" : "Dst is not found" }, + "185" : { "ticket" : "service_ticket_3"}, + "deprecated" : { "ticket" : "deprecated_ticket" } + })"; + + static const TString CACHE_DIR = "./tmp/"; + + static void CleanCache() { + NFs::RemoveRecursive(CACHE_DIR); + NFs::MakeDirectoryRecursive(CACHE_DIR); + } + + Y_UNIT_TEST(MockedUpdater) { + TMockedUpdater m; + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, m.GetStatus()); + UNIT_ASSERT(m.GetCachedServiceContext()->Check(SRV_TICKET)); + UNIT_ASSERT(m.GetCachedUserContext()->Check(TEST_TICKET)); + } + + Y_UNIT_TEST(Updater) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(GetCachePath()); + + auto l = MakeIntrusive<TLogger>(); + { + auto u = NTvmApi::TThreadedUpdater::Create(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); + } + + UNIT_ASSERT_C(l->Stream.Str().find("was successfully read") != TString::npos, l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") == TString::npos, l->Stream.Str()); + } + + Y_UNIT_TEST(Updater_badConfig) { + NTvmApi::TClientSettings s; + UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); + s.SetSelfTvmId(100500); + UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); + s.SetDiskCacheDir(GetCachePath()); + UNIT_ASSERT_EXCEPTION(NTvmApi::TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), yexception); + } + + class TOfflineUpdater: public NTvmApi::TThreadedUpdater { + bool Enabled_; + TString PublicKeys_; + + public: + TOfflineUpdater(const NTvmApi::TClientSettings& settings, + TIntrusivePtr<TLogger> l, + bool enabled = false, + TString keys = NUnittest::TVMKNIFE_PUBLIC_KEYS) + : NTvmApi::TThreadedUpdater(settings, l) + , Enabled_(enabled) + , PublicKeys_(keys) + { + Init(); + StartWorker(); + } + + NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString&) const override { + if (!Enabled_) { + throw yexception() << "alarm"; + } + return {200, {}, "/2/ticket", TVM_RESPONSE, ""}; + } + + NUtils::TFetchResult FetchPublicKeysFromHttp() const override { + if (!Enabled_) { + throw yexception() << "alarm"; + } + return {200, {}, "/2/keys", PublicKeys_, ""}; + } + }; + + Y_UNIT_TEST(StartWithoutCache) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.EnableServiceTicketChecking(); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry:"); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() << "6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n" - << "4: Failed to get ServiceTickets: alarm\n" - << "4: Failed to get ServiceTickets: alarm\n" - << "4: Failed to get ServiceTickets: alarm\n" - << "4: Failed to update service tickets: alarm\n" - << "3: Service tickets have not been refreshed for too long period\n", - l->Stream.Str()); - } - - static void WriteFile(TString name, TStringBuf body, TInstant time) { - NFs::Remove(CACHE_DIR + name); - TFileOutput f(CACHE_DIR + name); - f << TDiskWriter::PrepareData(time, body); - } - - Y_UNIT_TEST(StartWithOldCache) { - CleanCache(); - WriteFile("./public_keys", - NUnittest::TVMKNIFE_PUBLIC_KEYS, - TInstant::Now() - TDuration::Days(30)); // too old - WriteFile("./service_tickets", - R"({"19":{"ticket":"3:serv:CBAQACIGCJSRBhAL:Fi"}})" - "\t100500", - TInstant::Now()); // too old - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_C(l->Stream.Str().find("Disk cache (public keys) is too old") != TString::npos, l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().find("Disk cache (service tickets) is too old") != TString::npos, l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") != TString::npos, l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithMissingCache) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir("../"); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry: "); - - UNIT_ASSERT_C(l->Stream.Str().find("does not exist") != TString::npos, l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") == TString::npos, l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithBadCache_Tickets) { - CleanCache(); - WriteFile("./service_tickets", - TVM_RESPONSE, - TInstant::Now()); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "4: Failed to read service tickets from disk: YYYYYYYYYYYYYYY\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX"), - std::regex(R"(Failed to read service tickets from disk: [^\n]+)"), - "Failed to read service tickets from disk: YYYYYYYYYYYYYYY")); - } - - Y_UNIT_TEST(StartWithBadCache_PublicKeys) { - CleanCache(); - WriteFile("./public_keys", - "ksjdafnlskdjzfgbhdl", - TInstant::Now()); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry:"); - - UNIT_ASSERT_C(l->Stream.Str().find("4: Failed to read public keys from disk: Malformed TVM keys") != TString::npos, l->Stream.Str()); - } - - Y_UNIT_TEST(StartWithCacheForAnotherTvmId) { - CleanCache(); - WriteFile("./service_tickets", - TVM_RESPONSE + "\t" + "100499", - TInstant::Now()); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "4: Disk cache is for another tvmId (100499). Self=100500\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(StartWithCacheForAnotherDsts) { - CleanCache(); - TInstant now = TInstant::Now(); - WriteFile("./service_tickets", - R"({"213" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEAs:T-"}})" - "\t" - "100500", - now); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - auto cache = u.GetCachedServiceTickets(); - UNIT_ASSERT(cache->TicketsById.contains(213)); - UNIT_ASSERT(cache->TicketsById.contains(19)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" - << "6: Cache was partly updated with 1 service ticket(s). total: 2\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - l->Stream.Clear(); - - { - TOfflineUpdater u(s, l, true); - auto cache = u.GetCachedServiceTickets(); - UNIT_ASSERT(cache->TicketsById.contains(213)); - UNIT_ASSERT(cache->TicketsById.contains(19)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 2 service ticket(s) from disk\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(StartWithNotFreshCacheForAnotherDsts) { - CleanCache(); - TInstant now = TInstant::Now(); - WriteFile("./service_tickets", - R"({"213" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEAs:T-"}})" - "\t" - "100500", - now - TDuration::Hours(2)); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - auto cache = u.GetCachedServiceTickets(); - UNIT_ASSERT(cache->TicketsById.contains(213)); - UNIT_ASSERT(cache->TicketsById.contains(19)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - l->Stream.Clear(); - - { - TOfflineUpdater u(s, l, true); - auto cache = u.GetCachedServiceTickets(); - UNIT_ASSERT(cache->TicketsById.contains(213)); - UNIT_ASSERT(cache->TicketsById.contains(19)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 2 service ticket(s) from disk\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(StartWithPartialDiskCache) { - CleanCache(); - WriteFile("./public_keys", - NUnittest::TVMKNIFE_PUBLIC_KEYS, - TInstant::Now()); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: File './tmp/service_tickets' does not exist\n" - << "6: File './tmp/public_keys' was successfully read\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(StartFromHttpAndRestartFromDisk) { - CleanCache(); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - s.SetDiskCacheDir(CACHE_DIR); - - { - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: File './tmp/service_tickets' does not exist\n" - << "7: File './tmp/public_keys' does not exist\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/service_tickets' was successfully written\n" - << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "6: File './tmp/public_keys' was successfully written\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - { - auto l = MakeIntrusive<TLogger>(); - { - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/service_tickets' was successfully read\n" - << "6: Got 1 service ticket(s) from disk\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" - << "6: File './tmp/public_keys' was successfully read\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - } - - class TUnstableUpdater: public NTvmApi::TThreadedUpdater { - mutable int V1_ = 0; - mutable int V2_ = 0; - - public: - TUnstableUpdater(const NTvmApi::TClientSettings& settings, TIntrusivePtr<TLogger> l) - : NTvmApi::TThreadedUpdater(settings, l) - { - UNIT_ASSERT_NO_EXCEPTION_C(Init(), l->Stream.Str()); - ExpBackoff_.SetEnabled(false); - StartWorker(); - - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, GetStatus(), l->Stream.Str()); - - Sleep(TDuration::MicroSeconds(100)); - PublicKeysDurations_.Expiring = TDuration::MicroSeconds(100); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus(TClientStatus::Warning, "Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru"), - GetStatus(), - l->Stream.Str()); - - PublicKeysDurations_.Invalid = TDuration::MicroSeconds(20); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Error, GetStatus(), l->Stream.Str()); - - PublicKeysDurations_.Expiring = TDuration::Seconds(100); - PublicKeysDurations_.Invalid = TDuration::Seconds(200); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, GetStatus(), l->Stream.Str()); - - ServiceTicketsDurations_.Expiring = TDuration::MicroSeconds(100); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Warning, GetStatus(), l->Stream.Str()); - - ServiceTicketsDurations_.Invalid = TDuration::MicroSeconds(20); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Warning, GetStatus(), l->Stream.Str()); - - const TInstant* inv = &GetCachedServiceTickets()->InvalidationTime; - *const_cast<TInstant*>(inv) = TInstant::Now() + TDuration::Seconds(30); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Error, GetStatus(), l->Stream.Str()); - } - - NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString&) const override { - Y_ENSURE_EX(++V1_ > 1, yexception() << "++v1_ > 1:" << V1_); - return {200, {}, "/2/ticket", TVM_RESPONSE, ""}; - } - - NUtils::TFetchResult FetchPublicKeysFromHttp() const override { - Y_ENSURE_EX(++V2_ > 2, yexception() << "++v2_ > 2:" << V2_); - return {200, {}, "/2/keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, ""}; - } - }; - - Y_UNIT_TEST(StartFromUnstableHttp) { - CleanCache(); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TUnstableUpdater u(s, l); - } - - UNIT_ASSERT_C(l->Stream.Str().Contains("++v1_ > 1"), l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().Contains("++v2_ > 2"), l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().Contains("7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net"), l->Stream.Str()); - UNIT_ASSERT_C(l->Stream.Str().Contains("7: Public keys were successfully fetched"), l->Stream.Str()); - } - - Y_UNIT_TEST(GetUpdateTimeOfServiceTickets) { - CleanCache(); - TInstant ins = TInstant::Now(); - WriteFile("./service_tickets", - TVM_RESPONSE + "\t" + "100500", - ins); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - TOfflineUpdater u(s, l, true); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(ins.Seconds()), u.GetUpdateTimeOfServiceTickets()); - } - - class TSignalingUpdater: public NTvmApi::TThreadedUpdater { - mutable int V_ = 0; - TAutoEvent& Ev_; - const TStringBuf PublicKeys_; - - public: - TSignalingUpdater(const NTvmApi::TClientSettings& settings, - TLoggerPtr l, - TAutoEvent& ev, - const TStringBuf keys = NUnittest::TVMKNIFE_PUBLIC_KEYS) - : NTvmApi::TThreadedUpdater(settings, l) - , Ev_(ev) - , PublicKeys_(keys) - { - WorkerAwakingPeriod_ = TDuration::MilliSeconds(300); - PublicKeysDurations_.RefreshPeriod = TDuration::MilliSeconds(700); - Init(); - ExpBackoff_.SetEnabled(false); - StartWorker(); - } - - NUtils::TFetchResult FetchPublicKeysFromHttp() const override { - if (++V_ >= 2) { - Ev_.Signal(); - } - return {200, {}, "/2/keys", TString(PublicKeys_), ""}; - } - }; - - Y_UNIT_TEST(StartWorker) { - class TSignalingUpdater: public NTvmApi::TThreadedUpdater { - mutable int V_ = 0; - TAutoEvent& Ev_; - - public: - TSignalingUpdater(const NTvmApi::TClientSettings& settings, TLoggerPtr l, TAutoEvent& ev) - : NTvmApi::TThreadedUpdater(settings, l) - , Ev_(ev) - { - WorkerAwakingPeriod_ = TDuration::MilliSeconds(300); - PublicKeysDurations_.RefreshPeriod = TDuration::MilliSeconds(700); - Init(); - ExpBackoff_.SetEnabled(false); - StartWorker(); - } - - void Worker() override { - NTvmApi::TThreadedUpdater::Worker(); - Ev_.Signal(); - } - - NUtils::TFetchResult FetchPublicKeysFromHttp() const override { - if (++V_ < 4) { - return {500, {}, "/2/keys", "lol", ""}; - } - return {200, {}, "/2/keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, "CAEQChkAAAAAAAD4PyGamZmZmZm5PyhkMAE4B0BGSAI"}; - } - }; - - CleanCache(); - TInstant expiringPubKeys = TInstant::Now() - TDuration::Days(3); - WriteFile("./public_keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, expiringPubKeys); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - TAutoEvent ev; - { - TSignalingUpdater u(s, l, ev); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus(TClientStatus::Warning, "PublicKeys: Path:/2/keys.Code=500: lol"), - u.GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(expiringPubKeys.Seconds()), u.GetUpdateTimeOfPublicKeys()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfServiceTickets()); - - UNIT_ASSERT(ev.WaitT(TDuration::Seconds(15))); - Sleep(TDuration::MilliSeconds(500)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/public_keys' was successfully read\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" - << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" - << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" - << "4: Failed to update public keys: Path:/2/keys.Code=500: lol\n" - << "3: Public keys have not been refreshed for too long period\n" - << "7: Thread-worker started\n" - << "7: Retry settings were updated: exponential_backoff_min:0.000000s->1.000000s;exponential_backoff_max:60.000000s->10.000000s;exponential_backoff_factor:2->1.5;exponential_backoff_jitter:0.5->0.1;max_random_sleep_default:5.000000s->0.100000s;retries_on_start:3->1;worker_awaking_period:10.000000s->7.000000s;dsts_limit:300->70;\n" - << "6: File './tmp/retry_settings' was successfully written\n" - << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "6: File './tmp/public_keys' was successfully written\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - -#if defined(_unix_) - Y_UNIT_TEST(StartFromCacheAndBadPublicKeysFromHttp) { - CleanCache(); - TInstant now = TInstant::Now(); - WriteFile("public_keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, now - TDuration::Days(3)); // expiring public keys - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - s.SetDiskCacheDir(CACHE_DIR); - - auto l = MakeIntrusive<TLogger>(); - { - TAutoEvent ev; - TSignalingUpdater u(s, l, ev, "malformed keys"); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus(TClientStatus::Warning, "PublicKeys: Malformed TVM keys"), - u.GetStatus()); - - UNIT_ASSERT(ev.WaitT(TDuration::Seconds(15))); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "6: File './tmp/public_keys' was successfully read\n" - << "6: Cache was updated with public keys: " << TInstant::Seconds((now - TDuration::Days(3)).Seconds()) << "\n" - << "7: File './tmp/retry_settings' does not exist\n" - << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" - << "4: Failed to update public keys: Malformed TVM keys\n" - << "3: Public keys have not been refreshed for too long period\n" - << "7: Thread-worker started\n" - << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" - << "4: Failed to update public keys: Malformed TVM keys\n" - << "3: Public keys have not been refreshed for too long period\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - } -#endif - - Y_UNIT_TEST(StartWithBadPublicKeysFromHttp) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - - auto l = MakeIntrusive<TLogger>(); - TAutoEvent ev; - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l, true, "some public keys"), - TRetriableException, - "Failed to start TvmClient. You can retry:"); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() + << "4: Failed to get ServiceTickets: alarm\n" + << "4: Failed to get ServiceTickets: alarm\n" + << "4: Failed to get ServiceTickets: alarm\n" + << "4: Failed to update service tickets: alarm\n" + << "3: Service tickets have not been refreshed for too long period\n", + l->Stream.Str()); + } + + static void WriteFile(TString name, TStringBuf body, TInstant time) { + NFs::Remove(CACHE_DIR + name); + TFileOutput f(CACHE_DIR + name); + f << TDiskWriter::PrepareData(time, body); + } + + Y_UNIT_TEST(StartWithOldCache) { + CleanCache(); + WriteFile("./public_keys", + NUnittest::TVMKNIFE_PUBLIC_KEYS, + TInstant::Now() - TDuration::Days(30)); // too old + WriteFile("./service_tickets", + R"({"19":{"ticket":"3:serv:CBAQACIGCJSRBhAL:Fi"}})" + "\t100500", + TInstant::Now()); // too old + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_C(l->Stream.Str().find("Disk cache (public keys) is too old") != TString::npos, l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().find("Disk cache (service tickets) is too old") != TString::npos, l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") != TString::npos, l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithMissingCache) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir("../"); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry: "); + + UNIT_ASSERT_C(l->Stream.Str().find("does not exist") != TString::npos, l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().find("were successfully fetched") == TString::npos, l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithBadCache_Tickets) { + CleanCache(); + WriteFile("./service_tickets", + TVM_RESPONSE, + TInstant::Now()); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "4: Failed to read service tickets from disk: YYYYYYYYYYYYYYY\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX"), + std::regex(R"(Failed to read service tickets from disk: [^\n]+)"), + "Failed to read service tickets from disk: YYYYYYYYYYYYYYY")); + } + + Y_UNIT_TEST(StartWithBadCache_PublicKeys) { + CleanCache(); + WriteFile("./public_keys", + "ksjdafnlskdjzfgbhdl", + TInstant::Now()); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry:"); + + UNIT_ASSERT_C(l->Stream.Str().find("4: Failed to read public keys from disk: Malformed TVM keys") != TString::npos, l->Stream.Str()); + } + + Y_UNIT_TEST(StartWithCacheForAnotherTvmId) { + CleanCache(); + WriteFile("./service_tickets", + TVM_RESPONSE + "\t" + "100499", + TInstant::Now()); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "4: Disk cache is for another tvmId (100499). Self=100500\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(StartWithCacheForAnotherDsts) { + CleanCache(); + TInstant now = TInstant::Now(); + WriteFile("./service_tickets", + R"({"213" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEAs:T-"}})" + "\t" + "100500", + now); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + auto cache = u.GetCachedServiceTickets(); + UNIT_ASSERT(cache->TicketsById.contains(213)); + UNIT_ASSERT(cache->TicketsById.contains(19)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): " << TInstant::Seconds(now.Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" + << "6: Cache was partly updated with 1 service ticket(s). total: 2\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + l->Stream.Clear(); + + { + TOfflineUpdater u(s, l, true); + auto cache = u.GetCachedServiceTickets(); + UNIT_ASSERT(cache->TicketsById.contains(213)); + UNIT_ASSERT(cache->TicketsById.contains(19)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 2 service ticket(s) from disk\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(StartWithNotFreshCacheForAnotherDsts) { + CleanCache(); + TInstant now = TInstant::Now(); + WriteFile("./service_tickets", + R"({"213" : { "ticket" : "3:serv:CBAQ__________9_IgYIlJEGEAs:T-"}})" + "\t" + "100500", + now - TDuration::Hours(2)); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + auto cache = u.GetCachedServiceTickets(); + UNIT_ASSERT(cache->TicketsById.contains(213)); + UNIT_ASSERT(cache->TicketsById.contains(19)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + l->Stream.Clear(); + + { + TOfflineUpdater u(s, l, true); + auto cache = u.GetCachedServiceTickets(); + UNIT_ASSERT(cache->TicketsById.contains(213)); + UNIT_ASSERT(cache->TicketsById.contains(19)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 2 service ticket(s) from disk\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(StartWithPartialDiskCache) { + CleanCache(); + WriteFile("./public_keys", + NUnittest::TVMKNIFE_PUBLIC_KEYS, + TInstant::Now()); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"kolmo", 213}}); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: File './tmp/service_tickets' does not exist\n" + << "6: File './tmp/public_keys' was successfully read\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "6: Cache was updated with 2 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(StartFromHttpAndRestartFromDisk) { + CleanCache(); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + s.SetDiskCacheDir(CACHE_DIR); + + { + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: File './tmp/service_tickets' does not exist\n" + << "7: File './tmp/public_keys' does not exist\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/service_tickets' was successfully written\n" + << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "6: File './tmp/public_keys' was successfully written\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + { + auto l = MakeIntrusive<TLogger>(); + { + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/service_tickets' was successfully read\n" + << "6: Got 1 service ticket(s) from disk\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" + << "6: File './tmp/public_keys' was successfully read\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + } + + class TUnstableUpdater: public NTvmApi::TThreadedUpdater { + mutable int V1_ = 0; + mutable int V2_ = 0; + + public: + TUnstableUpdater(const NTvmApi::TClientSettings& settings, TIntrusivePtr<TLogger> l) + : NTvmApi::TThreadedUpdater(settings, l) + { + UNIT_ASSERT_NO_EXCEPTION_C(Init(), l->Stream.Str()); + ExpBackoff_.SetEnabled(false); + StartWorker(); + + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, GetStatus(), l->Stream.Str()); + + Sleep(TDuration::MicroSeconds(100)); + PublicKeysDurations_.Expiring = TDuration::MicroSeconds(100); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus(TClientStatus::Warning, "Internal client error: failed to collect last useful error message, please report this message to tvm-dev@yandex-team.ru"), + GetStatus(), + l->Stream.Str()); + + PublicKeysDurations_.Invalid = TDuration::MicroSeconds(20); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Error, GetStatus(), l->Stream.Str()); + + PublicKeysDurations_.Expiring = TDuration::Seconds(100); + PublicKeysDurations_.Invalid = TDuration::Seconds(200); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, GetStatus(), l->Stream.Str()); + + ServiceTicketsDurations_.Expiring = TDuration::MicroSeconds(100); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Warning, GetStatus(), l->Stream.Str()); + + ServiceTicketsDurations_.Invalid = TDuration::MicroSeconds(20); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Warning, GetStatus(), l->Stream.Str()); + + const TInstant* inv = &GetCachedServiceTickets()->InvalidationTime; + *const_cast<TInstant*>(inv) = TInstant::Now() + TDuration::Seconds(30); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Error, GetStatus(), l->Stream.Str()); + } + + NUtils::TFetchResult FetchServiceTicketsFromHttp(const TString&) const override { + Y_ENSURE_EX(++V1_ > 1, yexception() << "++v1_ > 1:" << V1_); + return {200, {}, "/2/ticket", TVM_RESPONSE, ""}; + } + + NUtils::TFetchResult FetchPublicKeysFromHttp() const override { + Y_ENSURE_EX(++V2_ > 2, yexception() << "++v2_ > 2:" << V2_); + return {200, {}, "/2/keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, ""}; + } + }; + + Y_UNIT_TEST(StartFromUnstableHttp) { + CleanCache(); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TUnstableUpdater u(s, l); + } + + UNIT_ASSERT_C(l->Stream.Str().Contains("++v1_ > 1"), l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().Contains("++v2_ > 2"), l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().Contains("7: Response with service tickets for 1 destination(s) was successfully fetched from https://tvm-api.yandex.net"), l->Stream.Str()); + UNIT_ASSERT_C(l->Stream.Str().Contains("7: Public keys were successfully fetched"), l->Stream.Str()); + } + + Y_UNIT_TEST(GetUpdateTimeOfServiceTickets) { + CleanCache(); + TInstant ins = TInstant::Now(); + WriteFile("./service_tickets", + TVM_RESPONSE + "\t" + "100500", + ins); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + TOfflineUpdater u(s, l, true); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(ins.Seconds()), u.GetUpdateTimeOfServiceTickets()); + } + + class TSignalingUpdater: public NTvmApi::TThreadedUpdater { + mutable int V_ = 0; + TAutoEvent& Ev_; + const TStringBuf PublicKeys_; + + public: + TSignalingUpdater(const NTvmApi::TClientSettings& settings, + TLoggerPtr l, + TAutoEvent& ev, + const TStringBuf keys = NUnittest::TVMKNIFE_PUBLIC_KEYS) + : NTvmApi::TThreadedUpdater(settings, l) + , Ev_(ev) + , PublicKeys_(keys) + { + WorkerAwakingPeriod_ = TDuration::MilliSeconds(300); + PublicKeysDurations_.RefreshPeriod = TDuration::MilliSeconds(700); + Init(); + ExpBackoff_.SetEnabled(false); + StartWorker(); + } + + NUtils::TFetchResult FetchPublicKeysFromHttp() const override { + if (++V_ >= 2) { + Ev_.Signal(); + } + return {200, {}, "/2/keys", TString(PublicKeys_), ""}; + } + }; + + Y_UNIT_TEST(StartWorker) { + class TSignalingUpdater: public NTvmApi::TThreadedUpdater { + mutable int V_ = 0; + TAutoEvent& Ev_; + + public: + TSignalingUpdater(const NTvmApi::TClientSettings& settings, TLoggerPtr l, TAutoEvent& ev) + : NTvmApi::TThreadedUpdater(settings, l) + , Ev_(ev) + { + WorkerAwakingPeriod_ = TDuration::MilliSeconds(300); + PublicKeysDurations_.RefreshPeriod = TDuration::MilliSeconds(700); + Init(); + ExpBackoff_.SetEnabled(false); + StartWorker(); + } + + void Worker() override { + NTvmApi::TThreadedUpdater::Worker(); + Ev_.Signal(); + } + + NUtils::TFetchResult FetchPublicKeysFromHttp() const override { + if (++V_ < 4) { + return {500, {}, "/2/keys", "lol", ""}; + } + return {200, {}, "/2/keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, "CAEQChkAAAAAAAD4PyGamZmZmZm5PyhkMAE4B0BGSAI"}; + } + }; + + CleanCache(); + TInstant expiringPubKeys = TInstant::Now() - TDuration::Days(3); + WriteFile("./public_keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, expiringPubKeys); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + TAutoEvent ev; + { + TSignalingUpdater u(s, l, ev); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus(TClientStatus::Warning, "PublicKeys: Path:/2/keys.Code=500: lol"), + u.GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(expiringPubKeys.Seconds()), u.GetUpdateTimeOfPublicKeys()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfServiceTickets()); + + UNIT_ASSERT(ev.WaitT(TDuration::Seconds(15))); + Sleep(TDuration::MilliSeconds(500)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/public_keys' was successfully read\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" + << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" + << "4: Failed to get PublicKeys: Path:/2/keys.Code=500: lol\n" + << "4: Failed to update public keys: Path:/2/keys.Code=500: lol\n" + << "3: Public keys have not been refreshed for too long period\n" + << "7: Thread-worker started\n" + << "7: Retry settings were updated: exponential_backoff_min:0.000000s->1.000000s;exponential_backoff_max:60.000000s->10.000000s;exponential_backoff_factor:2->1.5;exponential_backoff_jitter:0.5->0.1;max_random_sleep_default:5.000000s->0.100000s;retries_on_start:3->1;worker_awaking_period:10.000000s->7.000000s;dsts_limit:300->70;\n" + << "6: File './tmp/retry_settings' was successfully written\n" + << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "6: File './tmp/public_keys' was successfully written\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + +#if defined(_unix_) + Y_UNIT_TEST(StartFromCacheAndBadPublicKeysFromHttp) { + CleanCache(); + TInstant now = TInstant::Now(); + WriteFile("public_keys", NUnittest::TVMKNIFE_PUBLIC_KEYS, now - TDuration::Days(3)); // expiring public keys + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + s.SetDiskCacheDir(CACHE_DIR); + + auto l = MakeIntrusive<TLogger>(); + { + TAutoEvent ev; + TSignalingUpdater u(s, l, ev, "malformed keys"); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus(TClientStatus::Warning, "PublicKeys: Malformed TVM keys"), + u.GetStatus()); + + UNIT_ASSERT(ev.WaitT(TDuration::Seconds(15))); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "6: File './tmp/public_keys' was successfully read\n" + << "6: Cache was updated with public keys: " << TInstant::Seconds((now - TDuration::Days(3)).Seconds()) << "\n" + << "7: File './tmp/retry_settings' does not exist\n" + << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" + << "4: Failed to update public keys: Malformed TVM keys\n" + << "3: Public keys have not been refreshed for too long period\n" + << "7: Thread-worker started\n" + << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" + << "4: Failed to update public keys: Malformed TVM keys\n" + << "3: Public keys have not been refreshed for too long period\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + } +#endif + + Y_UNIT_TEST(StartWithBadPublicKeysFromHttp) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + + auto l = MakeIntrusive<TLogger>(); + TAutoEvent ev; + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l, true, "some public keys"), + TRetriableException, + "Failed to start TvmClient. You can retry:"); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() << "6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n" - << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" - << "4: Failed to update public keys: Malformed TVM keys\n" - << "3: Public keys have not been refreshed for too long period\n", - l->Stream.Str()); - } - - class TNotInitedUpdater: public NTvmApi::TThreadedUpdater { - public: - TNotInitedUpdater(const NTvmApi::TClientSettings& settings, TLoggerPtr l = TDevNullLogger::IAmBrave()) - : NTvmApi::TThreadedUpdater(settings, l) - { - this->ExpBackoff_.SetEnabled(false); - } - - using NTvmApi::TThreadedUpdater::AppendToJsonArray; - using NTvmApi::TThreadedUpdater::AreServicesTicketsOk; - using NTvmApi::TThreadedUpdater::CreateJsonArray; - using NTvmApi::TThreadedUpdater::FindMissingDsts; - using NTvmApi::TThreadedUpdater::GetPublicKeysFromHttp; - using NTvmApi::TThreadedUpdater::GetServiceTicketsFromHttp; - using NTvmApi::TThreadedUpdater::Init; - using NTvmApi::TThreadedUpdater::IsServiceContextOk; - using NTvmApi::TThreadedUpdater::IsTimeToUpdatePublicKeys; - using NTvmApi::TThreadedUpdater::IsTimeToUpdateServiceTickets; - using NTvmApi::TThreadedUpdater::IsUserContextOk; - using NTvmApi::TThreadedUpdater::ParseTicketsFromDisk; - using NTvmApi::TThreadedUpdater::ParseTicketsFromResponse; - using NTvmApi::TThreadedUpdater::PrepareRequestForServiceTickets; - using NTvmApi::TThreadedUpdater::PrepareTicketsForDisk; - using NTvmApi::TThreadedUpdater::SetServiceContext; - using NTvmApi::TThreadedUpdater::SetServiceTickets; - using NTvmApi::TThreadedUpdater::SetUserContext; - using NTvmApi::TThreadedUpdater::THttpResult; - using NTvmApi::TThreadedUpdater::TPairTicketsErrors; - using TAsyncUpdaterBase::IsServiceTicketMapOk; - }; - - Y_UNIT_TEST(IsCacheComplete_Empty) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - - TNotInitedUpdater u(s); - UNIT_ASSERT(!u.AreServicesTicketsOk()); - } - - Y_UNIT_TEST(IsCacheComplete_Tickets) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); - - TNotInitedUpdater u(s); - UNIT_ASSERT(!u.AreServicesTicketsOk()); - - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - TServiceTickets::TMapIdStr({{1, "mega_ticket"}}), - TServiceTickets::TMapIdStr({{2, "mega_error"}}), - TServiceTickets::TMapAliasId())); - UNIT_ASSERT(!u.AreServicesTicketsOk()); - - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - TServiceTickets::TMapIdStr({ - {1, "mega_ticket"}, - {2, "mega_ticket2"}, - }), - TServiceTickets::TMapIdStr({ - {3, "mega_error3"}, - }), - TServiceTickets::TMapAliasId())); - UNIT_ASSERT(u.AreServicesTicketsOk()); - } - - Y_UNIT_TEST(IsCacheComplete_Service) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - - TNotInitedUpdater u(s); - UNIT_ASSERT(!u.IsServiceContextOk()); - - u.SetServiceContext(MakeIntrusiveConst<TServiceContext>( - TServiceContext::CheckingFactory(100500, NUnittest::TVMKNIFE_PUBLIC_KEYS))); - UNIT_ASSERT(u.IsServiceContextOk()); - } - - Y_UNIT_TEST(IsCacheComplete_User) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - - TNotInitedUpdater u(s); - UNIT_ASSERT(!u.IsUserContextOk()); - - u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); - UNIT_ASSERT(u.IsUserContextOk()); - } - - Y_UNIT_TEST(TicketsOnDisk) { - TString res = R"({ - "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - "213" : { "ticket" : "service_ticket_2"}, - "234" : { "error" : "Dst is not found" }, - "185" : { "ticket" : "service_ticket_3"}, - "deprecated" : { "ticket" : "deprecated_ticket" } - })"; - res.append("\t100500"); - - UNIT_ASSERT_VALUES_EQUAL(res, TNotInitedUpdater::PrepareTicketsForDisk(TVM_RESPONSE, 100500)); - - auto pair = TNotInitedUpdater::ParseTicketsFromDisk(res); - UNIT_ASSERT_VALUES_EQUAL(pair.first, TVM_RESPONSE); - UNIT_ASSERT_VALUES_EQUAL(pair.second, 100500); - - res.push_back('a'); - UNIT_ASSERT_EXCEPTION(TNotInitedUpdater::ParseTicketsFromDisk(res), yexception); - } - - Y_UNIT_TEST(IsTimeToUpdatePublicKeys) { - NTvmApi::TClientSettings s; - s.EnableUserTicketChecking(EBlackboxEnv::Test); - - TNotInitedUpdater u(s); - - UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now())); - UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Hours(23))); - UNIT_ASSERT(u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Days(1) - TDuration::MilliSeconds(1))); - } - - Y_UNIT_TEST(IsTimeToUpdateServiceTickets) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); - - TNotInitedUpdater u(s); - - UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(TInstant::Now() - TDuration::Minutes(59))); - UNIT_ASSERT(u.IsTimeToUpdateServiceTickets(TInstant::Now() - TDuration::Hours(1) - TDuration::MilliSeconds(1))); - } - - Y_UNIT_TEST(StartWithIncompliteCache) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", NTvmApi::TClientSettings::TDstVector({19, 20})); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l, true), - TNonRetriableException, - "Failed to get ServiceTicket for 20: Missing tvm_id in response, should never happend: 20"); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() + << "7: Public keys were successfully fetched from https://tvm-api.yandex.net\n" + << "4: Failed to update public keys: Malformed TVM keys\n" + << "3: Public keys have not been refreshed for too long period\n", + l->Stream.Str()); + } + + class TNotInitedUpdater: public NTvmApi::TThreadedUpdater { + public: + TNotInitedUpdater(const NTvmApi::TClientSettings& settings, TLoggerPtr l = TDevNullLogger::IAmBrave()) + : NTvmApi::TThreadedUpdater(settings, l) + { + this->ExpBackoff_.SetEnabled(false); + } + + using NTvmApi::TThreadedUpdater::AppendToJsonArray; + using NTvmApi::TThreadedUpdater::AreServicesTicketsOk; + using NTvmApi::TThreadedUpdater::CreateJsonArray; + using NTvmApi::TThreadedUpdater::FindMissingDsts; + using NTvmApi::TThreadedUpdater::GetPublicKeysFromHttp; + using NTvmApi::TThreadedUpdater::GetServiceTicketsFromHttp; + using NTvmApi::TThreadedUpdater::Init; + using NTvmApi::TThreadedUpdater::IsServiceContextOk; + using NTvmApi::TThreadedUpdater::IsTimeToUpdatePublicKeys; + using NTvmApi::TThreadedUpdater::IsTimeToUpdateServiceTickets; + using NTvmApi::TThreadedUpdater::IsUserContextOk; + using NTvmApi::TThreadedUpdater::ParseTicketsFromDisk; + using NTvmApi::TThreadedUpdater::ParseTicketsFromResponse; + using NTvmApi::TThreadedUpdater::PrepareRequestForServiceTickets; + using NTvmApi::TThreadedUpdater::PrepareTicketsForDisk; + using NTvmApi::TThreadedUpdater::SetServiceContext; + using NTvmApi::TThreadedUpdater::SetServiceTickets; + using NTvmApi::TThreadedUpdater::SetUserContext; + using NTvmApi::TThreadedUpdater::THttpResult; + using NTvmApi::TThreadedUpdater::TPairTicketsErrors; + using TAsyncUpdaterBase::IsServiceTicketMapOk; + }; + + Y_UNIT_TEST(IsCacheComplete_Empty) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + + TNotInitedUpdater u(s); + UNIT_ASSERT(!u.AreServicesTicketsOk()); + } + + Y_UNIT_TEST(IsCacheComplete_Tickets) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); + + TNotInitedUpdater u(s); + UNIT_ASSERT(!u.AreServicesTicketsOk()); + + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + TServiceTickets::TMapIdStr({{1, "mega_ticket"}}), + TServiceTickets::TMapIdStr({{2, "mega_error"}}), + TServiceTickets::TMapAliasId())); + UNIT_ASSERT(!u.AreServicesTicketsOk()); + + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + TServiceTickets::TMapIdStr({ + {1, "mega_ticket"}, + {2, "mega_ticket2"}, + }), + TServiceTickets::TMapIdStr({ + {3, "mega_error3"}, + }), + TServiceTickets::TMapAliasId())); + UNIT_ASSERT(u.AreServicesTicketsOk()); + } + + Y_UNIT_TEST(IsCacheComplete_Service) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + + TNotInitedUpdater u(s); + UNIT_ASSERT(!u.IsServiceContextOk()); + + u.SetServiceContext(MakeIntrusiveConst<TServiceContext>( + TServiceContext::CheckingFactory(100500, NUnittest::TVMKNIFE_PUBLIC_KEYS))); + UNIT_ASSERT(u.IsServiceContextOk()); + } + + Y_UNIT_TEST(IsCacheComplete_User) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + + TNotInitedUpdater u(s); + UNIT_ASSERT(!u.IsUserContextOk()); + + u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); + UNIT_ASSERT(u.IsUserContextOk()); + } + + Y_UNIT_TEST(TicketsOnDisk) { + TString res = R"({ + "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + "213" : { "ticket" : "service_ticket_2"}, + "234" : { "error" : "Dst is not found" }, + "185" : { "ticket" : "service_ticket_3"}, + "deprecated" : { "ticket" : "deprecated_ticket" } + })"; + res.append("\t100500"); + + UNIT_ASSERT_VALUES_EQUAL(res, TNotInitedUpdater::PrepareTicketsForDisk(TVM_RESPONSE, 100500)); + + auto pair = TNotInitedUpdater::ParseTicketsFromDisk(res); + UNIT_ASSERT_VALUES_EQUAL(pair.first, TVM_RESPONSE); + UNIT_ASSERT_VALUES_EQUAL(pair.second, 100500); + + res.push_back('a'); + UNIT_ASSERT_EXCEPTION(TNotInitedUpdater::ParseTicketsFromDisk(res), yexception); + } + + Y_UNIT_TEST(IsTimeToUpdatePublicKeys) { + NTvmApi::TClientSettings s; + s.EnableUserTicketChecking(EBlackboxEnv::Test); + + TNotInitedUpdater u(s); + + UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now())); + UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Hours(23))); + UNIT_ASSERT(u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Days(1) - TDuration::MilliSeconds(1))); + } + + Y_UNIT_TEST(IsTimeToUpdateServiceTickets) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}, {"blackbox2", 20}}); + + TNotInitedUpdater u(s); + + UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(TInstant::Now() - TDuration::Minutes(59))); + UNIT_ASSERT(u.IsTimeToUpdateServiceTickets(TInstant::Now() - TDuration::Hours(1) - TDuration::MilliSeconds(1))); + } + + Y_UNIT_TEST(StartWithIncompliteCache) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", NTvmApi::TClientSettings::TDstVector({19, 20})); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TOfflineUpdater(s, l, true), + TNonRetriableException, + "Failed to get ServiceTicket for 20: Missing tvm_id in response, should never happend: 20"); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() << "6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" - << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" - << "3: Failed to get service ticket for dst=20: Missing tvm_id in response, should never happend: 20\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(PrepareRequestForServiceTickets) { - const TServiceContext ctx = TServiceContext::SigningFactory("AAAAAAAAAAAAAAAAAAAAAA"); - - TString s = TNotInitedUpdater::PrepareRequestForServiceTickets(117, - ctx, - {19, 20}, - NUtils::TProcInfo{ - "__some_pid__", - "__some_pname__", - "kar", - }, - 100700); - SubstGlobal(s.resize(s.size() - 5), "deb_", ""); - UNIT_ASSERT_VALUES_EQUAL("grant_type=client_credentials&src=117&dst=19,20&ts=100700&sign=XTz2Obd6PII_BHxswzWPJTjju9SrKsN6hyu1VsyxBvU&get_retry_settings=yes&_pid=__some_pid__&_procces_name=__some_pname__&lib_version=client_kar", - s); - - s = TNotInitedUpdater::PrepareRequestForServiceTickets(118, - ctx, - {19}, - NUtils::TProcInfo{ - "__some_pid__", - {}, - "kva_", - }, - 100900); - SubstGlobal(s.resize(s.size() - 5), "deb_", ""); - UNIT_ASSERT_VALUES_EQUAL("grant_type=client_credentials&src=118&dst=19&ts=100900&sign=-trBo9AtBLjp2ihy6cFAdMAQ6S9afHj23rFzYQ32jkQ&get_retry_settings=yes&_pid=__some_pid__&lib_version=client_kva_", - s); - } - - Y_UNIT_TEST(ParseTicketsFromResponse) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - - auto l = MakeIntrusive<TLogger>(); - TNotInitedUpdater u(s, l); - - TNotInitedUpdater::TPairTicketsErrors t; - UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseTicketsFromResponse("{", NTvmApi::TDstSet{19}, t), - yexception, - "Invalid json from tvm-api"); - - t = {}; - u.ParseTicketsFromResponse(TVM_RESPONSE, NTvmApi::TDstSet{19}, t); - - TNotInitedUpdater::TPairTicketsErrors expected{{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {}}; + << "7: Response with service tickets for 2 destination(s) was successfully fetched from https://tvm-api.yandex.net\n" + << "7: Got responses with service tickets with 1 pages for 2 destination(s)\n" + << "3: Failed to get service ticket for dst=20: Missing tvm_id in response, should never happend: 20\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(PrepareRequestForServiceTickets) { + const TServiceContext ctx = TServiceContext::SigningFactory("AAAAAAAAAAAAAAAAAAAAAA"); + + TString s = TNotInitedUpdater::PrepareRequestForServiceTickets(117, + ctx, + {19, 20}, + NUtils::TProcInfo{ + "__some_pid__", + "__some_pname__", + "kar", + }, + 100700); + SubstGlobal(s.resize(s.size() - 5), "deb_", ""); + UNIT_ASSERT_VALUES_EQUAL("grant_type=client_credentials&src=117&dst=19,20&ts=100700&sign=XTz2Obd6PII_BHxswzWPJTjju9SrKsN6hyu1VsyxBvU&get_retry_settings=yes&_pid=__some_pid__&_procces_name=__some_pname__&lib_version=client_kar", + s); + + s = TNotInitedUpdater::PrepareRequestForServiceTickets(118, + ctx, + {19}, + NUtils::TProcInfo{ + "__some_pid__", + {}, + "kva_", + }, + 100900); + SubstGlobal(s.resize(s.size() - 5), "deb_", ""); + UNIT_ASSERT_VALUES_EQUAL("grant_type=client_credentials&src=118&dst=19&ts=100900&sign=-trBo9AtBLjp2ihy6cFAdMAQ6S9afHj23rFzYQ32jkQ&get_retry_settings=yes&_pid=__some_pid__&lib_version=client_kva_", + s); + } + + Y_UNIT_TEST(ParseTicketsFromResponse) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + + auto l = MakeIntrusive<TLogger>(); + TNotInitedUpdater u(s, l); + + TNotInitedUpdater::TPairTicketsErrors t; + UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseTicketsFromResponse("{", NTvmApi::TDstSet{19}, t), + yexception, + "Invalid json from tvm-api"); + + t = {}; + u.ParseTicketsFromResponse(TVM_RESPONSE, NTvmApi::TDstSet{19}, t); + + TNotInitedUpdater::TPairTicketsErrors expected{{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {}}; UNIT_ASSERT_VALUES_EQUAL("6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n", - l->Stream.Str()); - UNIT_ASSERT_EQUAL(expected, t); - - t = {}; - u.ParseTicketsFromResponse(TVM_RESPONSE, - NTvmApi::TDstSet{19, 213, 234, 235}, - t); - expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - {213, "service_ticket_2"}}, - {{234, "Dst is not found"}, - {235, "Missing tvm_id in response, should never happend: 235"}}}; - UNIT_ASSERT_EQUAL(expected, t); + l->Stream.Str()); + UNIT_ASSERT_EQUAL(expected, t); + + t = {}; + u.ParseTicketsFromResponse(TVM_RESPONSE, + NTvmApi::TDstSet{19, 213, 234, 235}, + t); + expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + {213, "service_ticket_2"}}, + {{234, "Dst is not found"}, + {235, "Missing tvm_id in response, should never happend: 235"}}}; + UNIT_ASSERT_EQUAL(expected, t); UNIT_ASSERT_VALUES_EQUAL("6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n", - l->Stream.Str()); - - t = {}; - u.ParseTicketsFromResponse( - R"([ - {"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"},"234" : { "error" : "Dst is not found" }}, - {"213" : { "ticket" : "service_ticket_2"},"185" : { "ticket" : "service_ticket_3"}}, - {"deprecated" : { "ticket" : "deprecated_ticket" }} - ])", - NTvmApi::TDstSet{19, 213, 234, 235}, - t); - expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - {213, "service_ticket_2"}}, - {{234, "Dst is not found"}, - {235, "Missing tvm_id in response, should never happend: 235"}}}; - UNIT_ASSERT_EQUAL(expected, t); + l->Stream.Str()); + + t = {}; + u.ParseTicketsFromResponse( + R"([ + {"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"},"234" : { "error" : "Dst is not found" }}, + {"213" : { "ticket" : "service_ticket_2"},"185" : { "ticket" : "service_ticket_3"}}, + {"deprecated" : { "ticket" : "deprecated_ticket" }} + ])", + NTvmApi::TDstSet{19, 213, 234, 235}, + t); + expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + {213, "service_ticket_2"}}, + {{234, "Dst is not found"}, + {235, "Missing tvm_id in response, should never happend: 235"}}}; + UNIT_ASSERT_EQUAL(expected, t); UNIT_ASSERT_VALUES_EQUAL("6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(ParseTicketsFromResponseAsArray) { - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketChecking(); - - auto l = MakeIntrusive<TLogger>(); - TNotInitedUpdater u(s, l); - - TNotInitedUpdater::TPairTicketsErrors t; - UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseTicketsFromResponse("[", NTvmApi::TDstSet{19}, t), - yexception, - "Invalid json from tvm-api"); - - u.ParseTicketsFromResponse(R"([])", NTvmApi::TDstSet{19}, t); + l->Stream.Str()); + } + + Y_UNIT_TEST(ParseTicketsFromResponseAsArray) { + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketChecking(); + + auto l = MakeIntrusive<TLogger>(); + TNotInitedUpdater u(s, l); + + TNotInitedUpdater::TPairTicketsErrors t; + UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseTicketsFromResponse("[", NTvmApi::TDstSet{19}, t), + yexception, + "Invalid json from tvm-api"); + + u.ParseTicketsFromResponse(R"([])", NTvmApi::TDstSet{19}, t); UNIT_ASSERT_VALUES_EQUAL("6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n", - l->Stream.Str()); - TNotInitedUpdater::TPairTicketsErrors expected = { - {}, {{19, "Missing tvm_id in response, should never happend: 19"}}}; - UNIT_ASSERT_VALUES_EQUAL(expected, t); - l->Stream.Clear(); - - t = {}; - u.ParseTicketsFromResponse( - R"([{},{"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {"213" : { "ticket" : "service_ticket_2"}}])", - NTvmApi::TDstSet{19}, - t); - UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); - expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {}}; - UNIT_ASSERT_EQUAL(expected, t); - - t = {}; - u.ParseTicketsFromResponse( - R"([{ - "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"} - }, - { - "213" : { "ticket" : "service_ticket_2"}, - "234" : { "error" : "Dst is not found" } - }, - { - "185" : { "ticket" : "service_ticket_3"}, - "deprecated" : { "ticket" : "deprecated_ticket" } - } - ])", - NTvmApi::TDstSet{19, 213, 234, 235}, - t); - expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - {213, "service_ticket_2"}}, - {{234, "Dst is not found"}, - {235, "Missing tvm_id in response, should never happend: 235"}}}; - UNIT_ASSERT_EQUAL(expected, t); - UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); - } - - class TReplier: public TRequestReplier { - public: - HttpCodes Code = HTTP_OK; - - bool DoReply(const TReplyParams& params) override { - TParsedHttpFull fl(params.Input.FirstLine()); - - THttpResponse resp(Code); - if (fl.Path == "/2/keys") { - resp.SetContent(NUnittest::TVMKNIFE_PUBLIC_KEYS); - } else if (fl.Path == "/2/ticket") { - resp.SetContent(TVM_RESPONSE); - } else { - UNIT_ASSERT(false); - } - resp.OutTo(params.Output); - - return true; - } - }; - - class TOnlineUpdater: public NTvmApi::TThreadedUpdater { - public: - TOnlineUpdater(const NTvmApi::TClientSettings& settings, TIntrusivePtr<TLogger> l) - : NTvmApi::TThreadedUpdater(settings, l) - { - Init(); - ExpBackoff_.SetEnabled(false); - StartWorker(); - } - }; - - Y_UNIT_TEST(MocServerOk) { - TPortManager pm; - ui16 tvmPort = pm.GetPort(80); - NMock::TMockServer server(tvmPort, []() { return new TReplier; }); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - s.SetTvmHostPort("http://localhost", tvmPort); - - auto l = MakeIntrusive<TLogger>(); - { - TOnlineUpdater u(s, l); - UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, u.GetStatus(), l->Stream.Str()); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() + l->Stream.Str()); + TNotInitedUpdater::TPairTicketsErrors expected = { + {}, {{19, "Missing tvm_id in response, should never happend: 19"}}}; + UNIT_ASSERT_VALUES_EQUAL(expected, t); + l->Stream.Clear(); + + t = {}; + u.ParseTicketsFromResponse( + R"([{},{"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {"213" : { "ticket" : "service_ticket_2"}}])", + NTvmApi::TDstSet{19}, + t); + UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); + expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}}, {}}; + UNIT_ASSERT_EQUAL(expected, t); + + t = {}; + u.ParseTicketsFromResponse( + R"([{ + "19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"} + }, + { + "213" : { "ticket" : "service_ticket_2"}, + "234" : { "error" : "Dst is not found" } + }, + { + "185" : { "ticket" : "service_ticket_3"}, + "deprecated" : { "ticket" : "deprecated_ticket" } + } + ])", + NTvmApi::TDstSet{19, 213, 234, 235}, + t); + expected = {{{19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + {213, "service_ticket_2"}}, + {{234, "Dst is not found"}, + {235, "Missing tvm_id in response, should never happend: 235"}}}; + UNIT_ASSERT_EQUAL(expected, t); + UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); + } + + class TReplier: public TRequestReplier { + public: + HttpCodes Code = HTTP_OK; + + bool DoReply(const TReplyParams& params) override { + TParsedHttpFull fl(params.Input.FirstLine()); + + THttpResponse resp(Code); + if (fl.Path == "/2/keys") { + resp.SetContent(NUnittest::TVMKNIFE_PUBLIC_KEYS); + } else if (fl.Path == "/2/ticket") { + resp.SetContent(TVM_RESPONSE); + } else { + UNIT_ASSERT(false); + } + resp.OutTo(params.Output); + + return true; + } + }; + + class TOnlineUpdater: public NTvmApi::TThreadedUpdater { + public: + TOnlineUpdater(const NTvmApi::TClientSettings& settings, TIntrusivePtr<TLogger> l) + : NTvmApi::TThreadedUpdater(settings, l) + { + Init(); + ExpBackoff_.SetEnabled(false); + StartWorker(); + } + }; + + Y_UNIT_TEST(MocServerOk) { + TPortManager pm; + ui16 tvmPort = pm.GetPort(80); + NMock::TMockServer server(tvmPort, []() { return new TReplier; }); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + s.SetTvmHostPort("http://localhost", tvmPort); + + auto l = MakeIntrusive<TLogger>(); + { + TOnlineUpdater u(s, l); + UNIT_ASSERT_VALUES_EQUAL_C(TClientStatus::Ok, u.GetStatus(), l->Stream.Str()); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() << "6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from http://localhost\n" - << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" - << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" - << "7: Public keys were successfully fetched from http://localhost\n" - << "6: Cache was updated with public keys: XXXXXXXXXXX\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); - } - - Y_UNIT_TEST(MocServerBad) { - TPortManager pm; - ui16 tvmPort = pm.GetPort(80); - NMock::TMockServer server(tvmPort, - []() { - auto p = new TReplier; - p->Code = HTTP_BAD_REQUEST; - return p; - }); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); - s.EnableServiceTicketChecking(); - s.EnableUserTicketChecking(EBlackboxEnv::Test); - s.SetTvmHostPort("localhost", tvmPort); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS_C(TOnlineUpdater(s, l), - TNonRetriableException, - "Failed to start TvmClient. Do not retry: ServiceTickets: Path:/2/ticket.Code=400:", - l->Stream.Str()); - } - - Y_UNIT_TEST(MocServerPaginated) { - class TReplier: public TRequestReplier { - public: - TString Response; - TReplier(TString response) - : Response(response) - { - } - - bool DoReply(const TReplyParams& params) override { - TParsedHttpFull fl(params.Input.FirstLine()); - if (fl.Path != "/2/ticket") { - UNIT_ASSERT_C(false, fl.Path); - } - - THttpResponse resp(HTTP_OK); - resp.SetContent(Response); - resp.OutTo(params.Output); - return true; - } - }; - - TPortManager pm; - ui16 tvmPort = pm.GetPort(80); - TVector<TString> responses = { - R"({"15" : { "ticket" : "service_ticket_3" },"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})", - R"({"222" : { "ticket" : "service_ticket_2"}, "239" : { "error" : "Dst is not found" }})", - R"({"185" : { "ticket" : "service_ticket_3"}})", - }; - NMock::TMockServer server(tvmPort, [&responses]() { - if (responses.empty()) { - return new TReplier("<NULL>"); - } - TString r = responses.front(); - responses.erase(responses.begin()); - return new TReplier(r); - }); - - NTvmApi::TClientSettings s; - s.SetSelfTvmId(100500); - s.EnableServiceTicketsFetchOptions("qwerty", NTvmApi::TClientSettings::TDstVector{19, 222, 239, 100500, 15}); - s.SetTvmHostPort("http://localhost", tvmPort); - - auto l = MakeIntrusive<TLogger>(); - { - TNotInitedUpdater u(s, l); - TNotInitedUpdater::THttpResult result = u.GetServiceTicketsFromHttp(NTvmApi::TDstSet{19, 222, 239, 100500, 15}, 2); - UNIT_ASSERT_VALUES_EQUAL(TSmallVec<TString>({ - R"({"15" : { "ticket" : "service_ticket_3" },"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})", - R"({"222" : { "ticket" : "service_ticket_2"}, "239" : { "error" : "Dst is not found" }})", - R"({"185" : { "ticket" : "service_ticket_3"}})", - }), - result.Responses); - TNotInitedUpdater::TPairTicketsErrors expected{ - { - {19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, - {222, "service_ticket_2"}, - {15, "service_ticket_3"}, - }, - { - {239, "Dst is not found"}, - {100500, "Missing tvm_id in response, should never happend: 100500"}, - }, - }; - UNIT_ASSERT_VALUES_EQUAL(expected, result.TicketsWithErrors); - } - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() + << "7: Response with service tickets for 1 destination(s) was successfully fetched from http://localhost\n" + << "7: Got responses with service tickets with 1 pages for 1 destination(s)\n" + << "6: Cache was updated with 1 service ticket(s): XXXXXXXXXXX\n" + << "7: Public keys were successfully fetched from http://localhost\n" + << "6: Cache was updated with public keys: XXXXXXXXXXX\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + std::regex_replace(std::string(l->Stream.Str()), TIME_REGEX, "XXXXXXXXXXX")); + } + + Y_UNIT_TEST(MocServerBad) { + TPortManager pm; + ui16 tvmPort = pm.GetPort(80); + NMock::TMockServer server(tvmPort, + []() { + auto p = new TReplier; + p->Code = HTTP_BAD_REQUEST; + return p; + }); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", {{"blackbox", 19}}); + s.EnableServiceTicketChecking(); + s.EnableUserTicketChecking(EBlackboxEnv::Test); + s.SetTvmHostPort("localhost", tvmPort); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS_C(TOnlineUpdater(s, l), + TNonRetriableException, + "Failed to start TvmClient. Do not retry: ServiceTickets: Path:/2/ticket.Code=400:", + l->Stream.Str()); + } + + Y_UNIT_TEST(MocServerPaginated) { + class TReplier: public TRequestReplier { + public: + TString Response; + TReplier(TString response) + : Response(response) + { + } + + bool DoReply(const TReplyParams& params) override { + TParsedHttpFull fl(params.Input.FirstLine()); + if (fl.Path != "/2/ticket") { + UNIT_ASSERT_C(false, fl.Path); + } + + THttpResponse resp(HTTP_OK); + resp.SetContent(Response); + resp.OutTo(params.Output); + return true; + } + }; + + TPortManager pm; + ui16 tvmPort = pm.GetPort(80); + TVector<TString> responses = { + R"({"15" : { "ticket" : "service_ticket_3" },"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})", + R"({"222" : { "ticket" : "service_ticket_2"}, "239" : { "error" : "Dst is not found" }})", + R"({"185" : { "ticket" : "service_ticket_3"}})", + }; + NMock::TMockServer server(tvmPort, [&responses]() { + if (responses.empty()) { + return new TReplier("<NULL>"); + } + TString r = responses.front(); + responses.erase(responses.begin()); + return new TReplier(r); + }); + + NTvmApi::TClientSettings s; + s.SetSelfTvmId(100500); + s.EnableServiceTicketsFetchOptions("qwerty", NTvmApi::TClientSettings::TDstVector{19, 222, 239, 100500, 15}); + s.SetTvmHostPort("http://localhost", tvmPort); + + auto l = MakeIntrusive<TLogger>(); + { + TNotInitedUpdater u(s, l); + TNotInitedUpdater::THttpResult result = u.GetServiceTicketsFromHttp(NTvmApi::TDstSet{19, 222, 239, 100500, 15}, 2); + UNIT_ASSERT_VALUES_EQUAL(TSmallVec<TString>({ + R"({"15" : { "ticket" : "service_ticket_3" },"19" : { "ticket" : "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}})", + R"({"222" : { "ticket" : "service_ticket_2"}, "239" : { "error" : "Dst is not found" }})", + R"({"185" : { "ticket" : "service_ticket_3"}})", + }), + result.Responses); + TNotInitedUpdater::TPairTicketsErrors expected{ + { + {19, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, + {222, "service_ticket_2"}, + {15, "service_ticket_3"}, + }, + { + {239, "Dst is not found"}, + {100500, "Missing tvm_id in response, should never happend: 100500"}, + }, + }; + UNIT_ASSERT_VALUES_EQUAL(expected, result.TicketsWithErrors); + } + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() << "6: Disk cache disabled. Please set disk cache directory in settings for best reliability\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from http://localhost\n" - << "7: Response with service tickets for 2 destination(s) was successfully fetched from http://localhost\n" - << "7: Response with service tickets for 1 destination(s) was successfully fetched from http://localhost\n" - << "7: Got responses with service tickets with 3 pages for 5 destination(s)\n" - << "3: Failed to get service ticket for dst=100500: Missing tvm_id in response, should never happend: 100500\n" - << "3: Failed to get service ticket for dst=239: Dst is not found\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(FindMissingDsts) { - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({6, 9}), - TNotInitedUpdater::FindMissingDsts({1, 2, 3, 4}, {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(), - TNotInitedUpdater::FindMissingDsts({1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({1, 4, 6, 9}), - TNotInitedUpdater::FindMissingDsts(NTvmApi::TDstSet(), {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(1, 19), - TNotInitedUpdater::FindMissingDsts({213}, {19, 213})); - - auto make = [](TVector<int> ids) { - TServiceTickets::TMapIdStr m; - for (auto i : ids) { - m.insert({i, ""}); - } - return MakeIntrusiveConst<TServiceTickets>(std::move(m), TServiceTickets::TMapIdStr{}, TServiceTickets::TMapAliasId{}); - }; - - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({6, 9}), - TNotInitedUpdater::FindMissingDsts(make({1, 2, 3, 4}), {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(), - TNotInitedUpdater::FindMissingDsts(make({1, 2, 3, 4, 5, 6, 7, 8, 9}), {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({1, 4, 6, 9}), - TNotInitedUpdater::FindMissingDsts(make({}), {1, 4, 6, 9})); - UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(1, 19), - TNotInitedUpdater::FindMissingDsts(make({213}), {19, 213})); - } - - Y_UNIT_TEST(CreateJsonArray) { - UNIT_ASSERT_VALUES_EQUAL("[]", TNotInitedUpdater::CreateJsonArray({})); - UNIT_ASSERT_VALUES_EQUAL("[sdlzkjvbsdljhfbsdajlhfbsakjdfb]", - TNotInitedUpdater::CreateJsonArray({"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); - UNIT_ASSERT_VALUES_EQUAL("[sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", - TNotInitedUpdater::CreateJsonArray({"sdlzkjvbsdljhfbsdajlhfbsakjdfb", - "o92q83yh2uhq2eri23r"})); - } - - Y_UNIT_TEST(AppendArrayToJson) { - UNIT_ASSERT_EXCEPTION_CONTAINS(TNotInitedUpdater::AppendToJsonArray("", {}), - yexception, - "previous body required"); - UNIT_ASSERT_EXCEPTION_CONTAINS(TNotInitedUpdater::AppendToJsonArray("[kek", {}), - yexception, - "array is broken:"); - - UNIT_ASSERT_VALUES_EQUAL("[kek]", TNotInitedUpdater::AppendToJsonArray("kek", {})); - - UNIT_ASSERT_VALUES_EQUAL( - "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb]", - TNotInitedUpdater::AppendToJsonArray("kek", - {"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); - UNIT_ASSERT_VALUES_EQUAL( - "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", - TNotInitedUpdater::AppendToJsonArray("kek", - {"sdlzkjvbsdljhfbsdajlhfbsakjdfb", "o92q83yh2uhq2eri23r"})); - - UNIT_ASSERT_VALUES_EQUAL( - "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb]", - TNotInitedUpdater::AppendToJsonArray("[kek]", - {"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); - UNIT_ASSERT_VALUES_EQUAL( - "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", - TNotInitedUpdater::AppendToJsonArray("[kek]", - {"sdlzkjvbsdljhfbsdajlhfbsakjdfb", "o92q83yh2uhq2eri23r"})); - } + << "7: Response with service tickets for 2 destination(s) was successfully fetched from http://localhost\n" + << "7: Response with service tickets for 2 destination(s) was successfully fetched from http://localhost\n" + << "7: Response with service tickets for 1 destination(s) was successfully fetched from http://localhost\n" + << "7: Got responses with service tickets with 3 pages for 5 destination(s)\n" + << "3: Failed to get service ticket for dst=100500: Missing tvm_id in response, should never happend: 100500\n" + << "3: Failed to get service ticket for dst=239: Dst is not found\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(FindMissingDsts) { + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({6, 9}), + TNotInitedUpdater::FindMissingDsts({1, 2, 3, 4}, {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(), + TNotInitedUpdater::FindMissingDsts({1, 2, 3, 4, 5, 6, 7, 8, 9}, {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({1, 4, 6, 9}), + TNotInitedUpdater::FindMissingDsts(NTvmApi::TDstSet(), {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(1, 19), + TNotInitedUpdater::FindMissingDsts({213}, {19, 213})); + + auto make = [](TVector<int> ids) { + TServiceTickets::TMapIdStr m; + for (auto i : ids) { + m.insert({i, ""}); + } + return MakeIntrusiveConst<TServiceTickets>(std::move(m), TServiceTickets::TMapIdStr{}, TServiceTickets::TMapAliasId{}); + }; + + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({6, 9}), + TNotInitedUpdater::FindMissingDsts(make({1, 2, 3, 4}), {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(), + TNotInitedUpdater::FindMissingDsts(make({1, 2, 3, 4, 5, 6, 7, 8, 9}), {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector({1, 4, 6, 9}), + TNotInitedUpdater::FindMissingDsts(make({}), {1, 4, 6, 9})); + UNIT_ASSERT_VALUES_EQUAL(NTvmApi::TClientSettings::TDstVector(1, 19), + TNotInitedUpdater::FindMissingDsts(make({213}), {19, 213})); + } + + Y_UNIT_TEST(CreateJsonArray) { + UNIT_ASSERT_VALUES_EQUAL("[]", TNotInitedUpdater::CreateJsonArray({})); + UNIT_ASSERT_VALUES_EQUAL("[sdlzkjvbsdljhfbsdajlhfbsakjdfb]", + TNotInitedUpdater::CreateJsonArray({"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); + UNIT_ASSERT_VALUES_EQUAL("[sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", + TNotInitedUpdater::CreateJsonArray({"sdlzkjvbsdljhfbsdajlhfbsakjdfb", + "o92q83yh2uhq2eri23r"})); + } + + Y_UNIT_TEST(AppendArrayToJson) { + UNIT_ASSERT_EXCEPTION_CONTAINS(TNotInitedUpdater::AppendToJsonArray("", {}), + yexception, + "previous body required"); + UNIT_ASSERT_EXCEPTION_CONTAINS(TNotInitedUpdater::AppendToJsonArray("[kek", {}), + yexception, + "array is broken:"); + + UNIT_ASSERT_VALUES_EQUAL("[kek]", TNotInitedUpdater::AppendToJsonArray("kek", {})); + + UNIT_ASSERT_VALUES_EQUAL( + "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb]", + TNotInitedUpdater::AppendToJsonArray("kek", + {"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); + UNIT_ASSERT_VALUES_EQUAL( + "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", + TNotInitedUpdater::AppendToJsonArray("kek", + {"sdlzkjvbsdljhfbsdajlhfbsakjdfb", "o92q83yh2uhq2eri23r"})); + + UNIT_ASSERT_VALUES_EQUAL( + "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb]", + TNotInitedUpdater::AppendToJsonArray("[kek]", + {"sdlzkjvbsdljhfbsdajlhfbsakjdfb"})); + UNIT_ASSERT_VALUES_EQUAL( + "[kek,sdlzkjvbsdljhfbsdajlhfbsakjdfb,o92q83yh2uhq2eri23r]", + TNotInitedUpdater::AppendToJsonArray("[kek]", + {"sdlzkjvbsdljhfbsdajlhfbsakjdfb", "o92q83yh2uhq2eri23r"})); + } Y_UNIT_TEST(UpdaterTimeouts) { NTvmApi::TClientSettings s; s.SetSelfTvmId(100500); s.EnableServiceTicketChecking(); - s.TvmHost = "localhost"; - s.TvmPort = GetRandomPort(); + s.TvmHost = "localhost"; + s.TvmPort = GetRandomPort(); const auto timeout = TDuration::MilliSeconds(10); - s.TvmConnectTimeout = timeout; - s.TvmSocketTimeout = timeout; + s.TvmConnectTimeout = timeout; + s.TvmSocketTimeout = timeout; { auto l = MakeIntrusive<TLogger>(); @@ -1240,33 +1240,33 @@ Y_UNIT_TEST_SUITE(ApiUpdater) { UNIT_ASSERT_LT(::Now() - startTs, timeout * 2); } } -} - -template <> -void Out<TSmallVec<TString>>(IOutputStream& out, const TSmallVec<TString>& m) { - for (const TString& s : m) { - out << s << ";"; - } -} - -template <> -void Out<TServiceTickets::TMapIdStr>( - IOutputStream& out, - const TServiceTickets::TMapIdStr& m) { - for (const auto& pair : m) { - out << pair.first << " -> " << pair.second << ";"; - } -} - -template <> -void Out<NTestSuiteApiUpdater::TNotInitedUpdater::TPairTicketsErrors>( - IOutputStream& out, - const NTestSuiteApiUpdater::TNotInitedUpdater::TPairTicketsErrors& m) { - out << m.Tickets << "\n"; - out << m.Errors << "\n"; -} - -template <> -void Out<NTvmAuth::NTvmApi::TClientSettings::TDst>(IOutputStream& out, const NTvmAuth::NTvmApi::TClientSettings::TDst& m) { - out << m.Id; -} +} + +template <> +void Out<TSmallVec<TString>>(IOutputStream& out, const TSmallVec<TString>& m) { + for (const TString& s : m) { + out << s << ";"; + } +} + +template <> +void Out<TServiceTickets::TMapIdStr>( + IOutputStream& out, + const TServiceTickets::TMapIdStr& m) { + for (const auto& pair : m) { + out << pair.first << " -> " << pair.second << ";"; + } +} + +template <> +void Out<NTestSuiteApiUpdater::TNotInitedUpdater::TPairTicketsErrors>( + IOutputStream& out, + const NTestSuiteApiUpdater::TNotInitedUpdater::TPairTicketsErrors& m) { + out << m.Tickets << "\n"; + out << m.Errors << "\n"; +} + +template <> +void Out<NTvmAuth::NTvmApi::TClientSettings::TDst>(IOutputStream& out, const NTvmAuth::NTvmApi::TClientSettings::TDst& m) { + out << m.Id; +} diff --git a/library/cpp/tvmauth/client/ut/tvmtool_updater_ut.cpp b/library/cpp/tvmauth/client/ut/tvmtool_updater_ut.cpp index 89d4f924e9..1295ed750e 100644 --- a/library/cpp/tvmauth/client/ut/tvmtool_updater_ut.cpp +++ b/library/cpp/tvmauth/client/ut/tvmtool_updater_ut.cpp @@ -1,744 +1,744 @@ -#include "common.h" - -#include <library/cpp/tvmauth/client/facade.h> -#include <library/cpp/tvmauth/client/misc/tool/threaded_updater.h> - -#include <library/cpp/http/simple/http_client.h> +#include "common.h" + +#include <library/cpp/tvmauth/client/facade.h> +#include <library/cpp/tvmauth/client/misc/tool/threaded_updater.h> + +#include <library/cpp/http/simple/http_client.h> #include <library/cpp/testing/unittest/registar.h> - -#include <util/system/env.h> - -using namespace NTvmAuth; -using namespace NTvmAuth::NTvmTool; - -Y_UNIT_TEST_SUITE(ToolUpdater) { - static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; - static const TString SRV_TICKET_DST_100503 = "3:serv:CBAQ__________9_IggIwMQHEJeRBg:Kj7VApP6D91UJ8pKpeaE3vYaNTBBJcdYpJLbF9w2-Mb-75s_SmMKkPqqA2rMS358uFfoYpv9YZxq0tIaUj5HPQ1WaQ1yiVuPZ_oi3pJRdr006eRyihM8PUfl6m9ioCFftfOcAg9oN5BGeHTNhn7VWuj3yMg7feaMB0zAUpyaPG0"; - 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:G2wloFRSi8--RLb2GDSro_sKXPF2JSdL5CVOuOHgUcRvLm-3OxIPn0NUqbJ9DWDmhPplOqEiblIbLK85My1VMJ2aG5SLbRNKEtwfmxLvkwNpl_gUEwWPJm9_8Khslfj71P3hccxtEEqM9bJSMwHueVAY-a9HSzFo-uMFMeSgQ-k"; - - class TMetaInfoProxy: public TMetaInfo { - public: - using TMetaInfo::ApplySettings; - using TMetaInfo::BbEnvFromString; - using TMetaInfo::Config_; - using TMetaInfo::Fetch; - using TMetaInfo::ParseMetaString; - using TMetaInfo::TMetaInfo; - }; - - Y_UNIT_TEST(Settings) { - NTvmTool::TClientSettings s("foo"); - UNIT_ASSERT_EXCEPTION_CONTAINS(s.SetAuthToken("\n "), - TBrokenTvmClientSettings, - "Auth token cannot be empty"); - UNIT_ASSERT_EXCEPTION_CONTAINS(s.GetAuthToken(), - TBrokenTvmClientSettings, - "Auth token cannot be empty. Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); - - UNIT_ASSERT_NO_EXCEPTION(s.SetAuthToken(AUTH_TOKEN + "\n")); - UNIT_ASSERT_VALUES_EQUAL(AUTH_TOKEN, s.GetAuthToken()); - - UNIT_ASSERT_VALUES_EQUAL("localhost", s.GetHostname()); - UNIT_ASSERT_EXCEPTION_CONTAINS(s.SetHostname(""), - TBrokenTvmClientSettings, - "Hostname cannot be empty"); - - UNIT_ASSERT_NO_EXCEPTION(s.SetHostname("qwe")); - UNIT_ASSERT_VALUES_EQUAL("qwe", s.GetHostname()); - } - - Y_UNIT_TEST(SettingsCtor) { - UNIT_ASSERT_EXCEPTION_CONTAINS(NTvmTool::TClientSettings(""), - TBrokenTvmClientSettings, - "Alias for your TVM client cannot be empty"); - { - NTvmTool::TClientSettings s("self"); - UNIT_ASSERT_EXCEPTION_CONTAINS(s.GetAuthToken(), - TBrokenTvmClientSettings, - "Auth token cannot be empty. " - "Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); - } - - struct TEnvs { - TEnvs(const std::map<TString, TString>& Env) { - for (const auto& [key, value] : Env) { - Prev[key] = GetEnv(key); - SetEnv(key, value); - } - } - - ~TEnvs() { - for (const auto& [key, value] : Prev) { - SetEnv(key, value); - } - } - - std::map<TString, TString> Prev; - }; - - struct TCase { - std::map<TString, TString> Env; - TString AuthToken; - ui16 Port = 0; - }; - - std::vector<TCase> cases = { - { - { - {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, - }, - "qwerty", - 1, - }, - { - { - {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, - {"QLOUD_TVM_TOKEN", "zxcvbn"}, - }, - "qwerty", - 1, - }, - { - { - {"QLOUD_TVM_TOKEN", "zxcvbn"}, - }, - "zxcvbn", - 1, - }, - { - { - {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, - {"DEPLOY_TVM_TOOL_URL", "32272"}, - }, - "qwerty", - 1, - }, - { - { - {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, - {"DEPLOY_TVM_TOOL_URL", "localhost:32272"}, - }, - "qwerty", - 32272, - }, - { - { - {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, - {"DEPLOY_TVM_TOOL_URL", "http://localhost:32272"}, - }, - "qwerty", - 32272, - }, - }; - - for (const TCase& c : cases) { - TEnvs envs(c.Env); - - NTvmTool::TClientSettings s("self"); - UNIT_ASSERT_VALUES_EQUAL(c.AuthToken, s.GetAuthToken()); - UNIT_ASSERT_VALUES_EQUAL(c.Port, s.GetPort()); - } - } - - Y_UNIT_TEST(Meta_Fetch) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - TKeepAliveHttpClient client("localhost", port); - - TMetaInfoProxy m(nullptr); - NTvmTool::TClientSettings settings("me"); - settings.SetAuthToken(AUTH_TOKEN); - m.ApplySettings(settings); - - UNIT_ASSERT_VALUES_EQUAL(META, m.Fetch(client)); - - settings.SetAuthToken("qwerty"); - m.ApplySettings(settings); - UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), - TNonRetriableException, - "Failed to fetch meta from tvmtool: localhost:"); - - settings.SetAuthToken(AUTH_TOKEN); - m.ApplySettings(settings); - { - TKeepAliveHttpClient client("localhost", 0); - UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), - TRetriableException, - "Failed to fetch meta data from tvmtool: "); - } - - server.SetGenerator([]() { - auto p = new TTvmTool; - p->Code = HTTP_NOT_FOUND; - return p; }); - UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), - TNonRetriableException, - "Library does not support so old tvmtool. You need tvmtool>=1.1.0"); - server.SetGenerator([]() { - auto p = new TTvmTool; - p->Code = HTTP_INTERNAL_SERVER_ERROR; - return p; }); - UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), - TRetriableException, - "Failed to fetch meta from tvmtool: localhost:"); - } - - Y_UNIT_TEST(Meta_ParseMetaString_me) { - TMetaInfo::TConfigPtr c; - UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "me")); - UNIT_ASSERT_VALUES_EQUAL(100500, c->SelfTvmId); - UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); - UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"bbox", 242}, {"pass_likers", 11}}), c->DstAliases); - } - - Y_UNIT_TEST(Meta_ParseMetaString_pc) { - TMetaInfo::TConfigPtr c; - UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "push-client")); - UNIT_ASSERT_VALUES_EQUAL(100501, c->SelfTvmId); - UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); - UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"pass_likers", 100502}}), c->DstAliases); - } - - Y_UNIT_TEST(Meta_ParseMetaString_se) { - TMetaInfo::TConfigPtr c; - UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "something_else")); - UNIT_ASSERT_VALUES_EQUAL(100503, c->SelfTvmId); - UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); - UNIT_ASSERT(c->DstAliases.empty()); - } - - Y_UNIT_TEST(Meta_ParseMetaString_errors) { - TMetaInfoProxy m(nullptr); - UNIT_ASSERT(!m.ParseMetaString(META, "ololo")); - - TString meta = "}"; - UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); - meta = "{}"; - UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); - meta = R"({"tenants" : {}})"; - UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); - meta = R"({"tenants" : [{"self":{}}]})"; - UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); - } - - Y_UNIT_TEST(Meta_BbEnvFromString) { - UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Prod, TMetaInfoProxy::BbEnvFromString("Prod", META)); - UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Test, TMetaInfoProxy::BbEnvFromString("Test", META)); - UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::ProdYateam, TMetaInfoProxy::BbEnvFromString("ProdYaTeam", META)); - UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::TestYateam, TMetaInfoProxy::BbEnvFromString("TestYaTeam", META)); - UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Stress, TMetaInfoProxy::BbEnvFromString("Stress", META)); - UNIT_ASSERT_EXCEPTION_CONTAINS(TMetaInfoProxy::BbEnvFromString("foo", META), - yexception, - "'bb_env'=='foo'"); - } - - Y_UNIT_TEST(Meta_ApplySettings) { - NTvmTool::TClientSettings s("foo"); - s.SetAuthToken(AUTH_TOKEN); - - TMetaInfoProxy m(nullptr); - m.ApplySettings(s); - - UNIT_ASSERT_VALUES_EQUAL( - TKeepAliveHttpClient::THeaders({{"Authorization", AUTH_TOKEN}}), - m.GetAuthHeader()); - } - - Y_UNIT_TEST(Meta_Init) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - TKeepAliveHttpClient client("localhost", port); - - NTvmTool::TClientSettings s("me"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - auto l = MakeIntrusive<TLogger>(); - TMetaInfo m(l); - UNIT_ASSERT_NO_EXCEPTION(m.Init(client, s)); - UNIT_ASSERT_VALUES_EQUAL(100500, m.GetConfig()->SelfTvmId); - UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, m.GetConfig()->BbEnv); - UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"bbox", 242}, {"pass_likers", 11}}), m.GetConfig()->DstAliases); - UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", - l->Stream.Str()); - l->Stream.Clear(); - UNIT_ASSERT_VALUES_EQUAL( - "/tvm/tickets?src=100500&dsts=11,242", - TMetaInfo::GetRequestForTickets(*m.GetConfig())); - - server.SetGenerator([]() { - auto p = new TTvmTool; - p->Meta = R"({ - "bb_env" : "Prod", - "tenants" : [{ - "self": {"alias" : "me", "client_id": 100500}, - "dsts" : [{"alias" : "pass_likers","client_id": 11}] - }] - })"; - return p; }); - UNIT_ASSERT(m.TryUpdateConfig(client)); - UNIT_ASSERT_VALUES_EQUAL( - "6: Meta was updated. Old: (self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]). New: (self_tvm_id=100500, bb_env=Prod, dsts=[(pass_likers:11)])\n", - l->Stream.Str()); - l->Stream.clear(); - - s = NTvmTool::TClientSettings("foo"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - TMetaInfo m2(l); - UNIT_ASSERT_EXCEPTION_CONTAINS(m2.Init(client, s), TNonRetriableException, "Alias 'foo' not found in meta info"); - UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n", - l->Stream.Str()); - UNIT_ASSERT_EXCEPTION_CONTAINS(TMetaInfo::GetRequestForTickets({}), - yexception, - "DstAliases.empty()"); - - server.SetGenerator([]() { - auto p = new TTvmTool; - p->Meta = "}"; - return p; }); - UNIT_ASSERT_EXCEPTION_CONTAINS(m.Init(client, s), - TNonRetriableException, - "Malformed json from tvmtool:"); - } - - class TNonInitedUpdater: public TThreadedUpdater { - public: - TNonInitedUpdater(const TString& host, ui16 port, TLoggerPtr logger) + +#include <util/system/env.h> + +using namespace NTvmAuth; +using namespace NTvmAuth::NTvmTool; + +Y_UNIT_TEST_SUITE(ToolUpdater) { + static const TString SRV_TICKET = "3:serv:CBAQ__________9_IgYIexCUkQY:GioCM49Ob6_f80y6FY0XBVN4hLXuMlFeyMvIMiDuQnZkbkLpRpQOuQo5YjWoBjM0Vf-XqOm8B7xtrvxSYHDD7Q4OatN2l-Iwg7i71lE3scUeD36x47st3nd0OThvtjrFx_D8mw_c0GT5KcniZlqq1SjhLyAk1b_zJsx8viRAhCU"; + static const TString SRV_TICKET_DST_100503 = "3:serv:CBAQ__________9_IggIwMQHEJeRBg:Kj7VApP6D91UJ8pKpeaE3vYaNTBBJcdYpJLbF9w2-Mb-75s_SmMKkPqqA2rMS358uFfoYpv9YZxq0tIaUj5HPQ1WaQ1yiVuPZ_oi3pJRdr006eRyihM8PUfl6m9ioCFftfOcAg9oN5BGeHTNhn7VWuj3yMg7feaMB0zAUpyaPG0"; + 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:G2wloFRSi8--RLb2GDSro_sKXPF2JSdL5CVOuOHgUcRvLm-3OxIPn0NUqbJ9DWDmhPplOqEiblIbLK85My1VMJ2aG5SLbRNKEtwfmxLvkwNpl_gUEwWPJm9_8Khslfj71P3hccxtEEqM9bJSMwHueVAY-a9HSzFo-uMFMeSgQ-k"; + + class TMetaInfoProxy: public TMetaInfo { + public: + using TMetaInfo::ApplySettings; + using TMetaInfo::BbEnvFromString; + using TMetaInfo::Config_; + using TMetaInfo::Fetch; + using TMetaInfo::ParseMetaString; + using TMetaInfo::TMetaInfo; + }; + + Y_UNIT_TEST(Settings) { + NTvmTool::TClientSettings s("foo"); + UNIT_ASSERT_EXCEPTION_CONTAINS(s.SetAuthToken("\n "), + TBrokenTvmClientSettings, + "Auth token cannot be empty"); + UNIT_ASSERT_EXCEPTION_CONTAINS(s.GetAuthToken(), + TBrokenTvmClientSettings, + "Auth token cannot be empty. Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); + + UNIT_ASSERT_NO_EXCEPTION(s.SetAuthToken(AUTH_TOKEN + "\n")); + UNIT_ASSERT_VALUES_EQUAL(AUTH_TOKEN, s.GetAuthToken()); + + UNIT_ASSERT_VALUES_EQUAL("localhost", s.GetHostname()); + UNIT_ASSERT_EXCEPTION_CONTAINS(s.SetHostname(""), + TBrokenTvmClientSettings, + "Hostname cannot be empty"); + + UNIT_ASSERT_NO_EXCEPTION(s.SetHostname("qwe")); + UNIT_ASSERT_VALUES_EQUAL("qwe", s.GetHostname()); + } + + Y_UNIT_TEST(SettingsCtor) { + UNIT_ASSERT_EXCEPTION_CONTAINS(NTvmTool::TClientSettings(""), + TBrokenTvmClientSettings, + "Alias for your TVM client cannot be empty"); + { + NTvmTool::TClientSettings s("self"); + UNIT_ASSERT_EXCEPTION_CONTAINS(s.GetAuthToken(), + TBrokenTvmClientSettings, + "Auth token cannot be empty. " + "Env 'TVMTOOL_LOCAL_AUTHTOKEN' and 'QLOUD_TVM_TOKEN' are empty."); + } + + struct TEnvs { + TEnvs(const std::map<TString, TString>& Env) { + for (const auto& [key, value] : Env) { + Prev[key] = GetEnv(key); + SetEnv(key, value); + } + } + + ~TEnvs() { + for (const auto& [key, value] : Prev) { + SetEnv(key, value); + } + } + + std::map<TString, TString> Prev; + }; + + struct TCase { + std::map<TString, TString> Env; + TString AuthToken; + ui16 Port = 0; + }; + + std::vector<TCase> cases = { + { + { + {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, + }, + "qwerty", + 1, + }, + { + { + {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, + {"QLOUD_TVM_TOKEN", "zxcvbn"}, + }, + "qwerty", + 1, + }, + { + { + {"QLOUD_TVM_TOKEN", "zxcvbn"}, + }, + "zxcvbn", + 1, + }, + { + { + {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, + {"DEPLOY_TVM_TOOL_URL", "32272"}, + }, + "qwerty", + 1, + }, + { + { + {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, + {"DEPLOY_TVM_TOOL_URL", "localhost:32272"}, + }, + "qwerty", + 32272, + }, + { + { + {"TVMTOOL_LOCAL_AUTHTOKEN", "qwerty"}, + {"DEPLOY_TVM_TOOL_URL", "http://localhost:32272"}, + }, + "qwerty", + 32272, + }, + }; + + for (const TCase& c : cases) { + TEnvs envs(c.Env); + + NTvmTool::TClientSettings s("self"); + UNIT_ASSERT_VALUES_EQUAL(c.AuthToken, s.GetAuthToken()); + UNIT_ASSERT_VALUES_EQUAL(c.Port, s.GetPort()); + } + } + + Y_UNIT_TEST(Meta_Fetch) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + TKeepAliveHttpClient client("localhost", port); + + TMetaInfoProxy m(nullptr); + NTvmTool::TClientSettings settings("me"); + settings.SetAuthToken(AUTH_TOKEN); + m.ApplySettings(settings); + + UNIT_ASSERT_VALUES_EQUAL(META, m.Fetch(client)); + + settings.SetAuthToken("qwerty"); + m.ApplySettings(settings); + UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), + TNonRetriableException, + "Failed to fetch meta from tvmtool: localhost:"); + + settings.SetAuthToken(AUTH_TOKEN); + m.ApplySettings(settings); + { + TKeepAliveHttpClient client("localhost", 0); + UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), + TRetriableException, + "Failed to fetch meta data from tvmtool: "); + } + + server.SetGenerator([]() { + auto p = new TTvmTool; + p->Code = HTTP_NOT_FOUND; + return p; }); + UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), + TNonRetriableException, + "Library does not support so old tvmtool. You need tvmtool>=1.1.0"); + server.SetGenerator([]() { + auto p = new TTvmTool; + p->Code = HTTP_INTERNAL_SERVER_ERROR; + return p; }); + UNIT_ASSERT_EXCEPTION_CONTAINS(m.Fetch(client), + TRetriableException, + "Failed to fetch meta from tvmtool: localhost:"); + } + + Y_UNIT_TEST(Meta_ParseMetaString_me) { + TMetaInfo::TConfigPtr c; + UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "me")); + UNIT_ASSERT_VALUES_EQUAL(100500, c->SelfTvmId); + UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); + UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"bbox", 242}, {"pass_likers", 11}}), c->DstAliases); + } + + Y_UNIT_TEST(Meta_ParseMetaString_pc) { + TMetaInfo::TConfigPtr c; + UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "push-client")); + UNIT_ASSERT_VALUES_EQUAL(100501, c->SelfTvmId); + UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); + UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"pass_likers", 100502}}), c->DstAliases); + } + + Y_UNIT_TEST(Meta_ParseMetaString_se) { + TMetaInfo::TConfigPtr c; + UNIT_ASSERT(c = TMetaInfoProxy::ParseMetaString(META, "something_else")); + UNIT_ASSERT_VALUES_EQUAL(100503, c->SelfTvmId); + UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, c->BbEnv); + UNIT_ASSERT(c->DstAliases.empty()); + } + + Y_UNIT_TEST(Meta_ParseMetaString_errors) { + TMetaInfoProxy m(nullptr); + UNIT_ASSERT(!m.ParseMetaString(META, "ololo")); + + TString meta = "}"; + UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); + meta = "{}"; + UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); + meta = R"({"tenants" : {}})"; + UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); + meta = R"({"tenants" : [{"self":{}}]})"; + UNIT_ASSERT_EXCEPTION_CONTAINS(m.ParseMetaString(meta, "qqq"), yexception, meta); + } + + Y_UNIT_TEST(Meta_BbEnvFromString) { + UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Prod, TMetaInfoProxy::BbEnvFromString("Prod", META)); + UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Test, TMetaInfoProxy::BbEnvFromString("Test", META)); + UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::ProdYateam, TMetaInfoProxy::BbEnvFromString("ProdYaTeam", META)); + UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::TestYateam, TMetaInfoProxy::BbEnvFromString("TestYaTeam", META)); + UNIT_ASSERT_VALUES_EQUAL(EBlackboxEnv::Stress, TMetaInfoProxy::BbEnvFromString("Stress", META)); + UNIT_ASSERT_EXCEPTION_CONTAINS(TMetaInfoProxy::BbEnvFromString("foo", META), + yexception, + "'bb_env'=='foo'"); + } + + Y_UNIT_TEST(Meta_ApplySettings) { + NTvmTool::TClientSettings s("foo"); + s.SetAuthToken(AUTH_TOKEN); + + TMetaInfoProxy m(nullptr); + m.ApplySettings(s); + + UNIT_ASSERT_VALUES_EQUAL( + TKeepAliveHttpClient::THeaders({{"Authorization", AUTH_TOKEN}}), + m.GetAuthHeader()); + } + + Y_UNIT_TEST(Meta_Init) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + TKeepAliveHttpClient client("localhost", port); + + NTvmTool::TClientSettings s("me"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + auto l = MakeIntrusive<TLogger>(); + TMetaInfo m(l); + UNIT_ASSERT_NO_EXCEPTION(m.Init(client, s)); + UNIT_ASSERT_VALUES_EQUAL(100500, m.GetConfig()->SelfTvmId); + UNIT_ASSERT_EQUAL(EBlackboxEnv::ProdYateam, m.GetConfig()->BbEnv); + UNIT_ASSERT_EQUAL(TMetaInfo::TDstAliases({{"bbox", 242}, {"pass_likers", 11}}), m.GetConfig()->DstAliases); + UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", + l->Stream.Str()); + l->Stream.Clear(); + UNIT_ASSERT_VALUES_EQUAL( + "/tvm/tickets?src=100500&dsts=11,242", + TMetaInfo::GetRequestForTickets(*m.GetConfig())); + + server.SetGenerator([]() { + auto p = new TTvmTool; + p->Meta = R"({ + "bb_env" : "Prod", + "tenants" : [{ + "self": {"alias" : "me", "client_id": 100500}, + "dsts" : [{"alias" : "pass_likers","client_id": 11}] + }] + })"; + return p; }); + UNIT_ASSERT(m.TryUpdateConfig(client)); + UNIT_ASSERT_VALUES_EQUAL( + "6: Meta was updated. Old: (self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]). New: (self_tvm_id=100500, bb_env=Prod, dsts=[(pass_likers:11)])\n", + l->Stream.Str()); + l->Stream.clear(); + + s = NTvmTool::TClientSettings("foo"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + TMetaInfo m2(l); + UNIT_ASSERT_EXCEPTION_CONTAINS(m2.Init(client, s), TNonRetriableException, "Alias 'foo' not found in meta info"); + UNIT_ASSERT_VALUES_EQUAL(TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n", + l->Stream.Str()); + UNIT_ASSERT_EXCEPTION_CONTAINS(TMetaInfo::GetRequestForTickets({}), + yexception, + "DstAliases.empty()"); + + server.SetGenerator([]() { + auto p = new TTvmTool; + p->Meta = "}"; + return p; }); + UNIT_ASSERT_EXCEPTION_CONTAINS(m.Init(client, s), + TNonRetriableException, + "Malformed json from tvmtool:"); + } + + class TNonInitedUpdater: public TThreadedUpdater { + public: + TNonInitedUpdater(const TString& host, ui16 port, TLoggerPtr logger) : TThreadedUpdater(host, port, TDuration::Seconds(5), TDuration::Seconds(30), logger) - { - } - - using TThreadedUpdater::ArePublicKeysOk; - using TThreadedUpdater::AreServiceTicketsOk; - using TThreadedUpdater::FetchPublicKeys; - using TThreadedUpdater::FetchServiceTickets; - using TThreadedUpdater::GetBirthTimeFromResponse; - using TThreadedUpdater::Init; - using TThreadedUpdater::IsTimeToUpdatePublicKeys; - using TThreadedUpdater::IsTimeToUpdateServiceTickets; - using TThreadedUpdater::LastVisitForConfig_; - using TThreadedUpdater::MetaInfo_; - using TThreadedUpdater::ParseFetchTicketsResponse; - using TThreadedUpdater::SetBbEnv; - using TThreadedUpdater::SetServiceContext; - using TThreadedUpdater::SetServiceTickets; - using TThreadedUpdater::SetUpdateTimeOfPublicKeys; - using TThreadedUpdater::SetUpdateTimeOfServiceTickets; - using TThreadedUpdater::SetUserContext; - using TThreadedUpdater::TPairTicketsErrors; - using TThreadedUpdater::UpdateKeys; - using TThreadedUpdater::UpdateServiceTickets; - }; - - Y_UNIT_TEST(GetBirthTimeFromResponse) { - THttpHeaders h; - UNIT_ASSERT_EXCEPTION_CONTAINS(TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo"), - yexception, - "Failed to fetch bithtime of ololo from tvmtool"); - - h.AddHeader(THttpInputHeader("X-Ya-Tvmtool-Data-Birthtime: qwe")); - UNIT_ASSERT_EXCEPTION_CONTAINS(TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo"), - yexception, - "Bithtime of ololo from tvmtool must be unixtime. Got: qwe"); - - h.AddOrReplaceHeader(THttpInputHeader("X-Ya-Tvmtool-Data-Birthtime: 123")); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(123), TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo")); - } - - Y_UNIT_TEST(Fetch) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - TKeepAliveHttpClient client("localhost", port); - - auto l = MakeIntrusive<TLogger>(); - TNonInitedUpdater u("localhost", port, l); - NTvmTool::TClientSettings s("me"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - u.MetaInfo_.Init(client, s); - auto p = u.FetchPublicKeys(); - UNIT_ASSERT_STRINGS_EQUAL(NUnittest::TVMKNIFE_PUBLIC_KEYS, p.first); - UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, p.second); - - auto p2 = u.FetchServiceTickets(*u.MetaInfo_.GetConfig()); - UNIT_ASSERT_STRINGS_EQUAL(TICKETS_ME, p2.first); - UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, p2.second); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(ParseFetchTicketsResponse) { - auto l = MakeIntrusive<TLogger>(); - TNonInitedUpdater u("", 0, l); - - UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseFetchTicketsResponse("}", {}), - yexception, - "Invalid json from tvmtool: }"); - - auto t = u.ParseFetchTicketsResponse(TICKETS_ME, {{"pass_likers", 11}, {"se", 2}}); - auto expected = TNonInitedUpdater::TPairTicketsErrors{ - {{11, "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8"}}, - { - {2, "Missing tvm_id in response, should never happend: se"}, - }, - }; - UNIT_ASSERT_VALUES_EQUAL(expected, t); - - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "3: Failed to get ServiceTicket for se (2): Missing tvm_id in response, should never happend: se\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(Update) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - TKeepAliveHttpClient client("localhost", port); - - auto l = MakeIntrusive<TLogger>(); - TNonInitedUpdater u("localhost", port, l); - NTvmTool::TClientSettings s("me"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - u.MetaInfo_.Init(client, s); - - using TTickets = TServiceTickets::TMapAliasStr; - UNIT_ASSERT(!u.GetCachedServiceTickets()); - UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, u.UpdateServiceTickets(*u.MetaInfo_.GetConfig())); - UNIT_ASSERT(u.GetCachedServiceTickets()); - UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfServiceTickets()); - UNIT_ASSERT_EQUAL( - TTickets({ - {"bbox", "3:serv:CBAQ__________9_IgcIlJEGEPIB:N7luw0_rVmBosTTI130jwDbQd0-cMmqJeEl0ma4ZlIo_mHXjBzpOuMQ3A9YagbmOBOt8TZ_gzGvVSegWZkEeB24gM22acw0w-RcHaQKrzSOA5Zq8WLNIC8QUa4_WGTlAsb7R7eC4KTAGgouIquNAgMBdTuGOuZHnMLvZyLnOMKc"}, - {"pass_likers", "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8"}, - }), - u.GetCachedServiceTickets()->TicketsByAlias); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", - l->Stream.Str()); - l->Stream.Clear(); - - UNIT_ASSERT(!u.GetCachedServiceContext()); - UNIT_ASSERT(!u.GetCachedUserContext()); - UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, u.UpdateKeys(*u.MetaInfo_.GetConfig())); - UNIT_ASSERT(u.GetCachedServiceContext()); - UNIT_ASSERT(!u.GetCachedUserContext()); - u.SetBbEnv(EBlackboxEnv::Test); - UNIT_ASSERT(u.GetCachedUserContext()); - UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); - l->Stream.Clear(); - - { - TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); - UNIT_ASSERT(u->GetCachedServiceTickets()); - UNIT_ASSERT(u->GetCachedServiceContext()); - UNIT_ASSERT(u->GetCachedUserContext()); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); - - NTvmAuth::TTvmClient c(u); - UNIT_ASSERT(c.CheckServiceTicket(SRV_TICKET)); - UNIT_ASSERT(!c.CheckServiceTicket(SRV_TICKET_DST_100503)); - UNIT_ASSERT(c.CheckUserTicket(PROD_YATEAM_TICKET)); - UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8", c.GetServiceTicketFor("pass_likers")); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n" - << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - l->Stream.Clear(); - - { - NTvmTool::TClientSettings s("something_else"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - - TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); - UNIT_ASSERT(!u->GetCachedServiceTickets()); - UNIT_ASSERT(u->GetCachedServiceContext()); - UNIT_ASSERT(u->GetCachedUserContext()); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); - - NTvmAuth::TTvmClient c(u); - UNIT_ASSERT(!c.CheckServiceTicket(SRV_TICKET)); - UNIT_ASSERT(c.CheckServiceTicket(SRV_TICKET_DST_100503)); - UNIT_ASSERT(c.CheckUserTicket(PROD_YATEAM_TICKET)); - UNIT_ASSERT_EXCEPTION_CONTAINS(c.GetServiceTicketFor("pass_likers"), - TBrokenTvmClientSettings, - "Need to enable ServiceTickets fetching"); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100503, bb_env=ProdYateam, dsts=[]\n" - << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - l->Stream.Clear(); - } - - Y_UNIT_TEST(IsOk) { - TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); - using TTickets = TServiceTickets::TMapIdStr; - - UNIT_ASSERT(u.AreServiceTicketsOk(0)); - UNIT_ASSERT(!u.AreServiceTicketsOk(2)); - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(TTickets(), - TTickets(), - TServiceTickets::TMapAliasId())); - UNIT_ASSERT(u.AreServiceTicketsOk(0)); - UNIT_ASSERT(!u.AreServiceTicketsOk(2)); - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - TTickets({ - {1, "mega_ticket"}, - {2, "mega_ticket2"}, - }), - TTickets({ - {3, "mega_error3"}, - }), - TServiceTickets::TMapAliasId())); - UNIT_ASSERT(u.AreServiceTicketsOk(0)); - UNIT_ASSERT(!u.AreServiceTicketsOk(2)); - - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - TTickets({ - {1, "mega_ticket"}, - {2, "mega_ticket2"}, - }), - TTickets({ - {3, "mega_error3"}, - }), - TServiceTickets::TMapAliasId({ - {"mega_ticket", 1}, - {"mega_ticket2", 2}, - {"mega_ticket3", 3}, - }))); - UNIT_ASSERT(u.AreServiceTicketsOk(2)); - - UNIT_ASSERT(!u.ArePublicKeysOk()); - u.SetServiceContext(MakeIntrusiveConst<TServiceContext>( - TServiceContext::CheckingFactory(12, NUnittest::TVMKNIFE_PUBLIC_KEYS))); - UNIT_ASSERT(!u.ArePublicKeysOk()); - u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); - UNIT_ASSERT(!u.ArePublicKeysOk()); - u.SetBbEnv(EBlackboxEnv::Test); - UNIT_ASSERT(u.ArePublicKeysOk()); - } - - Y_UNIT_TEST(IsTimeToUpdate) { - TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); - - UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Seconds(597))); - UNIT_ASSERT(u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Seconds(603))); - - TMetaInfo::TConfig cfg; - UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(597))); - UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(603))); - - cfg.DstAliases = {{"q", 1}}; - UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(597))); - UNIT_ASSERT(u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(603))); - } - - Y_UNIT_TEST(InitWithOldData) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, - []() { - auto p = new TTvmTool; - p->Birthtime = TInstant::Seconds(123); - return p; - }); - - NTvmTool::TClientSettings s("me"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry: "); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n" - << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Service tickets have not been refreshed for too long period\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n" - << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Service tickets have not been refreshed for too long period\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n" - << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Service tickets have not been refreshed for too long period\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(InitWithOldData_onlyKeys) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, - []() { - auto p = new TTvmTool; - p->Birthtime = TInstant::Seconds(123); - return p; - }); - - NTvmTool::TClientSettings s("something_else"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - - { - s.OverrideBlackboxEnv(EBlackboxEnv::Stress); - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), - TBrokenTvmClientSettings, - "Overriding of BlackboxEnv is illegal: ProdYateam -> Stress"); - } - - s.OverrideBlackboxEnv(EBlackboxEnv::Prod); - auto l = MakeIntrusive<TLogger>(); - UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), - TRetriableException, - "Failed to start TvmClient. You can retry: "); - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100503, bb_env=ProdYateam, dsts=[]\n" - << "6: Meta: override blackbox env: ProdYateam->Prod\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n" - << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" - << "3: Public keys have not been refreshed for too long period\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(Init) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - - NTvmTool::TClientSettings s("push-client"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - s.SetHostname("localhost"); - - auto l = MakeIntrusive<TLogger>(); - { - TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100501, bb_env=ProdYateam, dsts=[(pass_likers:100502)]\n" - << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - } - - Y_UNIT_TEST(InitWithoutTvmtool) { - NTvmTool::TClientSettings s("me"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(0); - - UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), - TNonRetriableException, - "can not connect to "); - } - - Y_UNIT_TEST(GetStatus) { - TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); - TMetaInfoProxy m(nullptr); - m.Config_ = std::make_shared<TMetaInfo::TConfig>(); - u.MetaInfo_ = m; - u.LastVisitForConfig_ = TInstant::Now(); - - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); - u.SetUpdateTimeOfPublicKeys(TInstant::Now() - TDuration::Days(3)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); - u.SetUpdateTimeOfPublicKeys(TInstant::Now() - TDuration::Hours(3)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - - u.SetServiceTickets(new TServiceTickets({}, {}, {})); - - TMetaInfo::TConfig cfg; - cfg.DstAliases = {{"q", 1}, {"q2", 2}}; - m.Config_ = std::make_shared<TMetaInfo::TConfig>(cfg); - u.MetaInfo_ = m; - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); - u.SetUpdateTimeOfServiceTickets(TInstant::Now() - TDuration::Hours(3)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); - - u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( - TServiceTickets::TMapIdStr({{1, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, {2, "t"}}), - TServiceTickets::TMapIdStr({{3, "mega_error"}, {4, "error2"}}), - TServiceTickets::TMapAliasId({ - {"some_alias#1", 1}, - {"some_alias#2", 2}, - }))); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); - - const TInstant* inv = &u.GetCachedServiceTickets()->InvalidationTime; - *const_cast<TInstant*>(inv) = TInstant::Now() + TDuration::Hours(3); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); - - u.SetUpdateTimeOfServiceTickets(TInstant::Now() - TDuration::Minutes(3)); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); - - u.LastVisitForConfig_ = TInstant::Now() - TDuration::Minutes(1); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); - } - - Y_UNIT_TEST(multiNamesForDst) { - TPortManager pm; - ui16 port = pm.GetPort(80); - NMock::TMockServer server(port, []() { return new TTvmTool; }); - - NTvmTool::TClientSettings s("multi_names_for_dst"); - s.SetAuthToken(AUTH_TOKEN); - s.SetPort(port); - s.SetHostname("localhost"); - - auto l = MakeIntrusive<TLogger>(); - { - TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); - UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); - } - UNIT_ASSERT_VALUES_EQUAL( - TStringBuilder() - << "7: Meta info fetched from localhost:" << port << "\n" - << "6: Meta: self_tvm_id=100599, bb_env=ProdYateam, dsts=[(pass_haters:100502)(pass_likers:100502)]\n" - << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" - << "7: Thread-worker started\n" - << "7: Thread-worker stopped\n", - l->Stream.Str()); - } -} + { + } + + using TThreadedUpdater::ArePublicKeysOk; + using TThreadedUpdater::AreServiceTicketsOk; + using TThreadedUpdater::FetchPublicKeys; + using TThreadedUpdater::FetchServiceTickets; + using TThreadedUpdater::GetBirthTimeFromResponse; + using TThreadedUpdater::Init; + using TThreadedUpdater::IsTimeToUpdatePublicKeys; + using TThreadedUpdater::IsTimeToUpdateServiceTickets; + using TThreadedUpdater::LastVisitForConfig_; + using TThreadedUpdater::MetaInfo_; + using TThreadedUpdater::ParseFetchTicketsResponse; + using TThreadedUpdater::SetBbEnv; + using TThreadedUpdater::SetServiceContext; + using TThreadedUpdater::SetServiceTickets; + using TThreadedUpdater::SetUpdateTimeOfPublicKeys; + using TThreadedUpdater::SetUpdateTimeOfServiceTickets; + using TThreadedUpdater::SetUserContext; + using TThreadedUpdater::TPairTicketsErrors; + using TThreadedUpdater::UpdateKeys; + using TThreadedUpdater::UpdateServiceTickets; + }; + + Y_UNIT_TEST(GetBirthTimeFromResponse) { + THttpHeaders h; + UNIT_ASSERT_EXCEPTION_CONTAINS(TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo"), + yexception, + "Failed to fetch bithtime of ololo from tvmtool"); + + h.AddHeader(THttpInputHeader("X-Ya-Tvmtool-Data-Birthtime: qwe")); + UNIT_ASSERT_EXCEPTION_CONTAINS(TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo"), + yexception, + "Bithtime of ololo from tvmtool must be unixtime. Got: qwe"); + + h.AddOrReplaceHeader(THttpInputHeader("X-Ya-Tvmtool-Data-Birthtime: 123")); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(123), TNonInitedUpdater::GetBirthTimeFromResponse(h, "ololo")); + } + + Y_UNIT_TEST(Fetch) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + TKeepAliveHttpClient client("localhost", port); + + auto l = MakeIntrusive<TLogger>(); + TNonInitedUpdater u("localhost", port, l); + NTvmTool::TClientSettings s("me"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + u.MetaInfo_.Init(client, s); + auto p = u.FetchPublicKeys(); + UNIT_ASSERT_STRINGS_EQUAL(NUnittest::TVMKNIFE_PUBLIC_KEYS, p.first); + UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, p.second); + + auto p2 = u.FetchServiceTickets(*u.MetaInfo_.GetConfig()); + UNIT_ASSERT_STRINGS_EQUAL(TICKETS_ME, p2.first); + UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, p2.second); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(ParseFetchTicketsResponse) { + auto l = MakeIntrusive<TLogger>(); + TNonInitedUpdater u("", 0, l); + + UNIT_ASSERT_EXCEPTION_CONTAINS(u.ParseFetchTicketsResponse("}", {}), + yexception, + "Invalid json from tvmtool: }"); + + auto t = u.ParseFetchTicketsResponse(TICKETS_ME, {{"pass_likers", 11}, {"se", 2}}); + auto expected = TNonInitedUpdater::TPairTicketsErrors{ + {{11, "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8"}}, + { + {2, "Missing tvm_id in response, should never happend: se"}, + }, + }; + UNIT_ASSERT_VALUES_EQUAL(expected, t); + + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "3: Failed to get ServiceTicket for se (2): Missing tvm_id in response, should never happend: se\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(Update) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + TKeepAliveHttpClient client("localhost", port); + + auto l = MakeIntrusive<TLogger>(); + TNonInitedUpdater u("localhost", port, l); + NTvmTool::TClientSettings s("me"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + u.MetaInfo_.Init(client, s); + + using TTickets = TServiceTickets::TMapAliasStr; + UNIT_ASSERT(!u.GetCachedServiceTickets()); + UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, u.UpdateServiceTickets(*u.MetaInfo_.GetConfig())); + UNIT_ASSERT(u.GetCachedServiceTickets()); + UNIT_ASSERT_VALUES_EQUAL(TInstant(), u.GetUpdateTimeOfServiceTickets()); + UNIT_ASSERT_EQUAL( + TTickets({ + {"bbox", "3:serv:CBAQ__________9_IgcIlJEGEPIB:N7luw0_rVmBosTTI130jwDbQd0-cMmqJeEl0ma4ZlIo_mHXjBzpOuMQ3A9YagbmOBOt8TZ_gzGvVSegWZkEeB24gM22acw0w-RcHaQKrzSOA5Zq8WLNIC8QUa4_WGTlAsb7R7eC4KTAGgouIquNAgMBdTuGOuZHnMLvZyLnOMKc"}, + {"pass_likers", "3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8"}, + }), + u.GetCachedServiceTickets()->TicketsByAlias); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n", + l->Stream.Str()); + l->Stream.Clear(); + + UNIT_ASSERT(!u.GetCachedServiceContext()); + UNIT_ASSERT(!u.GetCachedUserContext()); + UNIT_ASSERT_VALUES_EQUAL(BIRTHTIME, u.UpdateKeys(*u.MetaInfo_.GetConfig())); + UNIT_ASSERT(u.GetCachedServiceContext()); + UNIT_ASSERT(!u.GetCachedUserContext()); + u.SetBbEnv(EBlackboxEnv::Test); + UNIT_ASSERT(u.GetCachedUserContext()); + UNIT_ASSERT_VALUES_EQUAL("", l->Stream.Str()); + l->Stream.Clear(); + + { + TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); + UNIT_ASSERT(u->GetCachedServiceTickets()); + UNIT_ASSERT(u->GetCachedServiceContext()); + UNIT_ASSERT(u->GetCachedUserContext()); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); + + NTvmAuth::TTvmClient c(u); + UNIT_ASSERT(c.CheckServiceTicket(SRV_TICKET)); + UNIT_ASSERT(!c.CheckServiceTicket(SRV_TICKET_DST_100503)); + UNIT_ASSERT(c.CheckUserTicket(PROD_YATEAM_TICKET)); + UNIT_ASSERT_VALUES_EQUAL("3:serv:CBAQ__________9_IgYIlJEGEAs:T-apeMNWFc_vHPQ3iLaZv9NjG-hf5-i23O4AhRu1M68ryN3FU5qvyqTSSiPbtJdFP6EE41QQBzEs59dHn9DRkqQNwwKf1is00Oewwj2XKO0uHukuzd9XxZnro7MfjPswsjWufxX28rmJtlfSXwAtyKt8TI5yKJnMeBPQ0m5R3k8", c.GetServiceTicketFor("pass_likers")); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n" + << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + l->Stream.Clear(); + + { + NTvmTool::TClientSettings s("something_else"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + + TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); + UNIT_ASSERT(!u->GetCachedServiceTickets()); + UNIT_ASSERT(u->GetCachedServiceContext()); + UNIT_ASSERT(u->GetCachedUserContext()); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); + + NTvmAuth::TTvmClient c(u); + UNIT_ASSERT(!c.CheckServiceTicket(SRV_TICKET)); + UNIT_ASSERT(c.CheckServiceTicket(SRV_TICKET_DST_100503)); + UNIT_ASSERT(c.CheckUserTicket(PROD_YATEAM_TICKET)); + UNIT_ASSERT_EXCEPTION_CONTAINS(c.GetServiceTicketFor("pass_likers"), + TBrokenTvmClientSettings, + "Need to enable ServiceTickets fetching"); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100503, bb_env=ProdYateam, dsts=[]\n" + << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + l->Stream.Clear(); + } + + Y_UNIT_TEST(IsOk) { + TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); + using TTickets = TServiceTickets::TMapIdStr; + + UNIT_ASSERT(u.AreServiceTicketsOk(0)); + UNIT_ASSERT(!u.AreServiceTicketsOk(2)); + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>(TTickets(), + TTickets(), + TServiceTickets::TMapAliasId())); + UNIT_ASSERT(u.AreServiceTicketsOk(0)); + UNIT_ASSERT(!u.AreServiceTicketsOk(2)); + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + TTickets({ + {1, "mega_ticket"}, + {2, "mega_ticket2"}, + }), + TTickets({ + {3, "mega_error3"}, + }), + TServiceTickets::TMapAliasId())); + UNIT_ASSERT(u.AreServiceTicketsOk(0)); + UNIT_ASSERT(!u.AreServiceTicketsOk(2)); + + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + TTickets({ + {1, "mega_ticket"}, + {2, "mega_ticket2"}, + }), + TTickets({ + {3, "mega_error3"}, + }), + TServiceTickets::TMapAliasId({ + {"mega_ticket", 1}, + {"mega_ticket2", 2}, + {"mega_ticket3", 3}, + }))); + UNIT_ASSERT(u.AreServiceTicketsOk(2)); + + UNIT_ASSERT(!u.ArePublicKeysOk()); + u.SetServiceContext(MakeIntrusiveConst<TServiceContext>( + TServiceContext::CheckingFactory(12, NUnittest::TVMKNIFE_PUBLIC_KEYS))); + UNIT_ASSERT(!u.ArePublicKeysOk()); + u.SetUserContext(NUnittest::TVMKNIFE_PUBLIC_KEYS); + UNIT_ASSERT(!u.ArePublicKeysOk()); + u.SetBbEnv(EBlackboxEnv::Test); + UNIT_ASSERT(u.ArePublicKeysOk()); + } + + Y_UNIT_TEST(IsTimeToUpdate) { + TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); + + UNIT_ASSERT(!u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Seconds(597))); + UNIT_ASSERT(u.IsTimeToUpdatePublicKeys(TInstant::Now() - TDuration::Seconds(603))); + + TMetaInfo::TConfig cfg; + UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(597))); + UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(603))); + + cfg.DstAliases = {{"q", 1}}; + UNIT_ASSERT(!u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(597))); + UNIT_ASSERT(u.IsTimeToUpdateServiceTickets(cfg, TInstant::Now() - TDuration::Seconds(603))); + } + + Y_UNIT_TEST(InitWithOldData) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, + []() { + auto p = new TTvmTool; + p->Birthtime = TInstant::Seconds(123); + return p; + }); + + NTvmTool::TClientSettings s("me"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry: "); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100500, bb_env=ProdYateam, dsts=[(pass_likers:11)(bbox:242)]\n" + << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Service tickets have not been refreshed for too long period\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n" + << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Service tickets have not been refreshed for too long period\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n" + << "4: Error while fetching of tickets: Service tickets are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Service tickets have not been refreshed for too long period\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(InitWithOldData_onlyKeys) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, + []() { + auto p = new TTvmTool; + p->Birthtime = TInstant::Seconds(123); + return p; + }); + + NTvmTool::TClientSettings s("something_else"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + + { + s.OverrideBlackboxEnv(EBlackboxEnv::Stress); + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), + TBrokenTvmClientSettings, + "Overriding of BlackboxEnv is illegal: ProdYateam -> Stress"); + } + + s.OverrideBlackboxEnv(EBlackboxEnv::Prod); + auto l = MakeIntrusive<TLogger>(); + UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, l), + TRetriableException, + "Failed to start TvmClient. You can retry: "); + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100503, bb_env=ProdYateam, dsts=[]\n" + << "6: Meta: override blackbox env: ProdYateam->Prod\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n" + << "4: Error while fetching of public keys: Public keys are too old: 1970-01-01T00:02:03.000000Z\n" + << "3: Public keys have not been refreshed for too long period\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(Init) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + + NTvmTool::TClientSettings s("push-client"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + s.SetHostname("localhost"); + + auto l = MakeIntrusive<TLogger>(); + { + TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100501, bb_env=ProdYateam, dsts=[(pass_likers:100502)]\n" + << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + } + + Y_UNIT_TEST(InitWithoutTvmtool) { + NTvmTool::TClientSettings s("me"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(0); + + UNIT_ASSERT_EXCEPTION_CONTAINS(TThreadedUpdater::Create(s, TDevNullLogger::IAmBrave()), + TNonRetriableException, + "can not connect to "); + } + + Y_UNIT_TEST(GetStatus) { + TNonInitedUpdater u("", 0, TDevNullLogger::IAmBrave()); + TMetaInfoProxy m(nullptr); + m.Config_ = std::make_shared<TMetaInfo::TConfig>(); + u.MetaInfo_ = m; + u.LastVisitForConfig_ = TInstant::Now(); + + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); + u.SetUpdateTimeOfPublicKeys(TInstant::Now() - TDuration::Days(3)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); + u.SetUpdateTimeOfPublicKeys(TInstant::Now() - TDuration::Hours(3)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + + u.SetServiceTickets(new TServiceTickets({}, {}, {})); + + TMetaInfo::TConfig cfg; + cfg.DstAliases = {{"q", 1}, {"q2", 2}}; + m.Config_ = std::make_shared<TMetaInfo::TConfig>(cfg); + u.MetaInfo_ = m; + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); + u.SetUpdateTimeOfServiceTickets(TInstant::Now() - TDuration::Hours(3)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Error, u.GetStatus()); + + u.SetServiceTickets(MakeIntrusiveConst<TServiceTickets>( + TServiceTickets::TMapIdStr({{1, "3:serv:CBAQ__________9_IgYIKhCUkQY:CX"}, {2, "t"}}), + TServiceTickets::TMapIdStr({{3, "mega_error"}, {4, "error2"}}), + TServiceTickets::TMapAliasId({ + {"some_alias#1", 1}, + {"some_alias#2", 2}, + }))); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); + + const TInstant* inv = &u.GetCachedServiceTickets()->InvalidationTime; + *const_cast<TInstant*>(inv) = TInstant::Now() + TDuration::Hours(3); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); + + u.SetUpdateTimeOfServiceTickets(TInstant::Now() - TDuration::Minutes(3)); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u.GetStatus()); + + u.LastVisitForConfig_ = TInstant::Now() - TDuration::Minutes(1); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Warning, u.GetStatus()); + } + + Y_UNIT_TEST(multiNamesForDst) { + TPortManager pm; + ui16 port = pm.GetPort(80); + NMock::TMockServer server(port, []() { return new TTvmTool; }); + + NTvmTool::TClientSettings s("multi_names_for_dst"); + s.SetAuthToken(AUTH_TOKEN); + s.SetPort(port); + s.SetHostname("localhost"); + + auto l = MakeIntrusive<TLogger>(); + { + TAsyncUpdaterPtr u = TThreadedUpdater::Create(s, l); + UNIT_ASSERT_VALUES_EQUAL(TClientStatus::Ok, u->GetStatus()); + } + UNIT_ASSERT_VALUES_EQUAL( + TStringBuilder() + << "7: Meta info fetched from localhost:" << port << "\n" + << "6: Meta: self_tvm_id=100599, bb_env=ProdYateam, dsts=[(pass_haters:100502)(pass_likers:100502)]\n" + << "7: Tickets fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Public keys fetched from tvmtool: 2425-09-17T11:04:00.000000Z\n" + << "7: Thread-worker started\n" + << "7: Thread-worker stopped\n", + l->Stream.Str()); + } +} diff --git a/library/cpp/tvmauth/client/ut/utils_ut.cpp b/library/cpp/tvmauth/client/ut/utils_ut.cpp index 23ac35f416..e780fb2779 100644 --- a/library/cpp/tvmauth/client/ut/utils_ut.cpp +++ b/library/cpp/tvmauth/client/ut/utils_ut.cpp @@ -1,88 +1,88 @@ -#include <library/cpp/tvmauth/client/misc/utils.h> - +#include <library/cpp/tvmauth/client/misc/utils.h> + #include <library/cpp/testing/unittest/registar.h> - -Y_UNIT_TEST_SUITE(UtilsTest) { - using namespace NTvmAuth; - - Y_UNIT_TEST(ParseDstMap) { - using TMap = NTvmAuth::NTvmApi::TClientSettings::TDstMap; - UNIT_ASSERT_EQUAL(TMap(), NUtils::ParseDstMap("")); - UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap(";"), TFromStringException); - UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap(":"), TFromStringException); - UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap("3;"), TFromStringException); - UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap("3:foo;"), TFromStringException); - - UNIT_ASSERT_EQUAL(TMap({ - {"foo", 3}, - }), - NUtils::ParseDstMap("foo:3")); - UNIT_ASSERT_EQUAL(TMap({ - {"foo", 3}, - {"bar", 17}, - }), - NUtils::ParseDstMap("foo:3;bar:17;")); - } - - Y_UNIT_TEST(ParseDstVector) { - using TVector = NTvmAuth::NTvmApi::TClientSettings::TDstVector; - UNIT_ASSERT_EQUAL(TVector(), NUtils::ParseDstVector("")); - UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector(";"), - yexception, - "Cannot parse empty string as number"); - UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector(":"), - yexception, - "Unexpected symbol"); - UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector("3:foo;"), - yexception, - "Unexpected symbol"); - UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector("foo:3;"), - yexception, - "Unexpected symbol"); - - UNIT_ASSERT_EQUAL(TVector(1, 3), - NUtils::ParseDstVector("3")); - UNIT_ASSERT_EQUAL(TVector({3, 17}), - NUtils::ParseDstVector("3;17;")); - } - - Y_UNIT_TEST(ToHex) { - UNIT_ASSERT_VALUES_EQUAL("", NUtils::ToHex("")); - UNIT_ASSERT_VALUES_EQUAL("61", NUtils::ToHex("a")); - UNIT_ASSERT_VALUES_EQUAL( - "6C6B787A6E7620736C6A6876627761656220", - NUtils::ToHex("lkxznv sljhvbwaeb ")); - } - - Y_UNIT_TEST(CheckBbEnvOverriding) { - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Prod)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Test)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::TestYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Stress)); - - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Prod)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Test)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::TestYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Stress)); - - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Prod)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Test)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::TestYateam)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Stress)); - - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Prod)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Test)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::TestYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Stress)); - - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Prod)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::ProdYateam)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Test)); - UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::TestYateam)); - UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Stress)); - } -} + +Y_UNIT_TEST_SUITE(UtilsTest) { + using namespace NTvmAuth; + + Y_UNIT_TEST(ParseDstMap) { + using TMap = NTvmAuth::NTvmApi::TClientSettings::TDstMap; + UNIT_ASSERT_EQUAL(TMap(), NUtils::ParseDstMap("")); + UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap(";"), TFromStringException); + UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap(":"), TFromStringException); + UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap("3;"), TFromStringException); + UNIT_ASSERT_EXCEPTION(NUtils::ParseDstMap("3:foo;"), TFromStringException); + + UNIT_ASSERT_EQUAL(TMap({ + {"foo", 3}, + }), + NUtils::ParseDstMap("foo:3")); + UNIT_ASSERT_EQUAL(TMap({ + {"foo", 3}, + {"bar", 17}, + }), + NUtils::ParseDstMap("foo:3;bar:17;")); + } + + Y_UNIT_TEST(ParseDstVector) { + using TVector = NTvmAuth::NTvmApi::TClientSettings::TDstVector; + UNIT_ASSERT_EQUAL(TVector(), NUtils::ParseDstVector("")); + UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector(";"), + yexception, + "Cannot parse empty string as number"); + UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector(":"), + yexception, + "Unexpected symbol"); + UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector("3:foo;"), + yexception, + "Unexpected symbol"); + UNIT_ASSERT_EXCEPTION_CONTAINS(NUtils::ParseDstVector("foo:3;"), + yexception, + "Unexpected symbol"); + + UNIT_ASSERT_EQUAL(TVector(1, 3), + NUtils::ParseDstVector("3")); + UNIT_ASSERT_EQUAL(TVector({3, 17}), + NUtils::ParseDstVector("3;17;")); + } + + Y_UNIT_TEST(ToHex) { + UNIT_ASSERT_VALUES_EQUAL("", NUtils::ToHex("")); + UNIT_ASSERT_VALUES_EQUAL("61", NUtils::ToHex("a")); + UNIT_ASSERT_VALUES_EQUAL( + "6C6B787A6E7620736C6A6876627761656220", + NUtils::ToHex("lkxznv sljhvbwaeb ")); + } + + Y_UNIT_TEST(CheckBbEnvOverriding) { + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Prod)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Test)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::TestYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Prod, EBlackboxEnv::Stress)); + + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Prod)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Test)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::TestYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::ProdYateam, EBlackboxEnv::Stress)); + + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Prod)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Test)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::TestYateam)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Test, EBlackboxEnv::Stress)); + + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Prod)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Test)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::TestYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::TestYateam, EBlackboxEnv::Stress)); + + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Prod)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::ProdYateam)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Test)); + UNIT_ASSERT(!NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::TestYateam)); + UNIT_ASSERT(NUtils::CheckBbEnvOverriding(EBlackboxEnv::Stress, EBlackboxEnv::Stress)); + } +} diff --git a/library/cpp/tvmauth/client/ut/ya.make b/library/cpp/tvmauth/client/ut/ya.make index 20eef6acba..e2686cd8d7 100644 --- a/library/cpp/tvmauth/client/ut/ya.make +++ b/library/cpp/tvmauth/client/ut/ya.make @@ -1,36 +1,36 @@ -UNITTEST_FOR(library/cpp/tvmauth/client) - -OWNER(g:passport_infra) - -DATA(arcadia/library/cpp/tvmauth/client/ut/files) - -PEERDIR( +UNITTEST_FOR(library/cpp/tvmauth/client) + +OWNER(g:passport_infra) + +DATA(arcadia/library/cpp/tvmauth/client/ut/files) + +PEERDIR( library/cpp/cgiparam - library/cpp/testing/mock_server -) - -SRCS( - async_updater_ut.cpp - checker_ut.cpp - client_status_ut.cpp - default_uid_checker_ut.cpp - disk_cache_ut.cpp - exponential_backoff_ut.cpp - facade_ut.cpp - last_error_ut.cpp - logger_ut.cpp - roles/decoder_ut.cpp - roles/entities_index_ut.cpp - roles/parser_ut.cpp - roles/roles_ut.cpp - roles/tvmapi_roles_fetcher_ut.cpp - settings_ut.cpp - src_checker_ut.cpp - tvmapi_updater_ut.cpp - tvmtool_updater_ut.cpp - utils_ut.cpp -) - + library/cpp/testing/mock_server +) + +SRCS( + async_updater_ut.cpp + checker_ut.cpp + client_status_ut.cpp + default_uid_checker_ut.cpp + disk_cache_ut.cpp + exponential_backoff_ut.cpp + facade_ut.cpp + last_error_ut.cpp + logger_ut.cpp + roles/decoder_ut.cpp + roles/entities_index_ut.cpp + roles/parser_ut.cpp + roles/roles_ut.cpp + roles/tvmapi_roles_fetcher_ut.cpp + settings_ut.cpp + src_checker_ut.cpp + tvmapi_updater_ut.cpp + tvmtool_updater_ut.cpp + utils_ut.cpp +) + REQUIREMENTS(ram:11) -END() +END() diff --git a/library/cpp/tvmauth/client/ya.make b/library/cpp/tvmauth/client/ya.make index c3986021b2..8ac4e56e01 100644 --- a/library/cpp/tvmauth/client/ya.make +++ b/library/cpp/tvmauth/client/ya.make @@ -1,49 +1,49 @@ -LIBRARY() - -OWNER(g:passport_infra) - -PEERDIR( - library/cpp/http/simple - library/cpp/json - library/cpp/openssl/crypto - library/cpp/streams/brotli - library/cpp/streams/zstd - library/cpp/string_utils/quote - library/cpp/tvmauth - library/cpp/tvmauth/client/misc/retry_settings/v1 -) - -SRCS( - client_status.cpp - facade.cpp - logger.cpp - misc/api/roles_fetcher.cpp - misc/api/settings.cpp - misc/api/threaded_updater.cpp - misc/async_updater.cpp - misc/disk_cache.cpp - misc/last_error.cpp - misc/proc_info.cpp - misc/roles/decoder.cpp - misc/roles/entities_index.cpp - misc/roles/parser.cpp - misc/roles/roles.cpp - misc/threaded_updater.cpp - misc/tool/meta_info.cpp - misc/tool/settings.cpp - misc/tool/threaded_updater.cpp - misc/utils.cpp - mocked_updater.cpp -) - -GENERATE_ENUM_SERIALIZATION(client_status.h) -GENERATE_ENUM_SERIALIZATION(misc/async_updater.h) -GENERATE_ENUM_SERIALIZATION(misc/last_error.h) - -END() - -RECURSE_FOR_TESTS( - examples - misc/api/dynamic_dst - ut -) +LIBRARY() + +OWNER(g:passport_infra) + +PEERDIR( + library/cpp/http/simple + library/cpp/json + library/cpp/openssl/crypto + library/cpp/streams/brotli + library/cpp/streams/zstd + library/cpp/string_utils/quote + library/cpp/tvmauth + library/cpp/tvmauth/client/misc/retry_settings/v1 +) + +SRCS( + client_status.cpp + facade.cpp + logger.cpp + misc/api/roles_fetcher.cpp + misc/api/settings.cpp + misc/api/threaded_updater.cpp + misc/async_updater.cpp + misc/disk_cache.cpp + misc/last_error.cpp + misc/proc_info.cpp + misc/roles/decoder.cpp + misc/roles/entities_index.cpp + misc/roles/parser.cpp + misc/roles/roles.cpp + misc/threaded_updater.cpp + misc/tool/meta_info.cpp + misc/tool/settings.cpp + misc/tool/threaded_updater.cpp + misc/utils.cpp + mocked_updater.cpp +) + +GENERATE_ENUM_SERIALIZATION(client_status.h) +GENERATE_ENUM_SERIALIZATION(misc/async_updater.h) +GENERATE_ENUM_SERIALIZATION(misc/last_error.h) + +END() + +RECURSE_FOR_TESTS( + examples + misc/api/dynamic_dst + ut +) diff --git a/library/cpp/tvmauth/deprecated/README.md b/library/cpp/tvmauth/deprecated/README.md index fffea3ae77..d9ea09c3c0 100644 --- a/library/cpp/tvmauth/deprecated/README.md +++ b/library/cpp/tvmauth/deprecated/README.md @@ -1,2 +1,2 @@ -Please don't use this part of library directly. -Please use [TTvmClient](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/README.md) instead. +Please don't use this part of library directly. +Please use [TTvmClient](https://a.yandex-team.ru/arc/trunk/arcadia/library/cpp/tvmauth/README.md) instead. diff --git a/library/cpp/tvmauth/deprecated/service_context.cpp b/library/cpp/tvmauth/deprecated/service_context.cpp index e0976de0a6..24822a9d53 100644 --- a/library/cpp/tvmauth/deprecated/service_context.cpp +++ b/library/cpp/tvmauth/deprecated/service_context.cpp @@ -1,37 +1,37 @@ -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/src/service_impl.h> - -namespace NTvmAuth { - static const char* EX_MSG = "ServiceContext already moved out"; - - TServiceContext::TServiceContext(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse) - : Impl_(MakeHolder<TImpl>(secretBase64, selfTvmId, tvmKeysResponse)) - { - } - - TServiceContext::TServiceContext(TServiceContext&& o) = default; - TServiceContext& TServiceContext::operator=(TServiceContext&& o) = default; - TServiceContext::~TServiceContext() = default; - - TServiceContext TServiceContext::CheckingFactory(TTvmId selfTvmId, TStringBuf tvmKeysResponse) { - TServiceContext c; - c.Impl_ = MakeHolder<TImpl>(selfTvmId, tvmKeysResponse); - return c; - } - - TServiceContext TServiceContext::SigningFactory(TStringBuf secretBase64) { - TServiceContext c; - c.Impl_ = MakeHolder<TImpl>(secretBase64); - return c; - } - - TCheckedServiceTicket TServiceContext::Check(TStringBuf ticketBody) const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->Check(ticketBody); - } - - TString TServiceContext::SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes) const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->SignCgiParamsForTvm(ts, dst, scopes); - } -} +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/src/service_impl.h> + +namespace NTvmAuth { + static const char* EX_MSG = "ServiceContext already moved out"; + + TServiceContext::TServiceContext(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse) + : Impl_(MakeHolder<TImpl>(secretBase64, selfTvmId, tvmKeysResponse)) + { + } + + TServiceContext::TServiceContext(TServiceContext&& o) = default; + TServiceContext& TServiceContext::operator=(TServiceContext&& o) = default; + TServiceContext::~TServiceContext() = default; + + TServiceContext TServiceContext::CheckingFactory(TTvmId selfTvmId, TStringBuf tvmKeysResponse) { + TServiceContext c; + c.Impl_ = MakeHolder<TImpl>(selfTvmId, tvmKeysResponse); + return c; + } + + TServiceContext TServiceContext::SigningFactory(TStringBuf secretBase64) { + TServiceContext c; + c.Impl_ = MakeHolder<TImpl>(secretBase64); + return c; + } + + TCheckedServiceTicket TServiceContext::Check(TStringBuf ticketBody) const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->Check(ticketBody); + } + + TString TServiceContext::SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes) const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->SignCgiParamsForTvm(ts, dst, scopes); + } +} diff --git a/library/cpp/tvmauth/deprecated/service_context.h b/library/cpp/tvmauth/deprecated/service_context.h index 5dc836261b..bc14d381b2 100644 --- a/library/cpp/tvmauth/deprecated/service_context.h +++ b/library/cpp/tvmauth/deprecated/service_context.h @@ -1,63 +1,63 @@ -#pragma once - -#include <library/cpp/tvmauth/checked_service_ticket.h> - -#include <util/generic/ptr.h> - -namespace NTvmAuth { - class TServiceContext: public TAtomicRefCount<TServiceContext> { - public: - /*! - * Create service context. Serivce contexts are used to store TVM keys and parse service tickets. - * @param selfTvmId - * @param secretBase64 - * @param tvmKeysResponse - */ - TServiceContext(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse); - TServiceContext(TServiceContext&&); - ~TServiceContext(); - - /*! - * Create service context only for checking service tickets - * \param[in] selfTvmId - * \param[in] tvmKeysResponse - * \return - */ - static TServiceContext CheckingFactory(TTvmId selfTvmId, TStringBuf tvmKeysResponse); - - /*! - * Create service context only for signing HTTP request to TVM-API - * \param[in] secretBase64 - * \return - */ - static TServiceContext SigningFactory(TStringBuf secretBase64); - - TServiceContext& operator=(TServiceContext&&); - - /*! - * Parse and validate service ticket body then create TCheckedServiceTicket object. - * @param ticketBody - * @return TCheckedServiceTicket object - */ - TCheckedServiceTicket Check(TStringBuf ticketBody) const; - - /*! - * Sign params for TVM API - * @param ts Param 'ts' of request to TVM - * @param dst Param 'dst' of request to TVM - * @param scopes Param 'scopes' of request to TVM - * @return Signed string - */ - TString SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes = TStringBuf()) const; - - class TImpl; - - private: - TServiceContext() = default; - - private: - THolder<TImpl> Impl_; - }; - - using TServiceContextPtr = TIntrusiveConstPtr<TServiceContext>; -} +#pragma once + +#include <library/cpp/tvmauth/checked_service_ticket.h> + +#include <util/generic/ptr.h> + +namespace NTvmAuth { + class TServiceContext: public TAtomicRefCount<TServiceContext> { + public: + /*! + * Create service context. Serivce contexts are used to store TVM keys and parse service tickets. + * @param selfTvmId + * @param secretBase64 + * @param tvmKeysResponse + */ + TServiceContext(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse); + TServiceContext(TServiceContext&&); + ~TServiceContext(); + + /*! + * Create service context only for checking service tickets + * \param[in] selfTvmId + * \param[in] tvmKeysResponse + * \return + */ + static TServiceContext CheckingFactory(TTvmId selfTvmId, TStringBuf tvmKeysResponse); + + /*! + * Create service context only for signing HTTP request to TVM-API + * \param[in] secretBase64 + * \return + */ + static TServiceContext SigningFactory(TStringBuf secretBase64); + + TServiceContext& operator=(TServiceContext&&); + + /*! + * Parse and validate service ticket body then create TCheckedServiceTicket object. + * @param ticketBody + * @return TCheckedServiceTicket object + */ + TCheckedServiceTicket Check(TStringBuf ticketBody) const; + + /*! + * Sign params for TVM API + * @param ts Param 'ts' of request to TVM + * @param dst Param 'dst' of request to TVM + * @param scopes Param 'scopes' of request to TVM + * @return Signed string + */ + TString SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes = TStringBuf()) const; + + class TImpl; + + private: + TServiceContext() = default; + + private: + THolder<TImpl> Impl_; + }; + + using TServiceContextPtr = TIntrusiveConstPtr<TServiceContext>; +} diff --git a/library/cpp/tvmauth/deprecated/user_context.cpp b/library/cpp/tvmauth/deprecated/user_context.cpp index 5ff7714db5..712f622f1a 100644 --- a/library/cpp/tvmauth/deprecated/user_context.cpp +++ b/library/cpp/tvmauth/deprecated/user_context.cpp @@ -1,20 +1,20 @@ -#include <library/cpp/tvmauth/checked_user_ticket.h> -#include <library/cpp/tvmauth/src/user_impl.h> - -namespace NTvmAuth { - static const char* EX_MSG = "UserContext already moved out"; - - TUserContext::TUserContext(EBlackboxEnv env, TStringBuf tvmKeysResponse) - : Impl_(MakeHolder<TImpl>(env, tvmKeysResponse)) - { - } - - TUserContext::TUserContext(TUserContext&& o) = default; - TUserContext& TUserContext::operator=(TUserContext&& o) = default; - TUserContext::~TUserContext() = default; - - TCheckedUserTicket TUserContext::Check(TStringBuf ticketBody) const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->Check(ticketBody); - } -} +#include <library/cpp/tvmauth/checked_user_ticket.h> +#include <library/cpp/tvmauth/src/user_impl.h> + +namespace NTvmAuth { + static const char* EX_MSG = "UserContext already moved out"; + + TUserContext::TUserContext(EBlackboxEnv env, TStringBuf tvmKeysResponse) + : Impl_(MakeHolder<TImpl>(env, tvmKeysResponse)) + { + } + + TUserContext::TUserContext(TUserContext&& o) = default; + TUserContext& TUserContext::operator=(TUserContext&& o) = default; + TUserContext::~TUserContext() = default; + + TCheckedUserTicket TUserContext::Check(TStringBuf ticketBody) const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->Check(ticketBody); + } +} diff --git a/library/cpp/tvmauth/deprecated/user_context.h b/library/cpp/tvmauth/deprecated/user_context.h index 3b2503b9b1..f7fe67d02e 100644 --- a/library/cpp/tvmauth/deprecated/user_context.h +++ b/library/cpp/tvmauth/deprecated/user_context.h @@ -1,30 +1,30 @@ -#pragma once - -#include <library/cpp/tvmauth/checked_user_ticket.h> - -#include <util/generic/ptr.h> - -namespace NTvmAuth { - class TUserContext: public TAtomicRefCount<TUserContext> { - public: - TUserContext(EBlackboxEnv env, TStringBuf tvmKeysResponse); - TUserContext(TUserContext&&); - ~TUserContext(); - - TUserContext& operator=(TUserContext&&); - - /*! - * Parse and validate user ticket body then create TCheckedUserTicket object. - * @param ticketBody - * @return TCheckedUserTicket object - */ - TCheckedUserTicket Check(TStringBuf ticketBody) const; - - class TImpl; - - private: - THolder<TImpl> Impl_; - }; - - using TUserContextPtr = TIntrusiveConstPtr<TUserContext>; -} +#pragma once + +#include <library/cpp/tvmauth/checked_user_ticket.h> + +#include <util/generic/ptr.h> + +namespace NTvmAuth { + class TUserContext: public TAtomicRefCount<TUserContext> { + public: + TUserContext(EBlackboxEnv env, TStringBuf tvmKeysResponse); + TUserContext(TUserContext&&); + ~TUserContext(); + + TUserContext& operator=(TUserContext&&); + + /*! + * Parse and validate user ticket body then create TCheckedUserTicket object. + * @param ticketBody + * @return TCheckedUserTicket object + */ + TCheckedUserTicket Check(TStringBuf ticketBody) const; + + class TImpl; + + private: + THolder<TImpl> Impl_; + }; + + using TUserContextPtr = TIntrusiveConstPtr<TUserContext>; +} diff --git a/library/cpp/tvmauth/exception.h b/library/cpp/tvmauth/exception.h index d59f03205a..f528886b95 100644 --- a/library/cpp/tvmauth/exception.h +++ b/library/cpp/tvmauth/exception.h @@ -4,7 +4,7 @@ #include <exception> -namespace NTvmAuth { +namespace NTvmAuth { class TTvmException: public yexception { }; class TContextException: public TTvmException { @@ -17,4 +17,4 @@ namespace NTvmAuth { }; class TNotAllowedException: public TTvmException { }; -} +} diff --git a/library/cpp/tvmauth/src/parser.cpp b/library/cpp/tvmauth/src/parser.cpp index b91b96bf3b..358de58d36 100644 --- a/library/cpp/tvmauth/src/parser.cpp +++ b/library/cpp/tvmauth/src/parser.cpp @@ -2,26 +2,26 @@ #include "utils.h" -#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/exception.h> #include <util/generic/strbuf.h> #include <util/string/split.h> #include <ctime> -namespace NTvmAuth { +namespace NTvmAuth { TString TParserTvmKeys::ParseStrV1(TStringBuf str) { while (str && str.back() == '\n') { str.Chop(1); } - TStringBuf ver = str.NextTok(DELIM); + TStringBuf ver = str.NextTok(DELIM); if (!str || !ver || ver != "1") { - throw TMalformedTvmKeysException() << "Malformed TVM keys"; + throw TMalformedTvmKeysException() << "Malformed TVM keys"; } TString res = NUtils::Base64url2bin(str); if (res.empty()) { - throw TMalformedTvmKeysException() << "Malformed TVM keys"; + throw TMalformedTvmKeysException() << "Malformed TVM keys"; } return res; } @@ -39,25 +39,25 @@ namespace NTvmAuth { TParserTickets::TRes TParserTickets::ParseV3(TStringBuf body, const NRw::TPublicKeys& keys, TStringBuf type) { TStrRes str = ParseStrV3(body, type); TRes res(str.Status); - if (str.Status != ETicketStatus::Ok) { + if (str.Status != ETicketStatus::Ok) { return TRes(str.Status); } if (!res.Ticket.ParseFromString(str.Proto)) { - res.Status = ETicketStatus::Malformed; + res.Status = ETicketStatus::Malformed; return res; } if (res.Ticket.expirationtime() <= time(nullptr)) { - res.Status = ETicketStatus::Expired; + res.Status = ETicketStatus::Expired; return res; } auto itKey = keys.find(res.Ticket.keyid()); if (itKey == keys.end()) { - res.Status = ETicketStatus::MissingKey; + res.Status = ETicketStatus::MissingKey; return res; } if (!itKey->second.CheckSign(str.ForCheck, str.Sign)) { - res.Status = ETicketStatus::SignBroken; + res.Status = ETicketStatus::SignBroken; return res; } return res; @@ -66,32 +66,32 @@ namespace NTvmAuth { TParserTickets::TStrRes TParserTickets::ParseStrV3(TStringBuf body, TStringBuf type) { TStringBuf forCheck = body; TStringBuf version = body.NextTok(DELIM); - if (!body || version.size() != 1) { - return {ETicketStatus::Malformed, {}, {}, {}}; - } + if (!body || version.size() != 1) { + return {ETicketStatus::Malformed, {}, {}, {}}; + } if (version != "3") { - return {ETicketStatus::UnsupportedVersion, {}, {}, {}}; + return {ETicketStatus::UnsupportedVersion, {}, {}, {}}; } TStringBuf ticketType = body.NextTok(DELIM); if (ticketType != type) { - return {ETicketStatus::InvalidTicketType, {}, {}, {}}; + return {ETicketStatus::InvalidTicketType, {}, {}, {}}; } TStringBuf proto = body.NextTok(DELIM); TStringBuf sign = body.NextTok(DELIM); if (!proto || !sign || body.size() > 0) { - return {ETicketStatus::Malformed, {}, {}, {}}; + return {ETicketStatus::Malformed, {}, {}, {}}; } TString protoBin = NUtils::Base64url2bin(proto); TString signBin = NUtils::Base64url2bin(sign); if (!protoBin || !signBin) { - return {ETicketStatus::Malformed, {}, {}, {}}; + return {ETicketStatus::Malformed, {}, {}, {}}; } - return {ETicketStatus::Ok, std::move(protoBin), std::move(signBin), forCheck.Chop(sign.size())}; + return {ETicketStatus::Ok, std::move(protoBin), std::move(signBin), forCheck.Chop(sign.size())}; } -} +} diff --git a/library/cpp/tvmauth/src/parser.h b/library/cpp/tvmauth/src/parser.h index 5424ff1f3a..678e709444 100644 --- a/library/cpp/tvmauth/src/parser.h +++ b/library/cpp/tvmauth/src/parser.h @@ -1,17 +1,17 @@ #pragma once -#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> -#include <library/cpp/tvmauth/src/rw/keys.h> +#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> +#include <library/cpp/tvmauth/src/rw/keys.h> -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/ticket_status.h> #include <util/generic/fwd.h> #include <string> -namespace NTvmAuth { +namespace NTvmAuth { struct TParserTvmKeys { - static inline const char DELIM = ':'; + static inline const char DELIM = ':'; static TString ParseStrV1(TStringBuf str); }; @@ -22,12 +22,12 @@ namespace NTvmAuth { static TStringBuf ServiceFlag(); struct TRes { - TRes(ETicketStatus status) + TRes(ETicketStatus status) : Status(status) { } - ETicketStatus Status; + ETicketStatus Status; ticket2::Ticket Ticket; }; @@ -35,7 +35,7 @@ namespace NTvmAuth { // private: struct TStrRes { - const ETicketStatus Status; + const ETicketStatus Status; TString Proto; TString Sign; @@ -48,4 +48,4 @@ namespace NTvmAuth { }; static TStrRes ParseStrV3(TStringBuf body, TStringBuf type); }; -} +} diff --git a/library/cpp/tvmauth/src/protos/ticket2.proto b/library/cpp/tvmauth/src/protos/ticket2.proto index 97faf48a4f..66c00a7d01 100644 --- a/library/cpp/tvmauth/src/protos/ticket2.proto +++ b/library/cpp/tvmauth/src/protos/ticket2.proto @@ -1,8 +1,8 @@ package ticket2; -option go_package = "a.yandex-team.ru/library/cpp/tvmauth/src/protos"; - -import "library/cpp/tvmauth/src/protos/tvm_keys.proto"; +option go_package = "a.yandex-team.ru/library/cpp/tvmauth/src/protos"; + +import "library/cpp/tvmauth/src/protos/tvm_keys.proto"; message User { required uint64 uid = 1; diff --git a/library/cpp/tvmauth/src/protos/tvm_keys.proto b/library/cpp/tvmauth/src/protos/tvm_keys.proto index 5c85fd2a70..9ba42dbf80 100644 --- a/library/cpp/tvmauth/src/protos/tvm_keys.proto +++ b/library/cpp/tvmauth/src/protos/tvm_keys.proto @@ -1,9 +1,9 @@ package tvm_keys; -option go_package = "a.yandex-team.ru/library/cpp/tvmauth/src/protos"; - +option go_package = "a.yandex-team.ru/library/cpp/tvmauth/src/protos"; + enum KeyType { - RabinWilliams = 0; + RabinWilliams = 0; } enum BbEnvType { diff --git a/library/cpp/tvmauth/src/protos/ya.make b/library/cpp/tvmauth/src/protos/ya.make index 78d7c812af..c2d579dc40 100644 --- a/library/cpp/tvmauth/src/protos/ya.make +++ b/library/cpp/tvmauth/src/protos/ya.make @@ -1,9 +1,9 @@ PROTO_LIBRARY() -OWNER(g:passport_infra) +OWNER(g:passport_infra) + +INCLUDE_TAGS(GO_PROTO) -INCLUDE_TAGS(GO_PROTO) - SRCS( ticket2.proto tvm_keys.proto diff --git a/library/cpp/tvmauth/src/rw/keys.cpp b/library/cpp/tvmauth/src/rw/keys.cpp index d37587c451..5395287f5c 100644 --- a/library/cpp/tvmauth/src/rw/keys.cpp +++ b/library/cpp/tvmauth/src/rw/keys.cpp @@ -2,137 +2,137 @@ #include "rw.h" -#include <library/cpp/openssl/init/init.h> - +#include <library/cpp/openssl/init/init.h> + #include <contrib/libs/openssl/include/openssl/evp.h> #include <util/generic/strbuf.h> -#include <util/generic/yexception.h> - -namespace { - struct TInit { - TInit() { - InitOpenSSL(); - } - } INIT; -} - -namespace NTvmAuth { +#include <util/generic/yexception.h> + +namespace { + struct TInit { + TInit() { + InitOpenSSL(); + } + } INIT; +} + +namespace NTvmAuth { namespace NRw { - namespace NPrivate { - void TRwDestroyer::Destroy(TRwInternal* o) { - RwFree(o); - } - - class TArrayDestroyer { - public: - static void Destroy(unsigned char* o) { - free(o); - } - }; - } - - static TString SerializeRW(TRwKey* rw, int (*func)(const TRwKey*, unsigned char**)) { + namespace NPrivate { + void TRwDestroyer::Destroy(TRwInternal* o) { + RwFree(o); + } + + class TArrayDestroyer { + public: + static void Destroy(unsigned char* o) { + free(o); + } + }; + } + + static TString SerializeRW(TRwKey* rw, int (*func)(const TRwKey*, unsigned char**)) { unsigned char* buf = nullptr; int size = func(rw, &buf); - THolder<unsigned char, NPrivate::TArrayDestroyer> guard(buf); + THolder<unsigned char, NPrivate::TArrayDestroyer> guard(buf); return TString((char*)buf, size); } - TKeyPair GenKeyPair(size_t size) { - TRw rw(RwNew()); - RwGenerateKey(rw.Get(), size); - - TRw skey(RwPrivateKeyDup(rw.Get())); - TRw vkey(RwPublicKeyDup(rw.Get())); - - TKeyPair res; - res.Private = SerializeRW(skey.Get(), &i2d_RWPrivateKey); - res.Public = SerializeRW(vkey.Get(), &i2d_RWPublicKey); - - TRwPrivateKey prKey(res.Private, 0); - TRwPublicKey pubKey(res.Public); - - const TStringBuf msg = "Test test test test test"; - - Y_ENSURE(pubKey.CheckSign(msg, prKey.SignTicket(msg)), "Failed to gen keys"); - - return res; + TKeyPair GenKeyPair(size_t size) { + TRw rw(RwNew()); + RwGenerateKey(rw.Get(), size); + + TRw skey(RwPrivateKeyDup(rw.Get())); + TRw vkey(RwPublicKeyDup(rw.Get())); + + TKeyPair res; + res.Private = SerializeRW(skey.Get(), &i2d_RWPrivateKey); + res.Public = SerializeRW(vkey.Get(), &i2d_RWPublicKey); + + TRwPrivateKey prKey(res.Private, 0); + TRwPublicKey pubKey(res.Public); + + const TStringBuf msg = "Test test test test test"; + + Y_ENSURE(pubKey.CheckSign(msg, prKey.SignTicket(msg)), "Failed to gen keys"); + + return res; } TRwPrivateKey::TRwPrivateKey(TStringBuf body, TKeyId id) - : Id_(id) - , Rw_(Deserialize(body)) - , SignLen_(RwModSize(Rw_.Get())) + : Id_(id) + , Rw_(Deserialize(body)) + , SignLen_(RwModSize(Rw_.Get())) { - Y_ENSURE(SignLen_ > 0, "Private key has bad len: " << SignLen_); + Y_ENSURE(SignLen_ > 0, "Private key has bad len: " << SignLen_); } TKeyId TRwPrivateKey::GetId() const { - return Id_; + return Id_; } TString TRwPrivateKey::SignTicket(TStringBuf ticket) const { - TString res(SignLen_, 0x00); - - int len = RwPssrSignMsg(ticket.size(), - (const unsigned char*)ticket.data(), - (unsigned char*)res.data(), - Rw_.Get(), - (EVP_MD*)EVP_sha256()); - - Y_ENSURE(len > 0 && len <= SignLen_, "Signing failed. len: " << len); - - res.resize(len); - return res; + TString res(SignLen_, 0x00); + + int len = RwPssrSignMsg(ticket.size(), + (const unsigned char*)ticket.data(), + (unsigned char*)res.data(), + Rw_.Get(), + (EVP_MD*)EVP_sha256()); + + Y_ENSURE(len > 0 && len <= SignLen_, "Signing failed. len: " << len); + + res.resize(len); + return res; } TRw TRwPrivateKey::Deserialize(TStringBuf key) { - TRwKey* rw = nullptr; + TRwKey* rw = nullptr; auto data = reinterpret_cast<const unsigned char*>(key.data()); if (!d2i_RWPrivateKey(&rw, &data, key.size())) { - ythrow yexception() << "Private key is malformed"; + ythrow yexception() << "Private key is malformed"; } - return TRw(rw); + return TRw(rw); } TRwPublicKey::TRwPublicKey(TStringBuf body) - : Rw_(Deserialize(body)) + : Rw_(Deserialize(body)) { } bool TRwPublicKey::CheckSign(TStringBuf ticket, TStringBuf sign) const { - int result = RwPssrVerifyMsg(ticket.size(), - (const unsigned char*)ticket.data(), - (unsigned char*)sign.data(), - sign.size(), - Rw_.Get(), - (EVP_MD*)EVP_sha256()); - - Y_ENSURE(result >= 0, "Failed to check sign: " << result); + int result = RwPssrVerifyMsg(ticket.size(), + (const unsigned char*)ticket.data(), + (unsigned char*)sign.data(), + sign.size(), + Rw_.Get(), + (EVP_MD*)EVP_sha256()); + + Y_ENSURE(result >= 0, "Failed to check sign: " << result); return result; } TRw TRwPublicKey::Deserialize(TStringBuf key) { - TRwKey* rw = nullptr; + TRwKey* rw = nullptr; auto data = reinterpret_cast<const unsigned char*>(key.data()); - auto status = d2i_RWPublicKey(&rw, &data, key.size()); - - TRw res(rw); - Y_ENSURE(status, "Public key is malformed: " << key); - return res; + auto status = d2i_RWPublicKey(&rw, &data, key.size()); + + TRw res(rw); + Y_ENSURE(status, "Public key is malformed: " << key); + return res; + } + + TSecureHeap::TSecureHeap(size_t totalSize, int minChunkSize) { + CRYPTO_secure_malloc_init(totalSize, minChunkSize); + } + + TSecureHeap::~TSecureHeap() { + CRYPTO_secure_malloc_done(); + } + + void TSecureHeap::Init(size_t totalSize, int minChunkSize) { + Singleton<TSecureHeap>(totalSize, minChunkSize); } - - TSecureHeap::TSecureHeap(size_t totalSize, int minChunkSize) { - CRYPTO_secure_malloc_init(totalSize, minChunkSize); - } - - TSecureHeap::~TSecureHeap() { - CRYPTO_secure_malloc_done(); - } - - void TSecureHeap::Init(size_t totalSize, int minChunkSize) { - Singleton<TSecureHeap>(totalSize, minChunkSize); - } } } diff --git a/library/cpp/tvmauth/src/rw/keys.h b/library/cpp/tvmauth/src/rw/keys.h index 1070b78358..e02b7e72a1 100644 --- a/library/cpp/tvmauth/src/rw/keys.h +++ b/library/cpp/tvmauth/src/rw/keys.h @@ -1,29 +1,29 @@ #pragma once -#include <util/generic/ptr.h> -#include <util/generic/string.h> +#include <util/generic/ptr.h> +#include <util/generic/string.h> #include <unordered_map> -struct TRwInternal; +struct TRwInternal; -namespace NTvmAuth { +namespace NTvmAuth { namespace NRw { - namespace NPrivate { - class TRwDestroyer { - public: - static void Destroy(TRwInternal* o); - }; - } - - using TRw = THolder<TRwInternal, NPrivate::TRwDestroyer>; - using TKeyId = ui32; - + namespace NPrivate { + class TRwDestroyer { + public: + static void Destroy(TRwInternal* o); + }; + } + + using TRw = THolder<TRwInternal, NPrivate::TRwDestroyer>; + using TKeyId = ui32; + struct TKeyPair { - TString Private; - TString Public; + TString Private; + TString Public; }; - TKeyPair GenKeyPair(size_t size); + TKeyPair GenKeyPair(size_t size); class TRwPrivateKey { public: @@ -35,9 +35,9 @@ namespace NTvmAuth { private: static TRw Deserialize(TStringBuf key); - TKeyId Id_; - TRw Rw_; - int SignLen_; + TKeyId Id_; + TRw Rw_; + int SignLen_; }; class TRwPublicKey { @@ -49,17 +49,17 @@ namespace NTvmAuth { private: static TRw Deserialize(TStringBuf key); - TRw Rw_; + TRw Rw_; }; using TPublicKeys = std::unordered_map<TKeyId, TRwPublicKey>; - - class TSecureHeap { - public: - TSecureHeap(size_t totalSize, int minChunkSize); - ~TSecureHeap(); - - static void Init(size_t totalSize = 16 * 1024 * 1024, int minChunkSize = 16); - }; + + class TSecureHeap { + public: + TSecureHeap(size_t totalSize, int minChunkSize); + ~TSecureHeap(); + + static void Init(size_t totalSize = 16 * 1024 * 1024, int minChunkSize = 16); + }; } } diff --git a/library/cpp/tvmauth/src/rw/rw.h b/library/cpp/tvmauth/src/rw/rw.h index 1f8805dab3..cbff96b85d 100644 --- a/library/cpp/tvmauth/src/rw/rw.h +++ b/library/cpp/tvmauth/src/rw/rw.h @@ -7,79 +7,79 @@ extern "C" { #endif - typedef struct { - BIGNUM* S; - } TRwSignature; - - /*Rabin–Williams*/ - typedef struct TRwInternal TRwKey; - - typedef struct { - TRwSignature* (*RwSign)(const unsigned char* dgst, const int dlen, TRwKey* rw); - int (*RwVerify)(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw); - int (*RwApply)(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw); - } TRwMethod; - - struct TRwInternal { - /* first private multiplier */ - BIGNUM* P; - /* second private multiplier */ - BIGNUM* Q; - /* n = p*q - RW modulus */ - BIGNUM* N; - /* precomputed 2^((3q-5)/8) mod q */ - BIGNUM* Twomq; - /* precomputed 2^((9p-11)/8) mod p*/ - BIGNUM* Twomp; - /* precomputed q^(p-2) == q^(-1) mod p */ - BIGNUM* Iqmp; - /* (q+1) / 8 */ - BIGNUM* Dq; - /* (p-3) / 8 */ - BIGNUM* Dp; - /* functions for working with RW */ - const TRwMethod* Meth; - }; - - TRwSignature* RwSignatureNew(void); - void RwSignatureFree(TRwSignature* a); - - /* RW signing functions */ - /* the function can put some tmp values to rw */ - int RwPssrSignHash(const unsigned char* from, unsigned char* to, TRwKey* rw, const EVP_MD* md); - int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, TRwKey* rw, const EVP_MD* md); - - /* RW-PSS verification functions */ - int RwPssrVerifyHash(const unsigned char* from, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md); - int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md); - - /* internal functions, use them only if you know what you're doing */ - int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwKey* rw); - int RwApply(const int flen, const unsigned char* from, unsigned char* to, const TRwKey* rw); - - const TRwMethod* RwDefaultMethods(void); - - TRwKey* RwNew(void); - void RwFree(TRwKey* r); - int RwSize(const TRwKey* rw); - int RwModSize(const TRwKey* rw); - - TRwKey* RwPublicKeyDup(TRwKey* rw); - TRwKey* RwPrivateKeyDup(TRwKey* rw); - - // NOLINTNEXTLINE(readability-identifier-naming) - TRwKey* d2i_RWPublicKey(TRwKey** a, const unsigned char** pp, long length); - // NOLINTNEXTLINE(readability-identifier-naming) - TRwKey* d2i_RWPrivateKey(TRwKey** a, const unsigned char** pp, long length); - - int RwGenerateKey(TRwKey* a, int bits); - // NOLINTNEXTLINE(readability-identifier-naming) - int i2d_RWPublicKey(const TRwKey* a, unsigned char** pp); - // NOLINTNEXTLINE(readability-identifier-naming) - int i2d_RWPrivateKey(const TRwKey* a, unsigned char** pp); - - int RwPaddingAddPssr(const TRwKey* rw, unsigned char* EM, const unsigned char* mHash, const EVP_MD* Hash, int sLen); - int RwVerifyPssr(const TRwKey* rw, const unsigned char* mHash, const EVP_MD* Hash, const unsigned char* EM, int sLen); + typedef struct { + BIGNUM* S; + } TRwSignature; + + /*Rabin–Williams*/ + typedef struct TRwInternal TRwKey; + + typedef struct { + TRwSignature* (*RwSign)(const unsigned char* dgst, const int dlen, TRwKey* rw); + int (*RwVerify)(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw); + int (*RwApply)(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw); + } TRwMethod; + + struct TRwInternal { + /* first private multiplier */ + BIGNUM* P; + /* second private multiplier */ + BIGNUM* Q; + /* n = p*q - RW modulus */ + BIGNUM* N; + /* precomputed 2^((3q-5)/8) mod q */ + BIGNUM* Twomq; + /* precomputed 2^((9p-11)/8) mod p*/ + BIGNUM* Twomp; + /* precomputed q^(p-2) == q^(-1) mod p */ + BIGNUM* Iqmp; + /* (q+1) / 8 */ + BIGNUM* Dq; + /* (p-3) / 8 */ + BIGNUM* Dp; + /* functions for working with RW */ + const TRwMethod* Meth; + }; + + TRwSignature* RwSignatureNew(void); + void RwSignatureFree(TRwSignature* a); + + /* RW signing functions */ + /* the function can put some tmp values to rw */ + int RwPssrSignHash(const unsigned char* from, unsigned char* to, TRwKey* rw, const EVP_MD* md); + int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, TRwKey* rw, const EVP_MD* md); + + /* RW-PSS verification functions */ + int RwPssrVerifyHash(const unsigned char* from, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md); + int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md); + + /* internal functions, use them only if you know what you're doing */ + int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwKey* rw); + int RwApply(const int flen, const unsigned char* from, unsigned char* to, const TRwKey* rw); + + const TRwMethod* RwDefaultMethods(void); + + TRwKey* RwNew(void); + void RwFree(TRwKey* r); + int RwSize(const TRwKey* rw); + int RwModSize(const TRwKey* rw); + + TRwKey* RwPublicKeyDup(TRwKey* rw); + TRwKey* RwPrivateKeyDup(TRwKey* rw); + + // NOLINTNEXTLINE(readability-identifier-naming) + TRwKey* d2i_RWPublicKey(TRwKey** a, const unsigned char** pp, long length); + // NOLINTNEXTLINE(readability-identifier-naming) + TRwKey* d2i_RWPrivateKey(TRwKey** a, const unsigned char** pp, long length); + + int RwGenerateKey(TRwKey* a, int bits); + // NOLINTNEXTLINE(readability-identifier-naming) + int i2d_RWPublicKey(const TRwKey* a, unsigned char** pp); + // NOLINTNEXTLINE(readability-identifier-naming) + int i2d_RWPrivateKey(const TRwKey* a, unsigned char** pp); + + int RwPaddingAddPssr(const TRwKey* rw, unsigned char* EM, const unsigned char* mHash, const EVP_MD* Hash, int sLen); + int RwVerifyPssr(const TRwKey* rw, const unsigned char* mHash, const EVP_MD* Hash, const unsigned char* EM, int sLen); #ifdef __cplusplus } diff --git a/library/cpp/tvmauth/src/rw/rw_asn1.c b/library/cpp/tvmauth/src/rw/rw_asn1.c index 0eb7134fdb..76682dcff4 100644 --- a/library/cpp/tvmauth/src/rw/rw_asn1.c +++ b/library/cpp/tvmauth/src/rw/rw_asn1.c @@ -8,16 +8,16 @@ /* Override the default new methods */ /* This callback is used by OpenSSL's ASN.1 parser */ -static int SignatureCallback(int operation, ASN1_VALUE** pval, const ASN1_ITEM* it, void* exarg) { +static int SignatureCallback(int operation, ASN1_VALUE** pval, const ASN1_ITEM* it, void* exarg) { (void)it; (void)exarg; if (operation == ASN1_OP_NEW_PRE) { - TRwSignature* sig; - sig = OPENSSL_malloc(sizeof(TRwSignature)); + TRwSignature* sig; + sig = OPENSSL_malloc(sizeof(TRwSignature)); if (!sig) return 0; - sig->S = NULL; + sig->S = NULL; *pval = (ASN1_VALUE*)sig; return 2; } @@ -25,25 +25,25 @@ static int SignatureCallback(int operation, ASN1_VALUE** pval, const ASN1_ITEM* } /* ASN.1 structure representing RW signature value */ -ASN1_SEQUENCE_cb(TRwSignature, SignatureCallback) = { - ASN1_SIMPLE(TRwSignature, S, BIGNUM), -} ASN1_SEQUENCE_END_cb(TRwSignature, TRwSignature) +ASN1_SEQUENCE_cb(TRwSignature, SignatureCallback) = { + ASN1_SIMPLE(TRwSignature, S, BIGNUM), +} ASN1_SEQUENCE_END_cb(TRwSignature, TRwSignature) - /* i2d_ and d2i functions implementation for RW */ - IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwSignature, TRwSignature, TRwSignature) + /* i2d_ and d2i functions implementation for RW */ + IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwSignature, TRwSignature, TRwSignature) /* Override the default free and new methods */ - static int RwCallback(int operation, ASN1_VALUE** pval, const ASN1_ITEM* it, void* exarg) { + static int RwCallback(int operation, ASN1_VALUE** pval, const ASN1_ITEM* it, void* exarg) { (void)it; (void)exarg; if (operation == ASN1_OP_NEW_PRE) { - *pval = (ASN1_VALUE*)RwNew(); + *pval = (ASN1_VALUE*)RwNew(); if (*pval) return 2; return 0; } else if (operation == ASN1_OP_FREE_PRE) { - RwFree((TRwKey*)*pval); + RwFree((TRwKey*)*pval); *pval = NULL; return 2; } @@ -51,31 +51,31 @@ ASN1_SEQUENCE_cb(TRwSignature, SignatureCallback) = { } /* ASN.1 representation of RW's private key */ -ASN1_SEQUENCE_cb(RWPrivateKey, RwCallback) = { - ASN1_SIMPLE(TRwKey, N, BIGNUM), - ASN1_SIMPLE(TRwKey, P, CBIGNUM), - ASN1_SIMPLE(TRwKey, Q, CBIGNUM), - ASN1_SIMPLE(TRwKey, Iqmp, CBIGNUM), - ASN1_SIMPLE(TRwKey, Dq, CBIGNUM), - ASN1_SIMPLE(TRwKey, Dp, CBIGNUM), - ASN1_SIMPLE(TRwKey, Twomp, CBIGNUM), - ASN1_SIMPLE(TRwKey, Twomq, CBIGNUM)} ASN1_SEQUENCE_END_cb(TRwKey, RWPrivateKey); +ASN1_SEQUENCE_cb(RWPrivateKey, RwCallback) = { + ASN1_SIMPLE(TRwKey, N, BIGNUM), + ASN1_SIMPLE(TRwKey, P, CBIGNUM), + ASN1_SIMPLE(TRwKey, Q, CBIGNUM), + ASN1_SIMPLE(TRwKey, Iqmp, CBIGNUM), + ASN1_SIMPLE(TRwKey, Dq, CBIGNUM), + ASN1_SIMPLE(TRwKey, Dp, CBIGNUM), + ASN1_SIMPLE(TRwKey, Twomp, CBIGNUM), + ASN1_SIMPLE(TRwKey, Twomq, CBIGNUM)} ASN1_SEQUENCE_END_cb(TRwKey, RWPrivateKey); -/* i2d_ and d2i_ functions for RW's private key */ -IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwKey, RWPrivateKey, RWPrivateKey); +/* i2d_ and d2i_ functions for RW's private key */ +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwKey, RWPrivateKey, RWPrivateKey); -/* ASN.1 representation of RW public key */ -ASN1_SEQUENCE_cb(RWPublicKey, RwCallback) = { - ASN1_SIMPLE(TRwKey, N, BIGNUM), -} ASN1_SEQUENCE_END_cb(TRwKey, RWPublicKey); +/* ASN.1 representation of RW public key */ +ASN1_SEQUENCE_cb(RWPublicKey, RwCallback) = { + ASN1_SIMPLE(TRwKey, N, BIGNUM), +} ASN1_SEQUENCE_END_cb(TRwKey, RWPublicKey); -/* i2d_ and d2i functions for RW public key */ -IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwKey, RWPublicKey, RWPublicKey); +/* i2d_ and d2i functions for RW public key */ +IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(TRwKey, RWPublicKey, RWPublicKey); -TRwKey* RwPublicKeyDup(TRwKey* rw) { +TRwKey* RwPublicKeyDup(TRwKey* rw) { return ASN1_item_dup(ASN1_ITEM_rptr(RWPublicKey), rw); } -TRwKey* RwPrivateKeyDup(TRwKey* rw) { +TRwKey* RwPrivateKeyDup(TRwKey* rw) { return ASN1_item_dup(ASN1_ITEM_rptr(RWPrivateKey), rw); } diff --git a/library/cpp/tvmauth/src/rw/rw_key.c b/library/cpp/tvmauth/src/rw/rw_key.c index 35a7b60112..8375c3ca20 100644 --- a/library/cpp/tvmauth/src/rw/rw_key.c +++ b/library/cpp/tvmauth/src/rw/rw_key.c @@ -2,7 +2,7 @@ #include <contrib/libs/openssl/include/openssl/rand.h> -int RwGenerateKey(TRwKey* rw, int bits) { +int RwGenerateKey(TRwKey* rw, int bits) { int ok = 0; BN_CTX* ctx = NULL; @@ -13,25 +13,25 @@ int RwGenerateKey(TRwKey* rw, int bits) { int bitsq = bits - bitsp; /* make sure that all components are not null */ - if ((ctx = BN_CTX_secure_new()) == NULL) + if ((ctx = BN_CTX_secure_new()) == NULL) goto err; if (!rw) goto err; - if (!rw->N && ((rw->N = BN_new()) == NULL)) + if (!rw->N && ((rw->N = BN_new()) == NULL)) goto err; - if (!rw->P && ((rw->P = BN_new()) == NULL)) + if (!rw->P && ((rw->P = BN_new()) == NULL)) goto err; - if (!rw->Q && ((rw->Q = BN_new()) == NULL)) + if (!rw->Q && ((rw->Q = BN_new()) == NULL)) goto err; - if (!rw->Iqmp && ((rw->Iqmp = BN_new()) == NULL)) + if (!rw->Iqmp && ((rw->Iqmp = BN_new()) == NULL)) goto err; - if (!rw->Twomq && ((rw->Twomq = BN_new()) == NULL)) + if (!rw->Twomq && ((rw->Twomq = BN_new()) == NULL)) goto err; - if (!rw->Twomp && ((rw->Twomp = BN_new()) == NULL)) + if (!rw->Twomp && ((rw->Twomp = BN_new()) == NULL)) goto err; - if (!rw->Dq && ((rw->Dq = BN_new()) == NULL)) + if (!rw->Dq && ((rw->Dq = BN_new()) == NULL)) goto err; - if (!rw->Dp && ((rw->Dp = BN_new()) == NULL)) + if (!rw->Dp && ((rw->Dp = BN_new()) == NULL)) goto err; BN_CTX_start(ctx); @@ -60,32 +60,32 @@ int RwGenerateKey(TRwKey* rw, int bits) { /* add == 8 */ /* rem == 3 */ /* safe == 0 as we don't need (p-1)/2 to be also prime */ - if (!BN_generate_prime_ex(rw->P, bitsp, 0, mod8, rem3, NULL)) + if (!BN_generate_prime_ex(rw->P, bitsp, 0, mod8, rem3, NULL)) goto err; /* generate q */ /* add == 8 */ /* rem == 7 */ /* safe == 0 */ - if (!BN_generate_prime_ex(rw->Q, bitsq, 0, mod8, rem7, NULL)) + if (!BN_generate_prime_ex(rw->Q, bitsq, 0, mod8, rem7, NULL)) goto err; /* n == p*q */ - if (!BN_mul(rw->N, rw->P, rw->Q, ctx)) + if (!BN_mul(rw->N, rw->P, rw->Q, ctx)) goto err; /* n == 5 mod 8 ? */ - if (!BN_nnmod(nmod, rw->N, mod8, ctx)) + if (!BN_nnmod(nmod, rw->N, mod8, ctx)) goto err; if (BN_ucmp(rem5, nmod) != 0) goto err; /* q^(-1) mod p */ - if (!BN_mod_inverse(rw->Iqmp, rw->Q, rw->P, ctx)) + if (!BN_mod_inverse(rw->Iqmp, rw->Q, rw->P, ctx)) goto err; /* twomqexp = (3q-5)/8 */ - if (!BN_copy(twomqexp, rw->Q)) + if (!BN_copy(twomqexp, rw->Q)) goto err; if (!BN_mul_word(twomqexp, 3)) goto err; @@ -93,11 +93,11 @@ int RwGenerateKey(TRwKey* rw, int bits) { goto err; if (!BN_rshift(twomqexp, twomqexp, 3)) goto err; - if (!BN_mod_exp(rw->Twomq, two, twomqexp, rw->Q, ctx)) + if (!BN_mod_exp(rw->Twomq, two, twomqexp, rw->Q, ctx)) goto err; /* twompexp = (9p-11)/8 */ - if (!BN_copy(twompexp, rw->P)) + if (!BN_copy(twompexp, rw->P)) goto err; if (!BN_mul_word(twompexp, 9)) goto err; @@ -105,23 +105,23 @@ int RwGenerateKey(TRwKey* rw, int bits) { goto err; if (!BN_rshift(twompexp, twompexp, 3)) goto err; - if (!BN_mod_exp(rw->Twomp, two, twompexp, rw->P, ctx)) + if (!BN_mod_exp(rw->Twomp, two, twompexp, rw->P, ctx)) goto err; /* dp = (p-3) / 8 */ - if (!BN_copy(rw->Dp, rw->P)) + if (!BN_copy(rw->Dp, rw->P)) goto err; - if (!BN_sub_word(rw->Dp, 3)) + if (!BN_sub_word(rw->Dp, 3)) goto err; - if (!BN_rshift(rw->Dp, rw->Dp, 3)) + if (!BN_rshift(rw->Dp, rw->Dp, 3)) goto err; /* dq = (q+1) / 8 */ - if (!BN_copy(rw->Dq, rw->Q)) + if (!BN_copy(rw->Dq, rw->Q)) goto err; - if (!BN_add_word(rw->Dq, 1)) + if (!BN_add_word(rw->Dq, 1)) goto err; - if (!BN_rshift(rw->Dq, rw->Dq, 3)) + if (!BN_rshift(rw->Dq, rw->Dq, 3)) goto err; ok = 1; diff --git a/library/cpp/tvmauth/src/rw/rw_lib.c b/library/cpp/tvmauth/src/rw/rw_lib.c index d4b1e06766..94d94caa4a 100644 --- a/library/cpp/tvmauth/src/rw/rw_lib.c +++ b/library/cpp/tvmauth/src/rw/rw_lib.c @@ -4,52 +4,52 @@ #include <stdio.h> -TRwKey* RwNew(void) { - TRwKey* ret = NULL; +TRwKey* RwNew(void) { + TRwKey* ret = NULL; - ret = (TRwKey*)malloc(sizeof(TRwKey)); + ret = (TRwKey*)malloc(sizeof(TRwKey)); if (ret == NULL) { return (NULL); } - ret->Meth = RwDefaultMethods(); + ret->Meth = RwDefaultMethods(); - ret->P = NULL; - ret->Q = NULL; - ret->N = NULL; - ret->Iqmp = NULL; - ret->Twomq = NULL; - ret->Twomp = NULL; - ret->Dp = NULL; - ret->Dq = NULL; + ret->P = NULL; + ret->Q = NULL; + ret->N = NULL; + ret->Iqmp = NULL; + ret->Twomq = NULL; + ret->Twomp = NULL; + ret->Dp = NULL; + ret->Dq = NULL; return ret; } -void RwFree(TRwKey* r) { +void RwFree(TRwKey* r) { if (r == NULL) return; - if (r->P != NULL) - BN_clear_free(r->P); - if (r->Q != NULL) - BN_clear_free(r->Q); - if (r->N != NULL) - BN_clear_free(r->N); - if (r->Iqmp != NULL) - BN_clear_free(r->Iqmp); - if (r->Dp != NULL) - BN_clear_free(r->Dp); - if (r->Dq != NULL) - BN_clear_free(r->Dq); - if (r->Twomp != NULL) - BN_clear_free(r->Twomp); - if (r->Twomq != NULL) - BN_clear_free(r->Twomq); + if (r->P != NULL) + BN_clear_free(r->P); + if (r->Q != NULL) + BN_clear_free(r->Q); + if (r->N != NULL) + BN_clear_free(r->N); + if (r->Iqmp != NULL) + BN_clear_free(r->Iqmp); + if (r->Dp != NULL) + BN_clear_free(r->Dp); + if (r->Dq != NULL) + BN_clear_free(r->Dq); + if (r->Twomp != NULL) + BN_clear_free(r->Twomp); + if (r->Twomq != NULL) + BN_clear_free(r->Twomq); - free(r); + free(r); } -int RwSize(const TRwKey* r) { +int RwSize(const TRwKey* r) { int ret = 0, i = 0; ASN1_INTEGER bs; unsigned char buf[4]; /* 4 bytes looks really small. @@ -57,7 +57,7 @@ int RwSize(const TRwKey* r) { beyond the first byte, as long as the second parameter is NULL. */ - i = BN_num_bits(r->N); + i = BN_num_bits(r->N); bs.length = (i + 7) / 8; bs.data = buf; bs.type = V_ASN1_INTEGER; @@ -70,8 +70,8 @@ int RwSize(const TRwKey* r) { return ret; } -int RwModSize(const TRwKey* rw) { - if (rw == NULL || rw->N == NULL) +int RwModSize(const TRwKey* rw) { + if (rw == NULL || rw->N == NULL) return 0; - return BN_num_bytes(rw->N); + return BN_num_bytes(rw->N); } diff --git a/library/cpp/tvmauth/src/rw/rw_ossl.c b/library/cpp/tvmauth/src/rw/rw_ossl.c index cfac5eb28a..951752bdb3 100644 --- a/library/cpp/tvmauth/src/rw/rw_ossl.c +++ b/library/cpp/tvmauth/src/rw/rw_ossl.c @@ -7,19 +7,19 @@ //#define FAULT_TOLERANCE_CHECK #ifdef RW_PRINT_DEBUG - #include <stdio.h> + #include <stdio.h> #endif -static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw); -static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw); -static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw); +static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw); +static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw); +static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw); -static TRwMethod rw_default_meth = { - RwDoSign, - RwDoVerify, - RwDoApply}; +static TRwMethod rw_default_meth = { + RwDoSign, + RwDoVerify, + RwDoApply}; -const TRwMethod* RwDefaultMethods(void) { +const TRwMethod* RwDefaultMethods(void) { return &rw_default_meth; } @@ -33,29 +33,29 @@ static void print_bn(char* name, BIGNUM* value) { OPENSSL_free(str_repr); } - #define DEBUG_PRINT_BN(s, x) \ - do { \ - print_bn((s), (x)); \ - } while (0); - #define DEBUG_PRINT_RW(r) \ - do { \ - DEBUG_PRINT_BN("rw->p", (r)->p); \ - DEBUG_PRINT_BN("rw->q", (r)->q); \ - DEBUG_PRINT_BN("rw->n", (r)->n); \ - DEBUG_PRINT_BN("rw->iqmp", (r)->iqmp); \ - DEBUG_PRINT_BN("rw->twomp", (r)->twomp); \ - DEBUG_PRINT_BN("rw->twomq", (r)->twomq); \ - DEBUG_PRINT_BN("rw->dp", (r)->dp); \ - DEBUG_PRINT_BN("rw->dq", (r)->dq); \ - } while (0); - #define DEBUG_PRINTF(s, v) \ - do { \ - printf((s), (v)); \ - } while (0); + #define DEBUG_PRINT_BN(s, x) \ + do { \ + print_bn((s), (x)); \ + } while (0); + #define DEBUG_PRINT_RW(r) \ + do { \ + DEBUG_PRINT_BN("rw->p", (r)->p); \ + DEBUG_PRINT_BN("rw->q", (r)->q); \ + DEBUG_PRINT_BN("rw->n", (r)->n); \ + DEBUG_PRINT_BN("rw->iqmp", (r)->iqmp); \ + DEBUG_PRINT_BN("rw->twomp", (r)->twomp); \ + DEBUG_PRINT_BN("rw->twomq", (r)->twomq); \ + DEBUG_PRINT_BN("rw->dp", (r)->dp); \ + DEBUG_PRINT_BN("rw->dq", (r)->dq); \ + } while (0); + #define DEBUG_PRINTF(s, v) \ + do { \ + printf((s), (v)); \ + } while (0); #else - #define DEBUG_PRINT_BN(s, x) - #define DEBUG_PRINT_RW(r) - #define DEBUG_PRINTF(s, v) + #define DEBUG_PRINT_BN(s, x) + #define DEBUG_PRINT_RW(r) + #define DEBUG_PRINTF(s, v) #endif /* @@ -73,18 +73,18 @@ static void print_bn(char* name, BIGNUM* value) { * 8. Compute s = Y^2 mod pq * 9. Fault tolerance: if efs^2 mod pq != h start over */ -static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { +static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { BIGNUM *m, *U, *V, *tmp, *m_q, *m_p, *tmp2; /* additional variables to avoid "if" statements */ BIGNUM *tmp_mp, *tmp_U, *tmp_V; - TRwSignature* ret = NULL; + TRwSignature* ret = NULL; BN_CTX* ctx = NULL; int ok = 0, e = 0, f = 0; - if (!rw || !rw->P || !rw->Q || !rw->N || !rw->Iqmp || !rw->Dp || !rw->Dq || !rw->Twomp || !rw->Twomq) + if (!rw || !rw->P || !rw->Q || !rw->N || !rw->Iqmp || !rw->Dp || !rw->Dq || !rw->Twomp || !rw->Twomq) goto err; - if ((ctx = BN_CTX_secure_new()) == NULL) + if ((ctx = BN_CTX_secure_new()) == NULL) goto err; BN_CTX_start(ctx); @@ -105,40 +105,40 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { if (!BN_bin2bn(dgst, dlen, m)) goto err; - if (BN_ucmp(m, rw->N) >= 0) + if (BN_ucmp(m, rw->N) >= 0) goto err; /* check if m % 16 == 12 */ - if (BN_mod_word(m, 16) != 12) + if (BN_mod_word(m, 16) != 12) goto err; DEBUG_PRINT_BN("m", m) /* TODO: optimization to avoid memory allocation? */ - if ((ret = RwSignatureNew()) == NULL) + if ((ret = RwSignatureNew()) == NULL) goto err; /* memory allocation */ - if ((ret->S = BN_new()) == NULL) + if ((ret->S = BN_new()) == NULL) goto err; /* m_q = m mod q */ - if (!BN_nnmod(m_q, m, rw->Q, ctx)) + if (!BN_nnmod(m_q, m, rw->Q, ctx)) goto err; /* m_p = m mod p */ - if (!BN_nnmod(m_p, m, rw->P, ctx)) + if (!BN_nnmod(m_p, m, rw->P, ctx)) goto err; DEBUG_PRINT_BN("m_p", m_p) DEBUG_PRINT_BN("m_q", m_q) /* U = h ** ((q+1)/8) mod q */ - if (!BN_mod_exp(U, m_q, rw->Dq, rw->Q, ctx)) + if (!BN_mod_exp(U, m_q, rw->Dq, rw->Q, ctx)) goto err; DEBUG_PRINT_BN("U", U) /* tmp = U^4 - h mod q */ - if (!BN_mod_sqr(tmp, U, rw->Q, ctx)) + if (!BN_mod_sqr(tmp, U, rw->Q, ctx)) goto err; - if (!BN_mod_sqr(tmp, tmp, rw->Q, ctx)) + if (!BN_mod_sqr(tmp, tmp, rw->Q, ctx)) goto err; DEBUG_PRINT_BN("U**4 mod q", tmp) @@ -151,35 +151,35 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { if e == -1: m_p = tmp_mp if e == 1: m_p = m_p */ - if (!BN_sub(tmp_mp, rw->P, m_p)) + if (!BN_sub(tmp_mp, rw->P, m_p)) goto err; m_p = (BIGNUM*)((1 - ((1 + e) >> 1)) * (BN_ULONG)tmp_mp + ((1 + e) >> 1) * (BN_ULONG)m_p); DEBUG_PRINT_BN("eh mod p", m_p) /* V = (eh) ** ((p-3)/8) */ - if (!BN_mod_exp(V, m_p, rw->Dp, rw->P, ctx)) + if (!BN_mod_exp(V, m_p, rw->Dp, rw->P, ctx)) goto err; DEBUG_PRINT_BN("V == ((eh) ** ((p-3)/8))", V) /* (eh) ** 2 */ - if (!BN_mod_sqr(tmp2, m_p, rw->P, ctx)) + if (!BN_mod_sqr(tmp2, m_p, rw->P, ctx)) goto err; DEBUG_PRINT_BN("(eh)**2", tmp2) /* V ** 4 */ - if (!BN_mod_sqr(tmp, V, rw->P, ctx)) + if (!BN_mod_sqr(tmp, V, rw->P, ctx)) goto err; - if (!BN_mod_sqr(tmp, tmp, rw->P, ctx)) + if (!BN_mod_sqr(tmp, tmp, rw->P, ctx)) goto err; DEBUG_PRINT_BN("V**4", tmp) /* V**4 * (eh)**2 */ - if (!BN_mod_mul(tmp, tmp, tmp2, rw->P, ctx)) + if (!BN_mod_mul(tmp, tmp, tmp2, rw->P, ctx)) goto err; DEBUG_PRINT_BN("tmp = (V**4 * (eh)**2) mod p", tmp) /* tmp = tmp - eh mod p */ - if (!BN_mod_sub(tmp, tmp, m_p, rw->P, ctx)) + if (!BN_mod_sub(tmp, tmp, m_p, rw->P, ctx)) goto err; /* f = 1 if zero else 2 */ @@ -198,7 +198,7 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { #else if (f == 2) { - if (!BN_mod_mul(U, U, rw->Twomq, rw->Q, ctx)) + if (!BN_mod_mul(U, U, rw->Twomq, rw->Q, ctx)) goto err; } @@ -207,14 +207,14 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { DEBUG_PRINT_BN("W", U) /* V ** 3 */ - if (!BN_mod_sqr(tmp, V, rw->P, ctx)) + if (!BN_mod_sqr(tmp, V, rw->P, ctx)) goto err; - if (!BN_mod_mul(V, V, tmp, rw->P, ctx)) + if (!BN_mod_mul(V, V, tmp, rw->P, ctx)) goto err; DEBUG_PRINT_BN("V**3", V) /* *(eh) */ - if (!BN_mod_mul(V, V, m_p, rw->P, ctx)) + if (!BN_mod_mul(V, V, m_p, rw->P, ctx)) goto err; DEBUG_PRINT_BN("V**3 * (eh) mod p", V) @@ -228,7 +228,7 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { #else if (f == 2) { - if (!BN_mod_mul(V, V, rw->Twomp, rw->P, ctx)) + if (!BN_mod_mul(V, V, rw->Twomp, rw->P, ctx)) goto err; } @@ -237,24 +237,24 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { DEBUG_PRINT_BN("X", V) /* W = U, X = V */ - if (!BN_mod_sub(V, V, U, rw->P, ctx)) + if (!BN_mod_sub(V, V, U, rw->P, ctx)) goto err; DEBUG_PRINT_BN("X - W mod p", V) - if (!BN_mod_mul(V, V, rw->Iqmp, rw->P, ctx)) + if (!BN_mod_mul(V, V, rw->Iqmp, rw->P, ctx)) goto err; DEBUG_PRINT_BN("q**(p-2) * (X-W) mod p", V) - if (!BN_mul(V, V, rw->Q, ctx)) + if (!BN_mul(V, V, rw->Q, ctx)) goto err; DEBUG_PRINT_BN("q * prev mod p", V) - if (!BN_mod_add(V, U, V, rw->N, ctx)) + if (!BN_mod_add(V, U, V, rw->N, ctx)) goto err; DEBUG_PRINT_BN("Y", V) /* now V = Y */ - if (!BN_mod_sqr(V, V, rw->N, ctx)) + if (!BN_mod_sqr(V, V, rw->N, ctx)) goto err; DEBUG_PRINT_BN("s", V) @@ -287,13 +287,13 @@ static TRwSignature* RwDoSign(const unsigned char* dgst, int dlen, TRwKey* rw) { #endif /* making the "principal square root" to be "|principal| square root" */ - if (!BN_sub(tmp, rw->N, V)) + if (!BN_sub(tmp, rw->N, V)) goto err; /* if tmp = MIN(V, rw->n - V) */ tmp = BN_ucmp(tmp, V) >= 0 ? V : tmp; - if (!BN_copy(ret->S, tmp)) + if (!BN_copy(ret->S, tmp)) goto err; ok = 1; @@ -304,23 +304,23 @@ err: BN_CTX_free(ctx); } if (!ok) { - RwSignatureFree(ret); + RwSignatureFree(ret); ret = NULL; } return ret; } -static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw) { +static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig, const TRwKey* rw) { BIGNUM *m = NULL, *x = NULL, *t1 = NULL, *t2 = NULL, *t1d = NULL, *t2d = NULL; BN_CTX* ctx = NULL; BN_ULONG rest1 = 0, rest2 = 0; int retval = 0; - if (!rw || !rw->N || !sig || !sig->S) + if (!rw || !rw->N || !sig || !sig->S) goto err; - if ((ctx = BN_CTX_secure_new()) == NULL) + if ((ctx = BN_CTX_secure_new()) == NULL) goto err; BN_CTX_start(ctx); @@ -333,7 +333,7 @@ static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig if (!BN_bin2bn(dgst, dgst_len, m)) goto err; /* dgst too big */ - if (!BN_copy(t1, rw->N)) + if (!BN_copy(t1, rw->N)) goto err; if (!BN_sub_word(t1, 1)) goto err; @@ -341,28 +341,28 @@ static int RwDoVerify(const unsigned char* dgst, int dgst_len, TRwSignature* sig goto err; /* check m and rw->n relation */ - if (BN_ucmp(m, rw->N) >= 0) + if (BN_ucmp(m, rw->N) >= 0) goto err; rest1 = BN_mod_word(m, 16); if (rest1 != 12) goto err; - if (BN_ucmp(t1, sig->S) < 0) + if (BN_ucmp(t1, sig->S) < 0) goto err; - if (BN_is_negative(sig->S)) + if (BN_is_negative(sig->S)) goto err; - if (!BN_mod_sqr(t1, sig->S, rw->N, ctx)) + if (!BN_mod_sqr(t1, sig->S, rw->N, ctx)) goto err; - if (!BN_sub(t2, rw->N, t1)) + if (!BN_sub(t2, rw->N, t1)) goto err; if (!BN_lshift1(t1d, t1)) goto err; if (!BN_lshift1(t2d, t2)) goto err; - rest1 = BN_mod_word(t1, 16); - rest2 = BN_mod_word(t2, 16); + rest1 = BN_mod_word(t1, 16); + rest2 = BN_mod_word(t2, 16); /* mod 16 */ if (rest1 == 12) { @@ -396,12 +396,12 @@ err: return retval; } -static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { +static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { BIGNUM *t1 = NULL, *t2 = NULL, *t1d = NULL, *t2d = NULL, *rs = NULL; BN_ULONG rest1 = 0, rest2 = 0; int retval = 0; - if (!rw || !rw->N || !x || !ctx || !r) + if (!rw || !rw->N || !x || !ctx || !r) goto err; DEBUG_PRINT_BN("Signature = x = ", x) @@ -414,7 +414,7 @@ static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { t1d = BN_CTX_get(ctx); t2d = BN_CTX_get(ctx); - if (!BN_copy(t1, rw->N)) + if (!BN_copy(t1, rw->N)) goto err; if (!BN_sub_word(t1, 1)) goto err; @@ -422,7 +422,7 @@ static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { goto err; /* check m and rw->n relation */ - if (BN_ucmp(x, rw->N) >= 0) + if (BN_ucmp(x, rw->N) >= 0) goto err; if (BN_ucmp(t1, x) < 0) @@ -430,11 +430,11 @@ static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { if (BN_is_negative(x)) goto err; - if (!BN_mod_sqr(t1, x, rw->N, ctx)) + if (!BN_mod_sqr(t1, x, rw->N, ctx)) goto err; DEBUG_PRINT_BN("x**2 mod n", t1) - if (!BN_sub(t2, rw->N, t1)) + if (!BN_sub(t2, rw->N, t1)) goto err; DEBUG_PRINT_BN("n - x**2", t2) @@ -443,8 +443,8 @@ static int RwDoApply(BIGNUM* r, BIGNUM* x, BN_CTX* ctx, const TRwKey* rw) { if (!BN_lshift1(t2d, t2)) goto err; - rest1 = BN_mod_word(t1, 16); - rest2 = BN_mod_word(t2, 16); + rest1 = BN_mod_word(t1, 16); + rest2 = BN_mod_word(t2, 16); /* mod 16 */ if (rest1 == 12) { diff --git a/library/cpp/tvmauth/src/rw/rw_pss.c b/library/cpp/tvmauth/src/rw/rw_pss.c index 4535cd236c..3bf6e2b99a 100644 --- a/library/cpp/tvmauth/src/rw/rw_pss.c +++ b/library/cpp/tvmauth/src/rw/rw_pss.c @@ -72,21 +72,21 @@ static const unsigned char zeroes[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; -static int PkcS1MgF1(unsigned char *mask, const int len, const unsigned char *seed, const int seedlen, const EVP_MD *dgst) { - int i, outlen = 0; +static int PkcS1MgF1(unsigned char *mask, const int len, const unsigned char *seed, const int seedlen, const EVP_MD *dgst) { + int i, outlen = 0; unsigned char cnt[4]; - EVP_MD_CTX* c = EVP_MD_CTX_create(); + EVP_MD_CTX* c = EVP_MD_CTX_create(); unsigned char md[EVP_MAX_MD_SIZE]; int mdlen; int rv = -1; - if (!c) { - return rv; - } - + if (!c) { + return rv; + } + mdlen = EVP_MD_size(dgst); - if (mdlen < 0 || seedlen < 0) + if (mdlen < 0 || seedlen < 0) goto err; for (i = 0; outlen < len; i++) { @@ -95,15 +95,15 @@ static int PkcS1MgF1(unsigned char *mask, const int len, const unsigned char *se cnt[2] = (unsigned char)((i >> 8)) & 255; cnt[3] = (unsigned char)(i & 255); - if (!EVP_DigestInit_ex(c,dgst, NULL) || !EVP_DigestUpdate(c, seed, seedlen) || !EVP_DigestUpdate(c, cnt, 4)) + if (!EVP_DigestInit_ex(c,dgst, NULL) || !EVP_DigestUpdate(c, seed, seedlen) || !EVP_DigestUpdate(c, cnt, 4)) goto err; if (outlen + mdlen <= len) { - if (!EVP_DigestFinal_ex(c, mask + outlen, NULL)) + if (!EVP_DigestFinal_ex(c, mask + outlen, NULL)) goto err; outlen += mdlen; } else { - if (!EVP_DigestFinal_ex(c, md, NULL)) + if (!EVP_DigestFinal_ex(c, md, NULL)) goto err; memcpy(mask + outlen, md, len - outlen); outlen = len; @@ -112,22 +112,22 @@ static int PkcS1MgF1(unsigned char *mask, const int len, const unsigned char *se rv = 0; err: - EVP_MD_CTX_destroy(c); + EVP_MD_CTX_destroy(c); return rv; } -int RwVerifyPssr(const TRwKey *rw, const unsigned char *mHash, const EVP_MD *Hash, const unsigned char *EM, int sLen) { +int RwVerifyPssr(const TRwKey *rw, const unsigned char *mHash, const EVP_MD *Hash, const unsigned char *EM, int sLen) { int i = 0, ret = 0, hLen = 0, maskedDBLen = 0, MSBits = 0, emLen = 0; const unsigned char *H = NULL; unsigned char *DB = NULL; - EVP_MD_CTX* ctx = NULL; + EVP_MD_CTX* ctx = NULL; unsigned char H_[EVP_MAX_MD_SIZE]; const EVP_MD *mgf1Hash = Hash; - ctx = EVP_MD_CTX_create(); - if (!ctx) { - return ret; - } + ctx = EVP_MD_CTX_create(); + if (!ctx) { + return ret; + } hLen = EVP_MD_size(Hash); if (hLen < 0) @@ -143,14 +143,14 @@ int RwVerifyPssr(const TRwKey *rw, const unsigned char *mHash, const EVP_MD *Has else if (sLen < -2) goto err; - { - int bits = BN_num_bits(rw->N); - if (bits <= 0) - goto err; - - MSBits = (bits - 1) & 0x7; - } - emLen = RwModSize(rw); + { + int bits = BN_num_bits(rw->N); + if (bits <= 0) + goto err; + + MSBits = (bits - 1) & 0x7; + } + emLen = RwModSize(rw); if (EM[0] & (0xFF << MSBits)) { goto err; @@ -164,23 +164,23 @@ int RwVerifyPssr(const TRwKey *rw, const unsigned char *mHash, const EVP_MD *Has if (emLen < (hLen + sLen + 2)) /* sLen can be small negative */ goto err; - if (emLen < 1) - goto err; - + if (emLen < 1) + goto err; + if (EM[emLen - 1] != 0xbc) goto err; maskedDBLen = emLen - hLen - 1; - if (maskedDBLen <= 0) - goto err; - + if (maskedDBLen <= 0) + goto err; + H = EM + maskedDBLen; - DB = malloc(maskedDBLen); + DB = malloc(maskedDBLen); if (!DB) goto err; - if (PkcS1MgF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0) + if (PkcS1MgF1(DB, maskedDBLen, H, hLen, mgf1Hash) < 0) goto err; for (i = 0; i < maskedDBLen; i++) @@ -197,24 +197,24 @@ int RwVerifyPssr(const TRwKey *rw, const unsigned char *mHash, const EVP_MD *Has if (sLen >= 0 && (maskedDBLen - i) != sLen) goto err; - if (!EVP_DigestInit_ex(ctx, Hash, NULL) || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) || !EVP_DigestUpdate(ctx, mHash, hLen)) + if (!EVP_DigestInit_ex(ctx, Hash, NULL) || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) || !EVP_DigestUpdate(ctx, mHash, hLen)) goto err; if (maskedDBLen - i) { - if (!EVP_DigestUpdate(ctx, DB + i, maskedDBLen - i)) + if (!EVP_DigestUpdate(ctx, DB + i, maskedDBLen - i)) goto err; } - if (!EVP_DigestFinal_ex(ctx, H_, NULL)) + if (!EVP_DigestFinal_ex(ctx, H_, NULL)) goto err; ret = memcmp(H, H_, hLen) ? 0 : 1; err: if (DB) - free(DB); + free(DB); - EVP_MD_CTX_destroy(ctx); + EVP_MD_CTX_destroy(ctx); return ret; } @@ -226,14 +226,14 @@ err: Hash - EVP_MD() that will be used to pad sLen - random salt len (usually == hashLen) */ -int RwPaddingAddPssr(const TRwKey *rw, unsigned char *EM, const unsigned char *mHash, const EVP_MD *Hash, int sLen) { +int RwPaddingAddPssr(const TRwKey *rw, unsigned char *EM, const unsigned char *mHash, const EVP_MD *Hash, int sLen) { int i = 0, ret = 0, hLen = 0, maskedDBLen = 0, MSBits = 0, emLen = 0; unsigned char *H = NULL, *salt = NULL, *p = NULL; const EVP_MD *mgf1Hash = Hash; - EVP_MD_CTX* ctx = EVP_MD_CTX_create(); - if (!ctx) { - return ret; - } + EVP_MD_CTX* ctx = EVP_MD_CTX_create(); + if (!ctx) { + return ret; + } hLen = EVP_MD_size(Hash); if (hLen < 0) @@ -249,20 +249,20 @@ int RwPaddingAddPssr(const TRwKey *rw, unsigned char *EM, const unsigned char *m else if (sLen < -2) goto err; - { - int bits = BN_num_bits(rw->N); - if (bits <= 0) - goto err; - MSBits = (bits - 1) & 0x7; - } - emLen = RwModSize(rw); - if (emLen <= 0) - goto err; + { + int bits = BN_num_bits(rw->N); + if (bits <= 0) + goto err; + MSBits = (bits - 1) & 0x7; + } + emLen = RwModSize(rw); + if (emLen <= 0) + goto err; if (MSBits == 0) { *EM++ = 0; emLen--; - fprintf(stderr, "MSBits == 0\n"); + fprintf(stderr, "MSBits == 0\n"); } if (sLen == -2) { @@ -272,28 +272,28 @@ int RwPaddingAddPssr(const TRwKey *rw, unsigned char *EM, const unsigned char *m goto err; if (sLen > 0) { - salt = malloc(sLen); + salt = malloc(sLen); if (!salt) goto err; if (RAND_bytes(salt, sLen) <= 0) goto err; } maskedDBLen = emLen - hLen - 1; - if (maskedDBLen < 0) - goto err; + if (maskedDBLen < 0) + goto err; H = EM + maskedDBLen; - if (!EVP_DigestInit_ex(ctx, Hash, NULL) || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) || !EVP_DigestUpdate(ctx, mHash, hLen)) + if (!EVP_DigestInit_ex(ctx, Hash, NULL) || !EVP_DigestUpdate(ctx, zeroes, sizeof zeroes) || !EVP_DigestUpdate(ctx, mHash, hLen)) goto err; - if (sLen && !EVP_DigestUpdate(ctx, salt, sLen)) + if (sLen && !EVP_DigestUpdate(ctx, salt, sLen)) goto err; - if (!EVP_DigestFinal_ex(ctx, H, NULL)) + if (!EVP_DigestFinal_ex(ctx, H, NULL)) goto err; /* Generate dbMask in place then perform XOR on it */ - if (PkcS1MgF1(EM, maskedDBLen, H, hLen, mgf1Hash)) + if (PkcS1MgF1(EM, maskedDBLen, H, hLen, mgf1Hash)) goto err; p = EM; @@ -319,10 +319,10 @@ int RwPaddingAddPssr(const TRwKey *rw, unsigned char *EM, const unsigned char *m ret = 1; err: - EVP_MD_CTX_destroy(ctx); - + EVP_MD_CTX_destroy(ctx); + if (salt) - free(salt); + free(salt); return ret; } diff --git a/library/cpp/tvmauth/src/rw/rw_pss_sign.c b/library/cpp/tvmauth/src/rw/rw_pss_sign.c index f1ae46f140..59897f1cf5 100644 --- a/library/cpp/tvmauth/src/rw/rw_pss_sign.c +++ b/library/cpp/tvmauth/src/rw/rw_pss_sign.c @@ -2,44 +2,44 @@ #include <contrib/libs/openssl/include/openssl/evp.h> -//#define DBG_FUZZING - -int RwApply(const int flen, const unsigned char* from, unsigned char* to, const TRwKey* rw) { +//#define DBG_FUZZING + +int RwApply(const int flen, const unsigned char* from, unsigned char* to, const TRwKey* rw) { int i, j, num, k, r = -1; BN_CTX* ctx = NULL; BIGNUM *f = NULL, *ret = NULL; - if ((ctx = BN_CTX_secure_new()) == NULL) + if ((ctx = BN_CTX_secure_new()) == NULL) goto err; BN_CTX_start(ctx); f = BN_CTX_get(ctx); ret = BN_CTX_get(ctx); - num = BN_num_bytes(rw->N); + num = BN_num_bytes(rw->N); + + if (num <= 0) + goto err; - if (num <= 0) - goto err; - if (!f || !ret) goto err; if (BN_bin2bn(from, flen, f) == NULL) goto err; - if (BN_ucmp(f, rw->N) >= 0) + if (BN_ucmp(f, rw->N) >= 0) goto err; - if (!rw->Meth->RwApply(ret, f, ctx, rw)) + if (!rw->Meth->RwApply(ret, f, ctx, rw)) goto err; j = BN_num_bytes(ret); - if (num < j || j < 0) - goto err; - - i = BN_bn2bin(ret, to + num - j); - if (i < 0 || i > num) - goto err; - + if (num < j || j < 0) + goto err; + + i = BN_bn2bin(ret, to + num - j); + if (i < 0 || i > num) + goto err; + for (k = 0; k < (num - i); k++) to[k] = 0; r = num; @@ -52,46 +52,46 @@ err: return r; } -int RwPssrSignHash(const unsigned char* from, unsigned char* to, TRwKey* rw, const EVP_MD* md) { - unsigned char* padding = NULL; +int RwPssrSignHash(const unsigned char* from, unsigned char* to, TRwKey* rw, const EVP_MD* md) { + unsigned char* padding = NULL; int result = 0; if (from == NULL || to == NULL || rw == NULL || md == NULL) return 0; - int digest_size = EVP_MD_size(md); - int sig_size = RwModSize(rw); - - if (digest_size <= 0 || sig_size <= 0) - return 0; - - int tries = 50; - do { - if (padding != NULL) { - free(padding); -#ifdef DBG_FUZZING - fprintf(stderr, "Padding regenerating required\n"); -#endif - } - - padding = malloc(sig_size); - if (padding == NULL) - return 0; - - if (!RwPaddingAddPssr(rw, padding, from, md, digest_size)) - goto err; - } while (padding[0] == 0x00 && tries-- > 0); - - result = RwNoPaddingSign(sig_size, padding, to, rw); + int digest_size = EVP_MD_size(md); + int sig_size = RwModSize(rw); + + if (digest_size <= 0 || sig_size <= 0) + return 0; + + int tries = 50; + do { + if (padding != NULL) { + free(padding); +#ifdef DBG_FUZZING + fprintf(stderr, "Padding regenerating required\n"); +#endif + } + + padding = malloc(sig_size); + if (padding == NULL) + return 0; + + if (!RwPaddingAddPssr(rw, padding, from, md, digest_size)) + goto err; + } while (padding[0] == 0x00 && tries-- > 0); + + result = RwNoPaddingSign(sig_size, padding, to, rw); err: if (padding != NULL) - free(padding); + free(padding); return result; } -int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, TRwKey* rw, const EVP_MD* md) { +int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, TRwKey* rw, const EVP_MD* md) { EVP_MD_CTX* mdctx = NULL; unsigned char* digest = NULL; unsigned int digestLen; @@ -100,7 +100,7 @@ int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, if (msg == NULL || to == NULL || rw == NULL || md == NULL) goto err; - if (rw->P == NULL || rw->Q == NULL) + if (rw->P == NULL || rw->Q == NULL) goto err; if ((mdctx = EVP_MD_CTX_create()) == NULL) @@ -112,63 +112,63 @@ int RwPssrSignMsg(const int msgLen, const unsigned char* msg, unsigned char* to, if (1 != EVP_DigestUpdate(mdctx, msg, msgLen)) goto err; - if ((digest = (unsigned char*)malloc(EVP_MD_size(md))) == NULL) + if ((digest = (unsigned char*)malloc(EVP_MD_size(md))) == NULL) goto err; if (1 != EVP_DigestFinal_ex(mdctx, digest, &digestLen)) goto err; - result = RwPssrSignHash(digest, to, rw, md); + result = RwPssrSignHash(digest, to, rw, md); err: if (mdctx != NULL) EVP_MD_CTX_destroy(mdctx); if (digest != NULL) - free(digest); + free(digest); return result; } -int RwPssrVerifyHash(const unsigned char* from, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md) { +int RwPssrVerifyHash(const unsigned char* from, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md) { unsigned char* buffer = NULL; int buffer_len; - int salt_size; + int salt_size; int result = 0; if (from == NULL || sig == NULL || rw == NULL || md == NULL) return 0; - if (rw->N == NULL || rw->Meth == NULL) + if (rw->N == NULL || rw->Meth == NULL) return 0; salt_size = EVP_MD_size(md); - if (salt_size <= 0) - return 0; - - buffer_len = RwModSize(rw); - if (buffer_len <= 0) - return 0; - - buffer = (unsigned char*)malloc(buffer_len); - if (buffer == NULL) - return 0; + if (salt_size <= 0) + return 0; + + buffer_len = RwModSize(rw); + if (buffer_len <= 0) + return 0; + + buffer = (unsigned char*)malloc(buffer_len); + if (buffer == NULL) + return 0; - if (RwApply(sig_len, sig, buffer, rw) <= 0) + if (RwApply(sig_len, sig, buffer, rw) <= 0) goto err; - if (RwVerifyPssr(rw, from, md, buffer, salt_size) <= 0) + if (RwVerifyPssr(rw, from, md, buffer, salt_size) <= 0) goto err; result = 1; err: if (buffer != NULL) - free(buffer); + free(buffer); return result; } -int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md) { +int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned char* sig, const int sig_len, const TRwKey* rw, const EVP_MD* md) { EVP_MD_CTX* mdctx = NULL; unsigned char* digest = NULL; unsigned int digestLen = 0; @@ -177,7 +177,7 @@ int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned c if (msg == NULL || msgLen == 0 || sig == NULL || rw == NULL || md == NULL) goto err; - if (rw->N == NULL) + if (rw->N == NULL) goto err; if ((mdctx = EVP_MD_CTX_create()) == NULL) @@ -186,26 +186,26 @@ int RwPssrVerifyMsg(const int msgLen, const unsigned char* msg, const unsigned c if (1 != EVP_DigestInit_ex(mdctx, md, NULL)) goto err; - int size_to_alloc = EVP_MD_size(md); - if (size_to_alloc <= 0) + int size_to_alloc = EVP_MD_size(md); + if (size_to_alloc <= 0) + goto err; + + if ((digest = (unsigned char*)malloc(size_to_alloc)) == NULL) goto err; - if ((digest = (unsigned char*)malloc(size_to_alloc)) == NULL) - goto err; - if (1 != EVP_DigestUpdate(mdctx, msg, msgLen)) goto err; if (1 != EVP_DigestFinal_ex(mdctx, digest, &digestLen)) goto err; - result = RwPssrVerifyHash(digest, sig, sig_len, rw, md); + result = RwPssrVerifyHash(digest, sig, sig_len, rw, md); err: if (mdctx != NULL) EVP_MD_CTX_destroy(mdctx); if (digest != NULL) - free(digest); + free(digest); return result; } diff --git a/library/cpp/tvmauth/src/rw/rw_sign.c b/library/cpp/tvmauth/src/rw/rw_sign.c index e070d6e7c1..e320808dd3 100644 --- a/library/cpp/tvmauth/src/rw/rw_sign.c +++ b/library/cpp/tvmauth/src/rw/rw_sign.c @@ -1,36 +1,36 @@ #include "rw.h" -TRwSignature* RwSignatureNew(void) { - TRwSignature* sig = NULL; - sig = malloc(sizeof(TRwSignature)); +TRwSignature* RwSignatureNew(void) { + TRwSignature* sig = NULL; + sig = malloc(sizeof(TRwSignature)); if (!sig) return NULL; - sig->S = NULL; + sig->S = NULL; return sig; } -void RwSignatureFree(TRwSignature* sig) { +void RwSignatureFree(TRwSignature* sig) { if (sig) { - if (sig->S) - BN_free(sig->S); - free(sig); + if (sig->S) + BN_free(sig->S); + free(sig); } } -int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwKey* rw) { - int i = 0, r = 0, num = -1; - TRwSignature* sig = NULL; +int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwKey* rw) { + int i = 0, r = 0, num = -1; + TRwSignature* sig = NULL; - if (!rw || !rw->N || !rw->Meth || !rw->Meth->RwSign || !from || !to) - goto err; - - if ((sig = rw->Meth->RwSign(from, flen, rw)) == NULL) + if (!rw || !rw->N || !rw->Meth || !rw->Meth->RwSign || !from || !to) goto err; - num = BN_num_bytes(rw->N); - r = BN_bn2bin(sig->S, to); - if (r < 0) - goto err; + if ((sig = rw->Meth->RwSign(from, flen, rw)) == NULL) + goto err; + num = BN_num_bytes(rw->N); + + r = BN_bn2bin(sig->S, to); + if (r < 0) + goto err; /* put zeroes to the rest of the 'to' buffer */ for (i = r; i < num; i++) { @@ -39,7 +39,7 @@ int RwNoPaddingSign(int flen, const unsigned char* from, unsigned char* to, TRwK err: if (sig != NULL) { - RwSignatureFree(sig); + RwSignatureFree(sig); } return r; diff --git a/library/cpp/tvmauth/src/rw/ut/rw_ut.cpp b/library/cpp/tvmauth/src/rw/ut/rw_ut.cpp index bef9d9d25a..73f1b1d769 100644 --- a/library/cpp/tvmauth/src/rw/ut/rw_ut.cpp +++ b/library/cpp/tvmauth/src/rw/ut/rw_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/tvmauth/src/rw/keys.h> -#include <library/cpp/tvmauth/src/rw/rw.h> +#include <library/cpp/tvmauth/src/rw/keys.h> +#include <library/cpp/tvmauth/src/rw/rw.h> #include <library/cpp/string_utils/base64/base64.h> #include <library/cpp/testing/unittest/registar.h> @@ -7,36 +7,36 @@ #include <contrib/libs/openssl/include/openssl/bn.h> #include <contrib/libs/openssl/include/openssl/evp.h> -namespace NTvmAuth { +namespace NTvmAuth { /* returns 0 in case of error */ - int MakeKeysRw(TRwKey** skey, TRwKey** vkey) { + int MakeKeysRw(TRwKey** skey, TRwKey** vkey) { int result = 0; - TRwKey* rw = RwNew(); + TRwKey* rw = RwNew(); do { - RwGenerateKey(rw, 2048); + RwGenerateKey(rw, 2048); if (rw == nullptr) { - printf("RwGenerateKey failed\n"); + printf("RwGenerateKey failed\n"); break; /* failed */ } - printf("RW key bits: %d\n", BN_num_bits(rw->N)); + printf("RW key bits: %d\n", BN_num_bits(rw->N)); /* Set signing key */ - *skey = RwPrivateKeyDup(rw); + *skey = RwPrivateKeyDup(rw); if (*skey == nullptr) { - printf("RwPrivateKeyDup failed\n"); + printf("RwPrivateKeyDup failed\n"); break; } /* Set verifier key */ - *vkey = RwPublicKeyDup(rw); + *vkey = RwPublicKeyDup(rw); if (*vkey == nullptr) { - printf("RwPublicKeyDup failed\n"); + printf("RwPublicKeyDup failed\n"); break; } @@ -45,14 +45,14 @@ namespace NTvmAuth { } while (0); if (rw) { - RwFree(rw); + RwFree(rw); rw = nullptr; } return result; } - static void PrintIt(const char* label, const unsigned char* buff, size_t len) { + static void PrintIt(const char* label, const unsigned char* buff, size_t len) { if (!buff || !len) return; @@ -65,26 +65,26 @@ namespace NTvmAuth { printf("\n"); } - int TestSignVerify() { - TRwKey *skey = nullptr, *vkey = nullptr; + int TestSignVerify() { + TRwKey *skey = nullptr, *vkey = nullptr; const char* msg = "Test test test test test"; unsigned int msg_len = 0; int res = 0; msg_len = (unsigned int)strlen(msg); - if (MakeKeysRw(&skey, &vkey)) { - unsigned char* sign = new unsigned char[RwModSize(skey) + 10]; - int sign_len; - printf("RwModSize(skey) returned %d\n", RwModSize(skey)); - memset(sign, 0x00, RwModSize(skey) + 10); + if (MakeKeysRw(&skey, &vkey)) { + unsigned char* sign = new unsigned char[RwModSize(skey) + 10]; + int sign_len; + printf("RwModSize(skey) returned %d\n", RwModSize(skey)); + memset(sign, 0x00, RwModSize(skey) + 10); printf("--- Signing call ---\n"); - if ((sign_len = RwPssrSignMsg(msg_len, (unsigned char*)msg, sign, skey, (EVP_MD*)EVP_sha256())) != 0) { + if ((sign_len = RwPssrSignMsg(msg_len, (unsigned char*)msg, sign, skey, (EVP_MD*)EVP_sha256())) != 0) { #ifdef RW_PRINT_DEBUG BIGNUM* s = BN_new(); #endif printf("\n"); - PrintIt("Signature", sign, RwModSize(skey)); + PrintIt("Signature", sign, RwModSize(skey)); #ifdef RW_PRINT_DEBUG BN_bin2bn(sign, RW_mod_size(skey), s); @@ -95,42 +95,42 @@ namespace NTvmAuth { #endif printf("--- Verification call ---\n"); - if (RwPssrVerifyMsg(msg_len, (unsigned char*)msg, sign, sign_len, vkey, (EVP_MD*)EVP_sha256())) { + if (RwPssrVerifyMsg(msg_len, (unsigned char*)msg, sign, sign_len, vkey, (EVP_MD*)EVP_sha256())) { printf("Verification: success!\n"); res = 1; } else { printf("Verification: failed!\n"); - printf("RwPssrVerifyMsg failed!\n"); + printf("RwPssrVerifyMsg failed!\n"); return 1; } } else { - printf("RwPssrSignMsg failed!\n"); + printf("RwPssrSignMsg failed!\n"); return 1; } if (sign != nullptr) - delete[] sign; + delete[] sign; } else { - printf("MakeKeysRw failed!\n"); + printf("MakeKeysRw failed!\n"); return 1; } if (skey != nullptr) { - RwFree(skey); + RwFree(skey); } if (vkey != nullptr) - RwFree(vkey); + RwFree(vkey); return res; } } -using namespace NTvmAuth; +using namespace NTvmAuth; Y_UNIT_TEST_SUITE(Rw) { Y_UNIT_TEST(SignVerify) { for (int i = 1; i < 10; ++i) { - UNIT_ASSERT_VALUES_EQUAL(1, TestSignVerify()); + UNIT_ASSERT_VALUES_EQUAL(1, TestSignVerify()); } } @@ -142,10 +142,10 @@ Y_UNIT_TEST_SUITE(Rw) { NRw::TRwPrivateKey priv3(Base64Decode("MIICVAKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NAkEAg1xBDL_UkHy347HwioMscJFP-6eKeim3LoG9rd1EvOycxkoStZ4299OdyzzEXC9cjLdq401BXe-LairiMUgZawJBALn5ziBCc2ycMaYjZDon2EN55jBEe0tJdUy4mOi0ozTV9OLcBANds0nMYPjZFOY3QymzU0LcOa_An3JknI0C2ucCQGxtwTb3h7ux5Ld8jkeRYzkNoB2Y6Is5fqCYVRIJZmz0IcQFb2iW0EX92U7_BpgVuKlvSDTP9LuaxuPfmY6WXEECQBc_OcQITm2ThjTEbIdE-whvPMYIj2lpLqmXEx0WlGaavpxbgIBrtmk5jB8bIpzG6GU2amhbhzX4E-5Mk5GgW10CQBBriCGX-pIPlvx2PhFQZY4SKf908U9FNuXQN7W7qJedk5jJQlazxt76c7lnmIuF65GW7VxpqCu98W1FXEYpAy0CQG-lpihdvxaZ8SkHqNFZGnXhELT2YesLs7GehZSTwuUwx1iTpVm88PVROLYBDZqoGM316s9aZEJBALe5zEpxQTQCQQCDMszX1cQlbBCP08isuMQ2ac3S-qNd0mfRXDCRfMm4s7iuJ5MeHU3uPUVlA_MR4ULRbg1d97TGio912z4KPgjE"), 0); - UNIT_ASSERT_EXCEPTION(NRw::TRwPrivateKey("asdzxcv", 0), yexception); + UNIT_ASSERT_EXCEPTION(NRw::TRwPrivateKey("asdzxcv", 0), yexception); UNIT_ASSERT_EXCEPTION(NRw::TRwPrivateKey(Base64Decode("AKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NAkEAg1xBDL_UkHy347HwioMscJFP-6eKeim3LoG9rd1EvOycxkoStZ4299OdyzzEXC9cjLdq401BXe-LairiMUgZawJBALn5ziBCc2ycMaYjZDon2EN55jBEe0tJdUy4mOi0ozTV9OLcBANds0nMYPjZFOY3QymzU0LcOa_An3JknI0C2ucCQGxtwTb3h7ux5Ld8jkeRYzkNoB2Y6Is5fqCYVRIJZmz0IcQFb2iW0EX92U7_BpgVuKlvSDTP9LuaxuPfmY6WXEECQBc_OcQITm2ThjTEbIdE-whvPMYIj2lpLqmXEx0WlGaavpxbgIBrtmk5jB8bIpzG6GU2amhbhzX4E-5Mk5GgW10CQBBriCGX-pIPlvx2PhFQZY4SKf908U9FNuXQN7W7qJedk5jJQlazxt76c7lnmIuF65GW7VxpqCu98W1FXEYpAy0CQG-lpihdvxaZ8SkHqNFZGnXhELT2YesLs7GehZSTwuUwx1iTpVm88PVROLYBDZqoGM316s9aZEJBALe5zEpxQTQCQQCDMszX1cQlbBCP08isuMQ2ac3S-qNd0mfRXDCRfMm4s7iuJ5MeHU3uPUVlA_MR4ULRbg1d97TGio912z4KP"), 0), - yexception); + yexception); UNIT_ASSERT(!priv.SignTicket("").empty()); } @@ -155,8 +155,8 @@ Y_UNIT_TEST_SUITE(Rw) { NRw::TRwPublicKey pub2(Base64Decode("MIIBBQKCAQEA4RATOfumLD1n6ICrW5biaAl9VldinczmkNPjpUWwc3gs8PnkCrtdnPFmpBwW3gjHdSNU1OuEg5A6K1o1xiGv9sU-jd88zQBOdK6E2zwnJnkK6bNusKE2H2CLqg3aMWCmTa9JbzSy1uO7wa-xCqqNUuCko-2lyv12HhL1ICIH951SHDa4qO1U5xZhhlUAnqWi9R4tYDeMiF41WdOjwT2fg8UkbusThmxa3yjCXjD7OyjshPtukN8Tl3UyGtV_s2CLnE3f28VAi-AVW8FtgL22xbGhuyEplXRrtF1E5oV7NSqxH1FS0SYROA8ffYQGV5tfx5WDFHiXDEP6BzoVfeBDRQ==")); NRw::TRwPublicKey pub3(Base64Decode("MIGDAoGAX23ZgkYAmRFEWrp9aGLebVMVbVQ4TR_pmt9iEcCSmoaUqWHRBV95M0-l4mGLvnFfMJ7qhF5FSb7QNuoM2FNKELu4ZS_Ug1idEFBYfoT7kVzletsMVK4ZDDYRiM18fL8d58clfFAoCo-_EEMowqQeBXnxa0zqsLyNGL2x1f-KDY0=")); - UNIT_ASSERT_EXCEPTION(NRw::TRwPublicKey("asdzxcv"), yexception); - UNIT_ASSERT_EXCEPTION(NRw::TRwPublicKey(Base64Decode("AoGAX23ZgkYAmRFEWrp9aGLebVMVbVQ4TR_pmt9iEcCSmoaUqWHRBV95M0-l4mGLvnFfMJ7qhF5FSb7QNuoM2FNKELu4ZS_Ug1idEFBYfoT7kVzletsMVK40")), yexception); + UNIT_ASSERT_EXCEPTION(NRw::TRwPublicKey("asdzxcv"), yexception); + UNIT_ASSERT_EXCEPTION(NRw::TRwPublicKey(Base64Decode("AoGAX23ZgkYAmRFEWrp9aGLebVMVbVQ4TR_pmt9iEcCSmoaUqWHRBV95M0-l4mGLvnFfMJ7qhF5FSb7QNuoM2FNKELu4ZS_Ug1idEFBYfoT7kVzletsMVK40")), yexception); UNIT_ASSERT(!pub.CheckSign("~~~", "~~~")); } @@ -181,20 +181,20 @@ Y_UNIT_TEST_SUITE(Rw) { } Y_UNIT_TEST(Keygen) { - for (size_t idx = 0; idx < 100; ++idx) { - NRw::TKeyPair pair = NRw::GenKeyPair(1024); - NRw::TRwPrivateKey priv(pair.Private, 0); - NRw::TRwPublicKey pub(pair.Public); - - const TString data = "my magic data"; - TStringStream s; - s << "data='" << data << "'."; - s << "private='" << Base64Encode(pair.Private) << "'."; - s << "public='" << Base64Encode(pair.Public) << "'."; - TString sign; - UNIT_ASSERT_NO_EXCEPTION_C(sign = priv.SignTicket(data), s.Str()); - s << "sign='" << Base64Encode(sign) << "'."; - UNIT_ASSERT_C(pub.CheckSign(data, sign), s.Str()); - } + for (size_t idx = 0; idx < 100; ++idx) { + NRw::TKeyPair pair = NRw::GenKeyPair(1024); + NRw::TRwPrivateKey priv(pair.Private, 0); + NRw::TRwPublicKey pub(pair.Public); + + const TString data = "my magic data"; + TStringStream s; + s << "data='" << data << "'."; + s << "private='" << Base64Encode(pair.Private) << "'."; + s << "public='" << Base64Encode(pair.Public) << "'."; + TString sign; + UNIT_ASSERT_NO_EXCEPTION_C(sign = priv.SignTicket(data), s.Str()); + s << "sign='" << Base64Encode(sign) << "'."; + UNIT_ASSERT_C(pub.CheckSign(data, sign), s.Str()); + } } } diff --git a/library/cpp/tvmauth/src/rw/ut/ya.make b/library/cpp/tvmauth/src/rw/ut/ya.make index eccbf89bc1..81dda79641 100644 --- a/library/cpp/tvmauth/src/rw/ut/ya.make +++ b/library/cpp/tvmauth/src/rw/ut/ya.make @@ -1,10 +1,10 @@ -UNITTEST_FOR(library/cpp/tvmauth/src/rw) +UNITTEST_FOR(library/cpp/tvmauth/src/rw) -OWNER( - g:passport_infra - e-sidorov - ezaitov -) +OWNER( + g:passport_infra + e-sidorov + ezaitov +) SRCS( rw_ut.cpp diff --git a/library/cpp/tvmauth/src/rw/ut_large/gen/main.cpp b/library/cpp/tvmauth/src/rw/ut_large/gen/main.cpp index 792308f48b..31a599c996 100644 --- a/library/cpp/tvmauth/src/rw/ut_large/gen/main.cpp +++ b/library/cpp/tvmauth/src/rw/ut_large/gen/main.cpp @@ -1,32 +1,32 @@ -#include <library/cpp/tvmauth/src/rw/keys.h> - +#include <library/cpp/tvmauth/src/rw/keys.h> + #include <library/cpp/string_utils/base64/base64.h> - -#include <util/generic/yexception.h> - -using namespace NTvmAuth; - -const TString DATA = "my magic data"; - -int main(int, char**) { - const NRw::TKeyPair pair = NRw::GenKeyPair(1024); - const NRw::TRwPrivateKey priv(pair.Private, 0); - const NRw::TRwPublicKey pub(pair.Public); - - Cout << "data='" << DATA << "'." - << "private='" << Base64Encode(pair.Private) << "'." - << "public='" << Base64Encode(pair.Public) << "'."; - - TString sign; - try { - sign = priv.SignTicket(DATA); - Cout << "sign='" << Base64Encode(sign) << "'."; - Y_ENSURE(pub.CheckSign(DATA, sign)); - } catch (const std::exception& e) { - Cout << "what='" << e.what() << "'" << Endl; - return 1; - } - Cout << Endl; - - return 0; -} + +#include <util/generic/yexception.h> + +using namespace NTvmAuth; + +const TString DATA = "my magic data"; + +int main(int, char**) { + const NRw::TKeyPair pair = NRw::GenKeyPair(1024); + const NRw::TRwPrivateKey priv(pair.Private, 0); + const NRw::TRwPublicKey pub(pair.Public); + + Cout << "data='" << DATA << "'." + << "private='" << Base64Encode(pair.Private) << "'." + << "public='" << Base64Encode(pair.Public) << "'."; + + TString sign; + try { + sign = priv.SignTicket(DATA); + Cout << "sign='" << Base64Encode(sign) << "'."; + Y_ENSURE(pub.CheckSign(DATA, sign)); + } catch (const std::exception& e) { + Cout << "what='" << e.what() << "'" << Endl; + return 1; + } + Cout << Endl; + + return 0; +} diff --git a/library/cpp/tvmauth/src/rw/ut_large/gen/ya.make b/library/cpp/tvmauth/src/rw/ut_large/gen/ya.make index cfe165160a..7b62d5c726 100644 --- a/library/cpp/tvmauth/src/rw/ut_large/gen/ya.make +++ b/library/cpp/tvmauth/src/rw/ut_large/gen/ya.make @@ -1,14 +1,14 @@ -PROGRAM() - -OWNER(g:passport_infra) - -SRCS( - main.cpp -) - -PEERDIR( +PROGRAM() + +OWNER(g:passport_infra) + +SRCS( + main.cpp +) + +PEERDIR( library/cpp/string_utils/base64 - library/cpp/tvmauth/src/rw -) - -END() + library/cpp/tvmauth/src/rw +) + +END() diff --git a/library/cpp/tvmauth/src/rw/ut_large/test.py b/library/cpp/tvmauth/src/rw/ut_large/test.py index 8fb0c0f91c..0cf95d9848 100644 --- a/library/cpp/tvmauth/src/rw/ut_large/test.py +++ b/library/cpp/tvmauth/src/rw/ut_large/test.py @@ -1,35 +1,35 @@ -from __future__ import print_function - -import os -import subprocess -import sys - -import yatest.common as yc - - -def test_fuzzing(): - errfile = './errfile' - outfile = './outfile' - env = os.environ.copy() - - for number in range(25000): - with open(errfile, 'w') as fe: - with open(outfile, 'w') as fo: - p = subprocess.Popen( - [ - yc.build_path('library/cpp/tvmauth/src/rw/ut_large/gen/gen'), - ], - env=env, - stdout=fo, - stderr=fe, - ) - code = p.wait() - - with open(errfile) as fe: - all = fe.read() - if all != '': - with open(outfile) as fo: - print(fo.read(), file=sys.stderr) - assert all == '' - - assert code == 0 +from __future__ import print_function + +import os +import subprocess +import sys + +import yatest.common as yc + + +def test_fuzzing(): + errfile = './errfile' + outfile = './outfile' + env = os.environ.copy() + + for number in range(25000): + with open(errfile, 'w') as fe: + with open(outfile, 'w') as fo: + p = subprocess.Popen( + [ + yc.build_path('library/cpp/tvmauth/src/rw/ut_large/gen/gen'), + ], + env=env, + stdout=fo, + stderr=fe, + ) + code = p.wait() + + with open(errfile) as fe: + all = fe.read() + if all != '': + with open(outfile) as fo: + print(fo.read(), file=sys.stderr) + assert all == '' + + assert code == 0 diff --git a/library/cpp/tvmauth/src/rw/ut_large/ya.make b/library/cpp/tvmauth/src/rw/ut_large/ya.make index f4095eef29..54f82065e7 100644 --- a/library/cpp/tvmauth/src/rw/ut_large/ya.make +++ b/library/cpp/tvmauth/src/rw/ut_large/ya.make @@ -1,17 +1,17 @@ PY2TEST() - -OWNER(g:passport_infra) - + +OWNER(g:passport_infra) + TEST_SRCS(test.py) - -DEPENDS(library/cpp/tvmauth/src/rw/ut_large/gen) - -TAG(ya:fat) -SIZE(LARGE) - -END() - +DEPENDS(library/cpp/tvmauth/src/rw/ut_large/gen) + +TAG(ya:fat) + +SIZE(LARGE) + +END() + RECURSE( gen ) diff --git a/library/cpp/tvmauth/src/rw/ya.make b/library/cpp/tvmauth/src/rw/ya.make index fffadceb30..e2ef68d416 100644 --- a/library/cpp/tvmauth/src/rw/ya.make +++ b/library/cpp/tvmauth/src/rw/ya.make @@ -1,14 +1,14 @@ LIBRARY(ticket_parser) OWNER( - g:passport_infra + g:passport_infra e-sidorov - ezaitov + ezaitov ) PEERDIR( contrib/libs/openssl - library/cpp/openssl/init + library/cpp/openssl/init ) SRCS( @@ -23,8 +23,8 @@ SRCS( ) END() - -RECURSE_FOR_TESTS( - ut - ut_large -) + +RECURSE_FOR_TESTS( + ut + ut_large +) diff --git a/library/cpp/tvmauth/src/service_impl.cpp b/library/cpp/tvmauth/src/service_impl.cpp index b27727494c..528a244647 100644 --- a/library/cpp/tvmauth/src/service_impl.cpp +++ b/library/cpp/tvmauth/src/service_impl.cpp @@ -3,139 +3,139 @@ #include "parser.h" #include "utils.h" -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/ticket_status.h> #include <util/generic/strbuf.h> #include <util/string/cast.h> #include <util/string/split.h> -namespace NTvmAuth { - static const char* EX_MSG = "Method cannot be used in non-valid ticket"; - - TCheckedServiceTicket::TImpl::operator bool() const { - return (Status_ == ETicketStatus::Ok); +namespace NTvmAuth { + static const char* EX_MSG = "Method cannot be used in non-valid ticket"; + + TCheckedServiceTicket::TImpl::operator bool() const { + return (Status_ == ETicketStatus::Ok); } - TTvmId TCheckedServiceTicket::TImpl::GetSrc() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return ProtobufTicket_.service().srcclientid(); + TTvmId TCheckedServiceTicket::TImpl::GetSrc() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return ProtobufTicket_.service().srcclientid(); } - const TScopes& TCheckedServiceTicket::TImpl::GetScopes() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - if (CachedScopes_.empty()) { - for (const auto& el : ProtobufTicket_.service().scopes()) { - CachedScopes_.push_back(el); + const TScopes& TCheckedServiceTicket::TImpl::GetScopes() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + if (CachedScopes_.empty()) { + for (const auto& el : ProtobufTicket_.service().scopes()) { + CachedScopes_.push_back(el); } } - return CachedScopes_; + return CachedScopes_; } - bool TCheckedServiceTicket::TImpl::HasScope(TStringBuf scopeName) const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return std::binary_search(ProtobufTicket_.service().scopes().begin(), ProtobufTicket_.service().scopes().end(), scopeName); + bool TCheckedServiceTicket::TImpl::HasScope(TStringBuf scopeName) const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return std::binary_search(ProtobufTicket_.service().scopes().begin(), ProtobufTicket_.service().scopes().end(), scopeName); } - ETicketStatus TCheckedServiceTicket::TImpl::GetStatus() const { - return Status_; + ETicketStatus TCheckedServiceTicket::TImpl::GetStatus() const { + return Status_; } - time_t TCheckedServiceTicket::TImpl::GetExpirationTime() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return ProtobufTicket_.expirationtime(); + time_t TCheckedServiceTicket::TImpl::GetExpirationTime() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return ProtobufTicket_.expirationtime(); } - TString TCheckedServiceTicket::TImpl::DebugInfo() const { - if (CachedDebugInfo_) { - return CachedDebugInfo_; - } - - if (Status_ == ETicketStatus::Malformed) { - CachedDebugInfo_ = "status=malformed;"; - return CachedDebugInfo_; + TString TCheckedServiceTicket::TImpl::DebugInfo() const { + if (CachedDebugInfo_) { + return CachedDebugInfo_; + } + + if (Status_ == ETicketStatus::Malformed) { + CachedDebugInfo_ = "status=malformed;"; + return CachedDebugInfo_; } - + TString targetString = "ticket_type="; - targetString.reserve(256); - if (Status_ == ETicketStatus::InvalidTicketType) { + targetString.reserve(256); + if (Status_ == ETicketStatus::InvalidTicketType) { targetString.append("not-serv;"); - CachedDebugInfo_ = targetString; + CachedDebugInfo_ = targetString; return targetString; } - + targetString.append("serv"); - if (ProtobufTicket_.has_expirationtime()) - targetString.append(";expiration_time=").append(IntToString<10>(ProtobufTicket_.expirationtime())); - if (ProtobufTicket_.service().has_srcclientid()) { - targetString.append(";src=").append(IntToString<10>(ProtobufTicket_.service().srcclientid())); - } - if (ProtobufTicket_.service().has_dstclientid()) { - targetString.append(";dst=").append(IntToString<10>(ProtobufTicket_.service().dstclientid())); - } - for (const auto& scope : ProtobufTicket_.service().scopes()) { + if (ProtobufTicket_.has_expirationtime()) + targetString.append(";expiration_time=").append(IntToString<10>(ProtobufTicket_.expirationtime())); + if (ProtobufTicket_.service().has_srcclientid()) { + targetString.append(";src=").append(IntToString<10>(ProtobufTicket_.service().srcclientid())); + } + if (ProtobufTicket_.service().has_dstclientid()) { + targetString.append(";dst=").append(IntToString<10>(ProtobufTicket_.service().dstclientid())); + } + for (const auto& scope : ProtobufTicket_.service().scopes()) { targetString.append(";scope=").append(scope); } - if (ProtobufTicket_.service().has_issueruid()) { - targetString.append(";issuer_uid=").append(IntToString<10>(ProtobufTicket_.service().GetissuerUid())); - } + if (ProtobufTicket_.service().has_issueruid()) { + targetString.append(";issuer_uid=").append(IntToString<10>(ProtobufTicket_.service().GetissuerUid())); + } targetString.append(";"); - - CachedDebugInfo_ = targetString; + + CachedDebugInfo_ = targetString; return targetString; } - TMaybe<TUid> TCheckedServiceTicket::TImpl::GetIssuerUid() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return ProtobufTicket_.service().has_issueruid() - ? ProtobufTicket_.service().GetissuerUid() - : TMaybe<TUid>(); - } - - void TCheckedServiceTicket::TImpl::SetStatus(ETicketStatus status) { - Status_ = status; - } - - TCheckedServiceTicket::TImpl::TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket) - : Status_(status) - , ProtobufTicket_(std::move(protobufTicket)) + TMaybe<TUid> TCheckedServiceTicket::TImpl::GetIssuerUid() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return ProtobufTicket_.service().has_issueruid() + ? ProtobufTicket_.service().GetissuerUid() + : TMaybe<TUid>(); + } + + void TCheckedServiceTicket::TImpl::SetStatus(ETicketStatus status) { + Status_ = status; + } + + TCheckedServiceTicket::TImpl::TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket) + : Status_(status) + , ProtobufTicket_(std::move(protobufTicket)) { } - TServiceTicketImplPtr TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus status, - TTvmId src, - TMaybe<TUid> issuerUid) { - ticket2::Ticket proto; - proto.mutable_service()->set_srcclientid(src); - proto.mutable_service()->set_dstclientid(100500); - if (issuerUid) { - proto.mutable_service()->set_issueruid(*issuerUid); - } - return MakeHolder<TImpl>(status, std::move(proto)); - } - - TServiceContext::TImpl::TImpl(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse) - : Secret_(ParseSecret(secretBase64)) - , SelfTvmId_(selfTvmId) + TServiceTicketImplPtr TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus status, + TTvmId src, + TMaybe<TUid> issuerUid) { + ticket2::Ticket proto; + proto.mutable_service()->set_srcclientid(src); + proto.mutable_service()->set_dstclientid(100500); + if (issuerUid) { + proto.mutable_service()->set_issueruid(*issuerUid); + } + return MakeHolder<TImpl>(status, std::move(proto)); + } + + TServiceContext::TImpl::TImpl(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse) + : Secret_(ParseSecret(secretBase64)) + , SelfTvmId_(selfTvmId) { ResetKeys(tvmKeysResponse); } - TServiceContext::TImpl::TImpl(TTvmId selfTvmId, TStringBuf tvmKeysResponse) - : SelfTvmId_(selfTvmId) + TServiceContext::TImpl::TImpl(TTvmId selfTvmId, TStringBuf tvmKeysResponse) + : SelfTvmId_(selfTvmId) { ResetKeys(tvmKeysResponse); } - TServiceContext::TImpl::TImpl(TStringBuf secretBase64) - : Secret_(ParseSecret(secretBase64)) - { - } - + TServiceContext::TImpl::TImpl(TStringBuf secretBase64) + : Secret_(ParseSecret(secretBase64)) + { + } + void TServiceContext::TImpl::ResetKeys(TStringBuf tvmKeysResponse) { tvm_keys::Keys protoKeys; if (!protoKeys.ParseFromString(TParserTvmKeys::ParseStrV1(tvmKeysResponse))) { - ythrow TMalformedTvmKeysException() << "Malformed TVM keys"; + ythrow TMalformedTvmKeysException() << "Malformed TVM keys"; } NRw::TPublicKeys keys; @@ -146,41 +146,41 @@ namespace NTvmAuth { } if (keys.empty()) { - ythrow TEmptyTvmKeysException() << "Empty TVM keys"; + ythrow TEmptyTvmKeysException() << "Empty TVM keys"; } - Keys_ = std::move(keys); + Keys_ = std::move(keys); } TServiceTicketImplPtr TServiceContext::TImpl::Check(TStringBuf ticketBody) const { - if (Keys_.empty()) { - ythrow TEmptyTvmKeysException() << "Empty TVM keys"; - } - - TParserTickets::TRes res = TParserTickets::ParseV3(ticketBody, Keys_, TParserTickets::ServiceFlag()); - if (res.Status != ETicketStatus::Ok) { - return MakeHolder<TCheckedServiceTicket::TImpl>(res.Status, std::move(res.Ticket)); + if (Keys_.empty()) { + ythrow TEmptyTvmKeysException() << "Empty TVM keys"; + } + + TParserTickets::TRes res = TParserTickets::ParseV3(ticketBody, Keys_, TParserTickets::ServiceFlag()); + if (res.Status != ETicketStatus::Ok) { + return MakeHolder<TCheckedServiceTicket::TImpl>(res.Status, std::move(res.Ticket)); } - const ETicketStatus status = CheckProtobufServiceTicket(res.Ticket); - return MakeHolder<TCheckedServiceTicket::TImpl>(status, std::move(res.Ticket)); + const ETicketStatus status = CheckProtobufServiceTicket(res.Ticket); + return MakeHolder<TCheckedServiceTicket::TImpl>(status, std::move(res.Ticket)); } TString TServiceContext::TImpl::SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes) const { - if (Secret_.Value().empty()) { - ythrow TMalformedTvmSecretException() << "Malformed TVM secret: it is empty"; + if (Secret_.Value().empty()) { + ythrow TMalformedTvmSecretException() << "Malformed TVM secret: it is empty"; } - return NUtils::SignCgiParamsForTvm(Secret_, ts, dst, scopes); + return NUtils::SignCgiParamsForTvm(Secret_, ts, dst, scopes); } - ETicketStatus TServiceContext::TImpl::CheckProtobufServiceTicket(const ticket2::Ticket& ticket) const { + ETicketStatus TServiceContext::TImpl::CheckProtobufServiceTicket(const ticket2::Ticket& ticket) const { if (!ticket.has_service()) { - return ETicketStatus::Malformed; + return ETicketStatus::Malformed; } - if (ticket.service().dstclientid() != SelfTvmId_) { - return ETicketStatus::InvalidDst; + if (ticket.service().dstclientid() != SelfTvmId_) { + return ETicketStatus::InvalidDst; } - return ETicketStatus::Ok; + return ETicketStatus::Ok; } TString TServiceContext::TImpl::ParseSecret(TStringBuf secretBase64) { @@ -188,16 +188,16 @@ namespace NTvmAuth { secretBase64.Chop(1); } - if (secretBase64.empty()) { - ythrow TMalformedTvmSecretException() << "Malformed TVM secret: it is empty"; - } - + if (secretBase64.empty()) { + ythrow TMalformedTvmSecretException() << "Malformed TVM secret: it is empty"; + } + const TString secret = NUtils::Base64url2bin(secretBase64); if (secret.empty()) { - ythrow TMalformedTvmSecretException() << "Malformed TVM secret: invalid base64url"; + ythrow TMalformedTvmSecretException() << "Malformed TVM secret: invalid base64url"; } return secret; } -} +} diff --git a/library/cpp/tvmauth/src/service_impl.h b/library/cpp/tvmauth/src/service_impl.h index 1009ea094b..18dd4ec335 100644 --- a/library/cpp/tvmauth/src/service_impl.h +++ b/library/cpp/tvmauth/src/service_impl.h @@ -1,59 +1,59 @@ #pragma once -#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> -#include <library/cpp/tvmauth/src/protos/tvm_keys.pb.h> -#include <library/cpp/tvmauth/src/rw/keys.h> +#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> +#include <library/cpp/tvmauth/src/protos/tvm_keys.pb.h> +#include <library/cpp/tvmauth/src/rw/keys.h> -#include <library/cpp/tvmauth/type.h> -#include <library/cpp/tvmauth/deprecated/service_context.h> +#include <library/cpp/tvmauth/type.h> +#include <library/cpp/tvmauth/deprecated/service_context.h> -#include <library/cpp/charset/ci_string.h> -#include <library/cpp/string_utils/secret_string/secret_string.h> +#include <library/cpp/charset/ci_string.h> +#include <library/cpp/string_utils/secret_string/secret_string.h> + +#include <util/generic/maybe.h> -#include <util/generic/maybe.h> - #include <string> -namespace NTvmAuth { - using TServiceTicketImplPtr = THolder<TCheckedServiceTicket::TImpl>; - class TCheckedServiceTicket::TImpl { +namespace NTvmAuth { + using TServiceTicketImplPtr = THolder<TCheckedServiceTicket::TImpl>; + class TCheckedServiceTicket::TImpl { public: explicit operator bool() const; - TTvmId GetSrc() const; + TTvmId GetSrc() const; const TScopes& GetScopes() const; bool HasScope(TStringBuf scopeName) const; - ETicketStatus GetStatus() const; + ETicketStatus GetStatus() const; time_t GetExpirationTime() const; TString DebugInfo() const; - TMaybe<TUid> GetIssuerUid() const; + TMaybe<TUid> GetIssuerUid() const; + + void SetStatus(ETicketStatus status); - void SetStatus(ETicketStatus status); - /*! * Constructor for creation invalid ticket storing error status in TServiceContext * @param status * @param protobufTicket */ - TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket); + TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket); + + static TServiceTicketImplPtr CreateTicketForTests(ETicketStatus status, + TTvmId src, + TMaybe<TUid> issuerUid); - static TServiceTicketImplPtr CreateTicketForTests(ETicketStatus status, - TTvmId src, - TMaybe<TUid> issuerUid); - private: - ETicketStatus Status_; - ticket2::Ticket ProtobufTicket_; - mutable TScopes CachedScopes_; - mutable TString CachedDebugInfo_; + ETicketStatus Status_; + ticket2::Ticket ProtobufTicket_; + mutable TScopes CachedScopes_; + mutable TString CachedDebugInfo_; }; class TServiceContext::TImpl { public: - TImpl(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse); - TImpl(TTvmId selfTvmId, TStringBuf tvmKeysResponse); - TImpl(TStringBuf secretBase64); + TImpl(TStringBuf secretBase64, TTvmId selfTvmId, TStringBuf tvmKeysResponse); + TImpl(TTvmId selfTvmId, TStringBuf tvmKeysResponse); + TImpl(TStringBuf secretBase64); void ResetKeys(TStringBuf tvmKeysResponse); @@ -61,17 +61,17 @@ namespace NTvmAuth { TString SignCgiParamsForTvm(TStringBuf ts, TStringBuf dst, TStringBuf scopes = TStringBuf()) const; const NRw::TPublicKeys& GetKeys() const { // for tests - return Keys_; + return Keys_; } private: - ETicketStatus CheckProtobufServiceTicket(const ticket2::Ticket& ticket) const; + ETicketStatus CheckProtobufServiceTicket(const ticket2::Ticket& ticket) const; static TString ParseSecret(TStringBuf secretBase64); - NRw::TPublicKeys Keys_; - const NSecretString::TSecretString Secret_; - const TTvmId SelfTvmId_ = 0; + NRw::TPublicKeys Keys_; + const NSecretString::TSecretString Secret_; + const TTvmId SelfTvmId_ = 0; - ::google::protobuf::LogSilencer LogSilencer_; + ::google::protobuf::LogSilencer LogSilencer_; }; -} +} diff --git a/library/cpp/tvmauth/src/service_ticket.cpp b/library/cpp/tvmauth/src/service_ticket.cpp index 70e9e60f66..077049ef3a 100644 --- a/library/cpp/tvmauth/src/service_ticket.cpp +++ b/library/cpp/tvmauth/src/service_ticket.cpp @@ -1,41 +1,41 @@ -#include "service_impl.h" - -#include <library/cpp/tvmauth/checked_service_ticket.h> - -namespace NTvmAuth { - static const char* EX_MSG = "Ticket already moved out"; - - TCheckedServiceTicket::TCheckedServiceTicket(THolder<TImpl> impl) - : Impl_(std::move(impl)) - { - } - - TCheckedServiceTicket::TCheckedServiceTicket(TCheckedServiceTicket&& o) = default; - TCheckedServiceTicket& TCheckedServiceTicket::operator=(TCheckedServiceTicket&& o) = default; - TCheckedServiceTicket::~TCheckedServiceTicket() = default; - - TCheckedServiceTicket::operator bool() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->operator bool(); - } - - TTvmId TCheckedServiceTicket::GetSrc() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetSrc(); - } - - ETicketStatus TCheckedServiceTicket::GetStatus() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetStatus(); - } - - TString TCheckedServiceTicket::DebugInfo() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->DebugInfo(); - } - - TMaybe<TUid> TCheckedServiceTicket::GetIssuerUid() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetIssuerUid(); - } -} +#include "service_impl.h" + +#include <library/cpp/tvmauth/checked_service_ticket.h> + +namespace NTvmAuth { + static const char* EX_MSG = "Ticket already moved out"; + + TCheckedServiceTicket::TCheckedServiceTicket(THolder<TImpl> impl) + : Impl_(std::move(impl)) + { + } + + TCheckedServiceTicket::TCheckedServiceTicket(TCheckedServiceTicket&& o) = default; + TCheckedServiceTicket& TCheckedServiceTicket::operator=(TCheckedServiceTicket&& o) = default; + TCheckedServiceTicket::~TCheckedServiceTicket() = default; + + TCheckedServiceTicket::operator bool() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->operator bool(); + } + + TTvmId TCheckedServiceTicket::GetSrc() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetSrc(); + } + + ETicketStatus TCheckedServiceTicket::GetStatus() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetStatus(); + } + + TString TCheckedServiceTicket::DebugInfo() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->DebugInfo(); + } + + TMaybe<TUid> TCheckedServiceTicket::GetIssuerUid() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetIssuerUid(); + } +} diff --git a/library/cpp/tvmauth/src/status.cpp b/library/cpp/tvmauth/src/status.cpp index fb871b40dc..1b08fc098f 100644 --- a/library/cpp/tvmauth/src/status.cpp +++ b/library/cpp/tvmauth/src/status.cpp @@ -1,32 +1,32 @@ -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/ticket_status.h> -#include <util/generic/yexception.h> - -namespace NTvmAuth { - TStringBuf StatusToString(ETicketStatus st) { +#include <util/generic/yexception.h> + +namespace NTvmAuth { + TStringBuf StatusToString(ETicketStatus st) { switch (st) { - case ETicketStatus::Ok: + case ETicketStatus::Ok: return "OK"; - case ETicketStatus::Expired: + case ETicketStatus::Expired: return "Expired ticket"; - case ETicketStatus::InvalidBlackboxEnv: + case ETicketStatus::InvalidBlackboxEnv: return "Invalid BlackBox environment"; - case ETicketStatus::InvalidDst: + case ETicketStatus::InvalidDst: return "Invalid ticket destination"; - case ETicketStatus::InvalidTicketType: + case ETicketStatus::InvalidTicketType: return "Invalid ticket type"; - case ETicketStatus::Malformed: + case ETicketStatus::Malformed: return "Malformed ticket"; - case ETicketStatus::MissingKey: - return "Context does not have required key to check ticket: public keys are too old"; - case ETicketStatus::SignBroken: + case ETicketStatus::MissingKey: + return "Context does not have required key to check ticket: public keys are too old"; + case ETicketStatus::SignBroken: return "Invalid ticket signature"; - case ETicketStatus::UnsupportedVersion: + case ETicketStatus::UnsupportedVersion: return "Unsupported ticket version"; - case ETicketStatus::NoRoles: - return "Subject (src or defaultUid) does not have any roles in IDM"; + case ETicketStatus::NoRoles: + return "Subject (src or defaultUid) does not have any roles in IDM"; } - ythrow yexception() << "Unexpected status: " << static_cast<int>(st); + ythrow yexception() << "Unexpected status: " << static_cast<int>(st); } -} +} diff --git a/library/cpp/tvmauth/src/unittest.cpp b/library/cpp/tvmauth/src/unittest.cpp index c0191d3fc6..5133d79ea9 100644 --- a/library/cpp/tvmauth/src/unittest.cpp +++ b/library/cpp/tvmauth/src/unittest.cpp @@ -1,14 +1,14 @@ -#include "service_impl.h" -#include "user_impl.h" - -#include <library/cpp/tvmauth/unittest.h> - -namespace NTvmAuth::NUnittest { - TCheckedServiceTicket CreateServiceTicket(ETicketStatus status, TTvmId src, TMaybe<TUid> issuerUid) { - return TCheckedServiceTicket(TCheckedServiceTicket::TImpl::CreateTicketForTests(status, src, issuerUid)); - } - - TCheckedUserTicket CreateUserTicket(ETicketStatus status, TUid defaultUid, const TScopes& scopes, const TUids& uids, EBlackboxEnv env) { - return TCheckedUserTicket(TCheckedUserTicket::TImpl::CreateTicketForTests(status, defaultUid, scopes, uids, env)); - } -} +#include "service_impl.h" +#include "user_impl.h" + +#include <library/cpp/tvmauth/unittest.h> + +namespace NTvmAuth::NUnittest { + TCheckedServiceTicket CreateServiceTicket(ETicketStatus status, TTvmId src, TMaybe<TUid> issuerUid) { + return TCheckedServiceTicket(TCheckedServiceTicket::TImpl::CreateTicketForTests(status, src, issuerUid)); + } + + TCheckedUserTicket CreateUserTicket(ETicketStatus status, TUid defaultUid, const TScopes& scopes, const TUids& uids, EBlackboxEnv env) { + return TCheckedUserTicket(TCheckedUserTicket::TImpl::CreateTicketForTests(status, defaultUid, scopes, uids, env)); + } +} diff --git a/library/cpp/tvmauth/src/user_impl.cpp b/library/cpp/tvmauth/src/user_impl.cpp index 2cd24f07aa..33002968d2 100644 --- a/library/cpp/tvmauth/src/user_impl.cpp +++ b/library/cpp/tvmauth/src/user_impl.cpp @@ -2,8 +2,8 @@ #include "parser.h" -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/ticket_status.h> #include <util/generic/strbuf.h> #include <util/string/cast.h> @@ -11,9 +11,9 @@ #include <algorithm> -namespace NTvmAuth { - static const char* EX_MSG = "Method cannot be used in non-valid ticket"; - +namespace NTvmAuth { + static const char* EX_MSG = "Method cannot be used in non-valid ticket"; + TStringBuf GetBlackboxEnvAsString(EBlackboxEnv environment) { switch (environment) { case (EBlackboxEnv::Prod): @@ -31,77 +31,77 @@ namespace NTvmAuth { } } - TCheckedUserTicket::TImpl::operator bool() const { - return (Status_ == ETicketStatus::Ok); + TCheckedUserTicket::TImpl::operator bool() const { + return (Status_ == ETicketStatus::Ok); } - TUid TCheckedUserTicket::TImpl::GetDefaultUid() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return ProtobufTicket_.user().defaultuid(); + TUid TCheckedUserTicket::TImpl::GetDefaultUid() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return ProtobufTicket_.user().defaultuid(); } - time_t TCheckedUserTicket::TImpl::GetExpirationTime() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return ProtobufTicket_.expirationtime(); + time_t TCheckedUserTicket::TImpl::GetExpirationTime() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return ProtobufTicket_.expirationtime(); } - const TScopes& TCheckedUserTicket::TImpl::GetScopes() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - if (CachedScopes_.empty()) { - for (const auto& el : ProtobufTicket_.user().scopes()) { - CachedScopes_.push_back(el); + const TScopes& TCheckedUserTicket::TImpl::GetScopes() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + if (CachedScopes_.empty()) { + for (const auto& el : ProtobufTicket_.user().scopes()) { + CachedScopes_.push_back(el); } } - return CachedScopes_; + return CachedScopes_; } - bool TCheckedUserTicket::TImpl::HasScope(TStringBuf scopeName) const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - return std::binary_search(ProtobufTicket_.user().scopes().begin(), ProtobufTicket_.user().scopes().end(), scopeName); + bool TCheckedUserTicket::TImpl::HasScope(TStringBuf scopeName) const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + return std::binary_search(ProtobufTicket_.user().scopes().begin(), ProtobufTicket_.user().scopes().end(), scopeName); } - ETicketStatus TCheckedUserTicket::TImpl::GetStatus() const { - return Status_; + ETicketStatus TCheckedUserTicket::TImpl::GetStatus() const { + return Status_; } - const TUids& TCheckedUserTicket::TImpl::GetUids() const { - Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); - if (CachedUids_.empty()) { - for (const auto& user : ProtobufTicket_.user().users()) { - CachedUids_.push_back(user.uid()); + const TUids& TCheckedUserTicket::TImpl::GetUids() const { + Y_ENSURE_EX(bool(*this), TNotAllowedException() << EX_MSG); + if (CachedUids_.empty()) { + for (const auto& user : ProtobufTicket_.user().users()) { + CachedUids_.push_back(user.uid()); } } - return CachedUids_; + return CachedUids_; } - TString TCheckedUserTicket::TImpl::DebugInfo() const { - if (CachedDebugInfo_) { - return CachedDebugInfo_; - } - - if (Status_ == ETicketStatus::Malformed) { - CachedDebugInfo_ = "status=malformed;"; - return CachedDebugInfo_; + TString TCheckedUserTicket::TImpl::DebugInfo() const { + if (CachedDebugInfo_) { + return CachedDebugInfo_; + } + + if (Status_ == ETicketStatus::Malformed) { + CachedDebugInfo_ = "status=malformed;"; + return CachedDebugInfo_; } - + TString targetString = "ticket_type="; - targetString.reserve(256); - if (Status_ == ETicketStatus::InvalidTicketType) { + targetString.reserve(256); + if (Status_ == ETicketStatus::InvalidTicketType) { targetString.append("not-user;"); - CachedDebugInfo_ = targetString; + CachedDebugInfo_ = targetString; return targetString; } - + targetString.append("user"); - if (ProtobufTicket_.expirationtime() > 0) - targetString.append(";expiration_time=").append(IntToString<10>(ProtobufTicket_.expirationtime())); - for (const auto& scope : ProtobufTicket_.user().scopes()) { + if (ProtobufTicket_.expirationtime() > 0) + targetString.append(";expiration_time=").append(IntToString<10>(ProtobufTicket_.expirationtime())); + for (const auto& scope : ProtobufTicket_.user().scopes()) { targetString.append(";scope=").append(scope); } - - if (ProtobufTicket_.user().defaultuid() > 0) - targetString.append(";default_uid=").append(IntToString<10>(ProtobufTicket_.user().defaultuid())); - for (const auto& user : ProtobufTicket_.user().users()) { + + if (ProtobufTicket_.user().defaultuid() > 0) + targetString.append(";default_uid=").append(IntToString<10>(ProtobufTicket_.user().defaultuid())); + for (const auto& user : ProtobufTicket_.user().users()) { targetString.append(";uid=").append(IntToString<10>(user.uid())); } @@ -109,66 +109,66 @@ namespace NTvmAuth { EBlackboxEnv environment = static_cast<EBlackboxEnv>(ProtobufTicket_.user().env()); targetString.append(GetBlackboxEnvAsString(environment)); targetString.append(";"); - - CachedDebugInfo_ = targetString; + + CachedDebugInfo_ = targetString; return targetString; } - EBlackboxEnv TCheckedUserTicket::TImpl::GetEnv() const { - return (EBlackboxEnv)ProtobufTicket_.user().env(); - } - - void TCheckedUserTicket::TImpl::SetStatus(ETicketStatus status) { - Status_ = status; - } - - TCheckedUserTicket::TImpl::TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket) - : Status_(status) - , ProtobufTicket_(std::move(protobufTicket)) + EBlackboxEnv TCheckedUserTicket::TImpl::GetEnv() const { + return (EBlackboxEnv)ProtobufTicket_.user().env(); + } + + void TCheckedUserTicket::TImpl::SetStatus(ETicketStatus status) { + Status_ = status; + } + + TCheckedUserTicket::TImpl::TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket) + : Status_(status) + , ProtobufTicket_(std::move(protobufTicket)) { } - TUserTicketImplPtr TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus status, - TUid defaultUid, - TScopes scopes, - TUids uids, - EBlackboxEnv env) { - auto prepareCont = [](auto& cont) { - std::sort(cont.begin(), cont.end()); - cont.erase(std::unique(cont.begin(), cont.end()), cont.end()); - }; - auto erase = [](auto& cont, auto val) { - auto it = std::find(cont.begin(), cont.end(), val); - if (it != cont.end()) { - cont.erase(it); - } - }; - - prepareCont(scopes); - erase(scopes, ""); - - uids.push_back(defaultUid); - prepareCont(uids); - erase(uids, 0); - Y_ENSURE(!uids.empty(), "User ticket cannot contain empty uid list"); - - ticket2::Ticket proto; - for (TUid uid : uids) { - proto.mutable_user()->add_users()->set_uid(uid); - } - proto.mutable_user()->set_defaultuid(defaultUid); - proto.mutable_user()->set_entrypoint(100500); - for (TStringBuf scope : scopes) { - proto.mutable_user()->add_scopes(TString(scope)); - } - - proto.mutable_user()->set_env((tvm_keys::BbEnvType)env); - - return MakeHolder<TImpl>(status, std::move(proto)); - } - + TUserTicketImplPtr TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus status, + TUid defaultUid, + TScopes scopes, + TUids uids, + EBlackboxEnv env) { + auto prepareCont = [](auto& cont) { + std::sort(cont.begin(), cont.end()); + cont.erase(std::unique(cont.begin(), cont.end()), cont.end()); + }; + auto erase = [](auto& cont, auto val) { + auto it = std::find(cont.begin(), cont.end(), val); + if (it != cont.end()) { + cont.erase(it); + } + }; + + prepareCont(scopes); + erase(scopes, ""); + + uids.push_back(defaultUid); + prepareCont(uids); + erase(uids, 0); + Y_ENSURE(!uids.empty(), "User ticket cannot contain empty uid list"); + + ticket2::Ticket proto; + for (TUid uid : uids) { + proto.mutable_user()->add_users()->set_uid(uid); + } + proto.mutable_user()->set_defaultuid(defaultUid); + proto.mutable_user()->set_entrypoint(100500); + for (TStringBuf scope : scopes) { + proto.mutable_user()->add_scopes(TString(scope)); + } + + proto.mutable_user()->set_env((tvm_keys::BbEnvType)env); + + return MakeHolder<TImpl>(status, std::move(proto)); + } + TUserContext::TImpl::TImpl(EBlackboxEnv env, TStringBuf tvmKeysResponse) - : Env_(env) + : Env_(env) { ResetKeys(tvmKeysResponse); } @@ -176,66 +176,66 @@ namespace NTvmAuth { void TUserContext::TImpl::ResetKeys(TStringBuf tvmKeysResponse) { tvm_keys::Keys protoKeys; if (!protoKeys.ParseFromString(TParserTvmKeys::ParseStrV1(tvmKeysResponse))) { - ythrow TMalformedTvmKeysException() << "Malformed TVM keys"; + ythrow TMalformedTvmKeysException() << "Malformed TVM keys"; } NRw::TPublicKeys keys; for (int idx = 0; idx < protoKeys.bb_size(); ++idx) { const tvm_keys::BbKey& k = protoKeys.bb(idx); - if (IsAllowed(k.env())) { + if (IsAllowed(k.env())) { keys.emplace(k.gen().id(), k.gen().body()); } } if (keys.empty()) { - ythrow TEmptyTvmKeysException() << "Empty TVM keys"; + ythrow TEmptyTvmKeysException() << "Empty TVM keys"; } - Keys_ = std::move(keys); + Keys_ = std::move(keys); } TUserTicketImplPtr TUserContext::TImpl::Check(TStringBuf ticketBody) const { - TParserTickets::TRes res = TParserTickets::ParseV3(ticketBody, Keys_, TParserTickets::UserFlag()); - ETicketStatus status = CheckProtobufUserTicket(res.Ticket); + TParserTickets::TRes res = TParserTickets::ParseV3(ticketBody, Keys_, TParserTickets::UserFlag()); + ETicketStatus status = CheckProtobufUserTicket(res.Ticket); - if (res.Status != ETicketStatus::Ok && !(res.Status == ETicketStatus::MissingKey && status == ETicketStatus::InvalidBlackboxEnv)) { + if (res.Status != ETicketStatus::Ok && !(res.Status == ETicketStatus::MissingKey && status == ETicketStatus::InvalidBlackboxEnv)) { status = res.Status; } - return MakeHolder<TCheckedUserTicket::TImpl>(status, std::move(res.Ticket)); + return MakeHolder<TCheckedUserTicket::TImpl>(status, std::move(res.Ticket)); } - ETicketStatus TUserContext::TImpl::CheckProtobufUserTicket(const ticket2::Ticket& ticket) const { + ETicketStatus TUserContext::TImpl::CheckProtobufUserTicket(const ticket2::Ticket& ticket) const { if (!ticket.has_user()) { - return ETicketStatus::Malformed; + return ETicketStatus::Malformed; } - if (!IsAllowed(ticket.user().env())) { - return ETicketStatus::InvalidBlackboxEnv; + if (!IsAllowed(ticket.user().env())) { + return ETicketStatus::InvalidBlackboxEnv; } - return ETicketStatus::Ok; + return ETicketStatus::Ok; } const NRw::TPublicKeys& TUserContext::TImpl::GetKeys() const { - return Keys_; + return Keys_; } - bool TUserContext::TImpl::IsAllowed(tvm_keys::BbEnvType env) const { - if (env == tvm_keys::Prod && (Env_ == EBlackboxEnv::Prod || Env_ == EBlackboxEnv::Stress)) { + bool TUserContext::TImpl::IsAllowed(tvm_keys::BbEnvType env) const { + if (env == tvm_keys::Prod && (Env_ == EBlackboxEnv::Prod || Env_ == EBlackboxEnv::Stress)) { return true; } - if (env == tvm_keys::ProdYateam && Env_ == EBlackboxEnv::ProdYateam) { + if (env == tvm_keys::ProdYateam && Env_ == EBlackboxEnv::ProdYateam) { return true; } - if (env == tvm_keys::Test && Env_ == EBlackboxEnv::Test) { + if (env == tvm_keys::Test && Env_ == EBlackboxEnv::Test) { return true; } - if (env == tvm_keys::TestYateam && Env_ == EBlackboxEnv::TestYateam) { + if (env == tvm_keys::TestYateam && Env_ == EBlackboxEnv::TestYateam) { return true; } - if (env == tvm_keys::Stress && Env_ == EBlackboxEnv::Stress) { + if (env == tvm_keys::Stress && Env_ == EBlackboxEnv::Stress) { return true; } return false; } -} +} diff --git a/library/cpp/tvmauth/src/user_impl.h b/library/cpp/tvmauth/src/user_impl.h index 7be3b9b4ea..e3f1099b90 100644 --- a/library/cpp/tvmauth/src/user_impl.h +++ b/library/cpp/tvmauth/src/user_impl.h @@ -1,18 +1,18 @@ #pragma once -#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> -#include <library/cpp/tvmauth/src/protos/tvm_keys.pb.h> -#include <library/cpp/tvmauth/src/rw/keys.h> +#include <library/cpp/tvmauth/src/protos/ticket2.pb.h> +#include <library/cpp/tvmauth/src/protos/tvm_keys.pb.h> +#include <library/cpp/tvmauth/src/rw/keys.h> -#include <library/cpp/tvmauth/deprecated/user_context.h> +#include <library/cpp/tvmauth/deprecated/user_context.h> -#include <library/cpp/charset/ci_string.h> +#include <library/cpp/charset/ci_string.h> #include <unordered_map> -namespace NTvmAuth { - using TUserTicketImplPtr = THolder<TCheckedUserTicket::TImpl>; - class TCheckedUserTicket::TImpl { +namespace NTvmAuth { + using TUserTicketImplPtr = THolder<TCheckedUserTicket::TImpl>; + class TCheckedUserTicket::TImpl { public: explicit operator bool() const; @@ -20,36 +20,36 @@ namespace NTvmAuth { time_t GetExpirationTime() const; const TScopes& GetScopes() const; bool HasScope(TStringBuf scopeName) const; - ETicketStatus GetStatus() const; + ETicketStatus GetStatus() const; const TUids& GetUids() const; TString DebugInfo() const; - EBlackboxEnv GetEnv() const; - - void SetStatus(ETicketStatus status); - + EBlackboxEnv GetEnv() const; + + void SetStatus(ETicketStatus status); + /*! * Constructor for creation invalid ticket storing error status in TServiceContext * @param status * @param protobufTicket */ - TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket); - - static TUserTicketImplPtr CreateTicketForTests(ETicketStatus status, - TUid defaultUid, - TScopes scopes, - TUids uids, - EBlackboxEnv env = EBlackboxEnv::Test); - + TImpl(ETicketStatus status, ticket2::Ticket&& protobufTicket); + + static TUserTicketImplPtr CreateTicketForTests(ETicketStatus status, + TUid defaultUid, + TScopes scopes, + TUids uids, + EBlackboxEnv env = EBlackboxEnv::Test); + private: static const int MaxUserCount = 15; - ETicketStatus Status_; - ticket2::Ticket ProtobufTicket_; - mutable TScopes CachedScopes_; - mutable TUids CachedUids_; - mutable TString CachedDebugInfo_; + ETicketStatus Status_; + ticket2::Ticket ProtobufTicket_; + mutable TScopes CachedScopes_; + mutable TUids CachedUids_; + mutable TString CachedDebugInfo_; }; class TUserContext::TImpl { @@ -60,13 +60,13 @@ namespace NTvmAuth { TUserTicketImplPtr Check(TStringBuf ticketBody) const; const NRw::TPublicKeys& GetKeys() const; - bool IsAllowed(tvm_keys::BbEnvType env) const; + bool IsAllowed(tvm_keys::BbEnvType env) const; private: - ETicketStatus CheckProtobufUserTicket(const ticket2::Ticket& ticket) const; + ETicketStatus CheckProtobufUserTicket(const ticket2::Ticket& ticket) const; - NRw::TPublicKeys Keys_; - EBlackboxEnv Env_; - ::google::protobuf::LogSilencer LogSilencer_; + NRw::TPublicKeys Keys_; + EBlackboxEnv Env_; + ::google::protobuf::LogSilencer LogSilencer_; }; -} +} diff --git a/library/cpp/tvmauth/src/user_ticket.cpp b/library/cpp/tvmauth/src/user_ticket.cpp index 0df1d5157a..3e4e0c0364 100644 --- a/library/cpp/tvmauth/src/user_ticket.cpp +++ b/library/cpp/tvmauth/src/user_ticket.cpp @@ -1,56 +1,56 @@ -#include "user_impl.h" - -#include <library/cpp/tvmauth/checked_user_ticket.h> - -namespace NTvmAuth { - static const char* EX_MSG = "Ticket already moved out"; - - TCheckedUserTicket::TCheckedUserTicket(THolder<TCheckedUserTicket::TImpl> impl) - : Impl_(std::move(impl)) - { - } - - TCheckedUserTicket::TCheckedUserTicket(TCheckedUserTicket&& o) = default; - TCheckedUserTicket::~TCheckedUserTicket() = default; - TCheckedUserTicket& TCheckedUserTicket::operator=(TCheckedUserTicket&& o) = default; - - TCheckedUserTicket::operator bool() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->operator bool(); - } - - const TUids& TCheckedUserTicket::GetUids() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetUids(); - } - - TUid TCheckedUserTicket::GetDefaultUid() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetDefaultUid(); - } - - const TScopes& TCheckedUserTicket::GetScopes() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetScopes(); - } - - bool TCheckedUserTicket::HasScope(TStringBuf scopeName) const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->HasScope(scopeName); - } - - ETicketStatus TCheckedUserTicket::GetStatus() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetStatus(); - } - - TString TCheckedUserTicket::DebugInfo() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->DebugInfo(); - } - - EBlackboxEnv TCheckedUserTicket::GetEnv() const { - Y_ENSURE(Impl_, EX_MSG); - return Impl_->GetEnv(); - } -} +#include "user_impl.h" + +#include <library/cpp/tvmauth/checked_user_ticket.h> + +namespace NTvmAuth { + static const char* EX_MSG = "Ticket already moved out"; + + TCheckedUserTicket::TCheckedUserTicket(THolder<TCheckedUserTicket::TImpl> impl) + : Impl_(std::move(impl)) + { + } + + TCheckedUserTicket::TCheckedUserTicket(TCheckedUserTicket&& o) = default; + TCheckedUserTicket::~TCheckedUserTicket() = default; + TCheckedUserTicket& TCheckedUserTicket::operator=(TCheckedUserTicket&& o) = default; + + TCheckedUserTicket::operator bool() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->operator bool(); + } + + const TUids& TCheckedUserTicket::GetUids() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetUids(); + } + + TUid TCheckedUserTicket::GetDefaultUid() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetDefaultUid(); + } + + const TScopes& TCheckedUserTicket::GetScopes() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetScopes(); + } + + bool TCheckedUserTicket::HasScope(TStringBuf scopeName) const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->HasScope(scopeName); + } + + ETicketStatus TCheckedUserTicket::GetStatus() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetStatus(); + } + + TString TCheckedUserTicket::DebugInfo() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->DebugInfo(); + } + + EBlackboxEnv TCheckedUserTicket::GetEnv() const { + Y_ENSURE(Impl_, EX_MSG); + return Impl_->GetEnv(); + } +} diff --git a/library/cpp/tvmauth/src/ut/parser_ut.cpp b/library/cpp/tvmauth/src/ut/parser_ut.cpp index b6c6ef467b..530f45331a 100644 --- a/library/cpp/tvmauth/src/ut/parser_ut.cpp +++ b/library/cpp/tvmauth/src/ut/parser_ut.cpp @@ -1,13 +1,13 @@ -#include <library/cpp/tvmauth/src/parser.h> -#include <library/cpp/tvmauth/src/utils.h> +#include <library/cpp/tvmauth/src/parser.h> +#include <library/cpp/tvmauth/src/utils.h> -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/ticket_status.h> #include <library/cpp/testing/unittest/registar.h> - + Y_UNIT_TEST_SUITE(ParserTestSuite) { - using namespace NTvmAuth; + using namespace NTvmAuth; Y_UNIT_TEST(Keys) { UNIT_ASSERT_EXCEPTION(TParserTvmKeys::ParseStrV1("2:asds"), TMalformedTvmKeysException); @@ -18,69 +18,69 @@ Y_UNIT_TEST_SUITE(ParserTestSuite) { } Y_UNIT_TEST(TicketsStrV3) { - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Ok, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Ok, NUtils::Base64url2bin("CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg"), NUtils::Base64url2bin("ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA"), "3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:"}), TParserTickets::ParseStrV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::UnsupportedVersion, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::UnsupportedVersion, {}, {}, {}}), TParserTickets::ParseStrV3("2:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::InvalidTicketType, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::InvalidTicketType, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::UserFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv::ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA:asd", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv:CgY+-*/IDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, {}, {}, {}}), TParserTickets::ParseStrV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERme/*-+H_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, - {}, - {}, - {}}), - TParserTickets::ParseStrV3("", - TParserTickets::ServiceFlag())); - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, - {}, - {}, - {}}), - TParserTickets::ParseStrV3("'", - TParserTickets::ServiceFlag())); + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + {}, + {}, + {}}), + TParserTickets::ParseStrV3("", + TParserTickets::ServiceFlag())); + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Malformed, + {}, + {}, + {}}), + TParserTickets::ParseStrV3("'", + TParserTickets::ServiceFlag())); // Invalid proto - UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Ok, + UNIT_ASSERT_EQUAL(TParserTickets::TStrRes({ETicketStatus::Ok, NUtils::Base64url2bin("YIDRCUkQYBgcIgdiYjpzZXNzIghiYjpzZXNzMg"), NUtils::Base64url2bin("ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA"), "3:serv:YIDRCUkQYBgcIgdiYjpzZXNzIghiYjpzZXNzMg:"}), @@ -91,50 +91,50 @@ Y_UNIT_TEST_SUITE(ParserTestSuite) { Y_UNIT_TEST(TicketsV3) { NRw::TPublicKeys pub; - UNIT_ASSERT_EQUAL(ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(ETicketStatus::Malformed, TParserTickets::ParseV3("3:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERme/*-+H_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", pub, TParserTickets::ServiceFlag()) .Status); // Invalid proto - UNIT_ASSERT_EQUAL(ETicketStatus::Malformed, + UNIT_ASSERT_EQUAL(ETicketStatus::Malformed, TParserTickets::ParseV3("3:serv:YIDRCUkQYBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA", pub, TParserTickets::ServiceFlag()) .Status); // Expire time == 100500 - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, TParserTickets::ParseV3("3:serv:CBAQlJEGIhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:HEzPbsjULegBvgX3nqwFX0GfVhESmN1kEWyeT7U03KAR-sQnNYgm6IuN-b9-lQYQKAJSW6p8ffyucC1yDrWSWRxXVzHJUxAVW4hnbiFDtXrurnEdpMK3izKbmTY25PJ4vH3_TkRXk-_oSAE8RvIFKXlh-aw1tezbXBUpJKvyJ0w", pub, TParserTickets::ServiceFlag()) .Status); - UNIT_ASSERT_EQUAL(ETicketStatus::MissingKey, + UNIT_ASSERT_EQUAL(ETicketStatus::MissingKey, TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:OKjKEbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qU", pub, TParserTickets::ServiceFlag()) .Status); pub.emplace(16, NRw::TRwPublicKey(NUtils::Base64url2bin("MIGEAoGBALhrihbf3EpjDQS2sCQHazoFgN0nBbE9eesnnFTfzQELXb2gnJU9enmV_aDqaHKjgtLIPpCgn40lHrn5k6mvH5OdedyI6cCzE-N-GFp3nAq0NDJyMe0fhtIRD__CbT0ulcvkeow65ubXWfw6dBC2gR_34rdMe_L_TGRLMWjDULbN"))); - UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, + UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMa:OKjKEbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qU", pub, TParserTickets::ServiceFlag()) .Status); - UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, + UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:OKjKEbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qa", pub, TParserTickets::ServiceFlag()) .Status); - UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, - TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:EbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qU", + UNIT_ASSERT_EQUAL(ETicketStatus::SignBroken, + TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:EbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qU", pub, TParserTickets::ServiceFlag()) .Status); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, TParserTickets::ParseV3("3:serv:CBAQ__________9_IhcIDBAcGgdiYjpzZXNzGghiYjpzZXNzMg:OKjKEbygehEZWH0XEeLzvf0q0aS0VvSk_CKSXGdpqxPbE4RzU70jeM-X9rXVpbYjt76VgBLlBpumJdyiclulfGPDPiL8nwJuu8AnWIR_o-QqyXbsloo2_syE6w2aYw2Yw_5_qjnipYdxGUWegHAGCj3yeMde6O2BmNZ0OCfg6qU", pub, TParserTickets::ServiceFlag()) diff --git a/library/cpp/tvmauth/src/ut/public_ut.cpp b/library/cpp/tvmauth/src/ut/public_ut.cpp index ba7c5afa86..74a483d57b 100644 --- a/library/cpp/tvmauth/src/ut/public_ut.cpp +++ b/library/cpp/tvmauth/src/ut/public_ut.cpp @@ -1,197 +1,197 @@ -// DO_NOT_STYLE -#include <library/cpp/tvmauth/src/service_impl.h> -#include <library/cpp/tvmauth/src/user_impl.h> +// DO_NOT_STYLE +#include <library/cpp/tvmauth/src/service_impl.h> +#include <library/cpp/tvmauth/src/user_impl.h> -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/ticket_status.h> -#include <library/cpp/tvmauth/unittest.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/unittest.h> #include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; - + +using namespace NTvmAuth; + Y_UNIT_TEST_SUITE(CommonPublicInterfaceTestSuite){ Y_UNIT_TEST(StatusTest){ UNIT_ASSERT_VALUES_EQUAL("OK", - StatusToString(ETicketStatus::Ok)); + StatusToString(ETicketStatus::Ok)); UNIT_ASSERT_VALUES_EQUAL("Expired ticket", - StatusToString(ETicketStatus::Expired)); + StatusToString(ETicketStatus::Expired)); UNIT_ASSERT_VALUES_EQUAL("Invalid BlackBox environment", - StatusToString(ETicketStatus::InvalidBlackboxEnv)); + StatusToString(ETicketStatus::InvalidBlackboxEnv)); UNIT_ASSERT_VALUES_EQUAL("Invalid ticket destination", - StatusToString(ETicketStatus::InvalidDst)); + StatusToString(ETicketStatus::InvalidDst)); UNIT_ASSERT_VALUES_EQUAL("Invalid ticket type", - StatusToString(ETicketStatus::InvalidTicketType)); + StatusToString(ETicketStatus::InvalidTicketType)); UNIT_ASSERT_VALUES_EQUAL("Malformed ticket", - StatusToString(ETicketStatus::Malformed)); + StatusToString(ETicketStatus::Malformed)); UNIT_ASSERT_VALUES_EQUAL("Invalid ticket signature", - StatusToString(ETicketStatus::SignBroken)); + StatusToString(ETicketStatus::SignBroken)); UNIT_ASSERT_VALUES_EQUAL("Context does not have required key to check ticket: public keys are too old", - StatusToString(ETicketStatus::MissingKey)); + StatusToString(ETicketStatus::MissingKey)); UNIT_ASSERT_VALUES_EQUAL("Unsupported ticket version", - StatusToString(ETicketStatus::UnsupportedVersion)); + StatusToString(ETicketStatus::UnsupportedVersion)); } -} +} Y_UNIT_TEST_SUITE(PublicInterfaceServiceTestSuite) { static const TString EMPTY_TVM_KEYS = "1:CpgCCpMCCAEQABqIAjCCAQQCggEAcLEXeH67FQESFUn4_7wnX7wN0PUrBoUsm3QQ4W5vC-qz6sXaEjSwnTV8w1o-z6X9KPLlhzMQvuS38NCNfK4uvJ4Zvfp3YsXJ25-rYtbnrYJHNvHohD-kPCCw_yZpMp21JdWigzQGuV7CtrxUhF-NNrsnUaJrE5-OpEWNt4X6nCItKIYeVcSK6XJUbEWbrNCRbvkSc4ak2ymFeMuHYJVjxh4eQbk7_ZPzodP0WvF6eUYrYeb42imVEOR8ofVLQWE5DVnb1z_TqZm4i1XkS7jMwZuBxBRw8DGdYei0lT_sAf7KST2jC0590NySB3vsBgWEVs1OdUUWA6r-Dvx9dsOQtSCVkQYQAAqZAgqUAggCEAAaiQIwggEFAoIBAQDhEBM5-6YsPWfogKtbluJoCX1WV2KdzOaQ0-OlRbBzeCzw-eQKu12c8WakHBbeCMd1I1TU64SDkDorWjXGIa_2xT6N3zzNAE50roTbPCcmeQrps26woTYfYIuqDdoxYKZNr0lvNLLW47vBr7EKqo1S4KSj7aXK_XYeEvUgIgf3nVIcNrio7VTnFmGGVQCepaL1Hi1gN4yIXjVZ06PBPZ-DxSRu6xOGbFrfKMJeMPs7KOyE-26Q3xOXdTIa1X-zYIucTd_bxUCL4BVbwW2AvbbFsaG7ISmVdGu0XUTmhXs1KrEfUVLRJhE4Dx99hAZXm1_HlYMUeJcMQ_oHOhV94ENFIJaRBhACCpYBCpEBCAMQABqGATCBgwKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NIJeRBhABCpYBCpEBCAQQABqGATCBgwKBgGB4d6eLGUBv-Q6EPLehC4S-yuE2HB-_rJ7WkeYwyp-xIPolPrd-PQme2utHB4ZgpXHIu_OFksDe_0bPgZniNRSVRbl7W49DgS5Ya3kMfrYB4DnF5Fta5tn1oV6EwxYD4JONpFTenOJALPGTPawxXEfon_peiHOSBuQMu3_Vn-l1IJiRBhADCpcBCpIBCAUQABqHATCBhAKBgQCTJMKIfmfeZpaI7Q9rnsc29gdWawK7TnpVKRHws1iY7EUlYROeVcMdAwEqVM6f8BVCKLGgzQ7Gar_uuxfUGKwqEQzoppDraw4F75J464-7D5f6_oJQuGIBHZxqbMONtLjBCXRUhQW5szBLmTQ_R3qaJb5vf-h0APZfkYhq1cTttSCZkQYQBAqWAQqRAQgLEAAahgEwgYMCgYBvvGVH_M2H8qxxv94yaDYUTWbRnJ1uiIYc59KIQlfFimMPhSS7x2tqUa2-hI55JiII0Xym6GNkwLhyc1xtWChpVuIdSnbvttbrt4weDMLHqTwNOF6qAsVKGKT1Yh8yf-qb-DSmicgvFc74mBQm_6gAY1iQsf33YX8578ClhKBWHSCVkQYQAAqXAQqSAQgMEAAahwEwgYQCgYEAkuzFcd5TJu7lYWYe2hQLFfUWIIj91BvQQLa_Thln4YtGCO8gG1KJqJm-YlmJOWQG0B7H_5RVhxUxV9KpmFnsDVkzUFKOsCBaYGXc12xPVioawUlAwp5qp3QQtZyx_se97YIoLzuLr46UkLcLnkIrp-Jo46QzYi_QHq45WTm8MQ0glpEGEAIKlwEKkgEIDRAAGocBMIGEAoGBAIUzbxOknXf_rNt17_ir8JlWvrtnCWsQd1MAnl5mgArvavDtKeBYHzi5_Ak7DHlLzuA6YE8W175FxLFKpN2hkz-l-M7ltUSd8N1BvJRhK4t6WffWfC_1wPyoAbeSN2Yb1jygtZJQ8wGoXHcJQUXiMit3eFNyylwsJFj1gzAR4JCdIJeRBhABCpYBCpEBCA4QABqGATCBgwKBgFMcbEpl9ukVR6AO_R6sMyiU11I8b8MBSUCEC15iKsrVO8v_m47_TRRjWPYtQ9eZ7o1ocNJHaGUU7qqInFqtFaVnIceP6NmCsXhjs3MLrWPS8IRAy4Zf4FKmGOx3N9O2vemjUygZ9vUiSkULdVrecinRaT8JQ5RG4bUMY04XGIwFIJiRBhADCpYBCpEBCA8QABqGATCBgwKBgGpCkW-NR3li8GlRvqpq2YZGSIgm_PTyDI2Zwfw69grsBmPpVFW48Vw7xoMN35zcrojEpialB_uQzlpLYOvsMl634CRIuj-n1QE3-gaZTTTE8mg-AR4mcxnTKThPnRQpbuOlYAnriwiasWiQEMbGjq_HmWioYYxFo9USlklQn4-9IJmRBhAE"; static const TString EXPIRED_SERVICE_TICKET = "3:serv:CBAQACIZCOUBEBwaCGJiOnNlc3MxGghiYjpzZXNzMg:IwfMNJYEqStY_SixwqJnyHOMCPR7-3HHk4uylB2oVRkthtezq-OOA7QizDvx7VABLs_iTlXuD1r5IjufNei_EiV145eaa3HIg4xCdJXCojMexf2UYJz8mF2b0YzFAy6_KWagU7xo13CyKAqzJuQf5MJcSUf0ecY9hVh36cJ51aw"; static const TString MALFORMED_TVM_KEYS = "1:CpgCCpMCCAEQABqIAjCCAQQCggEAcLEXeH67FQESFUn4_7wnX7wN0PUrBoUsm3QQ4W5vC-qz6sXaEjSwnTV8w1o-z6X9KPLlhzMQvuS38NCNfK4uvJ4Zvfp3YsXJ25-rYtbnrYJHNvHohD-kPCCw_yZpMp21JdWigzQGuV7CtrxUhF-NNrsnUaJrE5-OpEWNt4X6nCItKIYeVcSK6XJUbEWbrNCRbvkSc4ak2ymFeMuHYJVjxh4eQbk7_ZPzodP0WvF6eUYrYeb42imVEOR8ofVLQWE5DVnb1z_TqZm4i1XkS7jMwZuBxBRw8DGdYei0lT_sAf7KST2jC0590NySB3vsBgWEVs1OdUUWA6r-Dvx9dsOQtSCVkQYQAAqZAgqUAggCEAAaiQIwggEFAoIBAQDhEBM5-6YsPWfogKtbluJoCX1WV2KdzOaQ0-OlRbBzeCzw-eQKu12c8WakHBbeCMd1I1TU64SDkDorWjXGIa_2xT6N3zzNAE50roTbPCcmeQrps26woTYfYIuqDdoxYKZNr0lvNLLW47vBr7EKqo1S4KSj7aXK_XYeEvUgIgf3nVIcNrio7VTnFmGGVQCepaL1Hi1gN4yIXjVZ06PBPZ-DxSRu6xOGbFrfKMJeMPs7KOyE-26Q3xOXdTIa1X-zYIucTd_bxUCL4BVbwW2AvbbFsaG7ISmVdGu0XUTmhXs1KrEfUVLRJhE4Dx99hAZXm1_HlYMUeJcMQ_oHOhV94ENFIJaRBhACCpYBCpEBCAMQABqGATCBgwKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NIJeRBhABCpYBCpEBCAQQABqGATCBgwKBgGB4d6eLGUBv-Q6EPLehC4S-yuE2HB-_rJ7WkeYwyp-xIPolPrd-PQme2utHB4ZgpXHIu_OFksDe_0bPgZniNRSVRbl7W49DgS5Ya3kMfrYB4DnF5Fta5tn1oV6EwxYD4JONpFTenOJALPGTPawxXEfon_peiHOSBuQMu3_Vn-l1IJiRBhADCpcBCpIBCAUQABqHATCBhAKBgQCTJMKIfmfeZpaI7Q9rnsc29gdWawK7TnpVKRHws1iY7EUlYROeVcMdAwEqVM6f8BVCKLGgzQ7Gar_uuxfUGKwqEQzoppDraw4F75J464-7D5f6_oJQuGIBHZxqbMONtLjBCXRUhQW5szBLmTQ_R3qaJb5vf-h0APZfkYhq1cTttSCZkQYQBAqWAQqRAQgLEAAahgEwgYMCgYBvvGVH_M2H8qxxv94yaDYUTWbRnJ1uiIYc59KIQlfFimMPhSS7x2tqUa2-hI55JiII0Xym6GNkwLhyc1xtWChpVuIdSnbvttbrt4weDMLHqTwNOF6qAsVKGKT1Yh8yf-qb-DSmicgvFc74mBQm_6gAY1iQsf33YX8578ClhKBWHSCVkQYQAAqXAQqSAQgMEAAahwEwgYQCgYEAkuzFcd5TJu7lYWYe2hQLFfUWIIj91BvQQLa_Thln4YtGCO8gG1KJqJm-YlmJOWQG0B7H_5RVhxUxV9KpmFnsDVkzUFKOsCBaYGXc12xPVioawUlAwp5qp3QQtZyx_se97YIoLzuLr46UkLcLnkIrp-Jo46QzYi_QHq45WTm8MQ0glpEGEAIKlwEKkgEIDRAAGocBMIGEAoGBAIUzbxOknXf_rNt17_ir8JlWvrtnCWsQd1MAnl5mgArvavDtKeBYHzi5_Ak7DHlLzuA6YE8W175FxLFKpN2hkz-l-M7ltUSd8N1BvJRhK4t6WffWfC_1wPyoAbeSN2Yb1jygtZJQ8wGoXHcJQUXiMit3eFNyylwsJFj1gzAR4JCdIJeRBhABCpYBCpEBCA4QABqGATCBgwKBgFMcbEpl9ukVR6AO_R6sMyiU11I8b8MBSUCEC15iKsrVO8v_m47_TRRjWPYtQ9eZ7o1ocNJHaGUU7qqInFqtFaVnIceP6NmCsXhjs3MLrWPS8IRAy4Zf4FKmGOx3N9O2vemjUygZ9vUiSkULdVrecinRaT8JQ5RG4bUMY04XGIwFIJiRBhADCpYBCpEBCA8QABqGATCBgwKBgGpCkW-NR3li8GlRvqpq2YZGSIgm_PTyDI2Zwfw69grsBmPpVFW48Vw7xoMN35zcrojEpialB_uQzlpLYOvsMl634CRIuj-n1QE3-gaZTTTE8mg-AR4mcxnTKThPnRQpbuOlYAnriwiasWiQEMbGjq_HmWioYYxFo9USlklQn4-9IJmRBhAEEpUBCpIBCAYQABqHATCBhAKBgQCoZkFGm9oLTqjeXZAq6j5S6i7K20V0lNdBBLqfmFBIRuTkYxhs4vUYnWjZrKRAd5bp6_py0csmFmpl_5Yh0b-2pdo_E5PNP7LGRzKyKSiFddyykKKzVOazH8YYldDAfE8Z5HoS9e48an5JsPg0jr-TPu34DnJq3yv2a6dqiKL9zSCakQYSlQEKkgEIEBAAGocBMIGEAoGBALhrihbf3EpjDQS2sCQHazoFgN0nBbE9eesnnFTfzQELXb2gnJU9enmV_aDqaHKjgtLIPpCgn40lHrn5k6mvH5OdedyI6cCzE-N-GFp3nAq0NDJyMe0fhtIRD__CbT0ulcvkeow65ubXWfw6dBC2gR_34rdMe_L_TGRLMWjDULbNIJ"; static const TString MALFORMED_TVM_SECRET = "adcvxcv./-+"; - static const TTvmId NOT_OUR_ID = 27; - static const TTvmId OUR_ID = 28; + static const TTvmId NOT_OUR_ID = 27; + static const TTvmId OUR_ID = 28; static const TString SECRET = "GRMJrKnj4fOVnvOqe-WyD1"; static const TString SERVICE_TICKET_PROTOBUF = "CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My"; - static const TTvmId SRC_ID = 229; + static const TTvmId SRC_ID = 229; static const TString UNSUPPORTED_VERSION_SERVICE_TICKET = "2:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; static const TString VALID_SERVICE_TICKET_1 = "3:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; static const TString VALID_SERVICE_TICKET_2 = "3:serv:CBAQ__________9_IskICOUBEBwaCGJiOnNlc3MxGgliYjpzZXNzMTAaCmJiOnNlc3MxMDAaCWJiOnNlc3MxMRoJYmI6c2VzczEyGgliYjpzZXNzMTMaCWJiOnNlc3MxNBoJYmI6c2VzczE1GgliYjpzZXNzMTYaCWJiOnNlc3MxNxoJYmI6c2VzczE4GgliYjpzZXNzMTkaCGJiOnNlc3MyGgliYjpzZXNzMjAaCWJiOnNlc3MyMRoJYmI6c2VzczIyGgliYjpzZXNzMjMaCWJiOnNlc3MyNBoJYmI6c2VzczI1GgliYjpzZXNzMjYaCWJiOnNlc3MyNxoJYmI6c2VzczI4GgliYjpzZXNzMjkaCGJiOnNlc3MzGgliYjpzZXNzMzAaCWJiOnNlc3MzMRoJYmI6c2VzczMyGgliYjpzZXNzMzMaCWJiOnNlc3MzNBoJYmI6c2VzczM1GgliYjpzZXNzMzYaCWJiOnNlc3MzNxoJYmI6c2VzczM4GgliYjpzZXNzMzkaCGJiOnNlc3M0GgliYjpzZXNzNDAaCWJiOnNlc3M0MRoJYmI6c2VzczQyGgliYjpzZXNzNDMaCWJiOnNlc3M0NBoJYmI6c2VzczQ1GgliYjpzZXNzNDYaCWJiOnNlc3M0NxoJYmI6c2VzczQ4GgliYjpzZXNzNDkaCGJiOnNlc3M1GgliYjpzZXNzNTAaCWJiOnNlc3M1MRoJYmI6c2VzczUyGgliYjpzZXNzNTMaCWJiOnNlc3M1NBoJYmI6c2VzczU1GgliYjpzZXNzNTYaCWJiOnNlc3M1NxoJYmI6c2VzczU4GgliYjpzZXNzNTkaCGJiOnNlc3M2GgliYjpzZXNzNjAaCWJiOnNlc3M2MRoJYmI6c2VzczYyGgliYjpzZXNzNjMaCWJiOnNlc3M2NBoJYmI6c2VzczY1GgliYjpzZXNzNjYaCWJiOnNlc3M2NxoJYmI6c2VzczY4GgliYjpzZXNzNjkaCGJiOnNlc3M3GgliYjpzZXNzNzAaCWJiOnNlc3M3MRoJYmI6c2VzczcyGgliYjpzZXNzNzMaCWJiOnNlc3M3NBoJYmI6c2Vzczc1GgliYjpzZXNzNzYaCWJiOnNlc3M3NxoJYmI6c2Vzczc4GgliYjpzZXNzNzkaCGJiOnNlc3M4GgliYjpzZXNzODAaCWJiOnNlc3M4MRoJYmI6c2VzczgyGgliYjpzZXNzODMaCWJiOnNlc3M4NBoJYmI6c2Vzczg1GgliYjpzZXNzODYaCWJiOnNlc3M4NxoJYmI6c2Vzczg4GgliYjpzZXNzODkaCGJiOnNlc3M5GgliYjpzZXNzOTAaCWJiOnNlc3M5MRoJYmI6c2VzczkyGgliYjpzZXNzOTMaCWJiOnNlc3M5NBoJYmI6c2Vzczk1GgliYjpzZXNzOTYaCWJiOnNlc3M5NxoJYmI6c2Vzczk4GgliYjpzZXNzOTk:JYmABAVLM6y7_T4n1pRcwBfwDfzMV4JJ3cpbEG617zdGgKRZwL7MalsYn5bq1F2ibujMrsF9nzZf8l4s_e-Ivjkz_xu4KMzSp-pUh9V7XIF_smj0WHYpv6gOvWNuK8uIvlZTTKwtQX0qZOL9m-MEeZiHoQPKZGCfJ_qxMUp-J8I"; static const TString VALID_SERVICE_TICKET_3 = "3:serv:CBAQ__________9_IgUI5QEQHA:Sd6tmA1CNy2Nf7XevC3x7zr2DrGNRmcl-TxUsDtDW2xI3YXyCxBltWeg0-KtDlqyYuPOP5Jd_-XXNA12KlOPnNzrz3jm-5z8uQl6CjCcrVHUHJ75pGC8r9UOlS8cOgeXQB5dYP-fOWyo5CNadlozx1S2meCIxncbQRV1kCBi4KU"; - Y_UNIT_TEST(BlackboxTvmIdTest) { - UNIT_ASSERT_VALUES_EQUAL("222", NBlackboxTvmId::Prod); - UNIT_ASSERT_VALUES_EQUAL("224", NBlackboxTvmId::Test); - UNIT_ASSERT_VALUES_EQUAL("223", NBlackboxTvmId::ProdYateam); - UNIT_ASSERT_VALUES_EQUAL("225", NBlackboxTvmId::TestYateam); - UNIT_ASSERT_VALUES_EQUAL("226", NBlackboxTvmId::Stress); - UNIT_ASSERT_VALUES_EQUAL("239", NBlackboxTvmId::Mimino); - } + Y_UNIT_TEST(BlackboxTvmIdTest) { + UNIT_ASSERT_VALUES_EQUAL("222", NBlackboxTvmId::Prod); + UNIT_ASSERT_VALUES_EQUAL("224", NBlackboxTvmId::Test); + UNIT_ASSERT_VALUES_EQUAL("223", NBlackboxTvmId::ProdYateam); + UNIT_ASSERT_VALUES_EQUAL("225", NBlackboxTvmId::TestYateam); + UNIT_ASSERT_VALUES_EQUAL("226", NBlackboxTvmId::Stress); + UNIT_ASSERT_VALUES_EQUAL("239", NBlackboxTvmId::Mimino); + } Y_UNIT_TEST(Case1Test) { - TServiceContext context1(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context1(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); TServiceContext context2 = std::move(context1); TServiceContext context3(std::move(context2)); - TCheckedServiceTicket checkedTicket1 = context3.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket1.GetStatus()); - TCheckedServiceTicket checkedTicket2 = std::move(checkedTicket1); - TCheckedServiceTicket checkedTicket3(std::move(checkedTicket2)); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket3.GetStatus()); + TCheckedServiceTicket checkedTicket1 = context3.Check(VALID_SERVICE_TICKET_1); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket1.GetStatus()); + TCheckedServiceTicket checkedTicket2 = std::move(checkedTicket1); + TCheckedServiceTicket checkedTicket3(std::move(checkedTicket2)); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket3.GetStatus()); } Y_UNIT_TEST(ContextExceptionsTest) { - UNIT_ASSERT_EXCEPTION(TServiceContext(SECRET, OUR_ID, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); - UNIT_ASSERT_EXCEPTION(TServiceContext(SECRET, OUR_ID, EMPTY_TVM_KEYS), TEmptyTvmKeysException); - UNIT_ASSERT_EXCEPTION(TServiceContext(MALFORMED_TVM_SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS), TMalformedTvmSecretException); - } + UNIT_ASSERT_EXCEPTION(TServiceContext(SECRET, OUR_ID, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); + UNIT_ASSERT_EXCEPTION(TServiceContext(SECRET, OUR_ID, EMPTY_TVM_KEYS), TEmptyTvmKeysException); + UNIT_ASSERT_EXCEPTION(TServiceContext(MALFORMED_TVM_SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS), TMalformedTvmSecretException); + } Y_UNIT_TEST(ContextSignTest) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_VALUES_EQUAL( "NsPTYak4Cfk-4vgau5lab3W4GPiTtb2etuj3y4MDPrk", - context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "")); - } + context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "")); + } Y_UNIT_TEST(ContextSignExceptionTest) { - TServiceContext context = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EXCEPTION( context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", ""), TMalformedTvmSecretException ); - - context = TServiceContext::SigningFactory(SECRET); - UNIT_ASSERT_NO_EXCEPTION( - context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "") - ); - } + + context = TServiceContext::SigningFactory(SECRET); + UNIT_ASSERT_NO_EXCEPTION( + context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "") + ); + } Y_UNIT_TEST(ContextCheckExceptionTest) { - TServiceContext context = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - UNIT_ASSERT_NO_EXCEPTION( - context.Check("ABCDE") - ); - - context = TServiceContext::SigningFactory(SECRET); - UNIT_ASSERT_EXCEPTION( - context.Check("ABCDE"), - TEmptyTvmKeysException - ); - } - - + TServiceContext context = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + UNIT_ASSERT_NO_EXCEPTION( + context.Check("ABCDE") + ); + + context = TServiceContext::SigningFactory(SECRET); + UNIT_ASSERT_EXCEPTION( + context.Check("ABCDE"), + TEmptyTvmKeysException + ); + } + + Y_UNIT_TEST(ContextTest) { - TServiceContext context1(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - TServiceContext context2 = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - } + TServiceContext context1(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context2 = TServiceContext::CheckingFactory(OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + } Y_UNIT_TEST(Ticket1Test) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_EQUAL(SRC_ID, checkedTicket.GetSrc()); - UNIT_ASSERT_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess2;", checkedTicket.DebugInfo()); - } + UNIT_ASSERT_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess2;", checkedTicket.DebugInfo()); + } Y_UNIT_TEST(Ticket2Test) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_2); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess10;scope=bb:sess100;scope=bb:sess11;scope=bb:sess12;scope=bb:sess13;scope=bb:sess14;scope=bb:sess15;scope=bb:sess16;scope=bb:sess17;scope=bb:sess18;scope=bb:sess19;scope=bb:sess2;scope=bb:sess20;scope=bb:sess21;scope=bb:sess22;scope=bb:sess23;scope=bb:sess24;scope=bb:sess25;scope=bb:sess26;scope=bb:sess27;scope=bb:sess28;scope=bb:sess29;scope=bb:sess3;scope=bb:sess30;scope=bb:sess31;scope=bb:sess32;scope=bb:sess33;scope=bb:sess34;scope=bb:sess35;scope=bb:sess36;scope=bb:sess37;scope=bb:sess38;scope=bb:sess39;scope=bb:sess4;scope=bb:sess40;scope=bb:sess41;scope=bb:sess42;scope=bb:sess43;scope=bb:sess44;scope=bb:sess45;scope=bb:sess46;scope=bb:sess47;scope=bb:sess48;scope=bb:sess49;scope=bb:sess5;scope=bb:sess50;scope=bb:sess51;scope=bb:sess52;scope=bb:sess53;scope=bb:sess54;scope=bb:sess55;scope=bb:sess56;scope=bb:sess57;scope=bb:sess58;scope=bb:sess59;scope=bb:sess6;scope=bb:sess60;scope=bb:sess61;scope=bb:sess62;scope=bb:sess63;scope=bb:sess64;scope=bb:sess65;scope=bb:sess66;scope=bb:sess67;scope=bb:sess68;scope=bb:sess69;scope=bb:sess7;scope=bb:sess70;scope=bb:sess71;scope=bb:sess72;scope=bb:sess73;scope=bb:sess74;scope=bb:sess75;scope=bb:sess76;scope=bb:sess77;scope=bb:sess78;scope=bb:sess79;scope=bb:sess8;scope=bb:sess80;scope=bb:sess81;scope=bb:sess82;scope=bb:sess83;scope=bb:sess84;scope=bb:sess85;scope=bb:sess86;scope=bb:sess87;scope=bb:sess88;scope=bb:sess89;scope=bb:sess9;scope=bb:sess90;scope=bb:sess91;scope=bb:sess92;scope=bb:sess93;scope=bb:sess94;scope=bb:sess95;scope=bb:sess96;scope=bb:sess97;scope=bb:sess98;scope=bb:sess99;", checkedTicket.DebugInfo()); - } - + } + Y_UNIT_TEST(Ticket3Test) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_3); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;", checkedTicket.DebugInfo()); - } + } Y_UNIT_TEST(TicketCheckingTest) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto ticket = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, ticket.GetStatus()); UNIT_ASSERT_EQUAL(SRC_ID, ticket.GetSrc()); - } + } Y_UNIT_TEST(TicketErrorsTest) { - TServiceContext context(SECRET, NOT_OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, NOT_OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket1 = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::InvalidDst, checkedTicket1.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::InvalidDst, checkedTicket1.GetStatus()); auto checkedTicket2 = context.Check(UNSUPPORTED_VERSION_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket2.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket2.GetStatus()); auto checkedTicket3 = context.Check(EXPIRED_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket3.GetStatus()); - } + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket3.GetStatus()); + } Y_UNIT_TEST(TicketExceptionsTest) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(EXPIRED_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket.GetStatus()); UNIT_ASSERT(!bool(checkedTicket)); UNIT_ASSERT_EXCEPTION(checkedTicket.GetSrc(), TNotAllowedException); UNIT_ASSERT_NO_EXCEPTION(bool(checkedTicket)); UNIT_ASSERT_NO_EXCEPTION(checkedTicket.DebugInfo()); UNIT_ASSERT_NO_EXCEPTION(checkedTicket.GetStatus()); - } + } Y_UNIT_TEST(RemoveSignatureTest) { UNIT_ASSERT_VALUES_EQUAL("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("3:serv:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); UNIT_ASSERT_VALUES_EQUAL("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf", - NUtils::RemoveTicketSignature("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf")); - } + NUtils::RemoveTicketSignature("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf")); + } Y_UNIT_TEST(ResetKeysTest) { - TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - TCheckedServiceTicket checkedTicket = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); - } -} + TServiceContext context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TCheckedServiceTicket checkedTicket = context.Check(VALID_SERVICE_TICKET_1); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + } +} Y_UNIT_TEST_SUITE(PublicInterfaceUserTestSuite) { static const TString EMPTY_TVM_KEYS = "1:EpUBCpIBCAYQABqHATCBhAKBgQCoZkFGm9oLTqjeXZAq6j5S6i7K20V0lNdBBLqfmFBIRuTkYxhs4vUYnWjZrKRAd5bp6_py0csmFmpl_5Yh0b-2pdo_E5PNP7LGRzKyKSiFddyykKKzVOazH8YYldDAfE8Z5HoS9e48an5JsPg0jr-TPu34DnJq3yv2a6dqiKL9zSCakQY"; @@ -204,34 +204,34 @@ Y_UNIT_TEST_SUITE(PublicInterfaceUserTestSuite) { static const TString VALID_USER_TICKET_3 = "3:user:CA0Q__________9_Go8bCgIIAAoCCAEKAggCCgIIAwoCCAQKAggFCgIIBgoCCAcKAggICgIICQoCCAoKAggLCgIIDAoCCA0KAggOCgIIDwoCCBAKAggRCgIIEgoCCBMKAggUCgIIFQoCCBYKAggXCgIIGAoCCBkKAggaCgIIGwoCCBwKAggdCgIIHgoCCB8KAgggCgIIIQoCCCIKAggjCgIIJAoCCCUKAggmCgIIJwoCCCgKAggpCgIIKgoCCCsKAggsCgIILQoCCC4KAggvCgIIMAoCCDEKAggyCgIIMwoCCDQKAgg1CgIINgoCCDcKAgg4CgIIOQoCCDoKAgg7CgIIPAoCCD0KAgg-CgIIPwoCCEAKAghBCgIIQgoCCEMKAghECgIIRQoCCEYKAghHCgIISAoCCEkKAghKCgIISwoCCEwKAghNCgIITgoCCE8KAghQCgIIUQoCCFIKAghTCgIIVAoCCFUKAghWCgIIVwoCCFgKAghZCgIIWgoCCFsKAghcCgIIXQoCCF4KAghfCgIIYAoCCGEKAghiCgIIYwoCCGQKAghlCgIIZgoCCGcKAghoCgIIaQoCCGoKAghrCgIIbAoCCG0KAghuCgIIbwoCCHAKAghxCgIIcgoCCHMKAgh0CgIIdQoCCHYKAgh3CgIIeAoCCHkKAgh6CgIIewoCCHwKAgh9CgIIfgoCCH8KAwiAAQoDCIEBCgMIggEKAwiDAQoDCIQBCgMIhQEKAwiGAQoDCIcBCgMIiAEKAwiJAQoDCIoBCgMIiwEKAwiMAQoDCI0BCgMIjgEKAwiPAQoDCJABCgMIkQEKAwiSAQoDCJMBCgMIlAEKAwiVAQoDCJYBCgMIlwEKAwiYAQoDCJkBCgMImgEKAwibAQoDCJwBCgMInQEKAwieAQoDCJ8BCgMIoAEKAwihAQoDCKIBCgMIowEKAwikAQoDCKUBCgMIpgEKAwinAQoDCKgBCgMIqQEKAwiqAQoDCKsBCgMIrAEKAwitAQoDCK4BCgMIrwEKAwiwAQoDCLEBCgMIsgEKAwizAQoDCLQBCgMItQEKAwi2AQoDCLcBCgMIuAEKAwi5AQoDCLoBCgMIuwEKAwi8AQoDCL0BCgMIvgEKAwi_AQoDCMABCgMIwQEKAwjCAQoDCMMBCgMIxAEKAwjFAQoDCMYBCgMIxwEKAwjIAQoDCMkBCgMIygEKAwjLAQoDCMwBCgMIzQEKAwjOAQoDCM8BCgMI0AEKAwjRAQoDCNIBCgMI0wEKAwjUAQoDCNUBCgMI1gEKAwjXAQoDCNgBCgMI2QEKAwjaAQoDCNsBCgMI3AEKAwjdAQoDCN4BCgMI3wEKAwjgAQoDCOEBCgMI4gEKAwjjAQoDCOQBCgMI5QEKAwjmAQoDCOcBCgMI6AEKAwjpAQoDCOoBCgMI6wEKAwjsAQoDCO0BCgMI7gEKAwjvAQoDCPABCgMI8QEKAwjyAQoDCPMBCgMI9AEKAwj1AQoDCPYBCgMI9wEKAwj4AQoDCPkBCgMI-gEKAwj7AQoDCPwBCgMI_QEKAwj-AQoDCP8BCgMIgAIKAwiBAgoDCIICCgMIgwIKAwiEAgoDCIUCCgMIhgIKAwiHAgoDCIgCCgMIiQIKAwiKAgoDCIsCCgMIjAIKAwiNAgoDCI4CCgMIjwIKAwiQAgoDCJECCgMIkgIKAwiTAgoDCJQCCgMIlQIKAwiWAgoDCJcCCgMImAIKAwiZAgoDCJoCCgMImwIKAwicAgoDCJ0CCgMIngIKAwifAgoDCKACCgMIoQIKAwiiAgoDCKMCCgMIpAIKAwilAgoDCKYCCgMIpwIKAwioAgoDCKkCCgMIqgIKAwirAgoDCKwCCgMIrQIKAwiuAgoDCK8CCgMIsAIKAwixAgoDCLICCgMIswIKAwi0AgoDCLUCCgMItgIKAwi3AgoDCLgCCgMIuQIKAwi6AgoDCLsCCgMIvAIKAwi9AgoDCL4CCgMIvwIKAwjAAgoDCMECCgMIwgIKAwjDAgoDCMQCCgMIxQIKAwjGAgoDCMcCCgMIyAIKAwjJAgoDCMoCCgMIywIKAwjMAgoDCM0CCgMIzgIKAwjPAgoDCNACCgMI0QIKAwjSAgoDCNMCCgMI1AIKAwjVAgoDCNYCCgMI1wIKAwjYAgoDCNkCCgMI2gIKAwjbAgoDCNwCCgMI3QIKAwjeAgoDCN8CCgMI4AIKAwjhAgoDCOICCgMI4wIKAwjkAgoDCOUCCgMI5gIKAwjnAgoDCOgCCgMI6QIKAwjqAgoDCOsCCgMI7AIKAwjtAgoDCO4CCgMI7wIKAwjwAgoDCPECCgMI8gIKAwjzAgoDCPQCCgMI9QIKAwj2AgoDCPcCCgMI-AIKAwj5AgoDCPoCCgMI-wIKAwj8AgoDCP0CCgMI_gIKAwj_AgoDCIADCgMIgQMKAwiCAwoDCIMDCgMIhAMKAwiFAwoDCIYDCgMIhwMKAwiIAwoDCIkDCgMIigMKAwiLAwoDCIwDCgMIjQMKAwiOAwoDCI8DCgMIkAMKAwiRAwoDCJIDCgMIkwMKAwiUAwoDCJUDCgMIlgMKAwiXAwoDCJgDCgMImQMKAwiaAwoDCJsDCgMInAMKAwidAwoDCJ4DCgMInwMKAwigAwoDCKEDCgMIogMKAwijAwoDCKQDCgMIpQMKAwimAwoDCKcDCgMIqAMKAwipAwoDCKoDCgMIqwMKAwisAwoDCK0DCgMIrgMKAwivAwoDCLADCgMIsQMKAwiyAwoDCLMDCgMItAMKAwi1AwoDCLYDCgMItwMKAwi4AwoDCLkDCgMIugMKAwi7AwoDCLwDCgMIvQMKAwi-AwoDCL8DCgMIwAMKAwjBAwoDCMIDCgMIwwMKAwjEAwoDCMUDCgMIxgMKAwjHAwoDCMgDCgMIyQMKAwjKAwoDCMsDCgMIzAMKAwjNAwoDCM4DCgMIzwMKAwjQAwoDCNEDCgMI0gMKAwjTAwoDCNQDCgMI1QMKAwjWAwoDCNcDCgMI2AMKAwjZAwoDCNoDCgMI2wMKAwjcAwoDCN0DCgMI3gMKAwjfAwoDCOADCgMI4QMKAwjiAwoDCOMDCgMI5AMKAwjlAwoDCOYDCgMI5wMKAwjoAwoDCOkDCgMI6gMKAwjrAwoDCOwDCgMI7QMKAwjuAwoDCO8DCgMI8AMKAwjxAwoDCPIDCgMI8wMQyAMaCGJiOnNlc3MxGgliYjpzZXNzMTAaCmJiOnNlc3MxMDAaCWJiOnNlc3MxMRoJYmI6c2VzczEyGgliYjpzZXNzMTMaCWJiOnNlc3MxNBoJYmI6c2VzczE1GgliYjpzZXNzMTYaCWJiOnNlc3MxNxoJYmI6c2VzczE4GgliYjpzZXNzMTkaCGJiOnNlc3MyGgliYjpzZXNzMjAaCWJiOnNlc3MyMRoJYmI6c2VzczIyGgliYjpzZXNzMjMaCWJiOnNlc3MyNBoJYmI6c2VzczI1GgliYjpzZXNzMjYaCWJiOnNlc3MyNxoJYmI6c2VzczI4GgliYjpzZXNzMjkaCGJiOnNlc3MzGgliYjpzZXNzMzAaCWJiOnNlc3MzMRoJYmI6c2VzczMyGgliYjpzZXNzMzMaCWJiOnNlc3MzNBoJYmI6c2VzczM1GgliYjpzZXNzMzYaCWJiOnNlc3MzNxoJYmI6c2VzczM4GgliYjpzZXNzMzkaCGJiOnNlc3M0GgliYjpzZXNzNDAaCWJiOnNlc3M0MRoJYmI6c2VzczQyGgliYjpzZXNzNDMaCWJiOnNlc3M0NBoJYmI6c2VzczQ1GgliYjpzZXNzNDYaCWJiOnNlc3M0NxoJYmI6c2VzczQ4GgliYjpzZXNzNDkaCGJiOnNlc3M1GgliYjpzZXNzNTAaCWJiOnNlc3M1MRoJYmI6c2VzczUyGgliYjpzZXNzNTMaCWJiOnNlc3M1NBoJYmI6c2VzczU1GgliYjpzZXNzNTYaCWJiOnNlc3M1NxoJYmI6c2VzczU4GgliYjpzZXNzNTkaCGJiOnNlc3M2GgliYjpzZXNzNjAaCWJiOnNlc3M2MRoJYmI6c2VzczYyGgliYjpzZXNzNjMaCWJiOnNlc3M2NBoJYmI6c2VzczY1GgliYjpzZXNzNjYaCWJiOnNlc3M2NxoJYmI6c2VzczY4GgliYjpzZXNzNjkaCGJiOnNlc3M3GgliYjpzZXNzNzAaCWJiOnNlc3M3MRoJYmI6c2VzczcyGgliYjpzZXNzNzMaCWJiOnNlc3M3NBoJYmI6c2Vzczc1GgliYjpzZXNzNzYaCWJiOnNlc3M3NxoJYmI6c2Vzczc4GgliYjpzZXNzNzkaCGJiOnNlc3M4GgliYjpzZXNzODAaCWJiOnNlc3M4MRoJYmI6c2VzczgyGgliYjpzZXNzODMaCWJiOnNlc3M4NBoJYmI6c2Vzczg1GgliYjpzZXNzODYaCWJiOnNlc3M4NxoJYmI6c2Vzczg4GgliYjpzZXNzODkaCGJiOnNlc3M5GgliYjpzZXNzOTAaCWJiOnNlc3M5MRoJYmI6c2VzczkyGgliYjpzZXNzOTMaCWJiOnNlc3M5NBoJYmI6c2Vzczk1GgliYjpzZXNzOTYaCWJiOnNlc3M5NxoJYmI6c2Vzczk4GgliYjpzZXNzOTkgEigB:CX8PIOrxJnQqFXl7wAsiHJ_1VGjoI-asNlCXb8SE8jtI2vdh9x6CqbAurSgIlAAEgotVP-nuUR38x_a9YJuXzmG5AvJ458apWQtODHIDIX6ZaIwMxjS02R7S5LNqXa0gAuU_R6bCWpZdWe2uLMkdpu5KHbDgW08g-uaP_nceDOk"; Y_UNIT_TEST(Case1Test) { - TUserContext context1(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext context1(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); - TCheckedUserTicket checkedTicket1 = context1.Check("2:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA"); - UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1.GetStatus()); + TCheckedUserTicket checkedTicket1 = context1.Check("2:serv:CgYIDRCUkQYQDBgcIgdiYjpzZXNzIghiYjpzZXNzMg:ERmeH_yzC7K_QsoHTyw7llCsyExEz3CoEopPIuivA0ZAtTaFq_Pa0l9Fhhx_NX9WpOp2CPyY5cFc4PXhcO83jCB7-EGvHNxGN-j2NQalERzPiKqkDCO0Q5etLzSzrfTlvMz7sXDvELNBHyA0PkAQnbz4supY0l-0Q6JBYSEF3zOVMjjE-HeQIFL3ats3_PakaUMWRvgQQ88pVdYZqAtbDw9PlTla7ommygVZQjcfNFXV1pJKRgOCLs-YyCjOJHLKL04zYj0X6KsOCTUeqhj7ml96wLZ-g1X9tyOR2WAr2Ctq7wIEHwqhxOLgOSKqm05xH6Vi3E_hekf50oe2jPfKEA"); + UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1.GetStatus()); UNIT_ASSERT(!checkedTicket1); TUserContext context2 = std::move(context1); TUserContext context3(std::move(context2)); - TCheckedUserTicket checkedTicket2 = context3.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket2.GetStatus()); - TCheckedUserTicket checkedTicket3 = std::move(checkedTicket2); - TCheckedUserTicket checkedTicket4(std::move(checkedTicket3)); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket4.GetStatus()); - } + TCheckedUserTicket checkedTicket2 = context3.Check(VALID_USER_TICKET_1); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket2.GetStatus()); + TCheckedUserTicket checkedTicket3 = std::move(checkedTicket2); + TCheckedUserTicket checkedTicket4(std::move(checkedTicket3)); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket4.GetStatus()); + } Y_UNIT_TEST(ContextTest) { - TUserContext context(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); - } + TUserContext context(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); + } Y_UNIT_TEST(ContextExceptionsTest) { UNIT_ASSERT_EXCEPTION(TUserContext(EBlackboxEnv::Prod, EMPTY_TVM_KEYS), TEmptyTvmKeysException); UNIT_ASSERT_EXCEPTION(TUserContext(EBlackboxEnv::Prod, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); - } + } Y_UNIT_TEST(Ticket1Test) { - TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_EQUAL(TUids({456, 123}), checkedTicket.GetUids()); UNIT_ASSERT_EQUAL(456, checkedTicket.GetDefaultUid()); UNIT_ASSERT_EQUAL(TScopes({"bb:sess1", "bb:sess2"}), checkedTicket.GetScopes()); @@ -239,39 +239,39 @@ Y_UNIT_TEST_SUITE(PublicInterfaceUserTestSuite) { UNIT_ASSERT(checkedTicket.HasScope("bb:sess2")); UNIT_ASSERT(!checkedTicket.HasScope("bb:sess3")); UNIT_ASSERT_EQUAL("ticket_type=user;expiration_time=9223372036854775807;scope=bb:sess1;scope=bb:sess2;default_uid=456;uid=456;uid=123;env=Test;", checkedTicket.DebugInfo()); - } - + } + Y_UNIT_TEST(Ticket2Test) { - TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_2); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=user;expiration_time=9223372036854775807;default_uid=456;uid=456;uid=123;env=Test;", checkedTicket.DebugInfo()); - } + } Y_UNIT_TEST(Ticket3Test) { - TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_3); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=user;expiration_time=9223372036854775807;scope=bb:sess1;scope=bb:sess10;scope=bb:sess100;scope=bb:sess11;scope=bb:sess12;scope=bb:sess13;scope=bb:sess14;scope=bb:sess15;scope=bb:sess16;scope=bb:sess17;scope=bb:sess18;scope=bb:sess19;scope=bb:sess2;scope=bb:sess20;scope=bb:sess21;scope=bb:sess22;scope=bb:sess23;scope=bb:sess24;scope=bb:sess25;scope=bb:sess26;scope=bb:sess27;scope=bb:sess28;scope=bb:sess29;scope=bb:sess3;scope=bb:sess30;scope=bb:sess31;scope=bb:sess32;scope=bb:sess33;scope=bb:sess34;scope=bb:sess35;scope=bb:sess36;scope=bb:sess37;scope=bb:sess38;scope=bb:sess39;scope=bb:sess4;scope=bb:sess40;scope=bb:sess41;scope=bb:sess42;scope=bb:sess43;scope=bb:sess44;scope=bb:sess45;scope=bb:sess46;scope=bb:sess47;scope=bb:sess48;scope=bb:sess49;scope=bb:sess5;scope=bb:sess50;scope=bb:sess51;scope=bb:sess52;scope=bb:sess53;scope=bb:sess54;scope=bb:sess55;scope=bb:sess56;scope=bb:sess57;scope=bb:sess58;scope=bb:sess59;scope=bb:sess6;scope=bb:sess60;scope=bb:sess61;scope=bb:sess62;scope=bb:sess63;scope=bb:sess64;scope=bb:sess65;scope=bb:sess66;scope=bb:sess67;scope=bb:sess68;scope=bb:sess69;scope=bb:sess7;scope=bb:sess70;scope=bb:sess71;scope=bb:sess72;scope=bb:sess73;scope=bb:sess74;scope=bb:sess75;scope=bb:sess76;scope=bb:sess77;scope=bb:sess78;scope=bb:sess79;scope=bb:sess8;scope=bb:sess80;scope=bb:sess81;scope=bb:sess82;scope=bb:sess83;scope=bb:sess84;scope=bb:sess85;scope=bb:sess86;scope=bb:sess87;scope=bb:sess88;scope=bb:sess89;scope=bb:sess9;scope=bb:sess90;scope=bb:sess91;scope=bb:sess92;scope=bb:sess93;scope=bb:sess94;scope=bb:sess95;scope=bb:sess96;scope=bb:sess97;scope=bb:sess98;scope=bb:sess99;default_uid=456;uid=0;uid=1;uid=2;uid=3;uid=4;uid=5;uid=6;uid=7;uid=8;uid=9;uid=10;uid=11;uid=12;uid=13;uid=14;uid=15;uid=16;uid=17;uid=18;uid=19;uid=20;uid=21;uid=22;uid=23;uid=24;uid=25;uid=26;uid=27;uid=28;uid=29;uid=30;uid=31;uid=32;uid=33;uid=34;uid=35;uid=36;uid=37;uid=38;uid=39;uid=40;uid=41;uid=42;uid=43;uid=44;uid=45;uid=46;uid=47;uid=48;uid=49;uid=50;uid=51;uid=52;uid=53;uid=54;uid=55;uid=56;uid=57;uid=58;uid=59;uid=60;uid=61;uid=62;uid=63;uid=64;uid=65;uid=66;uid=67;uid=68;uid=69;uid=70;uid=71;uid=72;uid=73;uid=74;uid=75;uid=76;uid=77;uid=78;uid=79;uid=80;uid=81;uid=82;uid=83;uid=84;uid=85;uid=86;uid=87;uid=88;uid=89;uid=90;uid=91;uid=92;uid=93;uid=94;uid=95;uid=96;uid=97;uid=98;uid=99;uid=100;uid=101;uid=102;uid=103;uid=104;uid=105;uid=106;uid=107;uid=108;uid=109;uid=110;uid=111;uid=112;uid=113;uid=114;uid=115;uid=116;uid=117;uid=118;uid=119;uid=120;uid=121;uid=122;uid=123;uid=124;uid=125;uid=126;uid=127;uid=128;uid=129;uid=130;uid=131;uid=132;uid=133;uid=134;uid=135;uid=136;uid=137;uid=138;uid=139;uid=140;uid=141;uid=142;uid=143;uid=144;uid=145;uid=146;uid=147;uid=148;uid=149;uid=150;uid=151;uid=152;uid=153;uid=154;uid=155;uid=156;uid=157;uid=158;uid=159;uid=160;uid=161;uid=162;uid=163;uid=164;uid=165;uid=166;uid=167;uid=168;uid=169;uid=170;uid=171;uid=172;uid=173;uid=174;uid=175;uid=176;uid=177;uid=178;uid=179;uid=180;uid=181;uid=182;uid=183;uid=184;uid=185;uid=186;uid=187;uid=188;uid=189;uid=190;uid=191;uid=192;uid=193;uid=194;uid=195;uid=196;uid=197;uid=198;uid=199;uid=200;uid=201;uid=202;uid=203;uid=204;uid=205;uid=206;uid=207;uid=208;uid=209;uid=210;uid=211;uid=212;uid=213;uid=214;uid=215;uid=216;uid=217;uid=218;uid=219;uid=220;uid=221;uid=222;uid=223;uid=224;uid=225;uid=226;uid=227;uid=228;uid=229;uid=230;uid=231;uid=232;uid=233;uid=234;uid=235;uid=236;uid=237;uid=238;uid=239;uid=240;uid=241;uid=242;uid=243;uid=244;uid=245;uid=246;uid=247;uid=248;uid=249;uid=250;uid=251;uid=252;uid=253;uid=254;uid=255;uid=256;uid=257;uid=258;uid=259;uid=260;uid=261;uid=262;uid=263;uid=264;uid=265;uid=266;uid=267;uid=268;uid=269;uid=270;uid=271;uid=272;uid=273;uid=274;uid=275;uid=276;uid=277;uid=278;uid=279;uid=280;uid=281;uid=282;uid=283;uid=284;uid=285;uid=286;uid=287;uid=288;uid=289;uid=290;uid=291;uid=292;uid=293;uid=294;uid=295;uid=296;uid=297;uid=298;uid=299;uid=300;uid=301;uid=302;uid=303;uid=304;uid=305;uid=306;uid=307;uid=308;uid=309;uid=310;uid=311;uid=312;uid=313;uid=314;uid=315;uid=316;uid=317;uid=318;uid=319;uid=320;uid=321;uid=322;uid=323;uid=324;uid=325;uid=326;uid=327;uid=328;uid=329;uid=330;uid=331;uid=332;uid=333;uid=334;uid=335;uid=336;uid=337;uid=338;uid=339;uid=340;uid=341;uid=342;uid=343;uid=344;uid=345;uid=346;uid=347;uid=348;uid=349;uid=350;uid=351;uid=352;uid=353;uid=354;uid=355;uid=356;uid=357;uid=358;uid=359;uid=360;uid=361;uid=362;uid=363;uid=364;uid=365;uid=366;uid=367;uid=368;uid=369;uid=370;uid=371;uid=372;uid=373;uid=374;uid=375;uid=376;uid=377;uid=378;uid=379;uid=380;uid=381;uid=382;uid=383;uid=384;uid=385;uid=386;uid=387;uid=388;uid=389;uid=390;uid=391;uid=392;uid=393;uid=394;uid=395;uid=396;uid=397;uid=398;uid=399;uid=400;uid=401;uid=402;uid=403;uid=404;uid=405;uid=406;uid=407;uid=408;uid=409;uid=410;uid=411;uid=412;uid=413;uid=414;uid=415;uid=416;uid=417;uid=418;uid=419;uid=420;uid=421;uid=422;uid=423;uid=424;uid=425;uid=426;uid=427;uid=428;uid=429;uid=430;uid=431;uid=432;uid=433;uid=434;uid=435;uid=436;uid=437;uid=438;uid=439;uid=440;uid=441;uid=442;uid=443;uid=444;uid=445;uid=446;uid=447;uid=448;uid=449;uid=450;uid=451;uid=452;uid=453;uid=454;uid=455;uid=456;uid=457;uid=458;uid=459;uid=460;uid=461;uid=462;uid=463;uid=464;uid=465;uid=466;uid=467;uid=468;uid=469;uid=470;uid=471;uid=472;uid=473;uid=474;uid=475;uid=476;uid=477;uid=478;uid=479;uid=480;uid=481;uid=482;uid=483;uid=484;uid=485;uid=486;uid=487;uid=488;uid=489;uid=490;uid=491;uid=492;uid=493;uid=494;uid=495;uid=496;uid=497;uid=498;uid=499;env=Test;", checkedTicket.DebugInfo()); - } + } Y_UNIT_TEST(TicketErrorsTest) { - TUserContext contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket1 = contextTest.Check(UNSUPPORTED_VERSION_USER_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1.GetStatus()); auto checkedTicket2 = contextTest.Check(EXPIRED_USER_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket2.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket2.GetStatus()); - TUserContext contextProd(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext contextProd(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket3 = contextProd.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::InvalidBlackboxEnv, checkedTicket3.GetStatus()); - } + UNIT_ASSERT_EQUAL(ETicketStatus::InvalidBlackboxEnv, checkedTicket3.GetStatus()); + } Y_UNIT_TEST(TicketExceptionsTest) { - TUserContext contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = contextTest.Check(EXPIRED_USER_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket.GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket.GetStatus()); UNIT_ASSERT_EXCEPTION(checkedTicket.GetDefaultUid(), TNotAllowedException); UNIT_ASSERT_EXCEPTION(checkedTicket.GetUids(), TNotAllowedException); @@ -280,11 +280,11 @@ Y_UNIT_TEST_SUITE(PublicInterfaceUserTestSuite) { UNIT_ASSERT_NO_EXCEPTION(bool(checkedTicket)); UNIT_ASSERT_NO_EXCEPTION(checkedTicket.DebugInfo()); UNIT_ASSERT_NO_EXCEPTION(checkedTicket.GetStatus()); - } + } Y_UNIT_TEST(ResetKeysTest) { - TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); - } -} + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + } +} diff --git a/library/cpp/tvmauth/src/ut/service_ut.cpp b/library/cpp/tvmauth/src/ut/service_ut.cpp index a632379ddc..5b6b5143bd 100644 --- a/library/cpp/tvmauth/src/ut/service_ut.cpp +++ b/library/cpp/tvmauth/src/ut/service_ut.cpp @@ -1,21 +1,21 @@ -#include <library/cpp/tvmauth/src/service_impl.h> -#include <library/cpp/tvmauth/src/utils.h> +#include <library/cpp/tvmauth/src/service_impl.h> +#include <library/cpp/tvmauth/src/utils.h> -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/unittest.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/unittest.h> #include <library/cpp/testing/unittest/registar.h> - + #include <util/string/cast.h> -using namespace NTvmAuth; +using namespace NTvmAuth; Y_UNIT_TEST_SUITE(ServiceTestSuite) { Y_UNIT_TEST_DECLARE(TicketProtoTest); -} +} -class TTestServiceTicketImpl: public TCheckedServiceTicket::TImpl { - using TCheckedServiceTicket::TImpl::TImpl; +class TTestServiceTicketImpl: public TCheckedServiceTicket::TImpl { + using TCheckedServiceTicket::TImpl::TImpl; Y_UNIT_TEST_FRIEND(ServiceTestSuite, TicketProtoTest); }; @@ -24,133 +24,133 @@ Y_UNIT_TEST_SUITE_IMPLEMENTATION(ServiceTestSuite) { static const TString EXPIRED_SERVICE_TICKET = "3:serv:CBAQACIZCOUBEBwaCGJiOnNlc3MxGghiYjpzZXNzMg:IwfMNJYEqStY_SixwqJnyHOMCPR7-3HHk4uylB2oVRkthtezq-OOA7QizDvx7VABLs_iTlXuD1r5IjufNei_EiV145eaa3HIg4xCdJXCojMexf2UYJz8mF2b0YzFAy6_KWagU7xo13CyKAqzJuQf5MJcSUf0ecY9hVh36cJ51aw"; static const TString MALFORMED_TVM_KEYS = "1:CpgCCpMCCAEQABqIAjCCAQQCggEAcLEXeH67FQESFUn4_7wnX7wN0PUrBoUsm3QQ4W5vC-qz6sXaEjSwnTV8w1o-z6X9KPLlhzMQvuS38NCNfK4uvJ4Zvfp3YsXJ25-rYtbnrYJHNvHohD-kPCCw_yZpMp21JdWigzQGuV7CtrxUhF-NNrsnUaJrE5-OpEWNt4X6nCItKIYeVcSK6XJUbEWbrNCRbvkSc4ak2ymFeMuHYJVjxh4eQbk7_ZPzodP0WvF6eUYrYeb42imVEOR8ofVLQWE5DVnb1z_TqZm4i1XkS7jMwZuBxBRw8DGdYei0lT_sAf7KST2jC0590NySB3vsBgWEVs1OdUUWA6r-Dvx9dsOQtSCVkQYQAAqZAgqUAggCEAAaiQIwggEFAoIBAQDhEBM5-6YsPWfogKtbluJoCX1WV2KdzOaQ0-OlRbBzeCzw-eQKu12c8WakHBbeCMd1I1TU64SDkDorWjXGIa_2xT6N3zzNAE50roTbPCcmeQrps26woTYfYIuqDdoxYKZNr0lvNLLW47vBr7EKqo1S4KSj7aXK_XYeEvUgIgf3nVIcNrio7VTnFmGGVQCepaL1Hi1gN4yIXjVZ06PBPZ-DxSRu6xOGbFrfKMJeMPs7KOyE-26Q3xOXdTIa1X-zYIucTd_bxUCL4BVbwW2AvbbFsaG7ISmVdGu0XUTmhXs1KrEfUVLRJhE4Dx99hAZXm1_HlYMUeJcMQ_oHOhV94ENFIJaRBhACCpYBCpEBCAMQABqGATCBgwKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NIJeRBhABCpYBCpEBCAQQABqGATCBgwKBgGB4d6eLGUBv-Q6EPLehC4S-yuE2HB-_rJ7WkeYwyp-xIPolPrd-PQme2utHB4ZgpXHIu_OFksDe_0bPgZniNRSVRbl7W49DgS5Ya3kMfrYB4DnF5Fta5tn1oV6EwxYD4JONpFTenOJALPGTPawxXEfon_peiHOSBuQMu3_Vn-l1IJiRBhADCpcBCpIBCAUQABqHATCBhAKBgQCTJMKIfmfeZpaI7Q9rnsc29gdWawK7TnpVKRHws1iY7EUlYROeVcMdAwEqVM6f8BVCKLGgzQ7Gar_uuxfUGKwqEQzoppDraw4F75J464-7D5f6_oJQuGIBHZxqbMONtLjBCXRUhQW5szBLmTQ_R3qaJb5vf-h0APZfkYhq1cTttSCZkQYQBAqWAQqRAQgLEAAahgEwgYMCgYBvvGVH_M2H8qxxv94yaDYUTWbRnJ1uiIYc59KIQlfFimMPhSS7x2tqUa2-hI55JiII0Xym6GNkwLhyc1xtWChpVuIdSnbvttbrt4weDMLHqTwNOF6qAsVKGKT1Yh8yf-qb-DSmicgvFc74mBQm_6gAY1iQsf33YX8578ClhKBWHSCVkQYQAAqXAQqSAQgMEAAahwEwgYQCgYEAkuzFcd5TJu7lYWYe2hQLFfUWIIj91BvQQLa_Thln4YtGCO8gG1KJqJm-YlmJOWQG0B7H_5RVhxUxV9KpmFnsDVkzUFKOsCBaYGXc12xPVioawUlAwp5qp3QQtZyx_se97YIoLzuLr46UkLcLnkIrp-Jo46QzYi_QHq45WTm8MQ0glpEGEAIKlwEKkgEIDRAAGocBMIGEAoGBAIUzbxOknXf_rNt17_ir8JlWvrtnCWsQd1MAnl5mgArvavDtKeBYHzi5_Ak7DHlLzuA6YE8W175FxLFKpN2hkz-l-M7ltUSd8N1BvJRhK4t6WffWfC_1wPyoAbeSN2Yb1jygtZJQ8wGoXHcJQUXiMit3eFNyylwsJFj1gzAR4JCdIJeRBhABCpYBCpEBCA4QABqGATCBgwKBgFMcbEpl9ukVR6AO_R6sMyiU11I8b8MBSUCEC15iKsrVO8v_m47_TRRjWPYtQ9eZ7o1ocNJHaGUU7qqInFqtFaVnIceP6NmCsXhjs3MLrWPS8IRAy4Zf4FKmGOx3N9O2vemjUygZ9vUiSkULdVrecinRaT8JQ5RG4bUMY04XGIwFIJiRBhADCpYBCpEBCA8QABqGATCBgwKBgGpCkW-NR3li8GlRvqpq2YZGSIgm_PTyDI2Zwfw69grsBmPpVFW48Vw7xoMN35zcrojEpialB_uQzlpLYOvsMl634CRIuj-n1QE3-gaZTTTE8mg-AR4mcxnTKThPnRQpbuOlYAnriwiasWiQEMbGjq_HmWioYYxFo9USlklQn4-9IJmRBhAEEpUBCpIBCAYQABqHATCBhAKBgQCoZkFGm9oLTqjeXZAq6j5S6i7K20V0lNdBBLqfmFBIRuTkYxhs4vUYnWjZrKRAd5bp6_py0csmFmpl_5Yh0b-2pdo_E5PNP7LGRzKyKSiFddyykKKzVOazH8YYldDAfE8Z5HoS9e48an5JsPg0jr-TPu34DnJq3yv2a6dqiKL9zSCakQYSlQEKkgEIEBAAGocBMIGEAoGBALhrihbf3EpjDQS2sCQHazoFgN0nBbE9eesnnFTfzQELXb2gnJU9enmV_aDqaHKjgtLIPpCgn40lHrn5k6mvH5OdedyI6cCzE-N-GFp3nAq0NDJyMe0fhtIRD__CbT0ulcvkeow65ubXWfw6dBC2gR_34rdMe_L_TGRLMWjDULbNIJ"; static const TString MALFORMED_TVM_SECRET = "adcvxcv./-+"; - static const TTvmId NOT_OUR_ID = 27; - static const TTvmId OUR_ID = 28; + static const TTvmId NOT_OUR_ID = 27; + static const TTvmId OUR_ID = 28; static const TString SECRET = "GRMJrKnj4fOVnvOqe-WyD1"; static const TString SERVICE_TICKET_PROTOBUF = "CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My"; - static const TTvmId SRC_ID = 229; + static const TTvmId SRC_ID = 229; static const TString UNSUPPORTED_VERSION_SERVICE_TICKET = "2:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; static const TString VALID_SERVICE_TICKET_1 = "3:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; static const TString VALID_SERVICE_TICKET_2 = "3:serv:CBAQ__________9_IskICOUBEBwaCGJiOnNlc3MxGgliYjpzZXNzMTAaCmJiOnNlc3MxMDAaCWJiOnNlc3MxMRoJYmI6c2VzczEyGgliYjpzZXNzMTMaCWJiOnNlc3MxNBoJYmI6c2VzczE1GgliYjpzZXNzMTYaCWJiOnNlc3MxNxoJYmI6c2VzczE4GgliYjpzZXNzMTkaCGJiOnNlc3MyGgliYjpzZXNzMjAaCWJiOnNlc3MyMRoJYmI6c2VzczIyGgliYjpzZXNzMjMaCWJiOnNlc3MyNBoJYmI6c2VzczI1GgliYjpzZXNzMjYaCWJiOnNlc3MyNxoJYmI6c2VzczI4GgliYjpzZXNzMjkaCGJiOnNlc3MzGgliYjpzZXNzMzAaCWJiOnNlc3MzMRoJYmI6c2VzczMyGgliYjpzZXNzMzMaCWJiOnNlc3MzNBoJYmI6c2VzczM1GgliYjpzZXNzMzYaCWJiOnNlc3MzNxoJYmI6c2VzczM4GgliYjpzZXNzMzkaCGJiOnNlc3M0GgliYjpzZXNzNDAaCWJiOnNlc3M0MRoJYmI6c2VzczQyGgliYjpzZXNzNDMaCWJiOnNlc3M0NBoJYmI6c2VzczQ1GgliYjpzZXNzNDYaCWJiOnNlc3M0NxoJYmI6c2VzczQ4GgliYjpzZXNzNDkaCGJiOnNlc3M1GgliYjpzZXNzNTAaCWJiOnNlc3M1MRoJYmI6c2VzczUyGgliYjpzZXNzNTMaCWJiOnNlc3M1NBoJYmI6c2VzczU1GgliYjpzZXNzNTYaCWJiOnNlc3M1NxoJYmI6c2VzczU4GgliYjpzZXNzNTkaCGJiOnNlc3M2GgliYjpzZXNzNjAaCWJiOnNlc3M2MRoJYmI6c2VzczYyGgliYjpzZXNzNjMaCWJiOnNlc3M2NBoJYmI6c2VzczY1GgliYjpzZXNzNjYaCWJiOnNlc3M2NxoJYmI6c2VzczY4GgliYjpzZXNzNjkaCGJiOnNlc3M3GgliYjpzZXNzNzAaCWJiOnNlc3M3MRoJYmI6c2VzczcyGgliYjpzZXNzNzMaCWJiOnNlc3M3NBoJYmI6c2Vzczc1GgliYjpzZXNzNzYaCWJiOnNlc3M3NxoJYmI6c2Vzczc4GgliYjpzZXNzNzkaCGJiOnNlc3M4GgliYjpzZXNzODAaCWJiOnNlc3M4MRoJYmI6c2VzczgyGgliYjpzZXNzODMaCWJiOnNlc3M4NBoJYmI6c2Vzczg1GgliYjpzZXNzODYaCWJiOnNlc3M4NxoJYmI6c2Vzczg4GgliYjpzZXNzODkaCGJiOnNlc3M5GgliYjpzZXNzOTAaCWJiOnNlc3M5MRoJYmI6c2VzczkyGgliYjpzZXNzOTMaCWJiOnNlc3M5NBoJYmI6c2Vzczk1GgliYjpzZXNzOTYaCWJiOnNlc3M5NxoJYmI6c2Vzczk4GgliYjpzZXNzOTk:JYmABAVLM6y7_T4n1pRcwBfwDfzMV4JJ3cpbEG617zdGgKRZwL7MalsYn5bq1F2ibujMrsF9nzZf8l4s_e-Ivjkz_xu4KMzSp-pUh9V7XIF_smj0WHYpv6gOvWNuK8uIvlZTTKwtQX0qZOL9m-MEeZiHoQPKZGCfJ_qxMUp-J8I"; static const TString VALID_SERVICE_TICKET_3 = "3:serv:CBAQ__________9_IgUI5QEQHA:Sd6tmA1CNy2Nf7XevC3x7zr2DrGNRmcl-TxUsDtDW2xI3YXyCxBltWeg0-KtDlqyYuPOP5Jd_-XXNA12KlOPnNzrz3jm-5z8uQl6CjCcrVHUHJ75pGC8r9UOlS8cOgeXQB5dYP-fOWyo5CNadlozx1S2meCIxncbQRV1kCBi4KU"; - static const TString VALID_SERVICE_TICKET_ISSUER = "3:serv:CBAQ__________9_IgsI5QEQHCDr1MT4Ag:Gu66XJT_nKnIRJjFy1561wFhIqkJItcSTGftLo7Yvi7i5wIdV-QuKT_-IMPpgjxnnGbt1Dy3Ys2TEoeJAb0TdaCYG1uy3vpoLONmTx9AenN5dx1HHf46cypLK5D3OdiTjxvqI9uGmSIKrSdRxU8gprpu5QiBDPZqVCWhM60FVSY"; + static const TString VALID_SERVICE_TICKET_ISSUER = "3:serv:CBAQ__________9_IgsI5QEQHCDr1MT4Ag:Gu66XJT_nKnIRJjFy1561wFhIqkJItcSTGftLo7Yvi7i5wIdV-QuKT_-IMPpgjxnnGbt1Dy3Ys2TEoeJAb0TdaCYG1uy3vpoLONmTx9AenN5dx1HHf46cypLK5D3OdiTjxvqI9uGmSIKrSdRxU8gprpu5QiBDPZqVCWhM60FVSY"; Y_UNIT_TEST(ContextExceptionsTest) { - UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(SECRET, OUR_ID, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); - UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(SECRET, OUR_ID, EMPTY_TVM_KEYS), TEmptyTvmKeysException); - UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(MALFORMED_TVM_SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS), TMalformedTvmSecretException); - } + UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(SECRET, OUR_ID, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); + UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(SECRET, OUR_ID, EMPTY_TVM_KEYS), TEmptyTvmKeysException); + UNIT_ASSERT_EXCEPTION(TServiceContext::TImpl(MALFORMED_TVM_SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS), TMalformedTvmSecretException); + } Y_UNIT_TEST(ContextSignTest) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_VALUES_EQUAL( "NsPTYak4Cfk-4vgau5lab3W4GPiTtb2etuj3y4MDPrk", - context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "")); - } + context.SignCgiParamsForTvm(IntToString<10>(std::numeric_limits<time_t>::max()), "13,28", "")); + } Y_UNIT_TEST(Ticket1Test) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), checkedTicket->GetExpirationTime()); UNIT_ASSERT_EQUAL(SRC_ID, checkedTicket->GetSrc()); UNIT_ASSERT_EQUAL(TScopes({"bb:sess1", "bb:sess2"}), checkedTicket->GetScopes()); UNIT_ASSERT(checkedTicket->HasScope("bb:sess1")); UNIT_ASSERT(checkedTicket->HasScope("bb:sess2")); UNIT_ASSERT(!checkedTicket->HasScope("bb:sess3")); - UNIT_ASSERT_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess2;", checkedTicket->DebugInfo()); - UNIT_ASSERT(!checkedTicket->GetIssuerUid()); - } + UNIT_ASSERT_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess2;", checkedTicket->DebugInfo()); + UNIT_ASSERT(!checkedTicket->GetIssuerUid()); + } Y_UNIT_TEST(Ticket2Test) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_2); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;scope=bb:sess1;scope=bb:sess10;scope=bb:sess100;scope=bb:sess11;scope=bb:sess12;scope=bb:sess13;scope=bb:sess14;scope=bb:sess15;scope=bb:sess16;scope=bb:sess17;scope=bb:sess18;scope=bb:sess19;scope=bb:sess2;scope=bb:sess20;scope=bb:sess21;scope=bb:sess22;scope=bb:sess23;scope=bb:sess24;scope=bb:sess25;scope=bb:sess26;scope=bb:sess27;scope=bb:sess28;scope=bb:sess29;scope=bb:sess3;scope=bb:sess30;scope=bb:sess31;scope=bb:sess32;scope=bb:sess33;scope=bb:sess34;scope=bb:sess35;scope=bb:sess36;scope=bb:sess37;scope=bb:sess38;scope=bb:sess39;scope=bb:sess4;scope=bb:sess40;scope=bb:sess41;scope=bb:sess42;scope=bb:sess43;scope=bb:sess44;scope=bb:sess45;scope=bb:sess46;scope=bb:sess47;scope=bb:sess48;scope=bb:sess49;scope=bb:sess5;scope=bb:sess50;scope=bb:sess51;scope=bb:sess52;scope=bb:sess53;scope=bb:sess54;scope=bb:sess55;scope=bb:sess56;scope=bb:sess57;scope=bb:sess58;scope=bb:sess59;scope=bb:sess6;scope=bb:sess60;scope=bb:sess61;scope=bb:sess62;scope=bb:sess63;scope=bb:sess64;scope=bb:sess65;scope=bb:sess66;scope=bb:sess67;scope=bb:sess68;scope=bb:sess69;scope=bb:sess7;scope=bb:sess70;scope=bb:sess71;scope=bb:sess72;scope=bb:sess73;scope=bb:sess74;scope=bb:sess75;scope=bb:sess76;scope=bb:sess77;scope=bb:sess78;scope=bb:sess79;scope=bb:sess8;scope=bb:sess80;scope=bb:sess81;scope=bb:sess82;scope=bb:sess83;scope=bb:sess84;scope=bb:sess85;scope=bb:sess86;scope=bb:sess87;scope=bb:sess88;scope=bb:sess89;scope=bb:sess9;scope=bb:sess90;scope=bb:sess91;scope=bb:sess92;scope=bb:sess93;scope=bb:sess94;scope=bb:sess95;scope=bb:sess96;scope=bb:sess97;scope=bb:sess98;scope=bb:sess99;", checkedTicket->DebugInfo()); - UNIT_ASSERT(!checkedTicket->GetIssuerUid()); - } + UNIT_ASSERT(!checkedTicket->GetIssuerUid()); + } Y_UNIT_TEST(Ticket3Test) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_3); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;", checkedTicket->DebugInfo()); - UNIT_ASSERT(!checkedTicket->GetIssuerUid()); - } + UNIT_ASSERT(!checkedTicket->GetIssuerUid()); + } Y_UNIT_TEST(TicketIssuerTest) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - auto checkedTicket = context.Check(VALID_SERVICE_TICKET_ISSUER); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + auto checkedTicket = context.Check(VALID_SERVICE_TICKET_ISSUER); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;expiration_time=9223372036854775807;src=229;dst=28;issuer_uid=789654123;", - checkedTicket->DebugInfo()); - UNIT_ASSERT(checkedTicket->GetIssuerUid()); - UNIT_ASSERT_VALUES_EQUAL(789654123, *checkedTicket->GetIssuerUid()); - } - + checkedTicket->DebugInfo()); + UNIT_ASSERT(checkedTicket->GetIssuerUid()); + UNIT_ASSERT_VALUES_EQUAL(789654123, *checkedTicket->GetIssuerUid()); + } + Y_UNIT_TEST(TicketErrorsTest) { - TServiceContext::TImpl context(SECRET, NOT_OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, NOT_OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket1 = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::InvalidDst, checkedTicket1->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::InvalidDst, checkedTicket1->GetStatus()); auto checkedTicket2 = context.Check(UNSUPPORTED_VERSION_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket2->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket2->GetStatus()); auto checkedTicket3 = context.Check(EXPIRED_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket3->GetStatus()); - } + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket3->GetStatus()); + } Y_UNIT_TEST(TicketExceptionTest) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(EXPIRED_SERVICE_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket->GetStatus()); UNIT_ASSERT_EXCEPTION(checkedTicket->GetScopes(), TNotAllowedException); UNIT_ASSERT_EXCEPTION(checkedTicket->GetSrc(), TNotAllowedException); UNIT_ASSERT_EXCEPTION(checkedTicket->HasScope(""), TNotAllowedException); UNIT_ASSERT_NO_EXCEPTION(bool(*checkedTicket)); UNIT_ASSERT_NO_EXCEPTION(checkedTicket->DebugInfo()); - } + } Y_UNIT_TEST(TicketProtoTest) { ticket2::Ticket protobufTicket; UNIT_ASSERT(protobufTicket.ParseFromString(NUtils::Base64url2bin(SERVICE_TICKET_PROTOBUF))); - TTestServiceTicketImpl checkedTicket(ETicketStatus::Ok, std::move(protobufTicket)); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); + TTestServiceTicketImpl checkedTicket(ETicketStatus::Ok, std::move(protobufTicket)); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket.GetStatus()); UNIT_ASSERT_VALUES_EQUAL(std::numeric_limits<time_t>::max(), checkedTicket.GetExpirationTime()); UNIT_ASSERT_EQUAL(SRC_ID, checkedTicket.GetSrc()); - } + } Y_UNIT_TEST(ResetKeysTest) { - TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); - context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS); + TServiceContext::TImpl context(SECRET, OUR_ID, NUnittest::TVMKNIFE_PUBLIC_KEYS); + context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_SERVICE_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); - } - - Y_UNIT_TEST(CreateTicketForTests) { - TCheckedServiceTicket t = NTvmAuth::NUnittest::CreateServiceTicket(ETicketStatus::Ok, 42); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, t.GetStatus()); - UNIT_ASSERT_EQUAL(42, t.GetSrc()); - UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;src=42;dst=100500;", t.DebugInfo()); - } - - Y_UNIT_TEST(CreateForTests) { - auto t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, {}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(456, t->GetSrc()); - UNIT_ASSERT(!t->GetIssuerUid()); - - t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, 100800); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(456, t->GetSrc()); - UNIT_ASSERT(t->GetIssuerUid()); - UNIT_ASSERT_VALUES_EQUAL(*t->GetIssuerUid(), 100800); - - t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Expired, 456, {}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Expired, t->GetStatus()); - UNIT_ASSERT_EXCEPTION_CONTAINS(t->GetSrc(), TNotAllowedException, "Method cannot be used in non-valid ticket"); - UNIT_ASSERT_EXCEPTION_CONTAINS(t->GetIssuerUid(), TNotAllowedException, "Method cannot be used in non-valid ticket"); - } -} + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + } + + Y_UNIT_TEST(CreateTicketForTests) { + TCheckedServiceTicket t = NTvmAuth::NUnittest::CreateServiceTicket(ETicketStatus::Ok, 42); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, t.GetStatus()); + UNIT_ASSERT_EQUAL(42, t.GetSrc()); + UNIT_ASSERT_VALUES_EQUAL("ticket_type=serv;src=42;dst=100500;", t.DebugInfo()); + } + + Y_UNIT_TEST(CreateForTests) { + auto t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, {}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(456, t->GetSrc()); + UNIT_ASSERT(!t->GetIssuerUid()); + + t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, 100800); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(456, t->GetSrc()); + UNIT_ASSERT(t->GetIssuerUid()); + UNIT_ASSERT_VALUES_EQUAL(*t->GetIssuerUid(), 100800); + + t = TCheckedServiceTicket::TImpl::CreateTicketForTests(ETicketStatus::Expired, 456, {}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Expired, t->GetStatus()); + UNIT_ASSERT_EXCEPTION_CONTAINS(t->GetSrc(), TNotAllowedException, "Method cannot be used in non-valid ticket"); + UNIT_ASSERT_EXCEPTION_CONTAINS(t->GetIssuerUid(), TNotAllowedException, "Method cannot be used in non-valid ticket"); + } +} diff --git a/library/cpp/tvmauth/src/ut/user_ut.cpp b/library/cpp/tvmauth/src/ut/user_ut.cpp index e4b05d261b..c040e94974 100644 --- a/library/cpp/tvmauth/src/ut/user_ut.cpp +++ b/library/cpp/tvmauth/src/ut/user_ut.cpp @@ -1,19 +1,19 @@ -#include <library/cpp/tvmauth/src/user_impl.h> -#include <library/cpp/tvmauth/src/utils.h> +#include <library/cpp/tvmauth/src/user_impl.h> +#include <library/cpp/tvmauth/src/utils.h> -#include <library/cpp/tvmauth/exception.h> -#include <library/cpp/tvmauth/unittest.h> +#include <library/cpp/tvmauth/exception.h> +#include <library/cpp/tvmauth/unittest.h> #include <library/cpp/testing/unittest/registar.h> - -using namespace NTvmAuth; + +using namespace NTvmAuth; Y_UNIT_TEST_SUITE(UserTestSuite) { Y_UNIT_TEST_DECLARE(TicketProtoTest); -} +} -class TTestUserTicketImpl: TCheckedUserTicket::TImpl { - using TCheckedUserTicket::TImpl::TImpl; +class TTestUserTicketImpl: TCheckedUserTicket::TImpl { + using TCheckedUserTicket::TImpl::TImpl; Y_UNIT_TEST_FRIEND(UserTestSuite, TicketProtoTest); }; @@ -28,64 +28,64 @@ Y_UNIT_TEST_SUITE_IMPLEMENTATION(UserTestSuite) { static const TString VALID_USER_TICKET_3 = "3:user:CA0Q__________9_Go8bCgIIAAoCCAEKAggCCgIIAwoCCAQKAggFCgIIBgoCCAcKAggICgIICQoCCAoKAggLCgIIDAoCCA0KAggOCgIIDwoCCBAKAggRCgIIEgoCCBMKAggUCgIIFQoCCBYKAggXCgIIGAoCCBkKAggaCgIIGwoCCBwKAggdCgIIHgoCCB8KAgggCgIIIQoCCCIKAggjCgIIJAoCCCUKAggmCgIIJwoCCCgKAggpCgIIKgoCCCsKAggsCgIILQoCCC4KAggvCgIIMAoCCDEKAggyCgIIMwoCCDQKAgg1CgIINgoCCDcKAgg4CgIIOQoCCDoKAgg7CgIIPAoCCD0KAgg-CgIIPwoCCEAKAghBCgIIQgoCCEMKAghECgIIRQoCCEYKAghHCgIISAoCCEkKAghKCgIISwoCCEwKAghNCgIITgoCCE8KAghQCgIIUQoCCFIKAghTCgIIVAoCCFUKAghWCgIIVwoCCFgKAghZCgIIWgoCCFsKAghcCgIIXQoCCF4KAghfCgIIYAoCCGEKAghiCgIIYwoCCGQKAghlCgIIZgoCCGcKAghoCgIIaQoCCGoKAghrCgIIbAoCCG0KAghuCgIIbwoCCHAKAghxCgIIcgoCCHMKAgh0CgIIdQoCCHYKAgh3CgIIeAoCCHkKAgh6CgIIewoCCHwKAgh9CgIIfgoCCH8KAwiAAQoDCIEBCgMIggEKAwiDAQoDCIQBCgMIhQEKAwiGAQoDCIcBCgMIiAEKAwiJAQoDCIoBCgMIiwEKAwiMAQoDCI0BCgMIjgEKAwiPAQoDCJABCgMIkQEKAwiSAQoDCJMBCgMIlAEKAwiVAQoDCJYBCgMIlwEKAwiYAQoDCJkBCgMImgEKAwibAQoDCJwBCgMInQEKAwieAQoDCJ8BCgMIoAEKAwihAQoDCKIBCgMIowEKAwikAQoDCKUBCgMIpgEKAwinAQoDCKgBCgMIqQEKAwiqAQoDCKsBCgMIrAEKAwitAQoDCK4BCgMIrwEKAwiwAQoDCLEBCgMIsgEKAwizAQoDCLQBCgMItQEKAwi2AQoDCLcBCgMIuAEKAwi5AQoDCLoBCgMIuwEKAwi8AQoDCL0BCgMIvgEKAwi_AQoDCMABCgMIwQEKAwjCAQoDCMMBCgMIxAEKAwjFAQoDCMYBCgMIxwEKAwjIAQoDCMkBCgMIygEKAwjLAQoDCMwBCgMIzQEKAwjOAQoDCM8BCgMI0AEKAwjRAQoDCNIBCgMI0wEKAwjUAQoDCNUBCgMI1gEKAwjXAQoDCNgBCgMI2QEKAwjaAQoDCNsBCgMI3AEKAwjdAQoDCN4BCgMI3wEKAwjgAQoDCOEBCgMI4gEKAwjjAQoDCOQBCgMI5QEKAwjmAQoDCOcBCgMI6AEKAwjpAQoDCOoBCgMI6wEKAwjsAQoDCO0BCgMI7gEKAwjvAQoDCPABCgMI8QEKAwjyAQoDCPMBCgMI9AEKAwj1AQoDCPYBCgMI9wEKAwj4AQoDCPkBCgMI-gEKAwj7AQoDCPwBCgMI_QEKAwj-AQoDCP8BCgMIgAIKAwiBAgoDCIICCgMIgwIKAwiEAgoDCIUCCgMIhgIKAwiHAgoDCIgCCgMIiQIKAwiKAgoDCIsCCgMIjAIKAwiNAgoDCI4CCgMIjwIKAwiQAgoDCJECCgMIkgIKAwiTAgoDCJQCCgMIlQIKAwiWAgoDCJcCCgMImAIKAwiZAgoDCJoCCgMImwIKAwicAgoDCJ0CCgMIngIKAwifAgoDCKACCgMIoQIKAwiiAgoDCKMCCgMIpAIKAwilAgoDCKYCCgMIpwIKAwioAgoDCKkCCgMIqgIKAwirAgoDCKwCCgMIrQIKAwiuAgoDCK8CCgMIsAIKAwixAgoDCLICCgMIswIKAwi0AgoDCLUCCgMItgIKAwi3AgoDCLgCCgMIuQIKAwi6AgoDCLsCCgMIvAIKAwi9AgoDCL4CCgMIvwIKAwjAAgoDCMECCgMIwgIKAwjDAgoDCMQCCgMIxQIKAwjGAgoDCMcCCgMIyAIKAwjJAgoDCMoCCgMIywIKAwjMAgoDCM0CCgMIzgIKAwjPAgoDCNACCgMI0QIKAwjSAgoDCNMCCgMI1AIKAwjVAgoDCNYCCgMI1wIKAwjYAgoDCNkCCgMI2gIKAwjbAgoDCNwCCgMI3QIKAwjeAgoDCN8CCgMI4AIKAwjhAgoDCOICCgMI4wIKAwjkAgoDCOUCCgMI5gIKAwjnAgoDCOgCCgMI6QIKAwjqAgoDCOsCCgMI7AIKAwjtAgoDCO4CCgMI7wIKAwjwAgoDCPECCgMI8gIKAwjzAgoDCPQCCgMI9QIKAwj2AgoDCPcCCgMI-AIKAwj5AgoDCPoCCgMI-wIKAwj8AgoDCP0CCgMI_gIKAwj_AgoDCIADCgMIgQMKAwiCAwoDCIMDCgMIhAMKAwiFAwoDCIYDCgMIhwMKAwiIAwoDCIkDCgMIigMKAwiLAwoDCIwDCgMIjQMKAwiOAwoDCI8DCgMIkAMKAwiRAwoDCJIDCgMIkwMKAwiUAwoDCJUDCgMIlgMKAwiXAwoDCJgDCgMImQMKAwiaAwoDCJsDCgMInAMKAwidAwoDCJ4DCgMInwMKAwigAwoDCKEDCgMIogMKAwijAwoDCKQDCgMIpQMKAwimAwoDCKcDCgMIqAMKAwipAwoDCKoDCgMIqwMKAwisAwoDCK0DCgMIrgMKAwivAwoDCLADCgMIsQMKAwiyAwoDCLMDCgMItAMKAwi1AwoDCLYDCgMItwMKAwi4AwoDCLkDCgMIugMKAwi7AwoDCLwDCgMIvQMKAwi-AwoDCL8DCgMIwAMKAwjBAwoDCMIDCgMIwwMKAwjEAwoDCMUDCgMIxgMKAwjHAwoDCMgDCgMIyQMKAwjKAwoDCMsDCgMIzAMKAwjNAwoDCM4DCgMIzwMKAwjQAwoDCNEDCgMI0gMKAwjTAwoDCNQDCgMI1QMKAwjWAwoDCNcDCgMI2AMKAwjZAwoDCNoDCgMI2wMKAwjcAwoDCN0DCgMI3gMKAwjfAwoDCOADCgMI4QMKAwjiAwoDCOMDCgMI5AMKAwjlAwoDCOYDCgMI5wMKAwjoAwoDCOkDCgMI6gMKAwjrAwoDCOwDCgMI7QMKAwjuAwoDCO8DCgMI8AMKAwjxAwoDCPIDCgMI8wMQyAMaCGJiOnNlc3MxGgliYjpzZXNzMTAaCmJiOnNlc3MxMDAaCWJiOnNlc3MxMRoJYmI6c2VzczEyGgliYjpzZXNzMTMaCWJiOnNlc3MxNBoJYmI6c2VzczE1GgliYjpzZXNzMTYaCWJiOnNlc3MxNxoJYmI6c2VzczE4GgliYjpzZXNzMTkaCGJiOnNlc3MyGgliYjpzZXNzMjAaCWJiOnNlc3MyMRoJYmI6c2VzczIyGgliYjpzZXNzMjMaCWJiOnNlc3MyNBoJYmI6c2VzczI1GgliYjpzZXNzMjYaCWJiOnNlc3MyNxoJYmI6c2VzczI4GgliYjpzZXNzMjkaCGJiOnNlc3MzGgliYjpzZXNzMzAaCWJiOnNlc3MzMRoJYmI6c2VzczMyGgliYjpzZXNzMzMaCWJiOnNlc3MzNBoJYmI6c2VzczM1GgliYjpzZXNzMzYaCWJiOnNlc3MzNxoJYmI6c2VzczM4GgliYjpzZXNzMzkaCGJiOnNlc3M0GgliYjpzZXNzNDAaCWJiOnNlc3M0MRoJYmI6c2VzczQyGgliYjpzZXNzNDMaCWJiOnNlc3M0NBoJYmI6c2VzczQ1GgliYjpzZXNzNDYaCWJiOnNlc3M0NxoJYmI6c2VzczQ4GgliYjpzZXNzNDkaCGJiOnNlc3M1GgliYjpzZXNzNTAaCWJiOnNlc3M1MRoJYmI6c2VzczUyGgliYjpzZXNzNTMaCWJiOnNlc3M1NBoJYmI6c2VzczU1GgliYjpzZXNzNTYaCWJiOnNlc3M1NxoJYmI6c2VzczU4GgliYjpzZXNzNTkaCGJiOnNlc3M2GgliYjpzZXNzNjAaCWJiOnNlc3M2MRoJYmI6c2VzczYyGgliYjpzZXNzNjMaCWJiOnNlc3M2NBoJYmI6c2VzczY1GgliYjpzZXNzNjYaCWJiOnNlc3M2NxoJYmI6c2VzczY4GgliYjpzZXNzNjkaCGJiOnNlc3M3GgliYjpzZXNzNzAaCWJiOnNlc3M3MRoJYmI6c2VzczcyGgliYjpzZXNzNzMaCWJiOnNlc3M3NBoJYmI6c2Vzczc1GgliYjpzZXNzNzYaCWJiOnNlc3M3NxoJYmI6c2Vzczc4GgliYjpzZXNzNzkaCGJiOnNlc3M4GgliYjpzZXNzODAaCWJiOnNlc3M4MRoJYmI6c2VzczgyGgliYjpzZXNzODMaCWJiOnNlc3M4NBoJYmI6c2Vzczg1GgliYjpzZXNzODYaCWJiOnNlc3M4NxoJYmI6c2Vzczg4GgliYjpzZXNzODkaCGJiOnNlc3M5GgliYjpzZXNzOTAaCWJiOnNlc3M5MRoJYmI6c2VzczkyGgliYjpzZXNzOTMaCWJiOnNlc3M5NBoJYmI6c2Vzczk1GgliYjpzZXNzOTYaCWJiOnNlc3M5NxoJYmI6c2Vzczk4GgliYjpzZXNzOTkgEigB:CX8PIOrxJnQqFXl7wAsiHJ_1VGjoI-asNlCXb8SE8jtI2vdh9x6CqbAurSgIlAAEgotVP-nuUR38x_a9YJuXzmG5AvJ458apWQtODHIDIX6ZaIwMxjS02R7S5LNqXa0gAuU_R6bCWpZdWe2uLMkdpu5KHbDgW08g-uaP_nceDOk"; Y_UNIT_TEST(ContextText) { - TUserContext::TImpl context(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl context(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(2, context.GetKeys().size()); - UNIT_ASSERT_NO_EXCEPTION(context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS)); + UNIT_ASSERT_NO_EXCEPTION(context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS)); UNIT_ASSERT_EQUAL(2, context.GetKeys().size()); - } + } Y_UNIT_TEST(ContextEnvTest) { - TUserContext::TImpl p(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl p(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(2, p.GetKeys().size()); - UNIT_ASSERT(p.IsAllowed(tvm_keys::Prod)); - UNIT_ASSERT(!p.IsAllowed(tvm_keys::ProdYateam)); - UNIT_ASSERT(!p.IsAllowed(tvm_keys::Test)); - UNIT_ASSERT(!p.IsAllowed(tvm_keys::TestYateam)); - UNIT_ASSERT(!p.IsAllowed(tvm_keys::Stress)); + UNIT_ASSERT(p.IsAllowed(tvm_keys::Prod)); + UNIT_ASSERT(!p.IsAllowed(tvm_keys::ProdYateam)); + UNIT_ASSERT(!p.IsAllowed(tvm_keys::Test)); + UNIT_ASSERT(!p.IsAllowed(tvm_keys::TestYateam)); + UNIT_ASSERT(!p.IsAllowed(tvm_keys::Stress)); - TUserContext::TImpl pt(EBlackboxEnv::ProdYateam, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl pt(EBlackboxEnv::ProdYateam, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(2, pt.GetKeys().size()); - UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Prod)); - UNIT_ASSERT(pt.IsAllowed(tvm_keys::ProdYateam)); - UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Test)); - UNIT_ASSERT(!pt.IsAllowed(tvm_keys::TestYateam)); - UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Stress)); + UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Prod)); + UNIT_ASSERT(pt.IsAllowed(tvm_keys::ProdYateam)); + UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Test)); + UNIT_ASSERT(!pt.IsAllowed(tvm_keys::TestYateam)); + UNIT_ASSERT(!pt.IsAllowed(tvm_keys::Stress)); - TUserContext::TImpl t(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl t(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(2, t.GetKeys().size()); - UNIT_ASSERT(!t.IsAllowed(tvm_keys::Prod)); - UNIT_ASSERT(!t.IsAllowed(tvm_keys::ProdYateam)); - UNIT_ASSERT(t.IsAllowed(tvm_keys::Test)); - UNIT_ASSERT(!t.IsAllowed(tvm_keys::TestYateam)); - UNIT_ASSERT(!t.IsAllowed(tvm_keys::Stress)); + UNIT_ASSERT(!t.IsAllowed(tvm_keys::Prod)); + UNIT_ASSERT(!t.IsAllowed(tvm_keys::ProdYateam)); + UNIT_ASSERT(t.IsAllowed(tvm_keys::Test)); + UNIT_ASSERT(!t.IsAllowed(tvm_keys::TestYateam)); + UNIT_ASSERT(!t.IsAllowed(tvm_keys::Stress)); - TUserContext::TImpl tt(EBlackboxEnv::TestYateam, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl tt(EBlackboxEnv::TestYateam, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(2, tt.GetKeys().size()); - UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Prod)); - UNIT_ASSERT(!tt.IsAllowed(tvm_keys::ProdYateam)); - UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Test)); - UNIT_ASSERT(tt.IsAllowed(tvm_keys::TestYateam)); - UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Stress)); + UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Prod)); + UNIT_ASSERT(!tt.IsAllowed(tvm_keys::ProdYateam)); + UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Test)); + UNIT_ASSERT(tt.IsAllowed(tvm_keys::TestYateam)); + UNIT_ASSERT(!tt.IsAllowed(tvm_keys::Stress)); - TUserContext::TImpl s(EBlackboxEnv::Stress, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl s(EBlackboxEnv::Stress, NUnittest::TVMKNIFE_PUBLIC_KEYS); UNIT_ASSERT_EQUAL(4, s.GetKeys().size()); - UNIT_ASSERT(s.IsAllowed(tvm_keys::Prod)); - UNIT_ASSERT(!s.IsAllowed(tvm_keys::ProdYateam)); - UNIT_ASSERT(!s.IsAllowed(tvm_keys::Test)); - UNIT_ASSERT(!s.IsAllowed(tvm_keys::TestYateam)); - UNIT_ASSERT(s.IsAllowed(tvm_keys::Stress)); - } + UNIT_ASSERT(s.IsAllowed(tvm_keys::Prod)); + UNIT_ASSERT(!s.IsAllowed(tvm_keys::ProdYateam)); + UNIT_ASSERT(!s.IsAllowed(tvm_keys::Test)); + UNIT_ASSERT(!s.IsAllowed(tvm_keys::TestYateam)); + UNIT_ASSERT(s.IsAllowed(tvm_keys::Stress)); + } Y_UNIT_TEST(ContextExceptionsText) { UNIT_ASSERT_EXCEPTION(TUserContext::TImpl(EBlackboxEnv::Prod, EMPTY_TVM_KEYS), TEmptyTvmKeysException); UNIT_ASSERT_EXCEPTION(TUserContext::TImpl(EBlackboxEnv::Prod, MALFORMED_TVM_KEYS), TMalformedTvmKeysException); UNIT_ASSERT_EXCEPTION(TUserContext::TImpl(EBlackboxEnv::Prod, "adcvxcv./-+"), TMalformedTvmKeysException); - } + } Y_UNIT_TEST(Ticket1Test) { - TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), checkedTicket->GetExpirationTime()); UNIT_ASSERT_EQUAL(TUids({456, 123}), checkedTicket->GetUids()); UNIT_ASSERT_EQUAL(456, checkedTicket->GetDefaultUid()); @@ -94,33 +94,33 @@ Y_UNIT_TEST_SUITE_IMPLEMENTATION(UserTestSuite) { UNIT_ASSERT(checkedTicket->HasScope("bb:sess2")); UNIT_ASSERT(!checkedTicket->HasScope("bb:sess3")); UNIT_ASSERT_EQUAL("ticket_type=user;expiration_time=9223372036854775807;scope=bb:sess1;scope=bb:sess2;default_uid=456;uid=456;uid=123;env=Test;", checkedTicket->DebugInfo()); - } + } Y_UNIT_TEST(Ticket2Test) { - TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_2); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=user;expiration_time=9223372036854775807;default_uid=456;uid=456;uid=123;env=Test;", checkedTicket->DebugInfo()); - } + } Y_UNIT_TEST(Ticket3Test) { - TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_3); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=user;expiration_time=9223372036854775807;scope=bb:sess1;scope=bb:sess10;scope=bb:sess100;scope=bb:sess11;scope=bb:sess12;scope=bb:sess13;scope=bb:sess14;scope=bb:sess15;scope=bb:sess16;scope=bb:sess17;scope=bb:sess18;scope=bb:sess19;scope=bb:sess2;scope=bb:sess20;scope=bb:sess21;scope=bb:sess22;scope=bb:sess23;scope=bb:sess24;scope=bb:sess25;scope=bb:sess26;scope=bb:sess27;scope=bb:sess28;scope=bb:sess29;scope=bb:sess3;scope=bb:sess30;scope=bb:sess31;scope=bb:sess32;scope=bb:sess33;scope=bb:sess34;scope=bb:sess35;scope=bb:sess36;scope=bb:sess37;scope=bb:sess38;scope=bb:sess39;scope=bb:sess4;scope=bb:sess40;scope=bb:sess41;scope=bb:sess42;scope=bb:sess43;scope=bb:sess44;scope=bb:sess45;scope=bb:sess46;scope=bb:sess47;scope=bb:sess48;scope=bb:sess49;scope=bb:sess5;scope=bb:sess50;scope=bb:sess51;scope=bb:sess52;scope=bb:sess53;scope=bb:sess54;scope=bb:sess55;scope=bb:sess56;scope=bb:sess57;scope=bb:sess58;scope=bb:sess59;scope=bb:sess6;scope=bb:sess60;scope=bb:sess61;scope=bb:sess62;scope=bb:sess63;scope=bb:sess64;scope=bb:sess65;scope=bb:sess66;scope=bb:sess67;scope=bb:sess68;scope=bb:sess69;scope=bb:sess7;scope=bb:sess70;scope=bb:sess71;scope=bb:sess72;scope=bb:sess73;scope=bb:sess74;scope=bb:sess75;scope=bb:sess76;scope=bb:sess77;scope=bb:sess78;scope=bb:sess79;scope=bb:sess8;scope=bb:sess80;scope=bb:sess81;scope=bb:sess82;scope=bb:sess83;scope=bb:sess84;scope=bb:sess85;scope=bb:sess86;scope=bb:sess87;scope=bb:sess88;scope=bb:sess89;scope=bb:sess9;scope=bb:sess90;scope=bb:sess91;scope=bb:sess92;scope=bb:sess93;scope=bb:sess94;scope=bb:sess95;scope=bb:sess96;scope=bb:sess97;scope=bb:sess98;scope=bb:sess99;default_uid=456;uid=0;uid=1;uid=2;uid=3;uid=4;uid=5;uid=6;uid=7;uid=8;uid=9;uid=10;uid=11;uid=12;uid=13;uid=14;uid=15;uid=16;uid=17;uid=18;uid=19;uid=20;uid=21;uid=22;uid=23;uid=24;uid=25;uid=26;uid=27;uid=28;uid=29;uid=30;uid=31;uid=32;uid=33;uid=34;uid=35;uid=36;uid=37;uid=38;uid=39;uid=40;uid=41;uid=42;uid=43;uid=44;uid=45;uid=46;uid=47;uid=48;uid=49;uid=50;uid=51;uid=52;uid=53;uid=54;uid=55;uid=56;uid=57;uid=58;uid=59;uid=60;uid=61;uid=62;uid=63;uid=64;uid=65;uid=66;uid=67;uid=68;uid=69;uid=70;uid=71;uid=72;uid=73;uid=74;uid=75;uid=76;uid=77;uid=78;uid=79;uid=80;uid=81;uid=82;uid=83;uid=84;uid=85;uid=86;uid=87;uid=88;uid=89;uid=90;uid=91;uid=92;uid=93;uid=94;uid=95;uid=96;uid=97;uid=98;uid=99;uid=100;uid=101;uid=102;uid=103;uid=104;uid=105;uid=106;uid=107;uid=108;uid=109;uid=110;uid=111;uid=112;uid=113;uid=114;uid=115;uid=116;uid=117;uid=118;uid=119;uid=120;uid=121;uid=122;uid=123;uid=124;uid=125;uid=126;uid=127;uid=128;uid=129;uid=130;uid=131;uid=132;uid=133;uid=134;uid=135;uid=136;uid=137;uid=138;uid=139;uid=140;uid=141;uid=142;uid=143;uid=144;uid=145;uid=146;uid=147;uid=148;uid=149;uid=150;uid=151;uid=152;uid=153;uid=154;uid=155;uid=156;uid=157;uid=158;uid=159;uid=160;uid=161;uid=162;uid=163;uid=164;uid=165;uid=166;uid=167;uid=168;uid=169;uid=170;uid=171;uid=172;uid=173;uid=174;uid=175;uid=176;uid=177;uid=178;uid=179;uid=180;uid=181;uid=182;uid=183;uid=184;uid=185;uid=186;uid=187;uid=188;uid=189;uid=190;uid=191;uid=192;uid=193;uid=194;uid=195;uid=196;uid=197;uid=198;uid=199;uid=200;uid=201;uid=202;uid=203;uid=204;uid=205;uid=206;uid=207;uid=208;uid=209;uid=210;uid=211;uid=212;uid=213;uid=214;uid=215;uid=216;uid=217;uid=218;uid=219;uid=220;uid=221;uid=222;uid=223;uid=224;uid=225;uid=226;uid=227;uid=228;uid=229;uid=230;uid=231;uid=232;uid=233;uid=234;uid=235;uid=236;uid=237;uid=238;uid=239;uid=240;uid=241;uid=242;uid=243;uid=244;uid=245;uid=246;uid=247;uid=248;uid=249;uid=250;uid=251;uid=252;uid=253;uid=254;uid=255;uid=256;uid=257;uid=258;uid=259;uid=260;uid=261;uid=262;uid=263;uid=264;uid=265;uid=266;uid=267;uid=268;uid=269;uid=270;uid=271;uid=272;uid=273;uid=274;uid=275;uid=276;uid=277;uid=278;uid=279;uid=280;uid=281;uid=282;uid=283;uid=284;uid=285;uid=286;uid=287;uid=288;uid=289;uid=290;uid=291;uid=292;uid=293;uid=294;uid=295;uid=296;uid=297;uid=298;uid=299;uid=300;uid=301;uid=302;uid=303;uid=304;uid=305;uid=306;uid=307;uid=308;uid=309;uid=310;uid=311;uid=312;uid=313;uid=314;uid=315;uid=316;uid=317;uid=318;uid=319;uid=320;uid=321;uid=322;uid=323;uid=324;uid=325;uid=326;uid=327;uid=328;uid=329;uid=330;uid=331;uid=332;uid=333;uid=334;uid=335;uid=336;uid=337;uid=338;uid=339;uid=340;uid=341;uid=342;uid=343;uid=344;uid=345;uid=346;uid=347;uid=348;uid=349;uid=350;uid=351;uid=352;uid=353;uid=354;uid=355;uid=356;uid=357;uid=358;uid=359;uid=360;uid=361;uid=362;uid=363;uid=364;uid=365;uid=366;uid=367;uid=368;uid=369;uid=370;uid=371;uid=372;uid=373;uid=374;uid=375;uid=376;uid=377;uid=378;uid=379;uid=380;uid=381;uid=382;uid=383;uid=384;uid=385;uid=386;uid=387;uid=388;uid=389;uid=390;uid=391;uid=392;uid=393;uid=394;uid=395;uid=396;uid=397;uid=398;uid=399;uid=400;uid=401;uid=402;uid=403;uid=404;uid=405;uid=406;uid=407;uid=408;uid=409;uid=410;uid=411;uid=412;uid=413;uid=414;uid=415;uid=416;uid=417;uid=418;uid=419;uid=420;uid=421;uid=422;uid=423;uid=424;uid=425;uid=426;uid=427;uid=428;uid=429;uid=430;uid=431;uid=432;uid=433;uid=434;uid=435;uid=436;uid=437;uid=438;uid=439;uid=440;uid=441;uid=442;uid=443;uid=444;uid=445;uid=446;uid=447;uid=448;uid=449;uid=450;uid=451;uid=452;uid=453;uid=454;uid=455;uid=456;uid=457;uid=458;uid=459;uid=460;uid=461;uid=462;uid=463;uid=464;uid=465;uid=466;uid=467;uid=468;uid=469;uid=470;uid=471;uid=472;uid=473;uid=474;uid=475;uid=476;uid=477;uid=478;uid=479;uid=480;uid=481;uid=482;uid=483;uid=484;uid=485;uid=486;uid=487;uid=488;uid=489;uid=490;uid=491;uid=492;uid=493;uid=494;uid=495;uid=496;uid=497;uid=498;uid=499;env=Test;", checkedTicket->DebugInfo()); - } + } Y_UNIT_TEST(TicketExceptionsTest) { - TUserContext::TImpl contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl contextTest(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket1 = contextTest.Check(UNSUPPORTED_VERSION_USER_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::UnsupportedVersion, checkedTicket1->GetStatus()); auto checkedTicket2 = contextTest.Check(EXPIRED_USER_TICKET); - UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket2->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::Expired, checkedTicket2->GetStatus()); - TUserContext::TImpl contextProd(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl contextProd(EBlackboxEnv::Prod, NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket3 = contextProd.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::InvalidBlackboxEnv, checkedTicket3->GetStatus()); + UNIT_ASSERT_EQUAL(ETicketStatus::InvalidBlackboxEnv, checkedTicket3->GetStatus()); UNIT_ASSERT_EXCEPTION(checkedTicket3->GetDefaultUid(), TNotAllowedException); UNIT_ASSERT_EXCEPTION(checkedTicket3->GetUids(), TNotAllowedException); @@ -129,13 +129,13 @@ Y_UNIT_TEST_SUITE_IMPLEMENTATION(UserTestSuite) { UNIT_ASSERT_NO_EXCEPTION(bool(*checkedTicket3)); UNIT_ASSERT_NO_EXCEPTION(checkedTicket3->DebugInfo()); UNIT_ASSERT_NO_EXCEPTION(checkedTicket3->GetStatus()); - } + } Y_UNIT_TEST(TicketProtoTest) { ticket2::Ticket protobufTicket; UNIT_ASSERT(protobufTicket.ParseFromString(NUtils::Base64url2bin(USER_TICKET_PROTOBUF))); - TTestUserTicketImpl userTicket(ETicketStatus::Ok, std::move(protobufTicket)); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, userTicket.GetStatus()); + TTestUserTicketImpl userTicket(ETicketStatus::Ok, std::move(protobufTicket)); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, userTicket.GetStatus()); UNIT_ASSERT_EQUAL(std::numeric_limits<time_t>::max(), userTicket.GetExpirationTime()); UNIT_ASSERT_EQUAL(TUids({456, 123}), userTicket.GetUids()); UNIT_ASSERT_EQUAL(456, userTicket.GetDefaultUid()); @@ -143,74 +143,74 @@ Y_UNIT_TEST_SUITE_IMPLEMENTATION(UserTestSuite) { UNIT_ASSERT(userTicket.HasScope("bb:sess1")); UNIT_ASSERT(userTicket.HasScope("bb:sess2")); UNIT_ASSERT(!userTicket.HasScope("bb:sess3")); - } + } Y_UNIT_TEST(ResetKeysTest) { - TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); - context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS); + TUserContext::TImpl context(EBlackboxEnv::Test, NUnittest::TVMKNIFE_PUBLIC_KEYS); + context.ResetKeys(NUnittest::TVMKNIFE_PUBLIC_KEYS); auto checkedTicket = context.Check(VALID_USER_TICKET_1); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); - } - - Y_UNIT_TEST(CreateTicketForTests) { - TCheckedUserTicket t = NTvmAuth::NUnittest::CreateUserTicket(ETicketStatus::Ok, 42, {"qwerty", "omg"}, {43, 55, 47}); - UNIT_ASSERT_EQUAL(ETicketStatus::Ok, t.GetStatus()); - UNIT_ASSERT_EQUAL(42, t.GetDefaultUid()); - UNIT_ASSERT_EQUAL(TUids({42, 43, 47, 55}), t.GetUids()); - UNIT_ASSERT_EQUAL(TScopes({"omg", "qwerty"}), t.GetScopes()); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, checkedTicket->GetStatus()); + } + + Y_UNIT_TEST(CreateTicketForTests) { + TCheckedUserTicket t = NTvmAuth::NUnittest::CreateUserTicket(ETicketStatus::Ok, 42, {"qwerty", "omg"}, {43, 55, 47}); + UNIT_ASSERT_EQUAL(ETicketStatus::Ok, t.GetStatus()); + UNIT_ASSERT_EQUAL(42, t.GetDefaultUid()); + UNIT_ASSERT_EQUAL(TUids({42, 43, 47, 55}), t.GetUids()); + UNIT_ASSERT_EQUAL(TScopes({"omg", "qwerty"}), t.GetScopes()); UNIT_ASSERT_VALUES_EQUAL("ticket_type=user;scope=omg;scope=qwerty;default_uid=42;uid=42;uid=43;uid=47;uid=55;env=Test;", t.DebugInfo()); - } - - Y_UNIT_TEST(CreateForTests) { - TUids uids{456}; - TScopes scopes{"scope1", "scope2", "scope3"}; - TScopes scopesIn{"scope1", "scope2", "scope3", "scope1", ""}; - auto t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); - UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); - UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); - - t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {123, 456, 789}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); - uids = TUids{123, 456, 789}; - UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); - UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); - - t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {123, 789}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); - uids = TUids{123, 456, 789}; - UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); - UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); - - t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {123, 789}); - UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); - UNIT_ASSERT_VALUES_EQUAL(0, t->GetDefaultUid()); - uids = TUids{123, 789}; - UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); - UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); - - UNIT_ASSERT_EXCEPTION_CONTAINS(TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {}), - yexception, - "User ticket cannot contain empty uid list"); - UNIT_ASSERT_EXCEPTION_CONTAINS(TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {0}), - yexception, - "User ticket cannot contain empty uid list"); - } -} - -template <> -void Out<NTvmAuth::TUids>(IOutputStream& o, const NTvmAuth::TUids& v) { - for (const auto& uid : v) { - o << uid << ","; - } -} - -template <> -void Out<NTvmAuth::TScopes>(IOutputStream& o, const NTvmAuth::TScopes& v) { - for (const auto& scope : v) { - o << scope << ","; - } -} + } + + Y_UNIT_TEST(CreateForTests) { + TUids uids{456}; + TScopes scopes{"scope1", "scope2", "scope3"}; + TScopes scopesIn{"scope1", "scope2", "scope3", "scope1", ""}; + auto t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); + UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); + UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); + + t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {123, 456, 789}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); + uids = TUids{123, 456, 789}; + UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); + UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); + + t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 456, scopesIn, {123, 789}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(456, t->GetDefaultUid()); + uids = TUids{123, 456, 789}; + UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); + UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); + + t = TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {123, 789}); + UNIT_ASSERT_VALUES_EQUAL(ETicketStatus::Ok, t->GetStatus()); + UNIT_ASSERT_VALUES_EQUAL(0, t->GetDefaultUid()); + uids = TUids{123, 789}; + UNIT_ASSERT_VALUES_EQUAL(uids, t->GetUids()); + UNIT_ASSERT_VALUES_EQUAL(scopes, t->GetScopes()); + + UNIT_ASSERT_EXCEPTION_CONTAINS(TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {}), + yexception, + "User ticket cannot contain empty uid list"); + UNIT_ASSERT_EXCEPTION_CONTAINS(TCheckedUserTicket::TImpl::CreateTicketForTests(ETicketStatus::Ok, 0, scopesIn, {0}), + yexception, + "User ticket cannot contain empty uid list"); + } +} + +template <> +void Out<NTvmAuth::TUids>(IOutputStream& o, const NTvmAuth::TUids& v) { + for (const auto& uid : v) { + o << uid << ","; + } +} + +template <> +void Out<NTvmAuth::TScopes>(IOutputStream& o, const NTvmAuth::TScopes& v) { + for (const auto& scope : v) { + o << scope << ","; + } +} diff --git a/library/cpp/tvmauth/src/ut/utils_ut.cpp b/library/cpp/tvmauth/src/ut/utils_ut.cpp index ebf459a344..c9cb81c36f 100644 --- a/library/cpp/tvmauth/src/ut/utils_ut.cpp +++ b/library/cpp/tvmauth/src/ut/utils_ut.cpp @@ -1,13 +1,13 @@ -#include <library/cpp/tvmauth/src/utils.h> - +#include <library/cpp/tvmauth/src/utils.h> + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/maybe.h> - + +#include <util/generic/maybe.h> + Y_UNIT_TEST_SUITE(UtilsTestSuite) { - static const TString VALID_SERVICE_TICKET_1 = "3:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; - static const TString EXPIRED_SERVICE_TICKET = "3:serv:CBAQACIZCOUBEBwaCGJiOnNlc3MxGghiYjpzZXNzMg:IwfMNJYEqStY_SixwqJnyHOMCPR7-3HHk4uylB2oVRkthtezq-OOA7QizDvx7VABLs_iTlXuD1r5IjufNei_EiV145eaa3HIg4xCdJXCojMexf2UYJz8mF2b0YzFAy6_KWagU7xo13CyKAqzJuQf5MJcSUf0ecY9hVh36cJ51aw"; - using namespace NTvmAuth; + static const TString VALID_SERVICE_TICKET_1 = "3:serv:CBAQ__________9_IhkI5QEQHBoIYmI6c2VzczEaCGJiOnNlc3My:WUPx1cTf05fjD1exB35T5j2DCHWH1YaLJon_a4rN-D7JfXHK1Ai4wM4uSfboHD9xmGQH7extqtlEk1tCTCGm5qbRVloJwWzCZBXo3zKX6i1oBYP_89WcjCNPVe1e8jwGdLsnu6PpxL5cn0xCksiStILH5UmDR6xfkJdnmMG94o8"; + static const TString EXPIRED_SERVICE_TICKET = "3:serv:CBAQACIZCOUBEBwaCGJiOnNlc3MxGghiYjpzZXNzMg:IwfMNJYEqStY_SixwqJnyHOMCPR7-3HHk4uylB2oVRkthtezq-OOA7QizDvx7VABLs_iTlXuD1r5IjufNei_EiV145eaa3HIg4xCdJXCojMexf2UYJz8mF2b0YzFAy6_KWagU7xo13CyKAqzJuQf5MJcSUf0ecY9hVh36cJ51aw"; + using namespace NTvmAuth; Y_UNIT_TEST(base64Test) { UNIT_ASSERT_VALUES_EQUAL("-hHx", NUtils::Bin2base64url("\xfa\x11\xf1")); @@ -27,69 +27,69 @@ Y_UNIT_TEST_SUITE(UtilsTestSuite) { UNIT_ASSERT_VALUES_EQUAL("\xfa\x11\xf1\xfe\xff", NUtils::Base64url2bin("-hHx_v8=")); UNIT_ASSERT_VALUES_EQUAL("SGVsbG8sIGV2ZXJ5Ym9keSE", - NUtils::Bin2base64url(("Hello, everybody!"))); + NUtils::Bin2base64url(("Hello, everybody!"))); UNIT_ASSERT_VALUES_EQUAL("Hello, everybody!", - NUtils::Base64url2bin(("SGVsbG8sIGV2ZXJ5Ym9keSE"))); + NUtils::Base64url2bin(("SGVsbG8sIGV2ZXJ5Ym9keSE"))); UNIT_ASSERT_VALUES_EQUAL("VGhlIE1hZ2ljIFdvcmRzIGFyZSBTcXVlYW1pc2ggT3NzaWZyYWdl", - NUtils::Bin2base64url(("The Magic Words are Squeamish Ossifrage"))); + NUtils::Bin2base64url(("The Magic Words are Squeamish Ossifrage"))); UNIT_ASSERT_VALUES_EQUAL("The Magic Words are Squeamish Ossifrage", - NUtils::Base64url2bin(("VGhlIE1hZ2ljIFdvcmRzIGFyZSBTcXVlYW1pc2ggT3NzaWZyYWdl"))); + NUtils::Base64url2bin(("VGhlIE1hZ2ljIFdvcmRzIGFyZSBTcXVlYW1pc2ggT3NzaWZyYWdl"))); } Y_UNIT_TEST(sign) { UNIT_ASSERT_VALUES_EQUAL("wkGfeuopf709ozPAeGcDMqtZXPzsWvuNJ1BL586dSug", - NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOVnvOqe-WyD1"), - "1490000000", - "13,19", - "bb:sess,bb:sess2")); + NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOVnvOqe-WyD1"), + "1490000000", + "13,19", + "bb:sess,bb:sess2")); UNIT_ASSERT_VALUES_EQUAL("HANDYrA4ApQMQ5cfSWZk_InHWJffoXAa57P_X_B5s4M", - NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), - "1490000000", - "13,19", - "bb:sess,bb:sess2")); + NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), + "1490000000", + "13,19", + "bb:sess,bb:sess2")); UNIT_ASSERT_VALUES_EQUAL("T-M-3_qtjRM1dR_3hS1CRlHBTZRKK04doHXBJw-5VRk", - NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), - "1490000001", - "13,19", - "bb:sess,bb:sess2")); + NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), + "1490000001", + "13,19", + "bb:sess,bb:sess2")); UNIT_ASSERT_VALUES_EQUAL("gwB6M_9Jij50ZADmlDMnoyLc6AhQmtq6MClgGzO1PBE", - NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), - "1490000001", - "13,19", - "")); + NUtils::SignCgiParamsForTvm(NUtils::Base64url2bin("GRMJrKnj4fOasvOqe-WyD1"), + "1490000001", + "13,19", + "")); + } + + Y_UNIT_TEST(GetExpirationTime) { + UNIT_ASSERT(!NTvmAuth::NInternal::TCanningKnife::GetExpirationTime("3:aadasdasdasdas")); + + UNIT_ASSERT(NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(VALID_SERVICE_TICKET_1)); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), + *NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(VALID_SERVICE_TICKET_1)); + + UNIT_ASSERT(NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(EXPIRED_SERVICE_TICKET)); + UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(0), + *NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(EXPIRED_SERVICE_TICKET)); + } + + Y_UNIT_TEST(RemoveSignatureTest) { + UNIT_ASSERT_VALUES_EQUAL("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", + NUtils::RemoveTicketSignature("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", + NUtils::RemoveTicketSignature("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", + NUtils::RemoveTicketSignature("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds", + NUtils::RemoveTicketSignature("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("3:serv:", + NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); + UNIT_ASSERT_VALUES_EQUAL("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf", + NUtils::RemoveTicketSignature("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf")); } - - Y_UNIT_TEST(GetExpirationTime) { - UNIT_ASSERT(!NTvmAuth::NInternal::TCanningKnife::GetExpirationTime("3:aadasdasdasdas")); - - UNIT_ASSERT(NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(VALID_SERVICE_TICKET_1)); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(std::numeric_limits<time_t>::max()), - *NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(VALID_SERVICE_TICKET_1)); - - UNIT_ASSERT(NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(EXPIRED_SERVICE_TICKET)); - UNIT_ASSERT_VALUES_EQUAL(TInstant::Seconds(0), - *NTvmAuth::NInternal::TCanningKnife::GetExpirationTime(EXPIRED_SERVICE_TICKET)); - } - - Y_UNIT_TEST(RemoveSignatureTest) { - UNIT_ASSERT_VALUES_EQUAL("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("1:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("2:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("4:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds", - NUtils::RemoveTicketSignature("3.serv.ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs:asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("3:serv:", - NUtils::RemoveTicketSignature("3:serv:ASDkljbjhsdbfLJHABFJHBslfbsfjs.asdxcvbxcvniueliuweklsvds")); - UNIT_ASSERT_VALUES_EQUAL("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf", - NUtils::RemoveTicketSignature("asdxcbvfgdsgfasdfxczvdsgfxcdvbcbvf")); - } } diff --git a/library/cpp/tvmauth/src/ut/version_ut.cpp b/library/cpp/tvmauth/src/ut/version_ut.cpp index f13d4683e2..eeb95d1cde 100644 --- a/library/cpp/tvmauth/src/ut/version_ut.cpp +++ b/library/cpp/tvmauth/src/ut/version_ut.cpp @@ -1,18 +1,18 @@ -#include <library/cpp/tvmauth/version.h> - -#include <library/cpp/testing/unittest/registar.h> - -#include <regex> - -using namespace NTvmAuth; - -Y_UNIT_TEST_SUITE(VersionTest) { - Y_UNIT_TEST(base64Test) { - const std::regex re(R"(^\d+\.\d+\.\d+$)"); - - for (size_t idx = 0; idx < 2; ++idx) { - TStringBuf ver = LibVersion(); - UNIT_ASSERT(std::regex_match(ver.begin(), ver.end(), re)); - } - } -} +#include <library/cpp/tvmauth/version.h> + +#include <library/cpp/testing/unittest/registar.h> + +#include <regex> + +using namespace NTvmAuth; + +Y_UNIT_TEST_SUITE(VersionTest) { + Y_UNIT_TEST(base64Test) { + const std::regex re(R"(^\d+\.\d+\.\d+$)"); + + for (size_t idx = 0; idx < 2; ++idx) { + TStringBuf ver = LibVersion(); + UNIT_ASSERT(std::regex_match(ver.begin(), ver.end(), re)); + } + } +} diff --git a/library/cpp/tvmauth/src/ut/ya.make b/library/cpp/tvmauth/src/ut/ya.make index 7207f503c5..9f510a8363 100644 --- a/library/cpp/tvmauth/src/ut/ya.make +++ b/library/cpp/tvmauth/src/ut/ya.make @@ -1,6 +1,6 @@ -UNITTEST_FOR(library/cpp/tvmauth) +UNITTEST_FOR(library/cpp/tvmauth) -OWNER(g:passport_infra) +OWNER(g:passport_infra) SRCS( parser_ut.cpp @@ -8,7 +8,7 @@ SRCS( service_ut.cpp user_ut.cpp utils_ut.cpp - version_ut.cpp + version_ut.cpp ) END() diff --git a/library/cpp/tvmauth/src/utils.cpp b/library/cpp/tvmauth/src/utils.cpp index 7f5346ec29..d49efa28b5 100644 --- a/library/cpp/tvmauth/src/utils.cpp +++ b/library/cpp/tvmauth/src/utils.cpp @@ -1,162 +1,162 @@ #include "utils.h" -#include "parser.h" - +#include "parser.h" + #include <contrib/libs/openssl/include/openssl/evp.h> #include <contrib/libs/openssl/include/openssl/hmac.h> #include <contrib/libs/openssl/include/openssl/md5.h> #include <contrib/libs/openssl/include/openssl/sha.h> -#include <util/generic/maybe.h> +#include <util/generic/maybe.h> #include <util/generic/strbuf.h> -#include <array> - +#include <array> + namespace { - constexpr const unsigned char b64_encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; - - constexpr std::array<unsigned char, 256> B64Init() { - std::array<unsigned char, 256> buf{}; - for (auto& i : buf) + constexpr const unsigned char b64_encode[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"; + + constexpr std::array<unsigned char, 256> B64Init() { + std::array<unsigned char, 256> buf{}; + for (auto& i : buf) i = 0xff; for (int i = 0; i < 64; ++i) - buf[b64_encode[i]] = i; + buf[b64_encode[i]] = i; - return buf; + return buf; } - constexpr std::array<unsigned char, 256> b64_decode = B64Init(); -} - -namespace NTvmAuth::NUtils { - TString Bin2base64url(TStringBuf buf) { - if (!buf) { - return TString(); - } - - TString res; - res.resize(((buf.size() + 2) / 3) << 2, 0); - - const unsigned char* pB = (const unsigned char*)buf.data(); - const unsigned char* pE = (const unsigned char*)buf.data() + buf.size(); - unsigned char* p = (unsigned char*)res.data(); - for (; pB + 2 < pE; pB += 3) { - const unsigned char a = *pB; - *p++ = b64_encode[(a >> 2) & 0x3F]; - const unsigned char b = *(pB + 1); - *p++ = b64_encode[((a & 0x3) << 4) | ((b & 0xF0) >> 4)]; - const unsigned char c = *(pB + 2); - *p++ = b64_encode[((b & 0xF) << 2) | ((c & 0xC0) >> 6)]; - *p++ = b64_encode[c & 0x3F]; - } - - if (pB < pE) { - const unsigned char a = *pB; - *p++ = b64_encode[(a >> 2) & 0x3F]; - - if (pB == (pE - 1)) { - *p++ = b64_encode[((a & 0x3) << 4)]; - } else { - const unsigned char b = *(pB + 1); - *p++ = b64_encode[((a & 0x3) << 4) | - ((int)(b & 0xF0) >> 4)]; - *p++ = b64_encode[((b & 0xF) << 2)]; - } + constexpr std::array<unsigned char, 256> b64_decode = B64Init(); +} + +namespace NTvmAuth::NUtils { + TString Bin2base64url(TStringBuf buf) { + if (!buf) { + return TString(); + } + + TString res; + res.resize(((buf.size() + 2) / 3) << 2, 0); + + const unsigned char* pB = (const unsigned char*)buf.data(); + const unsigned char* pE = (const unsigned char*)buf.data() + buf.size(); + unsigned char* p = (unsigned char*)res.data(); + for (; pB + 2 < pE; pB += 3) { + const unsigned char a = *pB; + *p++ = b64_encode[(a >> 2) & 0x3F]; + const unsigned char b = *(pB + 1); + *p++ = b64_encode[((a & 0x3) << 4) | ((b & 0xF0) >> 4)]; + const unsigned char c = *(pB + 2); + *p++ = b64_encode[((b & 0xF) << 2) | ((c & 0xC0) >> 6)]; + *p++ = b64_encode[c & 0x3F]; } - res.resize(p - (unsigned char*)res.data()); - return res; + if (pB < pE) { + const unsigned char a = *pB; + *p++ = b64_encode[(a >> 2) & 0x3F]; + + if (pB == (pE - 1)) { + *p++ = b64_encode[((a & 0x3) << 4)]; + } else { + const unsigned char b = *(pB + 1); + *p++ = b64_encode[((a & 0x3) << 4) | + ((int)(b & 0xF0) >> 4)]; + *p++ = b64_encode[((b & 0xF) << 2)]; + } + } + + res.resize(p - (unsigned char*)res.data()); + return res; } - TString Base64url2bin(TStringBuf buf) { - const unsigned char* bufin = (const unsigned char*)buf.data(); - if (!buf || b64_decode[*bufin] > 63) { - return TString(); + TString Base64url2bin(TStringBuf buf) { + const unsigned char* bufin = (const unsigned char*)buf.data(); + if (!buf || b64_decode[*bufin] > 63) { + return TString(); + } + const unsigned char* bufend = (const unsigned char*)buf.data() + buf.size(); + while (++bufin < bufend && b64_decode[*bufin] < 64) + ; + int nprbytes = (bufin - (const unsigned char*)buf.data()); + int nbytesdecoded = ((nprbytes + 3) / 4) * 3; + + if (nprbytes < static_cast<int>(buf.size())) { + int left = buf.size() - nprbytes; + while (left--) { + if (*(bufin++) != '=') + return TString(); + } + } + + TString res; + res.resize(nbytesdecoded); + + unsigned char* bufout = (unsigned char*)res.data(); + bufin = (const unsigned char*)buf.data(); + + while (nprbytes > 4) { + unsigned char a = b64_decode[*bufin]; + unsigned char b = b64_decode[bufin[1]]; + *(bufout++) = (unsigned char)(a << 2 | b >> 4); + unsigned char c = b64_decode[bufin[2]]; + *(bufout++) = (unsigned char)(b << 4 | c >> 2); + unsigned char d = b64_decode[bufin[3]]; + *(bufout++) = (unsigned char)(c << 6 | d); + bufin += 4; + nprbytes -= 4; + } + + if (nprbytes == 1) { + return {}; // Impossible } - const unsigned char* bufend = (const unsigned char*)buf.data() + buf.size(); - while (++bufin < bufend && b64_decode[*bufin] < 64) - ; - int nprbytes = (bufin - (const unsigned char*)buf.data()); - int nbytesdecoded = ((nprbytes + 3) / 4) * 3; - - if (nprbytes < static_cast<int>(buf.size())) { - int left = buf.size() - nprbytes; - while (left--) { - if (*(bufin++) != '=') - return TString(); - } - } - - TString res; - res.resize(nbytesdecoded); - - unsigned char* bufout = (unsigned char*)res.data(); - bufin = (const unsigned char*)buf.data(); - - while (nprbytes > 4) { - unsigned char a = b64_decode[*bufin]; - unsigned char b = b64_decode[bufin[1]]; - *(bufout++) = (unsigned char)(a << 2 | b >> 4); - unsigned char c = b64_decode[bufin[2]]; - *(bufout++) = (unsigned char)(b << 4 | c >> 2); - unsigned char d = b64_decode[bufin[3]]; - *(bufout++) = (unsigned char)(c << 6 | d); - bufin += 4; - nprbytes -= 4; - } - - if (nprbytes == 1) { - return {}; // Impossible - } - if (nprbytes > 1) { - *(bufout++) = (unsigned char)(b64_decode[*bufin] << 2 | b64_decode[bufin[1]] >> 4); - } - if (nprbytes > 2) { - *(bufout++) = (unsigned char)(b64_decode[bufin[1]] << 4 | b64_decode[bufin[2]] >> 2); - } - if (nprbytes > 3) { - *(bufout++) = (unsigned char)(b64_decode[bufin[2]] << 6 | b64_decode[bufin[3]]); - } - - int diff = (4 - nprbytes) & 3; - if (diff) { - nbytesdecoded -= (4 - nprbytes) & 3; - res.resize(nbytesdecoded); - } - - return res; + if (nprbytes > 1) { + *(bufout++) = (unsigned char)(b64_decode[*bufin] << 2 | b64_decode[bufin[1]] >> 4); + } + if (nprbytes > 2) { + *(bufout++) = (unsigned char)(b64_decode[bufin[1]] << 4 | b64_decode[bufin[2]] >> 2); + } + if (nprbytes > 3) { + *(bufout++) = (unsigned char)(b64_decode[bufin[2]] << 6 | b64_decode[bufin[3]]); + } + + int diff = (4 - nprbytes) & 3; + if (diff) { + nbytesdecoded -= (4 - nprbytes) & 3; + res.resize(nbytesdecoded); + } + + return res; } - TString SignCgiParamsForTvm(TStringBuf secret, TStringBuf ts, TStringBuf dstTvmId, TStringBuf scopes) { - TString data; - data.reserve(ts.size() + dstTvmId.size() + scopes.size() + 3); - const char DELIM = '|'; - data.append(ts).push_back(DELIM); - data.append(dstTvmId).push_back(DELIM); - data.append(scopes).push_back(DELIM); - - TString value(EVP_MAX_MD_SIZE, 0); - unsigned macLen = 0; - - if (!::HMAC(EVP_sha256(), secret.data(), secret.size(), (unsigned char*)data.data(), data.size(), - (unsigned char*)value.data(), &macLen)) - { - return {}; - } - - if (macLen != EVP_MAX_MD_SIZE) { - value.resize(macLen); - } - return Bin2base64url(value); + TString SignCgiParamsForTvm(TStringBuf secret, TStringBuf ts, TStringBuf dstTvmId, TStringBuf scopes) { + TString data; + data.reserve(ts.size() + dstTvmId.size() + scopes.size() + 3); + const char DELIM = '|'; + data.append(ts).push_back(DELIM); + data.append(dstTvmId).push_back(DELIM); + data.append(scopes).push_back(DELIM); + + TString value(EVP_MAX_MD_SIZE, 0); + unsigned macLen = 0; + + if (!::HMAC(EVP_sha256(), secret.data(), secret.size(), (unsigned char*)data.data(), data.size(), + (unsigned char*)value.data(), &macLen)) + { + return {}; + } + + if (macLen != EVP_MAX_MD_SIZE) { + value.resize(macLen); + } + return Bin2base64url(value); + } +} + +namespace NTvmAuth::NInternal { + TMaybe<TInstant> TCanningKnife::GetExpirationTime(TStringBuf ticket) { + const TParserTickets::TRes res = TParserTickets::ParseV3(ticket, {}, TParserTickets::ServiceFlag()); + + return res.Status == ETicketStatus::MissingKey || res.Status == ETicketStatus::Expired + ? TInstant::Seconds(res.Ticket.expirationtime()) + : TMaybe<TInstant>(); } } - -namespace NTvmAuth::NInternal { - TMaybe<TInstant> TCanningKnife::GetExpirationTime(TStringBuf ticket) { - const TParserTickets::TRes res = TParserTickets::ParseV3(ticket, {}, TParserTickets::ServiceFlag()); - - return res.Status == ETicketStatus::MissingKey || res.Status == ETicketStatus::Expired - ? TInstant::Seconds(res.Ticket.expirationtime()) - : TMaybe<TInstant>(); - } -} diff --git a/library/cpp/tvmauth/src/utils.h b/library/cpp/tvmauth/src/utils.h index 7a457affb8..e5847ac89f 100644 --- a/library/cpp/tvmauth/src/utils.h +++ b/library/cpp/tvmauth/src/utils.h @@ -1,30 +1,30 @@ #pragma once -#include <library/cpp/tvmauth/checked_service_ticket.h> -#include <library/cpp/tvmauth/checked_user_ticket.h> -#include <library/cpp/tvmauth/ticket_status.h> +#include <library/cpp/tvmauth/checked_service_ticket.h> +#include <library/cpp/tvmauth/checked_user_ticket.h> +#include <library/cpp/tvmauth/ticket_status.h> -#include <util/datetime/base.h> +#include <util/datetime/base.h> #include <util/generic/fwd.h> -namespace NTvmAuth::NUtils { - TString Bin2base64url(TStringBuf buf); - TString Base64url2bin(TStringBuf buf); +namespace NTvmAuth::NUtils { + TString Bin2base64url(TStringBuf buf); + TString Base64url2bin(TStringBuf buf); - TString SignCgiParamsForTvm(TStringBuf secret, TStringBuf ts, TStringBuf dstTvmId, TStringBuf scopes); -} - -namespace NTvmAuth::NInternal { - class TCanningKnife { - public: - static TCheckedServiceTicket::TImpl* GetS(TCheckedServiceTicket& t) { - return t.Impl_.Release(); - } - - static TCheckedUserTicket::TImpl* GetU(TCheckedUserTicket& t) { - return t.Impl_.Release(); - } - - static TMaybe<TInstant> GetExpirationTime(TStringBuf ticket); - }; -} + TString SignCgiParamsForTvm(TStringBuf secret, TStringBuf ts, TStringBuf dstTvmId, TStringBuf scopes); +} + +namespace NTvmAuth::NInternal { + class TCanningKnife { + public: + static TCheckedServiceTicket::TImpl* GetS(TCheckedServiceTicket& t) { + return t.Impl_.Release(); + } + + static TCheckedUserTicket::TImpl* GetU(TCheckedUserTicket& t) { + return t.Impl_.Release(); + } + + static TMaybe<TInstant> GetExpirationTime(TStringBuf ticket); + }; +} diff --git a/library/cpp/tvmauth/src/version b/library/cpp/tvmauth/src/version index 1bcf861c56..15a2799817 100644 --- a/library/cpp/tvmauth/src/version +++ b/library/cpp/tvmauth/src/version @@ -1 +1 @@ -3.3.0 +3.3.0 diff --git a/library/cpp/tvmauth/src/version.cpp b/library/cpp/tvmauth/src/version.cpp index 05709c3929..6b389213d0 100644 --- a/library/cpp/tvmauth/src/version.cpp +++ b/library/cpp/tvmauth/src/version.cpp @@ -1,26 +1,26 @@ -#include <library/cpp/resource/resource.h> - -#include <util/string/strip.h> +#include <library/cpp/resource/resource.h> -namespace { - class TBuiltinVersion { - public: - TBuiltinVersion() { - Version_ = NResource::Find("/builtin/version"); - StripInPlace(Version_); - } - - TStringBuf Get() const { - return Version_; - } - - private: - TString Version_; - }; -} - -namespace NTvmAuth { +#include <util/string/strip.h> + +namespace { + class TBuiltinVersion { + public: + TBuiltinVersion() { + Version_ = NResource::Find("/builtin/version"); + StripInPlace(Version_); + } + + TStringBuf Get() const { + return Version_; + } + + private: + TString Version_; + }; +} + +namespace NTvmAuth { TStringBuf LibVersion() { - return Singleton<TBuiltinVersion>()->Get(); + return Singleton<TBuiltinVersion>()->Get(); } -} +} diff --git a/library/cpp/tvmauth/test_all/ya.make b/library/cpp/tvmauth/test_all/ya.make index 5ae50c1092..bb5bb9e5ef 100644 --- a/library/cpp/tvmauth/test_all/ya.make +++ b/library/cpp/tvmauth/test_all/ya.make @@ -1,21 +1,21 @@ -RECURSE_ROOT_RELATIVE( - library/cpp/tvmauth - library/cpp/tvmauth/client - library/go/yandex/tvm - library/go/yandex/tvm/tvmauth - library/java/ticket_parser2 - library/java/tvmauth - library/python/deprecated/ticket_parser2 - library/python/tvmauth -) - -IF (NOT OS_WINDOWS) - RECURSE_ROOT_RELATIVE( - library/c/tvmauth/src/ut - ) - IF (NOT SANITIZER_TYPE) - RECURSE_ROOT_RELATIVE( - library/c/tvmauth/src/ut_export - ) - ENDIF() -ENDIF() +RECURSE_ROOT_RELATIVE( + library/cpp/tvmauth + library/cpp/tvmauth/client + library/go/yandex/tvm + library/go/yandex/tvm/tvmauth + library/java/ticket_parser2 + library/java/tvmauth + library/python/deprecated/ticket_parser2 + library/python/tvmauth +) + +IF (NOT OS_WINDOWS) + RECURSE_ROOT_RELATIVE( + library/c/tvmauth/src/ut + ) + IF (NOT SANITIZER_TYPE) + RECURSE_ROOT_RELATIVE( + library/c/tvmauth/src/ut_export + ) + ENDIF() +ENDIF() diff --git a/library/cpp/tvmauth/ticket_status.h b/library/cpp/tvmauth/ticket_status.h index 2f413aef3f..532d4de56e 100644 --- a/library/cpp/tvmauth/ticket_status.h +++ b/library/cpp/tvmauth/ticket_status.h @@ -2,11 +2,11 @@ #include <util/generic/strbuf.h> -namespace NTvmAuth { - /*! - * Status mean result of ticket check - */ - enum class ETicketStatus { +namespace NTvmAuth { + /*! + * Status mean result of ticket check + */ + enum class ETicketStatus { Ok, Expired, InvalidBlackboxEnv, @@ -16,8 +16,8 @@ namespace NTvmAuth { MissingKey, SignBroken, UnsupportedVersion, - NoRoles, + NoRoles, }; - TStringBuf StatusToString(ETicketStatus st); + TStringBuf StatusToString(ETicketStatus st); } diff --git a/library/cpp/tvmauth/type.h b/library/cpp/tvmauth/type.h index 186714cd8b..7f4ce2b700 100644 --- a/library/cpp/tvmauth/type.h +++ b/library/cpp/tvmauth/type.h @@ -2,10 +2,10 @@ #include <library/cpp/containers/stack_vector/stack_vec.h> -namespace NTvmAuth { +namespace NTvmAuth { using TScopes = TSmallVec<TStringBuf>; - using TTvmId = ui32; - using TUid = ui64; + using TTvmId = ui32; + using TUid = ui64; using TUids = TSmallVec<TUid>; - using TAlias = TString; + using TAlias = TString; } diff --git a/library/cpp/tvmauth/unittest.h b/library/cpp/tvmauth/unittest.h index 50cc6f3b12..efa651befa 100644 --- a/library/cpp/tvmauth/unittest.h +++ b/library/cpp/tvmauth/unittest.h @@ -1,20 +1,20 @@ -#pragma once - -#include "checked_service_ticket.h" -#include "checked_user_ticket.h" - -#include <util/generic/maybe.h> - -namespace NTvmAuth::NUnittest { - static const TString TVMKNIFE_PUBLIC_KEYS = "1:CpgCCpMCCAEQABqIAjCCAQQCggEAcLEXeH67FQESFUn4_7wnX7wN0PUrBoUsm3QQ4W5vC-qz6sXaEjSwnTV8w1o-z6X9KPLlhzMQvuS38NCNfK4uvJ4Zvfp3YsXJ25-rYtbnrYJHNvHohD-kPCCw_yZpMp21JdWigzQGuV7CtrxUhF-NNrsnUaJrE5-OpEWNt4X6nCItKIYeVcSK6XJUbEWbrNCRbvkSc4ak2ymFeMuHYJVjxh4eQbk7_ZPzodP0WvF6eUYrYeb42imVEOR8ofVLQWE5DVnb1z_TqZm4i1XkS7jMwZuBxBRw8DGdYei0lT_sAf7KST2jC0590NySB3vsBgWEVs1OdUUWA6r-Dvx9dsOQtSCVkQYQAAqZAgqUAggCEAAaiQIwggEFAoIBAQDhEBM5-6YsPWfogKtbluJoCX1WV2KdzOaQ0-OlRbBzeCzw-eQKu12c8WakHBbeCMd1I1TU64SDkDorWjXGIa_2xT6N3zzNAE50roTbPCcmeQrps26woTYfYIuqDdoxYKZNr0lvNLLW47vBr7EKqo1S4KSj7aXK_XYeEvUgIgf3nVIcNrio7VTnFmGGVQCepaL1Hi1gN4yIXjVZ06PBPZ-DxSRu6xOGbFrfKMJeMPs7KOyE-26Q3xOXdTIa1X-zYIucTd_bxUCL4BVbwW2AvbbFsaG7ISmVdGu0XUTmhXs1KrEfUVLRJhE4Dx99hAZXm1_HlYMUeJcMQ_oHOhV94ENFIJaRBhACCpYBCpEBCAMQABqGATCBgwKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NIJeRBhABCpYBCpEBCAQQABqGATCBgwKBgGB4d6eLGUBv-Q6EPLehC4S-yuE2HB-_rJ7WkeYwyp-xIPolPrd-PQme2utHB4ZgpXHIu_OFksDe_0bPgZniNRSVRbl7W49DgS5Ya3kMfrYB4DnF5Fta5tn1oV6EwxYD4JONpFTenOJALPGTPawxXEfon_peiHOSBuQMu3_Vn-l1IJiRBhADCpcBCpIBCAUQABqHATCBhAKBgQCTJMKIfmfeZpaI7Q9rnsc29gdWawK7TnpVKRHws1iY7EUlYROeVcMdAwEqVM6f8BVCKLGgzQ7Gar_uuxfUGKwqEQzoppDraw4F75J464-7D5f6_oJQuGIBHZxqbMONtLjBCXRUhQW5szBLmTQ_R3qaJb5vf-h0APZfkYhq1cTttSCZkQYQBAqWAQqRAQgLEAAahgEwgYMCgYBvvGVH_M2H8qxxv94yaDYUTWbRnJ1uiIYc59KIQlfFimMPhSS7x2tqUa2-hI55JiII0Xym6GNkwLhyc1xtWChpVuIdSnbvttbrt4weDMLHqTwNOF6qAsVKGKT1Yh8yf-qb-DSmicgvFc74mBQm_6gAY1iQsf33YX8578ClhKBWHSCVkQYQAAqXAQqSAQgMEAAahwEwgYQCgYEAkuzFcd5TJu7lYWYe2hQLFfUWIIj91BvQQLa_Thln4YtGCO8gG1KJqJm-YlmJOWQG0B7H_5RVhxUxV9KpmFnsDVkzUFKOsCBaYGXc12xPVioawUlAwp5qp3QQtZyx_se97YIoLzuLr46UkLcLnkIrp-Jo46QzYi_QHq45WTm8MQ0glpEGEAIKlwEKkgEIDRAAGocBMIGEAoGBAIUzbxOknXf_rNt17_ir8JlWvrtnCWsQd1MAnl5mgArvavDtKeBYHzi5_Ak7DHlLzuA6YE8W175FxLFKpN2hkz-l-M7ltUSd8N1BvJRhK4t6WffWfC_1wPyoAbeSN2Yb1jygtZJQ8wGoXHcJQUXiMit3eFNyylwsJFj1gzAR4JCdIJeRBhABCpYBCpEBCA4QABqGATCBgwKBgFMcbEpl9ukVR6AO_R6sMyiU11I8b8MBSUCEC15iKsrVO8v_m47_TRRjWPYtQ9eZ7o1ocNJHaGUU7qqInFqtFaVnIceP6NmCsXhjs3MLrWPS8IRAy4Zf4FKmGOx3N9O2vemjUygZ9vUiSkULdVrecinRaT8JQ5RG4bUMY04XGIwFIJiRBhADCpYBCpEBCA8QABqGATCBgwKBgGpCkW-NR3li8GlRvqpq2YZGSIgm_PTyDI2Zwfw69grsBmPpVFW48Vw7xoMN35zcrojEpialB_uQzlpLYOvsMl634CRIuj-n1QE3-gaZTTTE8mg-AR4mcxnTKThPnRQpbuOlYAnriwiasWiQEMbGjq_HmWioYYxFo9USlklQn4-9IJmRBhAEEpUBCpIBCAYQABqHATCBhAKBgQCoZkFGm9oLTqjeXZAq6j5S6i7K20V0lNdBBLqfmFBIRuTkYxhs4vUYnWjZrKRAd5bp6_py0csmFmpl_5Yh0b-2pdo_E5PNP7LGRzKyKSiFddyykKKzVOazH8YYldDAfE8Z5HoS9e48an5JsPg0jr-TPu34DnJq3yv2a6dqiKL9zSCakQYSlQEKkgEIEBAAGocBMIGEAoGBALhrihbf3EpjDQS2sCQHazoFgN0nBbE9eesnnFTfzQELXb2gnJU9enmV_aDqaHKjgtLIPpCgn40lHrn5k6mvH5OdedyI6cCzE-N-GFp3nAq0NDJyMe0fhtIRD__CbT0ulcvkeow65ubXWfw6dBC2gR_34rdMe_L_TGRLMWjDULbNIJqRBg"; - - TCheckedServiceTicket CreateServiceTicket(ETicketStatus status, - TTvmId src, - TMaybe<TUid> issuerUid = TMaybe<TUid>()); - - TCheckedUserTicket CreateUserTicket(ETicketStatus status, - TUid defaultUid, - const TScopes& scopes, - const TUids& uids = TUids(), - EBlackboxEnv env = EBlackboxEnv::Test); -} +#pragma once + +#include "checked_service_ticket.h" +#include "checked_user_ticket.h" + +#include <util/generic/maybe.h> + +namespace NTvmAuth::NUnittest { + static const TString TVMKNIFE_PUBLIC_KEYS = "1:CpgCCpMCCAEQABqIAjCCAQQCggEAcLEXeH67FQESFUn4_7wnX7wN0PUrBoUsm3QQ4W5vC-qz6sXaEjSwnTV8w1o-z6X9KPLlhzMQvuS38NCNfK4uvJ4Zvfp3YsXJ25-rYtbnrYJHNvHohD-kPCCw_yZpMp21JdWigzQGuV7CtrxUhF-NNrsnUaJrE5-OpEWNt4X6nCItKIYeVcSK6XJUbEWbrNCRbvkSc4ak2ymFeMuHYJVjxh4eQbk7_ZPzodP0WvF6eUYrYeb42imVEOR8ofVLQWE5DVnb1z_TqZm4i1XkS7jMwZuBxBRw8DGdYei0lT_sAf7KST2jC0590NySB3vsBgWEVs1OdUUWA6r-Dvx9dsOQtSCVkQYQAAqZAgqUAggCEAAaiQIwggEFAoIBAQDhEBM5-6YsPWfogKtbluJoCX1WV2KdzOaQ0-OlRbBzeCzw-eQKu12c8WakHBbeCMd1I1TU64SDkDorWjXGIa_2xT6N3zzNAE50roTbPCcmeQrps26woTYfYIuqDdoxYKZNr0lvNLLW47vBr7EKqo1S4KSj7aXK_XYeEvUgIgf3nVIcNrio7VTnFmGGVQCepaL1Hi1gN4yIXjVZ06PBPZ-DxSRu6xOGbFrfKMJeMPs7KOyE-26Q3xOXdTIa1X-zYIucTd_bxUCL4BVbwW2AvbbFsaG7ISmVdGu0XUTmhXs1KrEfUVLRJhE4Dx99hAZXm1_HlYMUeJcMQ_oHOhV94ENFIJaRBhACCpYBCpEBCAMQABqGATCBgwKBgF9t2YJGAJkRRFq6fWhi3m1TFW1UOE0f6ZrfYhHAkpqGlKlh0QVfeTNPpeJhi75xXzCe6oReRUm-0DbqDNhTShC7uGUv1INYnRBQWH6E-5Fc5XrbDFSuGQw2EYjNfHy_HefHJXxQKAqPvxBDKMKkHgV58WtM6rC8jRi9sdX_ig2NIJeRBhABCpYBCpEBCAQQABqGATCBgwKBgGB4d6eLGUBv-Q6EPLehC4S-yuE2HB-_rJ7WkeYwyp-xIPolPrd-PQme2utHB4ZgpXHIu_OFksDe_0bPgZniNRSVRbl7W49DgS5Ya3kMfrYB4DnF5Fta5tn1oV6EwxYD4JONpFTenOJALPGTPawxXEfon_peiHOSBuQMu3_Vn-l1IJiRBhADCpcBCpIBCAUQABqHATCBhAKBgQCTJMKIfmfeZpaI7Q9rnsc29gdWawK7TnpVKRHws1iY7EUlYROeVcMdAwEqVM6f8BVCKLGgzQ7Gar_uuxfUGKwqEQzoppDraw4F75J464-7D5f6_oJQuGIBHZxqbMONtLjBCXRUhQW5szBLmTQ_R3qaJb5vf-h0APZfkYhq1cTttSCZkQYQBAqWAQqRAQgLEAAahgEwgYMCgYBvvGVH_M2H8qxxv94yaDYUTWbRnJ1uiIYc59KIQlfFimMPhSS7x2tqUa2-hI55JiII0Xym6GNkwLhyc1xtWChpVuIdSnbvttbrt4weDMLHqTwNOF6qAsVKGKT1Yh8yf-qb-DSmicgvFc74mBQm_6gAY1iQsf33YX8578ClhKBWHSCVkQYQAAqXAQqSAQgMEAAahwEwgYQCgYEAkuzFcd5TJu7lYWYe2hQLFfUWIIj91BvQQLa_Thln4YtGCO8gG1KJqJm-YlmJOWQG0B7H_5RVhxUxV9KpmFnsDVkzUFKOsCBaYGXc12xPVioawUlAwp5qp3QQtZyx_se97YIoLzuLr46UkLcLnkIrp-Jo46QzYi_QHq45WTm8MQ0glpEGEAIKlwEKkgEIDRAAGocBMIGEAoGBAIUzbxOknXf_rNt17_ir8JlWvrtnCWsQd1MAnl5mgArvavDtKeBYHzi5_Ak7DHlLzuA6YE8W175FxLFKpN2hkz-l-M7ltUSd8N1BvJRhK4t6WffWfC_1wPyoAbeSN2Yb1jygtZJQ8wGoXHcJQUXiMit3eFNyylwsJFj1gzAR4JCdIJeRBhABCpYBCpEBCA4QABqGATCBgwKBgFMcbEpl9ukVR6AO_R6sMyiU11I8b8MBSUCEC15iKsrVO8v_m47_TRRjWPYtQ9eZ7o1ocNJHaGUU7qqInFqtFaVnIceP6NmCsXhjs3MLrWPS8IRAy4Zf4FKmGOx3N9O2vemjUygZ9vUiSkULdVrecinRaT8JQ5RG4bUMY04XGIwFIJiRBhADCpYBCpEBCA8QABqGATCBgwKBgGpCkW-NR3li8GlRvqpq2YZGSIgm_PTyDI2Zwfw69grsBmPpVFW48Vw7xoMN35zcrojEpialB_uQzlpLYOvsMl634CRIuj-n1QE3-gaZTTTE8mg-AR4mcxnTKThPnRQpbuOlYAnriwiasWiQEMbGjq_HmWioYYxFo9USlklQn4-9IJmRBhAEEpUBCpIBCAYQABqHATCBhAKBgQCoZkFGm9oLTqjeXZAq6j5S6i7K20V0lNdBBLqfmFBIRuTkYxhs4vUYnWjZrKRAd5bp6_py0csmFmpl_5Yh0b-2pdo_E5PNP7LGRzKyKSiFddyykKKzVOazH8YYldDAfE8Z5HoS9e48an5JsPg0jr-TPu34DnJq3yv2a6dqiKL9zSCakQYSlQEKkgEIEBAAGocBMIGEAoGBALhrihbf3EpjDQS2sCQHazoFgN0nBbE9eesnnFTfzQELXb2gnJU9enmV_aDqaHKjgtLIPpCgn40lHrn5k6mvH5OdedyI6cCzE-N-GFp3nAq0NDJyMe0fhtIRD__CbT0ulcvkeow65ubXWfw6dBC2gR_34rdMe_L_TGRLMWjDULbNIJqRBg"; + + TCheckedServiceTicket CreateServiceTicket(ETicketStatus status, + TTvmId src, + TMaybe<TUid> issuerUid = TMaybe<TUid>()); + + TCheckedUserTicket CreateUserTicket(ETicketStatus status, + TUid defaultUid, + const TScopes& scopes, + const TUids& uids = TUids(), + EBlackboxEnv env = EBlackboxEnv::Test); +} diff --git a/library/cpp/tvmauth/utils.cpp b/library/cpp/tvmauth/utils.cpp index 16e9cb63b9..a06cd6f5ba 100644 --- a/library/cpp/tvmauth/utils.cpp +++ b/library/cpp/tvmauth/utils.cpp @@ -1,18 +1,18 @@ -#include "utils.h" - -namespace NTvmAuth::NUtils { - TStringBuf RemoveTicketSignature(TStringBuf ticketBody) { - if (ticketBody.size() < 2 || - ticketBody[0] != '3' || - ticketBody[1] != ':') { - return ticketBody; - } - - size_t pos = ticketBody.rfind(':'); - if (pos == TStringBuf::npos) { // impossible - return ticketBody; - } - - return ticketBody.substr(0, pos + 1); - } -} +#include "utils.h" + +namespace NTvmAuth::NUtils { + TStringBuf RemoveTicketSignature(TStringBuf ticketBody) { + if (ticketBody.size() < 2 || + ticketBody[0] != '3' || + ticketBody[1] != ':') { + return ticketBody; + } + + size_t pos = ticketBody.rfind(':'); + if (pos == TStringBuf::npos) { // impossible + return ticketBody; + } + + return ticketBody.substr(0, pos + 1); + } +} diff --git a/library/cpp/tvmauth/utils.h b/library/cpp/tvmauth/utils.h index e7af712c87..ad8950cab5 100644 --- a/library/cpp/tvmauth/utils.h +++ b/library/cpp/tvmauth/utils.h @@ -1,12 +1,12 @@ -#pragma once - -#include <util/generic/strbuf.h> - -namespace NTvmAuth::NUtils { - /*! - * Remove signature from ticket string - rest part can be parsed later with `tvmknife parse_ticket ...` - * @param ticketBody Raw ticket body - * @return safe for logging part of ticket - */ - TStringBuf RemoveTicketSignature(TStringBuf ticketBody); -} +#pragma once + +#include <util/generic/strbuf.h> + +namespace NTvmAuth::NUtils { + /*! + * Remove signature from ticket string - rest part can be parsed later with `tvmknife parse_ticket ...` + * @param ticketBody Raw ticket body + * @return safe for logging part of ticket + */ + TStringBuf RemoveTicketSignature(TStringBuf ticketBody); +} diff --git a/library/cpp/tvmauth/version.h b/library/cpp/tvmauth/version.h index 82bbef2b46..48ec279829 100644 --- a/library/cpp/tvmauth/version.h +++ b/library/cpp/tvmauth/version.h @@ -2,6 +2,6 @@ #include <util/generic/strbuf.h> -namespace NTvmAuth { +namespace NTvmAuth { TStringBuf LibVersion(); } diff --git a/library/cpp/tvmauth/ya.make b/library/cpp/tvmauth/ya.make index df422bbf39..655336c902 100644 --- a/library/cpp/tvmauth/ya.make +++ b/library/cpp/tvmauth/ya.make @@ -1,40 +1,40 @@ -LIBRARY() +LIBRARY() -OWNER(g:passport_infra) +OWNER(g:passport_infra) PEERDIR( - library/cpp/string_utils/secret_string - library/cpp/tvmauth/src/protos - library/cpp/tvmauth/src/rw + library/cpp/string_utils/secret_string + library/cpp/tvmauth/src/protos + library/cpp/tvmauth/src/rw ) SRCS( - deprecated/service_context.cpp - deprecated/user_context.cpp + deprecated/service_context.cpp + deprecated/user_context.cpp src/parser.cpp src/service_impl.cpp - src/service_ticket.cpp + src/service_ticket.cpp src/status.cpp - src/unittest.cpp + src/unittest.cpp src/user_impl.cpp - src/user_ticket.cpp + src/user_ticket.cpp src/utils.cpp src/version.cpp - utils.cpp + utils.cpp +) + +GENERATE_ENUM_SERIALIZATION(checked_user_ticket.h) +GENERATE_ENUM_SERIALIZATION(ticket_status.h) + +RESOURCE( + src/version /builtin/version ) -GENERATE_ENUM_SERIALIZATION(checked_user_ticket.h) -GENERATE_ENUM_SERIALIZATION(ticket_status.h) - -RESOURCE( - src/version /builtin/version -) - END() - -RECURSE( + +RECURSE( client - src/rw - src/ut - test_all -) + src/rw + src/ut + test_all +) diff --git a/library/cpp/unicode/normalization/custom_encoder.h b/library/cpp/unicode/normalization/custom_encoder.h index 5bd6c0d302..ef4d5b7f65 100644 --- a/library/cpp/unicode/normalization/custom_encoder.h +++ b/library/cpp/unicode/normalization/custom_encoder.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/charset/codepage.h> +#include <library/cpp/charset/codepage.h> struct TCustomEncoder: public Encoder { void Create(const CodePage* target, bool extended = false); diff --git a/library/cpp/unicode/normalization/generated/composition.cpp b/library/cpp/unicode/normalization/generated/composition.cpp index 8e31838961..7cc4dc7b75 100644 --- a/library/cpp/unicode/normalization/generated/composition.cpp +++ b/library/cpp/unicode/normalization/generated/composition.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/unicode/normalization/normalization.h> +#include <library/cpp/unicode/normalization/normalization.h> const NUnicode::NPrivate::TComposition::TRawData NUnicode::NPrivate::TComposition::RawData[] = { { 0x41, 0x300, 0xC0 }, diff --git a/library/cpp/unicode/normalization/generated/decomposition.cpp b/library/cpp/unicode/normalization/generated/decomposition.cpp index 0ee604a19c..9ac6a5f92a 100644 --- a/library/cpp/unicode/normalization/generated/decomposition.cpp +++ b/library/cpp/unicode/normalization/generated/decomposition.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/unicode/normalization/decomposition_table.h> +#include <library/cpp/unicode/normalization/decomposition_table.h> namespace { namespace NCannonDecompositionTableGenerated { using TV = const NUnicode::NPrivate::TDecompositionTable::TStored; diff --git a/library/cpp/unicode/normalization/ut/normalization_ut.cpp b/library/cpp/unicode/normalization/ut/normalization_ut.cpp index c922c1b302..54d4940a26 100644 --- a/library/cpp/unicode/normalization/ut/normalization_ut.cpp +++ b/library/cpp/unicode/normalization/ut/normalization_ut.cpp @@ -2,7 +2,7 @@ #include <util/charset/wide.h> -#include <library/cpp/unicode/normalization/normalization.h> +#include <library/cpp/unicode/normalization/normalization.h> Y_UNIT_TEST_SUITE(TUnicodeNormalizationTest) { template <NUnicode::ENormalization NormType> diff --git a/library/cpp/unicode/normalization/ut/ya.make b/library/cpp/unicode/normalization/ut/ya.make index 57ac24a472..a74372d9e1 100644 --- a/library/cpp/unicode/normalization/ut/ya.make +++ b/library/cpp/unicode/normalization/ut/ya.make @@ -3,7 +3,7 @@ UNITTEST() OWNER(mvel) PEERDIR( - library/cpp/unicode/normalization + library/cpp/unicode/normalization ) SRCS( diff --git a/library/cpp/unicode/normalization/ya.make b/library/cpp/unicode/normalization/ya.make index 0b0fb5f9ac..95bc93f297 100644 --- a/library/cpp/unicode/normalization/ya.make +++ b/library/cpp/unicode/normalization/ya.make @@ -16,7 +16,7 @@ IF(NOT CATBOOST_OPENSOURCE) custom_encoder.cpp ) PEERDIR( - library/cpp/charset + library/cpp/charset ) GENERATE_ENUM_SERIALIZATION(normalization.h) ENDIF() diff --git a/library/cpp/unicode/punycode/ut/ya.make b/library/cpp/unicode/punycode/ut/ya.make index ca8b0a97e8..74272102a8 100644 --- a/library/cpp/unicode/punycode/ut/ya.make +++ b/library/cpp/unicode/punycode/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/unicode/punycode) +UNITTEST_FOR(library/cpp/unicode/punycode) OWNER( g:base diff --git a/library/cpp/unicode/ya.make b/library/cpp/unicode/ya.make index 894187924e..4fcd9caacc 100644 --- a/library/cpp/unicode/ya.make +++ b/library/cpp/unicode/ya.make @@ -1,14 +1,14 @@ RECURSE( - folding - folding/ut - normalization - normalization/ut - punycode - punycode/ut + folding + folding/ut + normalization + normalization/ut + punycode + punycode/ut set set/ut - utf8_char - utf8_char/ut - utf8_iter - utf8_iter/ut + utf8_char + utf8_char/ut + utf8_iter + utf8_iter/ut ) diff --git a/library/cpp/uri/assign.cpp b/library/cpp/uri/assign.cpp index f9cb87b5dc..ae9125c727 100644 --- a/library/cpp/uri/assign.cpp +++ b/library/cpp/uri/assign.cpp @@ -3,7 +3,7 @@ #include <contrib/libs/libidn/idna.h> -#include <library/cpp/charset/recyr.hh> +#include <library/cpp/charset/recyr.hh> #include <util/charset/wide.h> #include <util/memory/tempbuf.h> #include <util/string/cast.h> diff --git a/library/cpp/uri/encodefsm.rl6 b/library/cpp/uri/encodefsm.rl6 index 3a5d90a98d..6a323aa85a 100644 --- a/library/cpp/uri/encodefsm.rl6 +++ b/library/cpp/uri/encodefsm.rl6 @@ -1,4 +1,4 @@ -#include <library/cpp/uri/encode.h> +#include <library/cpp/uri/encode.h> #ifdef __clang__ #pragma clang diagnostic ignored "-Wunused-variable" diff --git a/library/cpp/uri/parse.h b/library/cpp/uri/parse.h index 065f2265ef..ca2358e572 100644 --- a/library/cpp/uri/parse.h +++ b/library/cpp/uri/parse.h @@ -6,7 +6,7 @@ #include "common.h" -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> #include <util/generic/strbuf.h> #include <util/stream/output.h> #include <util/string/cast.h> diff --git a/library/cpp/uri/parsefsm.rl6 b/library/cpp/uri/parsefsm.rl6 index 51c5bb6237..7097723650 100644 --- a/library/cpp/uri/parsefsm.rl6 +++ b/library/cpp/uri/parsefsm.rl6 @@ -1,4 +1,4 @@ -#include <library/cpp/uri/parse.h> +#include <library/cpp/uri/parse.h> #ifdef __clang__ #pragma clang diagnostic ignored "-Wunused-variable" diff --git a/library/cpp/uri/uri-ru_ut.cpp b/library/cpp/uri/uri-ru_ut.cpp index 945dd005a5..ec35a164d2 100644 --- a/library/cpp/uri/uri-ru_ut.cpp +++ b/library/cpp/uri/uri-ru_ut.cpp @@ -1,6 +1,6 @@ #include "uri_ut.h" -#include <library/cpp/charset/recyr.hh> -#include <library/cpp/html/entity/htmlentity.h> +#include <library/cpp/charset/recyr.hh> +#include <library/cpp/html/entity/htmlentity.h> #include <util/system/maxlen.h> namespace NUri { diff --git a/library/cpp/uri/uri.h b/library/cpp/uri/uri.h index 1171aa80a5..3b6c19fe4a 100644 --- a/library/cpp/uri/uri.h +++ b/library/cpp/uri/uri.h @@ -3,7 +3,7 @@ #include "common.h" #include "encode.h" -#include <library/cpp/charset/doccodes.h> +#include <library/cpp/charset/doccodes.h> #include <util/generic/buffer.h> #include <util/generic/ptr.h> #include <util/generic/singleton.h> diff --git a/library/cpp/uri/uri_ut.cpp b/library/cpp/uri/uri_ut.cpp index 531968a9b3..2ebd83fc93 100644 --- a/library/cpp/uri/uri_ut.cpp +++ b/library/cpp/uri/uri_ut.cpp @@ -1,7 +1,7 @@ #include "uri_ut.h" #include "other.h" #include "qargs.h" -#include <library/cpp/html/entity/htmlentity.h> +#include <library/cpp/html/entity/htmlentity.h> #include <util/system/maxlen.h> diff --git a/library/cpp/uri/ut/ya.make b/library/cpp/uri/ut/ya.make index 37df1e97a1..b2b2c1291a 100644 --- a/library/cpp/uri/ut/ya.make +++ b/library/cpp/uri/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/uri) +UNITTEST_FOR(library/cpp/uri) OWNER(leo) @@ -7,7 +7,7 @@ NO_OPTIMIZE() NO_WSHADOW() PEERDIR( - library/cpp/html/entity + library/cpp/html/entity ) SRCS( diff --git a/library/cpp/uri/ya.make b/library/cpp/uri/ya.make index 06a6423b4b..8fc808a6af 100644 --- a/library/cpp/uri/ya.make +++ b/library/cpp/uri/ya.make @@ -21,7 +21,7 @@ SRCS( PEERDIR( contrib/libs/libidn - library/cpp/charset + library/cpp/charset ) END() diff --git a/library/cpp/xml/document/README b/library/cpp/xml/document/README index a3651354c1..b2649523d8 100644 --- a/library/cpp/xml/document/README +++ b/library/cpp/xml/document/README @@ -2,7 +2,7 @@ A wrapper around the DOM interface of libxml2. The standard way to use it is as follows: - #include <library/cpp/xml/document/xml-document.h> + #include <library/cpp/xml/document/xml-document.h> ... // open a document diff --git a/library/cpp/xml/document/libxml-guards.h b/library/cpp/xml/document/libxml-guards.h index 9fcfd69ad0..4188cecff1 100644 --- a/library/cpp/xml/document/libxml-guards.h +++ b/library/cpp/xml/document/libxml-guards.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/xml/init/ptr.h> +#include <library/cpp/xml/init/ptr.h> #include <util/generic/ptr.h> #include <libxml/xmlstring.h> #include <libxml/tree.h> diff --git a/library/cpp/xml/document/ut/ya.make b/library/cpp/xml/document/ut/ya.make index 20fb884d16..e955448c66 100644 --- a/library/cpp/xml/document/ut/ya.make +++ b/library/cpp/xml/document/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/xml/document) +UNITTEST_FOR(library/cpp/xml/document) OWNER(finder) diff --git a/library/cpp/xml/document/xml-document.cpp b/library/cpp/xml/document/xml-document.cpp index 527386f12b..18a554d732 100644 --- a/library/cpp/xml/document/xml-document.cpp +++ b/library/cpp/xml/document/xml-document.cpp @@ -3,7 +3,7 @@ #include <libxml/xinclude.h> #include <libxml/xpathInternals.h> -#include <library/cpp/xml/init/init.h> +#include <library/cpp/xml/init/init.h> #include <util/generic/yexception.h> #include <util/folder/dirut.h> diff --git a/library/cpp/xml/document/ya.make b/library/cpp/xml/document/ya.make index 4de943a4d2..86bbd639cf 100644 --- a/library/cpp/xml/document/ya.make +++ b/library/cpp/xml/document/ya.make @@ -9,7 +9,7 @@ SRCS( ) PEERDIR( - library/cpp/xml/init + library/cpp/xml/init contrib/libs/libxml library/cpp/string_utils/ztstrbuf ) diff --git a/library/cpp/xml/init/init.cpp b/library/cpp/xml/init/init.cpp index 7d28fb579c..aa96c2dd31 100644 --- a/library/cpp/xml/init/init.cpp +++ b/library/cpp/xml/init/init.cpp @@ -5,7 +5,7 @@ #include <libxml/parserInternals.h> #include <libxml/tree.h> -#include <library/cpp/charset/recyr.hh> +#include <library/cpp/charset/recyr.hh> #include <util/generic/singleton.h> namespace { diff --git a/library/cpp/xml/init/ptr.h b/library/cpp/xml/init/ptr.h index 59eb1057f7..7387c7cc40 100644 --- a/library/cpp/xml/init/ptr.h +++ b/library/cpp/xml/init/ptr.h @@ -61,8 +61,8 @@ namespace NXml { DEF_PTR(xmlNode, xmlFreeNode); DEF_PTR(xmlParserCtxt, xmlFreeParserCtxt); DEF_PTR(xmlParserInputBuffer, xmlFreeParserInputBuffer); - DEF_PTR(xmlDtd, xmlFreeDtd); - DEF_PTR(xmlValidCtxt, xmlFreeValidCtxt); + DEF_PTR(xmlDtd, xmlFreeDtd); + DEF_PTR(xmlValidCtxt, xmlFreeValidCtxt); #undef DEF_HOLDER #undef DEF_PTR diff --git a/library/cpp/xml/init/ya.make b/library/cpp/xml/init/ya.make index 5e9a974d6d..5f3883c2c9 100644 --- a/library/cpp/xml/init/ya.make +++ b/library/cpp/xml/init/ya.make @@ -4,7 +4,7 @@ OWNER(pg) PEERDIR( contrib/libs/libxml - library/cpp/charset + library/cpp/charset ) SRCS( diff --git a/library/cpp/ya.make b/library/cpp/ya.make index 1cba71c7ea..8c1193b007 100644 --- a/library/cpp/ya.make +++ b/library/cpp/ya.make @@ -1,450 +1,450 @@ OWNER(g:cpp-contrib) RECURSE( - accurate_accumulate - accurate_accumulate/benchmark - accurate_accumulate/benchmark/metrics + accurate_accumulate + accurate_accumulate/benchmark + accurate_accumulate/benchmark/metrics actors actors/ut - aio - any - any/ut - archive/ut - auth_client_parser - barcode - barcode/ut - binsaver + aio + any + any/ut + archive/ut + auth_client_parser + barcode + barcode/ut + binsaver binsaver/ut - binsaver/ut_util - bit_io - bit_io/ut - blackbox2 - blob_cache - blob_cache/ut - blockcodecs - blockcodecs/fuzz - bloom_filter - bloom_filter/benchmark - bloom_filter/ut - bucket_quoter - build_info + binsaver/ut_util + bit_io + bit_io/ut + blackbox2 + blob_cache + blob_cache/ut + blockcodecs + blockcodecs/fuzz + bloom_filter + bloom_filter/benchmark + bloom_filter/ut + bucket_quoter + build_info cache case_insensitive_string cgiparam cgiparam/fuzz cgiparam/ut - charset - charset/ut + charset + charset/ut chromium_trace clang_tidy - clickhouse - clustered_hnsw - clustered_hnsw/ut - codecs + clickhouse + clustered_hnsw + clustered_hnsw/ut + codecs codecs/float_huffman_bench - codecs/greedy_dict/ut - codecs/static/tools - codecs/static/tools/tests - codecs/static/ut - codecs/ut - colorizer - colorizer/ut - compproto - compproto/ut - comptable - comptable/usage - comptable/ut - compute_graph - compute_rt_graph - compute_rt_graph/ut - config - config/extra - config/ut + codecs/greedy_dict/ut + codecs/static/tools + codecs/static/tools/tests + codecs/static/ut + codecs/ut + colorizer + colorizer/ut + compproto + compproto/ut + comptable + comptable/usage + comptable/ut + compute_graph + compute_rt_graph + compute_rt_graph/ut + config + config/extra + config/ut consistent_hash_ring consistent_hash_ring/ut consistent_hashing consistent_hashing/ut containers - coroutine - cppparser - cpuid_check - cpuload - dbg_output - dbg_output/ut - deprecated + coroutine + cppparser + cpuid_check + cpuload + dbg_output + dbg_output/ut + deprecated diff diff/ut - digest - disjoint_sets - disjoint_sets/ut - dns - dns/ut - dolbilo - dolbilo/ut - domtree - domtree/tool + digest + disjoint_sets + disjoint_sets/ut + dns + dns/ut + dolbilo + dolbilo/ut + domtree + domtree/tool dot_product dot_product/bench dot_product/ut dwarf_backtrace dwarf_backtrace/registry - edit_distance - edit_distance/ut - enumbitset - enumbitset/ut + edit_distance + edit_distance/ut + enumbitset + enumbitset/ut erasure erasure/benchmark erasure/ut - eventlog - eventlog/dumper - eventlog/dumper/ut - eventlog/rt - eventlog/rt/tool - eventlog/test - eventlog/ut - eventlog/yt - exception_counter - execprofile - execprofile/autostart - expression - expression/ut - ext - ext/ut - fast_exp - fast_exp/benchmark - fast_exp/ut - fast_log - fieldcalc - fieldcalc/ut - file_checker - file_checker/test - file_checker/test/tests - file_checker/ut + eventlog + eventlog/dumper + eventlog/dumper/ut + eventlog/rt + eventlog/rt/tool + eventlog/test + eventlog/ut + eventlog/yt + exception_counter + execprofile + execprofile/autostart + expression + expression/ut + ext + ext/ut + fast_exp + fast_exp/benchmark + fast_exp/ut + fast_log + fieldcalc + fieldcalc/ut + file_checker + file_checker/test + file_checker/test/tests + file_checker/ut flatbuffers64_introspection flatbuffers64_introspection/example float16 float16/ut - framing - framing/ut - fuid - fuid/ut - function_tracer + framing + framing/ut + fuid + fuid/ut + function_tracer geo - geobase - geobase/ut + geobase + geobase/ut geohash geohash/tile geohash/tile/ut geohash/ut geolocation - geotarget + geotarget getopt getopt/last_getopt_demo getopt/small getopt/ut getoptpb - gettimeofday - gradient_optimize - gradient_optimize/ut - graph - grid_creator - grid_creator/fuzz - grid_creator/ut - grpc - histogram - hnsw + gettimeofday + gradient_optimize + gradient_optimize/ut + graph + grid_creator + grid_creator/fuzz + grid_creator/ut + grpc + histogram + hnsw html - html/dehtml/ut - http - hyperloglog - hyperloglog/ut - inf_buffer - infected_masks - infected_masks/tools - infected_masks/ut - int128 - int128/ut + html/dehtml/ut + http + hyperloglog + hyperloglog/ut + inf_buffer + infected_masks + infected_masks/tools + infected_masks/ut + int128 + int128/ut introspection - ipmath + ipmath ipreg ipreg/ut - ipv6_address - ipv6_address/ut - iterator - json + ipv6_address + ipv6_address/ut + iterator + json json/fast_sax - json/flex_buffers - json/flex_buffers/ut - json/fuzzy_test - json/ut - json/writer/ut - json/yson - json/yson/ut - kmeans_hnsw - kmeans_hnsw/ut - knn_index - knn_index/bench - knn_index/ut - l1_distance - l1_distance/bench - l1_distance/ut - l2_distance - l2_distance/bench - l2_distance/ut - langmask - langmask/proto - langmask/serialization - langmask/ut + json/flex_buffers + json/flex_buffers/ut + json/fuzzy_test + json/ut + json/writer/ut + json/yson + json/yson/ut + kmeans_hnsw + kmeans_hnsw/ut + knn_index + knn_index/bench + knn_index/ut + l1_distance + l1_distance/bench + l1_distance/ut + l2_distance + l2_distance/bench + l2_distance/ut + langmask + langmask/proto + langmask/serialization + langmask/ut langs langs/ut - lcookie - lcookie/ut - lcs - lcs/ut - lfalloc - lfalloc/dbg - lfalloc/dbg_info - lfalloc/yt + lcookie + lcookie/ut + lcs + lcs/ut + lfalloc + lfalloc/dbg + lfalloc/dbg_info + lfalloc/yt libgit2_wrapper - linear_regression - linear_regression/benchmark - linear_regression/ut - logger - logger/global - logger/global/ut - logger/ut - lua - lua/check - lua/check/ut - lua/sandbox/ut - lua/ut - lwtrace - lwtrace/example1 - lwtrace/example2 - lwtrace/example3 - lwtrace/example4 - lwtrace/example5 - lwtrace/tests - lwtrace/ut - malloc - map_text_file - map_text_file/ut - matrix - matrix/test - md5_checker - md5_checker/ut - mediator - mediator/ut - messagebus/all - messagebus/test - microbdb - microbdb/ut - mime - minhash - minhash/tools - minhash/ut + linear_regression + linear_regression/benchmark + linear_regression/ut + logger + logger/global + logger/global/ut + logger/ut + lua + lua/check + lua/check/ut + lua/sandbox/ut + lua/ut + lwtrace + lwtrace/example1 + lwtrace/example2 + lwtrace/example3 + lwtrace/example4 + lwtrace/example5 + lwtrace/tests + lwtrace/ut + malloc + map_text_file + map_text_file/ut + matrix + matrix/test + md5_checker + md5_checker/ut + mediator + mediator/ut + messagebus/all + messagebus/test + microbdb + microbdb/ut + mime + minhash + minhash/tools + minhash/ut mongo monlib - msgpack - msgpack2json - msgpack2json/ut - neh - neh/asio/ut - neh/ut - netliba - nirvana - nth_elements - nth_elements/fuzz - nth_elements/ut - numerator - numerator/blob - oauth - object_factory - object_factory/ut - offroad + msgpack + msgpack2json + msgpack2json/ut + neh + neh/asio/ut + neh/ut + netliba + nirvana + nth_elements + nth_elements/fuzz + nth_elements/ut + numerator + numerator/blob + oauth + object_factory + object_factory/ut + offroad on_disk - online_hnsw - online_hnsw/ut - openssl - os_family - os_family/protos - os_family/ut - packedtypes/ut - packers - packers/ut - par - perceptron + online_hnsw + online_hnsw/ut + openssl + os_family + os_family/protos + os_family/ut + packedtypes/ut + packers + packers/ut + par + perceptron pop_count pop_count/benchmark pop_count/ut presort presort/ut - prob_counter - prob_counter/ut - progress_bar - proto_config - proto_config/codegen - proto_config/exec_test - proto_config/exec_test/tool - proto_config/exec_test/tool_resource - proto_config/plugin - proto_config/protos - proto_config/ut + prob_counter + prob_counter/ut + progress_bar + proto_config + proto_config/codegen + proto_config/exec_test + proto_config/exec_test/tool + proto_config/exec_test/tool_resource + proto_config/plugin + proto_config/protos + proto_config/ut protobuf - pybind - pybind/example - pybind/example/dynamic - pybind/example/static - pybind/example/ut - query_marker - randomforest - regex - region - region/ut - resource - resource/ut - retry - retry/protos - retry/ut - reverse_geocoder - robots_txt - robots_txt/ut - safe_stats - safe_stats/ut - sampling - sampling/benchmark - sampling/benchmark/metrics - sampling/bin - sampling/ut - scheme - scheme/tests - scheme/ut_utils - scores - scores/ut + pybind + pybind/example + pybind/example/dynamic + pybind/example/static + pybind/example/ut + query_marker + randomforest + regex + region + region/ut + resource + resource/ut + retry + retry/protos + retry/ut + reverse_geocoder + robots_txt + robots_txt/ut + safe_stats + safe_stats/ut + sampling + sampling/benchmark + sampling/benchmark/metrics + sampling/bin + sampling/ut + scheme + scheme/tests + scheme/ut_utils + scores + scores/ut select_in_word select_in_word/bench select_in_word/ut - semver - semver/ut - shingles - shingles/ut - sighandler - simhash - simhash/ut + semver + semver/ut + shingles + shingles/ut + sighandler + simhash + simhash/ut skiff - sliding_window - sliding_window/ut - solve_ambig - solve_ambig/ut - sorter - sorter/ut + sliding_window + sliding_window/ut + solve_ambig + solve_ambig/ut + sorter + sorter/ut sqlite3 sqlite3/ut sse - ssh + ssh ssh/ut - ssh_sign - ssh_sign/ut - stat-handle - stat-handle/ut - statistics - statistics/ut - stopwords - stopwords/ut - streams - string_utils - succinct_arrays - succinct_arrays/ut - svnversion + ssh_sign + ssh_sign/ut + stat-handle + stat-handle/ut + statistics + statistics/ut + stopwords + stopwords/ut + streams + string_utils + succinct_arrays + succinct_arrays/ut + svnversion telfinder telfinder/ut terminate_handler terminate_handler/sample - testing - text_processing + testing + text_processing threading - timezone_conversion - timezone_conversion/ut - tld - tld/ut - token + timezone_conversion + timezone_conversion/ut + tld + tld/ut + token token/lite - token/serialization - token/serialization/ut - token/ut + token/serialization + token/serialization/ut + token/ut tokenclassifiers tokenizer tokenizer/ut - trace_usage - trace_usage/benchmark - trace_usage/ut - tvmauth - tvmknife + trace_usage + trace_usage/benchmark + trace_usage/ut + tvmauth + tvmknife type_info type_info/bench ucompress - udp - uilangdetect - uilangdetect/ut + udp + uilangdetect + uilangdetect/ut unicode - unistat - unistat/ut - uri - user_agent - vec4 - vec4/ut - vl_feat + unistat + unistat/ut + uri + user_agent + vec4 + vec4/ut + vl_feat vowpalwabbit vowpalwabbit/tools vowpalwabbit/ut - watchdog + watchdog watchdog/timeout/ut - wordlistreader - xml - xmlrpc - xsltransform - xsltransform/ut + wordlistreader + xml + xmlrpc + xsltransform + xsltransform/ut yaml - yappy - yconf - yconf/patcher - yconf/patcher/ut - yconf/ut + yappy + yconf + yconf/patcher + yconf/patcher/ut + yconf/ut yson yson/json yson/node yson/node/pybind - yson_pull - yson_pull/ut + yson_pull + yson_pull/ut yt zipatch ) - -IF (OS_LINUX) - RECURSE( - balloc/test - balloc/aba_agri_test - balloc_market/test - balloc_market/aba_agri_test + +IF (OS_LINUX) + RECURSE( + balloc/test + balloc/aba_agri_test + balloc_market/test + balloc_market/aba_agri_test ytalloc rseq - ) -ENDIF() - -IF (OS_WINDOWS) - RECURSE( - winservice - ) -ELSE() - RECURSE( + ) +ENDIF() + +IF (OS_WINDOWS) + RECURSE( + winservice + ) +ELSE() + RECURSE( fuse sse/ut - tf + tf xdelta3 - zookeeper - ) -ENDIF() - -IF (HAVE_CUDA) - RECURSE(cuda) -ENDIF() + zookeeper + ) +ENDIF() + +IF (HAVE_CUDA) + RECURSE(cuda) +ENDIF() diff --git a/library/cpp/yaml/ya.make b/library/cpp/yaml/ya.make index 1c7d14f25d..e9689fe65b 100644 --- a/library/cpp/yaml/ya.make +++ b/library/cpp/yaml/ya.make @@ -1,4 +1,4 @@ RECURSE( as - scheme + scheme ) diff --git a/library/cpp/yson/json/json_writer.cpp b/library/cpp/yson/json/json_writer.cpp index 0b7aa4b57d..87481256ec 100644 --- a/library/cpp/yson/json/json_writer.cpp +++ b/library/cpp/yson/json/json_writer.cpp @@ -1,6 +1,6 @@ #include "json_writer.h" -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_writer.h> namespace NYT { //////////////////////////////////////////////////////////////////////////////// diff --git a/library/cpp/yson/json/json_writer.h b/library/cpp/yson/json/json_writer.h index 3abfa00a01..d84ac0de53 100644 --- a/library/cpp/yson/json/json_writer.h +++ b/library/cpp/yson/json/json_writer.h @@ -3,7 +3,7 @@ #include <library/cpp/yson/public.h> #include <library/cpp/yson/consumer.h> -#include <library/cpp/json/json_writer.h> +#include <library/cpp/json/json_writer.h> #include <util/generic/vector.h> diff --git a/library/cpp/yson/json/yson2json_adapter.h b/library/cpp/yson/json/yson2json_adapter.h index 8d23ba8e2e..da1bf5ba70 100644 --- a/library/cpp/yson/json/yson2json_adapter.h +++ b/library/cpp/yson/json/yson2json_adapter.h @@ -2,7 +2,7 @@ #include <library/cpp/yson/consumer.h> -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <util/generic/stack.h> diff --git a/library/cpp/yson/node/node_builder.h b/library/cpp/yson/node/node_builder.h index 5d0b2c07e4..69800016e0 100644 --- a/library/cpp/yson/node/node_builder.h +++ b/library/cpp/yson/node/node_builder.h @@ -2,7 +2,7 @@ #include "node.h" -#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_reader.h> #include <library/cpp/yson/consumer.h> diff --git a/library/cpp/yson/node/node_io.cpp b/library/cpp/yson/node/node_io.cpp index c0993d4e64..294a7f7217 100644 --- a/library/cpp/yson/node/node_io.cpp +++ b/library/cpp/yson/node/node_io.cpp @@ -8,8 +8,8 @@ #include <library/cpp/yson/writer.h> #include <library/cpp/yson/json/yson2json_adapter.h> -#include <library/cpp/json/json_reader.h> -#include <library/cpp/json/json_value.h> +#include <library/cpp/json/json_reader.h> +#include <library/cpp/json/json_value.h> #include <util/stream/input.h> #include <util/stream/output.h> diff --git a/library/cpp/yson/node/pybind/node.cpp b/library/cpp/yson/node/pybind/node.cpp index bd2e98379f..79beba3647 100644 --- a/library/cpp/yson/node/pybind/node.cpp +++ b/library/cpp/yson/node/pybind/node.cpp @@ -2,7 +2,7 @@ #include <library/cpp/yson/node/node.h> -#include <library/cpp/pybind/cast.h> +#include <library/cpp/pybind/cast.h> #include <Python.h> diff --git a/library/cpp/yson/node/pybind/ya.make b/library/cpp/yson/node/pybind/ya.make index 67275fc1c8..97b7583e96 100644 --- a/library/cpp/yson/node/pybind/ya.make +++ b/library/cpp/yson/node/pybind/ya.make @@ -6,7 +6,7 @@ OWNER( ) PEERDIR( - library/cpp/pybind + library/cpp/pybind library/cpp/yson/node ) SRCS( diff --git a/library/cpp/yson_pull/consumer.cpp b/library/cpp/yson_pull/consumer.cpp index cc9c043e3d..c238e0a6fb 100644 --- a/library/cpp/yson_pull/consumer.cpp +++ b/library/cpp/yson_pull/consumer.cpp @@ -1,6 +1,6 @@ #include "consumer.h" -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> using namespace NYsonPull; diff --git a/library/cpp/yson_pull/detail/byte_reader.h b/library/cpp/yson_pull/detail/byte_reader.h index 5d421d964c..7cea50d323 100644 --- a/library/cpp/yson_pull/detail/byte_reader.h +++ b/library/cpp/yson_pull/detail/byte_reader.h @@ -4,7 +4,7 @@ #include "fail.h" #include "stream_counter.h" -#include <library/cpp/yson_pull/input.h> +#include <library/cpp/yson_pull/input.h> namespace NYsonPull { namespace NDetail { diff --git a/library/cpp/yson_pull/detail/byte_writer.h b/library/cpp/yson_pull/detail/byte_writer.h index d76c865658..dc1d4b4b96 100644 --- a/library/cpp/yson_pull/detail/byte_writer.h +++ b/library/cpp/yson_pull/detail/byte_writer.h @@ -2,7 +2,7 @@ #include "macros.h" -#include <library/cpp/yson_pull/output.h> +#include <library/cpp/yson_pull/output.h> #include <util/system/types.h> diff --git a/library/cpp/yson_pull/detail/fail.h b/library/cpp/yson_pull/detail/fail.h index 1d69b2d131..6937612d0b 100644 --- a/library/cpp/yson_pull/detail/fail.h +++ b/library/cpp/yson_pull/detail/fail.h @@ -3,8 +3,8 @@ #include "format_string.h" #include "macros.h" -#include <library/cpp/yson_pull/exceptions.h> -#include <library/cpp/yson_pull/position_info.h> +#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/position_info.h> namespace NYsonPull { namespace NDetail { diff --git a/library/cpp/yson_pull/detail/input/buffered.h b/library/cpp/yson_pull/detail/input/buffered.h index bbf1684b04..9b1482577f 100644 --- a/library/cpp/yson_pull/detail/input/buffered.h +++ b/library/cpp/yson_pull/detail/input/buffered.h @@ -1,9 +1,9 @@ #pragma once -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/exceptions.h> -#include <library/cpp/yson_pull/input.h> +#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/input.h> #include <cstdio> #include <memory> diff --git a/library/cpp/yson_pull/detail/input/stdio_file.h b/library/cpp/yson_pull/detail/input/stdio_file.h index 5c5941503b..c412b7e59b 100644 --- a/library/cpp/yson_pull/detail/input/stdio_file.h +++ b/library/cpp/yson_pull/detail/input/stdio_file.h @@ -2,10 +2,10 @@ #include "buffered.h" -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/exceptions.h> -#include <library/cpp/yson_pull/input.h> +#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/input.h> #include <cstdio> #include <memory> diff --git a/library/cpp/yson_pull/detail/input/stream.h b/library/cpp/yson_pull/detail/input/stream.h index c9c96ed9bd..791cd5a3f5 100644 --- a/library/cpp/yson_pull/detail/input/stream.h +++ b/library/cpp/yson_pull/detail/input/stream.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/input.h> +#include <library/cpp/yson_pull/input.h> #include <util/stream/buffered.h> #include <util/stream/file.h> diff --git a/library/cpp/yson_pull/detail/output/buffered.h b/library/cpp/yson_pull/detail/output/buffered.h index 669eabba0d..475cf34785 100644 --- a/library/cpp/yson_pull/detail/output/buffered.h +++ b/library/cpp/yson_pull/detail/output/buffered.h @@ -1,8 +1,8 @@ #pragma once -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/output.h> +#include <library/cpp/yson_pull/output.h> #include <util/generic/strbuf.h> diff --git a/library/cpp/yson_pull/detail/output/stdio_file.h b/library/cpp/yson_pull/detail/output/stdio_file.h index 8f281447c1..03f2b40dc5 100644 --- a/library/cpp/yson_pull/detail/output/stdio_file.h +++ b/library/cpp/yson_pull/detail/output/stdio_file.h @@ -2,9 +2,9 @@ #include "buffered.h" -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/exceptions.h> #include <cstdio> diff --git a/library/cpp/yson_pull/detail/output/stream.h b/library/cpp/yson_pull/detail/output/stream.h index 2c4b6780ab..d4810f3353 100644 --- a/library/cpp/yson_pull/detail/output/stream.h +++ b/library/cpp/yson_pull/detail/output/stream.h @@ -2,8 +2,8 @@ #include "buffered.h" -#include <library/cpp/yson_pull/detail/macros.h> -#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/exceptions.h> #include <util/stream/output.h> #include <util/stream/file.h> diff --git a/library/cpp/yson_pull/detail/reader.h b/library/cpp/yson_pull/detail/reader.h index 625b524908..0e02396358 100644 --- a/library/cpp/yson_pull/detail/reader.h +++ b/library/cpp/yson_pull/detail/reader.h @@ -3,7 +3,7 @@ #include "lexer_base.h" #include "symbols.h" -#include <library/cpp/yson_pull/reader.h> +#include <library/cpp/yson_pull/reader.h> #include <util/generic/maybe.h> #include <util/generic/vector.h> diff --git a/library/cpp/yson_pull/detail/stream_counter.h b/library/cpp/yson_pull/detail/stream_counter.h index 0f72cda0a2..3b41b27eb6 100644 --- a/library/cpp/yson_pull/detail/stream_counter.h +++ b/library/cpp/yson_pull/detail/stream_counter.h @@ -1,6 +1,6 @@ #pragma once -#include <library/cpp/yson_pull/position_info.h> +#include <library/cpp/yson_pull/position_info.h> #include <cstddef> diff --git a/library/cpp/yson_pull/detail/writer.h b/library/cpp/yson_pull/detail/writer.h index 1e01e56870..b24b994292 100644 --- a/library/cpp/yson_pull/detail/writer.h +++ b/library/cpp/yson_pull/detail/writer.h @@ -7,11 +7,11 @@ #include "symbols.h" #include "varint.h" -#include <library/cpp/yson_pull/consumer.h> -#include <library/cpp/yson_pull/event.h> -#include <library/cpp/yson_pull/output.h> -#include <library/cpp/yson_pull/stream_type.h> -#include <library/cpp/yson_pull/writer.h> +#include <library/cpp/yson_pull/consumer.h> +#include <library/cpp/yson_pull/event.h> +#include <library/cpp/yson_pull/output.h> +#include <library/cpp/yson_pull/stream_type.h> +#include <library/cpp/yson_pull/writer.h> #include <util/generic/vector.h> #include <util/system/yassert.h> diff --git a/library/cpp/yson_pull/event.cpp b/library/cpp/yson_pull/event.cpp index b9e25553ec..b7ede494b6 100644 --- a/library/cpp/yson_pull/event.cpp +++ b/library/cpp/yson_pull/event.cpp @@ -1,6 +1,6 @@ #include "event.h" -#include <library/cpp/yson_pull/detail/cescape.h> +#include <library/cpp/yson_pull/detail/cescape.h> #include <util/stream/output.h> diff --git a/library/cpp/yson_pull/input.cpp b/library/cpp/yson_pull/input.cpp index 28df205174..1373c89868 100644 --- a/library/cpp/yson_pull/input.cpp +++ b/library/cpp/yson_pull/input.cpp @@ -1,7 +1,7 @@ #include "input.h" -#include <library/cpp/yson_pull/detail/input/stdio_file.h> -#include <library/cpp/yson_pull/detail/input/stream.h> +#include <library/cpp/yson_pull/detail/input/stdio_file.h> +#include <library/cpp/yson_pull/detail/input/stream.h> #include <util/generic/ptr.h> #include <util/stream/file.h> diff --git a/library/cpp/yson_pull/output.cpp b/library/cpp/yson_pull/output.cpp index fc5f09d411..27c9ef9e69 100644 --- a/library/cpp/yson_pull/output.cpp +++ b/library/cpp/yson_pull/output.cpp @@ -1,7 +1,7 @@ #include "output.h" -#include <library/cpp/yson_pull/detail/output/stdio_file.h> -#include <library/cpp/yson_pull/detail/output/stream.h> +#include <library/cpp/yson_pull/detail/output/stdio_file.h> +#include <library/cpp/yson_pull/detail/output/stream.h> #include <util/generic/ptr.h> #include <util/stream/file.h> diff --git a/library/cpp/yson_pull/reader.cpp b/library/cpp/yson_pull/reader.cpp index 9c732b8ea8..ea26852756 100644 --- a/library/cpp/yson_pull/reader.cpp +++ b/library/cpp/yson_pull/reader.cpp @@ -1,5 +1,5 @@ #include "reader.h" -#include <library/cpp/yson_pull/detail/reader.h> +#include <library/cpp/yson_pull/detail/reader.h> using namespace NYsonPull; diff --git a/library/cpp/yson_pull/scalar.cpp b/library/cpp/yson_pull/scalar.cpp index 201ba57bbe..4325542e7a 100644 --- a/library/cpp/yson_pull/scalar.cpp +++ b/library/cpp/yson_pull/scalar.cpp @@ -1,6 +1,6 @@ #include "scalar.h" -#include <library/cpp/yson_pull/detail/cescape.h> +#include <library/cpp/yson_pull/detail/cescape.h> #include <util/stream/output.h> diff --git a/library/cpp/yson_pull/ut/cescape_ut.cpp b/library/cpp/yson_pull/ut/cescape_ut.cpp index 8c533f04a6..6628ba1d15 100644 --- a/library/cpp/yson_pull/ut/cescape_ut.cpp +++ b/library/cpp/yson_pull/ut/cescape_ut.cpp @@ -1,4 +1,4 @@ -#include <library/cpp/yson_pull/detail/cescape.h> +#include <library/cpp/yson_pull/detail/cescape.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/yson_pull/ut/loop_ut.cpp b/library/cpp/yson_pull/ut/loop_ut.cpp index bbd4453b3b..8c7b11dd1c 100644 --- a/library/cpp/yson_pull/ut/loop_ut.cpp +++ b/library/cpp/yson_pull/ut/loop_ut.cpp @@ -1,7 +1,7 @@ -#include <library/cpp/yson_pull/input.h> -#include <library/cpp/yson_pull/output.h> -#include <library/cpp/yson_pull/reader.h> -#include <library/cpp/yson_pull/writer.h> +#include <library/cpp/yson_pull/input.h> +#include <library/cpp/yson_pull/output.h> +#include <library/cpp/yson_pull/reader.h> +#include <library/cpp/yson_pull/writer.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/yson_pull/ut/reader_ut.cpp b/library/cpp/yson_pull/ut/reader_ut.cpp index 089bfa01cc..1184265ddb 100644 --- a/library/cpp/yson_pull/ut/reader_ut.cpp +++ b/library/cpp/yson_pull/ut/reader_ut.cpp @@ -1,8 +1,8 @@ -#include <library/cpp/yson_pull/exceptions.h> -#include <library/cpp/yson_pull/range.h> -#include <library/cpp/yson_pull/reader.h> -#include <library/cpp/yson_pull/detail/cescape.h> -#include <library/cpp/yson_pull/detail/macros.h> +#include <library/cpp/yson_pull/exceptions.h> +#include <library/cpp/yson_pull/range.h> +#include <library/cpp/yson_pull/reader.h> +#include <library/cpp/yson_pull/detail/cescape.h> +#include <library/cpp/yson_pull/detail/macros.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/yson_pull/ut/writer_ut.cpp b/library/cpp/yson_pull/ut/writer_ut.cpp index f191b581fb..5c304bad0f 100644 --- a/library/cpp/yson_pull/ut/writer_ut.cpp +++ b/library/cpp/yson_pull/ut/writer_ut.cpp @@ -1,5 +1,5 @@ -#include <library/cpp/yson_pull/scalar.h> -#include <library/cpp/yson_pull/detail/writer.h> +#include <library/cpp/yson_pull/scalar.h> +#include <library/cpp/yson_pull/detail/writer.h> #include <library/cpp/testing/unittest/registar.h> diff --git a/library/cpp/yson_pull/ut/ya.make b/library/cpp/yson_pull/ut/ya.make index c2f7e11ea7..a269dfd2ad 100644 --- a/library/cpp/yson_pull/ut/ya.make +++ b/library/cpp/yson_pull/ut/ya.make @@ -1,4 +1,4 @@ -UNITTEST_FOR(library/cpp/yson_pull) +UNITTEST_FOR(library/cpp/yson_pull) OWNER(borman) diff --git a/library/cpp/yson_pull/writer.cpp b/library/cpp/yson_pull/writer.cpp index eb0edc18b3..1df92bf40f 100644 --- a/library/cpp/yson_pull/writer.cpp +++ b/library/cpp/yson_pull/writer.cpp @@ -1,5 +1,5 @@ #include "writer.h" -#include <library/cpp/yson_pull/detail/writer.h> +#include <library/cpp/yson_pull/detail/writer.h> using namespace NYsonPull; |