Minio容器用于测试范围签名匹配异常
当我在当地运行应用程序时,我的春季项目在docker容器中运行,
一切正常,文件成功上传和下载。 但是,当我试图通过文件上传请求的testContainers测试此逻辑时,我会得到“我们计算的请求签名与您提供的签名不匹配。检查键和签名方法。”
我在测试和测试中
可以创建和列出的docker容器配置在测试中和列表桶中,但是在上载时,我
在这里得到了一个例外我的测试源代码:
@SpringBootTest
@Testcontainers
public class FileServiceTest {
private static final String accessKey = "AKIAIOSFODNN7EXAMPLE";
private static final String secretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
private static final Integer defaultPort = 9000;
@Container
private static final GenericContainer<?> minioContainer =
new GenericContainer<>(DockerImageName.parse("quay.io/minio/minio"))
.withExposedPorts(defaultPort)
.withEnv("MINIO_ACCESS_KEY", accessKey)
.withEnv("MINIO_SECRET_KEY", secretKey)
.withCommand("server", "/data");
private final MinioClient minioClient = MinioClient.builder()
.endpoint(minioContainer.getContainerIpAddress(), minioContainer.getMappedPort(defaultPort), false)
.credentials(accessKey, secretKey)
.build();
@Test
public void shouldUploadFile() throws Exception {
String bucket = "bucket-name";
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build()); // success
UUID fileId = UUID.randomUUID();
PutObjectArgs uploadObject = PutObjectArgs.builder()
.bucket(bucket)
.object(fileId.toString())
.stream(mockMultipartFile.getInputStream(), mockMultipartFile.getSize(), -1)
.contentType(mockMultipartFile.getContentType())
.build();
minioClient.putObject(uploadObject); // exception here
}
我该如何解决此问题?
I have spring project with minio s3 running in docker container
When I run my app locally everything works OK, files successfully uploading and downloading.
But when Im trying to test this logic via Testcontainers on file upload request i get "The request signature we calculated does not match the signature you provided. Check your key and signing method."
I run same docker container configuration in tests and outside of tests
Fun thing that i can create and list buckets, but on upload i get an exception
Here my test source code:
@SpringBootTest
@Testcontainers
public class FileServiceTest {
private static final String accessKey = "AKIAIOSFODNN7EXAMPLE";
private static final String secretKey = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY";
private static final Integer defaultPort = 9000;
@Container
private static final GenericContainer<?> minioContainer =
new GenericContainer<>(DockerImageName.parse("quay.io/minio/minio"))
.withExposedPorts(defaultPort)
.withEnv("MINIO_ACCESS_KEY", accessKey)
.withEnv("MINIO_SECRET_KEY", secretKey)
.withCommand("server", "/data");
private final MinioClient minioClient = MinioClient.builder()
.endpoint(minioContainer.getContainerIpAddress(), minioContainer.getMappedPort(defaultPort), false)
.credentials(accessKey, secretKey)
.build();
@Test
public void shouldUploadFile() throws Exception {
String bucket = "bucket-name";
minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build()); // success
UUID fileId = UUID.randomUUID();
PutObjectArgs uploadObject = PutObjectArgs.builder()
.bucket(bucket)
.object(fileId.toString())
.stream(mockMultipartFile.getInputStream(), mockMultipartFile.getSize(), -1)
.contentType(mockMultipartFile.getContentType())
.build();
minioClient.putObject(uploadObject); // exception here
}
Any tips how can i resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您是否有另一个正在返回此错误的Minio运行的本地实例。但是对我来说,我根本无法连接到运行Minio的testContainer,而无需将主机和容器端口绑定到9000
。
Not sure if you have another local instance of minio running which is returning this error. But for me, I was not able to connect to the testcontainer running minio at all, without binding the host and container ports to 9000. Therefore, I set a static host and exposed port on the container like so
This solved the problem for me