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