Skip to content

Commit

Permalink
Merge branch 'francisco/remove_session_token_tests' into 'master'
Browse files Browse the repository at this point in the history
feat: temporary remove session token tests

See merge request TankerHQ/sdk-rust!99
  • Loading branch information
francisco-tanker committed Apr 7, 2022
2 parents 95e1b49 + 876989c commit a99b93e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 133 deletions.
7 changes: 0 additions & 7 deletions tests/identity/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ impl Admin {
id: &str,
oidc_client_id: Option<&str>,
oidc_provider: Option<&str>,
with_session_token: Option<bool>,
preverified_verification: Option<bool>,
) -> Result<(), Error> {
let url = self.make_url(id);
Expand All @@ -80,12 +79,6 @@ impl Admin {
if let Some(oidc_provider) = oidc_provider {
json.insert("oidc_provider".to_owned(), oidc_provider.into());
}
if let Some(with_session_token) = with_session_token {
json.insert(
"session_certificates_enabled".to_owned(),
with_session_token.into(),
);
}
if let Some(preverified_verification) = preverified_verification {
json.insert(
"preverified_verification_enabled".to_owned(),
Expand Down
2 changes: 0 additions & 2 deletions tests/identity/test_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ impl TestApp {
&self,
oidc_client_id: Option<&str>,
oidc_provider: Option<&str>,
with_session_token: Option<bool>,
preverified_verification: Option<bool>,
) -> Result<(), Error> {
self.admin
.app_update(
&self.app.id,
oidc_client_id,
oidc_provider,
with_session_token,
preverified_verification,
)
.await
Expand Down
131 changes: 7 additions & 124 deletions tests/verify_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ async fn unlock_with_oidc_id_token() -> Result<(), Box<dyn std::error::Error>> {
let martine_config = &oidc.users["martine"];
let martine_identity = app.create_identity(Some(martine_config.email.clone()));

app.app_update(Some(&oidc.client_id), Some(&oidc.provider), None, None)
app.app_update(Some(&oidc.client_id), Some(&oidc.provider), None)
.await?;

let client = reqwest::Client::new();
Expand Down Expand Up @@ -212,127 +212,10 @@ async fn unlock_with_oidc_id_token() -> Result<(), Box<dyn std::error::Error>> {
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn get_session_token_with_register_identity() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, Some(true), None).await?;

let id = &app.create_identity(None);
let pass = Verification::Passphrase("The Cost of Legacy".into());

let tanker = Core::new(app.make_options()).await?;
tanker.start(id).await?;
let token = tanker
.register_identity(&pass, &VerificationOptions::new().with_session_token())
.await?;
assert!(token.is_some());
tanker.stop().await?;
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn get_session_token_with_verify_identity() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, Some(true), None).await?;

let id = &app.create_identity(None);
let pass = Verification::Passphrase("Merge remote-tracking branch 'rust/rust-next'".into());

let tanker = Core::new(app.make_options()).await?;
tanker.start(id).await?;
tanker
.register_identity(&pass, &VerificationOptions::new())
.await?;

let token = tanker
.verify_identity(&pass, &VerificationOptions::new().with_session_token())
.await?;
assert!(token.is_some());
tanker.stop().await?;
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn get_session_token_with_set_verififcation_method() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, Some(true), None).await?;

let id = &app.create_identity(None);
let pass = Verification::Passphrase("Phobos".into());
let pass2 = Verification::Passphrase("Deimos".into());

let tanker = Core::new(app.make_options()).await?;
tanker.start(id).await?;
tanker
.register_identity(&pass, &VerificationOptions::new())
.await?;

let token = tanker
.set_verification_method(&pass2, &VerificationOptions::new().with_session_token())
.await?;
assert!(token.is_some());
tanker.stop().await?;
Ok(())
}

async fn check_session_token_with_server(
app: &TestApp,
public_identity: &str,
session_token: &str,
allowed_method: &str,
) -> Result<String, Box<dyn std::error::Error>> {
let url = format!("{}/verification/session-token", app.trustchaind_url(),);

let reply: Value = reqwest::Client::new()
.post(url)
.json(&json!({
"app_id": app.id(),
"auth_token": app.auth_token(),
"public_identity": public_identity,
"session_token": session_token,
"allowed_methods": [{
"type": allowed_method
}]
}))
.send()
.await?
.json()
.await?;
Ok(reply["verification_method"].as_str().unwrap().to_owned())
}

#[tokio::test(flavor = "multi_thread")]
async fn check_session_token_is_valid() -> Result<(), Box<dyn std::error::Error>> {
let app = TestApp::get().await;
app.app_update(None, None, Some(true), None).await?;

let tanker = Core::new(app.make_options()).await?;
let identity = &app.create_identity(None);
tanker.start(identity).await?;
let token = tanker
.register_identity(
&Verification::Passphrase("Less than three".into()),
&VerificationOptions::new().with_session_token(),
)
.await?
.unwrap();

let expected_method = "passphrase";
let actual_method_used = check_session_token_with_server(
&app,
&app.get_public_identity(identity),
&token,
expected_method,
)
.await?;
assert_eq!(expected_method, actual_method_used);
Ok(())
}

#[tokio::test(flavor = "multi_thread")]
async fn register_fail_with_preverified_email() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let email = "[email protected]";

Expand All @@ -354,7 +237,7 @@ async fn register_fail_with_preverified_email() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
async fn register_fail_with_preverified_phone_number() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let phone_number = "+33639982233";

Expand All @@ -376,7 +259,7 @@ async fn register_fail_with_preverified_phone_number() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
async fn verify_identity_fail_with_preverified_email() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let email = "[email protected]";

Expand Down Expand Up @@ -409,7 +292,7 @@ async fn verify_identity_fail_with_preverified_email() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
async fn verify_identity_fail_with_preverified_phone_number() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let phone_number = "+33639982233";

Expand Down Expand Up @@ -442,7 +325,7 @@ async fn verify_identity_fail_with_preverified_phone_number() -> Result<(), Erro
#[tokio::test(flavor = "multi_thread")]
async fn set_verification_method_with_preverified_email() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let pass = Verification::Passphrase("The Beauty In The Ordinary".into());
let email = "[email protected]";
Expand Down Expand Up @@ -497,7 +380,7 @@ async fn set_verification_method_with_preverified_email() -> Result<(), Error> {
#[tokio::test(flavor = "multi_thread")]
async fn set_verification_method_with_preverified_phone_number() -> Result<(), Error> {
let app = TestApp::get().await;
app.app_update(None, None, None, Some(true)).await?;
app.app_update(None, None, Some(true)).await?;
let id = &app.create_identity(None);
let pass = Verification::Passphrase("The Beauty In The Ordinary".into());
let phone_number = "+33639982233".to_string();
Expand Down

0 comments on commit a99b93e

Please sign in to comment.