Files
base/tests/token_helper.go
zeekay ef827c8709 apis,forms,plugins: rip password cascade from consumers
- forms/RecordUpsert no longer manages a plain password / confirm /
  oldPassword triple; Load + validateFormFields only handle the
  email + verified system fields now. DrySubmit + Submit semantics
  unchanged
- apis/installer + apis/superuser_auth_oidc drop SetRandomPassword;
  the installer superuser and the OIDC auto-create path persist a
  verified passwordless record (IAM handles credentials)
- apis/collection_test snapshots updated for the slimmer auth
  collection bootstrap (no system "password" field) and the smaller
  collection inventory (12 not 16); the now-stale "create-base-
  collection-with-oldPassword-rejected" test is deleted because the
  reserved-key check is gone
- plugins/jsvm drops the PasswordField bind
- plugins/zap returns 410 Gone for /identity (the only ZAP path
  that called record.ValidatePassword) — IAM PKCE is the only login
- plugins/migratecmd test no longer probes a PasswordResetToken
  secret on auth collections
- tests/dynamic_stubs loses StubMFARecords + StubOTPRecords;
  tests/token_helper loses GetUserPasswordResetToken
2026-05-15 03:19:15 -07:00

65 lines
2.2 KiB
Go

// Package tests provides test token helper functions.
package tests
import (
"time"
"github.com/hanzoai/base/core"
)
// GetUserAuthToken returns a valid auth token for a test user in the given collection.
// This should be used in tests instead of hardcoded tokens.
func GetUserAuthToken(app core.App, collectionNameOrId, recordId string) (string, error) {
record, err := app.FindRecordById(collectionNameOrId, recordId)
if err != nil {
return "", err
}
return record.NewAuthToken()
}
// GetUserStaticAuthToken returns a long-lived static auth token for testing.
func GetUserStaticAuthToken(app core.App, collectionNameOrId, recordId string) (string, error) {
record, err := app.FindRecordById(collectionNameOrId, recordId)
if err != nil {
return "", err
}
return record.NewStaticAuthToken(86400 * 365 * 100 * time.Second) // 100 years
}
// GetUserVerificationToken returns a verification token for testing.
func GetUserVerificationToken(app core.App, collectionNameOrId, recordId string) (string, error) {
record, err := app.FindRecordById(collectionNameOrId, recordId)
if err != nil {
return "", err
}
return record.NewVerificationToken()
}
// GetSuperuserAuthToken returns a valid auth token for a test superuser.
func GetSuperuserAuthToken(app core.App, recordId string) (string, error) {
return GetUserAuthToken(app, core.CollectionNameSuperusers, recordId)
}
// Common test record IDs (matching tests/data/data.db)
const (
// Users collection (_users_auth_)
TestUserID1 = "4q1xlclmfloku33" // [email protected]
TestUserID2 = "oap640cot4yru2s" // [email protected]
TestUserID3 = "bgs820n361vj1qd" // [email protected]
// Clients collection (v851q4r790rhknl)
TestClientID1 = "gk390qegs4y47wn" // [email protected]
TestClientID2 = "o1y0dd0spd786md" // [email protected]
// Nologin collection (kpv709sk2lqbqk8)
TestNologinID1 = "dc49k6jgejn40h3" // [email protected]
TestNologinID2 = "phhq3wr65cap535" // [email protected]
TestNologinID3 = "oos036e9xvqeexy" // [email protected]
// Superusers collection (hbc_3142635823)
TestSuperuserID1 = "sywbhecnh46rhm0" // [email protected]
TestSuperuserID2 = "sbmbsdb40jyxf7h" // [email protected]
TestSuperuserID3 = "9q2trqumvlyr3bd" // [email protected]
TestSuperuserID4 = "q911776rrfy658l" // [email protected]
)