diff --git a/PlotLine.Tests/Browser/context-intent-palette-acceptance.cjs b/PlotLine.Tests/Browser/context-intent-palette-acceptance.cjs index b9980ae5..ad75c82d 100644 --- a/PlotLine.Tests/Browser/context-intent-palette-acceptance.cjs +++ b/PlotLine.Tests/Browser/context-intent-palette-acceptance.cjs @@ -16,8 +16,11 @@ let session, stage = 'login'; const url = '/Writing/Context/Intent/Palette?'+new URLSearchParams({...base,...query}); const result = await session.page.evaluate(async url => { const response = await fetch(url, {credentials:'same-origin'}); - return {status:response.status, data:response.status===200?await response.json():null}; + const json=(response.headers.get('content-type')||'').includes('application/json'); + return {status:response.status,redirected:response.redirected,path:new URL(response.url).pathname, + data:response.status===200&&json?await response.json():null}; }, url); + if(result.status!==expected) console.error(JSON.stringify({stage,expected,status:result.status,redirected:result.redirected,path:result.path})); assert.equal(result.status, expected); return result.data; } @@ -56,18 +59,20 @@ let session, stage = 'login'; assert.deepEqual((await read({sceneID:second})).entries.map(e=>e.key),['location:'+literal]); assert.deepEqual(new Set((await read()).entries.map(e=>e.key)),new Set(['location:'+place,'location:'+literal])); stage='invalid and mismatched scope denial'; - await read({chapterID:otherChapter},403); - await read({bookID:otherBook},403); - await read({chapterID:otherChapter,bookID:otherBook,sceneID:first},403); - await read({sceneID:0},400); - await read({search:'x'.repeat(201)},400); + stage='chapter/book mismatch denial';await read({chapterID:otherChapter},403); + stage='book/chapter mismatch denial';await read({bookID:otherBook},403); + stage='scene/chapter mismatch denial';await read({chapterID:otherChapter,bookID:otherBook,sceneID:first},403); + stage='invalid scene rejection';await read({sceneID:0},400); + stage='oversized search rejection';await read({search:'x'.repeat(201)},400); stage='fresh login persistence and read-only source'; await session.close(); session=await open(); scoped=await read({sceneID:first}); assert.equal(scoped.entries[0].key,'location:'+place); await session.goto('/Scenes/Edit/'+first); - assert.equal(await session.page.locator('#PrimaryLocationID').inputValue(),String(place)); - assert.equal(await session.page.locator('#SceneTitle').inputValue(),'Palette first scene'); + await session.page.getByRole('button',{name:'Edit scene details',exact:true}).click(); + const editor=session.page.locator('form[data-scene-editor-form]'); + assert.equal(await editor.locator('[name=PrimaryLocationID]').inputValue(),String(place)); + assert.equal(await editor.locator('[name=SceneTitle]').inputValue(),'Palette first scene'); console.log(JSON.stringify({passed:true,milestone:'palette read path only',checks:[ 'chapter without prose or scenes','canonical identity separation and hidden-label ambiguity', 'case-insensitive wider search and literal percent','chapter and optional scene associations/provenance', diff --git a/PlotLine/Controllers/ContextIntentController.cs b/PlotLine/Controllers/ContextIntentController.cs index 24904490..5c5729b2 100644 --- a/PlotLine/Controllers/ContextIntentController.cs +++ b/PlotLine/Controllers/ContextIntentController.cs @@ -18,7 +18,9 @@ public sealed class ContextIntentController(ContextIntentPalette palette) : Cont if (!ModelState.IsValid) return BadRequest(); try { return Json(await palette.Read(query)); } catch (ArgumentException e) { return BadRequest(new { message = e.Message }); } - catch (UnauthorizedAccessException) { return Forbid(); } - catch (SqlException e) when (e.Number == 51010) { return Forbid(); } + // This is a JSON data endpoint. Cookie Forbid redirects to an HTML + // AccessDenied page; callers need a terminal scope denial instead. + catch (UnauthorizedAccessException) { return StatusCode(StatusCodes.Status403Forbidden); } + catch (SqlException e) when (e.Number == 51010) { return StatusCode(StatusCodes.Status403Forbidden); } } }