|
Pierre-Yves Chibon |
893d4f |
# -*- coding: utf-8 -*-
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
"""
|
|
Pierre-Yves Chibon |
893d4f |
(c) 2018 - Copyright Red Hat Inc
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
Authors:
|
|
Pierre-Yves Chibon |
893d4f |
Pierre-Yves Chibon <pingou@pingoured.fr></pingou@pingoured.fr>
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
"""
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
import datetime
|
|
Pierre-Yves Chibon |
893d4f |
import os
|
|
Pierre-Yves Chibon |
893d4f |
import shutil
|
|
Pierre-Yves Chibon |
893d4f |
import sys
|
|
Pierre-Yves Chibon |
893d4f |
import tempfile
|
|
Pierre-Yves Chibon |
893d4f |
import time
|
|
Pierre-Yves Chibon |
893d4f |
import unittest
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
import pygit2
|
|
Pierre-Yves Chibon |
893d4f |
import six
|
|
Pierre-Yves Chibon |
893d4f |
from mock import patch, MagicMock, call
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
sys.path.insert(
|
|
Pierre-Yves Chibon |
73d120 |
0, os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.plugins
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.query
|
|
Pierre-Yves Chibon |
930073 |
import pagure.lib.tasks_mirror
|
|
Pierre-Yves Chibon |
893d4f |
import tests
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
import pagure.lib.tasks_mirror
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
class PagureLibTaskMirrortests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
893d4f |
""" Tests for pagure.lib.task_mirror """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
maxDiff = None
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def setUp(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
893d4f |
super(PagureLibTaskMirrortests, self).setUp()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["REQUESTS_FOLDER"] = None
|
|
Pierre-Yves Chibon |
73d120 |
self.sshkeydir = os.path.join(self.path, "sshkeys")
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["MIRROR_SSHKEYS_FOLDER"] = self.sshkeydir
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_create_ssh_key(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the _create_ssh_key method. """
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertFalse(os.path.exists(self.sshkeydir))
|
|
Pierre-Yves Chibon |
893d4f |
os.mkdir(self.sshkeydir)
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
keyfile = os.path.join(self.sshkeydir, "testkey")
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror._create_ssh_key(keyfile)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["testkey", "testkey.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_setup_mirroring(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the setup_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertFalse(os.path.exists(self.sshkeydir))
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# Install the plugin at the DB level
|
|
Pierre-Yves Chibon |
73d120 |
plugin = pagure.lib.plugins.get_plugin("Mirroring")
|
|
Pierre-Yves Chibon |
893d4f |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
893d4f |
dbobj.project_id = project.id
|
|
Pierre-Yves Chibon |
893d4f |
self.session.add(dbobj)
|
|
Pierre-Yves Chibon |
893d4f |
self.session.commit()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring(
|
|
Pierre-Yves Chibon |
73d120 |
username=None, namespace=None, name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(project.mirror_hook.public_key.startswith("ssh-rsa "))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_setup_mirroring_ssh_folder_exists_wrong_permissions(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the setup_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
os.makedirs(self.sshkeydir)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# Install the plugin at the DB level
|
|
Pierre-Yves Chibon |
73d120 |
plugin = pagure.lib.plugins.get_plugin("Mirroring")
|
|
Pierre-Yves Chibon |
893d4f |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
893d4f |
dbobj.project_id = project.id
|
|
Pierre-Yves Chibon |
893d4f |
self.session.add(dbobj)
|
|
Pierre-Yves Chibon |
893d4f |
self.session.commit()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
self.assertRaises(
|
|
Pierre-Yves Chibon |
893d4f |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring,
|
|
Pierre-Yves Chibon |
893d4f |
username=None,
|
|
Pierre-Yves Chibon |
893d4f |
namespace=None,
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_setup_mirroring_ssh_folder_symlink(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the setup_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
os.symlink(self.path, self.sshkeydir)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
893d4f |
sorted(os.listdir(self.sshkeydir)),
|
|
Pierre-Yves Chibon |
73d120 |
[
|
|
Pierre-Yves Chibon |
73d120 |
"attachments",
|
|
Pierre-Yves Chibon |
73d120 |
"config",
|
|
Pierre-Yves Chibon |
73d120 |
"forks",
|
|
Pierre-Yves Chibon |
73d120 |
"releases",
|
|
Pierre-Yves Chibon |
73d120 |
"remotes",
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"sshkeys",
|
|
Pierre-Yves Chibon |
73d120 |
],
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# Install the plugin at the DB level
|
|
Pierre-Yves Chibon |
73d120 |
plugin = pagure.lib.plugins.get_plugin("Mirroring")
|
|
Pierre-Yves Chibon |
893d4f |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
893d4f |
dbobj.project_id = project.id
|
|
Pierre-Yves Chibon |
893d4f |
self.session.add(dbobj)
|
|
Pierre-Yves Chibon |
893d4f |
self.session.commit()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
self.assertRaises(
|
|
Pierre-Yves Chibon |
893d4f |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring,
|
|
Pierre-Yves Chibon |
893d4f |
username=None,
|
|
Pierre-Yves Chibon |
893d4f |
namespace=None,
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
893d4f |
sorted(os.listdir(self.sshkeydir)),
|
|
Pierre-Yves Chibon |
73d120 |
[
|
|
Pierre-Yves Chibon |
73d120 |
"attachments",
|
|
Pierre-Yves Chibon |
73d120 |
"config",
|
|
Pierre-Yves Chibon |
73d120 |
"forks",
|
|
Pierre-Yves Chibon |
73d120 |
"releases",
|
|
Pierre-Yves Chibon |
73d120 |
"remotes",
|
|
Pierre-Yves Chibon |
73d120 |
"repos",
|
|
Pierre-Yves Chibon |
73d120 |
"sshkeys",
|
|
Pierre-Yves Chibon |
73d120 |
],
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("os.getuid", MagicMock(return_value=450))
|
|
Pierre-Yves Chibon |
893d4f |
def test_setup_mirroring_ssh_folder_owner(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the setup_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
os.makedirs(self.sshkeydir, mode=0o700)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# Install the plugin at the DB level
|
|
Pierre-Yves Chibon |
73d120 |
plugin = pagure.lib.plugins.get_plugin("Mirroring")
|
|
Pierre-Yves Chibon |
893d4f |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
893d4f |
dbobj.project_id = project.id
|
|
Pierre-Yves Chibon |
893d4f |
self.session.add(dbobj)
|
|
Pierre-Yves Chibon |
893d4f |
self.session.commit()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
self.assertRaises(
|
|
Pierre-Yves Chibon |
893d4f |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring,
|
|
Pierre-Yves Chibon |
893d4f |
username=None,
|
|
Pierre-Yves Chibon |
893d4f |
namespace=None,
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
class PagureLibTaskMirrorSetuptests(tests.Modeltests):
|
|
Pierre-Yves Chibon |
893d4f |
""" Tests for pagure.lib.task_mirror """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
maxDiff = None
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def setUp(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Set up the environnment, ran before every tests. """
|
|
Pierre-Yves Chibon |
893d4f |
super(PagureLibTaskMirrorSetuptests, self).setUp()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["REQUESTS_FOLDER"] = None
|
|
Pierre-Yves Chibon |
73d120 |
self.sshkeydir = os.path.join(self.path, "sshkeys")
|
|
Pierre-Yves Chibon |
73d120 |
pagure.config.config["MIRROR_SSHKEYS_FOLDER"] = self.sshkeydir
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
tests.create_projects(self.session)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# Install the plugin at the DB level
|
|
Pierre-Yves Chibon |
73d120 |
plugin = pagure.lib.plugins.get_plugin("Mirroring")
|
|
Pierre-Yves Chibon |
893d4f |
dbobj = plugin.db_object()
|
|
Pierre-Yves Chibon |
73d120 |
dbobj.target = "ssh://user@localhost.localdomain/foobar.git"
|
|
Pierre-Yves Chibon |
893d4f |
dbobj.project_id = project.id
|
|
Pierre-Yves Chibon |
893d4f |
self.session.add(dbobj)
|
|
Pierre-Yves Chibon |
893d4f |
self.session.commit()
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring(
|
|
Pierre-Yves Chibon |
73d120 |
username=None, namespace=None, name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_setup_mirroring_twice(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the setup_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
before_key = project.mirror_hook.public_key
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(project.mirror_hook.public_key.startswith("ssh-rsa "))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
self.assertRaises(
|
|
Pierre-Yves Chibon |
893d4f |
pagure.exceptions.PagureException,
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.setup_mirroring,
|
|
Pierre-Yves Chibon |
893d4f |
username=None,
|
|
Pierre-Yves Chibon |
893d4f |
namespace=None,
|
|
Pierre-Yves Chibon |
73d120 |
name="test",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(project.mirror_hook.public_key, before_key)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
def test_teardown_mirroring(self):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the teardown_mirroring method. """
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(project.mirror_hook.public_key.startswith("ssh-rsa "))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.teardown_mirroring(
|
|
Pierre-Yves Chibon |
73d120 |
username=None, namespace=None, name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
930073 |
self.session = pagure.lib.query.create_session(self.dbpath)
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(sorted(os.listdir(self.sshkeydir)), [])
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
@patch("pagure.lib.git.read_git_lines")
|
|
Pierre-Yves Chibon |
73d120 |
def test_mirror_project(self, rgl):
|
|
Pierre-Yves Chibon |
893d4f |
""" Test the mirror_project method. """
|
|
Pierre-Yves Chibon |
73d120 |
rgl.return_value = ("stdout", "stderr")
|
|
Pierre-Yves Chibon |
73d120 |
tests.create_projects_git(os.path.join(self.path, "repos"), bare=True)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# before
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(project.mirror_hook.public_key.startswith("ssh-rsa "))
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
pagure.lib.tasks_mirror.mirror_project(
|
|
Pierre-Yves Chibon |
73d120 |
username=None, namespace=None, name="test"
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
# after
|
|
Pierre-Yves Chibon |
893d4f |
self.assertEqual(
|
|
Pierre-Yves Chibon |
73d120 |
sorted(os.listdir(self.sshkeydir)), ["test", "test.pub"]
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
73d120 |
project = pagure.lib.query.get_authorized_project(self.session, "test")
|
|
Pierre-Yves Chibon |
893d4f |
self.assertIsNotNone(project.mirror_hook.public_key)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertTrue(project.mirror_hook.public_key.startswith("ssh-rsa "))
|
|
Pierre-Yves Chibon |
73d120 |
|
|
Pierre-Yves Chibon |
73d120 |
ssh_script = os.path.abspath(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.join(
|
|
Pierre-Yves Chibon |
73d120 |
os.path.dirname(os.path.abspath(__file__)),
|
|
Pierre-Yves Chibon |
73d120 |
"..",
|
|
Pierre-Yves Chibon |
73d120 |
"pagure",
|
|
Pierre-Yves Chibon |
73d120 |
"lib",
|
|
Pierre-Yves Chibon |
73d120 |
"ssh_script.sh",
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
73d120 |
)
|
|
Pierre-Yves Chibon |
605eaa |
|
|
Pierre-Yves Chibon |
893d4f |
calls = [
|
|
Pierre-Yves Chibon |
893d4f |
call(
|
|
Pierre-Yves Chibon |
73d120 |
[
|
|
Pierre-Yves Chibon |
73d120 |
"push",
|
|
Pierre-Yves Chibon |
73d120 |
"--mirror",
|
|
Pierre-Yves Chibon |
73d120 |
"ssh://user@localhost.localdomain/foobar.git",
|
|
Pierre-Yves Chibon |
73d120 |
],
|
|
Pierre-Yves Chibon |
73d120 |
abspath=os.path.join(self.path, "repos", "test.git"),
|
|
Pierre-Yves Chibon |
893d4f |
env={
|
|
Pierre-Yves Chibon |
73d120 |
"GIT_SSH": ssh_script,
|
|
Pierre-Yves Chibon |
73d120 |
"SSHKEY": "%s/sshkeys/test" % self.path,
|
|
Pierre-Yves Chibon |
893d4f |
},
|
|
Pierre-Yves Chibon |
73d120 |
error=True,
|
|
Pierre-Yves Chibon |
893d4f |
)
|
|
Pierre-Yves Chibon |
893d4f |
]
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
605eaa |
self.assertEqual(rgl.call_count, 1)
|
|
Pierre-Yves Chibon |
73d120 |
self.assertEqual(calls, rgl.mock_calls)
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
893d4f |
|
|
Pierre-Yves Chibon |
73d120 |
if __name__ == "__main__":
|
|
Pierre-Yves Chibon |
893d4f |
unittest.main(verbosity=2)
|