aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/tvmauth/client/ut/utils_ut.cpp
blob: dbe1982d1ec934352ef51b249e6f31a932681e9d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#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));
    }
}