github.com/weaviate/weaviate@v1.24.6/usecases/auth/authorization/errors/errors_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 errors 13 14 import ( 15 "testing" 16 17 "github.com/stretchr/testify/assert" 18 "github.com/weaviate/weaviate/entities/models" 19 ) 20 21 func Test_ForbiddenError_NoGroups(t *testing.T) { 22 principal := &models.Principal{ 23 Username: "john", 24 } 25 26 err := NewForbidden(principal, "delete", "schema/things") 27 expectedErrMsg := "forbidden: user 'john' has insufficient permissions to delete schema/things" 28 assert.Equal(t, expectedErrMsg, err.Error()) 29 } 30 31 func Test_ForbiddenError_SingleGroup(t *testing.T) { 32 principal := &models.Principal{ 33 Username: "john", 34 Groups: []string{"worstusers"}, 35 } 36 37 err := NewForbidden(principal, "delete", "schema/things") 38 expectedErrMsg := "forbidden: user 'john' (of group 'worstusers') has insufficient permissions to delete schema/things" 39 assert.Equal(t, expectedErrMsg, err.Error()) 40 } 41 42 func Test_ForbiddenError_MultipleGroups(t *testing.T) { 43 principal := &models.Principal{ 44 Username: "john", 45 Groups: []string{"worstusers", "fraudsters", "evilpeople"}, 46 } 47 48 err := NewForbidden(principal, "delete", "schema/things") 49 expectedErrMsg := "forbidden: user 'john' (of groups 'worstusers', 'fraudsters', 'evilpeople') " + 50 "has insufficient permissions to delete schema/things" 51 assert.Equal(t, expectedErrMsg, err.Error()) 52 }