This commit is contained in:
andy committed 2026-08-18 18:23:11 +08:00
1 parent 648b274c55
commit 18cb51670c
14 files changed
+420 -171

No files matched your search

@@ -78,17 +78,40 @@ func TestApplicationRejectsInvalidProductionDatabaseConfiguration(t *testing.T)
}
func TestProductionApplicationCanStartBeforeProviderSettingsAreConfigured(t *testing.T) {
app, err := application.New(application.Options{Getenv: applicationEnv(map[string]string{
"NODE_ENV": "production",
"ZHINIAN_DATA_BACKEND": "postgres",
"DATABASE_URL": "postgres://user:password@127.0.0.1:5432/zhinian",
})})
app, err := application.New(application.Options{
Getenv: applicationEnv(map[string]string{
"NODE_ENV": "production",
"ZHINIAN_DATA_BACKEND": "postgres",
"DATABASE_URL": "postgres://user:password@127.0.0.1:5432/zhinian",
}),
RuntimeSettingsRepository: applicationRuntimeSettingsRepositoryStub{},
})
if err != nil {
t.Fatalf("New() without provider credentials = %v", err)
}
app.Close()
}
func TestProductionApplicationUsesDatabaseSettingsDuringStartup(t *testing.T) {
app, err := application.New(application.Options{
Getenv: applicationEnv(map[string]string{
"NODE_ENV": "production",
"ZHINIAN_DATA_BACKEND": "postgres",
"DATABASE_URL": "postgres://user:password@127.0.0.1:5432/zhinian",
"ZHINIAN_AUTH_REQUIRED": "1",
"ZHINIAN_BILLING_REQUIRED": "1",
}),
RuntimeSettingsRepository: applicationRuntimeSettingsRepositoryStub{values: map[string]string{
"ZHINIAN_AUTH_REQUIRED": "0",
"ZHINIAN_BILLING_REQUIRED": "0",
}},
})
if err != nil {
t.Fatalf("New() with database startup settings = %v", err)
}
app.Close()
}
func TestProductionLocalBackendNeverGrantsAnonymousAdministrator(t *testing.T) {
app, err := application.New(application.Options{Getenv: applicationEnv(map[string]string{
"NODE_ENV": "production",
@@ -580,6 +603,20 @@ type applicationCredentialAuthenticator struct {
passwords []string
}
type applicationRuntimeSettingsRepositoryStub struct{ values map[string]string }
func (repository applicationRuntimeSettingsRepositoryStub) LoadRuntimeSettings(context.Context, []string) (map[string]string, error) {
values := map[string]string{}
for key, value := range repository.values {
values[key] = value
}
return values, nil
}
func (applicationRuntimeSettingsRepositoryStub) SaveRuntimeSettings(context.Context, map[string]string) error {
return nil
}
func (authenticator *applicationCredentialAuthenticator) AttemptPasswordLogin(_ context.Context, phone, password string, _ time.Time) (identity.LoginAccount, error) {
authenticator.phones = append(authenticator.phones, phone)
authenticator.passwords = append(authenticator.passwords, password)