Skip to content

Commit f3ddba6

Browse files
fix: remove hallucinated auth_method field, use real API auth_type
Tests were asserting against destConfig["auth_method"] which is not a real API field. All assertions silently passed because they used if-ok guards — the field was never present, so the checks never ran. - Replace auth_method assertions with auth_type (the actual API field) - Fix upsert update path to clear stale auth_type before setting new one - Remove phantom auth_method delete in upsert config merge Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent 4ba1f0b commit f3ddba6

3 files changed

Lines changed: 20 additions & 30 deletions

File tree

pkg/cmd/connection_upsert.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,12 +599,24 @@ func (cu *connectionUpsertCmd) buildDestinationInputForUpdate(existingDest *hook
599599

600600
// Apply authentication config if provided
601601
if cu.DestinationAuthMethod != "" {
602+
// Clear any existing auth fields before setting new ones
603+
delete(destConfig, "auth_type")
604+
delete(destConfig, "auth")
605+
602606
authConfig, err := cu.buildAuthConfig()
603607
if err != nil {
604608
return nil, err
605609
}
606610
if len(authConfig) > 0 {
607-
destConfig["auth_method"] = authConfig
611+
// Use the correct API format: auth_type + auth as separate fields
612+
destConfig["auth_type"] = authConfig["type"]
613+
auth := make(map[string]interface{})
614+
for k, v := range authConfig {
615+
if k != "type" {
616+
auth[k] = v
617+
}
618+
}
619+
destConfig["auth"] = auth
608620
}
609621
}
610622

test/acceptance/connection_test.go

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
746746
destConfig, ok := dest["config"].(map[string]interface{})
747747
require.True(t, ok, "Expected destination config object")
748748

749-
if authMethod, ok := destConfig["auth_method"].(map[string]interface{}); ok {
750-
assert.Equal(t, "API_KEY", authMethod["type"], "Auth type should be API_KEY")
751-
assert.Equal(t, "X-API-Key", authMethod["key"], "Auth key should be X-API-Key")
752-
assert.Equal(t, "header", authMethod["to"], "Auth location should be header")
753-
// API key itself should not be returned for security
754-
}
749+
assert.Equal(t, "API_KEY", destConfig["auth_type"], "Auth type should be API_KEY")
755750

756751
// Cleanup
757752
t.Cleanup(func() {
@@ -804,11 +799,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
804799
destConfig, ok := dest["config"].(map[string]interface{})
805800
require.True(t, ok, "Expected destination config object")
806801

807-
if authMethod, ok := destConfig["auth_method"].(map[string]interface{}); ok {
808-
assert.Equal(t, "API_KEY", authMethod["type"], "Auth type should be API_KEY")
809-
assert.Equal(t, "api_key", authMethod["key"], "Auth key should be api_key")
810-
assert.Equal(t, "query", authMethod["to"], "Auth location should be query")
811-
}
802+
assert.Equal(t, "API_KEY", destConfig["auth_type"], "Auth type should be API_KEY")
812803

813804
// Cleanup
814805
t.Cleanup(func() {
@@ -859,11 +850,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
859850
destConfig, ok := dest["config"].(map[string]interface{})
860851
require.True(t, ok, "Expected destination config object")
861852

862-
if authMethod, ok := destConfig["auth_method"].(map[string]interface{}); ok {
863-
assert.Equal(t, "CUSTOM_SIGNATURE", authMethod["type"], "Auth type should be CUSTOM_SIGNATURE")
864-
assert.Equal(t, "X-Signature", authMethod["key"], "Auth key should be X-Signature")
865-
// Signing secret should not be returned for security
866-
}
853+
assert.Equal(t, "CUSTOM_SIGNATURE", destConfig["auth_type"], "Auth type should be CUSTOM_SIGNATURE")
867854

868855
// Cleanup
869856
t.Cleanup(func() {
@@ -913,9 +900,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
913900
require.True(t, ok, "Expected destination config object")
914901

915902
// Hookdeck signature should be set as the auth type
916-
if authMethod, ok := destConfig["auth_method"].(map[string]interface{}); ok {
917-
assert.Equal(t, "HOOKDECK_SIGNATURE", authMethod["type"], "Auth type should be HOOKDECK_SIGNATURE")
918-
}
903+
assert.Equal(t, "HOOKDECK_SIGNATURE", destConfig["auth_type"], "Auth type should be HOOKDECK_SIGNATURE")
919904

920905
// Cleanup
921906
t.Cleanup(func() {
@@ -983,10 +968,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
983968
updateDestConfig, ok := updateDest["config"].(map[string]interface{})
984969
require.True(t, ok, "Expected destination config object in update response")
985970

986-
if authMethod, ok := updateDestConfig["auth_method"].(map[string]interface{}); ok {
987-
assert.Equal(t, "API_KEY", authMethod["type"], "Auth type should be updated to API_KEY")
988-
assert.Equal(t, "X-API-Key", authMethod["key"], "Auth key should be X-API-Key")
989-
}
971+
assert.Equal(t, "API_KEY", updateDestConfig["auth_type"], "Auth type should be updated to API_KEY")
990972

991973
// Update to Hookdeck signature (reset to default)
992974
stdout, stderr, err = cli.Run("connection", "upsert", connName,
@@ -1007,9 +989,7 @@ func TestConnectionAuthenticationTypes(t *testing.T) {
1007989
resetDestConfig, ok := resetDest["config"].(map[string]interface{})
1008990
require.True(t, ok, "Expected destination config object in reset response")
1009991

1010-
if authMethod, ok := resetDestConfig["auth_method"].(map[string]interface{}); ok {
1011-
assert.Equal(t, "HOOKDECK_SIGNATURE", authMethod["type"], "Auth type should be reset to HOOKDECK_SIGNATURE")
1012-
}
992+
assert.Equal(t, "HOOKDECK_SIGNATURE", resetDestConfig["auth_type"], "Auth type should be reset to HOOKDECK_SIGNATURE")
1013993

1014994
t.Logf("Successfully tested changing authentication methods via upsert: %s", connID)
1015995
})

test/acceptance/connection_upsert_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,7 @@ func TestConnectionUpsertPartialUpdates(t *testing.T) {
181181
updatedDestConfig, ok := updatedDest["config"].(map[string]interface{})
182182
require.True(t, ok, "Expected destination config")
183183

184-
if authMethod, ok := updatedDestConfig["auth_method"].(map[string]interface{}); ok {
185-
assert.Equal(t, "BEARER", authMethod["type"], "Auth type should be BEARER")
186-
}
184+
assert.Equal(t, "BEARER_TOKEN", updatedDestConfig["auth_type"], "Auth type should be BEARER_TOKEN")
187185

188186
t.Logf("Successfully updated connection %s auth method to bearer", connID)
189187
})

0 commit comments

Comments
 (0)