Add the concept of require_fresh_login to both the backend and frontend. Sensitive methods will now be marked with the annotation, which requires that the user has performed a login within 10 minutes or they are asked to do so in the UI before running the operation again.
This commit is contained in:
parent
1e7e012b92
commit
e783df31e0
9 changed files with 174 additions and 61 deletions
|
@ -23,7 +23,8 @@ from endpoints.api.trigger import (BuildTriggerActivate, BuildTriggerSources, Bu
|
|||
from endpoints.api.repoemail import RepositoryAuthorizedEmail
|
||||
from endpoints.api.repositorynotification import RepositoryNotification, RepositoryNotificationList
|
||||
from endpoints.api.user import (PrivateRepositories, ConvertToOrganization, Recovery, Signout,
|
||||
Signin, User, UserAuthorizationList, UserAuthorization, UserNotification)
|
||||
Signin, User, UserAuthorizationList, UserAuthorization, UserNotification,
|
||||
VerifyUser)
|
||||
from endpoints.api.repotoken import RepositoryToken, RepositoryTokenList
|
||||
from endpoints.api.prototype import PermissionPrototype, PermissionPrototypeList
|
||||
from endpoints.api.logs import UserLogs, OrgLogs, RepositoryLogs
|
||||
|
@ -434,6 +435,24 @@ class TestSignin(ApiTestCase):
|
|||
self._run_test('POST', 403, 'devtable', {u'username': 'E9RY', u'password': 'LQ0N'})
|
||||
|
||||
|
||||
class TestVerifyUser(ApiTestCase):
|
||||
def setUp(self):
|
||||
ApiTestCase.setUp(self)
|
||||
self._set_url(VerifyUser)
|
||||
|
||||
def test_post_anonymous(self):
|
||||
self._run_test('POST', 401, None, {u'password': 'LQ0N'})
|
||||
|
||||
def test_post_freshuser(self):
|
||||
self._run_test('POST', 403, 'freshuser', {u'password': 'LQ0N'})
|
||||
|
||||
def test_post_reader(self):
|
||||
self._run_test('POST', 403, 'reader', {u'password': 'LQ0N'})
|
||||
|
||||
def test_post_devtable(self):
|
||||
self._run_test('POST', 200, 'devtable', {u'password': 'password'})
|
||||
|
||||
|
||||
class TestListPlans(ApiTestCase):
|
||||
def setUp(self):
|
||||
ApiTestCase.setUp(self)
|
||||
|
@ -473,13 +492,13 @@ class TestUser(ApiTestCase):
|
|||
self._run_test('PUT', 401, None, {})
|
||||
|
||||
def test_put_freshuser(self):
|
||||
self._run_test('PUT', 200, 'freshuser', {})
|
||||
self._run_test('PUT', 401, 'freshuser', {})
|
||||
|
||||
def test_put_reader(self):
|
||||
self._run_test('PUT', 200, 'reader', {})
|
||||
self._run_test('PUT', 401, 'reader', {})
|
||||
|
||||
def test_put_devtable(self):
|
||||
self._run_test('PUT', 200, 'devtable', {})
|
||||
self._run_test('PUT', 401, 'devtable', {})
|
||||
|
||||
def test_post_anonymous(self):
|
||||
self._run_test('POST', 400, None, {u'username': 'T946', u'password': '0SG4', u'email': 'MENT'})
|
||||
|
|
|
@ -172,14 +172,14 @@ class TestCSRFFailure(ApiTestCase):
|
|||
|
||||
# Make sure a simple post call succeeds.
|
||||
self.putJsonResponse(User,
|
||||
data=dict(password='newpasswordiscool', current_password='password'))
|
||||
data=dict(password='newpasswordiscool'))
|
||||
|
||||
# Change the session's CSRF token.
|
||||
self.setCsrfToken('someinvalidtoken')
|
||||
|
||||
# Verify that the call now fails.
|
||||
self.putJsonResponse(User,
|
||||
data=dict(password='newpasswordiscool', current_password='password'),
|
||||
data=dict(password='newpasswordiscool'),
|
||||
expected_code=403)
|
||||
|
||||
|
||||
|
@ -325,29 +325,15 @@ class TestChangeUserDetails(ApiTestCase):
|
|||
def test_changepassword(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
self.putJsonResponse(User,
|
||||
data=dict(password='newpasswordiscool', current_password='password'))
|
||||
data=dict(password='newpasswordiscool'))
|
||||
self.login(READ_ACCESS_USER, password='newpasswordiscool')
|
||||
|
||||
def test_changepassword_invalidpasswor(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
self.putJsonResponse(User,
|
||||
data=dict(password='newpasswordiscool', current_password='notcorrect'),
|
||||
expected_code=400)
|
||||
|
||||
def test_changeeemail(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
||||
self.putJsonResponse(User,
|
||||
data=dict(email='test+foo@devtable.com', current_password='password'))
|
||||
data=dict(email='test+foo@devtable.com'))
|
||||
|
||||
def test_changeeemail_invalidpassword(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
||||
self.putJsonResponse(User,
|
||||
data=dict(email='test+foo@devtable.com', current_password='notcorrect'),
|
||||
expected_code=400)
|
||||
|
||||
|
||||
def test_changeinvoiceemail(self):
|
||||
self.login(READ_ACCESS_USER)
|
||||
|
||||
|
|
Reference in a new issue