2021-12-25 02:16:58 +01:00
|
|
|
package store
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
"time"
|
2022-06-24 00:11:21 +02:00
|
|
|
|
|
|
|
"orblivion/lbry-id/auth"
|
|
|
|
"orblivion/lbry-id/wallet"
|
2021-12-19 23:24:43 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// Test insertToken, using GetToken as a helper
|
2022-06-24 01:57:55 +02:00
|
|
|
// Try insertToken twice with the same user and device, error the second time
|
2021-12-19 23:24:43 +01:00
|
|
|
func TestStoreInsertToken(t *testing.T) {
|
|
|
|
|
2022-06-02 19:49:49 +02:00
|
|
|
s, sqliteTmpFile := StoreTestInit(t)
|
|
|
|
defer StoreTestCleanup(sqliteTmpFile)
|
2021-12-19 23:24:43 +01:00
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// created for addition to the DB (no expiration attached)
|
2021-12-25 02:16:58 +01:00
|
|
|
authToken1 := auth.AuthToken{
|
2021-12-19 23:24:43 +01:00
|
|
|
Token: "seekrit-1",
|
2022-06-07 19:25:14 +02:00
|
|
|
DeviceId: "dId",
|
2021-12-24 04:29:02 +01:00
|
|
|
Scope: "*",
|
2022-06-07 19:25:14 +02:00
|
|
|
UserId: 123,
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
expiration := time.Now().Add(time.Hour * 24 * 14).UTC()
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
// Get a token, come back empty
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err := s.GetToken(authToken1.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put in a token
|
2022-06-07 19:25:14 +02:00
|
|
|
if err := s.insertToken(&authToken1, expiration); err != nil {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf("Unexpected error in insertToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// The value expected when we pull it from the database.
|
|
|
|
authToken1Expected := authToken1
|
2022-06-08 00:26:47 +02:00
|
|
|
authToken1Expected.Expiration = &expiration
|
2022-06-07 19:25:14 +02:00
|
|
|
|
2021-12-19 23:24:43 +01:00
|
|
|
// Get and confirm the token we just put in
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken1.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken1Expected) {
|
|
|
|
t.Fatalf("token: \n expected %+v\n got: %+v", authToken1Expected, *gotToken)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// Try to put a different token, fail because we already have one
|
|
|
|
authToken2 := authToken1
|
|
|
|
authToken2.Token = "seekrit-2"
|
|
|
|
|
|
|
|
if err := s.insertToken(&authToken2, expiration); err != ErrDuplicateToken {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf(`insertToken err: wanted "%+v", got "%+v"`, ErrDuplicateToken, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the same *first* token we successfully put in
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken1.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken1Expected) {
|
|
|
|
t.Fatalf("token: expected %+v, got: %+v", authToken1Expected, gotToken)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test updateToken, using GetToken and insertToken as helpers
|
|
|
|
// Try updateToken with no existing token, err for lack of anything to update
|
|
|
|
// Try updateToken with a preexisting token, succeed
|
|
|
|
// Try updateToken again with a new token, succeed
|
|
|
|
func TestStoreUpdateToken(t *testing.T) {
|
2022-06-02 19:49:49 +02:00
|
|
|
s, sqliteTmpFile := StoreTestInit(t)
|
|
|
|
defer StoreTestCleanup(sqliteTmpFile)
|
2021-12-19 23:24:43 +01:00
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// created for addition to the DB (no expiration attached)
|
|
|
|
authTokenUpdate := auth.AuthToken{
|
|
|
|
Token: "seekrit-update",
|
|
|
|
DeviceId: "dId",
|
2021-12-24 04:29:02 +01:00
|
|
|
Scope: "*",
|
2022-06-07 19:25:14 +02:00
|
|
|
UserId: 123,
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
expiration := time.Now().Add(time.Hour * 24 * 14).UTC()
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
// Try to get a token, come back empty because we're just starting out
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err := s.GetToken(authTokenUpdate.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Try to update the token - fail because we don't have an entry there in the first place
|
2022-06-07 19:25:14 +02:00
|
|
|
if err := s.updateToken(&authTokenUpdate, expiration); err != ErrNoToken {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf(`updateToken err: wanted "%+v", got "%+v"`, ErrNoToken, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to get a token, come back empty because the update attempt failed to do anything
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authTokenUpdate.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// Put in a different token, just so we have something to test that
|
|
|
|
// updateToken overwrites it
|
|
|
|
authTokenInsert := authTokenUpdate
|
|
|
|
authTokenInsert.Token = "seekrit-insert"
|
|
|
|
|
|
|
|
if err := s.insertToken(&authTokenInsert, expiration); err != nil {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf("Unexpected error in insertToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now successfully update token
|
2022-06-07 19:25:14 +02:00
|
|
|
if err := s.updateToken(&authTokenUpdate, expiration); err != nil {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf("Unexpected error in updateToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// The value expected when we pull it from the database.
|
|
|
|
authTokenUpdateExpected := authTokenUpdate
|
2022-06-08 00:26:47 +02:00
|
|
|
authTokenUpdateExpected.Expiration = &expiration
|
2022-06-07 19:25:14 +02:00
|
|
|
|
2021-12-19 23:24:43 +01:00
|
|
|
// Get and confirm the token we just put in
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authTokenUpdate.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authTokenUpdateExpected) {
|
|
|
|
t.Fatalf("token: \n expected %+v\n got: %+v", authTokenUpdateExpected, *gotToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail to get the token we previously inserted, because it's now been overwritten
|
|
|
|
gotToken, err = s.GetToken(authTokenInsert.Token)
|
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// Test that a user can have two different devices.
|
2021-12-19 23:24:43 +01:00
|
|
|
// Test first and second Save (one for insert, one for update)
|
|
|
|
// Get fails initially
|
|
|
|
// Put token1-d1 token1-d2
|
|
|
|
// Get token1-d1 token1-d2
|
|
|
|
// Put token2-d1 token2-d2
|
|
|
|
// Get token2-d1 token2-d2
|
|
|
|
func TestStoreSaveToken(t *testing.T) {
|
2022-06-02 19:49:49 +02:00
|
|
|
s, sqliteTmpFile := StoreTestInit(t)
|
|
|
|
defer StoreTestCleanup(sqliteTmpFile)
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
// Version 1 of the token for both devices
|
2022-06-07 19:25:14 +02:00
|
|
|
// created for addition to the DB (no expiration attached)
|
2021-12-25 02:16:58 +01:00
|
|
|
authToken_d1_1 := auth.AuthToken{
|
2021-12-19 23:24:43 +01:00
|
|
|
Token: "seekrit-d1-1",
|
2022-06-07 19:25:14 +02:00
|
|
|
DeviceId: "dId-1",
|
2021-12-24 04:29:02 +01:00
|
|
|
Scope: "*",
|
2022-06-07 19:25:14 +02:00
|
|
|
UserId: 123,
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
authToken_d2_1 := authToken_d1_1
|
2022-06-07 19:25:14 +02:00
|
|
|
authToken_d2_1.DeviceId = "dId-2"
|
2021-12-19 23:24:43 +01:00
|
|
|
authToken_d2_1.Token = "seekrit-d2-1"
|
|
|
|
|
|
|
|
// Try to get the tokens, come back empty because we're just starting out
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err := s.GetToken(authToken_d1_1.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken_d2_1.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Save Version 1 tokens for both devices
|
|
|
|
if err = s.SaveToken(&authToken_d1_1); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in SaveToken: %+v", err)
|
|
|
|
}
|
|
|
|
if err = s.SaveToken(&authToken_d2_1); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in SaveToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check one of the authTokens to make sure expiration was set
|
|
|
|
if authToken_d1_1.Expiration == nil {
|
|
|
|
t.Fatalf("Expected SaveToken to set an Expiration")
|
|
|
|
}
|
|
|
|
nowDiff := authToken_d1_1.Expiration.Sub(time.Now())
|
|
|
|
if time.Hour*24*14+time.Minute < nowDiff || nowDiff < time.Hour*24*14-time.Minute {
|
|
|
|
t.Fatalf("Expected SaveToken to set a token Expiration 2 weeks in the future.")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get and confirm the tokens we just put in
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken_d1_1.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken_d1_1) {
|
|
|
|
t.Fatalf("token: \n expected %+v\n got: %+v", authToken_d1_1, gotToken)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken_d2_1.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken_d2_1) {
|
|
|
|
t.Fatalf("token: expected %+v, got: %+v", authToken_d2_1, gotToken)
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// Version 2 of the token for both devices
|
|
|
|
authToken_d1_2 := authToken_d1_1
|
|
|
|
authToken_d1_2.Token = "seekrit-d1-2"
|
|
|
|
|
|
|
|
authToken_d2_2 := authToken_d2_1
|
|
|
|
authToken_d2_2.Token = "seekrit-d2-2"
|
|
|
|
|
2021-12-19 23:24:43 +01:00
|
|
|
// Save Version 2 tokens for both devices
|
|
|
|
if err = s.SaveToken(&authToken_d1_2); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in SaveToken: %+v", err)
|
|
|
|
}
|
|
|
|
if err = s.SaveToken(&authToken_d2_2); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in SaveToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the expiration of this new token is marginally later
|
|
|
|
if authToken_d1_2.Expiration == nil {
|
|
|
|
t.Fatalf("Expected SaveToken to set an Expiration")
|
|
|
|
}
|
|
|
|
expDiff := authToken_d1_2.Expiration.Sub(*authToken_d1_1.Expiration)
|
|
|
|
if time.Second < expDiff || expDiff < 0 {
|
|
|
|
t.Fatalf("Expected new expiration to be slightly later than previous expiration. diff: %+v", expDiff)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get and confirm the tokens we just put in
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken_d1_2.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken_d1_2) {
|
|
|
|
t.Fatalf("token: \n expected %+v\n got: %+v", authToken_d1_2, gotToken)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken_d2_2.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authToken_d2_2) {
|
|
|
|
t.Fatalf("token: expected %+v, got: %+v", authToken_d2_2, gotToken)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// test GetToken using insertToken and updateToken as helpers (so we can set expiration timestamps)
|
|
|
|
// normal
|
2022-06-07 19:25:14 +02:00
|
|
|
// token not found
|
|
|
|
// expired not returned
|
2021-12-19 23:24:43 +01:00
|
|
|
func TestStoreGetToken(t *testing.T) {
|
2022-06-02 19:49:49 +02:00
|
|
|
s, sqliteTmpFile := StoreTestInit(t)
|
|
|
|
defer StoreTestCleanup(sqliteTmpFile)
|
2021-12-19 23:24:43 +01:00
|
|
|
|
|
|
|
// created for addition to the DB (no expiration attached)
|
2021-12-25 02:16:58 +01:00
|
|
|
authToken := auth.AuthToken{
|
2021-12-19 23:24:43 +01:00
|
|
|
Token: "seekrit-d1",
|
2022-06-07 19:25:14 +02:00
|
|
|
DeviceId: "dId",
|
2021-12-24 04:29:02 +01:00
|
|
|
Scope: "*",
|
2022-06-07 19:25:14 +02:00
|
|
|
UserId: 123,
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
expiration := time.Time(time.Now().UTC().Add(time.Hour * 24 * 14))
|
2021-12-19 23:24:43 +01:00
|
|
|
|
2022-06-23 23:29:16 +02:00
|
|
|
// Not found (nothing saved for this token string)
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err := s.GetToken(authToken.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put in a token
|
2022-06-07 19:25:14 +02:00
|
|
|
if err := s.insertToken(&authToken, expiration); err != nil {
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf("Unexpected error in insertToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
2022-06-07 19:25:14 +02:00
|
|
|
// The value expected when we pull it from the database.
|
|
|
|
authTokenExpected := authToken
|
2022-06-08 00:26:47 +02:00
|
|
|
authTokenExpected.Expiration = &expiration
|
2022-06-07 19:25:14 +02:00
|
|
|
|
2021-12-19 23:24:43 +01:00
|
|
|
// Confirm it saved
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken.Token)
|
2021-12-19 23:24:43 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Unexpected error in GetToken: %+v", err)
|
|
|
|
}
|
2022-06-07 19:25:14 +02:00
|
|
|
if gotToken == nil || !reflect.DeepEqual(*gotToken, authTokenExpected) {
|
|
|
|
t.Fatalf("token: \n expected %+v\n got: %+v", authTokenExpected, gotToken)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the token to be expired
|
|
|
|
expirationOld := time.Now().Add(time.Second * (-1))
|
|
|
|
if err := s.updateToken(&authToken, expirationOld); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in updateToken: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fail to get the expired token
|
2022-06-07 19:25:14 +02:00
|
|
|
gotToken, err = s.GetToken(authToken.Token)
|
2021-12-25 02:16:58 +01:00
|
|
|
if gotToken != nil || err != ErrNoToken {
|
|
|
|
t.Fatalf("Expected ErrNoToken, for expired token. token: %+v err: %+v", gotToken, err)
|
2021-12-19 23:24:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStoreSanitizeEmptyFields(t *testing.T) {
|
|
|
|
// Make sure expiration doesn't get set if sanitization fails
|
|
|
|
t.Fatalf("Test me")
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestStoreTimeZones(t *testing.T) {
|
2021-12-25 02:16:58 +01:00
|
|
|
// Make sure the tz situation is as we prefer in the DB unless we just do UTC.
|
2021-12-19 23:24:43 +01:00
|
|
|
t.Fatalf("Test me")
|
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreSetWalletSuccess(t *testing.T) {
|
2021-12-25 02:16:58 +01:00
|
|
|
/*
|
|
|
|
Sequence 1 - works via insert
|
|
|
|
Sequence 2 - works via update
|
|
|
|
Sequence 3 - works via update
|
|
|
|
*/
|
2022-06-09 23:04:49 +02:00
|
|
|
t.Fatalf("Test me: Wallet Set successes")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreSetWalletFail(t *testing.T) {
|
2021-12-25 02:16:58 +01:00
|
|
|
/*
|
|
|
|
Sequence 1 - fails via insert - fail by having something there already
|
|
|
|
Sequence 2 - fails via update - fail by not having something there already
|
|
|
|
Sequence 3 - fails via update - fail by having something with wrong sequence number
|
|
|
|
Sequence 4 - fails via update - fail by having something with non-matching device sequence history
|
|
|
|
|
|
|
|
Maybe some of the above gets put off to wallet util
|
|
|
|
*/
|
2022-06-09 23:04:49 +02:00
|
|
|
t.Fatalf("Test me: Wallet Set failures")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-24 00:11:21 +02:00
|
|
|
// Test insertFirstWallet, using GetWallet, CreateAccount and GetUserID as a helpers
|
2022-06-24 01:57:55 +02:00
|
|
|
// Try insertFirstWallet twice with the same user id, error the second time
|
2022-06-24 00:11:21 +02:00
|
|
|
func TestStoreInsertWallet(t *testing.T) {
|
|
|
|
s, sqliteTmpFile := StoreTestInit(t)
|
|
|
|
defer StoreTestCleanup(sqliteTmpFile)
|
2021-12-25 02:16:58 +01:00
|
|
|
|
2022-06-24 00:11:21 +02:00
|
|
|
// Get a valid userId
|
|
|
|
email, password := auth.Email("abc@example.com"), auth.Password("123")
|
|
|
|
_ = s.CreateAccount(email, password)
|
|
|
|
userId, _ := s.GetUserId(email, password)
|
|
|
|
|
|
|
|
// Get a wallet, come back empty
|
|
|
|
encryptedWallet, sequence, hmac, err := s.GetWallet(userId)
|
|
|
|
if len(encryptedWallet) != 0 || sequence != 0 || len(hmac) != 0 || err != ErrNoWallet {
|
|
|
|
t.Fatalf("Expected ErrNoWallet. encrypted wallet: %+v sequence: %+v hmac: %+v err: %+v", encryptedWallet, sequence, hmac, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Put in a first wallet
|
|
|
|
if err := s.insertFirstWallet(userId, wallet.EncryptedWallet("my-encrypted-wallet"), wallet.WalletHmac("my-hmac")); err != nil {
|
|
|
|
t.Fatalf("Unexpected error in insertFirstWallet: %+v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get a wallet, have the values we put in with a sequence of 1
|
|
|
|
encryptedWallet, sequence, hmac, err = s.GetWallet(userId)
|
|
|
|
if encryptedWallet != wallet.EncryptedWallet("my-encrypted-wallet") ||
|
|
|
|
sequence != wallet.Sequence(1) ||
|
|
|
|
hmac != wallet.WalletHmac("my-hmac") ||
|
|
|
|
err != nil {
|
2022-06-24 01:57:55 +02:00
|
|
|
t.Fatalf("Unexpected values for wallet: encrypted wallet: %+v sequence: %+v hmac: %+v err: %+v", encryptedWallet, sequence, hmac, err)
|
2022-06-24 00:11:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Put in a first wallet for a second time, have an error for trying
|
|
|
|
if err := s.insertFirstWallet(userId, wallet.EncryptedWallet("my-encrypted-wallet-2"), wallet.WalletHmac("my-hmac-2")); err != ErrDuplicateWallet {
|
|
|
|
t.Fatalf(`insertFirstWallet err: wanted "%+v", got "%+v"`, ErrDuplicateToken, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the same *first* wallet we successfully put in
|
|
|
|
encryptedWallet, sequence, hmac, err = s.GetWallet(userId)
|
|
|
|
if encryptedWallet != wallet.EncryptedWallet("my-encrypted-wallet") ||
|
|
|
|
sequence != wallet.Sequence(1) ||
|
|
|
|
hmac != wallet.WalletHmac("my-hmac") ||
|
|
|
|
err != nil {
|
2022-06-24 01:57:55 +02:00
|
|
|
t.Fatalf("Unexpected values for wallet: encrypted wallet: %+v sequence: %+v hmac: %+v err: %+v", encryptedWallet, sequence, hmac, err)
|
2022-06-24 00:11:21 +02:00
|
|
|
}
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreUpdateWalletSuccess(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Wallet update successes")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreUpdateWalletFail(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Wallet update failures")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreGetWalletSuccess(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Wallet get success")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-09 23:04:49 +02:00
|
|
|
func TestStoreGetWalletFail(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Wallet get failures")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-23 23:29:16 +02:00
|
|
|
func TestStoreCreateAccount(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: Account create success and failures")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|
|
|
|
|
2022-06-23 23:29:16 +02:00
|
|
|
func TestStoreGetUserId(t *testing.T) {
|
|
|
|
t.Fatalf("Test me: User ID get success and failures")
|
2021-12-25 02:16:58 +01:00
|
|
|
}
|