File size: 2,948 Bytes
6a7089a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/bin/bash
# 20-auto-https.sh β€” Test auto-https prefix for CLI URL arguments
# Verifies that CLI commands automatically prepend https:// to URLs without protocol

source "$(dirname "$0")/common.sh"

# ─────────────────────────────────────────────────────────────────
start_test "auto-https: goto without protocol adds https://"

# Navigate to fixture hostname without protocol
# Since fixtures are HTTP-only, https:// navigation will land on error page
pt goto "fixtures:80/index.html"

# Chrome shows error page for failed https:// - check URL or title indicates error
if echo "$PT_OUT" | grep -qiE "chrome-error|err_|error|refused|failed|ssl"; then
  echo -e "  ${GREEN}βœ“${NC} CLI added https:// prefix (Chrome shows error page)"
  ((ASSERTIONS_PASSED++)) || true
elif [ "$PT_CODE" -ne 0 ]; then
  echo -e "  ${GREEN}βœ“${NC} CLI added https:// prefix (navigation failed as expected)"
  ((ASSERTIONS_PASSED++)) || true
else
  # Check if the URL in response starts with https://
  if echo "$PT_OUT" | grep -q '"url".*https://'; then
    echo -e "  ${GREEN}βœ“${NC} CLI added https:// prefix (URL in response shows https)"
    ((ASSERTIONS_PASSED++)) || true
  else
    echo -e "  ${RED}βœ—${NC} Expected https:// URL or error, got: $PT_OUT"
    ((ASSERTIONS_FAILED++)) || true
  fi
fi

end_test

# ─────────────────────────────────────────────────────────────────
start_test "auto-https: explicit http:// is preserved"

# Navigate with explicit http:// - should work and URL should be http://
pt_ok goto "http://fixtures:80/index.html"

if echo "$PT_OUT" | grep -q '"url".*http://'; then
  echo -e "  ${GREEN}βœ“${NC} Response URL is http://"
  ((ASSERTIONS_PASSED++)) || true
else
  echo -e "  ${RED}βœ—${NC} Expected http:// in URL"
  ((ASSERTIONS_FAILED++)) || true
fi

end_test

# ─────────────────────────────────────────────────────────────────
start_test "auto-https: explicit https:// is preserved"

# Navigate with explicit https:// to http-only fixture
pt goto "https://fixtures:80/index.html"

# Should show error page or fail (fixture doesn't support HTTPS)
if echo "$PT_OUT" | grep -qiE "chrome-error|err_|error|refused|failed"; then
  echo -e "  ${GREEN}βœ“${NC} Explicit https:// preserved (Chrome shows error)"
  ((ASSERTIONS_PASSED++)) || true
elif echo "$PT_OUT" | grep -q '"url".*https://'; then
  echo -e "  ${GREEN}βœ“${NC} Explicit https:// preserved (URL shows https)"
  ((ASSERTIONS_PASSED++)) || true
else
  echo -e "  ${RED}βœ—${NC} Expected https:// URL or error, got: $PT_OUT"
  ((ASSERTIONS_FAILED++)) || true
fi

end_test