github.com/XiaoMi/Gaea@v1.2.5/parser/auth/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 auth
    15  
    16  import (
    17  	. "github.com/pingcap/check"
    18  
    19  	"github.com/XiaoMi/Gaea/util/testleak"
    20  )
    21  
    22  var _ = Suite(&testAuthSuite{})
    23  
    24  type testAuthSuite struct {
    25  }
    26  
    27  func (s *testAuthSuite) TestEncodePassword(c *C) {
    28  	defer testleak.AfterTest(c)()
    29  	pwd := "123"
    30  	c.Assert(EncodePassword(pwd), Equals, "*23AE809DDACAF96AF0FD78ED04B6A265E05AA257")
    31  }
    32  
    33  func (s *testAuthSuite) TestDecodePassword(c *C) {
    34  	defer testleak.AfterTest(c)()
    35  	x, err := DecodePassword(EncodePassword("123"))
    36  	c.Assert(err, IsNil)
    37  	c.Assert(x, DeepEquals, Sha1Hash(Sha1Hash([]byte("123"))))
    38  }
    39  
    40  func (s *testAuthSuite) TestCheckScramble(c *C) {
    41  	defer testleak.AfterTest(c)()
    42  	pwd := "abc"
    43  	salt := []byte{85, 92, 45, 22, 58, 79, 107, 6, 122, 125, 58, 80, 12, 90, 103, 32, 90, 10, 74, 82}
    44  	auth := []byte{24, 180, 183, 225, 166, 6, 81, 102, 70, 248, 199, 143, 91, 204, 169, 9, 161, 171, 203, 33}
    45  	encodepwd := EncodePassword(pwd)
    46  	hpwd, err := DecodePassword(encodepwd)
    47  	c.Assert(err, IsNil)
    48  
    49  	res := CheckScrambledPassword(salt, hpwd, auth)
    50  	c.Assert(res, IsTrue)
    51  }