blob: 5f32cb54a125e012aaee6cb693d3c60a43e7cf4f [file] [log] [blame]
Marco Kawajiri0e373b52023-10-31 13:36:58 -07001#include "http/mutual_tls_meta.hpp"
2
3#include <gtest/gtest.h> // IWYU pragma: keep
4
5namespace redfish
6{
7namespace
8{
9
10TEST(MetaParseSslUser, userTest)
11{
12 std::string sslUser = "user:kawajiri/hostname.facebook.com";
13 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
14}
15
16TEST(MetaParseSslUser, userNohostnameTest)
17{
18 // hostname is optional
19 std::string sslUser = "user:kawajiri";
20 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
21}
22
23TEST(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