Makes sure admin API calls do not unsuspend DB if they fail authentication
(t *testing.T)
| 639 | |
| 640 | // Makes sure admin API calls do not unsuspend DB if they fail authentication |
| 641 | func TestServerlessUnsuspendAdminAuth(t *testing.T) { |
| 642 | RequireBucketSpecificCredentials(t) |
| 643 | ctx := base.TestCtx(t) |
| 644 | // Get test bucket |
| 645 | tb := base.GetTestBucket(t) |
| 646 | defer tb.Close(ctx) |
| 647 | |
| 648 | rt := NewRestTester(t, &RestTesterConfig{CustomTestBucket: tb.NoCloseClone(), PersistentConfig: true, serverless: true, AdminInterfaceAuthentication: true}) |
| 649 | defer rt.Close() |
| 650 | |
| 651 | sc := rt.ServerContext() |
| 652 | |
| 653 | resp := rt.SendAdminRequestWithAuth(http.MethodPut, "/db/", fmt.Sprintf(`{ |
| 654 | "bucket": "%s", |
| 655 | "use_views": %t, |
| 656 | "num_index_replicas": 0 |
| 657 | }`, tb.GetName(), base.TestsDisableGSI()), base.TestClusterUsername(), base.TestClusterPassword()) |
| 658 | RequireStatus(t, resp, http.StatusCreated) |
| 659 | |
| 660 | err := sc.suspendDatabase(t, rt.Context(), "db") |
| 661 | assert.NoError(t, err) |
| 662 | |
| 663 | // Confirm db is suspended |
| 664 | require.True(t, sc.isDatabaseSuspended(t, "db")) |
| 665 | require.Nil(t, sc._databases["db"]) |
| 666 | |
| 667 | // Confirm unauthenticated admin request does not trigger unsuspend |
| 668 | resp = rt.SendAdminRequest(http.MethodGet, "/db/doc", "") |
| 669 | AssertStatus(t, resp, http.StatusUnauthorized) |
| 670 | require.Nil(t, sc._databases["db"]) // Confirm suspended |
| 671 | require.True(t, sc.isDatabaseSuspended(t, "db")) |
| 672 | |
| 673 | // Confirm authenticated admin request triggers unsuspend |
| 674 | resp = rt.SendAdminRequestWithAuth(http.MethodGet, "/db/doc", "", base.TestClusterUsername(), base.TestClusterPassword()) |
| 675 | AssertStatus(t, resp, http.StatusNotFound) |
| 676 | require.NotNil(t, sc._databases["db"]) // Confirm unsuspended |
| 677 | require.False(t, sc.isDatabaseSuspended(t, "db")) |
| 678 | |
| 679 | // Attempt to get DB that does not exist |
| 680 | resp = rt.SendAdminRequestWithAuth(http.MethodGet, "/invaliddb/doc", "", base.TestClusterUsername(), base.TestClusterPassword()) |
| 681 | AssertHTTPErrorReason(t, resp, http.StatusForbidden, "") |
| 682 | } |
| 683 | |
| 684 | func TestImportPartitionsServerless(t *testing.T) { |
| 685 | RequireBucketSpecificCredentials(t) |
nothing calls this directly
no test coverage detected