Skip to content

Commit

Permalink
Merge branch 'master' into fix-dumpling-column-collation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehco1996 authored Dec 9, 2021
2 parents c11ff6a + 7aee819 commit 49c687d
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 3 deletions.
2 changes: 1 addition & 1 deletion br/pkg/task/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ func (cfg *Config) parseCipherInfo(flags *pflag.FlagSet) error {
}

if !checkCipherKeyMatch(&cfg.CipherInfo) {
return errors.Annotate(err, "Cipher type and key not match")
return errors.Annotate(berrors.ErrInvalidArgument, "crypter method and key length not match")
}

return nil
Expand Down
99 changes: 99 additions & 0 deletions br/pkg/task/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
package task

import (
"encoding/hex"
"fmt"

. "github.com/pingcap/check"
backuppb "github.com/pingcap/kvproto/pkg/brpb"
"github.com/pingcap/kvproto/pkg/encryptionpb"
"github.com/pingcap/tidb/config"
"github.com/spf13/pflag"
)
Expand Down Expand Up @@ -62,3 +65,99 @@ func (s *testCommonSuite) TestStripingPDURL(c *C) {
c.Assert(err, IsNil)
c.Assert(noChange, Equals, "127.0.0.1:2379")
}

func (s *testCommonSuite) TestCheckCipherKeyMatch(c *C) {
testCases := []struct {
CipherType encryptionpb.EncryptionMethod
CipherKey string
ok bool
}{
{
CipherType: encryptionpb.EncryptionMethod_PLAINTEXT,
ok: true,
},
{
CipherType: encryptionpb.EncryptionMethod_UNKNOWN,
ok: false,
},
{
CipherType: encryptionpb.EncryptionMethod_AES128_CTR,
CipherKey: "0123456789abcdef0123456789abcdef",
ok: true,
},
{
CipherType: encryptionpb.EncryptionMethod_AES128_CTR,
CipherKey: "0123456789abcdef0123456789abcd",
ok: false,
},
{
CipherType: encryptionpb.EncryptionMethod_AES192_CTR,
CipherKey: "0123456789abcdef0123456789abcdef0123456789abcdef",
ok: true,
},
{
CipherType: encryptionpb.EncryptionMethod_AES192_CTR,
CipherKey: "0123456789abcdef0123456789abcdef0123456789abcdefff",
ok: false,
},
{
CipherType: encryptionpb.EncryptionMethod_AES256_CTR,
CipherKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef",
ok: true,
},
{
CipherType: encryptionpb.EncryptionMethod_AES256_CTR,
CipherKey: "",
ok: false,
},
}

for _, t := range testCases {
cipherKey, err := hex.DecodeString(t.CipherKey)
c.Assert(err, IsNil)

r := checkCipherKeyMatch(&backuppb.CipherInfo{
CipherType: t.CipherType,
CipherKey: cipherKey,
})
c.Assert(r, Equals, t.ok)
}
}

func (s *testCommonSuite) TestCheckCipherKey(c *C) {
cases := []struct {
cipherKey string
keyFile string
ok bool
}{
{
cipherKey: "0123456789abcdef0123456789abcdef",
keyFile: "",
ok: true,
},
{
cipherKey: "0123456789abcdef0123456789abcdef",
keyFile: "/tmp/abc",
ok: false,
},
{
cipherKey: "",
keyFile: "/tmp/abc",
ok: true,
},
{
cipherKey: "",
keyFile: "",
ok: false,
},
}

for _, t := range cases {
err := checkCipherKey(t.cipherKey, t.keyFile)
if t.ok {
c.Assert(err, IsNil)
} else {
c.Assert(err, NotNil)
}
}
}
4 changes: 2 additions & 2 deletions expression/builtin_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ func (c *concatFunctionClass) getFunction(ctx sessionctx.Context, args []Express

if argType.Flen < 0 {
bf.tp.Flen = mysql.MaxBlobWidth
logutil.BgLogger().Warn("unexpected `Flen` value(-1) in CONCAT's args", zap.Int("arg's index", i))
logutil.BgLogger().Debug("unexpected `Flen` value(-1) in CONCAT's args", zap.Int("arg's index", i))
}
bf.tp.Flen += argType.Flen
}
Expand Down Expand Up @@ -365,7 +365,7 @@ func (c *concatWSFunctionClass) getFunction(ctx sessionctx.Context, args []Expre
if i != 0 {
if argType.Flen < 0 {
bf.tp.Flen = mysql.MaxBlobWidth
logutil.BgLogger().Warn("unexpected `Flen` value(-1) in CONCAT_WS's args", zap.Int("arg's index", i))
logutil.BgLogger().Debug("unexpected `Flen` value(-1) in CONCAT_WS's args", zap.Int("arg's index", i))
}
bf.tp.Flen += argType.Flen
}
Expand Down

0 comments on commit 49c687d

Please sign in to comment.