ultisuite-backend/internal/migration/httpmock_test.go
R3D347HR4Y 7143a36c19
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(mail): integrate Stalwart hosted mail and migration features
- Added configuration options for Stalwart hosted mail in .env.example.
- Updated Docker Compose to include Stalwart service with health checks.
- Introduced new API endpoints for managing mail domains and migration projects.
- Enhanced Authentik blueprints for user enrollment and post-migration security.
- Updated OAuth handling for Google and Microsoft migration processes.
- Improved error handling and response structures in the mail API.
- Added integration tests for email claiming and migration workflows.
2026-06-13 12:47:08 +02:00

60 lines
1.2 KiB
Go

package migration
import (
"net/http"
"net/http/httptest"
"net/url"
"strings"
"testing"
)
type hostRewriteTransport struct {
mockBase string
match func(host string) bool
base http.RoundTripper
}
func (rt *hostRewriteTransport) RoundTrip(req *http.Request) (*http.Response, error) {
if rt.match(req.URL.Host) {
mockURL, err := url.Parse(rt.mockBase)
if err != nil {
return nil, err
}
req.URL.Scheme = mockURL.Scheme
req.URL.Host = mockURL.Host
}
base := rt.base
if base == nil {
base = http.DefaultTransport
}
return base.RoundTrip(req)
}
func mockGoogleHTTPClient(t *testing.T, handler http.HandlerFunc) *http.Client {
t.Helper()
srv := httptest.NewServer(handler)
t.Cleanup(srv.Close)
return &http.Client{
Transport: &hostRewriteTransport{
mockBase: srv.URL,
match: func(host string) bool {
return strings.Contains(host, "googleapis.com")
},
},
}
}
func mockGraphHTTPClient(t *testing.T, handler http.HandlerFunc) *http.Client {
t.Helper()
srv := httptest.NewServer(handler)
t.Cleanup(srv.Close)
return &http.Client{
Transport: &hostRewriteTransport{
mockBase: srv.URL,
match: func(host string) bool {
return strings.Contains(host, "graph.microsoft.com")
},
},
}
}