Skip to content

Commit 06d6caa

Browse files
committed
Feature: Added authentication to REST and GraphQL
1 parent eae5f5c commit 06d6caa

21 files changed

Lines changed: 588 additions & 6 deletions

Cargo.lock

Lines changed: 90 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "email-sanitizer"
3-
version = "0.9.0+sprint4"
3+
version = "0.10.0+sprint5"
44
edition = "2024"
55

66
[dependencies]
@@ -22,6 +22,10 @@ mockall = "0.13.1"
2222
redis = { version = "0.32.5", features = ["tokio-comp", "connection-manager"] }
2323
actix-http = "3.10.0"
2424
uuid = { version = "1.0", features = ["v4"] }
25+
async-trait = "0.1"
26+
jsonwebtoken = "9.3"
27+
sha2 = "0.10"
28+
bcrypt = "0.15"
2529

2630
[dev-dependencies]
2731
husky = "0.3.0"

manual-testing/README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Manual Testing Guide
2+
3+
## Authentication Flow
4+
5+
1. **Register a user**: Run `POST-register.http` to create a user and get an API key
6+
2. **Copy the API key**: From the response, copy the `api_key` value
7+
3. **Use in authenticated requests**: Replace `YOUR_API_KEY_HERE` in auth test files
8+
9+
## Test Files
10+
11+
### Authentication Tests
12+
- `POST-register.http` - Register new user and generate API key
13+
- `POST-register_duplicate.http` - Test duplicate registration (should fail)
14+
- `POST-register_invalid.http` - Test invalid registration data
15+
- `POST-auth_invalid_key.http` - Test invalid API key formats
16+
17+
### Email Validation (Authenticated)
18+
- `POST-email_valid_with_auth.http` - Validate email with API key
19+
- `POST-emails_bulk_with_auth.http` - Bulk validation with API key
20+
- `GET-job_status_with_auth.http` - Job status with API key
21+
22+
### Email Validation (Public)
23+
- `POST-email_valid.http` - Public email validation
24+
- `POST-email_invalid_*.http` - Various invalid email tests
25+
26+
## API Key Format
27+
28+
Generated API keys have the format: `{hash_prefix}.{jwt_token}`
29+
- Hash prefix: First 16 chars of SHA-256(email + password_hash)
30+
- JWT token: Contains email and expiration (30 days)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Valid email validation with authentication
2+
# First run POST-register.http to get an API key, then add it to HTTP headers:
3+
# Authorization: Bearer YOUR_API_KEY_HERE
4+
query ValidateEmailWithAuth {
5+
validateEmail(email: "test@example.com") {
6+
isValid
7+
status
8+
error {
9+
code
10+
message
11+
}
12+
}
13+
}
14+
15+
# Bulk validation with authentication
16+
query BulkValidationWithAuth {
17+
validateEmailsBulk(emails: ["test@example.com", "user@example.org"]) {
18+
results {
19+
email
20+
validation {
21+
isValid
22+
status
23+
error {
24+
code
25+
message
26+
}
27+
}
28+
}
29+
validCount
30+
invalidCount
31+
}
32+
}
33+
34+
# Job status with authentication
35+
query JobStatusWithAuth {
36+
getJobStatus(jobId: "test-job-id")
37+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Job status with valid API key
2+
### First run POST-register.http to get an API key, then replace YOUR_API_KEY_HERE
3+
GET http://localhost:8080/api/v1/job-status/test-job-id
4+
Authorization: Bearer YOUR_API_KEY_HERE
5+
6+
###
7+
8+
### Job status without API key (should fail)
9+
GET http://localhost:8080/api/v1/job-status/test-job-id
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
### Test with invalid API key
2+
POST http://localhost:8080/api/v1/validate-email
3+
Authorization: Bearer invalid-key-format
4+
Content-Type: application/json
5+
6+
{
7+
"email": "test@example.com"
8+
}
9+
10+
###
11+
12+
### Test with malformed JWT
13+
POST http://localhost:8080/api/v1/validate-email
14+
Authorization: Bearer abcd1234.invalid-jwt-token
15+
Content-Type: application/json
16+
17+
{
18+
"email": "test@example.com"
19+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
### Email validation without API key (should fail)
2+
POST http://localhost:8080/api/v1/validate-email
3+
Content-Type: application/json
4+
5+
{
6+
"email": "test@example.com"
7+
}
8+
9+
###
10+
11+
### Email validation with invalid API key (should fail)
12+
POST http://localhost:8080/api/v1/validate-email
13+
Authorization: Bearer invalid-key
14+
Content-Type: application/json
15+
16+
{
17+
"email": "test@example.com"
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Valid email with valid API key
2+
### First run POST-register.http to get an API key, then replace YOUR_API_KEY_HERE
3+
POST http://localhost:8080/api/v1/validate-email
4+
Authorization: Bearer YOUR_API_KEY_HERE
5+
Content-Type: application/json
6+
7+
{
8+
"email": "test@example.com"
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
### Bulk email validation with valid API key
2+
### First run POST-register.http to get an API key, then replace YOUR_API_KEY_HERE
3+
POST http://localhost:8080/api/v1/validate-emails-bulk
4+
Authorization: Bearer YOUR_API_KEY_HERE
5+
Content-Type: application/json
6+
7+
{
8+
"emails": ["test@example.com", "user@example.org"]
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
### Register user and generate API key
2+
POST http://localhost:8080/api/v1/register
3+
Content-Type: application/json
4+
5+
{
6+
"email": "test@example.com",
7+
"password": "mypassword123"
8+
}

0 commit comments

Comments
 (0)