Exemple #1
0
    def test_impersonation(self):
        """
        SessionStore.session_for_impersonation will return a session that can
        be retrieved by token_id but not username.
        """
        clock = Clock()
        sessions = SessionStore(clock)
        A_LITTLE = 1234
        clock.advance(A_LITTLE)
        A_LOT = 65432
        a = sessions.session_for_impersonation("pretender", A_LOT)
        a_prime = sessions.session_for_impersonation("pretender", A_LOT)
        self.assertIdentical(a, a_prime)
        b = sessions.session_for_token(a.token)
        self.assertEqual(
            a.expires, datetime.utcfromtimestamp(A_LITTLE + A_LOT))
        self.assertIdentical(a, b)
        c = sessions.session_for_username_password("pretender",
                                                   "not a password")
        self.assertNotIdentical(a, c)
        self.assertEqual(a.username, c.username)
        self.assertEqual(a.tenant_id, c.tenant_id)

        # Right now all data_for_api cares about is hashability; this may need
        # to change if it comes to rely upon its argument actually being an API
        # mock.
        same_api = 'not_an_api'

        username_data = c.data_for_api(same_api, list)
        token_data = b.data_for_api(same_api, list)
        impersonation_data = a.data_for_api(same_api, list)

        self.assertIs(username_data, impersonation_data)
        self.assertIs(token_data, impersonation_data)
Exemple #2
0
    def test_impersonation(self):
        """
        SessionStore.session_for_impersonation will return a session that can
        be retrieved by impersonated token_id or username.
        """
        clock = Clock()
        sessions = SessionStore(clock)
        A_LITTLE = 1234
        clock.advance(A_LITTLE)
        A_LOT = 65432
        a = sessions.session_for_impersonation("pretender", A_LOT)
        a_prime = sessions.session_for_impersonation("pretender", A_LOT)
        self.assertIdentical(a, a_prime)
        b = sessions.session_for_token(a.token)
        self.assertEqual(a.expires,
                         datetime.utcfromtimestamp(A_LITTLE + A_LOT))
        self.assertIdentical(a, b)
        c = sessions.session_for_username_password("pretender",
                                                   "not a password")
        self.assertIdentical(a, c)
        self.assertEqual(a.username, c.username)
        self.assertEqual(a.tenant_id, c.tenant_id)

        # Right now all data_for_api cares about is hashability; this may need
        # to change if it comes to rely upon its argument actually being an API
        # mock.
        same_api = 'not_an_api'

        username_data = c.data_for_api(same_api, list)
        token_data = b.data_for_api(same_api, list)
        impersonation_data = a.data_for_api(same_api, list)

        self.assertIs(username_data, impersonation_data)
        self.assertIs(token_data, impersonation_data)
Exemple #3
0
 def test_impersonation(self):
     """
     SessionStore.session_for_impersonation will return a session that can
     be retrieved by token_id but not username.
     """
     clock = Clock()
     sessions = SessionStore(clock)
     A_LITTLE = 1234
     clock.advance(A_LITTLE)
     A_LOT = 65432
     a = sessions.session_for_impersonation("pretender", A_LOT)
     a_prime = sessions.session_for_impersonation("pretender", A_LOT)
     self.assertIdentical(a, a_prime)
     b = sessions.session_for_token(a.token)
     self.assertEqual(a.expires,
                      datetime.utcfromtimestamp(A_LITTLE + A_LOT))
     self.assertIdentical(a, b)
     c = sessions.session_for_username_password("pretender",
                                                "not a password")
     self.assertNotIdentical(a, c)
     self.assertEqual(a.username, c.username)
     self.assertEqual(a.tenant_id, c.tenant_id)
Exemple #4
0
 def test_impersonation(self):
     """
     SessionStore.session_for_impersonation will return a session that can
     be retrieved by token_id but not username.
     """
     clock = Clock()
     sessions = SessionStore(clock)
     A_LITTLE = 1234
     clock.advance(A_LITTLE)
     A_LOT = 65432
     a = sessions.session_for_impersonation("pretender", A_LOT)
     a_prime = sessions.session_for_impersonation("pretender", A_LOT)
     self.assertIdentical(a, a_prime)
     b = sessions.session_for_token(a.token)
     self.assertEqual(
         a.expires, datetime.utcfromtimestamp(A_LITTLE + A_LOT))
     self.assertIdentical(a, b)
     c = sessions.session_for_username_password("pretender",
                                                "not a password")
     self.assertNotIdentical(a, c)
     self.assertEqual(a.username, c.username)
     self.assertEqual(a.tenant_id, c.tenant_id)
Exemple #5
0
 def test_sessions_created_all_have_integer_tenant_ids(self):
     """
     Sessions created by
     :class:`SessionStore.session_for_username_password`,
     :class:`SessionStore.session_for_impersonation`,
     :class:`SessionStore.session_for_api_key`, and
     :class:`SessionStore.session_for_token`, when not passed a specific
     tenant ID, all generate integer-style tenant IDs.
     """
     clock = Clock()
     sessions = SessionStore(clock)
     sessions = [
         sessions.session_for_username_password("someuser1", "testpass"),
         sessions.session_for_impersonation("someuser2", 12),
         sessions.session_for_api_key("someuser3", "someapikey"),
         sessions.session_for_token("sometoken"),
     ]
     integer = re.compile('^\d+$')
     for session in sessions:
         self.assertIsNot(integer.match(session.tenant_id), None,
                          "{0} is not an integer.".format(
                              session.tenant_id))
         self.assertTrue(int(session.tenant_id) < 1e15)
Exemple #6
0
 def test_sessions_created_all_have_integer_tenant_ids(self):
     """
     Sessions created by
     :class:`SessionStore.session_for_username_password`,
     :class:`SessionStore.session_for_impersonation`,
     :class:`SessionStore.session_for_api_key`, and
     :class:`SessionStore.session_for_token`, when not passed a specific
     tenant ID, all generate integer-style tenant IDs.
     """
     clock = Clock()
     sessions = SessionStore(clock)
     sessions = [
         sessions.session_for_username_password("someuser1", "testpass"),
         sessions.session_for_impersonation("someuser2", 12),
         sessions.session_for_api_key("someuser3", "someapikey"),
         sessions.session_for_token("sometoken"),
     ]
     integer = re.compile('^\d+$')
     for session in sessions:
         self.assertIsNot(
             integer.match(session.tenant_id), None,
             "{0} is not an integer.".format(session.tenant_id))
         self.assertTrue(int(session.tenant_id) < 1e15)