-
-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability to fail application / addon tests when a CSP violation is detected. #91
Conversation
What do you think about only using the meta for this? That way we'd have the same mechanism both for tests running through the browser and for
I agree, and I'm culpable here 😄 I don't know enough about Ember testing to say anything about this PR in general (rwjblue is an expert at that though). But I'm happy to assist a rework of the options for this addon (single key with nested opts inside). |
That might be the best idea. Especially cause the tests are run with CSP enforced. So even if tests don't throw cause of CSP violation they might fail due to code been blocked by CSP.
Please have a look at #92. |
a048841
to
90f7eb1
Compare
59bdd63
to
9819f7c
Compare
@rwjblue @sandstrom This is ready to review from my side. Updated the initial post with the implementation details. |
😩, I'm sorry looks like merging #103 caused a merge conflict |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is great btw!
node-tests/e2e/test-support-test.js
Outdated
await fs.ensureDir(app.filePath(testFolder)); | ||
await fs.writeFile( | ||
app.filePath(testFile), | ||
" \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use template strings here, which would make this a bit easier to author and read...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to escape the backticks used by htmlbars-inline-precompile
than. So doesn't make a big difference. But refactored to use backticks cause I don't care to be honest. 😄
|
||
// tests altering package.json | ||
describe('', function() { | ||
// @ToDo: VersionChecker reports qunit@2.9.2 even so app uses 2.7.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we implement this using ember-try? I don't think this needs to block landing the change though...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how we could use ember-try in the context of an ember-cli-addon-tests apps. The issue here isn't with ember-cli-addon-tests but with ember-cli-version-checker. Haven't had the time yet to open a issue but it seems to make some wrong assumptions leading to wrong version reported.
The test is setting up a correct environment. npm list
returns the specified version of ember-qunit but ember-cli-version-checker seems to pick up the version used by the host project. It seems to be confused by some internals used by ember-cli-addon-tests. At least that's what I got from a quick investigation.
Will try to find the time for opening a bug report including a reproduction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍, sounds good I had forgotten RE: this being an ember-cli-addon-tests type test
e2ebf88
to
41877f6
Compare
This addon helps to ensure that an application or addon is not violating a strict CSP while developing but doesn't provide any testing solution. Providing an easy to use solution for ensuring that an addon is not violating a strict CSP would help the ecosystem a lot IMO. I'm maintaining an application that requires a strict CSP and noticed that from time to time CSP violations are added in addons without being aware of it.
This is only a PoC and not a fully functional solution. There are some open questions:I would like to add some tests. Actually doing so shouldn't be that difficult. A combination ofhtmlbars-inline-precompile
andassert.rejects
should just work fine. But doing it with old testing API feels like a burden. Would be great if Drop node 4 and Ember CLI < 2.13 (update to Ember 3.7 blueprint) #87 lands first.CSP headers are only present if tests are executed through openinghttp://localhost:4200/tests
in browser. They are not present forember test --server
norember test
. Failing on CSP violations in that scenarios also would require injecting CSP as meta tag (contentSecurityPolicyMeta = true
).Providing an option to disable testing feels strange. I know we have to provide a way to not throw for a transition period but allowing to disable the addon per environment would feel more familiar, e.g.contentSecurityPolicy: { enabled: environment !== 'test' }
. This is current only supported by an undocumented hack (Added development configuration example #77).~~The last point already demonstrated that current configuration interface isn't inline with the rest of the ecosystem. It's using three different keys on the root configuration object:
contentSecurityPolicy
,contentSecurityPolicyHeader
andcontentSecurityPolicyMeta
. Maybe we should refactor that before adding another option.~~~Update
This adds a new configuration option
failTests
. If it's true (and addon is enabled) it will cause tests to fail on every CSP violation. This is done by adding an event listener for CSP violations, which throws an error. Uncaught global errors cause the test to fail.It enforces a delivery through meta tag for
test
environment cause that one may be executed without an express server (and therefore without CSP headers). Otherwiseember test
would not fail on CSP violations ifdelivery
option does not include'meta'
.This might be considered a breaking change. Tests that passed previously may fail after upgrade cause
failTests
defaults totrue
.