Don't check that userId is non-zero; it's already handled by ForeignKey constraints
This commit is contained in:
parent
a37b64faad
commit
8fce2cd868
3 changed files with 9 additions and 19 deletions
|
@ -79,7 +79,6 @@ func (s *Store) Migrate() error {
|
||||||
expiration DATETIME NOT NULL,
|
expiration DATETIME NOT NULL,
|
||||||
CHECK (
|
CHECK (
|
||||||
-- should eventually fail for foreign key constraint instead
|
-- should eventually fail for foreign key constraint instead
|
||||||
user_id <> 0 AND
|
|
||||||
device_id <> '' AND
|
device_id <> '' AND
|
||||||
|
|
||||||
token <> '' AND
|
token <> '' AND
|
||||||
|
@ -101,7 +100,6 @@ func (s *Store) Migrate() error {
|
||||||
PRIMARY KEY (user_id)
|
PRIMARY KEY (user_id)
|
||||||
FOREIGN KEY (user_id) REFERENCES accounts(user_id)
|
FOREIGN KEY (user_id) REFERENCES accounts(user_id)
|
||||||
CHECK (
|
CHECK (
|
||||||
user_id <> 0 AND
|
|
||||||
encrypted_wallet <> '' AND
|
encrypted_wallet <> '' AND
|
||||||
hmac <> '' AND
|
hmac <> '' AND
|
||||||
sequence <> 0
|
sequence <> 0
|
||||||
|
|
|
@ -361,23 +361,19 @@ func TestStoreTokenEmptyFields(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "missing token",
|
name: "missing token",
|
||||||
authToken: auth.AuthToken{Token: "", DeviceId: "dId", Scope: "*", UserId: 123},
|
authToken: auth.AuthToken{Token: "", DeviceId: "dId", Scope: "*"},
|
||||||
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
||||||
}, {
|
}, {
|
||||||
name: "missing device id",
|
name: "missing device id",
|
||||||
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "", Scope: "*", UserId: 123},
|
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "", Scope: "*"},
|
||||||
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
||||||
}, {
|
}, {
|
||||||
name: "missing scope",
|
name: "missing scope",
|
||||||
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "dId", Scope: "", UserId: 123},
|
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "dId", Scope: ""},
|
||||||
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
|
||||||
}, {
|
|
||||||
name: "missing user id",
|
|
||||||
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "dId", Scope: "*", UserId: 0},
|
|
||||||
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
expiration: time.Now().Add(time.Hour * 24 * 14).UTC(),
|
||||||
}, {
|
}, {
|
||||||
name: "missing expiration",
|
name: "missing expiration",
|
||||||
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "dId", Scope: "*", UserId: 123},
|
authToken: auth.AuthToken{Token: "seekrit-1", DeviceId: "dId", Scope: "*"},
|
||||||
expiration: time.Time{},
|
expiration: time.Time{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -387,6 +383,8 @@ func TestStoreTokenEmptyFields(t *testing.T) {
|
||||||
s, sqliteTmpFile := StoreTestInit(t)
|
s, sqliteTmpFile := StoreTestInit(t)
|
||||||
defer StoreTestCleanup(sqliteTmpFile)
|
defer StoreTestCleanup(sqliteTmpFile)
|
||||||
|
|
||||||
|
tc.authToken.UserId = makeTestUserId(t, &s)
|
||||||
|
|
||||||
var sqliteErr sqlite3.Error
|
var sqliteErr sqlite3.Error
|
||||||
|
|
||||||
err := s.insertToken(&tc.authToken, tc.expiration)
|
err := s.insertToken(&tc.authToken, tc.expiration)
|
||||||
|
|
|
@ -244,23 +244,15 @@ func TestStoreWalletEmptyFields(t *testing.T) {
|
||||||
// Make sure expiration doesn't get set if sanitization fails
|
// Make sure expiration doesn't get set if sanitization fails
|
||||||
tt := []struct {
|
tt := []struct {
|
||||||
name string
|
name string
|
||||||
userId auth.UserId
|
|
||||||
encryptedWallet wallet.EncryptedWallet
|
encryptedWallet wallet.EncryptedWallet
|
||||||
hmac wallet.WalletHmac
|
hmac wallet.WalletHmac
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "missing user id",
|
|
||||||
userId: auth.UserId(0),
|
|
||||||
encryptedWallet: wallet.EncryptedWallet("my-enc-wallet"),
|
|
||||||
hmac: wallet.WalletHmac("my-hmac"),
|
|
||||||
}, {
|
|
||||||
name: "missing encrypted wallet",
|
name: "missing encrypted wallet",
|
||||||
userId: auth.UserId(1),
|
|
||||||
encryptedWallet: wallet.EncryptedWallet(""),
|
encryptedWallet: wallet.EncryptedWallet(""),
|
||||||
hmac: wallet.WalletHmac("my-hmac"),
|
hmac: wallet.WalletHmac("my-hmac"),
|
||||||
}, {
|
}, {
|
||||||
name: "missing hmac",
|
name: "missing hmac",
|
||||||
userId: auth.UserId(1),
|
|
||||||
encryptedWallet: wallet.EncryptedWallet("my-enc-wallet"),
|
encryptedWallet: wallet.EncryptedWallet("my-enc-wallet"),
|
||||||
hmac: wallet.WalletHmac(""),
|
hmac: wallet.WalletHmac(""),
|
||||||
},
|
},
|
||||||
|
@ -272,9 +264,11 @@ func TestStoreWalletEmptyFields(t *testing.T) {
|
||||||
s, sqliteTmpFile := StoreTestInit(t)
|
s, sqliteTmpFile := StoreTestInit(t)
|
||||||
defer StoreTestCleanup(sqliteTmpFile)
|
defer StoreTestCleanup(sqliteTmpFile)
|
||||||
|
|
||||||
|
userId := makeTestUserId(t, &s)
|
||||||
|
|
||||||
var sqliteErr sqlite3.Error
|
var sqliteErr sqlite3.Error
|
||||||
|
|
||||||
err := s.insertFirstWallet(tc.userId, tc.encryptedWallet, tc.hmac)
|
err := s.insertFirstWallet(userId, tc.encryptedWallet, tc.hmac)
|
||||||
if errors.As(err, &sqliteErr) {
|
if errors.As(err, &sqliteErr) {
|
||||||
if errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintCheck) {
|
if errors.Is(sqliteErr.ExtendedCode, sqlite3.ErrConstraintCheck) {
|
||||||
return // We got the error we expected
|
return // We got the error we expected
|
||||||
|
|
Loading…
Add table
Reference in a new issue