(t *testing.T)
| 603 | } |
| 604 | |
| 605 | func TestAllSessionDeleteInvalidation(t *testing.T) { |
| 606 | rt := NewRestTester(t, nil) |
| 607 | defer rt.Close() |
| 608 | |
| 609 | const username = "user1" |
| 610 | |
| 611 | rt.CreateUser(username, []string{"*"}) |
| 612 | |
| 613 | const numSessions = 3 |
| 614 | cookies := make([]string, numSessions) |
| 615 | for i := 0; i < 3; i++ { |
| 616 | response := rt.SendUserRequest(http.MethodPost, "/{{.db}}/_session", "", username) |
| 617 | RequireStatus(t, response, http.StatusOK) |
| 618 | cookie := response.Header().Get("Set-Cookie") |
| 619 | require.NotEqual(t, "", cookie) |
| 620 | cookies[i] = cookie |
| 621 | } |
| 622 | // Create a doc as the first user, with session auth, channel-restricted to first user |
| 623 | firstCookieHeaders := map[string]string{ |
| 624 | "Cookie": cookies[0], |
| 625 | } |
| 626 | response := rt.SendRequestWithHeaders(http.MethodPut, "/{{.keyspace}}/doc1", `{"hi": "there"}`, firstCookieHeaders) |
| 627 | RequireStatus(t, response, http.StatusCreated) |
| 628 | |
| 629 | // make sure all sessions work to GET doc |
| 630 | for _, cookie := range cookies { |
| 631 | cookieHeaders := map[string]string{ |
| 632 | "Cookie": cookie, |
| 633 | } |
| 634 | |
| 635 | response = rt.SendRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/doc1", "", cookieHeaders) |
| 636 | RequireStatus(t, response, http.StatusOK) |
| 637 | } |
| 638 | |
| 639 | // make sure password works to GET doc |
| 640 | response = rt.SendUserRequest(http.MethodGet, "/{{.keyspace}}/doc1", "", username) |
| 641 | RequireStatus(t, response, http.StatusOK) |
| 642 | |
| 643 | // DELETE all sessions for a user |
| 644 | response = rt.SendAdminRequest("DELETE", fmt.Sprintf("/{{.db}}/_user/%s/_session", username), "") |
| 645 | RequireStatus(t, response, http.StatusOK) |
| 646 | |
| 647 | // make sure all sessions are invalid |
| 648 | for _, cookie := range cookies { |
| 649 | cookieHeaders := map[string]string{ |
| 650 | "Cookie": cookie, |
| 651 | } |
| 652 | |
| 653 | response = rt.SendRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/doc1", "", cookieHeaders) |
| 654 | RequireStatus(t, response, http.StatusUnauthorized) |
| 655 | require.Contains(t, response.Body.String(), "Session no longer valid") |
| 656 | } |
| 657 | |
| 658 | // make sure password still works |
| 659 | response = rt.SendUserRequest(http.MethodGet, "/{{.keyspace}}/doc1", "", username) |
| 660 | RequireStatus(t, response, http.StatusOK) |
| 661 | |
| 662 | } |
nothing calls this directly
no test coverage detected