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