- handleAuthLogin now authenticates via store.FindUserByPhone instead of FindUserByEmail; the login/bootstrap-super-admin request payload field is now `phone`. Old email addresses are no longer valid login credentials. - bootstrap-super-admin now validates phone format (isValidChinaMobilePhone) instead of net/mail.ParseAddress; net/mail is fully removed from internal/api. - Same-class gap fix: handleAdminOrganizationUsersCreate (the legacy per-organization admin endpoint, not touched by ticket 02) still created users by email only, which would have left them unable to log in under the new phone-only login. Switched it to phone validation/uniqueness too, and removed the now-dead normalizeUserInput/validateUserEmailAvailable helpers. - Frontend: authApi.login, UserContext's login signature, and UserBootstrapPanel's submit handler now send `phone` instead of `email` (the form/labels were already phone-based from ticket 04). - Updated ~20 Go test files whose fixtures/helpers logged in via user.Email; adminCreateUser/loginSession/bootstrapSuperAdminSession now work in terms of phone (deterministically derived from existing email-shaped test identities via testPhoneFromSeed, to avoid rewriting every call site). Added internal/api/auth_phone_login_test.go covering phone login success/failure and old-email rejection. go test ./internal/api/... and npm run test:frontend match their pre-ticket baselines exactly (75 Go failures / 599 frontend tests with 586 pass, 13 fail) by failing test name, not just count.
68 lines
3.3 KiB
Go
68 lines
3.3 KiB
Go
package api
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
|
|
"droboticflow/internal/domain"
|
|
"droboticflow/internal/store"
|
|
)
|
|
|
|
func TestObjectStorageUploadSessionPersistsSkipAndMultipartResumeState(t *testing.T) {
|
|
ctx := context.Background()
|
|
dataStore := store.NewMemoryStore()
|
|
organization, err := dataStore.EnsureDefaultOrganization(ctx)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
passwordHash, err := hashPassword("upload-admin-password")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
admin, err := dataStore.CreateUser(ctx, domain.CreateUserInput{OrganizationID: organization.ID, Name: "Upload Admin", Phone: "13800007001", Role: domain.UserRoleAdmin, PasswordHash: passwordHash})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
connection, err := dataStore.CreateStorageConnection(ctx, domain.CreateStorageConnectionInput{Name: "BOS", Provider: domain.StorageProviderBOS, Endpoint: "https://bos.example.test", Bucket: "datastorage", AccessKeyID: "ak", SecretAccessKey: "sk"})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fakeBrowser := newFakeObjectStorageBrowser()
|
|
fakeBrowser.objects["datastorage|dataset/already.bin"] = domain.ObjectStorageObjectSummary{Bucket: "datastorage", Key: "dataset/already.bin", SizeBytes: 10}
|
|
original := storageConnectionBrowserResolver
|
|
storageConnectionBrowserResolver = func(context.Context, *domain.StorageConnectionRecord) (objectStorageBrowser, func(), error) {
|
|
return fakeBrowser, func() {}, nil
|
|
}
|
|
t.Cleanup(func() { storageConnectionBrowserResolver = original })
|
|
handler := NewHandler(dataStore, nil)
|
|
cookie := loginSession(t, handler, admin.Phone, "upload-admin-password")
|
|
body := `{"bucket":"datastorage","prefix":"dataset","conflictPolicy":"skip","items":[{"relativePath":"already.bin","kind":"file","sizeBytes":10},{"relativePath":"large.bin","kind":"file","sizeBytes":104857600,"contentType":"application/octet-stream"}]}`
|
|
created := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions?connectionId="+connection.ID, []byte(body), cookie)
|
|
if created.Code != http.StatusCreated {
|
|
t.Fatalf("create=%d body=%s", created.Code, created.Body.String())
|
|
}
|
|
var summary domain.ObjectStorageUploadSessionSummary
|
|
if err := json.Unmarshal(created.Body.Bytes(), &summary); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if summary.SkippedCount != 1 || summary.ProcessedBytes != 10 || len(summary.Session.Items) != 2 {
|
|
t.Fatalf("summary=%#v", summary)
|
|
}
|
|
itemID := summary.Session.Items[1].ID
|
|
started := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/items/"+itemID+"/start", nil, cookie)
|
|
if started.Code != http.StatusOK || !strings.Contains(started.Body.String(), `"mode":"multipart"`) {
|
|
t.Fatalf("start=%d body=%s", started.Code, started.Body.String())
|
|
}
|
|
paused := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/pause", nil, cookie)
|
|
if paused.Code != http.StatusOK || !strings.Contains(paused.Body.String(), `"status":"paused"`) {
|
|
t.Fatalf("pause=%d body=%s", paused.Code, paused.Body.String())
|
|
}
|
|
cancelled := serveJSONWithCookie(handler, http.MethodPost, "/api/object-storage/upload-sessions/"+summary.Session.ID+"/cancel", nil, cookie)
|
|
if cancelled.Code != http.StatusOK || !strings.Contains(cancelled.Body.String(), `"status":"cancelled"`) {
|
|
t.Fatalf("cancel=%d body=%s", cancelled.Code, cancelled.Body.String())
|
|
}
|
|
}
|