...
1 package config
2
3 import (
4 "context"
5 "github.com/aws/aws-sdk-go-v2/credentials/stscreds"
6 "github.com/aws/aws-sdk-go-v2/internal/awstesting"
7 "os"
8 "path/filepath"
9 "runtime"
10 "strings"
11 "testing"
12 )
13
14
15 func TestResolveWebIdentityWithOptions(t *testing.T) {
16
17 t.Run("token from env", func(t *testing.T) {
18 restoreEnv := initConfigTestEnv()
19 defer awstesting.PopEnv(restoreEnv)
20
21 var tokenFile = filepath.Join("testdata", "wit.txt")
22 os.Setenv("AWS_WEB_IDENTITY_TOKEN_FILE", tokenFile)
23 os.Setenv("AWS_REGION", "us-east-1")
24
25 _, err := LoadDefaultConfig(context.Background(),
26 WithWebIdentityRoleCredentialOptions(func(options *stscreds.WebIdentityRoleOptions) {
27 options.RoleARN = "test-arn"
28 }),
29 )
30
31 if err != nil {
32 t.Fatalf("expect no error, got %v", err)
33 }
34 })
35
36 t.Run("token from profile", func(t *testing.T) {
37
38 restoreEnv := initConfigTestEnv()
39 defer awstesting.PopEnv(restoreEnv)
40
41 var configFileForWindows = filepath.Join("testdata", "config_source_shared_for_windows")
42 var configFile = filepath.Join("testdata", "config_source_shared")
43
44 os.Setenv("AWS_REGION", "us-east-1")
45 os.Setenv("AWS_PROFILE", "webident-partial")
46
47 if runtime.GOOS == "windows" {
48 os.Setenv("AWS_CONFIG_FILE", configFileForWindows)
49 } else {
50 os.Setenv("AWS_CONFIG_FILE", configFile)
51 }
52
53 _, err := LoadDefaultConfig(context.Background())
54
55 if err == nil || !strings.Contains(err.Error(), "web_identity_token_file requires role_arn") {
56 t.Fatalf("expected profile parsing error, got %v", err)
57 }
58 })
59 }
60
View as plain text