Example #1
0
    def setUp(self):
        self.updown_auth_manager = JWTUpDownAuthManager("secret",
                                                        timedelta(seconds=1))

        self.storage_dir = temp_folder()
        self.service = FileUploadDownloadService(self.updown_auth_manager, self.storage_dir)
        self.disk_path = os.path.join(self.storage_dir, "dir", "other")
        self.relative_file_path = "dir/other/thefile.txt"
        self.absolute_file_path = os.path.join(self.disk_path, "thefile.txt")
        mkdir(self.disk_path)
        self.content = "the content"
Example #2
0
class FileUploadDownloadServiceTest(unittest.TestCase):
    def setUp(self):
        self.updown_auth_manager = JWTUpDownAuthManager(
            "secret", timedelta(seconds=1))

        self.storage_dir = temp_folder()
        self.service = FileUploadDownloadService(self.updown_auth_manager,
                                                 self.storage_dir)
        self.disk_path = os.path.join(self.storage_dir, "dir", "other")
        self.relative_file_path = "dir/other/thefile.txt"
        self.absolute_file_path = os.path.join(self.disk_path, "thefile.txt")
        mkdir(self.disk_path)
        self.content = "the content"

    def test_file_download(self):
        save(os.path.join(self.disk_path, "thefile.txt"), self.content)
        token = self.updown_auth_manager.get_token_for(self.relative_file_path,
                                                       "pepe",
                                                       len(self.content))
        path_to_file = self.service.get_file_path(self.relative_file_path,
                                                  token)

        self.assertEquals(path_to_file, self.absolute_file_path)

        readed_content = load(self.absolute_file_path)
        self.assertEquals(readed_content, self.content)

        # Expire token
        sleep(2)
        self.assertRaises(NotFoundException, self.service.get_file_path,
                          self.relative_file_path, token)

    def test_file_upload(self):
        token = self.updown_auth_manager.get_token_for(self.relative_file_path,
                                                       "pepe",
                                                       len(self.content))

        file_saver = MockFileSaver("thefile.txt", self.content)
        self.assertFalse(os.path.exists(self.absolute_file_path))
        self.service.put_file(file_saver, self.absolute_file_path, token,
                              len(self.content))

        self.assertTrue(os.path.exists(self.absolute_file_path))

        # Raises if wrong size
        self.assertRaises(RequestErrorException, self.service.put_file,
                          file_saver, self.absolute_file_path, token,
                          len(self.content) + 1)
Example #3
0
    def __init__(self):
        user_folder = conan_expand_user("~")
        server_folder = os.path.join(user_folder, '.conan_server')

        server_config = migrate_and_get_server_config(user_folder)
        custom_auth = server_config.custom_authenticator
        if custom_auth:
            authenticator = load_authentication_plugin(server_folder,
                                                       custom_auth)
        else:
            authenticator = BasicAuthenticator(dict(server_config.users))

        authorizer = BasicAuthorizer(server_config.read_permissions,
                                     server_config.write_permissions)
        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)

        file_manager = get_file_manager(
            server_config, updown_auth_manager=updown_auth_manager)

        search_adapter = DiskSearchAdapter()
        search_manager = DiskSearchManager(
            SimplePaths(server_config.disk_storage_path), search_adapter)

        server_capabilities = SERVER_CAPABILITIES
        self.ra = ConanServer(server_config.port, credentials_manager,
                              updown_auth_manager, authorizer, authenticator,
                              file_manager, search_manager,
                              Version(SERVER_VERSION),
                              Version(MIN_CLIENT_COMPATIBLE_VERSION),
                              server_capabilities)
Example #4
0
    def __init__(self):
        user_folder = conan_expand_user("~")
        server_folder = os.path.join(user_folder, '.conan_server')

        server_config = migrate_and_get_server_config(user_folder)
        custom_auth = server_config.custom_authenticator
        if custom_auth:
            authenticator = load_authentication_plugin(server_folder, custom_auth)
        else:
            authenticator = BasicAuthenticator(dict(server_config.users))

        authorizer = BasicAuthorizer(server_config.read_permissions,
                                     server_config.write_permissions)
        credentials_manager = JWTCredentialsManager(server_config.jwt_secret,
                                                    server_config.jwt_expire_time)

        updown_auth_manager = JWTUpDownAuthManager(server_config.updown_secret,
                                                   server_config.authorize_timeout)

        server_store = get_server_store(server_config.disk_storage_path,
                                        server_config.public_url,
                                        updown_auth_manager=updown_auth_manager)

        server_capabilities = SERVER_CAPABILITIES
        server_capabilities.append(REVISIONS)

        self.ra = ConanServer(server_config.port, credentials_manager, updown_auth_manager,
                              authorizer, authenticator, server_store,
                              Version(SERVER_VERSION), Version(MIN_CLIENT_COMPATIBLE_VERSION),
                              server_capabilities, only_v1=False)
