github.com/weaviate/weaviate@v1.24.6/usecases/auth/authorization/authorizer_test.go (about) 1 // _ _ 2 // __ _____ __ ___ ___ __ _| |_ ___ 3 // \ \ /\ / / _ \/ _` \ \ / / |/ _` | __/ _ \ 4 // \ V V / __/ (_| |\ V /| | (_| | || __/ 5 // \_/\_/ \___|\__,_| \_/ |_|\__,_|\__\___| 6 // 7 // Copyright © 2016 - 2024 Weaviate B.V. All rights reserved. 8 // 9 // CONTACT: hello@weaviate.io 10 // 11 12 package authorization 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/weaviate/weaviate/usecases/auth/authorization/adminlist" 19 "github.com/weaviate/weaviate/usecases/config" 20 ) 21 22 func Test_Authorizer(t *testing.T) { 23 t.Run("when no authz is configured", func(t *testing.T) { 24 cfg := config.Config{} 25 26 authorizer := New(cfg) 27 28 t.Run("it uses the dummy authorizer", func(t *testing.T) { 29 _, ok := authorizer.(*DummyAuthorizer) 30 assert.Equal(t, true, ok) 31 }) 32 33 t.Run("any request is allowed", func(t *testing.T) { 34 err := authorizer.Authorize(nil, "delete", "the/world") 35 assert.Nil(t, err) 36 }) 37 }) 38 39 t.Run("when adminlist is configured", func(t *testing.T) { 40 cfg := config.Config{ 41 Authorization: config.Authorization{ 42 AdminList: adminlist.Config{ 43 Enabled: true, 44 }, 45 }, 46 } 47 48 authorizer := New(cfg) 49 50 _, ok := authorizer.(*adminlist.Authorizer) 51 assert.Equal(t, true, ok) 52 }) 53 }