2121// and to an administrator, in the item, layered and list reads. The stored
2222// row is never touched.
2323// - CARRY-FORWARD: a save of the served form keeps the stored values; an
24- // author's own edit of a served URL is stored as the author wrote it; a
25- // `retryConfig` the author removes is removed with its stored keys.
24+ // author's own edit of a served URL is stored as the author wrote it. An
25+ // explicit `retryConfig` — `{}` or the served form — replaces the stored
26+ // one whole: a key it does not declare is gone from the next read of the
27+ // stored row, and the answer names it, while a withheld header map on the
28+ // same row is kept (CONTROL). A `retryConfig` the author leaves out is
29+ // removed with its stored keys, as before (CONTROL), and one stored as a
30+ // non-object is still kept at rest by a save that leaves it out (CONTROL).
2631//
2732// Every credential below is an obviously-fake placeholder, and every assertion
2833// on one is its absence from what a door served or stored, or its presence at
@@ -41,6 +46,7 @@ const PLACEHOLDERS = {
4146 urlToken : 'TEST_PLACEHOLDER_CUN_URL_TOKEN' ,
4247 urlQuery : 'TEST_PLACEHOLDER_CUN_URL_QUERY' ,
4348 nested : 'TEST_PLACEHOLDER_CUN_NESTED' ,
49+ header : 'TEST_PLACEHOLDER_CUN_HEADER' ,
4450 authEndpoint : 'TEST_PLACEHOLDER_CUN_AUTH_ENDPOINT' ,
4551 resolvedRef : 'TEST_PLACEHOLDER_CUN_RESOLVED_REFERENCE' ,
4652} as const ;
@@ -53,6 +59,9 @@ const DESCRIPTOR = 'cun_descriptor';
5359const EXISTING = 'cun_existing' ;
5460const OAUTH_ROW = 'cun_oauth_stored' ;
5561const RETRY_ROW = 'cun_retry_stored' ;
62+ const RETRY_EMPTY = 'cun_retry_empty' ;
63+ const RETRY_OMIT = 'cun_retry_omit' ;
64+ const RETRY_MALFORMED = 'cun_retry_malformed' ;
5665
5766const rowsOf = ( r : any ) : any [ ] => ( Array . isArray ( r ) ? r : Array . isArray ( r ?. records ) ? r . records : Array . isArray ( r ?. value ) ? r . value : [ ] ) ;
5867const bodyOf = ( row : any ) : Record < string , any > =>
@@ -184,10 +193,18 @@ describe('connector metadata doors: an authored connector keeps no credential in
184193 tokenUrl : `https://cun:${ PLACEHOLDERS . authEndpoint } @auth.vendor.example.com/token` ,
185194 authorizationUrl : `https://${ PLACEHOLDERS . authEndpoint } @auth.vendor.example.com/authorize?region=eu` ,
186195 } ) ) ;
196+ // Each also holds a withheld header map, carried forward: the control on the same save.
197+ for ( const name of [ RETRY_ROW , RETRY_EMPTY , RETRY_OMIT ] ) {
198+ await seedOver ( name , instance ( name , { retryConfig : { maxAttempts : 2 } } ) , instance ( name , {
199+ providerConfig : { baseUrl : `${ upstreamUrl } /v1` , defaultHeaders : { Authorization : `Bearer ${ PLACEHOLDERS . header } ` } } ,
200+ retryConfig : { maxAttempts : 2 , secret : PLACEHOLDERS . nested } ,
201+ } ) ) ;
202+ }
203+ // Saved disabled: the pin is the door's answer, not a materialization of a policy no parse accepts.
187204 await seedOver (
188- RETRY_ROW ,
189- instance ( RETRY_ROW , { retryConfig : { maxAttempts : 2 } } ) ,
190- instance ( RETRY_ROW , { retryConfig : { maxAttempts : 2 , secret : PLACEHOLDERS . nested } } ) ,
205+ RETRY_MALFORMED ,
206+ instance ( RETRY_MALFORMED , { enabled : false } ) ,
207+ instance ( RETRY_MALFORMED , { enabled : false , retryConfig : PLACEHOLDERS . nested } ) ,
191208 ) ;
192209 } , 180_000 ) ;
193210
@@ -345,17 +362,53 @@ describe('connector metadata doors: an authored connector keeps no credential in
345362 expect ( atRest . auth . authorizationUrl ) . toBe ( `https://${ PLACEHOLDERS . authEndpoint } @auth.vendor.example.com/authorize?region=eu` ) ;
346363 } ) ;
347364
348- it ( 'a stored undeclared `retryConfig` key: kept on a save of the served form, cleared when the author removes `retryConfig`' , async ( ) => {
349- const served = authorable ( ( await read ( admin , RETRY_ROW ) ) . item ) ;
365+ const HEADERS_AT_REST = ( ) => ( { Authorization : `Bearer ${ PLACEHOLDERS . header } ` } ) ;
366+
367+ it ( '`retryConfig: {}` replaces the stored one whole: the next read of the stored row no longer has the undeclared key' , async ( ) => {
368+ expect ( bodyOf ( ( await stored ( RETRY_EMPTY ) ) [ 0 ] ) . retryConfig , 'guard the guard: the seeded row holds the key' )
369+ . toEqual ( { maxAttempts : 2 , secret : PLACEHOLDERS . nested } ) ;
370+ const served = authorable ( ( await read ( admin , RETRY_EMPTY ) ) . item ) ;
350371 expect ( served . retryConfig ) . toEqual ( { maxAttempts : 2 } ) ;
351- const kept = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_ROW } ` , { ...served , label : 'CUN retry (edited)' } ) ;
352- expect ( kept . status , await kept . clone ( ) . text ( ) ) . toBe ( 200 ) ;
353- expect ( bodyOf ( ( await stored ( RETRY_ROW ) ) [ 0 ] ) . retryConfig ) . toEqual ( { maxAttempts : 2 , secret : PLACEHOLDERS . nested } ) ;
354-
355- const { retryConfig : _removed , ...withoutRetry } = served ;
356- const cleared = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_ROW } ` , withoutRetry ) ;
357- expect ( cleared . status , await cleared . clone ( ) . text ( ) ) . toBe ( 200 ) ;
358- expect ( bodyOf ( ( await stored ( RETRY_ROW ) ) [ 0 ] ) ) . not . toHaveProperty ( 'retryConfig' ) ;
372+ const res = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_EMPTY } ` , { ...served , retryConfig : { } } ) ;
373+ const text = await res . text ( ) ;
374+ expect ( res . status , text . slice ( 0 , 300 ) ) . toBe ( 200 ) ;
375+ expect ( JSON . parse ( text ) . data . advisories , 'the save names the key it did not carry forward' ) . toEqual ( [
376+ expect . objectContaining ( { rule : 'withheld-key-dropped' , severity : 'warning' , path : 'connectors[0].retryConfig.secret' } ) ,
377+ ] ) ;
378+ expect ( text . includes ( PLACEHOLDERS . nested ) , 'the answer names the key, never its value' ) . toBe ( false ) ;
379+ const atRest = bodyOf ( ( await stored ( RETRY_EMPTY ) ) [ 0 ] ) ;
380+ expect ( atRest . retryConfig ) . toEqual ( { } ) ;
381+ // CONTROL, the same save: a withheld position outside `retryConfig` is still carried forward.
382+ expect ( atRest . providerConfig . defaultHeaders ) . toEqual ( HEADERS_AT_REST ( ) ) ;
383+ } ) ;
384+
385+ it ( 'a save of the served form replaces the stored `retryConfig` whole too' , async ( ) => {
386+ const served = authorable ( ( await read ( admin , RETRY_ROW ) ) . item ) ;
387+ const res = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_ROW } ` , { ...served , label : 'CUN retry (edited)' } ) ;
388+ expect ( res . status , await res . clone ( ) . text ( ) ) . toBe ( 200 ) ;
389+ const atRest = bodyOf ( ( await stored ( RETRY_ROW ) ) [ 0 ] ) ;
390+ expect ( atRest . label ) . toBe ( 'CUN retry (edited)' ) ;
391+ expect ( atRest . retryConfig ) . toEqual ( { maxAttempts : 2 } ) ;
392+ expect ( atRest . providerConfig . defaultHeaders ) . toEqual ( HEADERS_AT_REST ( ) ) ;
393+ } ) ;
394+
395+ it ( 'CONTROL: a save that leaves `retryConfig` out removes it with its stored keys, as before' , async ( ) => {
396+ const { retryConfig : _removed , ...withoutRetry } = authorable ( ( await read ( admin , RETRY_OMIT ) ) . item ) ;
397+ const res = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_OMIT } ` , withoutRetry ) ;
398+ expect ( res . status , await res . clone ( ) . text ( ) ) . toBe ( 200 ) ;
399+ const atRest = bodyOf ( ( await stored ( RETRY_OMIT ) ) [ 0 ] ) ;
400+ expect ( atRest ) . not . toHaveProperty ( 'retryConfig' ) ;
401+ expect ( atRest . providerConfig . defaultHeaders ) . toEqual ( HEADERS_AT_REST ( ) ) ;
402+ } ) ;
403+
404+ it ( 'CONTROL: a `retryConfig` stored as a non-object is withheld whole and still carried forward by a save that leaves it out' , async ( ) => {
405+ const served = authorable ( ( await read ( admin , RETRY_MALFORMED ) ) . item ) ;
406+ expect ( served ) . not . toHaveProperty ( 'retryConfig' ) ;
407+ const res = await stack . apiAs ( admin , 'PUT' , `/meta/connector/${ RETRY_MALFORMED } ` , { ...served , label : 'CUN retry malformed (edited)' } ) ;
408+ expect ( res . status , await res . clone ( ) . text ( ) ) . toBe ( 200 ) ;
409+ const atRest = bodyOf ( ( await stored ( RETRY_MALFORMED ) ) [ 0 ] ) ;
410+ expect ( atRest . label ) . toBe ( 'CUN retry malformed (edited)' ) ;
411+ expect ( atRest . retryConfig ) . toBe ( PLACEHOLDERS . nested ) ;
359412 } ) ;
360413 } ) ;
361414} ) ;
0 commit comments