Minio容器用于测试范围签名匹配异常

发布于 2025-02-11 00:41:38 字数 1819 浏览 2 评论 0原文

当我在当地运行应用程序时,我的春季项目在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Saygoodbye 2025-02-18 00:41:38

不确定您是否有另一个正在返回此错误的Minio运行的本地实例。但是对我来说,我根本无法连接到运行Minio的testContainer,而无需将主机和容器端口绑定到9000

@Container
private static final GenericContainer<?> minioContainer =
            new GenericContainer<>(DockerImageName.parse(dockerImage))
                    .withExposedPorts(exposedPort)
                    .withEnv("MINIO_ROOT_USER", accessKey)
                    .withEnv("MINIO_ROOT_PASSWORD", secretKey)
                    .withCommand("server", "/data")
                    .withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
                            new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(exposedPort), new ExposedPort(exposedPort)))));

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

@Container
private static final GenericContainer<?> minioContainer =
            new GenericContainer<>(DockerImageName.parse(dockerImage))
                    .withExposedPorts(exposedPort)
                    .withEnv("MINIO_ROOT_USER", accessKey)
                    .withEnv("MINIO_ROOT_PASSWORD", secretKey)
                    .withCommand("server", "/data")
                    .withCreateContainerCmdModifier(cmd -> cmd.withHostConfig(
                            new HostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(exposedPort), new ExposedPort(exposedPort)))));

This solved the problem for me

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文