OmniSciDB  5ade3759e0
StringTransformTest.cpp File Reference
#include "../Shared/StringTransform.h"
#include "TestHelpers.h"
#include <gtest/gtest.h>
+ Include dependency graph for StringTransformTest.cpp:

Go to the source code of this file.

Functions

 TEST (StringTransform, CsvQuote)
 
 TEST (StringTransform, HideSensitiveDataFromQuery)
 
int main (int argc, char *argv[])
 

Function Documentation

◆ main()

int main ( int  argc,
char *  argv[] 
)

Definition at line 70 of file StringTransformTest.cpp.

References logger::ERROR, TestHelpers::init_logger_stderr_only(), and LOG.

70  {
72  ::testing::InitGoogleTest(&argc, argv);
73 
74  int err{0};
75  try {
76  err = RUN_ALL_TESTS();
77  } catch (const std::exception& e) {
78  LOG(ERROR) << e.what();
79  }
80  return err;
81 }
#define LOG(tag)
Definition: Logger.h:182
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194
+ Here is the call graph for this function:

◆ TEST() [1/2]

TEST ( StringTransform  ,
CsvQuote   
)

Definition at line 22 of file StringTransformTest.cpp.

22  {
23  std::vector<std::pair<std::string, std::string>> qa_pairs{
24  {"", "\"\""},
25  {"h", "\"h\""},
26  {"hi", "\"hi\""},
27  {"hi\\!", "\"hi\\!\""},
28  {"\"", "\"\"\"\""},
29  {"\"\"", "\"\"\"\"\"\""},
30  {"\"h\"", "\"\"\"h\"\"\""},
31  {"\"hi\"", "\"\"\"hi\"\"\""},
32  {"\"hi\\!\"", "\"\"\"hi\\!\"\"\""},
33  {"(5'11\")", "\"(5'11\"\")\""}};
34  for (auto& test : qa_pairs) {
35  std::ostringstream oss;
36  oss << std::quoted(test.first, '"', '"');
37  ASSERT_EQ(oss.str(), test.second);
38  }
39 }

◆ TEST() [2/2]

TEST ( StringTransform  ,
HideSensitiveDataFromQuery   
)

Definition at line 41 of file StringTransformTest.cpp.

References hide_sensitive_data_from_query().

41  {
42  std::vector<std::pair<std::string, std::string>> const tests{
43  {"COPY testtable FROM 's3://example/*' WITH (header='true', geo='true', "
44  "s3_region='us-west-1', "
45  "s3_access_key='HelloWorldAccessKeys',s3_secret_key='abcxyz');",
46  "COPY testtable FROM 's3://example/*' WITH (header='true', geo='true', "
47  "s3_region='us-west-1', s3_access_key='XXXXXXXX',s3_secret_key='XXXXXXXX');"},
48  {"CREATE USER jason (password = 'OmniSciRocks!', is_super = 'true')",
49  "CREATE USER jason (password = 'XXXXXXXX', is_super = 'true')"},
50  {"ALTER USER omnisci (password = 'OmniSciIsFast!')",
51  "ALTER USER omnisci (password = 'XXXXXXXX')"},
52  {"ALTER USER jason (is_super = 'false', password = 'SilkySmooth')",
53  "ALTER USER jason (is_super = 'false', password = 'XXXXXXXX')"},
54  {"ALTER USER omnisci (password = 'short')",
55  "ALTER USER omnisci (password = 'XXXXXXXX')"},
56  {"ALTER USER omnisci (password='short', future_parameter = 3)",
57  "ALTER USER omnisci (password='XXXXXXXX', future_parameter = 3)"},
58  {"CREATE USER jason (password = 'OmniSciRocks!', is_super = 'true'); CREATE "
59  "USER omnisci (password = 'OmniSciIsFast!')",
60  "CREATE USER jason (password = 'XXXXXXXX', is_super = 'true'); CREATE USER "
61  "omnisci (password = 'XXXXXXXX')"},
62  {"\\set_license DONTSHOWTHISSTRING", "\\set_license XXXXXXXX"},
63  {" \\set_license 'DONTSHOWTHISSTRING';", " \\set_license XXXXXXXX"}};
64  for (auto const& test : tests) {
65  std::string const safe = hide_sensitive_data_from_query(test.first);
66  ASSERT_EQ(safe, test.second);
67  }
68 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
+ Here is the call graph for this function: