(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestFunkyRoleNames(t *testing.T) { |
| 117 | cases := []struct { |
| 118 | Name string |
| 119 | RoleName string |
| 120 | }{ |
| 121 | { |
| 122 | Name: "hashes", |
| 123 | RoleName: "foo#bar", |
| 124 | }, |
| 125 | { |
| 126 | Name: "question mark", |
| 127 | RoleName: "foo?bar", |
| 128 | }, |
| 129 | { |
| 130 | Name: "dollars", |
| 131 | RoleName: "$foo$bar", |
| 132 | }, |
| 133 | { |
| 134 | Name: "underscore prefix", |
| 135 | RoleName: "_sync-foobar", |
| 136 | }, |
| 137 | } |
| 138 | for _, tc := range cases { |
| 139 | t.Run(tc.Name, func(t *testing.T) { |
| 140 | require.Truef(t, auth.IsValidPrincipalName(tc.RoleName), "expected '%s' to be accepted", tc.RoleName) |
| 141 | roleNameJSON, err := json.Marshal("role:" + tc.RoleName) |
| 142 | require.NoError(t, err) |
| 143 | const username = "user1" |
| 144 | syncFn := fmt.Sprintf(`function(doc) {channel(doc.channels); role("%s", %s);}`, username, string(roleNameJSON)) |
| 145 | rt := NewRestTester(t, |
| 146 | &RestTesterConfig{ |
| 147 | SyncFn: syncFn, |
| 148 | }) |
| 149 | defer rt.Close() |
| 150 | ds := rt.GetSingleDataStore() |
| 151 | |
| 152 | ctx := rt.Context() |
| 153 | a := rt.ServerContext().Database(ctx, "db").Authenticator(ctx) |
| 154 | |
| 155 | // Create a test user |
| 156 | user, err := a.NewUser(username, "letmein", channels.BaseSetOf(t)) |
| 157 | require.NoError(t, err) |
| 158 | require.NoError(t, a.Save(user)) |
| 159 | |
| 160 | // Create role |
| 161 | response := rt.SendAdminRequest("PUT", fmt.Sprintf("/db/_role/%s", url.PathEscape(tc.RoleName)), GetRolePayload(t, "", ds, []string{"testchannel"})) |
| 162 | RequireStatus(t, response, 201) |
| 163 | |
| 164 | // Create test document |
| 165 | response = rt.SendAdminRequest("PUT", "/{{.keyspace}}/testdoc", `{"channels":["testchannel"]}`) |
| 166 | RequireStatus(t, response, 201) |
| 167 | |
| 168 | // Assert user can access it |
| 169 | response = rt.SendUserRequest("GET", "/{{.keyspace}}/testdoc", "", username) |
| 170 | RequireStatus(t, response, 200) |
| 171 | }) |
| 172 | } |
| 173 | } |
nothing calls this directly
no test coverage detected