pomerium/proxy/portal/logo_provider_test.go
Caleb Doxsey 3c5c7fbd31
proxy: add logo discovery (#5448)
* proxy: add logo discovery

* use a static url for testing
2025-01-29 12:57:26 -07:00

37 lines
936 B
Go

package portal_test
import (
"io"
"net/http"
"net/http/httptest"
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/pomerium/pomerium/internal/testutil"
"github.com/pomerium/pomerium/proxy/portal"
)
func TestLogoProvider(t *testing.T) {
t.Parallel()
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/icon":
w.Header().Set("Content-Type", "image/vnd.microsoft.icon")
io.WriteString(w, "NOT ACTUALLY AN ICON")
case "/":
io.WriteString(w, `<!doctype html><html><head><link rel="icon" href="/icon" /></head><body></body></html>`)
default:
http.NotFound(w, r)
}
}))
t.Cleanup(srv.Close)
ctx := testutil.GetContext(t, time.Minute)
p := portal.NewLogoProvider()
u, err := p.GetLogoURL(ctx, "", srv.URL)
assert.NoError(t, err)
assert.Equal(t, "data:image/vnd.microsoft.icon;base64,Tk9UIEFDVFVBTExZIEFOIElDT04=", u)
}