Example #5
0
    def setUp(self):
        self.conan_reference = ConanFileReference.loads(
            "openssl/2.0.3@lasote/testing")
        self.package_reference = PackageReference(self.conan_reference,
                                                  "123123123")
        self.tmp_dir = temp_folder()

        read_perms = [("*/*@*/*", "*")]
        write_perms = []
        authorizer = BasicAuthorizer(read_perms, write_perms)

        self.fake_url = "http://url"
        updown_auth_manager = JWTUpDownAuthManager("secret",
                                                   timedelta(seconds=200))
        adapter = DiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager)
        self.paths = SimplePaths(self.tmp_dir)
        self.file_manager = FileManager(self.paths, adapter)

        self.service = ConanService(authorizer, self.file_manager, "lasote")

        files = hello_source_files("test")
        save_files(self.paths.export(self.conan_reference), files)
        self.conan_digest = FileTreeManifest.create(
            self.paths.export(self.conan_reference))
        conan_digest_path = os.path.join(
            self.paths.export(self.conan_reference), CONAN_MANIFEST)
        save(conan_digest_path, str(self.conan_digest))

        files = hello_source_files("package")
        save_files(self.paths.package(self.package_reference), files)
Example #6
0
    def setUp(self):
        self.ref = ConanFileReference.loads("openssl/2.0.3@lasote/testing#%s" % DEFAULT_REVISION_V1)

        self.pref = PackageReference(self.ref, "123123123", DEFAULT_REVISION_V1)
        self.tmp_dir = temp_folder()

        read_perms = [("*/*@*/*", "*")]
        write_perms = []
        authorizer = BasicAuthorizer(read_perms, write_perms)

        self.fake_url = "http://url"
        updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=200))
        adapter = ServerDiskAdapter(self.fake_url, self.tmp_dir, updown_auth_manager)
        self.server_store = ServerStore(storage_adapter=adapter)
        self.service = ConanService(authorizer, self.server_store, "lasote")
        self.search_service = SearchService(authorizer, self.server_store, "lasote")

        files = hello_source_files("test")
        save_files(self.server_store.export(self.ref), files)
        self.server_store.update_last_revision(self.ref)
        self.conan_digest = FileTreeManifest.create(self.server_store.export(self.ref))
        conan_digest_path = os.path.join(self.server_store.export(self.ref), CONAN_MANIFEST)
        save(conan_digest_path, str(self.conan_digest))

        files = hello_source_files("package")
        save_files(self.server_store.package(self.pref), files)
Example #7
0
    def __init__(self, base_path=None, read_permissions=None,
                 write_permissions=None, users=None, base_url=None, plugins=None,
                 server_version=None,
                 min_client_compatible_version=None,
                 server_capabilities=None):

        plugins = plugins or []
        if not base_path:
            base_path = temp_folder()

        if server_capabilities is None:
            server_capabilities = SERVER_CAPABILITIES  # Default enabled

        if not os.path.exists(base_path):
            raise Exception("Base path not exist! %s")

        # Define storage_folder, if not, it will be readed from conf file and pointed to real user home
        self.storage_folder = os.path.join(base_path, ".conan_server", "data")
        mkdir(self.storage_folder)

        server_config = migrate_and_get_server_config(base_path, self.storage_folder)

        if TestServerLauncher.port == 0:
            TestServerLauncher.port = server_config.port

        # Encode and Decode signature for Upload and Download service
        updown_auth_manager = JWTUpDownAuthManager(server_config.updown_secret,
                                                   server_config.authorize_timeout)
        self.file_manager = get_file_manager(server_config, public_url=base_url,
                                             updown_auth_manager=updown_auth_manager)

        self.search_manager = DiskSearchManager(SimplePaths(server_config.disk_storage_path))
        # Prepare some test users
        if not read_permissions:
            read_permissions = server_config.read_permissions
            read_permissions.append(("private_library/1.0.0@private_user/testing", "*"))
            read_permissions.append(("*/*@*/*", "*"))

        if not write_permissions:
            write_permissions = server_config.write_permissions

        if not users:
            users = dict(server_config.users)

        users[TESTING_REMOTE_PRIVATE_USER] = TESTING_REMOTE_PRIVATE_PASS

        authorizer = BasicAuthorizer(read_permissions, write_permissions)
        authenticator = BasicAuthenticator(users)
        credentials_manager = JWTCredentialsManager(server_config.jwt_secret,
                                                    server_config.jwt_expire_time)

        logger.debug("Storage path: %s" % self.storage_folder)
        self.port = TestServerLauncher.port

        self.ra = ConanServer(self.port, credentials_manager, updown_auth_manager,
                              authorizer, authenticator, self.file_manager, self.search_manager,
                              server_version, min_client_compatible_version,
                              server_capabilities)
        for plugin in plugins:
            self.ra.api_v1.install(plugin)
