Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/fakecloud-cognito/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod service;
pub mod state;
pub mod triggers;
pub mod user_status;
19 changes: 10 additions & 9 deletions crates/fakecloud-cognito/src/service/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::state::{
AccessTokenData, AuthEvent, ChallengeResult, RefreshTokenData, SessionData, UserAttribute,
};
use crate::triggers::{self, TriggerSource};
use crate::user_status;

use super::{
generate_confirmation_code, generate_tokens, parse_user_attributes, require_str,
Expand Down Expand Up @@ -224,7 +225,7 @@ impl CognitoService {
}

// Check if user needs to change password
if user.user_status == "FORCE_CHANGE_PASSWORD" {
if user.user_status == user_status::FORCE_CHANGE_PASSWORD {
let session = Uuid::new_v4().to_string();
state.sessions.insert(
session.clone(),
Expand Down Expand Up @@ -489,7 +490,7 @@ impl CognitoService {
));
}

if user.user_status == "FORCE_CHANGE_PASSWORD" {
if user.user_status == user_status::FORCE_CHANGE_PASSWORD {
let session = Uuid::new_v4().to_string();
state.sessions.insert(
session.clone(),
Expand Down Expand Up @@ -1063,7 +1064,7 @@ impl CognitoService {

user.password = Some(new_password.to_string());
user.temporary_password = None;
user.user_status = "CONFIRMED".to_string();
user.user_status = user_status::CONFIRMED.to_string();
user.user_last_modified_date = Utc::now();

let sub = user.sub.clone();
Expand Down Expand Up @@ -1499,7 +1500,7 @@ impl CognitoService {
sub: sub.clone(),
attributes,
enabled: true,
user_status: "UNCONFIRMED".to_string(),
user_status: user_status::UNCONFIRMED.to_string(),
user_create_date: now,
user_last_modified_date: now,
password: Some(password.to_string()),
Expand Down Expand Up @@ -1562,7 +1563,7 @@ impl CognitoService {
.get_mut(&pool_id)
.and_then(|users| users.get_mut(username))
{
u.user_status = "CONFIRMED".to_string();
u.user_status = user_status::CONFIRMED.to_string();
u.user_last_modified_date = Utc::now();
}
}
Expand Down Expand Up @@ -1614,7 +1615,7 @@ impl CognitoService {
)
})?;

user.user_status = "CONFIRMED".to_string();
user.user_status = user_status::CONFIRMED.to_string();
user.user_last_modified_date = Utc::now();

let user_attrs = triggers::collect_user_attributes(user);
Expand Down Expand Up @@ -1677,7 +1678,7 @@ impl CognitoService {
)
})?;

user.user_status = "CONFIRMED".to_string();
user.user_status = user_status::CONFIRMED.to_string();
user.user_last_modified_date = Utc::now();

let user_attrs = triggers::collect_user_attributes(user);
Expand Down Expand Up @@ -1959,7 +1960,7 @@ impl CognitoService {
user.password = Some(password.to_string());
user.temporary_password = None;
user.confirmation_code = None;
user.user_status = "CONFIRMED".to_string();
user.user_status = user_status::CONFIRMED.to_string();
user.user_last_modified_date = Utc::now();

Ok(AwsResponse::ok_json(json!({})))
Expand Down Expand Up @@ -1997,7 +1998,7 @@ impl CognitoService {
)
})?;

user.user_status = "RESET_REQUIRED".to_string();
user.user_status = user_status::RESET_REQUIRED.to_string();
user.confirmation_code = Some(generate_confirmation_code());
user.user_last_modified_date = Utc::now();

Expand Down
7 changes: 4 additions & 3 deletions crates/fakecloud-cognito/src/service/users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use fakecloud_core::service::{AwsRequest, AwsResponse, AwsServiceError};

use crate::state::UserAttribute;
use crate::triggers::{self, TriggerSource};
use crate::user_status;

use super::{
generate_confirmation_code, matches_filter, parse_filter_expression, parse_string_array,
Expand Down Expand Up @@ -87,7 +88,7 @@ impl CognitoService {
sub: sub_val,
attributes,
enabled: true,
user_status: "FORCE_CHANGE_PASSWORD".to_string(),
user_status: user_status::FORCE_CHANGE_PASSWORD.to_string(),
user_create_date: now,
user_last_modified_date: now,
password: None,
Expand Down Expand Up @@ -142,7 +143,7 @@ impl CognitoService {
.get_mut(&pool_id_owned)
.and_then(|users| users.get_mut(&username_owned))
{
u.user_status = "CONFIRMED".to_string();
u.user_status = user_status::CONFIRMED.to_string();
u.user_last_modified_date = Utc::now();
}
}
Expand Down Expand Up @@ -642,7 +643,7 @@ impl CognitoService {
if permanent {
user.password = Some(password.to_string());
user.temporary_password = None;
user.user_status = "CONFIRMED".to_string();
user.user_status = user_status::CONFIRMED.to_string();
} else {
user.temporary_password = Some(password.to_string());
}
Expand Down
16 changes: 16 additions & 0 deletions crates/fakecloud-cognito/src/user_status.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Cognito user-status wire values.
//!
//! Cognito represents a user's account state as one of a small set of
//! string literals (``UNCONFIRMED``, ``CONFIRMED``, ``FORCE_CHANGE_PASSWORD``,
//! etc.) on the wire. We keep them as constants rather than an enum so the
//! JSON representation stays byte-identical to AWS without serde attributes,
//! and to make sure the literal is spelled consistently everywhere.

pub const UNCONFIRMED: &str = "UNCONFIRMED";
pub const CONFIRMED: &str = "CONFIRMED";
pub const ARCHIVED: &str = "ARCHIVED";
pub const COMPROMISED: &str = "COMPROMISED";
pub const UNKNOWN: &str = "UNKNOWN";
pub const RESET_REQUIRED: &str = "RESET_REQUIRED";
pub const FORCE_CHANGE_PASSWORD: &str = "FORCE_CHANGE_PASSWORD";
pub const EXTERNAL_PROVIDER: &str = "EXTERNAL_PROVIDER";
Loading