Beispiel #1
0
    def get_current_user(self, url):
        '''
        Return a User object with details of the current authenticated user,
        including a url for logging out.

        If user has not yet been authenticated, return a User object with a
        url to allow user to log in.
        '''
        e, n, ui, li, lo, oid, wrd = (None, None, None, None, None, -1, False)
        user = self.db.user
        ia = False
        if user is None:
            li = self.ae.create_login_url(url)
        else:
            ia = user.is_admin
            e, n, ui = user.email(), user.nickname(), user.user_id()
            # make sure ListOwnerDb record exists
            owner = self.db.get_owner_by_user(user)
            req = None
            if owner is None:
                if not user.is_admin:
                    req = self.db.get_req_by_user(user)
                    if req is None:
                        req = self.db.add_req(user)
                else:
                    owner = self.db.add_owner(user)
            oid = owner.key().id() if owner is not None else -1
            wrd = req.denied if req is not None else False
            base = get_base_url(url)
            lo = self.ae.create_logout_url('%s/#Goodbye:' % base)
        return User(email=e, nickname=n, user_id=ui, login_url=li,
                    logout_url=lo, owner_id=oid, was_req_denied=wrd,
                    is_admin=ia)
Beispiel #2
0
    def Xtest_get_user(self):
        """
        Verify that calling get_current_user while logged in provides you
        with a logout url and your login info
        """

        self.set_user(User(is_admin=True))
        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Beispiel #3
0
    def Xtest_get_user_add_req(self):
        """
        Verify that when non-admin user tries to log in, an Access Request is
        created for them.
        """

        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)
        self.assertEqual(-1, user.owner_id)
        self.assertEqual(num_owners, len(self.db.owners))

        # Verify access request was created correctly
        self.assertEqual(1, len(self.db.request_ids))
        req = self.db.requests.values()[0]
        self.assertEqual(self.user, req.user)
Beispiel #4
0
    def Xtest_get_user(self):
        """
        Verify that calling get_current_user while logged in provides you
        with a logout url and your login info
        """

        self.set_user(User(is_admin=True))
        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)

        # Verify owner was created correctly
        owner = self.db.user_owners.get(self.user)
        self.assertEqual(num_owners + 1, len(self.db.owners))
        self.assertEqual(self.user, owner.user)
        self.assertEqual(owner.key().id(), user.owner_id)
        self.assertEqual(self.user.nickname(), owner.nickname)
        self.assertEqual(self.user.email(), owner.email)
        self.assertEqual(extract_name(self.user.email()), owner.name)
Beispiel #5
0
    def Xtest_get_user_add_req(self):
        """
        Verify that when non-admin user tries to log in, an Access Request is
        created for them.
        """

        # Verify no owner exists before call
        self.assertEqual(None, self.db.user_owners.get(self.user, None))
        num_owners = len(self.db.owners)

        url = 'http://www.domain.com/some/extra/path/'
        user = self.rpc.get_current_user(url)

        # Verify correct user details are returned
        base = get_base_url(url)
        goodbye = '{}/#Goodbye:'.format(base)
        self.assertEqual(self.ae.create_logout_url(goodbye), user.logout_url)
        self.assertEqual(self.user.nickname(), user.nickname)
        self.assertEqual(self.user.email(), user.email)
        self.assertEqual(None, user.login_url)
        self.assertEqual(-1, user.owner_id)
        self.assertEqual(num_owners, len(self.db.owners))

        # Verify access request was created correctly
        self.assertEqual(1, len(self.db.request_ids))
        req = self.db.requests.values()[0]
        self.assertEqual(self.user, req.user)
Beispiel #6
0
    def get_current_user(self, url):
        '''
        Return a User object with details of the current authenticated user,
        including a url for logging out.

        If user has not yet been authenticated, return a User object with a
        url to allow user to log in.
        '''
        e, n, ui, li, lo, oid, wrd = (None, None, None, None, None, -1, False)
        user = self.db.user
        ia = False
        if user is None:
            li = self.ae.create_login_url(url)
        else:
            ia = user.is_admin
            e, n, ui = user.email(), user.nickname(), user.user_id()
            # make sure ListOwnerDb record exists
            owner = self.db.get_owner_by_user(user)
            req = None
            if owner is None:
                if not user.is_admin:
                    req = self.db.get_req_by_user(user)
                    if req is None:
                        req = self.db.add_req(user)
                else:
                    owner = self.db.add_owner(user)
            oid = owner.key().id() if owner is not None else -1
            wrd = req.denied if req is not None else False
            base = get_base_url(url)
            lo = self.ae.create_logout_url('%s/#Goodbye:' % base)
        return User(email=e,
                    nickname=n,
                    user_id=ui,
                    login_url=li,
                    logout_url=lo,
                    owner_id=oid,
                    was_req_denied=wrd,
                    is_admin=ia)
Beispiel #7
0
 def test_get_base_url(self):
     """Confirm proper extraction of base url"""
     base = 'http://www.domain.com'
     url = '{}/extra/stuff/at/the/end.html'.format(base)
     self.assertEqual(util.get_base_url(url), base)
Beispiel #8
0
 def test_get_base_url(self):
     """Confirm proper extraction of base url"""
     base = 'http://www.domain.com'
     url = '{}/extra/stuff/at/the/end.html'.format(base)
     self.assertEqual(util.get_base_url(url), base)