Test for issue 758 - basic auth with stale session cookie
(t *testing.T)
| 170 | |
| 171 | // Test for issue 758 - basic auth with stale session cookie |
| 172 | func TestBasicAuthWithSessionCookie(t *testing.T) { |
| 173 | |
| 174 | rt := NewRestTester(t, &RestTesterConfig{SyncFn: channels.DocChannelsSyncFunction}) |
| 175 | defer rt.Close() |
| 176 | |
| 177 | // Create two users |
| 178 | rt.CreateUser("bernard", []string{"bernard"}) |
| 179 | rt.CreateUser("manny", []string{"manny"}) |
| 180 | |
| 181 | // Create a session for the first user |
| 182 | response := rt.Send(RequestByUser("POST", "/db/_session", `{"name":"bernard", "password":"letmein"}`, "bernard")) |
| 183 | log.Println("response.Header()", response.Header()) |
| 184 | assert.True(t, response.Header().Get("Set-Cookie") != "") |
| 185 | |
| 186 | cookie := response.Header().Get("Set-Cookie") |
| 187 | |
| 188 | // Create a doc as the first user, with session auth, channel-restricted to first user |
| 189 | reqHeaders := map[string]string{ |
| 190 | "Cookie": cookie, |
| 191 | } |
| 192 | response = rt.SendRequestWithHeaders("PUT", "/{{.keyspace}}/bernardDoc", `{"hi": "there", "channels":["bernard"]}`, reqHeaders) |
| 193 | RequireStatus(t, response, 201) |
| 194 | response = rt.SendRequestWithHeaders("GET", "/{{.keyspace}}/bernardDoc", "", reqHeaders) |
| 195 | RequireStatus(t, response, 200) |
| 196 | |
| 197 | // Create a doc as the second user, with basic auth, channel-restricted to the second user |
| 198 | response = rt.SendUserRequest("PUT", "/{{.keyspace}}/mannyDoc", `{"hi": "there", "channels":["manny"]}`, "manny") |
| 199 | RequireStatus(t, response, 201) |
| 200 | response = rt.SendUserRequest("GET", "/{{.keyspace}}/mannyDoc", "", "manny") |
| 201 | RequireStatus(t, response, 200) |
| 202 | response = rt.SendUserRequest("GET", "/{{.keyspace}}/bernardDoc", "", "manny") |
| 203 | RequireStatus(t, response, 403) |
| 204 | |
| 205 | // Attempt to retrieve the docs with the first user's cookie, second user's basic auth credentials. Basic Auth should take precedence |
| 206 | response = rt.SendUserRequestWithHeaders("GET", "/{{.keyspace}}/bernardDoc", "", reqHeaders, "manny", "letmein") |
| 207 | RequireStatus(t, response, 403) |
| 208 | response = rt.SendUserRequestWithHeaders("GET", "/{{.keyspace}}/mannyDoc", "", reqHeaders, "manny", "letmein") |
| 209 | RequireStatus(t, response, 200) |
| 210 | } |
| 211 | |
| 212 | // Try to create session with invalid cert but valid credentials |
| 213 | func TestSessionFail(t *testing.T) { |
nothing calls this directly
no test coverage detected