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

Function TestSessionPasswordInvalidation

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

Source from the content-addressed store, hash-verified

525}
526
527func TestSessionPasswordInvalidation(t *testing.T) {
528 testCases := []struct {
529 name string
530 password string
531 }{
532 {
533 name: "emptypassword",
534 password: "",
535 },
536 {
537 name: "realpassword",
538 password: "password",
539 },
540 }
541 for _, test := range testCases {
542 t.Run(test.name, func(t *testing.T) {
543 rtConfig := &RestTesterConfig{}
544 if test.password == "" {
545 rtConfig.DatabaseConfig = &DatabaseConfig{
546 DbConfig: DbConfig{
547 AllowEmptyPassword: base.Ptr(true),
548 },
549 }
550
551 }
552 rt := NewRestTester(t, rtConfig)
553 defer rt.Close()
554
555 const username = "user1"
556 originalPassword := test.password
557
558 // create session test users
559 response := rt.SendAdminRequest(http.MethodPost, "/{{.db}}/_user/", GetUserPayload(t, username, originalPassword, "", rt.GetSingleDataStore(), []string{"*"}, nil))
560 RequireStatus(t, response, http.StatusCreated)
561
562 originalPasswordHeaders := map[string]string{
563 "Authorization": "Basic " + base64.StdEncoding.EncodeToString([]byte(username+":"+originalPassword)),
564 }
565 response = rt.SendRequestWithHeaders(http.MethodPost, "/db/_session", "", originalPasswordHeaders)
566 RequireStatus(t, response, http.StatusOK)
567 cookie := response.Header().Get("Set-Cookie")
568 require.NotEqual(t, "", cookie)
569
570 // Create a doc as the first user, with session auth, channel-restricted to first user
571 cookieHeaders := map[string]string{
572 "Cookie": cookie,
573 }
574 response = rt.SendRequestWithHeaders(http.MethodPut, "/{{.keyspace}}/doc1", `{"hi": "there"}`, cookieHeaders)
575 RequireStatus(t, response, http.StatusCreated)
576 response = rt.SendRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/doc1", "", cookieHeaders)
577 RequireStatus(t, response, http.StatusOK)
578
579 response = rt.SendRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/doc1", "", originalPasswordHeaders)
580 RequireStatus(t, response, http.StatusOK)
581
582 altPassword := "someotherpassword"
583 // TODO CBG-3790: Add POST (upsert) support on User API, and specify only password here.
584 // This test was relying on a bug (CBG-3610) which allowed only the password to be specified without wiping channels.

Callers

nothing calls this directly

Calls 13

CloseMethod · 0.95
SendAdminRequestMethod · 0.95
GetSingleDataStoreMethod · 0.95
PtrFunction · 0.92
NewRestTesterFunction · 0.85
GetUserPayloadFunction · 0.85
RequireStatusFunction · 0.85
HeaderMethod · 0.80
RunMethod · 0.65
ContainsMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected