// Copyright 2019 Yunion // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package cas import ( "reflect" "testing" ) func TestFetchAttributes(t *testing.T) { cases := []struct { Xml string Want map[string][]string }{ { Xml: ` casuser casproj `, Want: map[string][]string{ "cas:user": {"casuser"}, "cas:proj": {"casproj"}, }, }, { Xml: ` lcftest0416周凌测试无线公司1112342`, Want: map[string][]string{ "cas:user": {"lcftest0416"}, "cas:proj": {"周凌测试无线公司1112342"}, }, }, { Xml: ` casuser UsernamePasswordCredential false 2019-09-05T12:40:08.014Z[UTC] AcceptUsersAuthenticationHandler AcceptUsersAuthenticationHandler false `, Want: map[string][]string{ "cas:user": {"casuser"}, "cas:credentialType": {"UsernamePasswordCredential"}, "cas:isFromNewLogin": {"false"}, "cas:authenticationDate": {"2019-09-05T12:40:08.014Z[UTC]"}, "cas:authenticationMethod": {"AcceptUsersAuthenticationHandler"}, "cas:successfulAuthenticationHandlers": {"AcceptUsersAuthenticationHandler"}, "cas:longTermAuthenticationRequestTokenUsed": {"false"}, }, }, { Xml: ` casuser `, Want: map[string][]string{ "cas:user": {"casuser"}, }, }, } for _, c := range cases { got := fetchAttributes([]byte(c.Xml)) if !reflect.DeepEqual(got, c.Want) { t.Errorf("want %s got %s", c.Want, got) } } }