ultisuite-backend/internal/provision/handler_test.go
R3D347HR4Y 1ffd0817d8
Some checks are pending
CI / Go tests (push) Waiting to run
CI / Integration tests (push) Waiting to run
CI / DB migrations (push) Waiting to run
feat(migration): enhance migration API with roster and audit export features
- Added endpoints for listing and importing migration rosters.
- Introduced audit export functionality for migration jobs in CSV and NDJSON formats.
- Implemented tenant mismatch validation for Microsoft migration claims.
- Enhanced error handling for email claiming and migration processes.
- Added integration tests for roster import and claim workflows.
2026-06-13 13:11:30 +02:00

53 lines
1.6 KiB
Go

package provision
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
)
func TestDecodeProvisionBodyAuthentikPayload(t *testing.T) {
body := []byte(`{
"email": "alice@ultisuite.fr",
"password": "secret",
"name": "Alice",
"external_id": "uuid-123",
"user": {"email": "ignored@example.com", "uuid": "ignored"}
}`)
req := httptest.NewRequest(http.MethodPost, "/internal/provision/user", bytes.NewReader(body))
got, err := decodeProvisionBody(req)
if err != nil {
t.Fatalf("decodeProvisionBody() error = %v", err)
}
if got.Email != "alice@ultisuite.fr" || got.ExternalID != "uuid-123" || got.Name != "Alice" {
t.Fatalf("decodeProvisionBody() = %#v", got)
}
}
func TestAuthorizeProvisionSecret(t *testing.T) {
req := httptest.NewRequest(http.MethodPost, "/internal/provision/user", nil)
req.Header.Set("X-Provision-Secret", "topsecret")
if !authorizeProvision(req, "topsecret") {
t.Fatal("expected header secret to authorize")
}
req = httptest.NewRequest(http.MethodPost, "/internal/provision/user?secret=topsecret", nil)
if !authorizeProvision(req, "topsecret") {
t.Fatal("expected query secret to authorize")
}
if authorizeProvision(req, "wrong") {
t.Fatal("expected wrong secret to fail")
}
}
func TestNormalizeProvisionRequestUsesUsername(t *testing.T) {
req := provisionUserRequest{Username: "bob@ultisuite.fr"}
normalizeProvisionRequest(&req)
if req.Email != "bob@ultisuite.fr" {
t.Fatalf("email = %q, want bob@ultisuite.fr", req.Email)
}
if req.Name != "bob@ultisuite.fr" {
t.Fatalf("name = %q, want fallback to email", req.Name)
}
}