Noo88ear commited on
Commit
2f2c3d4
Β·
1 Parent(s): db70e19

πŸ”’ SECURITY: Remove exposed Adzuna API keys from test files - Remove hardcoded API key 'a9669ddf981b03634f0ae4661e1b9cf7' and App ID 'd42ea4e5' - Add proper environment variable validation - Exit gracefully if credentials are not set - Fixes critical security vulnerability

Browse files
Files changed (2) hide show
  1. test_adzuna.py +98 -0
  2. test_adzuna_no_ssl.py +123 -0
test_adzuna.py ADDED
@@ -0,0 +1,98 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test Adzuna API with the provided credentials
4
+ """
5
+
6
+ import os
7
+ import sys
8
+ import requests
9
+ from dotenv import load_dotenv
10
+
11
+ # Load environment variables
12
+ load_dotenv()
13
+
14
+ # Get credentials
15
+ app_id = os.getenv("ADZUNA_APP_ID")
16
+ app_key = os.getenv("ADZUNA_APP_KEY")
17
+
18
+ # Validate that required environment variables are set
19
+ if not app_id or not app_key:
20
+ print("❌ CRITICAL: ADZUNA_APP_ID and ADZUNA_APP_KEY must be set in environment")
21
+ print(" Please set these in your .env file or environment variables")
22
+ sys.exit(1)
23
+
24
+ print("πŸ” Testing Adzuna API")
25
+ print("=" * 50)
26
+ print(f"App ID: {app_id}")
27
+ print(f"App Key: {app_key[:10]}...{app_key[-4:]}")
28
+
29
+ # Test API directly
30
+ url = "https://api.adzuna.com/v1/api/jobs/gb/search/1"
31
+ params = {
32
+ "app_id": app_id,
33
+ "app_key": app_key,
34
+ "what": "Python Developer",
35
+ "where": "London",
36
+ "results_per_page": 5
37
+ }
38
+
39
+ print("\nπŸ“‘ Calling Adzuna API...")
40
+ try:
41
+ response = requests.get(url, params=params, timeout=10)
42
+
43
+ if response.status_code == 200:
44
+ data = response.json()
45
+ total = data.get("count", 0)
46
+ results = data.get("results", [])
47
+
48
+ print(f"\nβœ… SUCCESS! API responded with {total} total jobs")
49
+ print(f" Showing first {len(results)} results:\n")
50
+
51
+ for i, job in enumerate(results[:3], 1):
52
+ print(f"{i}. {job.get('title', 'No title')}")
53
+ print(f" Company: {job.get('company', {}).get('display_name', 'N/A')}")
54
+ print(f" Location: {job.get('location', {}).get('display_name', 'N/A')}")
55
+
56
+ # Salary info
57
+ if job.get("salary_min"):
58
+ print(f" Salary: Β£{job['salary_min']:,.0f} - Β£{job.get('salary_max', 0):,.0f}")
59
+
60
+ # URL
61
+ if job.get("redirect_url"):
62
+ print(f" URL: {job['redirect_url'][:50]}...")
63
+ print()
64
+
65
+ print("πŸŽ‰ Adzuna API is working perfectly with your keys!")
66
+
67
+ elif response.status_code == 401:
68
+ print(f"❌ Authentication failed: {response.text}")
69
+ print("\nPlease check your API keys.")
70
+ else:
71
+ print(f"❌ API Error: {response.status_code}")
72
+ print(f"Response: {response.text}")
73
+
74
+ except requests.exceptions.ConnectionError:
75
+ print("❌ Connection error - check your internet connection")
76
+ except Exception as e:
77
+ print(f"❌ Error: {e}")
78
+
79
+ # Now test with the aggregator
80
+ print("\n" + "=" * 50)
81
+ print("Testing with Job Aggregator...")
82
+
83
+ sys.path.insert(0, '.')
84
+ try:
85
+ from services.job_aggregator import JobAggregator
86
+
87
+ aggregator = JobAggregator()
88
+ jobs = aggregator.search_adzuna("Software Engineer", "United States")
89
+
90
+ if jobs:
91
+ print(f"βœ… Aggregator found {len(jobs)} jobs")
92
+ for job in jobs[:2]:
93
+ print(f" β€’ {job.title} at {job.company}")
94
+ else:
95
+ print("⚠️ No jobs returned from aggregator")
96
+
97
+ except Exception as e:
98
+ print(f"❌ Aggregator error: {e}")
test_adzuna_no_ssl.py ADDED
@@ -0,0 +1,123 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Test Adzuna API with SSL verification disabled (for corporate networks)
4
+ """
5
+
6
+ import os
7
+ import sys
8
+ import requests
9
+ import urllib3
10
+ from dotenv import load_dotenv
11
+
12
+ # Disable SSL warnings for testing
13
+ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
14
+
15
+ # Load environment variables
16
+ load_dotenv()
17
+
18
+ # Get credentials
19
+ app_id = os.getenv("ADZUNA_APP_ID")
20
+ app_key = os.getenv("ADZUNA_APP_KEY")
21
+
22
+ # Validate that required environment variables are set
23
+ if not app_id or not app_key:
24
+ print("❌ CRITICAL: ADZUNA_APP_ID and ADZUNA_APP_KEY must be set in environment")
25
+ print(" Please set these in your .env file or environment variables")
26
+ sys.exit(1)
27
+
28
+ print("πŸ” Testing Adzuna API (SSL verification disabled)")
29
+ print("=" * 50)
30
+ print(f"App ID: {app_id}")
31
+ print(f"App Key: {app_key[:10]}...{app_key[-4:]}")
32
+
33
+ # Test API directly without SSL verification
34
+ url = "https://api.adzuna.com/v1/api/jobs/gb/search/1"
35
+ params = {
36
+ "app_id": app_id,
37
+ "app_key": app_key,
38
+ "what": "Python Developer",
39
+ "where": "London",
40
+ "results_per_page": 5
41
+ }
42
+
43
+ print("\nπŸ“‘ Calling Adzuna API (bypassing SSL)...")
44
+ try:
45
+ # IMPORTANT: verify=False is only for testing in corporate environments
46
+ response = requests.get(url, params=params, timeout=10, verify=False)
47
+
48
+ if response.status_code == 200:
49
+ data = response.json()
50
+ total = data.get("count", 0)
51
+ results = data.get("results", [])
52
+
53
+ print(f"\nβœ… SUCCESS! API responded with {total:,} total jobs available")
54
+ print(f" Showing first {len(results)} results:\n")
55
+
56
+ for i, job in enumerate(results[:3], 1):
57
+ print(f"{i}. {job.get('title', 'No title')}")
58
+ company = job.get('company', {}).get('display_name', 'N/A')
59
+ print(f" Company: {company}")
60
+ location = job.get('location', {}).get('display_name', 'N/A')
61
+ print(f" Location: {location}")
62
+
63
+ # Salary info
64
+ if job.get("salary_min"):
65
+ print(f" Salary: Β£{job['salary_min']:,.0f} - Β£{job.get('salary_max', 0):,.0f}/year")
66
+
67
+ # Posted date
68
+ if job.get("created"):
69
+ print(f" Posted: {job['created'][:10]}")
70
+
71
+ print()
72
+
73
+ print("πŸŽ‰ Adzuna API is working perfectly with your keys!")
74
+ print("\nπŸ“Š Summary:")
75
+ print(f" β€’ Total jobs matching 'Python Developer' in London: {total:,}")
76
+ print(f" β€’ Your API keys are valid and working")
77
+ print(f" β€’ You have access to jobs from UK, US, CA, AU, and more")
78
+
79
+ elif response.status_code == 401:
80
+ print(f"❌ Authentication failed: Invalid API keys")
81
+ print(f"Response: {response.text}")
82
+ elif response.status_code == 400:
83
+ print(f"❌ Bad request: {response.text}")
84
+ else:
85
+ print(f"❌ API Error: {response.status_code}")
86
+ print(f"Response: {response.text}")
87
+
88
+ except Exception as e:
89
+ print(f"❌ Error: {e}")
90
+
91
+ # Test different locations
92
+ print("\n" + "=" * 50)
93
+ print("Testing different markets...")
94
+
95
+ markets = [
96
+ ("Software Engineer", "New York", "us"),
97
+ ("Data Scientist", "Toronto", "ca"),
98
+ ("DevOps Engineer", "Sydney", "au")
99
+ ]
100
+
101
+ for job_title, location, country in markets:
102
+ url = f"https://api.adzuna.com/v1/api/jobs/{country}/search/1"
103
+ params = {
104
+ "app_id": app_id,
105
+ "app_key": app_key,
106
+ "what": job_title,
107
+ "where": location,
108
+ "results_per_page": 1
109
+ }
110
+
111
+ try:
112
+ response = requests.get(url, params=params, timeout=10, verify=False)
113
+ if response.status_code == 200:
114
+ data = response.json()
115
+ count = data.get("count", 0)
116
+ print(f"βœ… {job_title} in {location}: {count:,} jobs available")
117
+ else:
118
+ print(f"⚠️ Could not fetch {job_title} in {location}")
119
+ except:
120
+ pass
121
+
122
+ print("\nπŸ’‘ Note: SSL verification is disabled for corporate network compatibility")
123
+ print(" In production, ensure proper SSL certificates are configured")