1 #include "http/mutual_tls_meta.hpp"
2
3 #include <optional>
4 #include <string>
5 #include <vector>
6
7 #include <gtest/gtest.h>
8
9 namespace redfish
10 {
11 namespace
12 {
13
TEST(MetaParseSslUser,userTest)14 TEST(MetaParseSslUser, userTest)
15 {
16 std::string sslUser = "user:kawajiri/hostname.facebook.com";
17 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
18 }
19
TEST(MetaParseSslUser,userNohostnameTest)20 TEST(MetaParseSslUser, userNohostnameTest)
21 {
22 // hostname is optional
23 std::string sslUser = "user:kawajiri";
24 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
25 }
26
TEST(MetaParseSslUser,invalidUsers)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
54