Marco Kawajiri | 0e373b5 | 2023-10-31 13:36:58 -0700 | [diff] [blame] | 1 | #include "http/mutual_tls_meta.hpp" |
| 2 | |
Ed Tanous | f0b59af | 2024-03-20 13:38:04 -0700 | [diff] [blame] | 3 | #include <optional> |
| 4 | #include <string> |
| 5 | #include <vector> |
| 6 | |
Ed Tanous | 478b7ad | 2024-07-15 19:11:54 -0700 | [diff] [blame] | 7 | #include <gtest/gtest.h> |
Marco Kawajiri | 0e373b5 | 2023-10-31 13:36:58 -0700 | [diff] [blame] | 8 | |
| 9 | namespace redfish |
| 10 | { |
| 11 | namespace |
| 12 | { |
| 13 | |
| 14 | TEST(MetaParseSslUser, userTest) |
| 15 | { |
| 16 | std::string sslUser = "user:kawajiri/hostname.facebook.com"; |
| 17 | EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri"); |
| 18 | } |
| 19 | |
| 20 | TEST(MetaParseSslUser, userNohostnameTest) |
| 21 | { |
| 22 | // hostname is optional |
| 23 | std::string sslUser = "user:kawajiri"; |
| 24 | EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri"); |
| 25 | } |
| 26 | |
| 27 | TEST(MetaParseSslUser, invalidUsers) |
| 28 | { |
| 29 | std::vector<std::string> invalidSslUsers = { |
| 30 | "", |
| 31 | ":", |
| 32 | ":/", |
| 33 | "ijslakd", |
| 34 | "user:", |
| 35 | "user:/", |
| 36 | "user:/hostname.facebook.com", |
| 37 | "user:/hostname.facebook.c om", |
| 38 | "user: space/hostname.facebook.com", |
| 39 | "svc:", |
| 40 | "svc:/", |
| 41 | "svc:/hostname.facebook.com", |
| 42 | "host:/", |
| 43 | "host:unexpected_user/", |
| 44 | }; |
| 45 | |
| 46 | for (const std::string& sslUser : invalidSslUsers) |
| 47 | { |
| 48 | EXPECT_EQ(mtlsMetaParseSslUser(sslUser), std::nullopt); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | } // namespace |
| 53 | } // namespace redfish |