Exemple #1
0
func TestMuxNotFound(t *testing.T) {
	m := perm.NewMux()
	err := m.Allow(nil, "access something")
	if err != perm.HandlerNotFound {
		t.Errorf("Error is not of expected type. Expecting perm.HandlerNotFound by get %#v", err)
	}
}
Exemple #2
0
func TestGetMux(t *testing.T) {
	ep := testEndpoint()
	_, err := ep(perm.WithMux(nil, perm.NewMux()), nil)
	if err != nil {
		t.Errorf("test error: %#v", err.Error())
	}
}
Exemple #3
0
func TestMuxFoundMux(t *testing.T) {

	// child mux
	m1 := perm.NewMux()
	m1.HandleFunc("access something", func(ctx context.Context, perm string, info ...interface{}) error {
		return nil
	})

	// parent mux
	m2 := perm.NewMux()
	m2.Handle("access something", m1)

	// test parent mux
	if err := m2.Allow(nil, "access something"); err != nil {
		t.Errorf("Unexpected error. Failed to obtain handler for permission")
	}
}
Exemple #4
0
func TestMiddleware(t *testing.T) {
	ep := testEndpoint()
	var mw endpoint.Middleware = perm.UseMux(perm.NewMux())
	_, err := mw(ep)(nil, nil)
	if err != nil {
		t.Errorf("test error: %#v", err.Error())
	}
}
Exemple #5
0
func TestMuxFoundFunc(t *testing.T) {
	m := perm.NewMux()
	m.HandleFunc("access something", func(ctx context.Context, perm string, info ...interface{}) error {
		return nil
	})
	if err := m.Allow(nil, "access something"); err != nil {
		t.Errorf("Unexpected error. Failed to obtain handler for permission")
	}
}
Exemple #6
0
func TestDefaultMux(t *testing.T) {
	// test if default mux implements mux
	var m perm.Mux = perm.NewMux()
	_ = m
}