Skip to content

Commit 47fb875

Browse files
committed
add tesing && review
1 parent 82cf7cb commit 47fb875

3 files changed

Lines changed: 75 additions & 3 deletions

File tree

cmd/extensions.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,5 +414,4 @@ func init() {
414414
extensionsUploadCmd.Flags().String("name", "", "Optional unique extension name")
415415
extensionsPrepareWebBotAuthCmd.Flags().String("output", "./web-bot-auth", "Output directory for the prepared extension")
416416
extensionsPrepareWebBotAuthCmd.Flags().String("url", "http://127.0.0.1:10001", "Base URL for update.xml and policy templates")
417-
extensionsPrepareWebBotAuthCmd.Flags().String("version", "main", "GitHub branch or tag to download")
418417
}

pkg/extensions/webbotauth.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ func displayWebBotAuthSuccess(outputDir, extensionID, hostURL string) {
329329
pterm.Info.Println("Next steps:")
330330
pterm.Printf("1. Upload using the extension ID as the name:\n")
331331
pterm.Printf(" kernel extensions upload %s --name %s\n\n", outputDir, extensionID)
332-
pterm.Printf("2. Use in your browser:\n")
333-
pterm.Printf(" kernel browsers create --extension %s\n\n", extensionID)
332+
pterm.Printf("2. Use in your browser, or upload to a session:\n")
333+
pterm.Printf(" kernel browsers create --extension %s\n", extensionID)
334+
pterm.Printf(" or run kernel browsers extensions upload <session-id> %s\n\n", outputDir)
334335
pterm.Warning.Println("⚠️ Keep private_key.pem secure - it determines your extension ID!")
335336
}

pkg/extensions/webbotauth_test.go

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package extensions
2+
3+
import (
4+
"context"
5+
"net/http"
6+
"testing"
7+
"time"
8+
)
9+
10+
// TestWebBotAuthDownloadable verifies that the web-bot-auth package can be downloaded from GitHub
11+
func TestWebBotAuthDownloadable(t *testing.T) {
12+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
13+
defer cancel()
14+
15+
client := &http.Client{
16+
Timeout: 30 * time.Second,
17+
}
18+
19+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, webBotAuthDownloadURL, nil)
20+
if err != nil {
21+
t.Fatalf("Failed to create request: %v", err)
22+
}
23+
24+
resp, err := client.Do(req)
25+
if err != nil {
26+
t.Fatalf("Failed to download web-bot-auth: %v", err)
27+
}
28+
defer resp.Body.Close()
29+
30+
if resp.StatusCode != http.StatusOK {
31+
t.Fatalf("Expected status 200, got %d", resp.StatusCode)
32+
}
33+
34+
// Verify Content-Type indicates a zip file
35+
contentType := resp.Header.Get("Content-Type")
36+
if contentType != "application/zip" && contentType != "application/x-zip-compressed" {
37+
t.Logf("Warning: unexpected Content-Type: %s (expected application/zip)", contentType)
38+
}
39+
40+
// Verify Content-Length is reasonable (should be at least 1KB)
41+
contentLength := resp.ContentLength
42+
if contentLength > 0 && contentLength < 1024 {
43+
t.Fatalf("Content-Length too small: %d bytes (expected at least 1KB)", contentLength)
44+
}
45+
46+
t.Logf("Successfully verified web-bot-auth is downloadable")
47+
t.Logf("Content-Type: %s", contentType)
48+
t.Logf("Content-Length: %d bytes", contentLength)
49+
}
50+
51+
// TestDownloadAndExtractWebBotAuth tests the full download and extraction process
52+
func TestDownloadAndExtractWebBotAuth(t *testing.T) {
53+
if testing.Short() {
54+
t.Skip("Skipping download test in short mode")
55+
}
56+
57+
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
58+
defer cancel()
59+
60+
browserExtDir, cleanup, err := downloadAndExtractWebBotAuth(ctx)
61+
defer cleanup()
62+
63+
if err != nil {
64+
t.Fatalf("Failed to download and extract web-bot-auth: %v", err)
65+
}
66+
67+
if browserExtDir == "" {
68+
t.Fatal("Expected non-empty browser extension directory path")
69+
}
70+
71+
t.Logf("Successfully downloaded and extracted to: %s", browserExtDir)
72+
}

0 commit comments

Comments
 (0)