Exemple #1
0
    def test_keep_and_not_delete_repository(self):
        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        repo = Repository(project=self.project, url='')
        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)
                repo.save()

        response = self.client.post(reverse('project:gitintegration:delete',
                                            kwargs={
                                                'project':
                                                self.project.name_short,
                                                'repository': '1'
                                            }), {'keep': 'true'},
                                    follow=True)
        self.assertEqual(self.project.repos.count(), 1)

        # delete the key files from the server
        os.unlink(repo.rsa_priv_path.path)
        os.unlink(repo.rsa_pub_path.path)
        # delete the key files locally
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)
Exemple #2
0
    def test_path_validator(self):
        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                response = self.client.post(reverse(
                    'project:gitintegration:create',
                    kwargs={'project': self.project.name_short}), {
                        'url': 'blubber-url',
                        'rsa_priv_path': f1,
                        'rsa_pub_path': f2,
                    },
                                            follow=True)

        repo = Repository(project=self.project, url='')

        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)

                tests = [
                    '', 'blub', 'bla://great.url/path',
                    'bla://../../letstestthis', REPOSITORY_ROOT, BASE_DIR,
                    os.path.join(REPOSITORY_ROOT, 'foreignRepo_1'),
                    os.path.join(BASE_DIR, 'dir'), '/opt/repo_path'
                ]

                for t in tests:
                    repo.url = t
                    self.assertRaises(ValidationError, repo.clean_fields)
                    try:
                        repo.clean_fields()
                    except ValidationError as e:
                        self.assertIn('url', e.message_dict.keys())

        # cleanup tmp-files
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)
Exemple #3
0
    def test_detail_allowed_for_developer(self):
        self.project.manager.clear()
        self.project.developer.clear()
        self.project.developer.add(self.user)
        self.project.save()

        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        repo = Repository(project=self.project, url='blub-url')

        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)
                repo.save()

        response = self.client.get(reverse('project:gitintegration:detail',
                                           kwargs={
                                               'project':
                                               self.project.name_short,
                                               'repository': '1'
                                           }),
                                   follow=True)
        self.assertEqual(response.context_data.get('repository'), repo)
        self.assertEqual(type(response.context_data.get('view')),
                         RepositoryDetailView)
        self.assertNotContains(
            response, "Your account doesn't have access to this page")
        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                self.assertContains(response, str(f2.read()))
                self.assertNotContains(response, str(f1.read()))

        # delete the key files from the server
        os.unlink(repo.rsa_priv_path.path)
        os.unlink(repo.rsa_pub_path.path)
        # delete the key files locally
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)
Exemple #4
0
    def test_views_not_allowed_for_non_project_member(self):
        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        repo = Repository(project=self.project, url='blub-url')
        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)
                repo.save()

        response = self.client.get(reverse(
            'project:gitintegration:list',
            kwargs={'project': self.project.name_short}),
                                   follow=True)
        self.assertEqual(response.status_code, 404)

        response = self.client.get(reverse('project:gitintegration:detail',
                                           kwargs={
                                               'project':
                                               self.project.name_short,
                                               'repository': repo.pk
                                           }),
                                   follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Your account doesn't have access to this page")

        response = self.client.post(reverse(
            'project:gitintegration:create',
            kwargs={'project': self.project.name_short}), {
                'url': 'blubber',
                'rsa_priv_path': '',
                'rsa_pub_path': '',
            },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Your account doesn't have access to this page")

        response = self.client.post(reverse('project:gitintegration:edit',
                                            kwargs={
                                                'project':
                                                self.project.name_short,
                                                'repository': repo.pk
                                            }), {
                                                'url': 'blubber',
                                                'rsa_priv_path': '',
                                                'rsa_pub_path': '',
                                            },
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Your account doesn't have access to this page")

        response = self.client.post(reverse('project:gitintegration:delete',
                                            kwargs={
                                                'project':
                                                self.project.name_short,
                                                'repository': repo.pk
                                            }), {'delete': 'true'},
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Your account doesn't have access to this page")

        # delete the key files from the server
        os.unlink(repo.rsa_priv_path.path)
        os.unlink(repo.rsa_pub_path.path)
        # delete the key files locally
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)
Exemple #5
0
    def test_add_edit_delete_not_allowed_for_developer(self):
        self.project.manager.clear()
        self.project.developer.add(self.user)
        self.project.save()

        response = self.client.post(reverse(
            'project:gitintegration:create',
            kwargs={'project': self.project.name_short}), {
                'url': 'blubber-url',
                'rsa_priv_path': '',
                'rsa_pub_path': '',
            },
                                    follow=True)
        self.assertContains(response,
                            "Your account doesn't have access to this page")
        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 0)

        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        repo = Repository(project=self.project, url='blub-url')

        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)
                repo.save()

        response = self.client.post(reverse('project:gitintegration:edit',
                                            kwargs={
                                                'project':
                                                self.project.name_short,
                                                'repository': '1'
                                            }), {
                                                'url': 'blubber',
                                                'rsa_priv_path': '',
                                                'rsa_pub_path': '',
                                            },
                                    follow=True)
        self.assertContains(response,
                            "Your account doesn't have access to this page")
        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 1)
        self.assertEqual(self.project.repos.first().url, 'blub-url')

        response = self.client.post(reverse('project:gitintegration:delete',
                                            kwargs={
                                                'project':
                                                self.project.name_short,
                                                'repository': '1'
                                            }), {'delete': 'true'},
                                    follow=True)
        self.assertEqual(response.status_code, 200)
        self.assertContains(response,
                            "Your account doesn't have access to this page")
        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 1)
        self.assertEqual(self.project.repos.first().url, 'blub-url')

        # delete the key files from the server
        repo = self.project.repos.first()
        os.unlink(repo.rsa_priv_path.path)
        os.unlink(repo.rsa_pub_path.path)
        # delete the key files locally
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)
Exemple #6
0
    def test_add_edit_delete_not_allowed_for_developer(self):
        self.project.manager.clear()
        self.project.developer.add(self.user)
        self.project.save()

        user_doesnt_pass_test_and_gets_404(
            self,
            'project:gitintegration:create',
            address_kwargs={'project': self.project.name_short},
            get_kwargs={
                'url': 'blubber-url',
                'rsa_priv_path': '',
                'rsa_pub_path': ''
            })

        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 0)

        filecontent1 = 'Hello World File 1'
        tmp1 = tempfile.NamedTemporaryFile(delete=False)
        tmp1.write(filecontent1.encode())
        tmp1.close()
        filecontent2 = 'Hello World File 2'
        tmp2 = tempfile.NamedTemporaryFile(delete=False)
        tmp2.write(filecontent2.encode())
        tmp2.close()

        repo = Repository(project=self.project, url='blub-url')

        with open(tmp1.name, 'r') as f1:
            with open(tmp2.name, 'r') as f2:
                repo.rsa_priv_path = File(f1)
                repo.rsa_pub_path = File(f2)
                repo.save()

        user_doesnt_pass_test_and_gets_404(self,
                                           'project:gitintegration:edit',
                                           address_kwargs={
                                               'project':
                                               self.project.name_short,
                                               'repository': '1'
                                           },
                                           get_kwargs={
                                               'url': 'blubber',
                                               'rsa_priv_path': '',
                                               'rsa_pub_path': '',
                                           })

        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 1)
        self.assertEqual(self.project.repos.first().url, 'blub-url')

        user_doesnt_pass_test_and_gets_404(self,
                                           'project:gitintegration:delete',
                                           address_kwargs={
                                               'project':
                                               self.project.name_short,
                                               'repository': '1'
                                           },
                                           get_kwargs={'delete': 'true'})
        self.project.refresh_from_db()
        self.assertEqual(self.project.repos.count(), 1)
        self.assertEqual(self.project.repos.first().url, 'blub-url')

        # delete the key files from the server
        repo = self.project.repos.first()
        os.unlink(repo.rsa_priv_path.path)
        os.unlink(repo.rsa_pub_path.path)
        # delete the key files locally
        os.unlink(tmp1.name)
        os.unlink(tmp2.name)