OmniSciDB  04ee39c94c
StringTransformTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "../Shared/StringTransform.h"
18 #include "TestHelpers.h"
19 
20 #include <gtest/gtest.h>
21 
22 TEST(StringTransform, CsvQuote) {
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 }
40 
41 TEST(StringTransform, HideSensitiveDataFromQuery) {
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 }
69 
70 int main(int argc, char* argv[]) {
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 }
std::string hide_sensitive_data_from_query(std::string const &query_str)
#define LOG(tag)
Definition: Logger.h:182
TEST(StringTransform, CsvQuote)
int main(int argc, char *argv[])
void init_logger_stderr_only(int argc, char const *const *argv)
Definition: TestHelpers.h:194