Skip to content

Commit

Permalink
Add unit test and fix IWYU
Browse files Browse the repository at this point in the history
  • Loading branch information
yujingwei committed Oct 18, 2023
1 parent 0b533f5 commit 4481ebf
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 3 deletions.
3 changes: 0 additions & 3 deletions src/base/pegasus_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <netinet/in.h>
#include <rocksdb/slice.h>
#include <stdio.h>
#include <sys/socket.h>
#include <cctype>
#include <utility>

#include "runtime/rpc/rpc_address.h"
#include "utils/blob.h"
#include "utils/fmt_logging.h"

namespace pegasus {
Expand Down
73 changes: 73 additions & 0 deletions src/base/test/redact_sensitive_string_test.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

// IWYU pragma: no_include <gtest/gtest-message.h>
// IWYU pragma: no_include <gtest/gtest-test-part.h>
#include <gtest/gtest.h>
#include <list>
#include <string>
#include <iostream>

#include "base/pegasus_utils.h"

const std::string test_string = "pegasus";

// FLAGS_encrypt_data_at_rest up
TEST(pegasus_utils, redact_sensitive_string)
{
FLAGS_encrypt_data_at_rest = true;
auto result_string = pegasus::utils::redact_sensitive_string(test_string);
ASSERT_EQ(pegasus::utils::kRedactedString, result_string);
}

// FLAGS_encrypt_data_at_rest down
TEST(pegasus_utils, redact_sensitive_string_with_encrypt)
{
FLAGS_encrypt_data_at_rest = false;
auto result_string = pegasus::utils::redact_sensitive_string(test_string);
ASSERT_EQ("pegasus", result_string);
}

TEST(pegasus_utils, c_escape_sensitive_string_with_no_encrypt_and_escape)
{
FLAGS_encrypt_data_at_rest = false;
auto result_string = pegasus::utils::c_escape_sensitive_string(test_string, false);
ASSERT_EQ("pegasus", result_string);
}

TEST(pegasus_utils, c_escape_sensitive_string_with_no_encrypt)
{
FLAGS_encrypt_data_at_rest = false;
auto result_string = pegasus::utils::c_escape_sensitive_string(test_string, true);
ASSERT_EQ("\\x70\\x65\\x67\\x61\\x73\\x75\\x73", result_string);
}

TEST(pegasus_utils, c_escape_sensitive_string_with_encrypt)
{
FLAGS_encrypt_data_at_rest = true;
auto result_string = pegasus::utils::c_escape_sensitive_string(test_string, false);
ASSERT_EQ(pegasus::utils::kRedactedString, result_string);
}

TEST(pegasus_utils, c_escape_sensitive_string_with_encrypt_and_escape)
{
FLAGS_encrypt_data_at_rest = true;
auto result_string = pegasus::utils::c_escape_sensitive_string(test_string, true);
ASSERT_EQ(pegasus::utils::kRedactedString, result_string);
}

0 comments on commit 4481ebf

Please sign in to comment.