Skip to content
Snippets Groups Projects
Commit 1f6597dc authored by Josh Brooks's avatar Josh Brooks
Browse files

Add handling of User's registration timestamp

parent 17aa557e
No related branches found
No related tags found
1 merge request!5Release
...@@ -12,9 +12,8 @@ require ( ...@@ -12,9 +12,8 @@ require (
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.0.0 github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 github.com/spf13/jwalterweatherman v1.1.0
github.com/spf13/viper v1.7.0 github.com/spf13/viper v1.7.0
gitlab.com/elixxir/comms v0.0.4-0.20210506225017-37485f5ba063 gitlab.com/elixxir/comms v0.0.4-0.20210510215231-525cc566ee11
gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110 gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110
gitlab.com/xx_network/comms v0.0.4-0.20210507215532-38ed97bd9365 gitlab.com/xx_network/comms v0.0.4-0.20210507215532-38ed97bd9365
gitlab.com/xx_network/crypto v0.0.5-0.20210504210244-9ddabbad25fd gitlab.com/xx_network/crypto v0.0.5-0.20210504210244-9ddabbad25fd
......
...@@ -371,10 +371,15 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm ...@@ -371,10 +371,15 @@ github.com/zeebo/pcg v0.0.0-20181207190024-3cdc6b625a05/go.mod h1:Gr+78ptB0MwXxm
github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0= github.com/zeebo/pcg v1.0.0 h1:dt+dx+HvX8g7Un32rY9XWoYnd0NmKmrIzpHF7qiTDj0=
github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4= github.com/zeebo/pcg v1.0.0/go.mod h1:09F0S9iiKrwn9rlI5yjLkmrug154/YRW6KnnXVDM/l4=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q= github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
gitlab.com/elixxir/comms v0.0.4-0.20210506182024-53912623ddd7 h1:8FEszwKqPYQJWyY4l3YFrW2ZqhJY96YFA7vS6Uh+0W8=
gitlab.com/elixxir/comms v0.0.4-0.20210506182024-53912623ddd7/go.mod h1:7ff+A4Nom55mKiRW7qWsN7LDjGay4OZwiaaIVXZ4hdk=
gitlab.com/elixxir/comms v0.0.4-0.20210506225017-37485f5ba063 h1:9A2FT1IDzb9E0HaEEcRMAZEVRM4SMXpklYvS6owSyIk= gitlab.com/elixxir/comms v0.0.4-0.20210506225017-37485f5ba063 h1:9A2FT1IDzb9E0HaEEcRMAZEVRM4SMXpklYvS6owSyIk=
gitlab.com/elixxir/comms v0.0.4-0.20210506225017-37485f5ba063/go.mod h1:KHV+lNKhcsXoor1KQizUHhCuHugnquldrAR8UU5PNKU= gitlab.com/elixxir/comms v0.0.4-0.20210506225017-37485f5ba063/go.mod h1:KHV+lNKhcsXoor1KQizUHhCuHugnquldrAR8UU5PNKU=
gitlab.com/elixxir/comms v0.0.4-0.20210510215231-525cc566ee11 h1:yetSThrWUS5wFxCYXxSfLbeqU++KwdsSkhEO/9VZeMg=
gitlab.com/elixxir/comms v0.0.4-0.20210510215231-525cc566ee11/go.mod h1:YhYFU6bXA628iJmHKV+Nuzvzh11cJNd5REU6Grb7jAY=
gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c= gitlab.com/elixxir/crypto v0.0.0-20200804182833-984246dea2c4/go.mod h1:ucm9SFKJo+K0N2GwRRpaNr+tKXMIOVWzmyUD0SbOu2c=
gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA= gitlab.com/elixxir/crypto v0.0.3/go.mod h1:ZNgBOblhYToR4m8tj4cMvJ9UsJAUKq+p0gCp07WQmhA=
gitlab.com/elixxir/crypto v0.0.7-0.20210504210535-3077ddf9984d/go.mod h1:pbq80k+R7XXvjyWDqanD2eCJi1ClfESdKS0K8NndoLs=
gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110 h1:4KWUbx1RI5TABBM2omWl5MLW16dwySglz895X2rhSFQ= gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110 h1:4KWUbx1RI5TABBM2omWl5MLW16dwySglz895X2rhSFQ=
gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110/go.mod h1:pbq80k+R7XXvjyWDqanD2eCJi1ClfESdKS0K8NndoLs= gitlab.com/elixxir/crypto v0.0.7-0.20210506223047-3196e4301110/go.mod h1:pbq80k+R7XXvjyWDqanD2eCJi1ClfESdKS0K8NndoLs=
gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg= gitlab.com/elixxir/primitives v0.0.0-20200731184040-494269b53b4d/go.mod h1:OQgUZq7SjnE0b+8+iIAT2eqQF+2IFHn73tOo+aV11mg=
......
...@@ -22,7 +22,12 @@ func TestImpl_InitDeleter(t *testing.T) { ...@@ -22,7 +22,12 @@ func TestImpl_InitDeleter(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to get intermediary ephemeral id: %+v", err) t.Errorf("Failed to get intermediary ephemeral id: %+v", err)
} }
u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Fatalf("Could not parse precanned time: %v", err.Error())
}
u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"), testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add user to storage: %+v", err) t.Errorf("Failed to add user to storage: %+v", err)
} }
...@@ -66,7 +71,12 @@ func TestImpl_InitCreator(t *testing.T) { ...@@ -66,7 +71,12 @@ func TestImpl_InitCreator(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to get intermediary ephemeral id: %+v", err) t.Errorf("Failed to get intermediary ephemeral id: %+v", err)
} }
u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
u, err := s.AddUser(iid, []byte("trsa"), []byte("Sig"),testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add user to storage: %+v", err) t.Errorf("Failed to add user to storage: %+v", err)
} }
......
...@@ -185,8 +185,8 @@ func (nb *Impl) RegisterForNotifications(request *pb.NotificationRegisterRequest ...@@ -185,8 +185,8 @@ func (nb *Impl) RegisterForNotifications(request *pb.NotificationRegisterRequest
//} //}
// Add the user to storage // Add the user to storage
u, err := nb.Storage.AddUser(request.IntermediaryId, request.TransmissionRsa, u, err := nb.Storage.AddUser(request.IntermediaryId, request.TransmissionRsa, request.IIDTransmissionRsaSig,
request.IIDTransmissionRsaSig, request.Token) time.Unix(0, request.RegistrationTimestamp), request.Token)
if err != nil { if err != nil {
return errors.Wrap(err, "Failed to register user with notifications") return errors.Wrap(err, "Failed to register user with notifications")
} }
......
...@@ -50,7 +50,12 @@ func TestNotifyUser(t *testing.T) { ...@@ -50,7 +50,12 @@ func TestNotifyUser(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to create iid: %+v", err) t.Errorf("Failed to create iid: %+v", err)
} }
u, err := s.AddUser(iid, []byte("rsacert"), []byte("sig"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
u, err := s.AddUser(iid, []byte("rsacert"), []byte("sig"),testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add fake user: %+v", err) t.Errorf("Failed to add fake user: %+v", err)
} }
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
"gorm.io/gorm" "gorm.io/gorm"
"gorm.io/gorm/logger" "gorm.io/gorm/logger"
"time"
) )
// interface declaration for storage methods // interface declaration for storage methods
...@@ -48,6 +49,8 @@ type User struct { ...@@ -48,6 +49,8 @@ type User struct {
Signature []byte `gorm:"not null"` Signature []byte `gorm:"not null"`
Token string `gorm:"not null"` Token string `gorm:"not null"`
Ephemerals []Ephemeral `gorm:"foreignKey:transmission_rsa_hash;references:transmission_rsa_hash;constraint:OnDelete:CASCADE;"` Ephemerals []Ephemeral `gorm:"foreignKey:transmission_rsa_hash;references:transmission_rsa_hash;constraint:OnDelete:CASCADE;"`
// Time in which user has registered with the network (ie permissioning)
RegistrationTimestamp time.Time
} }
type Ephemeral struct { type Ephemeral struct {
......
...@@ -22,8 +22,13 @@ func TestDatabaseImpl(t *testing.T) { ...@@ -22,8 +22,13 @@ func TestDatabaseImpl(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to make iid: %+v", err) t.Errorf("Failed to make iid: %+v", err)
} }
testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
token1 := "i'm a token" token1 := "i'm a token"
_, err = s.AddUser(iid, []byte("rsa"), sig, token1) _, err = s.AddUser(iid, []byte("rsa"), sig, testTime, token1)
if err != nil { if err != nil {
t.Errorf("Failed to upsert user: %+v", err) t.Errorf("Failed to upsert user: %+v", err)
} }
...@@ -37,7 +42,7 @@ func TestDatabaseImpl(t *testing.T) { ...@@ -37,7 +42,7 @@ func TestDatabaseImpl(t *testing.T) {
} }
token2 := "you're a token" token2 := "you're a token"
u1, err := s.AddUser(iid, []byte("rsa"), sig, token2) u1, err := s.AddUser(iid, []byte("rsa"), sig, testTime, token2)
if err != nil { if err != nil {
t.Errorf("Failed to upsert updated user: %+v", err) t.Errorf("Failed to upsert updated user: %+v", err)
} }
...@@ -58,7 +63,7 @@ func TestDatabaseImpl(t *testing.T) { ...@@ -58,7 +63,7 @@ func TestDatabaseImpl(t *testing.T) {
t.Errorf("Expected user with token %s. Instead got %s.", token1, u.Token) t.Errorf("Expected user with token %s. Instead got %s.", token1, u.Token)
} }
u2, err := s.AddUser([]byte("jakexx360"), []byte("rsa2"), sig, token2) u2, err := s.AddUser([]byte("jakexx360"), []byte("rsa2"), sig, testTime, token2)
if err != nil { if err != nil {
t.Errorf("Failed to upsert updated user: %+v", err) t.Errorf("Failed to upsert updated user: %+v", err)
} }
......
...@@ -20,7 +20,7 @@ func NewStorage(username, password, dbName, address, port string) (*Storage, err ...@@ -20,7 +20,7 @@ func NewStorage(username, password, dbName, address, port string) (*Storage, err
return storage, err return storage, err
} }
func (s *Storage) AddUser(iid, transmissionRSA, signature []byte, token string) (*User, error) { func (s *Storage) AddUser(iid, transmissionRSA, signature []byte, regTimestamp time.Time, token string) (*User, error) {
h, err := hash.NewCMixHash() h, err := hash.NewCMixHash()
if err != nil { if err != nil {
return nil, errors.WithMessage(err, "Failed to create cmix hash") return nil, errors.WithMessage(err, "Failed to create cmix hash")
...@@ -34,6 +34,7 @@ func (s *Storage) AddUser(iid, transmissionRSA, signature []byte, token string) ...@@ -34,6 +34,7 @@ func (s *Storage) AddUser(iid, transmissionRSA, signature []byte, token string)
TransmissionRSAHash: h.Sum(nil), TransmissionRSAHash: h.Sum(nil),
TransmissionRSA: transmissionRSA, TransmissionRSA: transmissionRSA,
Signature: signature, Signature: signature,
RegistrationTimestamp: regTimestamp,
OffsetNum: ephemeral.GetOffsetNum(ephemeral.GetOffset(iid)), OffsetNum: ephemeral.GetOffsetNum(ephemeral.GetOffset(iid)),
Token: token, Token: token,
} }
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral" "gitlab.com/xx_network/primitives/id/ephemeral"
"testing" "testing"
"time"
) )
func TestStorage_AddUser(t *testing.T) { func TestStorage_AddUser(t *testing.T) {
...@@ -16,7 +17,12 @@ func TestStorage_AddUser(t *testing.T) { ...@@ -16,7 +17,12 @@ func TestStorage_AddUser(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to create iid: %+v", err) t.Errorf("Failed to create iid: %+v", err)
} }
_, err = s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
_, err = s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"),testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add user: %+v", err) t.Errorf("Failed to add user: %+v", err)
} }
...@@ -32,7 +38,12 @@ func TestStorage_DeleteUser(t *testing.T) { ...@@ -32,7 +38,12 @@ func TestStorage_DeleteUser(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to create iid: %+v", err) t.Errorf("Failed to create iid: %+v", err)
} }
u, err := s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
u, err := s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"),testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add user: %+v", err) t.Errorf("Failed to add user: %+v", err)
} }
...@@ -52,7 +63,12 @@ func TestStorage_AddLatestEphemeral(t *testing.T) { ...@@ -52,7 +63,12 @@ func TestStorage_AddLatestEphemeral(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("Failed to create iid: %+v", err) t.Errorf("Failed to create iid: %+v", err)
} }
u, err := s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"), "token") testTime, err := time.Parse(time.RFC3339,
"2012-12-21T22:08:41+00:00")
if err != nil {
t.Errorf("Could not parse precanned time: %v", err.Error())
}
u, err := s.AddUser(iid, []byte("transmissionrsa"), []byte("signature"),testTime, "token")
if err != nil { if err != nil {
t.Errorf("Failed to add user: %+v", err) t.Errorf("Failed to add user: %+v", err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment