Skip to content

Commit 3c77ed5

Browse files
committed
PSMDB-1811: add clang-tidy warnings for testing
1 parent b3a275e commit 3c77ed5

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/mongo/db/encryption/vault_client.cpp

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

4447
#include <boost/tokenizer.hpp>
4548

@@ -63,6 +66,8 @@ Copyright (C) 2024-present Percona and/or its affiliates. All rights reserved.
6366

6467
#define MONGO_LOGV2_DEFAULT_COMPONENT ::mongo::logv2::LogComponent::kNetwork
6568

69+
// dummy change
70+
6671
namespace mongo::encryption {
6772
namespace {
6873
class PositiveUint64 {
@@ -82,6 +87,11 @@ class BadHttpReponse : public std::runtime_error {
8287
: std::runtime_error(str::stream()
8388
<< "Bad HTTP response from the Vault server while " << operation
8489
<< "; statusCode: " << code << "; body: `" << body << "`") {}
90+
91+
// Test function with StringData const ref (should trigger mongo-stringdata-const-ref-check)
92+
void testStringDataRef(const StringData& testParam) {
93+
// This parameter should be passed by value instead of const ref
94+
}
8595
};
8696

8797
class InvalidVaultResponse : public std::runtime_error {
@@ -92,6 +102,22 @@ class InvalidVaultResponse : public std::runtime_error {
92102
InvalidVaultResponse(const StringData& fieldName, const StringData& reason)
93103
: std::runtime_error(str::stream() << "Invalid Vault response: `" << fieldName << "` "
94104
<< reason << ".") {}
105+
106+
// Test function with std::optional (should trigger mongo-std-optional-check)
107+
std::optional<std::string> testStdOptional() {
108+
return std::nullopt; // Should use boost::optional instead
109+
}
110+
111+
// Test function with std::atomic (should trigger mongo-std-atomic-check)
112+
void testStdAtomic() {
113+
std::atomic<int> counter{0}; // Should use boost::atomic instead
114+
counter.store(42);
115+
}
116+
117+
// Test function with std::rand (should trigger mongo-rand-check)
118+
void testStdRand() {
119+
int randomValue = std::rand(); // Should use mongo::PseudoRandom instead
120+
}
95121
};
96122

97123
class ReachedMaxVersions : public std::runtime_error {
@@ -129,10 +155,21 @@ struct SecretMetadata {
129155
std::uint64_t currentVersion{0};
130156
};
131157

158+
namespace {
159+
void check_string_data(const StringData& sd) {
160+
if (sd.empty()) {
161+
throw std::invalid_argument("empty string");
162+
}
163+
if (sd.find('\0') != StringData::npos) {
164+
throw std::invalid_argument("embedded null character");
165+
}
166+
}
167+
}
168+
132169
template <typename T>
133170
T bsonObjectGetNestedValue(const BSONObj& object, const StringData& path) {
134171
invariant(!path.empty());
135-
172+
check_string_data(path);
136173
static constexpr const char* kNotObject = "is missing or not an object";
137174
static constexpr const char* kNotInteger = "is missing or not an integer";
138175
static constexpr const char* kNotString = "is missing or not a string";
@@ -441,6 +478,8 @@ StatusWith<BSONObj> VaultClient::Impl::getOpenAPISpec() const try {
441478
<< "Getting the OpenAPI spec failed, statusCode: " << reply.code);
442479
}
443480

481+
482+
444483
ConstDataRangeCursor cur = reply.body.getCursor();
445484
StringData replyBody(cur.data(), cur.length());
446485

0 commit comments

Comments
 (0)