def test_cache_diff_target(self):
     client = self.get_client()
     headers = {
         HTTP_HEADER_USER_INFO: "Brienne of Tarth",
         HTTP_HEADER_SIGNATURE: ""
     }
     t1 = client.fetch_user_token(headers, "SecurityClientTest")
     t2 = client.fetch_user_token(headers, "NotSecurityClientTest")
     nt.assert_not_equal(t1, t2)
 def test_cache_same_target(self):
     client = self.get_client()
     headers = {
         HTTP_HEADER_USER_INFO: "Joffrey Baratheon",
         HTTP_HEADER_SIGNATURE: ""
     }
     t1 = client.fetch_user_token(headers, "SecurityClientTest")
     t2 = client.fetch_user_token(headers, "SecurityClientTest")
     nt.assert_equal(t1, t2)
 def test_cache_no_target(self):
     client = self.get_client()
     headers = {
         HTTP_HEADER_USER_INFO: "John Snow",
         HTTP_HEADER_SIGNATURE: ""
     }
     t1 = client.fetch_user_token(headers)
     t2 = client.fetch_user_token(headers)
     nt.assert_equal(t1, t2)
 def test_cache_expire(self):
     client = self.get_client()
     headers = {
         HTTP_HEADER_USER_INFO: "Gendry",
         HTTP_HEADER_SIGNATURE: ""
     }
     t1 = client.fetch_user_token(headers, "SecurityClientTest")
     time.sleep(0.6)
     t2 = client.fetch_user_token(headers, "SecurityClientTest")
     nt.assert_not_equal(t1, t2)
    def test_user_info(self):
        client = self.get_client()
        subject = "Joe USER"
        headers = {
            HTTP_HEADER_USER_INFO: subject,
            HTTP_HEADER_SIGNATURE: ""
        }
        t = client.fetch_user_token(headers)

        nt.assert_equal(self.appId, t.validity.issuedTo)
        nt.assert_equal(self.appId, t.validity.issuedFor)
        nt.assert_equal(subject, t.tokenPrincipal.principal)
        nt.assert_equal("Joe User", t.tokenPrincipal.name)
        nt.assert_set_equal({'A', 'B', 'C'}, t.authorizations.formalAuthorizations)
        nt.assert_equal("EzBake", t.organization)
        nt.assert_equal("USA", t.citizenship)
        nt.assert_equal("low", t.authorizationLevel)
        nt.assert_dict_equal(dict([
            ('EzBake', ['Core']),
            ('42six', ['Dev', 'Emp']),
            ('Nothing', ['groups', 'group2'])]), t.externalProjectGroups)
        community_membership = t.externalCommunities['EzBake']
        nt.assert_equal("office", community_membership.type)
        nt.assert_equal("EzBake", community_membership.organization)
        nt.assert_true(community_membership.flags['ACIP'])
        nt.assert_list_equal(['topic1', 'topic2'], community_membership.topics)
        nt.assert_list_equal(['region1', 'region2', 'region3'], community_membership.regions)
        nt.assert_list_equal([], community_membership.groups)
 def test_validate_received_token(self):
     client = self.get_client()
     subject = "Joe USER"
     headers = {
         HTTP_HEADER_USER_INFO: subject,
         HTTP_HEADER_SIGNATURE: ""
     }
     token = client.fetch_user_token(headers, "SecurityClientTest")
     nt.assert_true(client.validate_received_token(token))
     b = TSer.serialize(token)
     token = EzSecurityToken()
     TSer.deserialize(token, b)
     nt.assert_true(client.validate_received_token(token))
 def test_mock_mode(self):
     client = self.get_client()
     headers = {}
     token = client.fetch_user_token(headers)
     nt.assert_is_not_none(token)