Malik Akbar Hashemi Rafsanjani | 4d7b5dd | 2025-02-26 13:14:30 -0800 | [diff] [blame] | 1 | #include "sessions.hpp" |
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | #include <gtest/gtest.h> |
| 6 | |
| 7 | namespace |
| 8 | { |
| 9 | TEST(AuthConfigMethods, FromJsonHappyPath) |
| 10 | { |
| 11 | persistent_data::AuthConfigMethods methods; |
| 12 | |
| 13 | nlohmann::json jsonValue = nlohmann::json::parse( |
| 14 | R"({"BasicAuth":true,"Cookie":true,"SessionToken":true,"TLS":true,"MTLSCommonNameParseMode":2,"TLSStrict":false,"XToken":true})"); |
| 15 | methods.fromJson(jsonValue); |
| 16 | |
| 17 | EXPECT_EQ(methods.basic, true); |
| 18 | EXPECT_EQ(methods.cookie, true); |
| 19 | EXPECT_EQ(methods.sessionToken, true); |
| 20 | EXPECT_EQ(methods.tls, true); |
| 21 | EXPECT_EQ(methods.tlsStrict, false); |
| 22 | EXPECT_EQ(methods.xtoken, true); |
| 23 | EXPECT_EQ(methods.mTLSCommonNameParsingMode, |
| 24 | static_cast<persistent_data::MTLSCommonNameParseMode>(2)); |
| 25 | } |
| 26 | |
| 27 | TEST(AuthConfigMethods, FromJsonMTLSCommonNameParseModeOutOfRange) |
| 28 | { |
| 29 | persistent_data::AuthConfigMethods methods; |
| 30 | persistent_data::MTLSCommonNameParseMode prevValue = |
| 31 | methods.mTLSCommonNameParsingMode; |
| 32 | |
| 33 | nlohmann::json jsonValue = nlohmann::json::parse( |
| 34 | R"({"BasicAuth":true,"Cookie":true,"SessionToken":true,"TLS":true,"MTLSCommonNameParseMode":4,"TLSStrict":false,"XToken":true})"); |
| 35 | methods.fromJson(jsonValue); |
| 36 | |
| 37 | EXPECT_EQ(methods.basic, true); |
| 38 | EXPECT_EQ(methods.cookie, true); |
| 39 | EXPECT_EQ(methods.sessionToken, true); |
| 40 | EXPECT_EQ(methods.tls, true); |
| 41 | EXPECT_EQ(methods.tlsStrict, false); |
| 42 | EXPECT_EQ(methods.xtoken, true); |
| 43 | EXPECT_EQ(methods.mTLSCommonNameParsingMode, prevValue); |
| 44 | } |
| 45 | } // namespace |