Skip to content
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

Fastboot instance initializer throws if reportOnly config is false #271

Merged
merged 4 commits into from
Dec 14, 2021
Merged

Conversation

JoeyBG
Copy link
Contributor

@JoeyBG JoeyBG commented Dec 2, 2021

The current behaviour makes it impossible to disable reportOnly mode, we actually want to ensure the configuration is properly defined, not that it's true.

    The current behavior makes it impossible to disable reportOnly mode, we actually want to ensure the configuration is properly defined, not that it's true.
Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for working on this. Would be great if you could add a test to prevent a regression.

Comment on lines 12 to 14
addonConfig &&
Object.prototype.hasOwnProperty.call(addonConfig, 'reportOnly') &&
Object.prototype.hasOwnProperty.call(addonConfig, 'policy')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wondering if we could assert against the type instead?

Suggested change
addonConfig &&
Object.prototype.hasOwnProperty.call(addonConfig, 'reportOnly') &&
Object.prototype.hasOwnProperty.call(addonConfig, 'policy')
typeof addonConfig === 'object' &&
typeof addonConfig.reportOnly === 'boolean' &&
typeof addonConfig.policy === 'string'

This seems to be more readable and even make the assertion more strict.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't seem to find an existing test that actually runs goes through that codepath. Any ideas?

I'm not too experienced with Ember, I have no clue where to begin to setup tests deeply integrated with Fastboot like that.

I can apply your suggestion, but I believe policy should be 'object' right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the implementation as suggested, I will not have time to add tests for this, sorry. Hopefully, this can still be merged and released, as currently, v2.0.0 crashes on startup when reportOnly is set to false in a dev environment.

We're using our fork for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are failing with latest changes. Maybe my suggestion isn't working as expected.

Not sure when I have time to look into it. No one is paying me for maintaining this addon. I'm doing it _after_y regular job.

If you have time to debug that would be great.

For tests please have a look at existing Fastboot related tests in node-tests folder.

I added a test. It doesn't actually fail with the previous code, since assert only fails in development mode, but as I said I have no clue how to make the test server behave like a dev environment would.

The failing tests were caused by me using object for policy, I went back to string and it works well now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jelhan Just making sure you've seen this notification. No worries if you didn't have time to get to this yet!

@jelhan
Copy link
Collaborator

jelhan commented Dec 2, 2021

Please ignore the failing test for Ember CLI beta. It is not related to your changes. It should be fixed by #272.

@JoeyBG JoeyBG requested a review from jelhan December 3, 2021 15:09
@jelhan
Copy link
Collaborator

jelhan commented Dec 3, 2021

The tests are failing with latest changes. Maybe my suggestion isn't working as expected.

Not sure when I have time to look into it. No one is paying me for maintaining this addon. I'm doing it _after_y regular job.

If you have time to debug that would be great.

For tests please have a look at existing Fastboot related tests in node-tests folder.

Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pushing this one forward and adding a test. I'm surprised that the test does not fail without the fix to be honest. Haven't had the chance to try and debug myself yet. 😟

node-tests/e2e/fastboot-support-test.js Show resolved Hide resolved
Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the time to debug the test. Should be good to merge as soon as you added the missing assertion and removed the left-over from debugging.

node-tests/e2e/fastboot-support-test.js Show resolved Hide resolved
await removeConfig(testProject);
});

it.only('sets CSP header if served via FastBoot', async function () {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a left-over from debugging.

Suggested change
it.only('sets CSP header if served via FastBoot', async function () {
it('sets CSP header if served via FastBoot', async function () {

node-tests/e2e/fastboot-support-test.js Show resolved Hide resolved
@JoeyBG
Copy link
Contributor Author

JoeyBG commented Dec 13, 2021

I found the time to debug the test. Should be good to merge as soon as you added the missing assertion and removed the left-over from debugging.

@jelhan Done! That makes perfect sense :)

@JoeyBG JoeyBG requested a review from jelhan December 13, 2021 21:25
@jelhan jelhan added the bug label Dec 13, 2021
@jelhan jelhan changed the title Revert config assertion changes in #198 Fastboot instance initializer throws if reportOnly config is false Dec 13, 2021
Copy link
Collaborator

@jelhan jelhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot!

@jelhan jelhan merged commit b048d2b into adopted-ember-addons:master Dec 14, 2021
@jelhan
Copy link
Collaborator

jelhan commented Dec 20, 2021

Released this as v2.0.2 just right now. I'm sorry that it took that long. To be honest I just missed that I hadn't released it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants