MCPcopy
hub / github.com/ory/keto / TestRewritesNamespaceConfig

Function TestRewritesNamespaceConfig

internal/driver/config/provider_test.go:193–274  ·  view source on GitHub ↗

Test that the namespaces can be configured through the Ory Permission Language.

(t *testing.T)

Source from the content-addressed store, hash-verified

191// Test that the namespaces can be configured through the Ory Permission
192// Language.
193func TestRewritesNamespaceConfig(t *testing.T) {
194 oplContent := `
195class User implements Namespace {
196 related: {
197 manager: User[]
198 }
199}
200
201class Group implements Namespace {
202 related: {
203 members: (User | Group)[]
204 }
205}`
206
207 oplConfigFile := createFile(t, oplContent)
208
209 srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
210 _, err := w.Write([]byte(oplContent))
211 if err != nil {
212 t.Fatal(err)
213 }
214 }))
215 t.Cleanup(func() { srv.Close() })
216
217 cases := []struct {
218 name string
219 location string
220 disallowPrivateIPRanges bool
221 expectErr bool
222 }{{
223 name: "local file",
224 location: "file://" + oplConfigFile,
225 }, {
226 name: "HTTP url forbidden",
227 location: srv.URL,
228 disallowPrivateIPRanges: true,
229 expectErr: true,
230 }, {
231 name: "HTTP url allowed",
232 location: srv.URL,
233 }}
234
235 for _, tc := range cases {
236 t.Run("case="+tc.name, func(t *testing.T) {
237 config := createFileF(t, `
238dsn: memory
239clients:
240 http:
241 disallow_private_ip_ranges: %v
242namespaces:
243 location: %s`, tc.disallowPrivateIPRanges, tc.location)
244
245 _, p := setup(t, config)
246 nm, err := p.NamespaceManager()
247 if tc.expectErr {
248 assert.Error(t, err)
249 return
250 }

Callers

nothing calls this directly

Calls 11

createFileFFunction · 0.85
setupFunction · 0.85
NewServerMethod · 0.80
StrictModeMethod · 0.80
createFileFunction · 0.70
CloseMethod · 0.65
NamespaceManagerMethod · 0.65
NamespacesMethod · 0.65
LenMethod · 0.65
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected