Skip to content

Commit

Permalink
fix yarn warning from d3-color (#27139)
Browse files Browse the repository at this point in the history
  • Loading branch information
a0x8o committed Oct 19, 2022
1 parent f27fbaa commit 603e591
Show file tree
Hide file tree
Showing 49 changed files with 379 additions and 468 deletions.
4 changes: 2 additions & 2 deletions TESTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ add them in ``tests/charts``.

.. code-block:: python
class TestBaseChartTest(unittest.TestCase):
class TestBaseChartTest:
...
To render the chart create a YAML string with the nested dictionary of options you wish to test. You can then
Expand All @@ -277,7 +277,7 @@ Example test here:
"""
class TestGitSyncScheduler(unittest.TestCase):
class TestGitSyncScheduler:
def test_basic(self):
helm_settings = yaml.safe_load(git_sync_basic)
res = render_chart(
Expand Down
1 change: 1 addition & 0 deletions airflow/www/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class ConnectionForm(DynamicForm):
conn_id = StringField(
lazy_gettext('Connection Id'), validators=[InputRequired()], widget=BS3TextFieldWidget()
)
# conn_type is added later via lazy_add_provider_discovered_options_to_connection_form
description = StringField(lazy_gettext('Description'), widget=BS3TextAreaFieldWidget())
host = StringField(lazy_gettext('Host'), widget=BS3TextFieldWidget())
schema = StringField(lazy_gettext('Schema'), widget=BS3TextFieldWidget())
Expand Down
3 changes: 3 additions & 0 deletions airflow/www/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,8 @@
"redoc": "^2.0.0-rc.72",
"type-fest": "^2.17.0",
"url-search-params-polyfill": "^8.1.0"
},
"resolutions": {
"d3-color": "^3.1.0"
}
}
27 changes: 11 additions & 16 deletions airflow/www/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
from json import JSONDecodeError
from operator import itemgetter
from typing import Any, Callable
from urllib.parse import parse_qsl, unquote, urlencode, urlparse
from urllib.parse import unquote, urljoin, urlsplit

import configupdater
import flask.json
Expand Down Expand Up @@ -155,27 +155,21 @@ def truncate_task_duration(task_duration):

def get_safe_url(url):
"""Given a user-supplied URL, ensure it points to our web server"""
valid_schemes = ['http', 'https', '']
valid_netlocs = [request.host, '']

if not url:
return url_for('Airflow.index')

parsed = urlparse(url)

# If the url contains semicolon, redirect it to homepage to avoid
# potential XSS. (Similar to https://github.com/python/cpython/pull/24297/files (bpo-42967))
if ';' in unquote(url):
return url_for('Airflow.index')

query = parse_qsl(parsed.query, keep_blank_values=True)

url = parsed._replace(query=urlencode(query)).geturl()

if parsed.scheme in valid_schemes and parsed.netloc in valid_netlocs:
return url
host_url = urlsplit(request.host_url)
redirect_url = urlsplit(urljoin(request.host_url, url))
if not (redirect_url.scheme in ("http", "https") and host_url.netloc == redirect_url.netloc):
return url_for('Airflow.index')

return url_for('Airflow.index')
# This will ensure we only redirect to the right scheme/netloc
return redirect_url.geturl()


def get_date_time_num_runs_dag_runs_form_data(www_request, session, dag):
Expand Down Expand Up @@ -4229,14 +4223,15 @@ def process_form(self, form, is_created):
flash(
Markup(
"<p>The <em>Extra</em> connection field contained an invalid value for Conn ID: "
f"<q>{conn_id}</q>.</p>"
"<q>{conn_id}</q>.</p>"
"<p>If connection parameters need to be added to <em>Extra</em>, "
"please make sure they are in the form of a single, valid JSON object.</p><br>"
"The following <em>Extra</em> parameters were <b>not</b> added to the connection:<br>"
f"{extra_json}",
),
"{extra_json}"
).format(conn_id=conn_id, extra_json=extra_json),
category="error",
)
del form.extra
del extra_json

for key in self.extra_fields:
Expand Down
13 changes: 4 additions & 9 deletions airflow/www/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4483,15 +4483,10 @@ d3-collection@1, d3-collection@^1.0.4:
resolved "https://registry.yarnpkg.com/d3-collection/-/d3-collection-1.0.7.tgz#349bd2aa9977db071091c13144d5e4f16b5b310e"
integrity sha512-ii0/r5f4sjKNTfh84Di+DpztYwqKhEyUlKoPrzUFfeSkWxjW49xU2QzO9qrPrNkpdI0XJkfzvmTu8V2Zylln6A==

d3-color@1:
version "1.4.1"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-1.4.1.tgz#c52002bf8846ada4424d55d97982fef26eb3bc8a"
integrity sha512-p2sTHSLCJI2QKunbGb7ocOh7DgTAn8IrLx21QRc/BSnodXM4sv6aLQlnfpvehFMLZEfBc6g9pH9SWQccFYfJ9Q==

"d3-color@1 - 2":
version "2.0.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-2.0.0.tgz#8d625cab42ed9b8f601a1760a389f7ea9189d62e"
integrity sha512-SPXi0TSKPD4g9tw0NMZFnR95XVgUZiBH+uUTqQuDu1OsE2zomHU7ho0FISciaPvosimixwHFl3WHLGabv6dDgQ==
d3-color@1, "d3-color@1 - 2", d3-color@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-3.1.0.tgz#395b2833dfac71507f12ac2f7af23bf819de24e2"
integrity sha512-zg/chbXyeBtMQ1LbD/WSoW2DpC3I0mpmPdW+ynRTj/x2DAWYrIY7qeZIHidozwV24m4iavr15lNwIwLxRmOxhA==

d3-contour@1:
version "1.3.2"
Expand Down
11 changes: 6 additions & 5 deletions dev/breeze/src/airflow_breeze/utils/selective_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ def __hash__(self):
r"^airflow/api",
],
FileGroupForCi.API_CODEGEN_FILES: [
"^airflow/api_connexion/openapi/v1.yaml",
"^clients/gen",
r"^airflow/api_connexion/openapi/v1\.yaml",
r"^clients/gen",
],
FileGroupForCi.HELM_FILES: [
"^chart",
"^airflow/kubernetes",
"^tests/kubernetes",
r"^chart",
r"^airflow/kubernetes",
r"^tests/kubernetes",
r"^tests/charts",
],
FileGroupForCi.SETUP_FILES: [
r"^pyproject.toml",
Expand Down
6 changes: 3 additions & 3 deletions tests/charts/test_airflow_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import jmespath
import pytest
from parameterized import parameterized

from tests.charts.helm_template_generator import render_chart

Expand All @@ -32,7 +31,8 @@ class TestAirflowCommon:
as it requires extra test setup.
"""

@parameterized.expand(
@pytest.mark.parametrize(
"dag_values, expected_mount",
[
(
{"gitSync": {"enabled": True}},
Expand Down Expand Up @@ -70,7 +70,7 @@ class TestAirflowCommon:
"readOnly": False,
},
),
]
],
)
def test_dags_mount(self, dag_values, expected_mount):
docs = render_chart(
Expand Down
41 changes: 16 additions & 25 deletions tests/charts/test_basic_helm_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,20 @@
# under the License.
from __future__ import annotations

import unittest
import warnings
from subprocess import CalledProcessError
from typing import Any
from unittest import mock

import jmespath
from parameterized import parameterized
import pytest

from tests.charts.helm_template_generator import render_chart

OBJECT_COUNT_IN_BASIC_DEPLOYMENT = 35


class TestBaseChartTest(unittest.TestCase):
class TestBaseChartTest:
def _get_values_with_version(self, values, version):
if version != "default":
values["airflowVersion"] = version
Expand All @@ -41,7 +40,7 @@ def _get_object_count(self, version):
return OBJECT_COUNT_IN_BASIC_DEPLOYMENT + 1
return OBJECT_COUNT_IN_BASIC_DEPLOYMENT

@parameterized.expand(["2.3.2", "2.4.0", "default"])
@pytest.mark.parametrize("version", ["2.3.2", "2.4.0", "default"])
def test_basic_deployments(self, version):
expected_object_count_in_basic_deployment = self._get_object_count(version)
k8s_objects = render_chart(
Expand Down Expand Up @@ -114,7 +113,7 @@ def test_basic_deployments(self, version):
"test-label"
), f"Missing label test-label on {k8s_name}. Current labels: {labels}"

@parameterized.expand(["2.3.2", "2.4.0", "default"])
@pytest.mark.parametrize("version", ["2.3.2", "2.4.0", "default"])
def test_basic_deployment_with_standalone_dag_processor(self, version):
# Dag Processor creates two extra objects compared to the basic deployment
object_count_in_basic_deployment = self._get_object_count(version)
Expand Down Expand Up @@ -192,7 +191,7 @@ def test_basic_deployment_with_standalone_dag_processor(self, version):
"test-label"
), f"Missing label test-label on {k8s_name}. Current labels: {labels}"

