@@ -138,11 +138,13 @@ export function wordpressAdversarialActionSpec(action: WordPressAdversarialActio
138138 return { kind : "command" , command : "wordpress.wp-cli" , args : [ `command=${ command } ` ] , operation : `adversarial:${ action . surface } ` , metadata : actionMetadata ( action , capability ) }
139139 }
140140 if ( action . surface === "ajax" ) {
141+ requirePostOperation ( action )
141142 if ( ! action . target ) throw new Error ( "WordPress adversarial AJAX actions require the target action name." )
142- const body = new URLSearchParams ( { action : action . target , ... httpFormValues ( action . input ) } ) . toString ( )
143+ const body = new URLSearchParams ( { ... httpFormValues ( action . input ) , action : action . target } ) . toString ( )
143144 return { kind : "command" , command : "wordpress.browser-actions" , args : [ `steps-json=${ JSON . stringify ( httpBrowserSteps ( "/wp-admin/admin-ajax.php" , "application/x-www-form-urlencoded" , body ) ) } ` ] , operation : "adversarial:ajax" , metadata : actionMetadata ( action , capability ) }
144145 }
145146 if ( action . surface === "xmlrpc" ) {
147+ requirePostOperation ( action )
146148 if ( typeof action . input !== "string" || action . input . trim ( ) === "" ) throw new Error ( "WordPress adversarial XML-RPC actions require a non-empty XML request body." )
147149 return { kind : "command" , command : "wordpress.browser-actions" , args : [ `steps-json=${ JSON . stringify ( httpBrowserSteps ( "/xmlrpc.php" , "text/xml" , action . input ) ) } ` ] , operation : "adversarial:xmlrpc" , metadata : actionMetadata ( action , capability ) }
148150 }
@@ -324,6 +326,12 @@ function httpFormValues(value: unknown): Record<string, string> {
324326 return Object . fromEntries ( Object . entries ( record ?? { } ) . map ( ( [ name , item ] ) => [ name , typeof item === "string" ? item : JSON . stringify ( item ) ] ) )
325327}
326328
329+ function requirePostOperation ( action : WordPressAdversarialAction ) : void {
330+ if ( action . operation . trim ( ) . toUpperCase ( ) !== "POST" ) {
331+ throw new Error ( `WordPress adversarial ${ action . surface . toUpperCase ( ) } actions only support POST requests.` )
332+ }
333+ }
334+
327335function httpBrowserSteps ( path : string , contentType : string , body : string ) : Array < Record < string , unknown > > {
328336 const expression = `const response = await fetch(${ JSON . stringify ( path ) } , { method: 'POST', headers: { 'Content-Type': ${ JSON . stringify ( contentType ) } }, body: ${ JSON . stringify ( body ) } }); return response.ok`
329337 return [ { kind : "navigate" , url : "/" , waitFor : "load" } , { kind : "evaluate" , expression, assert : true } ]
0 commit comments