Example #8
0
    def __init__(self):
        user_folder = conan_expand_user("~")

        server_config = migrate_and_get_server_config(user_folder)

        authorizer = BasicAuthorizer(server_config.read_permissions,
                                     server_config.write_permissions)
        authenticator = BasicAuthenticator(dict(server_config.users))

        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)

        file_manager = get_file_manager(
            server_config, updown_auth_manager=updown_auth_manager)

        search_adapter = DiskSearchAdapter()
        search_manager = DiskSearchManager(
            SimplePaths(server_config.disk_storage_path), search_adapter)
        self.ra = ConanServer(server_config.port, server_config.ssl_enabled,
                              credentials_manager, updown_auth_manager,
                              authorizer, authenticator, file_manager,
                              search_manager, Version(SERVER_VERSION),
                              Version(MIN_CLIENT_COMPATIBLE_VERSION))
Example #9
0
    def __init__(self,
                 base_path=None,
                 read_permissions=None,
                 write_permissions=None,
                 users=None,
                 base_url=None,
                 plugins=None,
                 server_capabilities=None):

        plugins = plugins or []
        if not base_path:
            base_path = temp_folder()

        if not os.path.exists(base_path):
            raise Exception("Base path not exist! %s")

        self._base_path = base_path

        server_config = migrate_and_get_server_config(base_path)
        if server_capabilities is None:
            server_capabilities = set(SERVER_CAPABILITIES)

        if TestServerLauncher.port == 0:
            TestServerLauncher.port = server_config.port

        # Encode and Decode signature for Upload and Download service
        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)
        base_url = base_url or server_config.public_url
        self.server_store = get_server_store(server_config.disk_storage_path,
                                             base_url, updown_auth_manager)

        # Prepare some test users
        if not read_permissions:
            read_permissions = server_config.read_permissions
            read_permissions.append(
                ("private_library/1.0.0@private_user/testing", "*"))
            read_permissions.append(("*/*@*/*", "*"))

        if not write_permissions:
            write_permissions = server_config.write_permissions

        if not users:
            users = dict(server_config.users)

        users[TESTING_REMOTE_PRIVATE_USER] = TESTING_REMOTE_PRIVATE_PASS

        authorizer = BasicAuthorizer(read_permissions, write_permissions)
        authenticator = BasicAuthenticator(users)
        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        self.port = TestServerLauncher.port
        self.ra = ConanServer(self.port, credentials_manager,
                              updown_auth_manager, authorizer, authenticator,
                              self.server_store, server_capabilities)
        for plugin in plugins:
            self.ra.api_v1.install(plugin)
            self.ra.api_v2.install(plugin)
Example #10
0
class FileUploadDownloadServiceTest(unittest.TestCase):
    def setUp(self):
        self.updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=1))

        self.storage_dir = temp_folder()
        self.service = FileUploadDownloadService(self.updown_auth_manager, self.storage_dir)
        self.disk_path = os.path.join(self.storage_dir, "dir", "other")
        self.relative_file_path = "dir/other/thefile.txt"
        self.absolute_file_path = os.path.join(self.disk_path, "thefile.txt")
        mkdir(self.disk_path)
        self.content = "the content"

    def test_file_download(self):
        save(os.path.join(self.disk_path, "thefile.txt"), self.content)
        token = self.updown_auth_manager.get_token_for(self.relative_file_path, "pepe", len(self.content))
        path_to_file = self.service.get_file_path(self.relative_file_path, token)

        self.assertEquals(path_to_file, self.absolute_file_path)

        readed_content = load(self.absolute_file_path)
        self.assertEquals(readed_content, self.content)

        # Expire token
        sleep(2)
        self.assertRaises(NotFoundException, self.service.get_file_path, self.relative_file_path, token)

    def test_file_upload(self):
        token = self.updown_auth_manager.get_token_for(self.relative_file_path, "pepe", len(self.content))

        file_saver = MockFileSaver("thefile.txt", self.content)
        self.assertFalse(os.path.exists(self.absolute_file_path))
        self.service.put_file(file_saver, self.absolute_file_path, token, len(self.content))

        self.assertTrue(os.path.exists(self.absolute_file_path))

        # Raises if wrong size
        self.assertRaises(
            RequestErrorException,
            self.service.put_file,
            file_saver,
            self.absolute_file_path,
            token,
            len(self.content) + 1,
        )
