def test_no_preferred_username(self): """ Ensure the service gracefully handles an inability to extract a username from the id token. """ # with preferred_username: all good authentication = JwtAuthentication() user = authentication.authenticate_credentials({'preferred_username': self.USERNAME}) self.assertEqual(user.username, self.USERNAME) # missing preferred_username: exception authentication = JwtAuthentication() with self.assertRaises(AuthenticationFailed): authentication.authenticate_credentials({})
def test_no_preferred_username(self): """ Ensure the service gracefully handles an inability to extract a username from the id token. """ # with preferred_username: all good authentication = JwtAuthentication() user = authentication.authenticate_credentials( {'preferred_username': self.USERNAME}) self.assertEqual(user.username, self.USERNAME) # missing preferred_username: exception authentication = JwtAuthentication() with self.assertRaises(AuthenticationFailed): authentication.authenticate_credentials({})
def test_admin_user(self): """ Ensure the service gracefully handles an admin role from the id token. """ authentication = JwtAuthentication() user = authentication.authenticate_credentials( { 'preferred_username': self.USERNAME, 'administrator': True } ) self.assertEqual(user.username, self.USERNAME) self.assertEqual(len(user.groups.all()), 1) self.assertEqual(user.groups.all()[0].name, Role.ADMINS)
def test_admin_user(self): """ Ensure the service gracefully handles an admin role from the id token. """ authentication = JwtAuthentication() user = authentication.authenticate_credentials({ 'preferred_username': self.USERNAME, 'administrator': True }) self.assertEqual(user.username, self.USERNAME) self.assertEqual(len(user.groups.all()), 1) self.assertEqual(user.groups.all()[0].name, Role.ADMINS)