blob: 191a16af8617d4aaf2cbbf0d70ff112003635a54 [file] [log] [blame]
Ed Tanous04e438c2020-10-03 08:06:26 -07001#include "utility.hpp"
Jonathan Doman5beaf842020-08-14 11:23:33 -07002
3#include "gmock/gmock.h"
4
5TEST(Utility, Base64DecodeAuthString)
6{
7 std::string authString("dXNlcm40bWU6cGFzc3cwcmQ=");
8 std::string result;
9 EXPECT_TRUE(crow::utility::base64Decode(authString, result));
10 EXPECT_EQ(result, "usern4me:passw0rd");
11}
12
13TEST(Utility, Base64DecodeNonAscii)
14{
15 std::string junkString("\xff\xee\xdd\xcc\x01\x11\x22\x33");
16 std::string result;
17 EXPECT_FALSE(crow::utility::base64Decode(junkString, result));
18}
Adriana Kobylakd830ff52021-01-27 14:15:27 -060019
20TEST(Utility, Base64EncodeString)
21{
22 using namespace std::string_literals;
23 std::string encoded;
24
25 encoded = crow::utility::base64encode("");
26 EXPECT_EQ(encoded, "");
27
28 encoded = crow::utility::base64encode("f");
29 EXPECT_EQ(encoded, "Zg==");
30
31 encoded = crow::utility::base64encode("f0");
32 EXPECT_EQ(encoded, "ZjA=");
33
34 encoded = crow::utility::base64encode("f0\0"s);
35 EXPECT_EQ(encoded, "ZjAA");
36
37 encoded = crow::utility::base64encode("f0\0 "s);
38 EXPECT_EQ(encoded, "ZjAAIA==");
39
40 encoded = crow::utility::base64encode("f0\0 B"s);
41 EXPECT_EQ(encoded, "ZjAAIEI=");
42
43 encoded = crow::utility::base64encode("f0\0 Ba"s);
44 EXPECT_EQ(encoded, "ZjAAIEJh");
45
46 encoded = crow::utility::base64encode("f0\0 Bar"s);
47 EXPECT_EQ(encoded, "ZjAAIEJhcg==");
48}
49
50TEST(Utility, Base64EncodeDecodeString)
51{
52 using namespace std::string_literals;
53 std::string data("Data fr\0m 90 reading a \nFile"s);
54 std::string encoded = crow::utility::base64encode(data);
55 std::string decoded;
56 EXPECT_TRUE(crow::utility::base64Decode(encoded, decoded));
57 EXPECT_EQ(data, decoded);
58}