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

Function TestCORSLoginOriginOnSessionPost

rest/session_test.go:26–54  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

24)
25
26func TestCORSLoginOriginOnSessionPost(t *testing.T) {
27
28 rt := NewRestTesterPersistentConfigNoDB(t)
29 defer rt.Close()
30
31 // force TLS mode to test SameSite=None cookie attribute
32 rt.ServerContext().Config.API.HTTPS.TLSCertPath = "/pretend/valid/cert"
33
34 RequireStatus(t, rt.CreateDatabase("db", rt.NewDbConfig()), http.StatusCreated)
35
36 reqHeaders := map[string]string{
37 "Origin": "http://example.com",
38 }
39
40 response := rt.SendRequestWithHeaders("POST", "/db/_session", "{\"name\":\"jchris\",\"password\":\"secret\"}", reqHeaders)
41 RequireStatus(t, response, 401)
42
43 response = rt.SendRequestWithHeaders("POST", "/db/_facebook", `{"access_token":"true"}`, reqHeaders)
44 assertGatewayStatus(t, response, 401)
45
46 const username = "alice"
47 rt.CreateUser(username, []string{"*"})
48
49 response = rt.SendUserRequest(http.MethodPost, "/{{.db}}/_session", "", username)
50 RequireStatus(t, response, http.StatusOK)
51 cookie, err := http.ParseSetCookie(response.Header().Get("Set-Cookie"))
52 require.NoError(t, err)
53 require.Equal(t, cookie.SameSite, http.SameSiteNoneMode)
54}
55
56// #issue 991
57func TestCORSLoginOriginOnSessionPostNoCORSConfig(t *testing.T) {

Callers

nothing calls this directly

Calls 13

RequireStatusFunction · 0.85
assertGatewayStatusFunction · 0.85
ServerContextMethod · 0.80
CreateDatabaseMethod · 0.80
NewDbConfigMethod · 0.80
CreateUserMethod · 0.80
SendUserRequestMethod · 0.80
HeaderMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.45

Tested by

no test coverage detected