コード例 #1
0
def test_inherited_robot_accounts_same_namespace_no_read_permission(
    get_monkeypatch, initialized_db, client
):
    patch_permissions(get_monkeypatch, False)
    analyzer = TriggerAnalyzer(FakeHandler(), "devtable", "localhost:5000", {}, True)

    result = analyzer.analyze_trigger()
    assert analyzer.analyze_trigger()["status"] == "error"
コード例 #2
0
def test_trigger_analyzer(
    handler_fn,
    config_dict,
    admin_org_permission,
    status,
    message,
    get_base_image,
    robots,
    server_hostname,
    get_repository,
    can_read,
    namespace,
    name,
    get_monkeypatch,
    client,
):
    patch_list_namespace_robots(get_monkeypatch)
    patch_get_all_repo_users_transitive(get_monkeypatch)
    patch_parse_dockerfile(get_monkeypatch, get_base_image)
    patch_model_repository_get_repository(get_monkeypatch, get_repository)
    patch_permissions(get_monkeypatch, can_read)
    handler_mock = Mock()
    handler_mock.configure_mock(**{"load_dockerfile_contents": handler_fn})
    trigger_analyzer = TriggerAnalyzer(
        handler_mock, "namespace", server_hostname, config_dict, admin_org_permission
    )
    assert trigger_analyzer.analyze_trigger() == {
        "namespace": namespace,
        "name": name,
        "robots": robots,
        "status": status,
        "message": message,
        "is_admin": admin_org_permission,
    }
コード例 #3
0
    def post(self, namespace_name, repo_name, trigger_uuid):
        """
        Analyze the specified build trigger configuration.
        """
        trigger = get_trigger(trigger_uuid)

        if trigger.repository.namespace_user.username != namespace_name:
            raise NotFound()

        if trigger.repository.name != repo_name:
            raise NotFound()

        new_config_dict = request.get_json()["config"]
        handler = BuildTriggerHandler.get_handler(trigger, new_config_dict)
        server_hostname = app.config["SERVER_HOSTNAME"]
        try:
            trigger_analyzer = TriggerAnalyzer(
                handler,
                namespace_name,
                server_hostname,
                new_config_dict,
                AdministerOrganizationPermission(namespace_name).can(),
            )
            return trigger_analyzer.analyze_trigger()
        except TriggerException as rre:
            return {
                "status": "error",
                "message": "Could not analyze the repository: %s" % rre.message,
            }
        except NotImplementedError:
            return {
                "status": "notimplemented",
            }
コード例 #4
0
def test_inherited_robot_accounts_same_namespace_not_org_admin(
    get_monkeypatch, initialized_db, client
):
    patch_permissions(get_monkeypatch, True)
    analyzer = TriggerAnalyzer(FakeHandler(), "devtable", "localhost:5000", {}, False)

    result = analyzer.analyze_trigger()
    assert result["status"] == "requiresrobot"
    assert not result["robots"]
コード例 #5
0
def test_inherited_robot_accounts_same_namespace(get_monkeypatch, initialized_db, client):
    patch_permissions(get_monkeypatch, True)
    analyzer = TriggerAnalyzer(FakeHandler(), "devtable", "localhost:5000", {}, True)

    result = analyzer.analyze_trigger()
    assert result["status"] == "requiresrobot"
    for robot in result["robots"]:
        assert robot["name"].startswith("devtable+")
        assert "token" not in robot
コード例 #6
0
def test_trigger_analyzer(handler_fn, config_dict, admin_org_permission,
                          status, message, get_base_image, robots,
                          server_hostname, get_repository, can_read, namespace,
                          name, get_monkeypatch):
    patch_list_namespace_robots(get_monkeypatch)
    patch_get_all_repo_users_transitive(get_monkeypatch)
    patch_parse_dockerfile(get_monkeypatch, get_base_image)
    patch_model_repository_get_repository(get_monkeypatch, get_repository)
    patch_permissions(get_monkeypatch, can_read)
    handler_mock = Mock()
    handler_mock.configure_mock(**{'load_dockerfile_contents': handler_fn})
    trigger_analyzer = TriggerAnalyzer(handler_mock, 'namespace',
                                       server_hostname, config_dict,
                                       admin_org_permission)
    assert trigger_analyzer.analyze_trigger() == {
        'namespace': namespace,
        'name': name,
        'robots': robots,
        'status': status,
        'message': message,
        'is_admin': admin_org_permission
    }