github.com/greenpau/go-authcrunch@v1.1.4/pkg/util/validate/additional_scopes_test.go (about) 1 // Copyright 2022 Paul Greenberg greenpau@outlook.com 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package validate 16 17 import ( 18 "github.com/greenpau/go-authcrunch/internal/tests" 19 "github.com/greenpau/go-authcrunch/pkg/errors" 20 "testing" 21 ) 22 23 func TestAdditionalScopes(t *testing.T) { 24 var testcases = []struct { 25 name string 26 additionalScopes string 27 shouldErr bool 28 err error 29 }{ 30 { 31 name: "doesn't return an error if the provided additional_scopes are in a valid format", 32 additionalScopes: "email profile orders", 33 shouldErr: false, 34 err: nil, 35 }, 36 { 37 name: "doesn't return an error if the provided additional_scopes is only one", 38 additionalScopes: "email", 39 shouldErr: false, 40 err: nil, 41 }, 42 { 43 name: "returns an error if the provided additional_scopes have invalid characters #1", 44 additionalScopes: "<e_mail>", 45 shouldErr: true, 46 err: errors.ErrInvalidAdditionalScopes, 47 }, 48 { 49 name: "returns an error if the provided additional_scopes have invalid characters #2", 50 additionalScopes: "&e_mail?", 51 shouldErr: true, 52 err: errors.ErrInvalidAdditionalScopes, 53 }, 54 } 55 for _, tc := range testcases { 56 t.Run(tc.name, func(t *testing.T) { 57 err := AdditionalScopes(tc.additionalScopes) 58 59 if tests.EvalErrWithLog(t, err, nil, tc.shouldErr, tc.err, []string{}) { 60 return 61 } 62 }) 63 } 64 }