Exemplo n.º 1
0
    def test_values(self):
        config = ConanServerConfigParser(self.file_path, environment=self.environ)
        self.assertEquals(config.jwt_secret, "mysecret")
        self.assertEquals(config.jwt_expire_time, timedelta(minutes=121))
        self.assertEquals(config.disk_storage_path, self.storage_path)
        self.assertTrue(config.ssl_enabled)
        self.assertEquals(config.port, 9220)
        self.assertEquals(config.write_permissions, [("openssl/2.0.1@lasote/testing", "pepe")])
        self.assertEquals(config.read_permissions, [("*/*@*/*", "*"),
                                                    ("openssl/2.0.1@lasote/testing", "pepe")])
        self.assertEquals(config.users, {"lasote": "defaultpass", "pepe": "pepepass"})

        # Now check with environments
        tmp_storage = temp_folder()
        self.environ["CONAN_STORAGE_PATH"] = tmp_storage
        self.environ["CONAN_JWT_SECRET"] = "newkey"
        self.environ["CONAN_JWT_EXPIRE_MINUTES"] = "123"
        self.environ["CONAN_SSL_ENABLED"] = "False"
        self.environ["CONAN_SERVER_PORT"] = "1233"
        self.environ["CONAN_SERVER_USERS"] = "lasote:lasotepass,pepe2:pepepass2"

        config = ConanServerConfigParser(self.file_path, environment=self.environ)
        self.assertEquals(config.jwt_secret,  "newkey")
        self.assertEquals(config.jwt_expire_time, timedelta(minutes=123))
        self.assertEquals(config.disk_storage_path, conan_expand_user(tmp_storage))
        self.assertFalse(config.ssl_enabled)
        self.assertEquals(config.port, 1233)
        self.assertEquals(config.write_permissions, [("openssl/2.0.1@lasote/testing", "pepe")])
        self.assertEquals(config.read_permissions, [("*/*@*/*", "*"),
                                                    ("openssl/2.0.1@lasote/testing", "pepe")])
        self.assertEquals(config.users, {"lasote": "lasotepass", "pepe2": "pepepass2"})
Exemplo n.º 2
0
def migrate_and_get_server_config(base_folder, storage_folder=None):
    server_config = ConanServerConfigParser(base_folder, storage_folder=storage_folder)
    storage_path = server_config.disk_storage_path
    migrator = ServerMigrator(server_config.conan_folder, storage_path,
                              Version(SERVER_VERSION), logger)
    migrator.migrate()

    # Init again server_config, migrator could change something
    server_config = ConanServerConfigParser(base_folder, storage_folder=storage_folder)
    return server_config
    def test_not_allowed_encoding_password(self):
        tmp_dir = temp_folder()
        server_conf = """
[server]
jwt_secret: 534534534
jwt_expire_minutes: 120
ssl_enabled: False
port: 9300
public_port:
host_name: localhost
store_adapter: disk
authorize_timeout: 1800
disk_storage_path: ~/.conan_server/data
disk_authorize_timeout: 1800
updown_secret: tbsiGzeEygYSCcNrSYcuzmZr


[write_permissions]

[users]
demo: %s
        """
        server_dir = os.path.join(tmp_dir, ".conan_server")
        mkdir(server_dir)
        conf_path = os.path.join(server_dir, "server.conf")

        save(conf_path, server_conf % "cönan")

        server_config = ConanServerConfigParser(tmp_dir)
        with self.assertRaisesRegexp(
                ConanException,
                "Password contains invalid characters. Only ASCII encoding is supported"
        ):
            server_config.users

        save(conf_path, server_conf % "manol ito!@")
        server_config = ConanServerConfigParser(tmp_dir)
        self.assertEquals(server_config.users, {"demo": "manol ito!@"})

        # Now test from ENV
        server_config = ConanServerConfigParser(
            tmp_dir, environment={"CONAN_SERVER_USERS": "demo: cönan"})
        with self.assertRaisesRegexp(
                ConanException,
                "Password contains invalid characters. Only ASCII encoding is supported"
        ):
            server_config.users

        server_config = ConanServerConfigParser(
            tmp_dir, environment={"CONAN_SERVER_USERS": "demo:manolito!@"})
        self.assertEquals(server_config.users, {"demo": "manolito!@"})
Exemplo n.º 4
0
def migrate_and_get_server_config(base_folder,
                                  force_migration=False,
                                  is_custom_path=False):
    server_config = ConanServerConfigParser(base_folder,
                                            is_custom_path=is_custom_path)
    storage_path = server_config.disk_storage_path
    migrator = ServerMigrator(server_config.conan_folder, storage_path,
                              Version(SERVER_VERSION), logger, force_migration)
    migrator.migrate()

    # Init again server_config, migrator could change something
    server_config = ConanServerConfigParser(base_folder,
                                            is_custom_path=is_custom_path)
    return server_config
Exemplo n.º 5
0
    def test_relative_public_url(self):
        tmp_dir = temp_folder()
        server_conf = """
[server]

[write_permissions]

[users]
        """
        server_dir = os.path.join(tmp_dir, ".conan_server")
        mkdir(server_dir)
        conf_path = os.path.join(server_dir, "server.conf")
        save(conf_path, server_conf)

        server_config = ConanServerConfigParser(tmp_dir)
        self.assertEqual(server_config.public_url, "v1")
Exemplo n.º 6
0
    def test_custom_server_folder_path(self):
        tmp_dir = temp_folder()
        server_dir = os.path.join(tmp_dir, ".custom_conan_server")
        mkdir(server_dir)
        conf_path = os.path.join(server_dir, "server.conf")
        server_conf = """
[server]

[write_permissions]

[users]
        """
        save(conf_path, server_conf)
        server_config = ConanServerConfigParser(server_dir,
                                                is_custom_path=True)
        self.assertEqual(server_config.conan_folder, server_dir)