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

Function TestDisablePermissionCheck

rest/admin_api_auth_test.go:913–997  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

911}
912
913func TestDisablePermissionCheck(t *testing.T) {
914 if base.UnitTestUrlIsWalrus() {
915 t.Skip("This test only works against Couchbase Server")
916 }
917
918 clusterAdminPermission := Permission{"!admin", false}
919
920 // Some random role and perm
921 viewsAdminRole := RouteRole{RoleName: "views_admin", DatabaseScoped: true}
922 statsReadPermission := Permission{".stats!read", true}
923
924 serverIsCE := base.TestsUseServerCE()
925
926 rt := NewRestTester(t, nil)
927 SGWorBFArole := RouteRole{MobileSyncGatewayRole.RoleName, true}
928 if serverIsCE {
929 SGWorBFArole = RouteRole{BucketFullAccessRole.RoleName, true}
930 }
931 rt.Close()
932
933 testCases := []struct {
934 Name string
935 CreateUser string
936 CreateUserRole *RouteRole
937 RequirePerms []Permission
938 EEOnly bool
939 DoPermissionCheck bool
940 ExpectedStatusCode int
941 }{
942 {
943 Name: "AccessViaRole",
944 CreateUser: "SGWUser",
945 CreateUserRole: &SGWorBFArole,
946 RequirePerms: []Permission{clusterAdminPermission},
947 DoPermissionCheck: false,
948 ExpectedStatusCode: http.StatusOK,
949 },
950 {
951 Name: "AccessViaPermission",
952 CreateUser: "PermUser",
953 CreateUserRole: &viewsAdminRole,
954 RequirePerms: []Permission{statsReadPermission},
955 EEOnly: true, // Permissions only exist in EE Server
956 DoPermissionCheck: true,
957 ExpectedStatusCode: http.StatusOK,
958 },
959 {
960 Name: "AccessViaPermissionButDisabled",
961 CreateUser: "SGWUser",
962 CreateUserRole: &viewsAdminRole,
963 RequirePerms: []Permission{statsReadPermission},
964 EEOnly: true, // Permissions only exist in EE Server
965 DoPermissionCheck: false,
966 ExpectedStatusCode: http.StatusForbidden,
967 },
968 }
969
970 for _, testCase := range testCases {

Callers

nothing calls this directly

Calls 14

CloseMethod · 0.95
RunMethod · 0.95
ServerContextMethod · 0.95
BucketMethod · 0.95
ContextMethod · 0.95
UnitTestUrlIsWalrusFunction · 0.92
TestsUseServerCEFunction · 0.92
NewRestTesterFunction · 0.85
MakeUserFunction · 0.85
DeleteUserFunction · 0.85
checkAdminAuthFunction · 0.85
GetNameMethod · 0.65

Tested by

no test coverage detected