blob: 918a9c921ec418abeb7d82321b43e1a54ce71365 [file] [log] [blame]
Marco Kawajiri0e373b52023-10-31 13:36:58 -07001#include "http/mutual_tls_meta.hpp"
2
Ed Tanousf0b59af2024-03-20 13:38:04 -07003#include <optional>
4#include <string>
5#include <vector>
6
Ed Tanous478b7ad2024-07-15 19:11:54 -07007#include <gtest/gtest.h>
Marco Kawajiri0e373b52023-10-31 13:36:58 -07008
9namespace redfish
10{
11namespace
12{
13
14TEST(MetaParseSslUser, userTest)
15{
16 std::string sslUser = "user:kawajiri/hostname.facebook.com";
17 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
18}
19
20TEST(MetaParseSslUser, userNohostnameTest)
21{
22 // hostname is optional
23 std::string sslUser = "user:kawajiri";
24 EXPECT_EQ(mtlsMetaParseSslUser(sslUser), "kawajiri");
25}
26
27TEST(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