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

Set cookie after login to ignore own visits #171

Merged

Conversation

yehudab
Copy link
Contributor

@yehudab yehudab commented Oct 16, 2020

Fix #100

@coveralls
Copy link

coveralls commented Oct 16, 2020

Pull Request Test Coverage Report for Build 613

  • 2 of 13 (15.38%) changed or added relevant lines in 1 file are covered.
  • 2 unchanged lines in 1 file lost coverage.
  • Overall coverage decreased (-0.7%) to 45.78%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/resolvers/tokens.js 2 13 15.38%
Files with Coverage Reduction New Missed Lines %
src/resolvers/tokens.js 2 14.29%
Totals Coverage Status
Change from base Build 604: -0.7%
Covered Lines: 455
Relevant Lines: 793

💛 - Coveralls

@yehudab
Copy link
Contributor Author

yehudab commented Oct 16, 2020

@electerious
Any idea how I can re-run the above build?
Coverage on my local testing looks better now after the new commit.

@electerious
Copy link
Owner

  1. Is my assumption correct that this only works when process.env.ACKEE_ALLOW_ORIGIN is available? This isn't always the case as process.env.ACKEE_ALLOW_ORIGIN is just a fallback for those not using a reverse proxy.

  2. Let's say Ackee runs on ackee.example.com. It creates a cookie for example.com because this is the matching parent domain. Would it still ignore requests from example2.com?

My idea was that Ackee creates a cookie for the current domain (e.g. ackee.example.com) and a request will contain this cookie (e.g. from example2.com) so Ackee can ignore it. I'm however not sure if that's possible, because of blocked third party cookies. I want to ensure that it works without process.env.ACKEE_ALLOW_ORIGIN.

@electerious electerious mentioned this pull request Oct 18, 2020
@yehudab
Copy link
Contributor Author

yehudab commented Oct 18, 2020

  1. Is my assumption correct that this only works when process.env.ACKEE_ALLOW_ORIGIN is available? This isn't always the case as process.env.ACKEE_ALLOW_ORIGIN is just a fallback for those not using a reverse proxy.

Yes, this was my plan. I wasn't aware that using ACKEE_ALLOW_ORIGIN is optional

  1. Let's say Ackee runs on ackee.example.com. It creates a cookie for example.com because this is the matching parent domain. Would it still ignore requests from example2.com?

In this case, only results from example.com will be ignored

My idea was that Ackee creates a cookie for the current domain (e.g. ackee.example.com) and a request will contain this cookie (e.g. from example2.com) so Ackee can ignore it. I'm however not sure if that's possible, because of blocked third party cookies. I want to ensure that it works without process.env.ACKEE_ALLOW_ORIGIN.

Got it. I'll try a different approach and see if I cover both 1 and 2 above.

@yehudab
Copy link
Contributor Author

yehudab commented Oct 18, 2020

Pushed another version.
I still need to test it to make sure it's working well and to resolve the above conflicts.
Notice that there is still a change needed in ackee-tracker part (also pushed)

@yehudab
Copy link
Contributor Author

yehudab commented Oct 19, 2020

@electerious
After a few more checks and fixes, I think that the PR is ready and covers the flow mentioned in your comment from yesterday.
I don't have two domains to test example.com and example2.com, but I think that it should work.

Copy link
Owner

@electerious electerious left a comment

Choose a reason for hiding this comment

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

Great work! Just a few small things and it's ready to be merged :)

const mongod = new MongoMemoryServer()

// Create connection to mongoose before all tests
exports.before = async t =>
Copy link
Owner

Choose a reason for hiding this comment

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

There's a new function in src/utils/connect that can be used here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

return {
success: true,
payload: {
"id": "88888888-8888-8888-8888-888888888888"
Copy link
Owner

Choose a reason for hiding this comment

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

Please run npm run lint to align the code with the rest.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed here and in other files in this PR


// In case of own site don't update
if (req.cookies && req.cookies.ackee_login === "1") {
Copy link
Owner

Choose a reason for hiding this comment

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

Let's create a small util for this as it's used in two places. isLoggedIn(res) => true/false in src/utils/.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. Done.
One small change: Parameter name will be req, not res

@electerious electerious changed the base branch from develop to feature/ignore-own-visits October 24, 2020 18:26
@electerious electerious merged commit cf510dd into electerious:feature/ignore-own-visits Oct 24, 2020
@electerious
Copy link
Owner

Thanks for the great work 🙌

@electerious
Copy link
Owner

There's now an ignore-own-visits branch for both Ackee and ackee-tracker. I will do some testing on my server and on Netlify. This might take a while, but I'm sure that it will be part of the next release.

The biggest outcome for me is 'MongoMemoryServer'. Haven't seen it before and it's great to add tests for all MongoDB related files. More tests are welcome (can be based on the electerious:feature/ignore-own-visits branch) if you want to help out with more contributions :)

@yehudab
Copy link
Contributor Author

yehudab commented Oct 25, 2020

Happy to help with the feature and the testing.
I willl do my best to add more tests.

@yehudab yehudab deleted the ignore-own-visits branch October 29, 2020 19:29
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.

3 participants