-
-
Notifications
You must be signed in to change notification settings - Fork 153
Expand file tree
/
Copy pathterraform_output_authcontext_wrapper_test.go
More file actions
100 lines (81 loc) · 3.71 KB
/
terraform_output_authcontext_wrapper_test.go
File metadata and controls
100 lines (81 loc) · 3.71 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package exec
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/cloudposse/atmos/pkg/schema"
)
// TestNewAuthContextWrapper verifies that authContextWrapper is properly created.
func TestNewAuthContextWrapper(t *testing.T) {
t.Run("nil authContext returns nil wrapper", func(t *testing.T) {
wrapper := newAuthContextWrapper(nil)
assert.Nil(t, wrapper, "Should return nil for nil authContext")
})
t.Run("valid authContext creates wrapper with stackInfo", func(t *testing.T) {
authContext := &schema.AuthContext{
AWS: &schema.AWSAuthContext{
Profile: "test-profile",
Region: "us-east-1",
},
}
wrapper := newAuthContextWrapper(authContext)
require.NotNil(t, wrapper, "Should create wrapper for valid authContext")
require.NotNil(t, wrapper.stackInfo, "Wrapper should have stackInfo")
assert.Equal(t, authContext, wrapper.stackInfo.AuthContext, "StackInfo should contain the provided authContext")
})
}
// TestAuthContextWrapperGetStackInfo verifies GetStackInfo returns the correct stackInfo.
func TestAuthContextWrapperGetStackInfo(t *testing.T) {
authContext := &schema.AuthContext{
AWS: &schema.AWSAuthContext{
Profile: "test-identity",
Region: "us-west-2",
CredentialsFile: "/tmp/creds",
ConfigFile: "/tmp/config",
},
}
wrapper := newAuthContextWrapper(authContext)
stackInfo := wrapper.GetStackInfo()
require.NotNil(t, stackInfo, "GetStackInfo should return non-nil")
assert.Equal(t, authContext, stackInfo.AuthContext, "GetStackInfo should return stackInfo with authContext")
assert.Equal(t, "test-identity", stackInfo.AuthContext.AWS.Profile)
assert.Equal(t, "us-west-2", stackInfo.AuthContext.AWS.Region)
}
// TestAuthContextWrapperResolvePrincipalSetting verifies ResolvePrincipalSetting returns nil, false.
// The wrapper doesn't have access to identity/provider configuration, only auth context.
func TestAuthContextWrapperResolvePrincipalSetting(t *testing.T) {
authContext := &schema.AuthContext{
AWS: &schema.AWSAuthContext{
Profile: "test-identity",
Region: "us-west-2",
},
}
wrapper := newAuthContextWrapper(authContext)
// ResolvePrincipalSetting should always return nil, false for the wrapper.
// It only propagates existing auth context, not full identity configuration.
val, found := wrapper.ResolvePrincipalSetting("any-identity", "region")
assert.Nil(t, val, "ResolvePrincipalSetting should return nil")
assert.False(t, found, "ResolvePrincipalSetting should return false")
val, found = wrapper.ResolvePrincipalSetting("test-identity", "any-key")
assert.Nil(t, val, "ResolvePrincipalSetting should return nil for any key")
assert.False(t, found, "ResolvePrincipalSetting should return false for any key")
}
// TestAuthContextWrapperResolveProviderConfig verifies ResolveProviderConfig returns nil, false.
// The wrapper doesn't have access to provider configuration.
func TestAuthContextWrapperResolveProviderConfig(t *testing.T) {
authContext := &schema.AuthContext{
AWS: &schema.AWSAuthContext{
Profile: "test-identity",
Region: "us-west-2",
},
}
wrapper := newAuthContextWrapper(authContext)
// ResolveProviderConfig should always return nil, false for the wrapper.
// It only propagates existing auth context, not provider configuration.
provider, found := wrapper.ResolveProviderConfig("any-identity")
assert.Nil(t, provider, "ResolveProviderConfig should return nil")
assert.False(t, found, "ResolveProviderConfig should return false")
provider, found = wrapper.ResolveProviderConfig("test-identity")
assert.Nil(t, provider, "ResolveProviderConfig should return nil for any identity")
assert.False(t, found, "ResolveProviderConfig should return false for any identity")
}