Skip to content

Commit 322b5cf

Browse files
committed
fix: Comprehensive field compatibility fixes for Commander API
Field Type Definition Updates: - Update field-types.json with missing elements for complex fields - Fix phone field: add elements [region, number, ext, type] - Fix name field: change elements from [firstName, lastName, fullName] to [first, middle, last] - Fix bankAccount field: add missing otherType element - Fix privateKey field: add elements [publicKey, privateKey] - Fix schedule field: add elements [type, time, month] - Add missing appFiller field type with elements [applicationTitle, contentFilter, macroSequence] - Add missing pamResources field type with elements [controllerUid, folderUid, resourceRef] - Update complex field processing logic to handle new field definitions Field Value Formatting Fixes: - Add automatic field validation and formatting in processFieldsForSDK() - Fix date fields: auto-convert Unix seconds to milliseconds - Fix card numbers: remove dashes, spaces, and dots from card numbers - Fix expiration dates: convert MM/YY to MM/YYYY format with smart year detection - Provide user warnings when field values are automatically reformatted Testing & Infrastructure: - Add GetFieldType() helper function for testing field type definitions - Add comprehensive field loading tests in loader_test.go - Add field processing tests for new complex field types (appFiller, schedule) - Add field formatting tests with 25+ test cases covering edge cases - Add field reconstruction tests for complex field processing pipeline Resolves issues with: - Field type mismatches between MCP and Commander API expectations - Date fields sending Unix timestamps in wrong format - Card numbers being created with dashes causing display issues - Expiration dates using MM/YY when Vault expects MM/YYYY - Missing field type definitions causing processing failures All changes ensure full compatibility with Commander API field requirements and provide comprehensive test coverage for field processing pipeline.
1 parent cac3629 commit 322b5cf

File tree

6 files changed

+982
-41
lines changed

6 files changed

+982
-41
lines changed

internal/ksm/complex_fields_test.go

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,3 +1064,183 @@ func TestIsSensitiveFieldComprehensive(t *testing.T) {
10641064
})
10651065
}
10661066
}
1067+
1068+
func TestProcessAppFillerField(t *testing.T) {
1069+
client := &Client{}
1070+
1071+
tests := []struct {
1072+
name string
1073+
value interface{}
1074+
unmask bool
1075+
expected interface{}
1076+
found bool
1077+
}{
1078+
{
1079+
name: "app filler - masked",
1080+
value: []interface{}{
1081+
map[string]interface{}{
1082+
"applicationTitle": "Banking App",
1083+
"contentFilter": "input[type=password]",
1084+
"macroSequence": "username{TAB}password{ENTER}",
1085+
},
1086+
},
1087+
unmask: false,
1088+
expected: []map[string]interface{}{
1089+
{
1090+
"applicationTitle": "Banking App",
1091+
"contentFilter": "input[type=password]",
1092+
"macroSequence": "use***ER}",
1093+
},
1094+
},
1095+
found: true,
1096+
},
1097+
{
1098+
name: "app filler - unmasked",
1099+
value: []interface{}{
1100+
map[string]interface{}{
1101+
"applicationTitle": "Shopping Site",
1102+
"contentFilter": ".login-form",
1103+
"macroSequence": "[email protected]{TAB}SecurePass123{ENTER}",
1104+
},
1105+
},
1106+
unmask: true,
1107+
expected: []map[string]interface{}{
1108+
{
1109+
"applicationTitle": "Shopping Site",
1110+
"contentFilter": ".login-form",
1111+
"macroSequence": "[email protected]{TAB}SecurePass123{ENTER}",
1112+
},
1113+
},
1114+
found: true,
1115+
},
1116+
{
1117+
name: "minimal app filler",
1118+
value: []interface{}{
1119+
map[string]interface{}{
1120+
"applicationTitle": "Simple App",
1121+
},
1122+
},
1123+
unmask: false,
1124+
expected: []map[string]interface{}{
1125+
{
1126+
"applicationTitle": "Simple App",
1127+
},
1128+
},
1129+
found: true,
1130+
},
1131+
{
1132+
name: "empty value",
1133+
value: []interface{}{},
1134+
unmask: false,
1135+
expected: nil,
1136+
found: false,
1137+
},
1138+
}
1139+
1140+
for _, tt := range tests {
1141+
t.Run(tt.name, func(t *testing.T) {
1142+
result, found := client.processAppFillerField(tt.value, tt.unmask)
1143+
assert.Equal(t, tt.found, found, "Found status should match")
1144+
if tt.found {
1145+
assert.Equal(t, tt.expected, result, "App filler data should match")
1146+
}
1147+
})
1148+
}
1149+
}
1150+
1151+
func TestProcessScheduleField(t *testing.T) {
1152+
client := &Client{}
1153+
1154+
tests := []struct {
1155+
name string
1156+
value interface{}
1157+
unmask bool
1158+
expected interface{}
1159+
found bool
1160+
}{
1161+
{
1162+
name: "complete schedule",
1163+
value: []interface{}{
1164+
map[string]interface{}{
1165+
"type": "Monthly",
1166+
"time": "14:30",
1167+
"cron": "0 14 1 * *",
1168+
"tz": "America/New_York",
1169+
"weekday": "1",
1170+
"intervalCount": float64(1),
1171+
},
1172+
},
1173+
unmask: false,
1174+
expected: []map[string]interface{}{
1175+
{
1176+
"type": "Monthly",
1177+
"time": "14:30",
1178+
"cron": "0 14 1 * *",
1179+
"tz": "America/New_York",
1180+
"weekday": "1",
1181+
"intervalCount": float64(1),
1182+
},
1183+
},
1184+
found: true,
1185+
},
1186+
{
1187+
name: "weekly schedule",
1188+
value: []interface{}{
1189+
map[string]interface{}{
1190+
"type": "Weekly",
1191+
"time": "09:00",
1192+
},
1193+
},
1194+
unmask: false,
1195+
expected: []map[string]interface{}{
1196+
{
1197+
"type": "Weekly",
1198+
"time": "09:00",
1199+
},
1200+
},
1201+
found: true,
1202+
},
1203+
{
1204+
name: "multiple schedules",
1205+
value: []interface{}{
1206+
map[string]interface{}{
1207+
"type": "Daily",
1208+
"time": "06:00",
1209+
},
1210+
map[string]interface{}{
1211+
"type": "Weekly",
1212+
"time": "12:00",
1213+
},
1214+
},
1215+
unmask: false,
1216+
expected: []map[string]interface{}{
1217+
{
1218+
"type": "Daily",
1219+
"time": "06:00",
1220+
},
1221+
{
1222+
"type": "Weekly",
1223+
"time": "12:00",
1224+
},
1225+
},
1226+
found: true,
1227+
},
1228+
{
1229+
name: "empty value",
1230+
value: []interface{}{},
1231+
unmask: false,
1232+
expected: nil,
1233+
found: false,
1234+
},
1235+
}
1236+
1237+
for _, tt := range tests {
1238+
t.Run(tt.name, func(t *testing.T) {
1239+
result, found := client.processScheduleField(tt.value, tt.unmask)
1240+
assert.Equal(t, tt.found, found, "Found status should match")
1241+
if tt.found {
1242+
assert.Equal(t, tt.expected, result, "Schedule data should match")
1243+
}
1244+
})
1245+
}
1246+
}

0 commit comments

Comments
 (0)