Skip to content

Commit 3433232

Browse files
committed
test(libstore): add regression tests for S3 fixes
Add tests to prevent regression of S3 functionality: 1. Store Registration (commit 7a2f289): - Test that S3 scheme is recognized in supported URI schemes - Test that S3 store config can be created without errors 2. Upload Support (commit c0164e0): - Test that S3 uploads are not rejected with "not supported" error - Verify upload requests are accepted (may fail on credentials/network) 3. Region Handling (commit e618ac7e0): - Test that query parameters are preserved for S3 stores - Test URL parsing with various region specifications - Verify region parameters are correctly maintained
1 parent 9e6804b commit 3433232

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed

src/libstore-tests/filetransfer-s3.cc

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include "nix/store/filetransfer.hh"
22
#include "nix/store/config.hh"
3+
#include "nix/store/http-binary-cache-store.hh"
4+
#include "nix/store/store-api.hh"
5+
#include "nix/util/types.hh"
36

47
#if NIX_WITH_AWS_CRT_SUPPORT
58

@@ -157,6 +160,106 @@ TEST_F(S3FileTransferTest, regionExtraction)
157160
}
158161
}
159162

163+
/**
164+
* Regression test for commit 7a2f2891e
165+
* Test that S3 store URLs are properly recognized and handled
166+
*/
167+
TEST_F(S3FileTransferTest, s3StoreRegistration)
168+
{
169+
// Test that S3 URI scheme is in the supported schemes
170+
auto schemes = HttpBinaryCacheStoreConfig::uriSchemes();
171+
EXPECT_TRUE(schemes.count("s3") > 0) << "S3 scheme should be in supported URI schemes";
172+
173+
// Test that S3 store can be opened without error
174+
try {
175+
auto storeUrl = "s3://test-bucket";
176+
auto parsedUrl = parseURL(storeUrl);
177+
EXPECT_EQ(parsedUrl.scheme, "s3");
178+
179+
// Verify that HttpBinaryCacheStoreConfig accepts S3 URLs
180+
HttpBinaryCacheStoreConfig config("s3", "test-bucket", {});
181+
EXPECT_EQ(config.cacheUri.scheme, "s3");
182+
EXPECT_EQ(config.cacheUri.authority->host, "test-bucket");
183+
} catch (const std::exception & e) {
184+
FAIL() << "Should be able to create S3 store config: " << e.what();
185+
}
186+
}
187+
188+
/**
189+
* Regression test for commit c0164e087
190+
* Test that S3 uploads are not rejected with "not supported" error
191+
*/
192+
TEST_F(S3FileTransferTest, s3UploadsNotRejected)
193+
{
194+
auto ft = makeFileTransfer();
195+
196+
// Create a mock upload request
197+
FileTransferRequest uploadReq("s3://test-bucket/test-file");
198+
uploadReq.data = std::string("test data");
199+
200+
// This should not throw "uploading to 's3://...' is not supported"
201+
// We're testing that S3 uploads aren't immediately rejected
202+
bool gotNotSupportedError = false;
203+
try {
204+
ft->upload(uploadReq);
205+
} catch (const Error & e) {
206+
std::string msg = e.what();
207+
if (msg.find("is not supported") != std::string::npos) {
208+
gotNotSupportedError = true;
209+
}
210+
} catch (...) {
211+
// Other errors are expected (no credentials, network issues, etc.)
212+
}
213+
214+
EXPECT_FALSE(gotNotSupportedError) << "S3 uploads should not be rejected with 'not supported' error";
215+
}
216+
217+
/**
218+
* Regression test for commit e618ac7e0
219+
* Test that S3 URLs with region query parameters are handled correctly
220+
*/
221+
TEST_F(S3FileTransferTest, s3RegionQueryParameters)
222+
{
223+
// Test that query parameters are preserved in S3 URLs
224+
StringMap params;
225+
params["region"] = "us-west-2";
226+
227+
HttpBinaryCacheStoreConfig config("s3", "test-bucket", params);
228+
229+
// For S3 stores, query parameters should be preserved
230+
EXPECT_FALSE(config.cacheUri.query.empty()) << "S3 store should preserve query parameters";
231+
EXPECT_EQ(config.cacheUri.query["region"], "us-west-2") << "Region parameter should be preserved";
232+
233+
// Test with different regions
234+
StringMap params2;
235+
params2["region"] = "eu-central-1";
236+
237+
HttpBinaryCacheStoreConfig config2("s3", "another-bucket", params2);
238+
EXPECT_EQ(config2.cacheUri.query["region"], "eu-central-1") << "Different region parameter should be preserved";
239+
}
240+
241+
/**
242+
* Test S3 URL parsing with various query parameters
243+
*/
244+
TEST_F(S3FileTransferTest, s3UrlParsingWithQueryParams)
245+
{
246+
// Test various S3 URLs with query parameters
247+
std::vector<std::tuple<std::string, std::string, std::string, std::string>> testCases = {
248+
{"s3://bucket/key?region=us-east-2", "s3", "bucket", "us-east-2"},
249+
{"s3://my-bucket/path/to/file?region=eu-west-1", "s3", "my-bucket", "eu-west-1"},
250+
{"s3://test/obj?region=ap-south-1", "s3", "test", "ap-south-1"},
251+
};
252+
253+
for (const auto & [url, expectedScheme, expectedBucket, expectedRegion] : testCases) {
254+
auto parsed = parseURL(url);
255+
EXPECT_EQ(parsed.scheme, expectedScheme) << "URL: " << url;
256+
EXPECT_EQ(parsed.authority->host, expectedBucket) << "URL: " << url;
257+
if (!expectedRegion.empty()) {
258+
EXPECT_EQ(parsed.query["region"], expectedRegion) << "URL: " << url;
259+
}
260+
}
261+
}
262+
160263
} // namespace nix
161264

162265
#endif // NIX_WITH_AWS_CRT_SUPPORT

0 commit comments

Comments
 (0)