Files
orbit/internal/transport/httpserver/console_test.go

35 lines
1.0 KiB
Go

package httpserver
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
)
func TestConsoleIsEmbeddedAndDoesNotRequireCredentials(t *testing.T) {
server := New("127.0.0.1:0", nil)
r := httptest.NewRequest(http.MethodGet, "/console/", nil)
w := httptest.NewRecorder()
server.Handler.ServeHTTP(w, r)
if w.Code != http.StatusOK {
t.Fatalf("status = %d, want 200", w.Code)
}
if got := w.Header().Get("Content-Type"); !strings.Contains(got, "text/html") {
t.Fatalf("content type = %q, want HTML", got)
}
if !strings.Contains(w.Body.String(), "Orbit Console") {
t.Fatal("embedded console page is missing its title")
}
}
func TestConsoleRedirectsWithoutTouchingAPIAuthentication(t *testing.T) {
server := New("127.0.0.1:0", nil)
r := httptest.NewRequest(http.MethodGet, "/console", nil)
w := httptest.NewRecorder()
server.Handler.ServeHTTP(w, r)
if w.Code != http.StatusPermanentRedirect || w.Header().Get("Location") != "/console/" {
t.Fatalf("redirect = %d %q", w.Code, w.Header().Get("Location"))
}
}