SachinyadavAug20 commented on code in PR #77209:
URL: https://github.com/apache/airflow/pull/77209#discussion_r4615899947
##########
providers/amazon/tests/unit/amazon/aws/auth_manager/routes/test_login.py:
##########
@@ -226,6 +241,107 @@ def test_login(self, test_client, url):
"https://portal.sso.us-east-1.amazonaws.com/saml/assertion/"
)
+ @pytest.mark.parametrize(
+ "next_url",
+ [
+ "/dags/my_dag",
+ "/dags/my_dag/runs/run_1/tasks/task_1",
+ ],
+ )
+ def test_login_stores_safe_next_url(self, test_client, next_url):
+ response = test_client.get(
+ AUTH_MANAGER_FASTAPI_APP_PREFIX + "/login",
+ params={"next": next_url},
+ follow_redirects=False,
+ )
+ assert response.status_code == 307
+ entries = parse_login_state_cookie(response)
+ assert len(entries) == 1
+ assert entries[0].get("next") == next_url
+
+ @pytest.mark.parametrize(
+ "next_url",
+ [
+ "https://attacker.example.net/dags",
+ "//attacker.example.net/dags",
+ "javascript:alert(1)",
+ ],
+ )
+ def test_login_does_not_store_unsafe_next_url(self, test_client, next_url):
+ response = test_client.get(
+ AUTH_MANAGER_FASTAPI_APP_PREFIX + "/login",
+ params={"next": next_url},
+ follow_redirects=False,
+ )
+ assert response.status_code == 307
+ entries = parse_login_state_cookie(response)
+ assert len(entries) == 1
+ assert "next" not in entries[0]
+
+ def test_login_does_not_store_overly_long_next_url(self, test_client):
+ long_url = "/dags/" + "a" * (MAX_NEXT_URL_LENGTH + 1)
+ response = test_client.get(
+ AUTH_MANAGER_FASTAPI_APP_PREFIX + "/login",
+ params={"next": long_url},
+ follow_redirects=False,
+ )
+ assert response.status_code == 307
+ entries = parse_login_state_cookie(response)
+ assert len(entries) == 1
+ assert "next" not in entries[0]
+
+ def test_login_stores_non_latin1_next_url(self, test_client):
+ """Starlette Set-Cookie is latin-1; storing next in base64 state
cookie avoids 500."""
+ non_latin1_url = "/dags?search=日本"
+ response = test_client.get(
+ AUTH_MANAGER_FASTAPI_APP_PREFIX + "/login",
+ params={"next": non_latin1_url},
+ follow_redirects=False,
+ )
+ assert response.status_code == 307
+ entries = parse_login_state_cookie(response)
+ assert len(entries) == 1
+ assert entries[0].get("next") == non_latin1_url
+
+ def test_login_token_does_not_store_next_url(self, test_client):
+ response = test_client.get(
+ AUTH_MANAGER_FASTAPI_APP_PREFIX + "/login/token",
+ params={"next": "/dags/my_dag"},
+ follow_redirects=False,
+ )
+ assert response.status_code == 307
+ entries = parse_login_state_cookie(response)
+ assert len(entries) == 1
+ assert "next" not in entries[0]
+
+ def test_login_preserves_per_tab_next_url(self):
Review Comment:
Makes complete sense(will make more test more accurate). Updated
`test_login_preserves_per_tab_next_url` to call `/login` twice on the same
`test_client` and verify both entries are preserved.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]