salesforce / near-membrane

JavaScript Near Membrane Library that powers Lightning Locker Service
113 stars 27 forks source link

feat: default policy in every Virtual DOM Environment #431

Closed dgitin closed 1 year ago

dgitin commented 1 year ago

It seems to me that remapping is something that we could do, but distort the defaultPolicy instance with the one created prior to patching the iframe. That should be equivalent but more elegant.

The policy needs to be declared as being part of this window, not distorted. Once things are remapped declaring a default policy in the virtual env becomes a problem so if you know a more elegant way of achieving the same result I'd like to know about it.

github-actions[bot] commented 1 year ago
Metric Coverage Percent Covered / Total
Statements 80.75% ( 822/1018 )
Branches 61.24% ( 256/418 )
Functions 72.48% ( 79/109 )
Lines 80.49% ( 792/984 )
Total 73.74%

See detailed coverage

dgitin commented 1 year ago

thanks for making these changes. can we add some tests for this?

Testing is problematic there is absolutely nothing set up at the moment to support this scenario. First, there is no policy to assert on in the virtual environment because the entire trustedTypes object gets remapped. Second, testing with Trusted Types is quite the challenge on this repo, the code needs to load once, declare the policies and then assert that evaluation is possible in the environment but not in the main window which would confirm that virtual environment run with their own TT policy. So definitely not as simple as just writing a test. The test is easy, the setting up, quite the opposite.