Skip to content

Commit 6fd1b7d

Browse files
committed
Update the upstream oauth user registration test
1 parent fd8afc8 commit 6fd1b7d

File tree

1 file changed

+29
-23
lines changed
  • crates/handlers/src/upstream_oauth2

1 file changed

+29
-23
lines changed

crates/handlers/src/upstream_oauth2/link.rs

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,20 +1075,18 @@ mod tests {
10751075
use mas_data_model::{
10761076
UpstreamOAuthAuthorizationSession, UpstreamOAuthLink, UpstreamOAuthProviderClaimsImports,
10771077
UpstreamOAuthProviderImportPreference, UpstreamOAuthProviderLocalpartPreference,
1078-
UpstreamOAuthProviderTokenAuthMethod,
1078+
UpstreamOAuthProviderTokenAuthMethod, UserEmailAuthentication, UserRegistration,
10791079
};
10801080
use mas_iana::jose::JsonWebSignatureAlg;
10811081
use mas_jose::jwt::{JsonWebSignatureHeader, Jwt};
10821082
use mas_keystore::Keystore;
10831083
use mas_router::Route;
1084-
use mas_storage::{
1085-
Pagination, Repository, RepositoryError, upstream_oauth2::UpstreamOAuthProviderParams,
1086-
user::UserEmailFilter,
1087-
};
1084+
use mas_storage::{Repository, RepositoryError, upstream_oauth2::UpstreamOAuthProviderParams};
10881085
use oauth2_types::scope::{OPENID, Scope};
10891086
use rand_chacha::ChaChaRng;
10901087
use serde_json::Value;
10911088
use sqlx::PgPool;
1089+
use ulid::Ulid;
10921090

10931091
use super::UpstreamSessionsCookie;
10941092
use crate::test_utils::{CookieHelper, RequestBuilderExt, ResponseExt, TestState, setup};
@@ -1250,33 +1248,41 @@ mod tests {
12501248
let response = state.request(request).await;
12511249
cookies.save_cookies(&response);
12521250
response.assert_status(StatusCode::SEE_OTHER);
1251+
let location = response.headers().get(hyper::header::LOCATION).unwrap();
1252+
// Grab the registration ID from the redirected URL:
1253+
// /register/steps/{id}/finish
1254+
let registration_id: Ulid = str::from_utf8(location.as_bytes())
1255+
.unwrap()
1256+
.rsplit('/')
1257+
.nth(1)
1258+
.expect("Location to have two slashes")
1259+
.parse()
1260+
.expect("last segment of location to be a ULID");
12531261

12541262
// Check that we have a registered user, with the email imported
12551263
let mut repo = state.repository().await.unwrap();
1256-
let user = repo
1257-
.user()
1258-
.find_by_username("john")
1264+
let registration: UserRegistration = repo
1265+
.user_registration()
1266+
.lookup(registration_id)
12591267
.await
12601268
.unwrap()
1261-
.expect("user exists");
1269+
.expect("user registration exists");
12621270

1263-
let link = repo
1264-
.upstream_oauth_link()
1265-
.find_by_subject(&provider, "subject")
1266-
.await
1267-
.unwrap()
1268-
.expect("link exists");
1269-
1270-
assert_eq!(link.user_id, Some(user.id));
1271+
assert_eq!(registration.password, None);
1272+
assert_eq!(registration.completed_at, None);
1273+
assert_eq!(registration.username, "john");
12711274

1272-
let page = repo
1275+
let email_auth_id = registration
1276+
.email_authentication_id
1277+
.expect("registration should have an email authentication");
1278+
let email_auth: UserEmailAuthentication = repo
12731279
.user_email()
1274-
.list(UserEmailFilter::new().for_user(&user), Pagination::first(1))
1280+
.lookup_authentication(email_auth_id)
12751281
.await
1276-
.unwrap();
1277-
let edge = page.edges.first().expect("email exists");
1278-
1279-
assert_eq!(edge.node.email, "[email protected]");
1282+
.unwrap()
1283+
.expect("email authentication should exist");
1284+
assert_eq!(email_auth.email, "[email protected]");
1285+
assert!(email_auth.completed_at.is_some());
12801286
}
12811287

12821288
#[sqlx::test(migrator = "mas_storage_pg::MIGRATOR")]

0 commit comments

Comments
 (0)