feat: add embedded Orbit console
This commit is contained in:
34
internal/transport/httpserver/console_test.go
Normal file
34
internal/transport/httpserver/console_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
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"))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user