Fix stale cmd/ scripts, export LoginWithChromedp, clean up vet warnings

Update 5 cmd/ test utilities that referenced APIs that drifted after
bridge refactors (NewBrowserAuthManager, bridge.NewConfig, changed
function signatures). Rewrite test-kosmi and test-native to use
NewGraphQLWSClient directly. Export LoginWithChromedp for use by cmd
scripts. Fix redundant-newline vet warnings across 5 cmd/ files.
Remove unreachable code and replace deprecated ioutil calls in
bridge/helper/lottie_convert.go.

Made-with: Cursor
This commit is contained in:
cottongin
2026-04-05 05:49:26 -04:00
parent 4fc7f08b24
commit d314193540
12 changed files with 213 additions and 74 deletions

View File

@@ -1,11 +1,14 @@
package main
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"os"
"strings"
"time"
bkosmi "github.com/42wim/matterbridge/bridge/kosmi"
"github.com/sirupsen/logrus"
@@ -36,10 +39,9 @@ func main() {
fmt.Println(strings.Repeat("=", 80))
fmt.Println()
// Get anonymous token
// Get anonymous token via HTTP (same mutation the client uses internally)
fmt.Println("📝 Step 1: Getting anonymous token...")
client := bkosmi.NewGraphQLWSClient("https://app.kosmi.io/room/@test", "@test", entry)
anonToken, err := client.GetAnonymousTokenForTest()
anonToken, err := getAnonymousToken()
if err != nil {
fmt.Printf("❌ Failed to get anonymous token: %v\n", err)
os.Exit(1)
@@ -47,10 +49,9 @@ func main() {
fmt.Printf("✅ Anonymous token obtained (length: %d)\n", len(anonToken))
fmt.Println()
// Get authenticated token
// Get authenticated token via browser automation
fmt.Println("📝 Step 2: Getting authenticated token via browser...")
browserAuth := bkosmi.NewBrowserAuthManager(email, password, entry)
authToken, err := browserAuth.GetToken()
authToken, err := bkosmi.LoginWithChromedp(email, password, entry)
if err != nil {
fmt.Printf("❌ Failed to get authenticated token: %v\n", err)
os.Exit(1)
@@ -134,6 +135,49 @@ func printClaims(claims map[string]interface{}) {
}
}
func getAnonymousToken() (string, error) {
mutation := map[string]interface{}{
"query": `mutation { anonLogin { token } }`,
}
jsonBody, err := json.Marshal(mutation)
if err != nil {
return "", err
}
client := &http.Client{Timeout: 10 * time.Second}
req, err := http.NewRequest("POST", "https://engine.kosmi.io/", bytes.NewReader(jsonBody))
if err != nil {
return "", err
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Referer", "https://app.kosmi.io/")
req.ContentLength = int64(len(jsonBody))
resp, err := client.Do(req)
if err != nil {
return "", err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return "", fmt.Errorf("HTTP %d", resp.StatusCode)
}
var result map[string]interface{}
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return "", err
}
if data, ok := result["data"].(map[string]interface{}); ok {
if anonLogin, ok := data["anonLogin"].(map[string]interface{}); ok {
if token, ok := anonLogin["token"].(string); ok {
return token, nil
}
}
}
return "", fmt.Errorf("no token in response")
}
func compareClaims(anon, auth map[string]interface{}) {
allKeys := make(map[string]bool)
for k := range anon {