github.com/aliyun/credentials-go@v1.4.7/integration/proxy/proxy_test.go (about) 1 package proxy 2 3 import ( 4 "os" 5 "testing" 6 7 "github.com/alibabacloud-go/tea/tea" 8 "github.com/aliyun/credentials-go/credentials" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 func TestRAMRoleARNWithInvalidProxy(t *testing.T) { 13 config := &credentials.Config{ 14 Type: tea.String("ram_role_arn"), 15 AccessKeyId: tea.String("akid"), 16 AccessKeySecret: tea.String("aksecret"), 17 RoleArn: tea.String("rolearn"), 18 RoleSessionName: tea.String("rolesessionname"), 19 RoleSessionExpiration: tea.Int(3600), 20 Proxy: tea.String("https://localhost:3600/"), 21 } 22 cred, err := credentials.NewCredential(config) 23 assert.Nil(t, err) 24 _, err = cred.GetCredential() 25 assert.Contains(t, err.Error(), "proxyconnect tcp: dial tcp") 26 assert.Contains(t, err.Error(), ":3600: connect: connection refused") 27 } 28 29 func TestOIDCWithInvalidProxy(t *testing.T) { 30 config := &credentials.Config{ 31 Type: tea.String("oidc_role_arn"), 32 RoleArn: tea.String(os.Getenv("ALIBABA_CLOUD_ROLE_ARN")), 33 OIDCProviderArn: tea.String(os.Getenv("ALIBABA_CLOUD_OIDC_PROVIDER_ARN")), 34 OIDCTokenFilePath: tea.String(os.Getenv("ALIBABA_CLOUD_OIDC_TOKEN_FILE")), 35 RoleSessionName: tea.String("credentials-go-test"), 36 Proxy: tea.String("https://localhost:3600/"), 37 } 38 cred, err := credentials.NewCredential(config) 39 assert.Nil(t, err) 40 _, err = cred.GetCredential() 41 assert.Contains(t, err.Error(), "proxyconnect tcp: dial tcp") 42 assert.Contains(t, err.Error(), ":3600: connect: connection refused") 43 }