Initial cloud-services repo - gateway service + pkg modules

This commit is contained in:
Chris Rai
2026-01-30 23:14:52 -05:00
commit fbb820d7b3
1037 changed files with 171318 additions and 0 deletions

View File

@@ -0,0 +1,86 @@
package websocket
import (
"encoding/json"
"fmt"
"net"
"net/http"
"net/http/httptest"
"testing"
"fiskerinc.com/modules/common"
"fiskerinc.com/modules/testhelper"
"github.com/gobwas/ws"
"github.com/gobwas/ws/wsutil"
)
func TestSessionMobile(t *testing.T) {
ws, _ := net.Pipe()
s := SessionMobile{
Session: &Session{
Websocket: ws,
},
}
if fmt.Sprintf("%T", s) != "websocket.SessionMobile" {
t.Errorf(testhelper.TestErrorTemplate, "TestSessionMobile", "websocket.SessionMobile", fmt.Sprintf("%T", s))
}
}
func TestNewSessionMobile(t *testing.T) {
createNewSession := func(w http.ResponseWriter, r *http.Request) {
s, err := NewMobileSession(w, r, "1.2.3.4")
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestNewSessionMobile", nil, err)
}
defer s.Close()
if fmt.Sprintf("%T", s) != "*websocket.SessionMobile" {
t.Errorf(testhelper.TestErrorTemplate, "TestNewSessionMobile", "*websocket.SessionMobile", fmt.Sprintf("%T", s))
}
}
server := httptest.NewServer(http.HandlerFunc(createNewSession))
defer server.Close()
conn := createMockWebsocketClient(server.URL, "")
defer conn.Close()
}
func TestSessionMobileAuthenticate(t *testing.T) {
userAgent := "Mobile 1.2.3.4"
createNewSession := func(w http.ResponseWriter, r *http.Request) {
s, err := NewInsecureSession(w, r)
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestSessionMobileAuthenticate", nil, err)
}
defer s.Close()
err = s.Authenticate()
if err == nil {
t.Errorf(testhelper.TestErrorTemplate, "TestSessionMobileAuthenticate", "error", nil)
}
}
server := httptest.NewServer(http.HandlerFunc(createNewSession))
defer server.Close()
conn := createMockWebsocketClient(server.URL, userAgent)
defer conn.Close()
am := common.MobileSessionMessage{
Handler: "verify",
Data: common.MobileSessionData{
Token: "validtoken",
},
}
msg, err := json.Marshal(am)
if err != nil {
t.Errorf(testhelper.TestErrorTemplate, "TestSessionMobileAuthenticate", nil, err)
}
wsutil.WriteClientMessage(conn, ws.OpText, msg)
}