MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestBlipSyncErrorUserinfo

Function TestBlipSyncErrorUserinfo

db/active_replicator_test.go:25–79  ·  view source on GitHub ↗

TestBlipSyncErrorUserinfo ensures the websocket errors returned by blipSync contain no basic auth component.

(t *testing.T)

Source from the content-addressed store, hash-verified

23
24// TestBlipSyncErrorUserinfo ensures the websocket errors returned by blipSync contain no basic auth component.
25func TestBlipSyncErrorUserinfo(t *testing.T) {
26 tests := []struct {
27 name string
28 username string
29 password string
30 }{
31 {
32 name: "no creds",
33 username: "",
34 password: "",
35 },
36 {
37 name: "username",
38 username: "foo",
39 },
40 {
41 name: "user and password",
42 username: "foo",
43 password: "bar",
44 },
45 }
46
47 for _, test := range tests {
48 t.Run(test.name, func(t *testing.T) {
49 // Create a HTTP server to get past the initial HTTP request inside blipSync.
50 // HTTP errors have basic auth components redacted by the Go stdlib anyway.
51 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
52 w.WriteHeader(http.StatusOK)
53 }))
54 defer srv.Close()
55
56 srvURL, err := url.Parse(srv.URL)
57 require.NoError(t, err)
58
59 if test.username != "" && test.password != "" {
60 srvURL.User = url.UserPassword(test.username, test.password)
61 } else if test.username != "" {
62 srvURL.User = url.User(test.username)
63 }
64
65 srvURL.Path = "/db1"
66 t.Logf("srvURL: %v", srvURL.String())
67
68 _, blipContext, err := NewSGBlipContext(base.TestCtx(t), t.Name(), nil, nil)
69 require.NoError(t, err)
70
71 _, err = blipSync(*srvURL, blipContext, false)
72 require.Error(t, err)
73 t.Logf("error: %v", err)
74 if targetPassword, hasPassword := srvURL.User.Password(); hasPassword {
75 assert.NotContains(t, err.Error(), targetPassword)
76 }
77 })
78 }
79}

Callers

nothing calls this directly

Calls 11

TestCtxFunction · 0.92
NewSGBlipContextFunction · 0.85
blipSyncFunction · 0.85
RunMethod · 0.65
CloseMethod · 0.65
StringMethod · 0.65
NameMethod · 0.65
WriteHeaderMethod · 0.45
UserMethod · 0.45
LogfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected