TestCollectionsSGIndexQuery is more of an end-to-end test to ensure SG indexes are built correctly, and the channel access query is able to run when pulling a document as a user, and backfill the channel cache.
(t *testing.T)
| 486 | // TestCollectionsSGIndexQuery is more of an end-to-end test to ensure SG indexes are built correctly, |
| 487 | // and the channel access query is able to run when pulling a document as a user, and backfill the channel cache. |
| 488 | func TestCollectionsSGIndexQuery(t *testing.T) { |
| 489 | t.Skip("Requires config-based collection channel assignment (pending CBG-2551)") |
| 490 | base.TestRequiresCollections(t) |
| 491 | |
| 492 | // force GSI for this one test |
| 493 | useViews := base.Ptr(false) |
| 494 | |
| 495 | const ( |
| 496 | username = "alice" |
| 497 | password = "letmein" |
| 498 | validChannel = "valid" |
| 499 | invalidChannel = "invalid" |
| 500 | |
| 501 | validDocID = "doc1" |
| 502 | invalidDocID = "doc2" |
| 503 | ) |
| 504 | |
| 505 | rt := NewRestTester(t, &RestTesterConfig{ |
| 506 | DatabaseConfig: &DatabaseConfig{ |
| 507 | DbConfig: DbConfig{ |
| 508 | UseViews: useViews, |
| 509 | Users: map[string]*auth.PrincipalConfig{ |
| 510 | username: { |
| 511 | ExplicitChannels: base.SetOf(validChannel), |
| 512 | Password: base.Ptr(password), |
| 513 | }, |
| 514 | }, |
| 515 | }, |
| 516 | }, |
| 517 | }) |
| 518 | defer rt.Close() |
| 519 | |
| 520 | resp := rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+validDocID, `{"test": true, "channels": ["`+validChannel+`"]}`) |
| 521 | RequireStatus(t, resp, http.StatusCreated) |
| 522 | resp = rt.SendAdminRequest(http.MethodPut, "/{{.keyspace}}/"+invalidDocID, `{"test": true, "channels": ["`+invalidChannel+`"]}`) |
| 523 | RequireStatus(t, resp, http.StatusCreated) |
| 524 | |
| 525 | resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/db/_all_docs", ``, nil, username, password) |
| 526 | RequireStatus(t, resp, http.StatusOK) |
| 527 | var allDocsResponse struct { |
| 528 | TotalRows int `json:"total_rows"` |
| 529 | Rows []struct { |
| 530 | ID string `json:"id"` |
| 531 | } `json:"rows"` |
| 532 | } |
| 533 | require.NoError(t, base.JSONDecoder(resp.Body).Decode(&allDocsResponse)) |
| 534 | assert.Equal(t, 1, allDocsResponse.TotalRows) |
| 535 | require.Len(t, allDocsResponse.Rows, 1) |
| 536 | assert.Equal(t, validDocID, allDocsResponse.Rows[0].ID) |
| 537 | |
| 538 | resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/"+validDocID, ``, nil, username, password) |
| 539 | RequireStatus(t, resp, http.StatusOK) |
| 540 | resp = rt.SendUserRequestWithHeaders(http.MethodGet, "/{{.keyspace}}/"+invalidDocID, ``, nil, username, password) |
| 541 | RequireStatus(t, resp, http.StatusForbidden) |
| 542 | |
| 543 | rt.WaitForChanges(1, "/{{.keyspace}}/_changes", username, false) |
| 544 | } |
| 545 |
nothing calls this directly
no test coverage detected