Skip to content

Commit 7cad053

Browse files
committed
fix: lint
1 parent f5bfcdc commit 7cad053

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

tests/e2e/mnist_raycluster_sdk_oauth_test.py

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def run_mnist_raycluster_sdk_oauth(self):
7676

7777
def assert_jobsubmit_withoutLogin(self, cluster):
7878
dashboard_url = cluster.cluster_dashboard_uri()
79-
79+
8080
# Verify that job submission is actually blocked by attempting to submit without auth
8181
# The endpoint path depends on whether we're using HTTPRoute (with path prefix) or not
8282
if "/ray/" in dashboard_url:
@@ -87,7 +87,7 @@ def assert_jobsubmit_withoutLogin(self, cluster):
8787
# OpenShift Route format: https://hostname
8888
# API endpoint is directly under the hostname
8989
api_url = dashboard_url + "/api/jobs/"
90-
90+
9191
jobdata = {
9292
"entrypoint": "python mnist.py",
9393
"runtime_env": {
@@ -96,20 +96,22 @@ def assert_jobsubmit_withoutLogin(self, cluster):
9696
"env_vars": get_setup_env_variables(),
9797
},
9898
}
99-
99+
100100
# Try to submit a job without authentication
101101
# Follow redirects to see the final response - if it redirects to login, that's still a failure
102-
response = requests.post(api_url, verify=False, json=jobdata, allow_redirects=True)
103-
102+
response = requests.post(
103+
api_url, verify=False, json=jobdata, allow_redirects=True
104+
)
105+
104106
# Check if the submission was actually blocked
105107
# Success indicators that submission was blocked:
106108
# 1. Status code 403 (Forbidden)
107109
# 2. Status code 302 (Redirect to login) - but we need to verify the final response after redirect
108110
# 3. Status code 200 but with HTML content (login page) instead of JSON (job submission response)
109111
# 4. Status code 401 (Unauthorized)
110-
112+
111113
submission_blocked = False
112-
114+
113115
if response.status_code == 403:
114116
submission_blocked = True
115117
elif response.status_code == 401:
@@ -120,8 +122,8 @@ def assert_jobsubmit_withoutLogin(self, cluster):
120122
submission_blocked = True # Redirect to login means submission failed
121123
elif response.status_code == 200:
122124
# Check if response is HTML (login page) instead of JSON (job submission response)
123-
content_type = response.headers.get('Content-Type', '')
124-
if 'text/html' in content_type or 'application/json' not in content_type:
125+
content_type = response.headers.get("Content-Type", "")
126+
if "text/html" in content_type or "application/json" not in content_type:
125127
# Got HTML (likely login page) instead of JSON - submission was blocked
126128
submission_blocked = True
127129
else:
@@ -130,7 +132,7 @@ def assert_jobsubmit_withoutLogin(self, cluster):
130132
json_response = response.json()
131133
# If it's a successful job submission, it should have a 'job_id' or 'submission_id'
132134
# If it's an error, it might have 'error' or 'message'
133-
if 'job_id' in json_response or 'submission_id' in json_response:
135+
if "job_id" in json_response or "submission_id" in json_response:
134136
# Job was actually submitted - this is a failure!
135137
submission_blocked = False
136138
else:
@@ -139,20 +141,28 @@ def assert_jobsubmit_withoutLogin(self, cluster):
139141
except ValueError:
140142
# Not JSON - likely HTML login page
141143
submission_blocked = True
142-
144+
143145
if not submission_blocked:
144-
assert False, f"Job submission succeeded without authentication! Status: {response.status_code}, Response: {response.text[:200]}"
145-
146+
assert (
147+
False
148+
), f"Job submission succeeded without authentication! Status: {response.status_code}, Response: {response.text[:200]}"
149+
146150
# Also verify that RayJobClient cannot be used without authentication
147151
try:
148152
client = RayJobClient(address=dashboard_url, verify=False)
149153
# Try to call a method to trigger the connection and authentication check
150154
client.list_jobs()
151-
assert False, "RayJobClient succeeded without authentication - this should not be possible"
152-
except (requests.exceptions.JSONDecodeError, requests.exceptions.HTTPError, Exception):
155+
assert (
156+
False
157+
), "RayJobClient succeeded without authentication - this should not be possible"
158+
except (
159+
requests.exceptions.JSONDecodeError,
160+
requests.exceptions.HTTPError,
161+
Exception,
162+
):
153163
# Any exception is expected when trying to use the client without auth
154164
pass
155-
165+
156166
assert True, "Job submission without authentication was correctly blocked"
157167

158168
def assert_jobsubmit_withlogin(self, cluster):
@@ -165,13 +175,18 @@ def assert_jobsubmit_withlogin(self, cluster):
165175
# This ensures that the authentication check in assert_jobsubmit_withoutLogin actually worked
166176
existing_jobs = client.list_jobs()
167177
if existing_jobs:
168-
job_ids = [job.job_id if hasattr(job, 'job_id') else str(job) for job in existing_jobs]
178+
job_ids = [
179+
job.job_id if hasattr(job, "job_id") else str(job)
180+
for job in existing_jobs
181+
]
169182
assert False, (
170183
f"Found {len(existing_jobs)} existing job(s) before authenticated submission: {job_ids}. "
171184
"This indicates that the unauthenticated job submission test failed to properly block submission."
172185
)
173186
else:
174-
print("Verified: No jobs exist from the previous unauthenticated submission attempt.")
187+
print(
188+
"Verified: No jobs exist from the previous unauthenticated submission attempt."
189+
)
175190

176191
submission_id = client.submit_job(
177192
entrypoint="python mnist.py",

0 commit comments

Comments
 (0)