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='******')
     jane = models.User(username='******')
     marcus = models.User(username='******')
     volturi = models.Organization(name='volturi', title='The Volturi')
     volturi.owners.users.append(aro)
     volterra = models.AuthClient(
         title='Volterra, Tuscany',
         organization=volturi,
         confidential=True,
         website='volterra.co.it',
     )
     enforcers = models.AuthClient(
         title='Volturi\'s thugs',
         organization=volturi,
         confidential=True,
         website='volturi.co.it',
     )
     volterra_auth_token = models.AuthToken(auth_client=volterra,
                                            user=aro,
                                            scope='teams',
                                            validity=0)
     volterra_auth_token
     enforcers_auth_token = models.AuthToken(auth_client=enforcers,
                                             user=marcus,
                                             scope='teams',
                                             validity=0)
     enforcers_auth_token
     self.assertCountEqual(aro.clients_with_team_access(), [volterra])
     self.assertCountEqual(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='******', fullname="Beetee")
     district3 = models.AuthClient(title='District 3')
     access_permissions = 'siteadmin'
     result = models.AuthClientUserPermissions(
         user=beetee, auth_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='******', fullname="Finnick Odair")
     district4 = models.AuthClient(title="District 4")
     access_permissions = 'siteadmin'
     result = models.AuthClientUserPermissions(
         user=finnick, auth_client=district4, access_permissions=access_permissions
     )
     self.assertEqual(result.pickername, finnick.pickername)
    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
        auth_client = self.fixtures.auth_client
        crusoe = self.fixtures.crusoe
        result = auth_client.authtoken_for(crusoe)
        client_token = models.AuthToken(
            auth_client=auth_client, user=crusoe, scope='id', validity=0
        )
        result = auth_client.authtoken_for(user=crusoe)
        self.assertEqual(client_token, result)
        self.assertIsInstance(result, models.AuthToken)
        assert result.user == crusoe

        # scenario 2: for a client that has confidential=False
        varys = models.User(username='******', fullname='Lord Varys')
        house_lannisters = models.AuthClient(
            title='House of Lannisters',
            confidential=False,
            user=varys,
            website='houseoflannisters.westeros',
        )
        varys_session = models.UserSession(
            user=varys,
            ipaddr='192.168.1.99',
            user_agent='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(
            auth_client=house_lannisters,
            user=varys,
            scope='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" == result.user.fullname
 def test_authtoken_get(self):
     """
     Test for retreiving a AuthToken instance given a token
     """
     specialdachs = self.fixtures.specialdachs
     oakley = self.fixtures.oakley
     scope = ['id']
     dachsadv = models.AuthClient(
         title="Dachshund Adventures",
         organization=specialdachs,
         confidential=True,
         website="http://dachsadv.com",
     )
     auth_token = models.AuthToken(auth_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.auth_client, dachsadv)