商城c端前端
This commit is contained in:
@@ -2,10 +2,8 @@ package accounts
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/aes"
|
||||
"crypto/cipher"
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.118im.com/im_team/im_workbench/internal/store"
|
||||
@@ -16,7 +14,7 @@ type fakeRepository struct{}
|
||||
func (fakeRepository) RegisterAccount(context.Context, store.AccountRegistration) (*store.Account, error) {
|
||||
return nil, errors.New("should not be called")
|
||||
}
|
||||
func (fakeRepository) AccountByMobileHash(context.Context, int64, string) (*store.Account, error) {
|
||||
func (fakeRepository) AccountByMobile(context.Context, int64, string) (*store.Account, error) {
|
||||
return nil, errors.New("should not be called")
|
||||
}
|
||||
func (fakeRepository) RecordLogin(context.Context, int64, int64) error {
|
||||
@@ -61,31 +59,11 @@ func TestRegisterValidation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestMobileEncryptionRoundTrip(t *testing.T) {
|
||||
key := make([]byte, 32)
|
||||
block, err := aes.NewCipher(key)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
aead, err := cipher.NewGCM(block)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := &Service{aead: aead, lookupKey: []byte("01234567890123456789012345678901")}
|
||||
encrypted, err := s.encrypt("+8613800138000")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
raw, err := base64.RawStdEncoding.DecodeString(encrypted)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
plain, err := aead.Open(nil, raw[:aead.NonceSize()], raw[aead.NonceSize():], nil)
|
||||
if err != nil || string(plain) != "+8613800138000" {
|
||||
t.Fatalf("decrypt = %q, err=%v", plain, err)
|
||||
}
|
||||
if len(s.lookupHash("+8613800138000")) != 64 {
|
||||
t.Fatal("mobile lookup hash must be hex sha256")
|
||||
func TestLoginRateKeyDoesNotExposePhone(t *testing.T) {
|
||||
s := &Service{}
|
||||
key := s.loginRateKey("13800138000")
|
||||
if strings.Contains(key, "13800138000") {
|
||||
t.Fatal("login rate key must not expose the phone number")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user