Test: Added auto-commit documentation and test file
This commit is contained in:
58
test_gitea_login.py
Normal file
58
test_gitea_login.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import requests
|
||||
import re
|
||||
|
||||
def test_gitea_login():
|
||||
session = requests.Session()
|
||||
|
||||
# First get login page and CSRF token
|
||||
login_url = "https://git.mtrcompute.com/user/login"
|
||||
response = session.get(login_url)
|
||||
|
||||
# Extract CSRF token
|
||||
csrf_token = None
|
||||
match = re.search(r'csrfToken:\s*\'([^\']+)\'', response.text)
|
||||
if match:
|
||||
csrf_token = match.group(1)
|
||||
else:
|
||||
match = re.search(r'name="csrf_token"\s+value="([^"]+)"', response.text)
|
||||
if match:
|
||||
csrf_token = match.group(1)
|
||||
|
||||
if not csrf_token:
|
||||
print("Could not find CSRF token")
|
||||
return False
|
||||
|
||||
print(f"CSRF Token: {csrf_token}")
|
||||
|
||||
# Login
|
||||
data = {
|
||||
'user_name': 'jleu3482',
|
||||
'password': 'jleu1212',
|
||||
'csrf_token': csrf_token
|
||||
}
|
||||
|
||||
headers = {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Referer': login_url
|
||||
}
|
||||
|
||||
response = session.post(login_url, data=data, headers=headers, allow_redirects=False)
|
||||
|
||||
print(f"Login Status Code: {response.status_code}")
|
||||
print(f"Login Headers: {response.headers}")
|
||||
|
||||
if response.status_code == 302:
|
||||
print("Login successful!")
|
||||
|
||||
# Try to access user repos API
|
||||
api_url = "https://git.mtrcompute.com/api/v1/user/repos"
|
||||
response = session.get(api_url)
|
||||
print(f"API Status: {response.status_code}")
|
||||
print(f"API Response: {response.text[:500]}")
|
||||
return True
|
||||
else:
|
||||
print(f"Login failed. Response: {response.text[:500]}")
|
||||
return False
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_gitea_login()
|
||||
Reference in New Issue
Block a user