github.com/insionng/yougam@v0.0.0-20170714101924-2bc18d833463/libraries/pingcap/tidb/util/auth_test.go (about) 1 // Copyright 2015 PingCAP, Inc. 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 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package util 15 16 import ( 17 . "github.com/insionng/yougam/libraries/pingcap/check" 18 "github.com/insionng/yougam/libraries/pingcap/tidb/util/testleak" 19 ) 20 21 var _ = Suite(&testAuthSuite{}) 22 23 type testAuthSuite struct { 24 } 25 26 func (s *testAuthSuite) TestEncodePassword(c *C) { 27 defer testleak.AfterTest(c)() 28 pwd := "123" 29 c.Assert(EncodePassword(pwd), Equals, "40bd001563085fc35165329ea1ff5c5ecbdbbeef") 30 } 31 32 func (s *testAuthSuite) TestDecodePassword(c *C) { 33 defer testleak.AfterTest(c)() 34 x, err := DecodePassword(EncodePassword("123")) 35 c.Assert(err, IsNil) 36 c.Assert(x, DeepEquals, Sha1Hash([]byte("123"))) 37 } 38 39 func (s *testAuthSuite) TestCalcPassword(c *C) { 40 defer testleak.AfterTest(c)() 41 salt := []byte{116, 32, 122, 120, 2, 51, 33, 66, 47, 85, 34, 39, 84, 58, 108, 14, 62, 47, 120, 126} 42 pwd := Sha1Hash([]byte("123")) 43 checkAuth := []byte{126, 168, 249, 64, 180, 223, 60, 240, 69, 249, 184, 57, 21, 34, 214, 219, 8, 193, 208, 55} 44 c.Assert(CalcPassword(salt, pwd), DeepEquals, checkAuth) 45 }