MCPcopy Create free account
hub / github.com/apache/arrow / TEST

Function TEST

cpp/src/arrow/util/secure_string_test.cc:105–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103#undef COMPARE
104
105TEST(TestSecureString, AssertSecurelyCleared) {
106 // This tests AssertSecurelyCleared helper methods is actually able to identify secret
107 // leakage. It retrieves assertion results and asserts result type and message.
108 testing::AssertionResult result = testing::AssertionSuccess();
109
110 // check short string with all zeros
111 auto short_zeros = std::string(8, '\0');
112 short_zeros.resize(short_zeros.capacity(), '\0'); // for string buffers longer than 8
113 short_zeros.resize(8); // now the entire string buffer has zeros
114 // checks the entire string buffer (capacity)
115 ASSERT_TRUE(IsSecurelyCleared(short_zeros));
116 // checks only 10 bytes (length)
117 ASSERT_TRUE(IsSecurelyCleared(std::string_view(short_zeros)));
118
119 // check long string with all zeros
120 auto long_zeros = std::string(1000, '\0');
121 long_zeros.resize(long_zeros.capacity(), '\0'); // for longer string buffers
122 long_zeros.resize(1000); // now the entire string buffer has zeros
123 // checks the entire string buffer (capacity)
124 ASSERT_TRUE(IsSecurelyCleared(long_zeros));
125 // checks only 1000 bytes (length)
126 ASSERT_TRUE(IsSecurelyCleared(std::string_view(long_zeros)));
127
128 auto no_zeros = std::string("abcdefghijklmnopqrstuvwxyz");
129 // string buffer in no_zeros can be larger than no_zeros.length()
130 // assert only the area that we can control
131 auto no_zeros_view = std::string_view(no_zeros);
132 result = IsSecurelyCleared(no_zeros_view);
133 ASSERT_FALSE(result);
134 ASSERT_EQ(std::string(result.message()),
135 "Expected equality of these values:\n"
136 " area\n"
137 " Which is: \"abcdefghijklmnopqrstuvwxyz\"\n"
138 " std::string_view(zeros)\n"
139 " Which is: "
140 "\"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\"
141 "0\\0\\0\\0\\0\"");
142
143 // check short string with zeros and non-zeros after string length
144 auto stars = std::string(12, '*');
145 auto short_some_zeros = stars;
146 memset(short_some_zeros.data(), '\0', 8);
147 short_some_zeros.resize(8);
148 // string buffer in short_some_zeros can be larger than 12
149 // assert only the area that we can control
150 auto short_some_zeros_view = std::string_view(short_some_zeros.data(), 12);
151 result = IsSecurelyCleared(short_some_zeros_view);
152 ASSERT_FALSE(result);
153 ASSERT_EQ(std::string(result.message()),
154 "Expected equality of these values:\n"
155 " area\n"
156 " Which is: \"\\0\\0\\0\\0\\0\\0\\0\\0\\0***\"\n"
157 " std::string_view(zeros)\n"
158 " Which is: \"\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\\0\"");
159
160 ASSERT_TRUE(IsSecurelyCleared(short_some_zeros, stars));
161#if CAN_TEST_DEALLOCATED_AREAS
162 result = IsSecurelyCleared(short_some_zeros_view, stars);

Callers

nothing calls this directly

Calls 14

IsSecurelyClearedFunction · 0.85
StringAreaFunction · 0.85
SecureStringFunction · 0.85
equalFunction · 0.85
resizeMethod · 0.80
as_viewMethod · 0.80
as_spanMethod · 0.80
capacityMethod · 0.45
dataMethod · 0.45
lengthMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected