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

[WIP] Allow Session triggers #4373

Conversation

addisonElliott
Copy link
Contributor

Remove restriction on having beforeSave & afterSave triggers on _Session class.

Fixes issue #4020

@codecov
Copy link

codecov bot commented Nov 23, 2017

Codecov Report

Merging #4373 into master will decrease coverage by 0.03%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4373      +/-   ##
==========================================
- Coverage   92.69%   92.66%   -0.04%     
==========================================
  Files         118      118              
  Lines        8353     8354       +1     
==========================================
- Hits         7743     7741       -2     
- Misses        610      613       +3
Impacted Files Coverage Δ
src/RestWrite.js 93.12% <100%> (-0.34%) ⬇️
src/Routers/PublicAPIRouter.js 91.17% <100%> (ø) ⬆️
src/triggers.js 94.11% <100%> (-0.03%) ⬇️
src/Adapters/Auth/meetup.js 84.21% <0%> (-5.27%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 33de770...624c7cd. Read the comment docs.

@@ -1780,12 +1780,6 @@ describe('afterFind hooks', () => {
});

it('should validate triggers correctly', () => {
expect(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If we do this we should keep these, but check for a valid response rather than an exception. You can use .not.ToThrow() as seen just a bit below here.

@flovilmart
Copy link
Contributor

Remove restriction on having beforeSave & afterSave triggers on _Session class.

What's the motivation behind it? It was restricted for what I believe to be good reasons.

@addisonElliott
Copy link
Contributor Author

For issue #4020, I needed it for performing an action when a user logged on.

You mentioned that we could lift the restriction for this purpose. Another user asked about the status of this recently and I'm sure he found a reason as well.

Also look at #4027 for another reason.

I understand that you can shoot yourself in the foot with this and it can be dangerous but I think the developer will know not to change session information.

@flovilmart
Copy link
Contributor

but I think the developer will know not to change session information.

Nope, you can't trust devs on that, on certain issue we're taken the ground of hardening the security. and it requires a good evaluation. If there's any risk this may cause harm to the developer, we should not proceed.

@addisonElliott
Copy link
Contributor Author

Fair enough. In issue #4020, you mentioned that we could lift the restrictions for my case. What did you mean there?

First, I would like to ask what exactly can the user do to the Session class that will mess things up catastrophically? My first question is maybe we can restrict editing the Session class in the triggers.

Second, if the Session triggers method isn't going to work, then what is a way to solve the issues I listed above? Should we just have special callback functions like on login, on logout, on email verification, etc? This is a bit different from triggers for classes.

@flovilmart
Copy link
Contributor

We could lift the restriction, the reason why I didn't open the PR in the first place, was that I was still pondering the 'could' not the 'can' part of it.

For sure, the _Sessions objects are quite nice as they give good info about logins, signups etc...
I believe in a 1st step I would be OK, with non mutating hooks, where the user would only be able to read the contents of the _Session objects and not provide additional values from there. What do you think?

@addisonElliott
Copy link
Contributor Author

I think that's a good idea. Ill update the PR when I get a chance.

I can't think of a potential case of why you would want to change the _Session so I think that's safe to do until someone provides reason to allow it.

@montymxb
Copy link
Contributor

I like the idea of making it read-only. That would remove the potential maliciousness that could happen on an _Session object, decreasing the likelihood of an issue in hooks.

Instead of removing the tests for validating _Session triggers, I restored them and made sure that having a _Session trigger does NOT throw an exception
…t and new object into one REST array and then convert to ParseObject. Previously, it would convert the extraData and original object into a ParseObject and copy data from new array over. This has the side effect of failing for _Session class because the attributes are read only.

Rename sanitizedData to sanitizeData because sanitizedData implies the data will be returned. Instead, sanitizeData mutates the data field to remove any sensitive information.

Create expandData function which mutates the data field and expands any keys that use dot notation ('x.y')
@addisonElliott addisonElliott changed the title Allow Session triggers [WIP] Allow Session triggers Nov 30, 2017
@overpod
Copy link

overpod commented Dec 7, 2017

I really need this feature

@addisonElliott
Copy link
Contributor Author

addisonElliott commented Dec 7, 2017

I haven't had time to finish this up. There is one more test that is failing that I need to look at.

The issue is that the _Session class has read only attributes and when using triggers, it builds the _Session class by starting with an empty object and setting each value. This throws an error because they are meant to be read only.

If you want, test out this code (npm test) and find the issue in my code.

@addisonElliott addisonElliott mentioned this pull request Jan 20, 2018
@pewh
Copy link

pewh commented Feb 2, 2018

Hey, I need to delete Installation after Session was deleted (logout). If this PR is not merged, how to achieve my case?

@flovilmart
Copy link
Contributor

@addisonElliott sorry it took forever, I changed my mind, let's open it up simply.

@addisonElliott
Copy link
Contributor Author

@flovilmart No problem at all! I'll resume working on this soon.

I was having some issues with tests randomly failing when _Session triggers are eliminated...

@flovilmart
Copy link
Contributor

@addisonElliott Awesome!

@stale
Copy link

stale bot commented Sep 22, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Sep 22, 2018
@stale stale bot closed this Sep 29, 2018
@somq
Copy link

somq commented Oct 5, 2018

@addisonElliott Have you got somewhere with this one? Maybe we could fallback and "open it up" as @flovilmart proposed.

I will probably be in huge need of a way to catch logins soon.
I have taken a look at your work and everything looks OK to me.
Can you give us the infos on your work state please?

@addisonElliott
Copy link
Contributor Author

Sorry, haven't made progress. No time.

It's on my list of TODOs but feel free to make a PR if you've got time. I'm trying to get Parse setup for my Windows environment first.

@moritzsternemann
Copy link

I inspected your changes, looks good to me. However I could not reproduce the failing test case you mentioned above because of another issue (#4370, on macOS though).
Could you describe your issues in a little bit more detail please?

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

Successfully merging this pull request may close these issues.

7 participants