Skip to content

Commit 15f75d8

Browse files
committed
PSMDB-1811: add clang-tidy warnings for testing
1 parent 85662b6 commit 15f75d8

1 file changed

Lines changed: 40 additions & 1 deletion

File tree

src/mongo/db/encryption/vault_client.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ Copyright (C) 2024-present Percona and/or its affiliates. All rights reserved.
3838
#include <type_traits>
3939
#include <vector>
4040
#include <regex>
41+
#include <optional> // This will trigger mongo-std-optional-check
42+
#include <atomic> // This will trigger mongo-std-atomic-check
43+
#include <cstdlib> // This will trigger mongo-rand-check
4144

4245
#include <boost/tokenizer.hpp>
4346
#include <boost/optional.hpp>
@@ -60,6 +63,8 @@ Copyright (C) 2024-present Percona and/or its affiliates. All rights reserved.
6063

6164
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kNetwork
6265

66+
// dummy change
67+
6368
namespace mongo::encryption {
6469
namespace {
6570
class PositiveUint64 {
@@ -79,6 +84,11 @@ class BadHttpReponse : public std::runtime_error {
7984
: std::runtime_error(str::stream()
8085
<< "Bad HTTP response from the Vault server while " << operation
8186
<< "; statusCode: " << code << "; body: `" << body << "`") {}
87+
88+
// Test function with StringData const ref (should trigger mongo-stringdata-const-ref-check)
89+
void testStringDataRef(const StringData& testParam) {
90+
// This parameter should be passed by value instead of const ref
91+
}
8292
};
8393

8494
class InvalidVaultResponse : public std::runtime_error {
@@ -89,6 +99,22 @@ class InvalidVaultResponse : public std::runtime_error {
8999
InvalidVaultResponse(StringData fieldName, StringData reason)
90100
: std::runtime_error(str::stream() << "Invalid Vault response: `" << fieldName << "` "
91101
<< reason << ".") {}
102+
103+
// Test function with std::optional (should trigger mongo-std-optional-check)
104+
std::optional<std::string> testStdOptional() {
105+
return std::nullopt; // Should use boost::optional instead
106+
}
107+
108+
// Test function with std::atomic (should trigger mongo-std-atomic-check)
109+
void testStdAtomic() {
110+
std::atomic<int> counter{0}; // Should use boost::atomic instead
111+
counter.store(42);
112+
}
113+
114+
// Test function with std::rand (should trigger mongo-rand-check)
115+
void testStdRand() {
116+
int randomValue = std::rand(); // Should use mongo::PseudoRandom instead
117+
}
92118
};
93119

94120
class ReachedMaxVersions : public std::runtime_error {
@@ -126,10 +152,21 @@ struct SecretMetadata {
126152
std::uint64_t currentVersion{0};
127153
};
128154

155+
namespace {
156+
void check_string_data(const StringData& sd) {
157+
if (sd.empty()) {
158+
throw std::invalid_argument("empty string");
159+
}
160+
if (sd.find('\0') != StringData::npos) {
161+
throw std::invalid_argument("embedded null character");
162+
}
163+
}
164+
}
165+
129166
template <typename T>
130167
T bsonObjectGetNestedValue(const BSONObj& object, StringData path) {
131168
invariant(!path.empty());
132-
169+
check_string_data(path);
133170
static constexpr const char* kNotObject = "is missing or not an object";
134171
static constexpr const char* kNotInteger = "is missing or not an integer";
135172
static constexpr const char* kNotString = "is missing or not a string";
@@ -435,6 +472,8 @@ StatusWith<BSONObj> VaultClient::Impl::getOpenAPISpec() const try {
435472
<< "Getting the OpenAPI spec failed, statusCode: " << reply.code);
436473
}
437474

475+
476+
438477
ConstDataRangeCursor cur = reply.body.getCursor();
439478
StringData replyBody(cur.data(), cur.length());
440479

0 commit comments

Comments
 (0)