Exemple #1
0
    def test_update_project(self):
        # create project
        self.c.post(
            '/project/add/', {'name': 'proj 1', 'description': 'my first project'})

        # update
        # add user-2 as admin, and user-3 as user
        self.c.login(username='******', password='******')
        response = self.c.post('/project/1/update/',
                               {'admin_users': User.objects.get(username='******').id,
                                'user_users': User.objects.get(username='******').id},
                               follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(
            'jenkins_auth/project_detail.html' in get_template_names(response.templates))
        self.assertTrue(self.MESSAGE_3 in str(response.content))

        # check user-2 can now update the project
        self.c.login(username='******', password='******')
        response = self.c.get('/project/1/update/')
        self.assertEquals(response.status_code, 200)
        self.assertTrue(
            'jenkins_auth/project_form_update.html' in get_template_names(response.templates))

        # check user-3 still cannot update the project
        self.c.login(username='******', password='******')
        response = self.c.get('/project/1/update/', follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(
            'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #2
0
 def est_not_jenkins_user(self):
     print("test_normal_user")
     User.objects.create_user("user-1", password="******")
     self.c.login(username='******', password='******')
     response = self.c.get('/user/user-1', follow=True)
     print(get_template_names(response.templates))
     print("xxxxxxxxxxxxxxxxxxxxxxxxxxxx")
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #3
0
 def test_delete_user(self):
     self.c.login(username='******', password='******')
     # delete user-1
     response = self.c.get('/accounts/profile/delete/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'user/profile_confirm_delete.html' in get_template_names(response.templates))
     response = self.c.post('/accounts/profile/delete/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'user/profile_deleted.html' in get_template_names(response.templates))
     self.assertTrue(self.MESSAGE_1 in str(response.content))
Exemple #4
0
 def test_delete_user_with_project(self):
     self.c.login(username='******', password='******')
     # create project
     self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     response = self.c.get('/accounts/profile/delete/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'user/profile_confirm_delete.html' in get_template_names(response.templates))
     # cannot delete user
     response = self.c.post('/accounts/profile/delete/', follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'user/profile.html' in get_template_names(response.templates))
     self.assertTrue(self.ALERT_1 in str(response.content))
Exemple #5
0
 def test_login_post_ok(self):
     User.objects.create_user("user-1", password="******", last_name="1")
     response = self.c.post(
         '/accounts/login/', {'username': '******', 'password': '******'}, follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #6
0
 def test_home_authenticated(self):
     User.objects.create_user("user-1", password="******", last_name="1")
     self.c.login(username='******', password='******')
     response = self.c.get('/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #7
0
 def test_shib_unauthenticated(self):
     persistent_id = 'shib-id'
     response = self.c.get('/accounts/shib/',
                           persistent_id=persistent_id, follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'registration/registration_form_shib.html' in get_template_names(response.templates))
Exemple #8
0
 def test_shib_authenticated_no_profile(self):
     User.objects.create_user("shib-no-profile", password="******")
     self.c.login(username='******', password='******')
     persistent_id = 'shib-no-profile'
     response = self.c.get('/accounts/shib/',
                           persistent_id=persistent_id, follow=True)
     self.assertEquals(response.status_code, 500)
     self.assertTrue('500.html' in get_template_names(response.templates))
Exemple #9
0
 def test_staff_user(self):
     self.c.login(username='******', password='******')
     user = User.objects.get(username='******')
     self.assertFalse(user.is_staff)
     url = '/staff/user/{}/togglestaff/'.format(user.id)
     response = self.c.post(url, follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #10
0
 def test_get_project_unauthorised(self):
     # create project
     self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     # check unauthorised user access
     self.c.login(username='******', password='******')
     response = self.c.get('/project/1/', follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #11
0
 def test_delete_project_by_owner(self):
     # create project
     self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     # add user-2 as admin, and user-3 as user
     self.c.post('/project/1/update/',
                 {'admin_users': User.objects.get(username='******').id,
                  'user_users': User.objects.get(username='******').id})
     # check owner can delete
     self.c.login(username='******', password='******')
     response = self.c.get('/project/1/delete/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/project_confirm_delete.html' in get_template_names(response.templates))
     response = self.c.post('/project/1/delete/', follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
     self.assertTrue(self.MESSAGE_2 in str(response.content))
Exemple #12
0
 def test_create_project_description_too_long(self):
     response = self.c.post(
         '/project/add/',
         {
             'name': 'proj 1',
             'description': '1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901'},
         follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(self.ALERT_2 in str(response.content))
     self.assertTrue(
         'jenkins_auth/project_form.html' in get_template_names(response.templates))
Exemple #13
0
 def test_create_project_duplicate_name(self):
     # create project
     self.c.post('/project/add/',
                 {'name': 'proj 1',
                  'description': 'my first project'})
     response = self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     self.assertEquals(response.status_code, 200)
     self.assertTrue(self.ALERT_1 in str(response.content))
     self.assertTrue(
         'jenkins_auth/project_form.html' in get_template_names(response.templates))
Exemple #14
0
    def test_superuser(self):
        self.c.login(username='******', password='******')
        user = User.objects.get(username='******')
        self.assertFalse(user.is_staff)
        url = '/staff/user/{}/togglestaff/'.format(user.id)

        # toggle on
        response = self.c.post(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('jenkins_auth/staff/account_form.html' in
                        get_template_names(response.templates))
        user = User.objects.get(username='******')
        self.assertTrue(user.is_staff)

        # toggle off
        response = self.c.post(url, follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue('jenkins_auth/staff/account_form.html' in
                        get_template_names(response.templates))
        user = User.objects.get(username='******')
        self.assertFalse(user.is_staff)
Exemple #15
0
 def test_shib_authenticated_good(self):
     shib_user = User.objects.create_user("shib-user", password="******")
     JenkinsUserProfile.objects.create(
         user_id=shib_user.id,
         shib_uid="shib-user")
     self.c.login(username='******', password='******')
     persistent_id = 'shib-user'
     response = self.c.get('/accounts/shib/',
                           persistent_id=persistent_id, follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #16
0
 def test_shib_authenticated_shib_inactive(self):
     shib_user = User.objects.create_user(
         username="******",
         password="******")
     self.c.login(username='******', password="******")
     shib_user.is_active = False
     shib_user.save()
     persistent_id = 'shib-inactive'
     response = self.c.get('/accounts/shib/',
                           persistent_id=persistent_id, follow=True)
     self.assertEquals(response.status_code, 400)
     self.assertTrue(
         'registration/login.html' in get_template_names(response.templates))
Exemple #17
0
 def test_get_project_unauthorised_access(self):
     # create project
     self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     # add admin and user privileges
     self.c.post('/project/1/update/',
                 {'admin_users': User.objects.get(username='******').id,
                  'user_users': User.objects.get(username='******').id})
     # check unauthorised user access
     self.c.login(username='******', password='******')
     response = self.c.get('/project/1/', follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #18
0
    def test_shib_register_get_after_post(self):
        persistent_id = 'shib-id'
        self.c.post('/accounts/shib/register/',
                    {'first_name': 'shi',
                     'last_name': 'bboleth',
                     'email': '*****@*****.**'},
                    persistent_id=persistent_id)

        response = self.c.get(
            '/accounts/shib/register/',
            persistent_id=persistent_id)
        self.assertEquals(response.status_code, 400)
        self.assertTrue(
            'registration/login.html' in get_template_names(response.templates))
Exemple #19
0
 def test_get_project(self):
     # create project
     self.c.post(
         '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
     # retrieve details
     response = self.c.get('/project/1/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/project_detail.html' in get_template_names(response.templates))
     self.assertEquals(response.context['project'].name, 'proj 1')
     self.assertEquals(
         response.context['project'].description,
         'my first project')
     self.assertEquals(response.context['project'].owner.username, 'user-1')
Exemple #20
0
    def test_delete_project_by_admin(self):
        # create project
        self.c.post(
            '/project/add/', {'name': 'proj 1', 'description': 'my first project'})
        # add user-2 as admin, and user-3 as user
        self.c.post('/project/1/update/',
                    {'admin_users': User.objects.get(username='******').id,
                     'user_users': User.objects.get(username='******').id})

        # check user-2 (admin user) cannot delete the project
        self.c.login(username='******', password='******')
        response = self.c.get('/project/1/delete/', follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(
            'jenkins_auth/home.html' in get_template_names(response.templates))
Exemple #21
0
 def test_create_project(self):
     # new project
     response = self.c.post('/project/add/',
                            {'name': 'proj 1',
                             'description': 'my first project'},
                            follow=True)
     # returns project description page
     self.assertEquals(response.status_code, 200)
     self.assertTrue(self.MESSAGE_1 in str(response.content))
     self.assertTrue(
         'jenkins_auth/project_detail.html' in get_template_names(response.templates))
     self.assertEquals(response.context['project'].name, 'proj 1')
     self.assertEquals(
         response.context['project'].description,
         'my first project')
     self.assertEquals(response.context['project'].owner.username, 'user-1')
Exemple #22
0
    def test_shib_register_post(self):
        persistent_id = 'shib-id'
        response = self.c.post('/accounts/shib/register/',
                               {'first_name': 'shi',
                                'last_name': 'bboleth',
                                'email': '*****@*****.**'},
                               persistent_id=persistent_id,
                               follow=True)
        self.assertEquals(response.status_code, 200)
        self.assertTrue(
            'registration/registration_complete.html' in get_template_names(response.templates))
        self.assertTrue(self.MESSAGE_2 in str(response.content))

        shib_user = User.objects.get(username=persistent_id)
        self.assertFalse(shib_user.is_active)
        self.assertFalse(shib_user.has_usable_password())
        self.assertFalse(shib_user.registrationprofile.activated)
        self.assertEqual(shib_user.jenkinsuserprofile.shib_uid, persistent_id)
Exemple #23
0
    def test_shib_register_post_after_post(self):
        persistent_id = 'shib-id'
        self.c.post('/accounts/shib/register/',
                    {'first_name': 'shi',
                     'last_name': 'bboleth',
                     'email': '*****@*****.**'},
                    persistent_id=persistent_id)

        # post the form for 'shib-id' again
        response = self.c.post('/accounts/shib/register/',
                               {'first_name': 'shi',
                                'last_name': 'bboleth',
                                'email': '*****@*****.**'},
                               persistent_id=persistent_id,
                               follow=True)
        self.assertEquals(response.status_code, 400)
        self.assertTrue(
            '400.html' in get_template_names(
                response.templates))
Exemple #24
0
 def test_unknown_user(self):
     self.c.login(username=API_USER, password='******')
     response = self.c.get('/user/unknown')
     self.assertEquals(response.status_code, 404)
     self.assertTrue('404.html' in get_template_names(response.templates))
Exemple #25
0
 def test_in_active_user(self):
     self.c.login(username=API_USER, password='******')
     User.objects.create_user("user-2", password="******", is_active=False)
     response = self.c.get('/user/user-2')
     self.assertEquals(response.status_code, 404)
     self.assertTrue('404.html' in get_template_names(response.templates))
Exemple #26
0
 def test_login_post_unknown_user(self):
     response = self.c.post(
         '/accounts/login/', {'username': '******', 'password': '******'}, follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'registration/login.html' in get_template_names(response.templates))
Exemple #27
0
 def test_login_get(self):
     response = self.c.get('/accounts/login/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'registration/login.html' in get_template_names(response.templates))
Exemple #28
0
 def test_tos_unauthenticated(self):
     response = self.c.get('/tos/')
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'jenkins_auth/tos.html' in get_template_names(response.templates))
Exemple #29
0
 def test_home_unauthenticated(self):
     response = self.c.get('/', follow=True)
     self.assertEquals(response.status_code, 200)
     self.assertTrue(
         'registration/login.html' in get_template_names(response.templates))