Skip to content

Commit

Permalink
feat(security): introduce API to terminate user account
Browse files Browse the repository at this point in the history
  • Loading branch information
azasypkin committed May 16, 2024
1 parent 67ff622 commit 8be73d4
Show file tree
Hide file tree
Showing 15 changed files with 201 additions and 126 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,11 @@ cargo run -p jwt_tools generate \
--secret 8ffe0cc38d7ff1afa78b6cd5696f2e21 \
--sub [email protected] --exp 30days
---
curl -XGET --header "Authorization: Bearer __token__" http:https://localhost:7070/api/status
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MTgyNjYxNTQsInN1YiI6InVzZXJAc2VjdXRpbHMuZGV2In0.e9sHurEyxhonOcR8dVVhmXdAWi287XReMiWUEVZuFwU
---
curl -XGET --header \
"Authorization: Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MTgyNjYxNTQsInN1YiI6InVzZXJAc2VjdXRpbHMuZGV2In0.e9sHurEyxhonOcR8dVVhmXdAWi287XReMiWUEVZuFwU" \
http:https://localhost:7070/api/status
```

### Re-initialize local database
Expand Down
8 changes: 0 additions & 8 deletions dev/api/security/kratos.http
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@ Accept: application/json
Content-Type: application/json
Cookie: id=xxxx

###
GET http:https://127.0.0.1:4433/sessions/whoami
Accept: application/json
Content-Type: application/json
Cookie: id=xxxx


### Start registration flow.
// @no-cookie-jar
GET http:https://127.0.0.1:4433/self-service/registration/browser
Accept: application/json



### Get identity
GET {{kratosAdminHost}}/admin/identities/c94b3e19-321b-431a-8a4f-8b101ea03f98
Accept: application/json
Expand Down
9 changes: 0 additions & 9 deletions dev/api/security/signin.http

This file was deleted.

2 changes: 1 addition & 1 deletion dev/api/security/users_remove.http
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ Content-Type: application/json
Authorization: {{api-credentials}}

{
"email": "dev@secutils.dev"
"email": "test@secutils.dev"
}
File renamed without changes.
2 changes: 1 addition & 1 deletion src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ pub mod tests {
let notifications_send_job_id = uuid!("00000000-0000-0000-0000-000000000004");

// Create user, trackers and tracker jobs.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let resources_tracker = api
.web_scraping(&user)
.create_resources_tracker(WebPageTrackerCreateParams {
Expand Down
22 changes: 11 additions & 11 deletions src/scheduler/scheduler_jobs/web_page_trackers_fetch_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user and trackers.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let resources_tracker_job_id = scheduler
.add(
WebPageTrackersTriggerJob::create(
Expand Down Expand Up @@ -622,7 +622,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

// Make sure that the tracker is only run once during a single minute (2 seconds after the
// current second).
Expand Down Expand Up @@ -799,7 +799,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

// Make sure that the tracker is only run once during a single minute (2 seconds after the
// current second).
Expand Down Expand Up @@ -958,7 +958,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -1140,7 +1140,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -1303,7 +1303,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -1504,7 +1504,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -1740,7 +1740,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -1906,7 +1906,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -2067,7 +2067,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down Expand Up @@ -2266,7 +2266,7 @@ mod tests {
let tracker_schedule = mock_schedule_in_sec(1);

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let trigger_job_id = scheduler
.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user, trackers and tracker jobs.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let web_scraping = api.web_scraping(&user);
let tracker_one = web_scraping
Expand Down Expand Up @@ -419,7 +419,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user, trackers and tracker jobs.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let resources_tracker = api
.web_scraping(&user)
Expand Down Expand Up @@ -505,7 +505,7 @@ mod tests {
let api = Arc::new(mock_api_with_config(pool, config).await?);

// Create user, trackers and tracker jobs.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let resources_tracker = api
.web_scraping(&user)
Expand Down
12 changes: 6 additions & 6 deletions src/scheduler/scheduler_jobs/web_page_trackers_trigger_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let tracker = api
.web_scraping(&user)
.create_resources_tracker(WebPageTrackerCreateParams {
Expand Down Expand Up @@ -284,7 +284,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let tracker = api
.web_scraping(&user)
.create_content_tracker(WebPageTrackerCreateParams {
Expand Down Expand Up @@ -368,7 +368,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let tracker = api
.web_scraping(&user)
.create_resources_tracker(WebPageTrackerCreateParams {
Expand Down Expand Up @@ -434,7 +434,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let tracker = api
.web_scraping(&user)
.create_resources_tracker(WebPageTrackerCreateParams {
Expand Down Expand Up @@ -492,7 +492,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;
let tracker = api
.web_scraping(&user)
.create_resources_tracker(WebPageTrackerCreateParams {
Expand Down Expand Up @@ -554,7 +554,7 @@ mod tests {
let job_id = uuid!("00000000-0000-0000-0000-000000000000");

// Create user, tracker and tracker job.
api.users().upsert(user.clone()).await?;
api.db.upsert_user(user.clone()).await?;

let job = WebPageTrackersTriggerJob::try_resume(
api.clone(),
Expand Down
Loading

0 comments on commit 8be73d4

Please sign in to comment.