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
This commit is contained in:
parent
70c82ba8f1
commit
b3af717013
2 changed files with 16 additions and 29 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue