@@ -12,6 +12,7 @@ import {
1212 FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE ,
1313 FLOW_TRIGGER_UNROUTABLE ,
1414 FLOW_API_TRIGGER_SECRET_MISSING ,
15+ FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ,
1516 validateFlowApiTriggerSecret as validateFlowApiTriggerSecretUnrecorded ,
1617 schemaRefusalHead ,
1718} from './validate-flow-trigger-readiness.js' ;
@@ -30,6 +31,7 @@ const NEVER_FIRE_IDS: readonly string[] = [
3031 FLOW_TIME_RELATIVE_DESCRIPTOR_UNROUTABLE ,
3132 FLOW_TRIGGER_UNROUTABLE ,
3233 FLOW_API_TRIGGER_SECRET_MISSING ,
34+ FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ,
3335 FLOW_TRIGGER_UNKNOWN_EVENT ,
3436] ;
3537const fired : Array < { rule : string ; message : string ; hint : string } > = [ ] ;
@@ -1521,6 +1523,31 @@ describe('validateFlowTriggerReadiness', () => {
15211523 ] ,
15221524 } ,
15231525 ] ,
1526+ // [#30009] A declared sender scheme the spec refuses: never-fire, like a missing secret.
1527+ [
1528+ FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ,
1529+ 'error' ,
1530+ {
1531+ objects : [ candidateObject ] ,
1532+ flows : [
1533+ {
1534+ name : 'broken_vendor_hook' ,
1535+ type : 'api' ,
1536+ status : 'active' ,
1537+ nodes : [
1538+ {
1539+ id : 'start' ,
1540+ type : 'start' ,
1541+ config : {
1542+ secretRef : 'DOCUSIGN_CONNECT_KEY' ,
1543+ signature : { signs : 'body' , header : 'X-DocuSign-Signature-1' , algorithm : 'hmac-sha1' , encoding : 'base64' } ,
1544+ } ,
1545+ } ,
1546+ ] ,
1547+ } ,
1548+ ] ,
1549+ } ,
1550+ ] ,
15241551 // ── The controls. Both are hedged, and the hedge is the whole reason the
15251552 // promotion above is not "everything in this file is an error now".
15261553 [
@@ -1753,6 +1780,89 @@ describe('validateFlowTriggerReadiness', () => {
17531780 } ) ;
17541781} ) ;
17551782
1783+ // [#30009] A start node that declares its sender's own scheme (`config.signature`)
1784+ // is graded by the hook's ONE verifier, read through the spec's
1785+ // `apiTriggerVerifierOf` (the reader the engine and the trigger share): ready on
1786+ // the key `config.secretRef` names and nothing else, and never ready when the
1787+ // reader answers `unusable`.
1788+ describe ( '[#30009] api trigger readiness reads the hook\'s one verifier (config.signature)' , ( ) => {
1789+ const DOCUSIGN = { signs : 'body' , header : 'X-DocuSign-Signature-1' , algorithm : 'hmac-sha256' , encoding : 'base64' } ;
1790+ const STRIPE = {
1791+ signs : 'timestamp.body' , header : 'Stripe-Signature' , algorithm : 'hmac-sha256' , encoding : 'hex' ,
1792+ timestampElement : 't' , digestElement : 'v1' ,
1793+ } ;
1794+ const vendorFlow = ( config : Record < string , unknown > , type = 'api' ) => ( {
1795+ name : 'vendor_hook' ,
1796+ label : 'Vendor hook' ,
1797+ type,
1798+ status : 'active' ,
1799+ nodes : [
1800+ { id : 'start' , type : 'start' , label : 'Start' , config } ,
1801+ { id : 'end' , type : 'end' , label : 'End' } ,
1802+ ] ,
1803+ edges : [ { id : 'e1' , source : 'start' , target : 'end' } ] ,
1804+ } ) ;
1805+ const judge = ( flow : Record < string , unknown > ) => cliFlowFamily ( { objects : [ candidateObject ] , flows : [ flow ] } ) ;
1806+ const rules = ( flow : Record < string , unknown > ) => judge ( flow ) . map ( ( f ) => [ f . rule , f . severity , f . path ] ) ;
1807+
1808+ it ( 'a usable declaration keyed by secretRef is ready, on both arms, at the CLI and the runtime publish gate' , ( ) => {
1809+ for ( const signature of [ DOCUSIGN , STRIPE , { ...DOCUSIGN , encoding : 'hex' , prefix : 'sha256=' } ] ) {
1810+ const flow = vendorFlow ( { hookId : 'vendor' , secretRef : 'VENDOR_WEBHOOK_KEY' , signature } ) ;
1811+ expect ( judge ( flow ) , JSON . stringify ( signature ) ) . toEqual ( [ ] ) ;
1812+ expect ( runRuntimeAuthoringRules ( { type : 'flow' , item : flow } ) . errors , JSON . stringify ( signature ) ) . toEqual ( [ ] ) ;
1813+ }
1814+ } ) ;
1815+
1816+ it ( 'an unusable declaration is never ready: one error, at the key the spec refuses' , ( ) => {
1817+ const cases : Array < [ string , Record < string , unknown > , string ] > = [
1818+ [ 'an algorithm the spec refuses' , { secretRef : 'K' , signature : { ...DOCUSIGN , algorithm : 'hmac-sha1' } } , 'config.signature.algorithm' ] ,
1819+ [ 'a reserved header' , { secretRef : 'K' , signature : { ...DOCUSIGN , header : 'x-objectstack-signature' } } , 'config.signature.header' ] ,
1820+ [ 'a timestamped scheme with no timestamp element' , { secretRef : 'K' , signature : { ...STRIPE , timestampElement : undefined } } , 'config.signature.timestampElement' ] ,
1821+ [ 'no key reference' , { signature : DOCUSIGN } , 'config.signature' ] ,
1822+ [ 'a literal secret beside it (an inline key)' , { secret : 'whsec_inline' , signature : DOCUSIGN } , 'config.signature' ] ,
1823+ [ 'a literal secret AND a secretRef beside it' , { secret : 'whsec_inline' , secretRef : 'K' , signature : DOCUSIGN } , 'config.signature' ] ,
1824+ [ 'a secretRef that is not a usable name' , { secretRef : 'OS_AUTH_SECRET' , signature : DOCUSIGN } , 'config.secretRef' ] ,
1825+ ] ;
1826+ for ( const [ label , config , keyPath ] of cases ) {
1827+ const findings = judge ( vendorFlow ( config ) ) . filter ( ( f ) => f . rule === FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ) ;
1828+ expect ( findings . map ( ( f ) => [ f . severity , f . path ] ) , label ) . toEqual ( [ [ 'error' , `flows[0].nodes[0].${ keyPath } ` ] ] ) ;
1829+ expect ( findings [ 0 ] ! . message , label ) . toContain ( keyPath ) ;
1830+ expect ( findings [ 0 ] ! . message , label ) . toContain ( `type: 'api'` ) ;
1831+ // Never the missing-secret id beside it: one verdict per hook.
1832+ expect ( judge ( vendorFlow ( config ) ) . map ( ( f ) => f . rule ) , label ) . not . toContain ( FLOW_API_TRIGGER_SECRET_MISSING ) ;
1833+ // And never let through at the runtime publish gate.
1834+ expect (
1835+ runRuntimeAuthoringRules ( { type : 'flow' , item : vendorFlow ( config ) } ) . errors . map ( ( f ) => f . rule ) ,
1836+ label ,
1837+ ) . toContain ( FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ) ;
1838+ }
1839+ } ) ;
1840+
1841+ it ( 'a declared scheme is graded on its key reference alone: a withheld-and-stored literal secret does not make it ready' , ( ) => {
1842+ const flow = vendorFlow ( { signature : DOCUSIGN } ) ;
1843+ const findings = validateFlowApiTriggerSecret (
1844+ { objects : [ candidateObject ] , flows : [ flow ] } ,
1845+ { restoredCredentialPaths : new Set ( [ 'flows[0].nodes[0].config.secret' ] ) } ,
1846+ ) ;
1847+ expect ( findings . map ( ( f ) => [ f . rule , f . path ] ) ) . toEqual ( [ [ FLOW_API_TRIGGER_SIGNATURE_UNUSABLE , 'flows[0].nodes[0].config.signature' ] ] ) ;
1848+ } ) ;
1849+
1850+ it ( 'CONTROL: a flow that binds no api trigger is not graded by this rule, and a hook with no declaration keeps its own verdicts' , ( ) => {
1851+ expect ( rules ( vendorFlow ( { secretRef : 'K' , signature : { ...DOCUSIGN , algorithm : 'hmac-sha1' } } , 'autolaunched' ) )
1852+ . map ( ( [ rule ] ) => rule ) ) . not . toContain ( FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ) ;
1853+ expect ( rules ( vendorFlow ( { hookId : 'vendor' } ) ) ) . toEqual ( [ [ FLOW_API_TRIGGER_SECRET_MISSING , 'error' , 'flows[0].nodes[0].config.secret' ] ] ) ;
1854+ expect ( judge ( vendorFlow ( { secretRef : 'VENDOR_WEBHOOK_KEY' } ) ) ) . toEqual ( [ ] ) ;
1855+ } ) ;
1856+
1857+ it ( '`os explain flow-api-trigger-signature-unusable` says what a declared scheme is and why a broken one admits nothing' , ( ) => {
1858+ expect ( FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ) . toBe ( 'flow-api-trigger-signature-unusable' ) ;
1859+ const text = explanationOf ( FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ) ;
1860+ for ( const fact of [ 'config.signature' , 'config.secretRef' , 'REPLACES' , 'never falls back' , '401 INVALID_SIGNATURE' , '300-second' ] ) {
1861+ expect ( text , fact ) . toContain ( fact ) ;
1862+ }
1863+ } ) ;
1864+ } ) ;
1865+
17561866describe ( '[#22161] one-line verdicts — the never-fire family' , ( ) => {
17571867 it ( 'every verdict the cases above fired is one line of at most 200 characters' , ( ) => {
17581868 // The coverage control first: each of the five ids fired at least once, so
@@ -1798,9 +1908,10 @@ describe('[#22161] one-line verdicts — the never-fire family', () => {
17981908 [ FLOW_TRIGGER_UNROUTABLE ] : [ '`resolveTriggerBinding`' , 'manual — nothing to bind' , 'one higher than its bound count' , 'RESOLVED type' , 'record-{before,after}-{create,insert,update,delete,write}' ] ,
17991909 [ FLOW_TRIGGER_UNKNOWN_EVENT ] : [ 'record-{before,after}-{create,insert,update,delete,write}' , 'bind-time warn' , 'multi-event shape' , '`record-after-write`' ] ,
18001910 [ FLOW_API_TRIGGER_SECRET_MISSING ] : [ 'ADR-0041' , 'HMAC' , '`registerFlow`' , 'whatever the flow\'s `status`' , 'never receives a post' , 'withholds' ] ,
1911+ [ FLOW_API_TRIGGER_SIGNATURE_UNUSABLE ] : [ 'REPLACES' , 'never falls back' , 'flow parse refuses the flow at registration' , 'names the key the spec refuses at' ] ,
18011912 } ;
18021913
1803- it ( 'covers exactly the five ids' , ( ) => {
1914+ it ( 'covers exactly the never-fire ids' , ( ) => {
18041915 expect ( Object . keys ( MOVED ) . sort ( ) ) . toEqual ( [ ...NEVER_FIRE_IDS ] . sort ( ) ) ;
18051916 } ) ;
18061917
0 commit comments