@@ -53,12 +53,34 @@ func TestConnectionOAuth2AWSAuthentication(t *testing.T) {
5353 destConfig , ok := dest ["config" ].(map [string ]interface {})
5454 require .True (t , ok , "Expected destination config object" )
5555
56- if authMethod , ok := destConfig ["auth_method" ].(map [string ]interface {}); ok {
57- assert .Equal (t , "OAUTH2_CLIENT_CREDENTIALS" , authMethod ["type" ], "Auth type should be OAUTH2_CLIENT_CREDENTIALS" )
58- assert .Equal (t , "https://auth.example.com/oauth/token" , authMethod ["auth_server" ], "Auth server should match" )
59- assert .Equal (t , "client_123" , authMethod ["client_id" ], "Client ID should match" )
60- // Client secret and scopes may or may not be returned depending on API
61- }
56+ authType , ok := destConfig ["auth_type" ].(string )
57+ require .True (t , ok , "Expected auth_type string in destination config, got config: %v" , destConfig )
58+ assert .Equal (t , "OAUTH2_CLIENT_CREDENTIALS" , authType , "Auth type should be OAUTH2_CLIENT_CREDENTIALS" )
59+
60+ // Fetch connection with --include-destination-auth to verify credentials were stored
61+ getStdout , getStderr , getErr := cli .Run ("connection" , "get" , connID ,
62+ "--include-destination-auth" ,
63+ "--output" , "json" )
64+ require .NoError (t , getErr , "Failed to get connection: stderr=%s" , getStderr )
65+
66+ var getResp map [string ]interface {}
67+ err = json .Unmarshal ([]byte (getStdout ), & getResp )
68+ require .NoError (t , err , "Failed to parse get response: %s" , getStdout )
69+
70+ getDest , ok := getResp ["destination" ].(map [string ]interface {})
71+ require .True (t , ok , "Expected destination in get response" )
72+ getConfig , ok := getDest ["config" ].(map [string ]interface {})
73+ require .True (t , ok , "Expected config in get response destination" )
74+
75+ getAuthType , ok := getConfig ["auth_type" ].(string )
76+ require .True (t , ok , "Expected auth_type in get response config: %v" , getConfig )
77+ assert .Equal (t , "OAUTH2_CLIENT_CREDENTIALS" , getAuthType , "Auth type should match on get" )
78+
79+ getAuth , ok := getConfig ["auth" ].(map [string ]interface {})
80+ require .True (t , ok , "Expected auth object in get response config: %v" , getConfig )
81+ assert .Equal (t , "https://auth.example.com/oauth/token" , getAuth ["auth_server" ], "Auth server should match" )
82+ assert .Equal (t , "client_123" , getAuth ["client_id" ], "Client ID should match" )
83+ assert .Equal (t , "secret_456" , getAuth ["client_secret" ], "Client secret should match with --include-destination-auth" )
6284
6385 // Cleanup
6486 t .Cleanup (func () {
@@ -112,12 +134,34 @@ func TestConnectionOAuth2AWSAuthentication(t *testing.T) {
112134 destConfig , ok := dest ["config" ].(map [string ]interface {})
113135 require .True (t , ok , "Expected destination config object" )
114136
115- if authMethod , ok := destConfig ["auth_method" ].(map [string ]interface {}); ok {
116- assert .Equal (t , "OAUTH2_AUTHORIZATION_CODE" , authMethod ["type" ], "Auth type should be OAUTH2_AUTHORIZATION_CODE" )
117- assert .Equal (t , "https://auth.example.com/oauth/token" , authMethod ["auth_server" ], "Auth server should match" )
118- assert .Equal (t , "client_789" , authMethod ["client_id" ], "Client ID should match" )
119- // Sensitive fields like client_secret, refresh_token may not be returned
120- }
137+ authType , ok := destConfig ["auth_type" ].(string )
138+ require .True (t , ok , "Expected auth_type string in destination config, got config: %v" , destConfig )
139+ assert .Equal (t , "OAUTH2_AUTHORIZATION_CODE" , authType , "Auth type should be OAUTH2_AUTHORIZATION_CODE" )
140+
141+ // Fetch connection with --include-destination-auth to verify credentials were stored
142+ getStdout , getStderr , getErr := cli .Run ("connection" , "get" , connID ,
143+ "--include-destination-auth" ,
144+ "--output" , "json" )
145+ require .NoError (t , getErr , "Failed to get connection: stderr=%s" , getStderr )
146+
147+ var getResp map [string ]interface {}
148+ err = json .Unmarshal ([]byte (getStdout ), & getResp )
149+ require .NoError (t , err , "Failed to parse get response: %s" , getStdout )
150+
151+ getDest , ok := getResp ["destination" ].(map [string ]interface {})
152+ require .True (t , ok , "Expected destination in get response" )
153+ getConfig , ok := getDest ["config" ].(map [string ]interface {})
154+ require .True (t , ok , "Expected config in get response destination" )
155+
156+ getAuthType , ok := getConfig ["auth_type" ].(string )
157+ require .True (t , ok , "Expected auth_type in get response config: %v" , getConfig )
158+ assert .Equal (t , "OAUTH2_AUTHORIZATION_CODE" , getAuthType , "Auth type should match on get" )
159+
160+ getAuth , ok := getConfig ["auth" ].(map [string ]interface {})
161+ require .True (t , ok , "Expected auth object in get response config: %v" , getConfig )
162+ assert .Equal (t , "https://auth.example.com/oauth/token" , getAuth ["auth_server" ], "Auth server should match" )
163+ assert .Equal (t , "client_789" , getAuth ["client_id" ], "Client ID should match" )
164+ assert .Equal (t , "secret_abc" , getAuth ["client_secret" ], "Client secret should match with --include-destination-auth" )
121165
122166 // Cleanup
123167 t .Cleanup (func () {
@@ -170,12 +214,35 @@ func TestConnectionOAuth2AWSAuthentication(t *testing.T) {
170214 destConfig , ok := dest ["config" ].(map [string ]interface {})
171215 require .True (t , ok , "Expected destination config object" )
172216
173- if authMethod , ok := destConfig ["auth_method" ].(map [string ]interface {}); ok {
174- assert .Equal (t , "AWS_SIGNATURE" , authMethod ["type" ], "Auth type should be AWS_SIGNATURE" )
175- assert .Equal (t , "us-east-1" , authMethod ["region" ], "AWS region should match" )
176- assert .Equal (t , "execute-api" , authMethod ["service" ], "AWS service should match" )
177- // Access key may be returned but secret key should not be for security
178- }
217+ authType , ok := destConfig ["auth_type" ].(string )
218+ require .True (t , ok , "Expected auth_type string in destination config, got config: %v" , destConfig )
219+ assert .Equal (t , "AWS_SIGNATURE" , authType , "Auth type should be AWS_SIGNATURE" )
220+
221+ // Fetch connection with --include-destination-auth to verify credentials were stored
222+ getStdout , getStderr , getErr := cli .Run ("connection" , "get" , connID ,
223+ "--include-destination-auth" ,
224+ "--output" , "json" )
225+ require .NoError (t , getErr , "Failed to get connection: stderr=%s" , getStderr )
226+
227+ var getResp map [string ]interface {}
228+ err = json .Unmarshal ([]byte (getStdout ), & getResp )
229+ require .NoError (t , err , "Failed to parse get response: %s" , getStdout )
230+
231+ getDest , ok := getResp ["destination" ].(map [string ]interface {})
232+ require .True (t , ok , "Expected destination in get response" )
233+ getConfig , ok := getDest ["config" ].(map [string ]interface {})
234+ require .True (t , ok , "Expected config in get response destination" )
235+
236+ getAuthType , ok := getConfig ["auth_type" ].(string )
237+ require .True (t , ok , "Expected auth_type in get response config: %v" , getConfig )
238+ assert .Equal (t , "AWS_SIGNATURE" , getAuthType , "Auth type should match on get" )
239+
240+ getAuth , ok := getConfig ["auth" ].(map [string ]interface {})
241+ require .True (t , ok , "Expected auth object in get response config: %v" , getConfig )
242+ assert .Equal (t , "AKIAIOSFODNN7EXAMPLE" , getAuth ["access_key_id" ], "AWS access key ID should match" )
243+ assert .Equal (t , "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" , getAuth ["secret_access_key" ], "AWS secret access key should match" )
244+ assert .Equal (t , "us-east-1" , getAuth ["region" ], "AWS region should match" )
245+ assert .Equal (t , "execute-api" , getAuth ["service" ], "AWS service should match" )
179246
180247 // Cleanup
181248 t .Cleanup (func () {
@@ -229,11 +296,33 @@ func TestConnectionOAuth2AWSAuthentication(t *testing.T) {
229296 destConfig , ok := dest ["config" ].(map [string ]interface {})
230297 require .True (t , ok , "Expected destination config object" )
231298
232- if authMethod , ok := destConfig ["auth_method" ].(map [string ]interface {}); ok {
233- assert .Equal (t , "GCP_SERVICE_ACCOUNT" , authMethod ["type" ], "Auth type should be GCP_SERVICE_ACCOUNT" )
234- assert .Equal (t , "https://www.googleapis.com/auth/cloud-platform" , authMethod ["scope" ], "GCP scope should match" )
235- // Service account key should not be returned for security reasons
236- }
299+ authType , ok := destConfig ["auth_type" ].(string )
300+ require .True (t , ok , "Expected auth_type string in destination config, got config: %v" , destConfig )
301+ assert .Equal (t , "GCP_SERVICE_ACCOUNT" , authType , "Auth type should be GCP_SERVICE_ACCOUNT" )
302+
303+ // Fetch connection with --include-destination-auth to verify credentials were stored
304+ getStdout , getStderr , getErr := cli .Run ("connection" , "get" , connID ,
305+ "--include-destination-auth" ,
306+ "--output" , "json" )
307+ require .NoError (t , getErr , "Failed to get connection: stderr=%s" , getStderr )
308+
309+ var getResp map [string ]interface {}
310+ err = json .Unmarshal ([]byte (getStdout ), & getResp )
311+ require .NoError (t , err , "Failed to parse get response: %s" , getStdout )
312+
313+ getDest , ok := getResp ["destination" ].(map [string ]interface {})
314+ require .True (t , ok , "Expected destination in get response" )
315+ getConfig , ok := getDest ["config" ].(map [string ]interface {})
316+ require .True (t , ok , "Expected config in get response destination" )
317+
318+ getAuthType , ok := getConfig ["auth_type" ].(string )
319+ require .True (t , ok , "Expected auth_type in get response config: %v" , getConfig )
320+ assert .Equal (t , "GCP_SERVICE_ACCOUNT" , getAuthType , "Auth type should match on get" )
321+
322+ getAuth , ok := getConfig ["auth" ].(map [string ]interface {})
323+ require .True (t , ok , "Expected auth object in get response config: %v" , getConfig )
324+ assert .Equal (t , "https://www.googleapis.com/auth/cloud-platform" , getAuth ["scope" ], "GCP scope should match" )
325+ assert .NotEmpty (t , getAuth ["service_account_key" ], "Service account key should be present with --include-destination-auth" )
237326
238327 // Cleanup
239328 t .Cleanup (func () {
0 commit comments