func TestTimeValueSlice(t *testing.T) { for idx, in := range testCasesTimeValueSlice { if in == nil { continue } out := TimeValueSlice(in) assert.Len(t, out, len(in), "Unexpected len at idx %d", idx) for i := range out { if in[i] == nil { assert.Empty(t, out[i], "Unexpected value at idx %d", idx) } else { assert.Equal(t, *(in[i]), out[i], "Unexpected value at idx %d", idx) } } out2 := TimeSlice(out) assert.Len(t, out2, len(in), "Unexpected len at idx %d", idx) for i := range out2 { if in[i] == nil { assert.Empty(t, *(out2[i]), "Unexpected value at idx %d", idx) } else { assert.Equal(t, in[i], out2[i], "Unexpected value at idx %d", idx) } } } }
func TestGenericEndpoint(t *testing.T) { name := "service" region := "mock-region-1" ep, sr := endpoints.EndpointForRegion(name, region, false) assert.Equal(t, fmt.Sprintf("https://%s.%s.amazonaws.com", name, region), ep) assert.Empty(t, sr) }
func TestServicesInCN(t *testing.T) { region := "cn-north-1" svcs := []string{"cloudfront", "iam", "importexport", "route53", "sts", "s3", "waf"} for _, name := range svcs { ep, sr := endpoints.EndpointForRegion(name, region, false) assert.Equal(t, fmt.Sprintf("https://%s.%s.amazonaws.com.cn", name, region), ep) assert.Empty(t, sr) } }
func TestSharedCredentialsProviderColonInCredFile(t *testing.T) { os.Clearenv() p := SharedCredentialsProvider{Filename: "example.ini", Profile: "with_colon"} creds, err := p.Retrieve() assert.Nil(t, err, "Expect no error") assert.Equal(t, "accessKey", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "secret", creds.SecretAccessKey, "Expect secret access key to match") assert.Empty(t, creds.SessionToken, "Expect no token") }
func TestSharedCredentialsProviderWithAWS_PROFILE(t *testing.T) { os.Clearenv() os.Setenv("AWS_PROFILE", "no_token") p := SharedCredentialsProvider{Filename: "example.ini", Profile: ""} creds, err := p.Retrieve() assert.Nil(t, err, "Expect no error") assert.Equal(t, "accessKey", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "secret", creds.SecretAccessKey, "Expect secret access key to match") assert.Empty(t, creds.SessionToken, "Expect no token") }
func TestEnvProviderAlternateNames(t *testing.T) { os.Clearenv() os.Setenv("AWS_ACCESS_KEY", "access") os.Setenv("AWS_SECRET_KEY", "secret") e := EnvProvider{} creds, err := e.Retrieve() assert.Nil(t, err, "Expect no error") assert.Equal(t, "access", creds.AccessKeyID, "Expected access key ID") assert.Equal(t, "secret", creds.SecretAccessKey, "Expected secret access key") assert.Empty(t, creds.SessionToken, "Expected no token") }
func TestStaticProviderGet(t *testing.T) { s := StaticProvider{ Value: Value{ AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "", }, } creds, err := s.Retrieve() assert.Nil(t, err, "Expect no error") assert.Equal(t, "AKID", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "SECRET", creds.SecretAccessKey, "Expect secret access key to match") assert.Empty(t, creds.SessionToken, "Expect no session token") }
func TestCredentialsGet(t *testing.T) { c := NewCredentials(&stubProvider{ creds: Value{ AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "", }, expired: true, }) creds, err := c.Get() assert.Nil(t, err, "Expected no error") assert.Equal(t, "AKID", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "SECRET", creds.SecretAccessKey, "Expect secret access key to match") assert.Empty(t, creds.SessionToken, "Expect session token to be empty") }
func TestChainProviderGet(t *testing.T) { p := &ChainProvider{ Providers: []Provider{ &stubProvider{err: awserr.New("FirstError", "first provider error", nil)}, &stubProvider{err: awserr.New("SecondError", "second provider error", nil)}, &stubProvider{ creds: Value{ AccessKeyID: "AKID", SecretAccessKey: "SECRET", SessionToken: "", }, }, }, } creds, err := p.Retrieve() assert.Nil(t, err, "Expect no error") assert.Equal(t, "AKID", creds.AccessKeyID, "Expect access key ID to match") assert.Equal(t, "SECRET", creds.SecretAccessKey, "Expect secret access key to match") assert.Empty(t, creds.SessionToken, "Expect session token to be empty") }
func TestAnonymousCredentials(t *testing.T) { svc := awstesting.NewClient(&aws.Config{Credentials: credentials.AnonymousCredentials}) r := svc.NewRequest( &request.Operation{ Name: "BatchGetItem", HTTPMethod: "POST", HTTPPath: "/", }, nil, nil, ) Sign(r) urlQ := r.HTTPRequest.URL.Query() assert.Empty(t, urlQ.Get("X-Amz-Signature")) assert.Empty(t, urlQ.Get("X-Amz-Credential")) assert.Empty(t, urlQ.Get("X-Amz-SignedHeaders")) assert.Empty(t, urlQ.Get("X-Amz-Date")) hQ := r.HTTPRequest.Header assert.Empty(t, hQ.Get("Authorization")) assert.Empty(t, hQ.Get("X-Amz-Date")) }