blob: 0f337125eedca8ebcfd313a25881845ae194ff02 [file] [log] [blame]
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -08001#include "sessions.hpp"
2
3#include <nlohmann/json.hpp>
4
5#include <gtest/gtest.h>
6
7namespace
8{
9TEST(AuthConfigMethods, FromJsonHappyPath)
10{
11 persistent_data::AuthConfigMethods methods;
Ed Tanous82b286f2025-05-06 13:29:48 -070012 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;
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -080020
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -080021 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
33TEST(AuthConfigMethods, FromJsonMTLSCommonNameParseModeOutOfRange)
34{
35 persistent_data::AuthConfigMethods methods;
36 persistent_data::MTLSCommonNameParseMode prevValue =
37 methods.mTLSCommonNameParsingMode;
Ed Tanous82b286f2025-05-06 13:29:48 -070038 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;
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -080046
Malik Akbar Hashemi Rafsanjani4d7b5dd2025-02-26 13:14:30 -080047 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