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

IA-only auth flow #526

Merged
merged 8 commits into from
Aug 7, 2017
Merged

IA-only auth flow #526

merged 8 commits into from
Aug 7, 2017

Conversation

mekarpeles
Copy link
Member

Note: Before accepting, we need to CR and checkin code into olsystem

Todo:

  • some naming needs to change.
  • test cases required

Test flows:
Account Creation

  1. Attempt to create an account on OpenLibrary.org w/ the email of an existing Archive.org user (e.g. foo@archive.org)
  2. Attempt to create an account on OpenLibrary.org w/ the email of an existing Open Library username
  3. Attempt to create an account on OpenLibrary.org w/ with an email that doesn't exist on IA or OL (e.g. foo+test1@archive.org)

Login

  1. Attempt to login w/ valid OL credentials (the following should all fail):
  • try w/ an OL account which hasn't been activated
  • try w/ an OL account which is blocked
  • try w/ an OL account which is linked
  • try w/ an OL account which is not linked
  1. Attempt to login w/ an email that doesn't exist on IA or OL (this should fail -- no such account)
  2. Attempt to login w/ a valid IA account...
  • which isn't verified/activated (should fail)
  • which is already linked to an OL account (should succeed)
  • which is unlinked & where no OL account exists with matching email (should succeed)
  • which is unlinked & shares the same email as an OL account which is also unlinked (should succeed)
  • which is unlinked & shares the same email as an OL account linked to another account (this should fail!)

@mekarpeles mekarpeles requested a review from bfalling August 2, 2017 01:59
# `ol_account` shares the same email as our IA account and
# thus can and should be safely linked to our IA account, or
# (c) no `ol_account` which is linked or can be linked has
# been found and therefore, asuming
Copy link
Collaborator

Choose a reason for hiding this comment

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

Misspell. Should be "assuming".

except ValueError as e:
return {'error': 'max_retries_exceeded', 'msg': str(e)}

if not ol_account.itemname:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Under which conditions would ol_account.itemname be true-y? We've already determined that there was no ol_account going in to this branch, and OpenLibraryAccount.create() will return an error dictionary if it fails, won't it? (Or is there a case where it will return None?) Cuz if what I say is correct, then seems like if not ol_account.itemname will always be true, since it's always dealing with a newly created, therefore unlinked ol_account.

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right, there shouldn't be a case possible, I added this because a function had been removed between branches causing it to appear as if the account did not have an itemname set after login (when really the function to fetch the itemname was indeed the problem)

if not ol_account.verified:
return {'error': 'account_not_verified'}
if lending.config_ia_auth_only:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can slightly simplify the logic by consolidating this if with the occurrence of if lending.config_ia_auth_only just above. If you go that route, you'll need to move around the if not ol_account.verified logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think this is about the same level of complexity in either case as ol_account.verified would then have to be checked in 2 locations instead of lending.config_ia_auth_only

# call to safely activate them.
ol_account.activate()
else:
return {'error': 'ia_account_not_verified'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

At this point, wouldn't it be the OL account which is not verified (for dev usage)? (Of course, this logic may shift if you follow the previous suggestion.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right

# call to safely activate them.
ol_account.activate()
else:
return {'error': 'ia_account_not_verified'}
if ol_account.blocked:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe add comment. This is for the new OL account.

Copy link
Collaborator

Choose a reason for hiding this comment

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

i.e. We already checked for blocked accounts up above, but you might comment that this is for the newly fetched OL account.

# When enabled, this will prevent users from logging in
# with their Open Library credentials and instead require
# Internet Archive (Archive.org) credentials.
return {'error': 'ia_login_only'}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why wait this long to shut out OL logins when in production? In this current code, if the IA login fails, then the system still makes a db call to OL and an HTTP call to IA and then realizes "Oh, hey, I'm in production. I should return an error." Seems these should be moved up.

Copy link
Member Author

@mekarpeles mekarpeles Aug 3, 2017

Choose a reason for hiding this comment

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

Removed this flow entirely to simplify path of execution

@@ -681,13 +736,15 @@ def audit_accounts(email, password, test=False):
ol_account.link(audit['link'])
stats.increment('ol.account.xauth.auto-linked')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like this whole branch starting with # Links the accounts if they can be and are not already is not needed for the production case. Haven't we already hit every case up above?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this was an attempt to fix the problem where user logged in and it appeared as if they were not linked (when really the function to check link status had a regression). Resolved

@@ -23,7 +23,7 @@
<p>If you can't find the email, just hit this button to send a fresh one:</p>

<form method="POST" class="olform">
<input type="hidden" name="username" value="$username"/>
<input type="hidden" name="email" value="$email"/>
<input type="hidden" name="password" value="$password"/>
<input type="hidden" name="action" value="resend_verification_email"/>

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please make sure all these forms are in the test plan.

@bfalling
Copy link
Collaborator

bfalling commented Aug 4, 2017

LGTM

@mekarpeles mekarpeles merged commit 413ee7e into master Aug 7, 2017
@LeadSongDog
Copy link

@mekarpeles Did this change not disable the user's ability to set preferences, such as interface language? I can't even find the menu anymore.

@mekarpeles mekarpeles deleted the ia-auth-only branch April 22, 2019 01:49
@mekarpeles mekarpeles changed the title [WIP] IA-only auth flow IA-only auth flow Jan 23, 2021
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