Skip to content

Commit

Permalink
Add unit test for case-insensitive etag parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
bbockelm committed Dec 15, 2024
1 parent 96e8c5b commit f99ffb1
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/HTTPCommands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ bool HTTPRequest::Fail(const std::string &ecode, const std::string &emsg) {
void HTTPRequest::Notify() {
std::lock_guard<std::mutex> lk(m_mtx);
m_result_ready = true;
modifyResponse(m_result);
m_cv.notify_one();
}

Expand Down
4 changes: 4 additions & 0 deletions src/HTTPCommands.hh
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class HTTPRequest {
// call to send more data.
bool Timeout() const { return m_timeout; }

// Function that can be overridden by test cases, allowing modification
// of the server response
virtual void modifyResponse(std::string &) {}

typedef std::map<std::string, std::string> AttributeValueMap;
AttributeValueMap query_parameters;
AttributeValueMap headers;
Expand Down
2 changes: 1 addition & 1 deletion src/S3Commands.hh
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class AmazonS3CompleteMultipartUpload : public AmazonRequest {
protected:
};

class AmazonS3SendMultipartPart final : public AmazonRequest {
class AmazonS3SendMultipartPart : public AmazonRequest {
using AmazonRequest::SendRequest;

public:
Expand Down
49 changes: 49 additions & 0 deletions test/s3_unit_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ s3.end
}

public:
std::unique_ptr<S3FileSystem> GetFS() {
return std::unique_ptr<S3FileSystem>(new S3FileSystem(&m_log, m_configfn.c_str(), nullptr));
}

void WritePattern(const std::string &name, const off_t writeSize,
const unsigned char chunkByte, const size_t chunkSize,
bool known_size) {
Expand Down Expand Up @@ -260,6 +264,8 @@ s3.end
rv = fh->Close();
ASSERT_EQ(rv, 0);
}

XrdSysLogger m_log;
};

// Upload a single byte into S3
Expand Down Expand Up @@ -576,6 +582,49 @@ TEST_F(FileSystemS3Fixture, StressGet) {
}
}

class AmazonS3SendMultipartPartLowercase : public AmazonS3SendMultipartPart {
protected:
virtual void modifyResponse(std::string &resp) override {
std::transform(resp.begin(), resp.end(), resp.begin(), [](unsigned char c){ return std::tolower(c); });
}
};

TEST_F(FileSystemS3Fixture, Etag) {
// Determine the S3 info.
auto oss = GetFS();
std::string exposedPath, object;
std::string path = "/test/etag_casesensitive_test";
ASSERT_EQ(oss->parsePath(path.c_str(), exposedPath, object), 0);

auto ai = oss->getS3AccessInfo(exposedPath, object);
ASSERT_NE(ai.get(), nullptr);
ASSERT_NE(ai->getS3BucketName(), "");
ASSERT_NE(object, "");

// Start an upload.
XrdSysLogger log;
XrdSysError err(&log, "test");
AmazonS3CreateMultipartUpload startUpload(*ai, object, err);
ASSERT_TRUE(startUpload.SendRequest());
std::string uploadId, errMsg;
startUpload.Results(uploadId, errMsg);

// Upload an etag.
AmazonS3SendMultipartPart upload_part_request(*ai, object, err);
std::string streaming_buffer = "aaaa";
ASSERT_TRUE(upload_part_request.SendRequest(streaming_buffer,
std::to_string(1), uploadId,
streaming_buffer.size(), true));
std::string etag;
ASSERT_TRUE(upload_part_request.GetEtag(etag));
std::vector<std::string> eTags;
eTags.push_back(etag);

// Finalize the object
AmazonS3CompleteMultipartUpload complete_upload_request(*ai, object, err);
ASSERT_TRUE(complete_upload_request.SendRequest(eTags, 2, uploadId));
}

int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
Expand Down

0 comments on commit f99ffb1

Please sign in to comment.