- Introduced a new `.env.test.example` file for integration test configuration. - Added a `Makefile` to streamline test commands for unit and integration tests. - Implemented an integration testing harness with support for PostgreSQL, MinIO, and Redis using testcontainers. - Created a suite of integration tests covering health checks and user management functionalities. - Enhanced CI workflow to include integration tests with necessary environment variables.
46 lines
1.4 KiB
Go
46 lines
1.4 KiB
Go
//go:build integration
|
|
|
|
package auth_test
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/ultisuite/ulti-backend/internal/integrationtest"
|
|
)
|
|
|
|
func TestUserProvisionedOnFirstRequest(t *testing.T) {
|
|
h := integrationtest.RequireHarness(t)
|
|
externalID := integrationtest.NewExternalID("provision")
|
|
claims := integrationtest.RegularUser(externalID)
|
|
client, err := h.Client(claims)
|
|
integrationtest.FailIf(err, t, "client")
|
|
|
|
resp, err := client.Get("/api/v1/mail/settings")
|
|
integrationtest.FailIf(err, t, "GET settings")
|
|
integrationtest.FailUnlessStatus(t, resp, 200)
|
|
integrationtest.AssertUserProvisioned(t, h, externalID)
|
|
}
|
|
|
|
func TestDisabledUserForbidden(t *testing.T) {
|
|
h := integrationtest.RequireHarness(t)
|
|
externalID := integrationtest.NewExternalID("disabled")
|
|
claims := integrationtest.RegularUser(externalID)
|
|
client, err := h.Client(claims)
|
|
integrationtest.FailIf(err, t, "client")
|
|
|
|
resp, err := client.Get("/api/v1/mail/settings")
|
|
integrationtest.FailIf(err, t, "provision user")
|
|
integrationtest.FailUnlessStatus(t, resp, 200)
|
|
|
|
if err := integrationtest.DisableUser(context.Background(), h, externalID); err != nil {
|
|
t.Fatalf("disable user: %v", err)
|
|
}
|
|
|
|
resp, err = client.Get("/api/v1/mail/settings")
|
|
integrationtest.FailIf(err, t, "GET after disable")
|
|
if resp.Status != 403 {
|
|
t.Fatalf("status = %d, want 403; body = %s", resp.Status, string(resp.Body))
|
|
}
|
|
}
|