-
Notifications
You must be signed in to change notification settings - Fork 643
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: apply cspNonce when client reordering (#1836)
* feat: apply cspNonce when client reordering
- Loading branch information
Showing
12 changed files
with
212 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"marko": patch | ||
--- | ||
|
||
Avoid inline styles when using tight Content Security Policy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
...st/render/fixtures-async-callback/await-client-reorder-cspnonce/expected-events-vdom.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"event": "await:begin", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false | ||
} | ||
}, | ||
{ | ||
"event": "await:beforeRender", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false | ||
} | ||
}, | ||
{ | ||
"event": "await:finish", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false, | ||
"finished": true | ||
} | ||
} | ||
] |
27 changes: 27 additions & 0 deletions
27
...ko/test/render/fixtures-async-callback/await-client-reorder-cspnonce/expected-events.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
[ | ||
{ | ||
"event": "await:begin", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"id": 0 | ||
} | ||
}, | ||
{ | ||
"event": "await:beforeRender", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"id": 0 | ||
} | ||
}, | ||
{ | ||
"event": "await:finish", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"id": 0, | ||
"finished": true | ||
} | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
...ges/marko/test/render/fixtures-async-callback/await-client-reorder-cspnonce/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<noscript id="afph0"></noscript><!--FLUSH--><style nonce="xyz">#af0{display:none;}</style><div id="af0"><div class="foo"><h1>Foo</h1> Hello World</div></div><script nonce="xyz">function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b<f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b<f;b++)c(a[b])}};$af(0)</script> |
8 changes: 8 additions & 0 deletions
8
...es/marko/test/render/fixtures-async-callback/await-client-reorder-cspnonce/template.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<await(data.outer) client-reorder> | ||
<@then|outer|> | ||
<div class="foo"> | ||
<h1>Foo</h1> Hello World | ||
</div> | ||
</@then> | ||
</await> | ||
<await-reorderer/> |
29 changes: 29 additions & 0 deletions
29
packages/marko/test/render/fixtures-async-callback/await-client-reorder-cspnonce/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
var extend = require("raptor-util/extend"); | ||
var expect = require("chai").expect; | ||
const { callbackProvider } = require("../../../__util__/async-helpers"); | ||
|
||
exports.templateData = { | ||
outer: callbackProvider(1, {}), | ||
$global: { | ||
cspNonce: "xyz" | ||
} | ||
}; | ||
|
||
exports.checkEvents = function (events, snapshot, out) { | ||
events = events.map(function (eventInfo) { | ||
var arg = extend({}, eventInfo.arg); | ||
expect(arg.out != null).to.equal(true); | ||
|
||
delete arg.out; // Not serializable | ||
delete arg.asyncValue; // Not serializable | ||
|
||
return { | ||
event: eventInfo.event, | ||
arg: arg | ||
}; | ||
}); | ||
|
||
snapshot(events, out.isVDOM ? "-events-vdom.json" : "-events.json"); | ||
}; | ||
|
||
exports.skip_vdom = "client-reorder/placeholders are not supported in vdom"; |
24 changes: 24 additions & 0 deletions
24
packages/marko/test/render/fixtures/await-client-reorder-cspnonce/expected-events-vdom.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[ | ||
{ | ||
"event": "await:begin", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false | ||
} | ||
}, | ||
{ | ||
"event": "await:beforeRender", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false | ||
} | ||
}, | ||
{ | ||
"event": "await:finish", | ||
"arg": { | ||
"name": "data.outer", | ||
"clientReorder": false, | ||
"finished": true | ||
} | ||
} | ||
] |
30 changes: 30 additions & 0 deletions
30
packages/marko/test/render/fixtures/await-client-reorder-cspnonce/expected-events.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
[ | ||
{ | ||
"event": "await:begin", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"dataProvider": {}, | ||
"id": 0 | ||
} | ||
}, | ||
{ | ||
"event": "await:beforeRender", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"dataProvider": {}, | ||
"id": 0 | ||
} | ||
}, | ||
{ | ||
"event": "await:finish", | ||
"arg": { | ||
"name": "input.outer", | ||
"clientReorder": true, | ||
"dataProvider": {}, | ||
"id": 0, | ||
"finished": true | ||
} | ||
} | ||
] |
1 change: 1 addition & 0 deletions
1
packages/marko/test/render/fixtures/await-client-reorder-cspnonce/expected.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<noscript id="afph0"></noscript><style nonce="xyz">#af0{display:none;}</style><div id="af0"><div class="foo"><h1>Foo</h1> Hello World</div></div><script nonce="xyz">function $af(d,a,e,l,g,h,k,b,f,c){c=$af;if(a&&!c[a])(c[a+="$"]||(c[a]=[])).push(d);else{e=document;l=e.getElementById("af"+d);g=e.getElementById("afph"+d);h=e.createDocumentFragment();k=l.childNodes;b=0;for(f=k.length;b<f;b++)h.appendChild(k.item(0));g&&g.parentNode.replaceChild(h,g);c[d]=1;if(a=c[d+"$"])for(b=0,f=a.length;b<f;b++)c(a[b])}};$af(0)</script> |
8 changes: 8 additions & 0 deletions
8
packages/marko/test/render/fixtures/await-client-reorder-cspnonce/template.marko
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<await(data.outer) client-reorder> | ||
<@then|outer|> | ||
<div class="foo"> | ||
<h1>Foo</h1> Hello World | ||
</div> | ||
</@then> | ||
</await> | ||
<await-reorderer/> |
28 changes: 28 additions & 0 deletions
28
packages/marko/test/render/fixtures/await-client-reorder-cspnonce/test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
var extend = require("raptor-util/extend"); | ||
var expect = require("chai").expect; | ||
|
||
exports.templateData = { | ||
outer: Promise.resolve(), | ||
$global: { | ||
cspNonce: "xyz" | ||
} | ||
}; | ||
|
||
exports.checkEvents = function (events, snapshot, out) { | ||
events = events.map(function (eventInfo) { | ||
var arg = extend({}, eventInfo.arg); | ||
expect(arg.out != null).to.equal(true); | ||
|
||
delete arg.out; // Not serializable | ||
delete arg.asyncValue; // Not serializable | ||
|
||
return { | ||
event: eventInfo.event, | ||
arg: arg | ||
}; | ||
}); | ||
|
||
snapshot(events, out.isVDOM ? "-events-vdom.json" : "-events.json"); | ||
}; | ||
|
||
exports.skip_vdom = "client-reorder/placeholders are not supported in vdom"; |