Commit 7cfadff8 authored by Sietse Ringers's avatar Sietse Ringers
Browse files

refactor: remove KeyshareUser/KeyshareUserData distinction

parent 94e22459
......@@ -21,7 +21,7 @@ var keyshareServ *http.Server
func StartKeyshareServer(t *testing.T, l *logrus.Logger) {
db := keyshareserver.NewMemoryDatabase()
_, err := db.NewUser(keyshareserver.KeyshareUserData{
err := db.NewUser(&keyshareserver.KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -30,7 +30,7 @@ func StartKeyshareServer(t *testing.T, l *logrus.Logger) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(keyshareserver.KeyshareUserData{
err = db.NewUser(&keyshareserver.KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......
......@@ -28,36 +28,31 @@ const (
// - postgresdb (postgresdb.go) storing all data in a postgres database
type KeyshareDB interface {
// User management
NewUser(user KeyshareUserData) (KeyshareUser, error)
User(username string) (KeyshareUser, error)
UpdateUser(user KeyshareUser) error
NewUser(user *KeyshareUser) error
User(username string) (*KeyshareUser, error)
UpdateUser(user *KeyshareUser) error
// Pin checking logic
// Reserve returns (allow, tries, wait, error)
// where allow is whether we can do the actual pin check
// tries is how many tries are remaining after doing so
// wait is how long to wait if tries is 0 or allow false
ReservePincheck(user KeyshareUser) (bool, int, int64, error)
ClearPincheck(user KeyshareUser) error
ReservePincheck(user *KeyshareUser) (bool, int, int64, error)
ClearPincheck(user *KeyshareUser) error
// User activity registration
// SetSeen calls are used to track when a users account was last active, for deleting old accounts
SetSeen(user KeyshareUser) error
AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error
SetSeen(user *KeyshareUser) error
AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error
// Store email verification tokens on registration
AddEmailVerification(user KeyshareUser, emailAddress, token string) error
}
// We wrap KeyshareUserData in an interface to allow implementation-specific data
// to also be returned. This is used in postgresdb to deal with database identifiers
type KeyshareUser interface {
Data() *KeyshareUserData
AddEmailVerification(user *KeyshareUser, emailAddress, token string) error
}
// Actual data on a user used by this server.
type KeyshareUserData struct {
type KeyshareUser struct {
Username string
Language string
Coredata keysharecore.EncryptedKeysharePacket
id int64
}
......@@ -15,19 +15,11 @@ type keyshareMemoryDB struct {
users map[string]keysharecore.EncryptedKeysharePacket
}
type keyshareMemoryUser struct {
KeyshareUserData
}
func (m *keyshareMemoryUser) Data() *KeyshareUserData {
return &m.KeyshareUserData
}
func NewMemoryDatabase() KeyshareDB {
return &keyshareMemoryDB{users: map[string]keysharecore.EncryptedKeysharePacket{}}
}
func (db *keyshareMemoryDB) User(username string) (KeyshareUser, error) {
func (db *keyshareMemoryDB) User(username string) (*KeyshareUser, error) {
// Ensure access to database is single-threaded
db.lock.Lock()
defer db.lock.Unlock()
......@@ -37,10 +29,10 @@ func (db *keyshareMemoryDB) User(username string) (KeyshareUser, error) {
if !ok {
return nil, ErrUserNotFound
}
return &keyshareMemoryUser{KeyshareUserData{Username: username, Coredata: data}}, nil
return &KeyshareUser{Username: username, Coredata: data}, nil
}
func (db *keyshareMemoryDB) NewUser(user KeyshareUserData) (KeyshareUser, error) {
func (db *keyshareMemoryDB) NewUser(user *KeyshareUser) error {
// Ensure access to database is single-threaded
db.lock.Lock()
defer db.lock.Unlock()
......@@ -48,49 +40,47 @@ func (db *keyshareMemoryDB) NewUser(user KeyshareUserData) (KeyshareUser, error)
// Check and insert user
_, exists := db.users[user.Username]
if exists {
return nil, ErrUserAlreadyExists
return ErrUserAlreadyExists
}
db.users[user.Username] = user.Coredata
return &keyshareMemoryUser{KeyshareUserData: user}, nil
return nil
}
func (db *keyshareMemoryDB) UpdateUser(user KeyshareUser) error {
userdata := user.(*keyshareMemoryUser)
func (db *keyshareMemoryDB) UpdateUser(user *KeyshareUser) error {
// Ensure access to database is single-threaded
db.lock.Lock()
defer db.lock.Unlock()
// Check and update user.
_, exists := db.users[userdata.Username]
_, exists := db.users[user.Username]
if !exists {
return ErrUserNotFound
}
db.users[userdata.Username] = userdata.Coredata
db.users[user.Username] = user.Coredata
return nil
}
func (db *keyshareMemoryDB) ReservePincheck(user KeyshareUser) (bool, int, int64, error) {
func (db *keyshareMemoryDB) ReservePincheck(user *KeyshareUser) (bool, int, int64, error) {
// Since this is a testing DB, implementing anything more than always allow creates hastle
return true, 1, 0, nil
}
func (db *keyshareMemoryDB) ClearPincheck(user KeyshareUser) error {
func (db *keyshareMemoryDB) ClearPincheck(user *KeyshareUser) error {
// Since this is a testing DB, implementing anything more than always allow creates hastle
return nil
}
func (db *keyshareMemoryDB) SetSeen(user KeyshareUser) error {
func (db *keyshareMemoryDB) SetSeen(user *KeyshareUser) error {
// We don't need to do anything here, as this information cannot be extracted locally
return nil
}
func (db *keyshareMemoryDB) AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error {
func (db *keyshareMemoryDB) AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error {
// We don't need to do anything here, as this information cannot be extracted locally
return nil
}
func (db *keyshareMemoryDB) AddEmailVerification(user KeyshareUser, emailAddress, token string) error {
func (db *keyshareMemoryDB) AddEmailVerification(user *KeyshareUser, emailAddress, token string) error {
// We don't need to do anything here, as this information cannot be extracted locally
return nil
}
......@@ -10,18 +10,20 @@ import (
func TestMemoryDBUserManagement(t *testing.T) {
db := NewMemoryDatabase()
user, err := db.NewUser(KeyshareUserData{Username: "testuser"})
user := &KeyshareUser{Username: "testuser"}
err := db.NewUser(user)
require.NoError(t, err)
assert.Equal(t, "testuser", user.Data().Username)
assert.Equal(t, "testuser", user.Username)
nuser, err := db.User("testuser")
require.NoError(t, err)
assert.Equal(t, "testuser", nuser.Data().Username)
assert.Equal(t, "testuser", nuser.Username)
_, err = db.User("nonexistent")
assert.Error(t, err)
_, err = db.NewUser(KeyshareUserData{Username: "testuser"})
user = &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
assert.Error(t, err)
err = db.UpdateUser(nuser)
......
......@@ -17,16 +17,6 @@ type keysharePostgresDatabase struct {
db *sql.DB
}
// For easy access in the database, we store the row id also in the returned user data
type keysharePostgresUser struct {
KeyshareUserData
id int64
}
func (m *keysharePostgresUser) Data() *KeyshareUserData {
return &m.KeyshareUserData
}
const MAX_PIN_TRIES = 3 // Number of tries allowed on pin before we start with exponential backoff
const EMAIL_TOKEN_VALIDITY = 24 // Ammount of time user's email validation token is valid (in hours)
......@@ -44,28 +34,29 @@ func NewPostgresDatabase(connstring string) (KeyshareDB, error) {
}, nil
}
func (db *keysharePostgresDatabase) NewUser(user KeyshareUserData) (KeyshareUser, error) {
func (db *keysharePostgresDatabase) NewUser(user *KeyshareUser) error {
res, err := db.db.Query("INSERT INTO irma.users (username, language, coredata, last_seen, pin_counter, pin_block_date) VALUES ($1, $2, $3, $4, 0, 0) RETURNING id",
user.Username,
user.Language,
user.Coredata[:],
time.Now().Unix())
if err != nil {
return nil, err
return err
}
defer common.Close(res)
if !res.Next() {
return nil, ErrUserAlreadyExists
return ErrUserAlreadyExists
}
var id int64
err = res.Scan(&id)
if err != nil {
return nil, err
return err
}
return &keysharePostgresUser{KeyshareUserData: user, id: id}, nil
user.id = id
return nil
}
func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error) {
func (db *keysharePostgresDatabase) User(username string) (*KeyshareUser, error) {
rows, err := db.db.Query("SELECT id, username, language, coredata FROM irma.users WHERE username = $1 AND coredata IS NOT NULL", username)
if err != nil {
return nil, err
......@@ -74,7 +65,7 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error)
if !rows.Next() {
return nil, ErrUserNotFound
}
var result keysharePostgresUser
var result KeyshareUser
var ep []byte
err = rows.Scan(&result.id, &result.Username, &result.Language, &ep)
if err != nil {
......@@ -87,21 +78,17 @@ func (db *keysharePostgresDatabase) User(username string) (KeyshareUser, error)
return &result, nil
}
func (db *keysharePostgresDatabase) UpdateUser(user KeyshareUser) error {
userdata := user.(*keysharePostgresUser)
func (db *keysharePostgresDatabase) UpdateUser(user *KeyshareUser) error {
return db.updateUser(
"UPDATE irma.users SET username=$1, language=$2, coredata=$3 WHERE id=$4",
userdata.Username,
userdata.Language,
userdata.Coredata[:],
userdata.id,
user.Username,
user.Language,
user.Coredata[:],
user.id,
)
}
func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, int, int64, error) {
// Extract data
userdata := user.(*keysharePostgresUser)
func (db *keysharePostgresDatabase) ReservePincheck(user *KeyshareUser) (bool, int, int64, error) {
// Check that account is not blocked already, and if not,
// update pinCounter and pinBlockDate
uprows, err := db.db.Query(`
......@@ -113,7 +100,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
time.Now().Unix()-1-BACKOFF_START, // Grace time of 2 seconds on pinBlockDate set
BACKOFF_START,
MAX_PIN_TRIES-2,
userdata.id,
user.id,
time.Now().Unix())
if err != nil {
return false, 0, 0, err
......@@ -128,7 +115,7 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
if !uprows.Next() {
// if no results, then account either does not exist (which would be weird here) or is blocked
// so request wait timeout
pinrows, err := db.db.Query("SELECT pin_block_date FROM irma.users WHERE id=$1 AND coredata IS NOT NULL", userdata.id)
pinrows, err := db.db.Query("SELECT pin_block_date FROM irma.users WHERE id=$1 AND coredata IS NOT NULL", user.id)
if err != nil {
return false, 0, 0, err
}
......@@ -161,18 +148,18 @@ func (db *keysharePostgresDatabase) ReservePincheck(user KeyshareUser) (bool, in
return allowed, tries, wait, nil
}
func (db *keysharePostgresDatabase) ClearPincheck(user KeyshareUser) error {
func (db *keysharePostgresDatabase) ClearPincheck(user *KeyshareUser) error {
return db.updateUser(
"UPDATE irma.users SET pin_counter=0, pin_block_date=0 WHERE id=$1",
user.(*keysharePostgresUser).id,
user.id,
)
}
func (db *keysharePostgresDatabase) SetSeen(user KeyshareUser) error {
func (db *keysharePostgresDatabase) SetSeen(user *KeyshareUser) error {
return db.updateUser(
"UPDATE irma.users SET last_seen = $1 WHERE id = $2",
time.Now().Unix(),
user.(*keysharePostgresUser).id,
user.id,
)
}
......@@ -191,9 +178,7 @@ func (db *keysharePostgresDatabase) updateUser(query string, args ...interface{}
return nil
}
func (db *keysharePostgresDatabase) AddLog(user KeyshareUser, eventType LogEntryType, param interface{}) error {
userdata := user.(*keysharePostgresUser)
func (db *keysharePostgresDatabase) AddLog(user *KeyshareUser, eventType LogEntryType, param interface{}) error {
var encodedParamString *string
if param != nil {
encodedParam, err := json.Marshal(param)
......@@ -208,17 +193,15 @@ func (db *keysharePostgresDatabase) AddLog(user KeyshareUser, eventType LogEntry
time.Now().Unix(),
eventType,
encodedParamString,
userdata.id)
user.id)
return err
}
func (db *keysharePostgresDatabase) AddEmailVerification(user KeyshareUser, emailAddress, token string) error {
userdata := user.(*keysharePostgresUser)
func (db *keysharePostgresDatabase) AddEmailVerification(user *KeyshareUser, emailAddress, token string) error {
_, err := db.db.Exec("INSERT INTO irma.email_verification_tokens (token, email, user_id, expiry) VALUES ($1, $2, $3, $4)",
token,
emailAddress,
userdata.id,
user.id,
time.Now().Add(EMAIL_TOKEN_VALIDITY*time.Hour).Unix())
return err
}
......@@ -22,13 +22,14 @@ func TestPostgresDBUserManagement(t *testing.T) {
db, err := NewPostgresDatabase(postgresTestUrl)
require.NoError(t, err)
user, err := db.NewUser(KeyshareUserData{Username: "testuser"})
user := &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
require.NoError(t, err)
assert.Equal(t, "testuser", user.Data().Username)
assert.Equal(t, "testuser", user.Username)
nuser, err := db.User("testuser")
require.NoError(t, err)
assert.Equal(t, "testuser", nuser.Data().Username)
assert.Equal(t, "testuser", nuser.Username)
_, err = db.User("notexist")
assert.Error(t, err)
......@@ -36,7 +37,8 @@ func TestPostgresDBUserManagement(t *testing.T) {
err = db.UpdateUser(nuser)
assert.NoError(t, err)
_, err = db.NewUser(KeyshareUserData{Username: "testuser"})
user = &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
assert.Error(t, err)
err = db.AddLog(nuser, PinCheckFailed, 15)
......@@ -58,7 +60,8 @@ func TestPostgresDBPinReservation(t *testing.T) {
db, err := NewPostgresDatabase(postgresTestUrl)
require.NoError(t, err)
user, err := db.NewUser(KeyshareUserData{Username: "testuser"})
user := &KeyshareUser{Username: "testuser"}
err = db.NewUser(user)
require.NoError(t, err)
ok, tries, wait, err := db.ReservePincheck(user)
......
......@@ -162,7 +162,7 @@ func (s *Server) LoadIdemixKeys(conf *irma.Configuration) {
// /prove/getCommitments
func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) {
// Fetch from context
user := r.Context().Value("user").(KeyshareUser)
user := r.Context().Value("user").(*KeyshareUser)
authorization := r.Context().Value("authorization").(string)
// Read keys
......@@ -200,9 +200,9 @@ func (s *Server) handleCommitments(w http.ResponseWriter, r *http.Request) {
server.WriteJson(w, commitments)
}
func (s *Server) generateCommitments(user KeyshareUser, authorization string, keys []irma.PublicKeyIdentifier) (*irma.ProofPCommitmentMap, error) {
func (s *Server) generateCommitments(user *KeyshareUser, authorization string, keys []irma.PublicKeyIdentifier) (*irma.ProofPCommitmentMap, error) {
// Generate commitments
commitments, commitID, err := s.core.GenerateCommitments(user.Data().Coredata, authorization, keys)
commitments, commitID, err := s.core.GenerateCommitments(user.Coredata, authorization, keys)
if err != nil {
s.conf.Logger.WithField("error", err).Warn("Could not generate commitments for request")
return nil, err
......@@ -219,7 +219,7 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke
}
// Store needed data for later requests.
username := user.Data().Username
username := user.Username
s.sessionLock.Lock()
if _, ok := s.sessions[username]; !ok {
s.sessions[username] = &SessionData{}
......@@ -240,8 +240,8 @@ func (s *Server) generateCommitments(user KeyshareUser, authorization string, ke
// /prove/getResponse
func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
// Fetch from context
user := r.Context().Value("user").(KeyshareUser)
username := user.Data().Username
user := r.Context().Value("user").(*KeyshareUser)
username := user.Username
authorization := r.Context().Value("authorization").(string)
// Read challenge
......@@ -291,7 +291,7 @@ func (s *Server) handleResponse(w http.ResponseWriter, r *http.Request) {
server.WriteString(w, proofResponse)
}
func (s *Server) doGenerateResponses(user KeyshareUser, authorization string, challenge *big.Int, commitID uint64, keyID irma.PublicKeyIdentifier) (string, error) {
func (s *Server) doGenerateResponses(user *KeyshareUser, authorization string, challenge *big.Int, commitID uint64, keyID irma.PublicKeyIdentifier) (string, error) {
// Indicate activity on user account
err := s.db.SetSeen(user)
if err != nil {
......@@ -306,7 +306,7 @@ func (s *Server) doGenerateResponses(user KeyshareUser, authorization string, ch
return "", err
}
proofResponse, err := s.core.GenerateResponse(user.Data().Coredata, authorization, commitID, challenge, keyID)
proofResponse, err := s.core.GenerateResponse(user.Coredata, authorization, commitID, challenge, keyID)
if err != nil {
s.conf.Logger.WithField("error", err).Error("Could not generate response for request")
return "", err
......@@ -360,7 +360,7 @@ func (s *Server) handleVerifyPin(w http.ResponseWriter, r *http.Request) {
server.WriteJson(w, result)
}
func (s *Server) doVerifyPin(user KeyshareUser, username, pin string) (irma.KeysharePinStatus, error) {
func (s *Server) doVerifyPin(user *KeyshareUser, username, pin string) (irma.KeysharePinStatus, error) {
// Check whether timing allows this pin to be checked
ok, tries, wait, err := s.db.ReservePincheck(user)
if err != nil {
......@@ -376,7 +376,7 @@ func (s *Server) doVerifyPin(user KeyshareUser, username, pin string) (irma.Keys
return irma.KeysharePinStatus{Status: "error", Message: fmt.Sprintf("%v", wait)}, nil
}
// At this point, we are allowed to do an actual check (we have successfully reserved a spot for it), so do it.
jwtt, err := s.core.ValidatePin(user.Data().Coredata, pin, username)
jwtt, err := s.core.ValidatePin(user.Coredata, pin, username)
if err != nil && err != keysharecore.ErrInvalidPin {
// Errors other than invalid pin are real errors
s.conf.Logger.WithField("error", err).Error("Could not validate pin")
......@@ -456,7 +456,7 @@ func (s *Server) handleChangePin(w http.ResponseWriter, r *http.Request) {
server.WriteJson(w, result)
}
func (s *Server) doUpdatePin(user KeyshareUser, oldPin, newPin string) (irma.KeysharePinStatus, error) {
func (s *Server) doUpdatePin(user *KeyshareUser, oldPin, newPin string) (irma.KeysharePinStatus, error) {
// Check whether pin check is currently allowed
ok, tries, wait, err := s.db.ReservePincheck(user)
if err != nil {
......@@ -468,7 +468,7 @@ func (s *Server) doUpdatePin(user KeyshareUser, oldPin, newPin string) (irma.Key
}
// Try to do the update
user.Data().Coredata, err = s.core.ChangePin(user.Data().Coredata, oldPin, newPin)
user.Coredata, err = s.core.ChangePin(user.Coredata, oldPin, newPin)
if err == keysharecore.ErrInvalidPin {
if tries == 0 {
return irma.KeysharePinStatus{Status: "error", Message: fmt.Sprintf("%v", wait)}, nil
......@@ -536,7 +536,8 @@ func (s *Server) doRegistration(msg irma.KeyshareEnrollment) (*irma.Qr, error) {
s.conf.Logger.WithField("error", err).Error("Could not register user")
return nil, err
}
user, err := s.db.NewUser(KeyshareUserData{Username: username, Language: msg.Language, Coredata: coredata})
user := &KeyshareUser{Username: username, Language: msg.Language, Coredata: coredata}
err = s.db.NewUser(user)
if err != nil {
s.conf.Logger.WithField("error", err).Error("Could not store new user in database")
return nil, err
......@@ -567,7 +568,7 @@ func (s *Server) doRegistration(msg irma.KeyshareEnrollment) (*irma.Qr, error) {
return sessionptr, nil
}
func (s *Server) sendRegistrationEmail(user KeyshareUser, language, email string) error {
func (s *Server) sendRegistrationEmail(user *KeyshareUser, language, email string) error {
// Fetch template and configuration data for users language, falling back if needed
template, ok := s.conf.RegistrationEmailTemplates[language]
if !ok {
......@@ -666,7 +667,7 @@ func (s *Server) authorizationMiddleware(next http.Handler) http.Handler {
// verify access
ctx := r.Context()
err := s.core.ValidateJWT(ctx.Value("user").(KeyshareUser).Data().Coredata, authorization)
err := s.core.ValidateJWT(ctx.Value("user").(*KeyshareUser).Coredata, authorization)
hasValidAuthorization := (err == nil)
// Construct new context with both authorization and its validity
......
......@@ -92,7 +92,7 @@ func TestServerHandleRegister(t *testing.T) {
func TestServerHandleValidate(t *testing.T) {
db := NewMemoryDatabase()
_, err := db.NewUser(KeyshareUserData{
err := db.NewUser(&KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -101,7 +101,7 @@ func TestServerHandleValidate(t *testing.T) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(KeyshareUserData{
err = db.NewUser(&KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......@@ -165,7 +165,7 @@ func TestServerHandleValidate(t *testing.T) {
func TestPinTries(t *testing.T) {
db := NewMemoryDatabase()
_, err := db.NewUser(KeyshareUserData{
err := db.NewUser(&KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -174,7 +174,7 @@ func TestPinTries(t *testing.T) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(KeyshareUserData{
err = db.NewUser(&KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......@@ -210,7 +210,7 @@ func TestPinTries(t *testing.T) {
func TestPinWait(t *testing.T) {
db := NewMemoryDatabase()
_, err := db.NewUser(KeyshareUserData{
err := db.NewUser(&KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -219,7 +219,7 @@ func TestPinWait(t *testing.T) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(KeyshareUserData{
err = db.NewUser(&KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......@@ -255,7 +255,7 @@ func TestPinWait(t *testing.T) {
func TestPinWaitRefused(t *testing.T) {
db := NewMemoryDatabase()
_, err := db.NewUser(KeyshareUserData{
err := db.NewUser(&KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -264,7 +264,7 @@ func TestPinWaitRefused(t *testing.T) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(KeyshareUserData{
err = db.NewUser(&KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......@@ -348,7 +348,7 @@ func TestMissingUser(t *testing.T) {
func TestInvalidKeyshareSessions(t *testing.T) {
db := NewMemoryDatabase()
_, err := db.NewUser(KeyshareUserData{
err := db.NewUser(&KeyshareUser{
Username: "",
Coredata: keysharecore.EncryptedKeysharePacket{},
})
......@@ -357,7 +357,7 @@ func TestInvalidKeyshareSessions(t *testing.T) {
p, err := base64.StdEncoding.DecodeString("YWJjZK4w5SC+7D4lDrhiJGvB1iwxSeF90dGGPoGqqG7g3ivbfHibOdkKoOTZPbFlttBzn2EJgaEsL24Re8OWWWw5pd31/GCd14RXcb9Wy2oWhbr0pvJDLpIxXZt/qiQC0nJiIAYWLGZOdj5o0irDfqP1CSfw3IoKkVEl4lHRj0LCeINJIOpEfGlFtl4DHlWu8SMQFV1AIm3Gv64XzGncdkclVd41ti7cicBrcK8N2u9WvY/jCS4/Lxa2syp/O4IY")
require.NoError(t, err)
copy(ep[:], p)
_, err = db.NewUser(KeyshareUserData{
err = db.NewUser(&KeyshareUser{
Username: "testusername",
Coredata: ep,
})
......@@ -508,34 +508,34 @@ type testDB struct {
err error
}
func (db *testDB) NewUser(user KeyshareUserData) (KeyshareUser, error) {
func (db *testDB) NewUser(user *KeyshareUser) error {
return db.db.NewUser(user)