1 #include "sessions.hpp"
2
3 #include <nlohmann/json.hpp>
4
5 #include <gtest/gtest.h>
6
7 namespace
8 {
TEST(AuthConfigMethods,FromJsonHappyPath)9 TEST(AuthConfigMethods, FromJsonHappyPath)
10 {
11 persistent_data::AuthConfigMethods methods;
12 nlohmann::json::object_t jsonValue;
13 jsonValue["BasicAuth"] = true;
14 jsonValue["CookieAuth"] = true;
15 jsonValue["MTLSCommonNameParseMode"] = 2;
16 jsonValue["SessionToken"] = true;
17 jsonValue["TLS"] = true;
18 jsonValue["TLSStrict"] = false;
19 jsonValue["XToken"] = true;
20
21 methods.fromJson(jsonValue);
22
23 EXPECT_EQ(methods.basic, true);
24 EXPECT_EQ(methods.cookie, true);
25 EXPECT_EQ(methods.sessionToken, true);
26 EXPECT_EQ(methods.tls, true);
27 EXPECT_EQ(methods.tlsStrict, false);
28 EXPECT_EQ(methods.xtoken, true);
29 EXPECT_EQ(methods.mTLSCommonNameParsingMode,
30 static_cast<persistent_data::MTLSCommonNameParseMode>(2));
31 }
32
TEST(AuthConfigMethods,FromJsonMTLSCommonNameParseModeOutOfRange)33 TEST(AuthConfigMethods, FromJsonMTLSCommonNameParseModeOutOfRange)
34 {
35 persistent_data::AuthConfigMethods methods;
36 persistent_data::MTLSCommonNameParseMode prevValue =
37 methods.mTLSCommonNameParsingMode;
38 nlohmann::json::object_t jsonValue;
39 jsonValue["BasicAuth"] = true;
40 jsonValue["CookieAuth"] = true;
41 jsonValue["MTLSCommonNameParseMode"] = 4;
42 jsonValue["SessionToken"] = true;
43 jsonValue["TLS"] = true;
44 jsonValue["TLSStrict"] = false;
45 jsonValue["XToken"] = true;
46
47 methods.fromJson(jsonValue);
48
49 EXPECT_EQ(methods.basic, true);
50 EXPECT_EQ(methods.cookie, true);
51 EXPECT_EQ(methods.sessionToken, true);
52 EXPECT_EQ(methods.tls, true);
53 EXPECT_EQ(methods.tlsStrict, false);
54 EXPECT_EQ(methods.xtoken, true);
55 EXPECT_EQ(methods.mTLSCommonNameParsingMode, prevValue);
56 }
57 } // namespace
58