@parameterized.expand(["2.3.2", "2.4.0", "default"])
@pytest.mark.parametrize("version", ["2.3.2", "2.4.0", "default"])
def test_basic_deployment_without_default_users(self, version):
expected_object_count_in_basic_deployment = self._get_object_count(version)
k8s_objects = render_chart(
Expand All @@ -207,7 +206,7 @@ def test_basic_deployment_without_default_users(self, version):
assert ('Job', 'test-basic-create-user') not in list_of_kind_names_tuples
assert expected_object_count_in_basic_deployment - 2 == len(k8s_objects)

@parameterized.expand(["2.3.2", "2.4.0", "default"])
@pytest.mark.parametrize("version", ["2.3.2", "2.4.0", "default"])
def test_basic_deployment_without_statsd(self, version):
expected_object_count_in_basic_deployment = self._get_object_count(version)
k8s_objects = render_chart(
Expand Down Expand Up @@ -462,7 +461,7 @@ def get_k8s_objs_with_image(obj: list[Any] | dict[str, Any]) -> list[dict[str, A
assert "command" not in obj

def test_unsupported_executor(self):
with self.assertRaises(CalledProcessError) as ex_ctx:
with pytest.raises(CalledProcessError) as ex_ctx:
render_chart(
"test-basic",
{
Expand All @@ -472,23 +471,15 @@ def test_unsupported_executor(self):
assert (
'executor must be one of the following: "LocalExecutor", '
'"LocalKubernetesExecutor", "CeleryExecutor", '
'"KubernetesExecutor", "CeleryKubernetesExecutor"' in ex_ctx.exception.stderr.decode()
'"KubernetesExecutor", "CeleryKubernetesExecutor"' in ex_ctx.value.stderr.decode()
)

@parameterized.expand(
[
("airflow",),
("pod_template",),
("flower",),
("statsd",),
("redis",),
("pgbouncer",),
("pgbouncerExporter",),
("gitSync",),
]
@pytest.mark.parametrize(
"image",
["airflow", "pod_template", "flower", "statsd", "redis", "pgbouncer", "pgbouncerExporter", "gitSync"],
)
def test_invalid_pull_policy(self, image):
with self.assertRaises(CalledProcessError) as ex_ctx:
with pytest.raises(CalledProcessError) as ex_ctx:
render_chart(
"test-basic",
{
Expand All @@ -497,11 +488,11 @@ def test_invalid_pull_policy(self, image):
)
assert (
'pullPolicy must be one of the following: "Always", "Never", "IfNotPresent"'
in ex_ctx.exception.stderr.decode()
in ex_ctx.value.stderr.decode()
)

def test_invalid_dags_access_mode(self):
with self.assertRaises(CalledProcessError) as ex_ctx:
with pytest.raises(CalledProcessError) as ex_ctx:
render_chart(
"test-basic",
{
Expand All @@ -510,10 +501,10 @@ def test_invalid_dags_access_mode(self):
)
assert (
'accessMode must be one of the following: "ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany"'
in ex_ctx.exception.stderr.decode()
in ex_ctx.value.stderr.decode()
)

@parameterized.expand(["abc", "123", "123abc", "123-abc"])
@pytest.mark.parametrize("namespace", ["abc", "123", "123abc", "123-abc"])
def test_namespace_names(self, namespace):
"""Test various namespace names to make sure they render correctly in templates"""
render_chart(namespace=namespace)
4 changes: 1 addition & 3 deletions tests/charts/test_celery_kubernetes_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,12 @@
# under the License.
from __future__ import annotations

import unittest

import jmespath

from tests.charts.helm_template_generator import render_chart


class CeleryKubernetesExecutorTest(unittest.TestCase):
class TestCeleryKubernetesExecutor:
def test_should_create_a_worker_deployment_with_the_celery_executor(self):
docs = render_chart(
values={
Expand Down
3 changes: 1 addition & 2 deletions tests/charts/test_chart_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from __future__ import annotations

import json
import unittest
from pathlib import Path

import yaml
Expand All @@ -26,7 +25,7 @@
CHART_DIR = Path(__file__).parent / ".." / ".." / "chart"


class ChartQualityTest(unittest.TestCase):
class TestChartQuality:
def test_values_validate_schema(self):
values = yaml.safe_load((CHART_DIR / "values.yaml").read_text())
schema = json.loads((CHART_DIR / "values.schema.json").read_text())
Expand Down
18 changes: 5 additions & 13 deletions tests/charts/test_cleanup_pods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
# under the License.
from __future__ import annotations

import unittest

import jmespath
from parameterized import parameterized
import pytest

from tests.charts.helm_template_generator import render_chart


class CleanupPodsTest(unittest.TestCase):
class TestCleanupPods:
def test_should_create_cronjob_for_enabled_cleanup(self):
docs = render_chart(
values={
Expand Down Expand Up @@ -139,14 +137,8 @@ def test_should_add_extraEnvs(self):
"spec.jobTemplate.spec.template.spec.containers[0].env", docs[0]
)

@parameterized.expand(
[
(None, None),
(None, ["custom", "args"]),
(["custom", "command"], None),
(["custom", "command"], ["custom", "args"]),
]
)
@pytest.mark.parametrize("command", [None, ["custom", "command"]])
@pytest.mark.parametrize("args", [None, ["custom", "args"]])
def test_command_and_args_overrides(self, command, args):
docs = render_chart(
values={"cleanup": {"enabled": True, "command": command, "args": args}},
Expand Down Expand Up @@ -248,7 +240,7 @@ def test_should_set_job_history_limits(self):
assert 4 == jmespath.search("spec.successfulJobsHistoryLimit", docs[0])


class CleanupServiceAccountTest(unittest.TestCase):
class TestCleanupServiceAccount:
def test_should_add_component_specific_labels(self):
docs = render_chart(
values={
Expand Down
Loading

0 comments on commit 603e591

Please sign in to comment.