github.com/cs3org/reva/v2@v2.27.7/pkg/user/manager/ldap/ldap_test.go (about) 1 // Copyright 2018-2021 CERN 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 // In applying this license, CERN does not waive the privileges and immunities 16 // granted to it by virtue of its status as an Intergovernmental Organization 17 // or submit itself to any jurisdiction. 18 19 package ldap 20 21 import ( 22 "testing" 23 24 ldapIdentity "github.com/cs3org/reva/v2/pkg/utils/ldap" 25 ) 26 27 func TestUserManager(t *testing.T) { 28 // negative test for parseConfig 29 _, err := New(map[string]interface{}{"uri": 42}) 30 if err == nil { 31 t.Fatal("expected error but got none") 32 } 33 defaults := ldapIdentity.New() 34 internal := map[string]interface{}{ 35 "mail": "email", 36 "dn": "dn", 37 } 38 39 con := map[string]interface{}{ 40 "user_schema": internal, 41 } 42 43 c, err := parseConfig(con) 44 if err != nil { 45 t.Fatalf("config is invalid") 46 } 47 48 // ID not provided in config file. should not modify defaults 49 if c.LDAPIdentity.User.Schema.ID != defaults.User.Schema.ID { 50 t.Fatalf("expected default ID to be: %v, got %v", defaults.User.Schema.ID, c.LDAPIdentity.User.Schema.ID) 51 } 52 53 // DisplayName not provided in config file. should not modify defaults 54 if c.LDAPIdentity.User.Schema.DisplayName != defaults.User.Schema.DisplayName { 55 t.Fatalf("expected DisplayName to be: %v, got %v", defaults.User.Schema.DisplayName, c.LDAPIdentity.User.Schema.DisplayName) 56 } 57 58 // Mail provided in config file 59 if c.LDAPIdentity.User.Schema.Mail != "email" { 60 t.Fatalf("expected default UID to be: %v, got %v", "email", c.LDAPIdentity.User.Schema.Mail) 61 } 62 63 // positive tests for New 64 _, err = New(map[string]interface{}{}) 65 if err != nil { 66 t.Fatal(err.Error()) 67 } 68 }