Beispiel #1
0
 def test_user_clients_with_team_access(self):
     """
     Test to verify a list of clients with access to the user's organizations' teams.
     """
     aro = models.User(username=u'aro')
     jane = models.User(username=u'jane')
     marcus = models.User(username=u'marcus')
     volturi = models.Organization(name=u'volturi', title=u'The Volturi')
     volturi.owners.users.append(aro)
     volturi.members.users.append(marcus)
     volturi.members.users.append(jane)
     volturi.make_teams()
     volterra = models.Client(title=u'Volterra, Tuscany',
                              org=volturi,
                              confidential=True,
                              website=u'volterra.co.it')
     enforcers = models.Client(title=u'Volturi\'s thugs',
                               org=volturi,
                               confidential=True,
                               website=u'volturi.co.it')
     volterra_auth_token = models.AuthToken(client=volterra,
                                            user=aro,
                                            scope=u'teams',
                                            validity=0)
     volterra_auth_token  # NOQA
     enforcers_auth_token = models.AuthToken(client=enforcers,
                                             user=marcus,
                                             scope=u'teams',
                                             validity=0)
     enforcers_auth_token  # NOQA
     self.assertItemsEqual(aro.clients_with_team_access(), [volterra])
     self.assertItemsEqual(marcus.clients_with_team_access(), [enforcers])
     self.assertEqual(jane.clients_with_team_access(), [])
Beispiel #2
0
 def test_userclientpermissions_buid(self):
     """
     Test for UserClientPermissions' buid
     """
     beetee = models.User(username=u'beetee', fullname=u'Beetee')
     district3 = models.Client(title=u'District 3')
     access_permissions = u'siteadmin'
     result = models.UserClientPermissions(
         user=beetee,
         client=district3,
         access_permissions=access_permissions)
     self.assertEqual(result.buid, beetee.buid)
Beispiel #3
0
 def test_userclientpermissions_pickername(self):
     """
     Test for UserClientPermissions' pickername
     """
     finnick = models.User(username=u'finnick', fullname=u'Finnick Odair')
     district4 = models.Client(title=u"District 4")
     access_permissions = u'siteadmin'
     result = models.UserClientPermissions(
         user=finnick,
         client=district4,
         access_permissions=access_permissions)
     self.assertEqual(result.pickername, finnick.pickername)
 def test_AuthToken_get(self):
     """
     Test for retreiving a AuthToken instance given a token
     """
     specialdachs = self.fixtures.specialdachs
     oakley = self.fixtures.oakley
     scope = [u'id']
     dachsadv = models.Client(title=u"Dachshund Adventures", org=specialdachs, confidential=True, website=u"http://dachsadv.com")
     auth_token = models.AuthToken(client=dachsadv, user=oakley, scope=scope)
     token = auth_token.token
     db.session.add(dachsadv, auth_token)
     result = models.AuthToken.get(token)
     self.assertIsInstance(result, models.AuthToken)
     self.assertEqual(result.client, dachsadv)
    def test_client_authtoken_for(self):
        """
        Test for retrieving authtoken for this user and client (only confidential clients)
        """
        # scenario 1: for a client that has confidential=True
        client = self.fixtures.client
        crusoe = self.fixtures.crusoe
        result = client.authtoken_for(crusoe)
        client_token = models.AuthToken(client=client,
                                        user=crusoe,
                                        scope=u'id',
                                        validity=0)
        result = client.authtoken_for(user=crusoe)
        self.assertEqual(client_token, result)
        self.assertIsInstance(result, models.AuthToken)
        assert "Crusoe Celebrity Dachshund" in repr(result)

        # scenario 2: for a client that has confidential=False
        varys = models.User(username=u'varys', fullname=u'Lord Varys')
        house_lannisters = models.Client(title=u'House of Lannisters',
                                         confidential=False,
                                         user=varys,
                                         website=u'houseoflannisters.westeros')
        varys_session = models.UserSession(
            user=varys,
            ipaddr='192.168.1.99',
            user_agent=
            u'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.110 Safari/537.36',
            accessed_at=utcnow())
        lannisters_auth_token = models.AuthToken(client=house_lannisters,
                                                 user=varys,
                                                 scope=u'throne',
                                                 validity=0,
                                                 user_session=varys_session)
        db.session.add_all(
            [varys, house_lannisters, lannisters_auth_token, varys_session])
        db.session.commit()
        result = house_lannisters.authtoken_for(varys,
                                                user_session=varys_session)
        self.assertIsInstance(result, models.AuthToken)
        assert "Lord Varys" in repr(result)