Example #11
0
    def setUp(self):
        self.updown_auth_manager = JWTUpDownAuthManager("secret", timedelta(seconds=1))

        self.storage_dir = temp_folder()
        self.service = FileUploadDownloadService(self.updown_auth_manager, self.storage_dir)
        self.disk_path = os.path.join(self.storage_dir, "dir", "other")
        self.relative_file_path = "dir/other/thefile.txt"
        self.absolute_file_path = os.path.join(self.disk_path, "thefile.txt")
        mkdir(self.disk_path)
        self.content = "the content"
Example #12
0
    def __init__(self, force_migration=False, server_dir=None):
        if sys.version_info.major == 2:
            raise Exception("The conan_server needs Python>=3 for running")
        self.force_migration = force_migration
        if server_dir:
            user_folder = server_folder = server_dir
        else:
            user_folder = conan_expand_user("~")
            server_folder = os.path.join(user_folder, '.conan_server')

        server_config = migrate_and_get_server_config(user_folder,
                                                      self.force_migration,
                                                      server_dir is not None)
        custom_auth = server_config.custom_authenticator
        if custom_auth:
            authenticator = load_authentication_plugin(server_folder,
                                                       custom_auth)
        else:
            authenticator = BasicAuthenticator(dict(server_config.users))

        authorizer = BasicAuthorizer(server_config.read_permissions,
                                     server_config.write_permissions)
        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)

        server_store = get_server_store(
            server_config.disk_storage_path,
            server_config.public_url,
            updown_auth_manager=updown_auth_manager)

        server_capabilities = SERVER_CAPABILITIES
        server_capabilities.append(REVISIONS)

        self.server = ConanServer(server_config.port, credentials_manager,
                                  updown_auth_manager, authorizer,
                                  authenticator, server_store,
                                  server_capabilities)
        if not self.force_migration:
            print("***********************")
            print("Using config: %s" % server_config.config_filename)
            print("Storage: %s" % server_config.disk_storage_path)
            print("Public URL: %s" % server_config.public_url)
            print("PORT: %s" % server_config.port)
            print("***********************")
Example #13
0
    def __init__(self, force_migration=False):
        self.force_migration = force_migration
        user_folder = conan_expand_user("~")
        server_folder = os.path.join(user_folder, '.conan_server')

        server_config = migrate_and_get_server_config(user_folder, None,
                                                      self.force_migration)
        custom_auth = server_config.custom_authenticator
        if custom_auth:
            authenticator = load_authentication_plugin(server_folder,
                                                       custom_auth)
        else:
            authenticator = BasicAuthenticator(dict(server_config.users))

        authorizer = BasicAuthorizer(server_config.read_permissions,
                                     server_config.write_permissions)
        credentials_manager = JWTCredentialsManager(
            server_config.jwt_secret, server_config.jwt_expire_time)

        updown_auth_manager = JWTUpDownAuthManager(
            server_config.updown_secret, server_config.authorize_timeout)

        server_store = get_server_store(
            server_config.disk_storage_path,
            server_config.public_url,
            updown_auth_manager=updown_auth_manager)

        server_capabilities = SERVER_CAPABILITIES
        server_capabilities.append(REVISIONS)

        self.server = ConanServer(server_config.port, credentials_manager,
                                  updown_auth_manager, authorizer,
                                  authenticator, server_store,
                                  Version(SERVER_VERSION),
                                  Version(MIN_CLIENT_COMPATIBLE_VERSION),
                                  server_capabilities)
        if not self.force_migration:
            print("***********************")
            print("Using config: %s" % server_config.config_filename)
            print("Storage: %s" % server_config.disk_storage_path)
            print("Public URL: %s" % server_config.public_url)
            print("PORT: %s" % server_config.port)
            print("***********************")