From b3af7170130f28e2ac602b0c259a096e38e56e4e Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 6 Mar 2026 15:46:11 -0600 Subject: [PATCH] fix: update e2e scripts to use correct TOTP API - Fix create_test_user.exs to use create_totp_device instead of create_user_credential - Update TOTP_SETUP.md to reference UserTotpDevice schema and user_totp_devices table - Fix function signatures to match Accounts.create_totp_device(user_id, device_name, secret) - Add terms_of_service_consent and privacy_policy_consent to user registration --- e2e/TOTP_SETUP.md | 21 ++++++++------------- e2e/scripts/create_test_user.exs | 24 ++++++++---------------- 2 files changed, 16 insertions(+), 29 deletions(-) diff --git a/e2e/TOTP_SETUP.md b/e2e/TOTP_SETUP.md index 662b6917..68a8ff29 100644 --- a/e2e/TOTP_SETUP.md +++ b/e2e/TOTP_SETUP.md @@ -64,18 +64,17 @@ iex -S mix # Get the TOTP secret user = Towerops.Accounts.get_user_by_email("your-test@example.com") -credential = Towerops.Repo.get_by(Towerops.Accounts.UserCredential, user_id: user.id, type: :totp) -IO.puts("TOTP Secret: #{credential.totp_secret}") +device = Towerops.Repo.get_by(Towerops.Accounts.UserTotpDevice, user_id: user.id) +IO.puts("TOTP Secret: #{device.totp_secret}") ``` **Via SQL:** ```sql -SELECT u.email, uc.totp_secret +SELECT u.email, utd.totp_secret FROM users u -JOIN user_credentials uc ON uc.user_id = u.id -WHERE u.email = 'your-test@example.com' - AND uc.type = 'totp'; +JOIN user_totp_devices utd ON utd.user_id = u.id +WHERE u.email = 'your-test@example.com'; ``` ### Add to .env @@ -107,11 +106,7 @@ alias Towerops.{Accounts, Organizations, Repo} # Set a known TOTP secret totp_secret = "JBSWY3DPEHPK3PXP" -{:ok, _credential} = Accounts.create_user_credential(user, %{ - type: :totp, - totp_secret: totp_secret, - enabled: true -}) +{:ok, _device, _secret} = Accounts.create_totp_device(user.id, "E2E Test Device", totp_secret) # Create an organization {:ok, _org} = Organizations.create_organization(%{ @@ -137,8 +132,8 @@ If you want to skip TOTP entirely for testing (not recommended for production-li ```elixir user = Accounts.get_user_by_email("test@example.com") -credential = Repo.get_by(Accounts.UserCredential, user_id: user.id, type: :totp) -if credential, do: Repo.delete(credential) +device = Repo.get_by(Accounts.UserTotpDevice, user_id: user.id) +if device, do: Repo.delete(device) ``` ### 2. Update Auth Setup diff --git a/e2e/scripts/create_test_user.exs b/e2e/scripts/create_test_user.exs index 69c6d4b3..b94b31e6 100644 --- a/e2e/scripts/create_test_user.exs +++ b/e2e/scripts/create_test_user.exs @@ -33,12 +33,8 @@ case Accounts.get_user_by_email(email) do # Set up TOTP IO.puts("Setting up TOTP authentication...") - case Accounts.create_user_credential(user, %{ - type: :totp, - totp_secret: totp_secret, - enabled: true - }) do - {:ok, _credential} -> + case Accounts.create_totp_device(user.id, "E2E Test Device", totp_secret) do + {:ok, _device, _secret} -> IO.puts("[OK] TOTP enabled!") # Create organization @@ -76,29 +72,25 @@ case Accounts.get_user_by_email(email) do IO.puts("[WARN] User already exists: #{email}") IO.puts("\nExisting user details:") - # Get TOTP credential - credential = Repo.get_by(Accounts.UserCredential, user_id: user.id, type: :totp) + # Get TOTP device + device = Repo.get_by(Accounts.UserTotpDevice, user_id: user.id) - if credential do + if device do IO.puts("\n" <> String.duplicate("=", 40)) IO.puts("\nE2E Test User Credentials:") IO.puts("\nAdd these to e2e/.env:\n") IO.puts("TEST_USER_EMAIL=#{email}") IO.puts("TEST_USER_PASSWORD=#{password}") - IO.puts("TEST_USER_TOTP_SECRET=#{credential.totp_secret}") + IO.puts("TEST_USER_TOTP_SECRET=#{device.totp_secret}") IO.puts("\n" <> String.duplicate("=", 40) <> "\n") else - IO.puts("[WARN] No TOTP credential found for this user") + IO.puts("[WARN] No TOTP device found for this user") IO.puts("\nTo set up TOTP manually, run:") IO.puts(""" user = Towerops.Accounts.get_user_by_email("#{email}") - Towerops.Accounts.create_user_credential(user, %{ - type: :totp, - totp_secret: "#{totp_secret}", - enabled: true - }) + Towerops.Accounts.create_totp_device(user.id, "E2E Test Device", "#{totp_secret}") """) end