@@ -194,4 +194,59 @@ class HttpServerCorsTest {
194194 expect ( methods ) . to . contain ( "GET" ) ;
195195 expect ( methods ) . to . contain ( "OPTIONS" ) ;
196196 }
197+
198+ @test async "should handle CORS for write property (PUT)" ( ) {
199+ this . thing = new ExposedThing ( this . servient , {
200+ title : "TestThingWrite" ,
201+ properties : {
202+ test : {
203+ type : "string" ,
204+ forms : [ ] ,
205+ } ,
206+ } ,
207+ } ) ;
208+
209+ this . thing . setPropertyWriteHandler ( "test" , ( ) => Promise . resolve ( undefined ) ) ;
210+
211+ await this . httpServer . expose ( this . thing ) ;
212+
213+ const uri = `http://localhost:${ this . httpServer . getPort ( ) } /testthingwrite/properties/test` ;
214+ const response = await fetch ( uri , {
215+ method : "PUT" ,
216+ body : JSON . stringify ( "new-value" ) ,
217+ headers : {
218+ Origin : "http://example.com" ,
219+ "Content-Type" : "application/json" ,
220+ } ,
221+ } ) ;
222+
223+ expect ( response . status ) . to . equal ( 204 ) ;
224+ expect ( response . headers . get ( "Access-Control-Allow-Origin" ) ) . to . equal ( "*" ) ;
225+ }
226+
227+ @test async "should handle CORS for invoke action (POST)" ( ) {
228+ this . thing = new ExposedThing ( this . servient , {
229+ title : "TestThingAction" ,
230+ actions : {
231+ test : {
232+ forms : [ ] ,
233+ } ,
234+ } ,
235+ } ) ;
236+
237+ this . thing . setActionHandler ( "test" , ( ) => Promise . resolve ( undefined ) ) ;
238+
239+ await this . httpServer . expose ( this . thing ) ;
240+
241+ const uri = `http://localhost:${ this . httpServer . getPort ( ) } /testthingaction/actions/test` ;
242+ const response = await fetch ( uri , {
243+ method : "POST" ,
244+ headers : {
245+ Origin : "http://example.com" ,
246+ } ,
247+ } ) ;
248+
249+ expect ( response . status ) . to . equal ( 204 ) ; // Action without output returns 204
250+ expect ( response . headers . get ( "Access-Control-Allow-Origin" ) ) . to . equal ( "*" ) ;
251+ }
197252}
0 commit comments