-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain_s3_test.go
More file actions
54 lines (44 loc) · 1.97 KB
/
main_s3_test.go
File metadata and controls
54 lines (44 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package main
import (
"context"
"net"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/require"
"golang.org/x/sync/errgroup"
)
func TestStartS3ServerRejectsVirtualHostedStyleConfig(t *testing.T) {
eg, ctx := errgroup.WithContext(context.Background())
srv, err := startS3Server(ctx, &net.ListenConfig{}, eg, "localhost:9000", nil, nil, nil, "us-east-1", "", false, nil)
require.ErrorContains(t, err, "virtual-hosted style S3 requests are not implemented")
require.Nil(t, srv)
}
func TestStartS3ServerAllowsEmptyAddress(t *testing.T) {
eg, ctx := errgroup.WithContext(context.Background())
srv, err := startS3Server(ctx, &net.ListenConfig{}, eg, "", nil, nil, nil, "us-east-1", "", false, nil)
require.NoError(t, err)
require.Nil(t, srv)
}
func TestLoadS3StaticCredentials(t *testing.T) {
path := filepath.Join(t.TempDir(), "s3creds.json")
err := os.WriteFile(path, []byte(`{"credentials":[{"access_key_id":"akid","secret_access_key":"secret"}]}`), 0o600)
require.NoError(t, err)
creds, err := loadS3StaticCredentials(path)
require.NoError(t, err)
require.Equal(t, map[string]string{"akid": "secret"}, creds)
}
func TestLoadS3StaticCredentialsRejectsEmptyValues(t *testing.T) {
path := filepath.Join(t.TempDir(), "s3creds.json")
err := os.WriteFile(path, []byte(`{"credentials":[{"access_key_id":" ","secret_access_key":"secret"}]}`), 0o600)
require.NoError(t, err)
_, err = loadS3StaticCredentials(path)
require.ErrorContains(t, err, "s3 credentials file contains an empty access key or secret key")
}
func TestLoadS3StaticCredentialsRejectsDuplicateAccessKeyIDs(t *testing.T) {
path := filepath.Join(t.TempDir(), "s3creds.json")
err := os.WriteFile(path, []byte(`{"credentials":[{"access_key_id":"akid","secret_access_key":"secret-1"},{"access_key_id":"akid","secret_access_key":"secret-2"}]}`), 0o600)
require.NoError(t, err)
_, err = loadS3StaticCredentials(path)
require.ErrorContains(t, err, `s3 credentials file contains duplicate access key ID: "akid"`)
}