Пример #1
0
 def setUp(self):
     # Mock the DeviceCloudConnector used by auth module to return fake success/failures
     patcher = patch('xbgw_dashboard.libs.digi.auth.DeviceCloudConnector',
                     autospec=True)
     self.mockedConnector = patcher.start()
     self.addCleanup(patcher.stop)
     # By default cloud cred check will return valid, individual test can change this if desired
     mc = self.mockedConnector.return_value
     mc.authenticate.return_value = (True, {})
     self.backend = DeviceCloudBackend()
     self.existing_user = User.objects.create_user(username='******',
                                                   cloud_fqdn='cloud_fqdn')
Пример #2
0
 def setUp(self):
     # Mock the DeviceCloudConnector used by auth module to return fake success/failures
     patcher = patch('xbgw_dashboard.libs.digi.auth.DeviceCloudConnector', autospec=True)
     self.mockedConnector = patcher.start()
     self.addCleanup(patcher.stop)
     # By default cloud cred check will return valid, individual test can change this if desired
     mc = self.mockedConnector.return_value
     mc.authenticate.return_value = (True, {})
     self.backend = DeviceCloudBackend()
     self.existing_user = User.objects.create_user(username='******', cloud_fqdn='cloud_fqdn')
Пример #3
0
class DeviceCloudBackendTest(TestCase):

    def setUp(self):
        # Mock the DeviceCloudConnector used by auth module to return fake success/failures
        patcher = patch('xbgw_dashboard.libs.digi.auth.DeviceCloudConnector', autospec=True)
        self.mockedConnector = patcher.start()
        self.addCleanup(patcher.stop)
        # By default cloud cred check will return valid, individual test can change this if desired
        mc = self.mockedConnector.return_value
        mc.authenticate.return_value = (True, {})
        self.backend = DeviceCloudBackend()
        self.existing_user = User.objects.create_user(username='******', cloud_fqdn='cloud_fqdn')

    def tearDown(self):
        self.existing_user.delete()

    def test_auth_good_credentials(self):
        """
        Test that authentication succeeds for a good set of device cloud credentials
        """
        user = self.backend.authenticate('good#cloud_fqdn', 'creds')
        self.assertIsNotNone(user)

    def test_auth_bad_credentials(self):
        """
        Test that authentication fails for a bad set of device cloud credentials
        """
        mc = self.mockedConnector.return_value
        mc.authenticate.return_value = (False, {})
        user = self.backend.authenticate('bad#cloud_fqdn', 'creds')
        self.assertIsNone(user)

    def test_auth_missing_credentials(self):
        """
        Test that authentication fails when credentials are missing
        """
        user = self.backend.authenticate()
        self.assertIsNone(user)
        user = self.backend.authenticate('a')
        self.assertIsNone(user)

    def test_auth_existing_user(self):
        """
        Test that an existing django user is returned when
        authenticating with good credentials
        """
        starting_user_count = User.objects.count()
        user = self.backend.authenticate('existinguser#cloud_fqdn', 'password')
        ending_user_count = User.objects.count()
        self.assertIsNotNone(user)
        self.assertEqual(user, self.existing_user)
        self.assertEquals(starting_user_count, ending_user_count)

    def test_auth_new_user(self):
        """
        Test that a new django user is created when authenticating
        with good credentials if a matching one doesn't exist
        """
        starting_user_count = User.objects.count()
        user = self.backend.authenticate('newuser#cloud_fqdn', 'password')
        ending_user_count = User.objects.count()
        self.assertIsNotNone(user)
        self.assertNotEqual(user, self.existing_user)
        self.assertEquals(starting_user_count+1, ending_user_count)
Пример #4
0
class DeviceCloudBackendTest(TestCase):
    def setUp(self):
        # Mock the DeviceCloudConnector used by auth module to return fake success/failures
        patcher = patch('xbgw_dashboard.libs.digi.auth.DeviceCloudConnector',
                        autospec=True)
        self.mockedConnector = patcher.start()
        self.addCleanup(patcher.stop)
        # By default cloud cred check will return valid, individual test can change this if desired
        mc = self.mockedConnector.return_value
        mc.authenticate.return_value = (True, {})
        self.backend = DeviceCloudBackend()
        self.existing_user = User.objects.create_user(username='******',
                                                      cloud_fqdn='cloud_fqdn')

    def tearDown(self):
        self.existing_user.delete()

    def test_auth_good_credentials(self):
        """
        Test that authentication succeeds for a good set of device cloud credentials
        """
        user = self.backend.authenticate('good#cloud_fqdn', 'creds')
        self.assertIsNotNone(user)

    def test_auth_bad_credentials(self):
        """
        Test that authentication fails for a bad set of device cloud credentials
        """
        mc = self.mockedConnector.return_value
        mc.authenticate.return_value = (False, {})
        user = self.backend.authenticate('bad#cloud_fqdn', 'creds')
        self.assertIsNone(user)

    def test_auth_missing_credentials(self):
        """
        Test that authentication fails when credentials are missing
        """
        user = self.backend.authenticate()
        self.assertIsNone(user)
        user = self.backend.authenticate('a')
        self.assertIsNone(user)

    def test_auth_existing_user(self):
        """
        Test that an existing django user is returned when
        authenticating with good credentials
        """
        starting_user_count = User.objects.count()
        user = self.backend.authenticate('existinguser#cloud_fqdn', 'password')
        ending_user_count = User.objects.count()
        self.assertIsNotNone(user)
        self.assertEqual(user, self.existing_user)
        self.assertEquals(starting_user_count, ending_user_count)

    def test_auth_new_user(self):
        """
        Test that a new django user is created when authenticating
        with good credentials if a matching one doesn't exist
        """
        starting_user_count = User.objects.count()
        user = self.backend.authenticate('newuser#cloud_fqdn', 'password')
        ending_user_count = User.objects.count()
        self.assertIsNotNone(user)
        self.assertNotEqual(user, self.existing_user)
        self.assertEquals(starting_user_count + 1, ending_user_count)