@@ -1370,3 +1370,144 @@ describe('#20611 — the runtime authoring gate reads a withheld-and-stored secr
13701370 expect ( redactedPathsCarriedForward ( 'view' , { name : 'v' } , { name : 'v' , secret : 'x' } ) ) . toEqual ( [ ] ) ;
13711371 } ) ;
13721372} ) ;
1373+
1374+ // ---------------------------------------------------------------------------
1375+ // The `connector` read: a top-level key the authored entry does not declare
1376+ // ---------------------------------------------------------------------------
1377+ //
1378+ // A row stored while the connector entry was open can hold a top-level key the
1379+ // entry does not declare. Seeded directly, never through `saveMetaItem`: the
1380+ // save door now refuses such a key, so only a direct seed reproduces the row.
1381+
1382+ const ROOT_KEY_VALUE = 'TEST_PLACEHOLDER_ROOT_KEY_VALUE' ;
1383+ const ROOT_PLAIN_VALUE = 'TEST_PLACEHOLDER_ROOT_PLAIN_VALUE' ;
1384+
1385+ function storedConnectorBody ( ) {
1386+ return {
1387+ name : 'vendor_api' ,
1388+ label : 'Vendor API' ,
1389+ type : 'api' ,
1390+ provider : 'rest' ,
1391+ providerConfig : { baseUrl : 'https://api.vendor.example/v1' } ,
1392+ auth : { type : 'bearer' , credentialRef : 'VENDOR_API_TOKEN' } ,
1393+ apiKey : ROOT_KEY_VALUE ,
1394+ region : ROOT_PLAIN_VALUE ,
1395+ } ;
1396+ }
1397+
1398+ function seedConnectorRow ( rows : Map < string , Row > ) {
1399+ const where = { type : 'connector' , name : 'vendor_api' , organization_id : null , package_id : null , state : 'active' } ;
1400+ const body = storedConnectorBody ( ) ;
1401+ rows . set ( keyOf ( where ) , {
1402+ id : 'r_connector' ,
1403+ ...where ,
1404+ metadata : JSON . stringify ( body ) ,
1405+ checksum : hashSpec ( body ) ,
1406+ version : 1 ,
1407+ } as Row ) ;
1408+ }
1409+
1410+ const storedConnector = ( rows : Map < string , Row > ) =>
1411+ JSON . parse ( Array . from ( rows . values ( ) ) . find ( ( r ) => r . type === 'connector' && r . state === 'active' ) ! . metadata ) ;
1412+
1413+ function expectRootKeysWithheld ( served : any ) {
1414+ expect ( served ) . not . toHaveProperty ( 'apiKey' ) ;
1415+ expect ( served ) . not . toHaveProperty ( 'region' ) ;
1416+ expect ( served . name ) . toBe ( 'vendor_api' ) ;
1417+ expect ( served . providerConfig ) . toEqual ( { baseUrl : 'https://api.vendor.example/v1' } ) ;
1418+ }
1419+
1420+ function expectNoRootKeyValue ( payload : unknown ) {
1421+ const strings = allStrings ( payload ) ;
1422+ expect ( strings . some ( ( s ) => s . includes ( ROOT_KEY_VALUE ) || s . includes ( ROOT_PLAIN_VALUE ) ) ) . toBe ( false ) ;
1423+ }
1424+
1425+ const BUILTIN_CONNECTOR_REDACTOR = getMetadataTypeRedactor ( 'connector' ) ! ;
1426+
1427+ describe ( 'the connector read withholds root keys the entry shape does not declare' , ( ) => {
1428+ afterEach ( ( ) => registerMetadataTypeRedactor ( 'connector' , BUILTIN_CONNECTOR_REDACTOR ) ) ;
1429+
1430+ it ( 'withholds undeclared root keys on read: the item read' , async ( ) => {
1431+ const { engine, rows } = makeStubEngine ( ) ;
1432+ seedConnectorRow ( rows ) ;
1433+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1434+
1435+ const res : any = await protocol . getMetaItem ( { type : 'connector' , name : 'vendor_api' } ) ;
1436+ expectRootKeysWithheld ( res . item ) ;
1437+ expectNoRootKeyValue ( res ) ;
1438+ // The badge is computed on the raw body: the row is still reported invalid.
1439+ expect ( res . item . _diagnostics . valid ) . toBe ( false ) ;
1440+ expect ( storedConnector ( rows ) . apiKey ) . toBe ( ROOT_KEY_VALUE ) ;
1441+ } ) ;
1442+
1443+ it ( 'withholds undeclared root keys on read: the list read, both spellings' , async ( ) => {
1444+ const { engine, rows } = makeStubEngine ( ) ;
1445+ seedConnectorRow ( rows ) ;
1446+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1447+
1448+ for ( const type of [ 'connector' , 'connectors' ] ) {
1449+ const res : any = await protocol . getMetaItems ( { type } ) ;
1450+ const item = res . items . find ( ( i : any ) => i . name === 'vendor_api' ) ;
1451+ expect ( item , type ) . toBeDefined ( ) ;
1452+ expectRootKeysWithheld ( item ) ;
1453+ expectNoRootKeyValue ( res ) ;
1454+ }
1455+ } ) ;
1456+
1457+ it ( 'withholds undeclared root keys on read: the layered read' , async ( ) => {
1458+ const { engine, rows } = makeStubEngine ( ) ;
1459+ seedConnectorRow ( rows ) ;
1460+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1461+
1462+ const res : any = await protocol . getMetaItemLayered ( { type : 'connector' , name : 'vendor_api' } ) ;
1463+ expect ( res . overlay ) . not . toBeNull ( ) ;
1464+ expectRootKeysWithheld ( res . overlay ) ;
1465+ expectRootKeysWithheld ( res . effective ) ;
1466+ expectNoRootKeyValue ( res ) ;
1467+ } ) ;
1468+
1469+ it ( 'a save of the served form keeps the withheld keys at rest' , async ( ) => {
1470+ const { engine, rows } = makeStubEngine ( ) ;
1471+ seedConnectorRow ( rows ) ;
1472+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1473+
1474+ const served : any = ( await protocol . getMetaItem ( { type : 'connector' , name : 'vendor_api' } ) ) . item ;
1475+ await protocol . saveMetaItem ( {
1476+ type : 'connector' ,
1477+ name : 'vendor_api' ,
1478+ item : { ...served , label : 'Vendor API (edited)' } ,
1479+ } ) ;
1480+
1481+ const atRest = storedConnector ( rows ) ;
1482+ expect ( atRest . label ) . toBe ( 'Vendor API (edited)' ) ;
1483+ expect ( atRest . apiKey ) . toBe ( ROOT_KEY_VALUE ) ;
1484+ expect ( atRest . region ) . toBe ( ROOT_PLAIN_VALUE ) ;
1485+ const reread : any = await protocol . getMetaItem ( { type : 'connector' , name : 'vendor_api' } ) ;
1486+ expectRootKeysWithheld ( reread . item ) ;
1487+ } ) ;
1488+
1489+ it ( 'an undeclared root key the author types is refused, and the row is unchanged' , async ( ) => {
1490+ const { engine, rows } = makeStubEngine ( ) ;
1491+ seedConnectorRow ( rows ) ;
1492+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1493+
1494+ const served : any = ( await protocol . getMetaItem ( { type : 'connector' , name : 'vendor_api' } ) ) . item ;
1495+ await expect ( protocol . saveMetaItem ( {
1496+ type : 'connector' ,
1497+ name : 'vendor_api' ,
1498+ item : { ...served , apiKey : 'typed-by-hand' } ,
1499+ } ) ) . rejects . toMatchObject ( { code : 'INVALID_METADATA' , status : 422 } ) ;
1500+ expect ( storedConnector ( rows ) ) . toEqual ( storedConnectorBody ( ) ) ;
1501+ } ) ;
1502+
1503+ it ( 'ABLATION — with an identity `connector` redactor the item, list and layered reads carry the keys again' , async ( ) => {
1504+ registerMetadataTypeRedactor ( 'connector' , ( item ) => ( { item, redactedKeys : [ ] } ) ) ;
1505+ const { engine, rows } = makeStubEngine ( ) ;
1506+ seedConnectorRow ( rows ) ;
1507+ const protocol = new ObjectStackProtocolImplementation ( engine ) ;
1508+
1509+ expect ( ( ( await protocol . getMetaItem ( { type : 'connector' , name : 'vendor_api' } ) ) as any ) . item . apiKey ) . toBe ( ROOT_KEY_VALUE ) ;
1510+ expect ( ( ( await protocol . getMetaItems ( { type : 'connector' } ) ) as any ) . items [ 0 ] . apiKey ) . toBe ( ROOT_KEY_VALUE ) ;
1511+ expect ( ( ( await protocol . getMetaItemLayered ( { type : 'connector' , name : 'vendor_api' } ) ) as any ) . effective . apiKey ) . toBe ( ROOT_KEY_VALUE ) ;
1512+ } ) ;
1513+ } ) ;
0 commit comments