INNER CODE UNIT · Go

TestFilteredAdapter

apache/casbin-mongodb-adapter · adapter_test.go:360

func TestFilteredAdapter(t *testing.T) {
	// Now the DB has policy, so we can provide a normal use case.
	// Create an adapter and an enforcer.
	// NewEnforcer() will load the policy automatically.
	a, err := NewFilteredAdapter(getDbURL())
	if err != nil {
		panic(err)
	}

	e, err := casbin.NewEnforcer("examples/rbac_model.conf", a)
	if err != nil {
		panic(err)
	}

	// Load filtered policies from the database.
	e.AddPolicy("alice", "data1", "write")
	e.AddPolicy("bob", "data2", "write")
	// Reload the filtered policy from the storage.

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…