vitess.io/vitess@v0.16.2/go/vt/vtgate/vschemaacl/vschemaacl_test.go (about) 1 /* 2 Copyright 2019 The Vitess Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vschemaacl 18 19 import ( 20 "testing" 21 22 querypb "vitess.io/vitess/go/vt/proto/query" 23 ) 24 25 func TestVschemaAcl(t *testing.T) { 26 redUser := querypb.VTGateCallerID{Username: "redUser"} 27 yellowUser := querypb.VTGateCallerID{Username: "yellowUser"} 28 29 // By default no users are allowed in 30 if Authorized(&redUser) { 31 t.Errorf("user should not be authorized") 32 } 33 if Authorized(&yellowUser) { 34 t.Errorf("user should not be authorized") 35 } 36 37 // Test wildcard 38 AuthorizedDDLUsers = "%" 39 Init() 40 41 if !Authorized(&redUser) { 42 t.Errorf("user should be authorized") 43 } 44 if !Authorized(&yellowUser) { 45 t.Errorf("user should be authorized") 46 } 47 48 // Test user list 49 AuthorizedDDLUsers = "oneUser, twoUser, redUser, blueUser" 50 Init() 51 52 if !Authorized(&redUser) { 53 t.Errorf("user should be authorized") 54 } 55 if Authorized(&yellowUser) { 56 t.Errorf("user should not be authorized") 57 } 58 59 // Revert to baseline state for other tests 60 AuthorizedDDLUsers = "" 61 Init() 62 63 // By default no users are allowed in 64 if Authorized(&redUser) { 65 t.Errorf("user should not be authorized") 66 } 67 if Authorized(&yellowUser) { 68 t.Errorf("user should not be authorized") 69 } 70 }