replace Id with ID

This commit is contained in:
2025-02-13 08:00:49 -06:00
parent f948a06b66
commit 32facb1767
19 changed files with 172 additions and 169 deletions

View File

@@ -3,6 +3,7 @@ version: "3"
vars: vars:
test_db: "~/databases/test.db" test_db: "~/databases/test.db"
schema_db: "./sqlite/schema.sql" schema_db: "./sqlite/schema.sql"
svg_path: "~/svgs/flaticon_colored_svgs"
tasks: tasks:
sqlc: sqlc:
cmds: cmds:
@@ -10,5 +11,7 @@ tasks:
rebuild_test_db: rebuild_test_db:
cmds: cmds:
- go build cmd/nkode/nkode.go
- rm {{.test_db}} - rm {{.test_db}}
- sqlite3 {{.test_db}} < {{.schema_db}} - sqlite3 {{.test_db}} < {{.schema_db}}
- ./nkode -db-path {{.test_db}} -svg-path {{.svg_path}}

View File

@@ -36,7 +36,7 @@ func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKo
} }
} }
func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entities.CustomerId, error) { func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entities.CustomerID, error) {
newCustomer, err := entities.NewCustomer(nkodePolicy) newCustomer, err := entities.NewCustomer(nkodePolicy)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -46,22 +46,22 @@ func (n *NKodeAPI) CreateNewCustomer(nkodePolicy entities.NKodePolicy) (*entitie
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &newCustomer.Id, nil return &newCustomer.ID, nil
} }
func (n *NKodeAPI) CreateCustomerWithID(id entities.CustomerId, nkodePolicy entities.NKodePolicy) error { func (n *NKodeAPI) CreateCustomerWithID(id entities.CustomerID, nkodePolicy entities.NKodePolicy) error {
newCustomer, err := entities.NewCustomer(nkodePolicy) newCustomer, err := entities.NewCustomer(nkodePolicy)
if err != nil { if err != nil {
return err return err
} }
newCustomer.Id = id newCustomer.ID = id
if err = n.repo.CreateCustomer(*newCustomer); err != nil { if err = n.repo.CreateCustomer(*newCustomer); err != nil {
return err return err
} }
return nil return nil
} }
func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, customerId entities.CustomerId, kp entities.KeypadDimension, reset bool) (*entities.SignupResetInterface, error) { func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, customerId entities.CustomerID, kp entities.KeypadDimension, reset bool) (*entities.SignupResetInterface, error) {
user, err := n.repo.GetUser(userEmail, customerId) user, err := n.repo.GetUser(userEmail, customerId)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -78,23 +78,23 @@ func (n *NKodeAPI) GenerateSignupResetInterface(userEmail entities.UserEmail, cu
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err := n.signupSessionCache.Add(signupSession.Id.String(), *signupSession, sessionExpiration); err != nil { if err := n.signupSessionCache.Add(signupSession.ID.String(), *signupSession, sessionExpiration); err != nil {
return nil, err return nil, err
} }
svgInterface, err := n.repo.GetSvgStringInterface(signupSession.LoginUserInterface.SvgId) svgInterface, err := n.repo.GetSvgStringInterface(signupSession.LoginUserInterface.SvgID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
resp := entities.SignupResetInterface{ resp := entities.SignupResetInterface{
UserIdxInterface: signupSession.SetIdxInterface, UserIdxInterface: signupSession.SetIdxInterface,
SvgInterface: svgInterface, SvgInterface: svgInterface,
SessionId: uuid.UUID(signupSession.Id).String(), SessionID: uuid.UUID(signupSession.ID).String(),
Colors: signupSession.Colors, Colors: signupSession.Colors,
} }
return &resp, nil return &resp, nil
} }
func (n *NKodeAPI) SetNKode(customerId entities.CustomerId, sessionId entities.SessionId, keySelection entities.KeySelection) (entities.IdxInterface, error) { func (n *NKodeAPI) SetNKode(customerId entities.CustomerID, sessionId entities.SessionID, keySelection entities.KeySelection) (entities.IdxInterface, error) {
_, err := n.repo.GetCustomer(customerId) _, err := n.repo.GetCustomer(customerId)
if err != nil { if err != nil {
@@ -118,7 +118,7 @@ func (n *NKodeAPI) SetNKode(customerId entities.CustomerId, sessionId entities.S
return confirmInterface, nil return confirmInterface, nil
} }
func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerId, sessionId entities.SessionId, keySelection entities.KeySelection) error { func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerID, sessionId entities.SessionID, keySelection entities.KeySelection) error {
session, exists := n.signupSessionCache.Get(sessionId.String()) session, exists := n.signupSessionCache.Get(sessionId.String())
if !exists { if !exists {
log.Printf("session id does not exist %s", sessionId) log.Printf("session id does not exist %s", sessionId)
@@ -149,11 +149,11 @@ func (n *NKodeAPI) ConfirmNKode(customerId entities.CustomerId, sessionId entiti
} else { } else {
err = n.repo.WriteNewUser(*user) err = n.repo.WriteNewUser(*user)
} }
n.signupSessionCache.Delete(userSession.Id.String()) n.signupSessionCache.Delete(userSession.ID.String())
return err return err
} }
func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId entities.CustomerId) (*entities.LoginInterface, error) { func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId entities.CustomerID) (*entities.LoginInterface, error) {
user, err := n.repo.GetUser(userEmail, customerId) user, err := n.repo.GetUser(userEmail, customerId)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -162,7 +162,7 @@ func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId en
log.Printf("user %s for customer %s dne", userEmail, customerId) log.Printf("user %s for customer %s dne", userEmail, customerId)
return nil, config.ErrUserForCustomerDNE return nil, config.ErrUserForCustomerDNE
} }
svgInterface, err := n.repo.GetSvgStringInterface(user.Interface.SvgId) svgInterface, err := n.repo.GetSvgStringInterface(user.Interface.SvgID)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -176,7 +176,7 @@ func (n *NKodeAPI) GetLoginInterface(userEmail entities.UserEmail, customerId en
return &resp, nil return &resp, nil
} }
func (n *NKodeAPI) Login(customerId entities.CustomerId, userEmail entities.UserEmail, keySelection entities.KeySelection) (*security.AuthenticationTokens, error) { func (n *NKodeAPI) Login(customerId entities.CustomerID, userEmail entities.UserEmail, keySelection entities.KeySelection) (*security.AuthenticationTokens, error) {
customer, err := n.repo.GetCustomer(customerId) customer, err := n.repo.GetCustomer(customerId)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -205,19 +205,19 @@ func (n *NKodeAPI) Login(customerId entities.CustomerId, userEmail entities.User
if err != nil { if err != nil {
return nil, err return nil, err
} }
if err = n.repo.UpdateUserRefreshToken(user.Id, jwtToken.RefreshToken); err != nil { if err = n.repo.UpdateUserRefreshToken(user.ID, jwtToken.RefreshToken); err != nil {
return nil, err return nil, err
} }
if err = user.Interface.LoginShuffle(); err != nil { if err = user.Interface.LoginShuffle(); err != nil {
return nil, err return nil, err
} }
if err = n.repo.UpdateUserInterface(user.Id, user.Interface); err != nil { if err = n.repo.UpdateUserInterface(user.ID, user.Interface); err != nil {
return nil, err return nil, err
} }
return &jwtToken, nil return &jwtToken, nil
} }
func (n *NKodeAPI) RenewAttributes(customerId entities.CustomerId) error { func (n *NKodeAPI) RenewAttributes(customerId entities.CustomerID) error {
return n.repo.Renew(customerId) return n.repo.Renew(customerId)
} }
@@ -225,7 +225,7 @@ func (n *NKodeAPI) RandomSvgInterface() ([]string, error) {
return n.repo.RandomSvgInterface(entities.KeypadMax) return n.repo.RandomSvgInterface(entities.KeypadMax)
} }
func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entities.CustomerId, refreshToken string) (string, error) { func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entities.CustomerID, refreshToken string) (string, error) {
user, err := n.repo.GetUser(userEmail, customerId) user, err := n.repo.GetUser(userEmail, customerId)
if err != nil { if err != nil {
return "", err return "", err
@@ -248,7 +248,7 @@ func (n *NKodeAPI) RefreshToken(userEmail entities.UserEmail, customerId entitie
return security.EncodeAndSignClaims(newAccessClaims) return security.EncodeAndSignClaims(newAccessClaims)
} }
func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities.CustomerId) error { func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities.CustomerID) error {
user, err := n.repo.GetUser(userEmail, customerId) user, err := n.repo.GetUser(userEmail, customerId)
if err != nil { if err != nil {
return fmt.Errorf("error getting user in rest nkode %v", err) return fmt.Errorf("error getting user in rest nkode %v", err)
@@ -278,7 +278,7 @@ func (n *NKodeAPI) ForgotNKode(userEmail entities.UserEmail, customerId entities
return nil return nil
} }
func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.CustomerId) error { func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.CustomerID) error {
user, err := n.repo.GetUser(userEmail, customerId) user, err := n.repo.GetUser(userEmail, customerId)
if err != nil { if err != nil {
return err return err
@@ -287,7 +287,7 @@ func (n *NKodeAPI) Signout(userEmail entities.UserEmail, customerId entities.Cus
log.Printf("user %s for customer %s dne", userEmail, customerId) log.Printf("user %s for customer %s dne", userEmail, customerId)
return config.ErrUserForCustomerDNE return config.ErrUserForCustomerDNE
} }
if err = n.repo.UpdateUserRefreshToken(user.Id, ""); err != nil { if err = n.repo.UpdateUserRefreshToken(user.ID, ""); err != nil {
return err return err
} }
return nil return nil

View File

@@ -52,8 +52,8 @@ func testNKodeAPI(t *testing.T, db repository.CustomerUserRepository) {
signupResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, false) signupResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, false)
assert.NoError(t, err) assert.NoError(t, err)
setInterface := signupResponse.UserIdxInterface setInterface := signupResponse.UserIdxInterface
sessionIdStr := signupResponse.SessionId sessionIdStr := signupResponse.SessionID
sessionId, err := entities.SessionIdFromString(sessionIdStr) sessionId, err := entities.SessionIDFromString(sessionIdStr)
assert.NoError(t, err) assert.NoError(t, err)
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys} keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
userPasscode := setInterface[:passcodeLen] userPasscode := setInterface[:passcodeLen]
@@ -89,8 +89,8 @@ func testNKodeAPI(t *testing.T, db repository.CustomerUserRepository) {
resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true) resetResponse, err := nkodeApi.GenerateSignupResetInterface(userEmail, *customerId, keypadSize, true)
assert.NoError(t, err) assert.NoError(t, err)
setInterface = resetResponse.UserIdxInterface setInterface = resetResponse.UserIdxInterface
sessionIdStr = resetResponse.SessionId sessionIdStr = resetResponse.SessionID
sessionId, err = entities.SessionIdFromString(sessionIdStr) sessionId, err = entities.SessionIDFromString(sessionIdStr)
assert.NoError(t, err) assert.NoError(t, err)
keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys} keypadSize = entities.KeypadDimension{AttrsPerKey: numbOfKeys, NumbOfKeys: numbOfKeys}
userPasscode = setInterface[:passcodeLen] userPasscode = setInterface[:passcodeLen]

View File

@@ -10,7 +10,7 @@ import (
) )
type Customer struct { type Customer struct {
Id CustomerId ID CustomerID
NKodePolicy NKodePolicy NKodePolicy NKodePolicy
Attributes CustomerAttributes Attributes CustomerAttributes
} }
@@ -21,7 +21,7 @@ func NewCustomer(nkodePolicy NKodePolicy) (*Customer, error) {
return nil, err return nil, err
} }
customer := Customer{ customer := Customer{
Id: CustomerId(uuid.New()), ID: CustomerID(uuid.New()),
NKodePolicy: nkodePolicy, NKodePolicy: nkodePolicy,
Attributes: *customerAttrs, Attributes: *customerAttrs,
} }
@@ -87,7 +87,7 @@ func (c *Customer) RenewKeys() ([]uint64, []uint64, error) {
func (c *Customer) ToSqlcCreateCustomerParams() sqlc.CreateCustomerParams { func (c *Customer) ToSqlcCreateCustomerParams() sqlc.CreateCustomerParams {
return sqlc.CreateCustomerParams{ return sqlc.CreateCustomerParams{
ID: uuid.UUID(c.Id).String(), ID: uuid.UUID(c.ID).String(),
MaxNkodeLen: int64(c.NKodePolicy.MaxNkodeLen), MaxNkodeLen: int64(c.NKodePolicy.MaxNkodeLen),
MinNkodeLen: int64(c.NKodePolicy.MinNkodeLen), MinNkodeLen: int64(c.NKodePolicy.MinNkodeLen),
DistinctSets: int64(c.NKodePolicy.DistinctSets), DistinctSets: int64(c.NKodePolicy.DistinctSets),

View File

@@ -21,7 +21,7 @@ func testCustomerValidKeyEntry(t *testing.T) {
nkodePolicy := NewDefaultNKodePolicy() nkodePolicy := NewDefaultNKodePolicy()
customer, err := NewCustomer(nkodePolicy) customer, err := NewCustomer(nkodePolicy)
assert.NoError(t, err) assert.NoError(t, err)
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
userInterface, err := NewUserInterface(&kp, mockSvgInterface) userInterface, err := NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
userEmail := "testing@example.com" userEmail := "testing@example.com"
@@ -45,7 +45,7 @@ func testCustomerIsValidNKode(t *testing.T) {
nkodePolicy := NewDefaultNKodePolicy() nkodePolicy := NewDefaultNKodePolicy()
customer, err := NewCustomer(nkodePolicy) customer, err := NewCustomer(nkodePolicy)
assert.NoError(t, err) assert.NoError(t, err)
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
userInterface, err := NewUserInterface(&kp, mockSvgInterface) userInterface, err := NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
userEmail := "testing123@example.com" userEmail := "testing123@example.com"

View File

@@ -9,30 +9,30 @@ import (
type KeySelection []int type KeySelection []int
type CustomerId uuid.UUID type CustomerID uuid.UUID
func (c *CustomerId) String() string { func (c *CustomerID) String() string {
id := uuid.UUID(*c) id := uuid.UUID(*c)
return id.String() return id.String()
} }
type SessionId uuid.UUID type SessionID uuid.UUID
type UserId uuid.UUID type UserID uuid.UUID
func (u *UserId) String() string { func (u *UserID) String() string {
id := uuid.UUID(*u) id := uuid.UUID(*u)
return id.String() return id.String()
} }
func UserIdFromString(userId string) UserId { func UserIDFromString(userID string) UserID {
id, err := uuid.Parse(userId) id, err := uuid.Parse(userID)
if err != nil { if err != nil {
fmt.Errorf("unable to parse user id %+v", err) fmt.Errorf("unable to parse user id %+v", err)
} }
return UserId(id) return UserID(id)
} }
func (s *SessionId) String() string { func (s *SessionID) String() string {
id := uuid.UUID(*s) id := uuid.UUID(*s)
return id.String() return id.String()
} }
@@ -49,15 +49,15 @@ func ParseEmail(email string) (UserEmail, error) {
} }
type IdxInterface []int type IdxInterface []int
type SvgIdInterface []int type SvgIDInterface []int
func SessionIdFromString(sessionId string) (SessionId, error) { func SessionIDFromString(sessionID string) (SessionID, error) {
id, err := uuid.Parse(sessionId) id, err := uuid.Parse(sessionID)
if err != nil { if err != nil {
return SessionId{}, err return SessionID{}, err
} }
return SessionId(id), nil return SessionID(id), nil
} }
type EncipheredNKode struct { type EncipheredNKode struct {
@@ -91,7 +91,7 @@ var SetColors = []RGBColor{
} }
type SignupResetInterface struct { type SignupResetInterface struct {
SessionId string `json:"session_id"` SessionID string `json:"session_id"`
UserIdxInterface IdxInterface `json:"user_interface"` UserIdxInterface IdxInterface `json:"user_interface"`
SvgInterface []string `json:"svg_interface"` SvgInterface []string `json:"svg_interface"`
Colors []RGBColor `json:"colors"` Colors []RGBColor `json:"colors"`

View File

@@ -8,8 +8,8 @@ import (
) )
type User struct { type User struct {
Id UserId ID UserID
CustomerId CustomerId CustomerID CustomerID
Email UserEmail Email UserEmail
EncipheredPasscode EncipheredNKode EncipheredPasscode EncipheredNKode
Kp KeypadDimension Kp KeypadDimension
@@ -130,13 +130,13 @@ func NewUser(customer Customer, userEmail string, passcodeIdx []int, ui UserInte
return nil, err return nil, err
} }
newUser := User{ newUser := User{
Id: UserId(uuid.New()), ID: UserID(uuid.New()),
Email: UserEmail(userEmail), Email: UserEmail(userEmail),
EncipheredPasscode: *encipheredNKode, EncipheredPasscode: *encipheredNKode,
CipherKeys: *newKeys, CipherKeys: *newKeys,
Interface: ui, Interface: ui,
Kp: kp, Kp: kp,
CustomerId: customer.Id, CustomerID: customer.ID,
} }
return &newUser, nil return &newUser, nil
} }

View File

@@ -9,15 +9,15 @@ import (
type UserInterface struct { type UserInterface struct {
IdxInterface IdxInterface IdxInterface IdxInterface
SvgId SvgIdInterface SvgID SvgIDInterface
Kp *KeypadDimension Kp *KeypadDimension
} }
func NewUserInterface(kp *KeypadDimension, svgId SvgIdInterface) (*UserInterface, error) { func NewUserInterface(kp *KeypadDimension, svgID SvgIDInterface) (*UserInterface, error) {
idxInterface := security.IdentityArray(kp.TotalAttrs()) idxInterface := security.IdentityArray(kp.TotalAttrs())
userInterface := UserInterface{ userInterface := UserInterface{
IdxInterface: idxInterface, IdxInterface: idxInterface,
SvgId: svgId, SvgID: svgID,
Kp: kp, Kp: kp,
} }
if err := userInterface.RandomShuffle(); err != nil { if err := userInterface.RandomShuffle(); err != nil {

View File

@@ -11,8 +11,8 @@ import (
) )
type UserSignSession struct { type UserSignSession struct {
Id SessionId ID SessionID
CustomerId CustomerId CustomerID CustomerID
LoginUserInterface UserInterface LoginUserInterface UserInterface
Kp KeypadDimension Kp KeypadDimension
SetIdxInterface IdxInterface SetIdxInterface IdxInterface
@@ -24,7 +24,7 @@ type UserSignSession struct {
Colors []RGBColor Colors []RGBColor
} }
func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId CustomerId, svgInterface SvgIdInterface, reset bool) (*UserSignSession, error) { func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId CustomerID, svgInterface SvgIDInterface, reset bool) (*UserSignSession, error) {
loginInterface, err := NewUserInterface(&kp, svgInterface) loginInterface, err := NewUserInterface(&kp, svgInterface)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -34,8 +34,8 @@ func NewSignupResetSession(userEmail UserEmail, kp KeypadDimension, customerId C
return nil, err return nil, err
} }
session := UserSignSession{ session := UserSignSession{
Id: SessionId(uuid.New()), ID: SessionID(uuid.New()),
CustomerId: customerId, CustomerID: customerId,
LoginUserInterface: *loginInterface, LoginUserInterface: *loginInterface,
SetIdxInterface: signupInterface.IdxInterface, SetIdxInterface: signupInterface.IdxInterface,
ConfirmIdxInterface: nil, ConfirmIdxInterface: nil,

View File

@@ -64,7 +64,7 @@ func TestUserInterface_RandomShuffle(t *testing.T) {
AttrsPerKey: 10, AttrsPerKey: 10,
NumbOfKeys: 8, NumbOfKeys: 8,
} }
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
userInterface, err := NewUserInterface(&kp, mockSvgInterface) userInterface, err := NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
userInterfaceCopy := make([]int, len(userInterface.IdxInterface)) userInterfaceCopy := make([]int, len(userInterface.IdxInterface))
@@ -87,7 +87,7 @@ func TestUserInterface_DisperseInterface(t *testing.T) {
for idx := 0; idx < 10000; idx++ { for idx := 0; idx < 10000; idx++ {
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10} kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
userInterface, err := NewUserInterface(&kp, mockSvgInterface) userInterface, err := NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
preDispersion, err := userInterface.AttributeAdjacencyGraph() preDispersion, err := userInterface.AttributeAdjacencyGraph()
@@ -106,7 +106,7 @@ func TestUserInterface_DisperseInterface(t *testing.T) {
func TestUserInterface_PartialInterfaceShuffle(t *testing.T) { func TestUserInterface_PartialInterfaceShuffle(t *testing.T) {
kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10} kp := KeypadDimension{AttrsPerKey: 7, NumbOfKeys: 10}
mockSvgInterface := make(SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(SvgIDInterface, kp.TotalAttrs())
userInterface, err := NewUserInterface(&kp, mockSvgInterface) userInterface, err := NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
preShuffle := userInterface.IdxInterface preShuffle := userInterface.IdxInterface

View File

@@ -19,9 +19,9 @@ type NkodeHandler struct {
} }
const ( const (
malformedCustomerId = "malformed customer id" malformedCustomerID = "malformed customer id"
malformedUserEmail = "malformed user email" malformedUserEmail = "malformed user email"
malformedSessionId = "malformed session id" malformedSessionID = "malformed session id"
invalidKeypadDimensions = "invalid keypad dimensions" invalidKeypadDimensions = "invalid keypad dimensions"
) )
@@ -78,9 +78,9 @@ func (h *NkodeHandler) SignupHandler(c *gin.Context) {
return return
} }
customerId, err := uuid.Parse(postBody.CustomerId) customerId, err := uuid.Parse(postBody.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
@@ -90,7 +90,7 @@ func (h *NkodeHandler) SignupHandler(c *gin.Context) {
return return
} }
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerId(customerId), kp, false) resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerID(customerId), kp, false)
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return
@@ -106,18 +106,18 @@ func (h *NkodeHandler) SetNKodeHandler(c *gin.Context) {
handleError(c, err) handleError(c, err)
return return
} }
customerId, err := uuid.Parse(postBody.CustomerId) customerId, err := uuid.Parse(postBody.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
sessionId, err := uuid.Parse(postBody.SessionId) sessionId, err := uuid.Parse(postBody.SessionID)
if err != nil { if err != nil {
c.String(400, malformedSessionId) c.String(400, malformedSessionID)
return return
} }
confirmInterface, err := h.API.SetNKode(entities.CustomerId(customerId), entities.SessionId(sessionId), postBody.KeySelection) confirmInterface, err := h.API.SetNKode(entities.CustomerID(customerId), entities.SessionID(sessionId), postBody.KeySelection)
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return
@@ -133,17 +133,17 @@ func (h *NkodeHandler) ConfirmNKodeHandler(c *gin.Context) {
handleError(c, err) handleError(c, err)
return return
} }
customerId, err := uuid.Parse(postBody.CustomerId) customerId, err := uuid.Parse(postBody.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
sessionId, err := uuid.Parse(postBody.SessionId) sessionId, err := uuid.Parse(postBody.SessionID)
if err != nil { if err != nil {
c.String(400, malformedSessionId) c.String(400, malformedSessionID)
return return
} }
if err := h.API.ConfirmNKode(entities.CustomerId(customerId), entities.SessionId(sessionId), postBody.KeySelection); err != nil { if err := h.API.ConfirmNKode(entities.CustomerID(customerId), entities.SessionID(sessionId), postBody.KeySelection); err != nil {
handleError(c, err) handleError(c, err)
return return
} }
@@ -158,9 +158,9 @@ func (h *NkodeHandler) GetLoginInterfaceHandler(c *gin.Context) {
return return
} }
customerId, err := uuid.Parse(loginInterfacePost.CustomerId) customerId, err := uuid.Parse(loginInterfacePost.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
@@ -169,7 +169,7 @@ func (h *NkodeHandler) GetLoginInterfaceHandler(c *gin.Context) {
c.String(400, malformedUserEmail) c.String(400, malformedUserEmail)
return return
} }
postBody, err := h.API.GetLoginInterface(userEmail, entities.CustomerId(customerId)) postBody, err := h.API.GetLoginInterface(userEmail, entities.CustomerID(customerId))
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return
@@ -185,9 +185,9 @@ func (h *NkodeHandler) LoginHandler(c *gin.Context) {
handleError(c, err) handleError(c, err)
return return
} }
customerId, err := uuid.Parse(loginPost.CustomerId) customerId, err := uuid.Parse(loginPost.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
@@ -196,7 +196,7 @@ func (h *NkodeHandler) LoginHandler(c *gin.Context) {
c.String(400, malformedUserEmail) c.String(400, malformedUserEmail)
return return
} }
jwtToken, err := h.API.Login(entities.CustomerId(customerId), userEmail, loginPost.KeySelection) jwtToken, err := h.API.Login(entities.CustomerID(customerId), userEmail, loginPost.KeySelection)
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return
@@ -213,13 +213,13 @@ func (h *NkodeHandler) RenewAttributesHandler(c *gin.Context) {
return return
} }
customerId, err := uuid.Parse(renewAttributesPost.CustomerId) customerId, err := uuid.Parse(renewAttributesPost.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
if err = h.API.RenewAttributes(entities.CustomerId(customerId)); err != nil { if err = h.API.RenewAttributes(entities.CustomerID(customerId)); err != nil {
handleError(c, err) handleError(c, err)
return return
} }
@@ -251,7 +251,7 @@ func (h *NkodeHandler) RefreshTokenHandler(c *gin.Context) {
} }
customerId, err := uuid.Parse(refreshClaims.Issuer) customerId, err := uuid.Parse(refreshClaims.Issuer)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
userEmail, err := entities.ParseEmail(refreshClaims.Subject) userEmail, err := entities.ParseEmail(refreshClaims.Subject)
@@ -259,7 +259,7 @@ func (h *NkodeHandler) RefreshTokenHandler(c *gin.Context) {
c.String(400, malformedUserEmail) c.String(400, malformedUserEmail)
return return
} }
accessToken, err := h.API.RefreshToken(userEmail, entities.CustomerId(customerId), refreshToken) accessToken, err := h.API.RefreshToken(userEmail, entities.CustomerID(customerId), refreshToken)
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return
@@ -274,9 +274,9 @@ func (h *NkodeHandler) ForgotNKodeHandler(c *gin.Context) {
handleError(c, err) handleError(c, err)
return return
} }
customerId, err := uuid.Parse(forgotNKodePost.CustomerId) customerId, err := uuid.Parse(forgotNKodePost.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
userEmail, err := entities.ParseEmail(forgotNKodePost.UserEmail) userEmail, err := entities.ParseEmail(forgotNKodePost.UserEmail)
@@ -285,7 +285,7 @@ func (h *NkodeHandler) ForgotNKodeHandler(c *gin.Context) {
return return
} }
if err := h.API.ForgotNKode(userEmail, entities.CustomerId(customerId)); err != nil { if err := h.API.ForgotNKode(userEmail, entities.CustomerID(customerId)); err != nil {
handleError(c, err) handleError(c, err)
return return
} }
@@ -306,7 +306,7 @@ func (h *NkodeHandler) SignoutHandler(c *gin.Context) {
} }
customerId, err := uuid.Parse(accessClaims.Issuer) customerId, err := uuid.Parse(accessClaims.Issuer)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
userEmail, err := entities.ParseEmail(accessClaims.Subject) userEmail, err := entities.ParseEmail(accessClaims.Subject)
@@ -314,7 +314,7 @@ func (h *NkodeHandler) SignoutHandler(c *gin.Context) {
c.String(400, malformedUserEmail) c.String(400, malformedUserEmail)
return return
} }
if err = h.API.Signout(userEmail, entities.CustomerId(customerId)); err != nil { if err = h.API.Signout(userEmail, entities.CustomerID(customerId)); err != nil {
handleError(c, err) handleError(c, err)
return return
} }
@@ -339,9 +339,9 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
handleError(c, err) handleError(c, err)
return return
} }
customerId, err := uuid.Parse(postBody.CustomerId) customerId, err := uuid.Parse(postBody.CustomerID)
if err != nil { if err != nil {
c.String(400, malformedCustomerId) c.String(400, malformedCustomerID)
return return
} }
userEmail, err := entities.ParseEmail(postBody.UserEmail) userEmail, err := entities.ParseEmail(postBody.UserEmail)
@@ -350,7 +350,7 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
return return
} }
if postBody.UserEmail != resetClaims.Subject || if postBody.UserEmail != resetClaims.Subject ||
postBody.CustomerId != resetClaims.Issuer { postBody.CustomerID != resetClaims.Issuer {
c.String(403, "forbidden") c.String(403, "forbidden")
return return
} }
@@ -364,7 +364,7 @@ func (h *NkodeHandler) ResetHandler(c *gin.Context) {
c.String(400, invalidKeypadDimensions) c.String(400, invalidKeypadDimensions)
return return
} }
resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerId(customerId), kp, true) resp, err := h.API.GenerateSignupResetInterface(userEmail, entities.CustomerID(customerId), kp, true)
if err != nil { if err != nil {
handleError(c, err) handleError(c, err)
return return

View File

@@ -49,7 +49,7 @@ func TestNKodeAPI(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// *** Set nKode *** // *** Set nKode ***
confirmInterface, status, err := tr.SetNKode(customerID, setKeySelection, resp.SessionId) confirmInterface, status, err := tr.SetNKode(customerID, setKeySelection, resp.SessionID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 200, status) assert.Equal(t, 200, status)
@@ -57,7 +57,7 @@ func TestNKodeAPI(t *testing.T) {
assert.NoError(t, err) assert.NoError(t, err)
// *** Confirm nKode *** // *** Confirm nKode ***
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resp.SessionId) status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resp.SessionID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 200, status) assert.Equal(t, 200, status)
@@ -101,16 +101,16 @@ func TestNKodeAPI(t *testing.T) {
resetResp, status, err := tr.Reset(customerID, attrPerKey, numKeys, userEmail, nkodeResetJwt) resetResp, status, err := tr.Reset(customerID, attrPerKey, numKeys, userEmail, nkodeResetJwt)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 200, status) assert.Equal(t, 200, status)
assert.NotEmpty(t, resetResp.SessionId) assert.NotEmpty(t, resetResp.SessionID)
userPasscode = resetResp.UserIdxInterface[:passcodeLen] userPasscode = resetResp.UserIdxInterface[:passcodeLen]
setKeySelection, err = entities.SelectKeyByAttrIdx(resetResp.UserIdxInterface, userPasscode, kpSet) setKeySelection, err = entities.SelectKeyByAttrIdx(resetResp.UserIdxInterface, userPasscode, kpSet)
assert.NoError(t, err) assert.NoError(t, err)
confirmInterface, status, err = tr.SetNKode(customerID, setKeySelection, resetResp.SessionId) confirmInterface, status, err = tr.SetNKode(customerID, setKeySelection, resetResp.SessionID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 200, status) assert.Equal(t, 200, status)
confirmKeySelection, err = entities.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet) confirmKeySelection, err = entities.SelectKeyByAttrIdx(confirmInterface, userPasscode, kpSet)
assert.NoError(t, err) assert.NoError(t, err)
status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resetResp.SessionId) status, err = tr.ConfirmNKode(customerID, confirmKeySelection, resetResp.SessionID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, 200, status) assert.Equal(t, 200, status)
loginInterface, status, err = tr.GetLoginInterface(userEmail, customerID) loginInterface, status, err = tr.GetLoginInterface(userEmail, customerID)
@@ -211,9 +211,9 @@ func (r *TestRouter) SetNKode(
sessionID string, sessionID string,
) ([]int, int, error) { ) ([]int, int, error) {
data := models.SetNKodePost{ data := models.SetNKodePost{
CustomerId: customerID, CustomerID: customerID,
KeySelection: selection, KeySelection: selection,
SessionId: sessionID, SessionID: sessionID,
} }
body, err := json.Marshal(data) body, err := json.Marshal(data)
@@ -240,9 +240,9 @@ func (r *TestRouter) ConfirmNKode(
sessionID string, sessionID string,
) (int, error) { ) (int, error) {
data := models.ConfirmNKodePost{ data := models.ConfirmNKodePost{
CustomerId: customerID, CustomerID: customerID,
KeySelection: selection, KeySelection: selection,
SessionId: sessionID, SessionID: sessionID,
} }
body, err := json.Marshal(data) body, err := json.Marshal(data)
if err != nil { if err != nil {
@@ -282,7 +282,7 @@ func (r *TestRouter) Login(
selection []int, selection []int,
) (security.AuthenticationTokens, int, error) { ) (security.AuthenticationTokens, int, error) {
data := models.LoginPost{ data := models.LoginPost{
CustomerId: customerID, CustomerID: customerID,
UserEmail: userEmail, UserEmail: userEmail,
KeySelection: selection, KeySelection: selection,
} }
@@ -305,7 +305,7 @@ func (r *TestRouter) RenewAttributes(
customerID string, customerID string,
) (int, error) { ) (int, error) {
data := models.RenewAttributesPost{ data := models.RenewAttributesPost{
CustomerId: customerID, CustomerID: customerID,
} }
body, err := json.Marshal(data) body, err := json.Marshal(data)
if err != nil { if err != nil {
@@ -323,7 +323,7 @@ func (r *TestRouter) ForgotNKode(
userEmail string, userEmail string,
) (int, error) { ) (int, error) {
data := models.ForgotNKodePost{ data := models.ForgotNKodePost{
CustomerId: customerID, CustomerID: customerID,
UserEmail: userEmail, UserEmail: userEmail,
} }
body, err := json.Marshal(data) body, err := json.Marshal(data)

View File

@@ -20,19 +20,19 @@ func NewForgotNKodeCache() ForgotNKodeCache {
return ForgotNKodeCache{forgotCache} return ForgotNKodeCache{forgotCache}
} }
func (f *ForgotNKodeCache) Set(userEmail entities.UserEmail, customerId entities.CustomerId) { func (f *ForgotNKodeCache) Set(userEmail entities.UserEmail, customerId entities.CustomerID) {
f.innerCache.Set(key(userEmail, customerId), true, forgotExpiration) f.innerCache.Set(key(userEmail, customerId), true, forgotExpiration)
} }
func (f *ForgotNKodeCache) Get(userEmail entities.UserEmail, customerId entities.CustomerId) bool { func (f *ForgotNKodeCache) Get(userEmail entities.UserEmail, customerId entities.CustomerID) bool {
_, found := f.innerCache.Get(key(userEmail, customerId)) _, found := f.innerCache.Get(key(userEmail, customerId))
return found return found
} }
func (f *ForgotNKodeCache) Delete(userEmail entities.UserEmail, customerId entities.CustomerId) { func (f *ForgotNKodeCache) Delete(userEmail entities.UserEmail, customerId entities.CustomerID) {
f.innerCache.Delete(key(userEmail, customerId)) f.innerCache.Delete(key(userEmail, customerId))
} }
func key(email entities.UserEmail, id entities.CustomerId) string { func key(email entities.UserEmail, id entities.CustomerID) string {
return string(email) + id.String() return string(email) + id.String()
} }

View File

@@ -16,44 +16,44 @@ type RefreshTokenResp struct {
} }
type SignupPostBody struct { type SignupPostBody struct {
CustomerId string `form:"customer_id"` CustomerID string `form:"customer_id"`
AttrsPerKey int `form:"attrs_per_key"` AttrsPerKey int `form:"attrs_per_key"`
NumbOfKeys int `form:"numb_of_keys"` NumbOfKeys int `form:"numb_of_keys"`
UserEmail string `form:"email"` UserEmail string `form:"email"`
} }
type SetNKodePost struct { type SetNKodePost struct {
CustomerId string `json:"customer_id" binding:"required"` CustomerID string `json:"customer_id" binding:"required"`
KeySelection []int `json:"key_selection" binding:"required"` KeySelection []int `json:"key_selection" binding:"required"`
SessionId string `json:"session_id" binding:"required"` SessionID string `json:"session_id" binding:"required"`
} }
type ConfirmNKodePost struct { type ConfirmNKodePost struct {
CustomerId string `json:"customer_id" binding:"required"` CustomerID string `json:"customer_id" binding:"required"`
KeySelection []int `json:"key_selection" binding:"required"` KeySelection []int `json:"key_selection" binding:"required"`
SessionId string `json:"session_id" binding:"required"` SessionID string `json:"session_id" binding:"required"`
} }
type LoginInterfacePost struct { type LoginInterfacePost struct {
UserEmail string `form:"email" binding:"required"` UserEmail string `form:"email" binding:"required"`
CustomerId string `form:"customer_id" binding:"required"` CustomerID string `form:"customer_id" binding:"required"`
} }
type LoginPost struct { type LoginPost struct {
CustomerId string `form:"customer_id" binding:"required"` CustomerID string `form:"customer_id" binding:"required"`
UserEmail string `form:"email" binding:"required"` UserEmail string `form:"email" binding:"required"`
KeySelection entities.KeySelection `form:"key_selection" binding:"required"` KeySelection entities.KeySelection `form:"key_selection" binding:"required"`
} }
type RenewAttributesPost struct { type RenewAttributesPost struct {
CustomerId string `form:"customer_id" binding:"required"` CustomerID string `form:"customer_id" binding:"required"`
} }
type ForgotNKodePost struct { type ForgotNKodePost struct {
UserEmail string `form:"email" binding:"required"` UserEmail string `form:"email" binding:"required"`
CustomerId string `form:"customer_id" binding:"required"` CustomerID string `form:"customer_id" binding:"required"`
} }
type CreateNewCustomerResp struct { type CreateNewCustomerResp struct {
CustomerId string `form:"customer_id" binding:"required"` CustomerID string `form:"customer_id" binding:"required"`
} }

View File

@@ -5,16 +5,16 @@ import (
) )
type CustomerUserRepository interface { type CustomerUserRepository interface {
GetCustomer(entities.CustomerId) (*entities.Customer, error) GetCustomer(entities.CustomerID) (*entities.Customer, error)
GetUser(entities.UserEmail, entities.CustomerId) (*entities.User, error) GetUser(entities.UserEmail, entities.CustomerID) (*entities.User, error)
CreateCustomer(entities.Customer) error CreateCustomer(entities.Customer) error
WriteNewUser(entities.User) error WriteNewUser(entities.User) error
UpdateUserNKode(entities.User) error UpdateUserNKode(entities.User) error
UpdateUserInterface(entities.UserId, entities.UserInterface) error UpdateUserInterface(entities.UserID, entities.UserInterface) error
UpdateUserRefreshToken(entities.UserId, string) error UpdateUserRefreshToken(entities.UserID, string) error
Renew(entities.CustomerId) error Renew(entities.CustomerID) error
RefreshUserPasscode(entities.User, []int, entities.CustomerAttributes) error RefreshUserPasscode(entities.User, []int, entities.CustomerAttributes) error
RandomSvgInterface(entities.KeypadDimension) ([]string, error) RandomSvgInterface(entities.KeypadDimension) ([]string, error)
RandomSvgIdxInterface(entities.KeypadDimension) (entities.SvgIdInterface, error) RandomSvgIdxInterface(entities.KeypadDimension) (entities.SvgIDInterface, error)
GetSvgStringInterface(entities.SvgIdInterface) ([]string, error) GetSvgStringInterface(entities.SvgIDInterface) ([]string, error)
} }

View File

@@ -70,11 +70,11 @@ func (d *SqliteNKodeRepo) WriteNewUser(u entities.User) error {
} }
// Map entities.User to CreateUserParams // Map entities.User to CreateUserParams
params := sqlc.CreateUserParams{ params := sqlc.CreateUserParams{
ID: uuid.UUID(u.Id).String(), ID: uuid.UUID(u.ID).String(),
Email: string(u.Email), Email: string(u.Email),
Renew: int64(renew), Renew: int64(renew),
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""}, RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
CustomerID: uuid.UUID(u.CustomerId).String(), CustomerID: uuid.UUID(u.CustomerID).String(),
Code: u.EncipheredPasscode.Code, Code: u.EncipheredPasscode.Code,
Mask: u.EncipheredPasscode.Mask, Mask: u.EncipheredPasscode.Mask,
AttributesPerKey: int64(u.Kp.AttrsPerKey), AttributesPerKey: int64(u.Kp.AttrsPerKey),
@@ -86,7 +86,7 @@ func (d *SqliteNKodeRepo) WriteNewUser(u entities.User) error {
Salt: u.CipherKeys.Salt, Salt: u.CipherKeys.Salt,
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen), MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface), IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgId), SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgID),
CreatedAt: sql.NullString{String: utils.TimeStamp(), Valid: true}, CreatedAt: sql.NullString{String: utils.TimeStamp(), Valid: true},
} }
return d.Queue.EnqueueWriteTx(queryFunc, params) return d.Queue.EnqueueWriteTx(queryFunc, params)
@@ -109,7 +109,7 @@ func (d *SqliteNKodeRepo) UpdateUserNKode(u entities.User) error {
Email: string(u.Email), Email: string(u.Email),
Renew: int64(renew), Renew: int64(renew),
RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""}, RefreshToken: sql.NullString{String: u.RefreshToken, Valid: u.RefreshToken != ""},
CustomerID: uuid.UUID(u.CustomerId).String(), CustomerID: uuid.UUID(u.CustomerID).String(),
Code: u.EncipheredPasscode.Code, Code: u.EncipheredPasscode.Code,
Mask: u.EncipheredPasscode.Mask, Mask: u.EncipheredPasscode.Mask,
AttributesPerKey: int64(u.Kp.AttrsPerKey), AttributesPerKey: int64(u.Kp.AttrsPerKey),
@@ -121,12 +121,12 @@ func (d *SqliteNKodeRepo) UpdateUserNKode(u entities.User) error {
Salt: u.CipherKeys.Salt, Salt: u.CipherKeys.Salt,
MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen), MaxNkodeLen: int64(u.CipherKeys.MaxNKodeLen),
IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface), IdxInterface: security.IntArrToByteArr(u.Interface.IdxInterface),
SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgId), SvgIDInterface: security.IntArrToByteArr(u.Interface.SvgID),
} }
return d.Queue.EnqueueWriteTx(queryFunc, params) return d.Queue.EnqueueWriteTx(queryFunc, params)
} }
func (d *SqliteNKodeRepo) UpdateUserInterface(id entities.UserId, ui entities.UserInterface) error { func (d *SqliteNKodeRepo) UpdateUserInterface(id entities.UserID, ui entities.UserInterface) error {
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error { queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
params, ok := args.(sqlc.UpdateUserInterfaceParams) params, ok := args.(sqlc.UpdateUserInterfaceParams)
if !ok { if !ok {
@@ -143,7 +143,7 @@ func (d *SqliteNKodeRepo) UpdateUserInterface(id entities.UserId, ui entities.Us
return d.Queue.EnqueueWriteTx(queryFunc, params) return d.Queue.EnqueueWriteTx(queryFunc, params)
} }
func (d *SqliteNKodeRepo) UpdateUserRefreshToken(id entities.UserId, refreshToken string) error { func (d *SqliteNKodeRepo) UpdateUserRefreshToken(id entities.UserID, refreshToken string) error {
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error { queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
params, ok := args.(sqlc.UpdateUserRefreshTokenParams) params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
if !ok { if !ok {
@@ -172,7 +172,7 @@ func (d *SqliteNKodeRepo) RenewCustomer(renewParams sqlc.RenewCustomerParams) er
return d.Queue.EnqueueWriteTx(queryFunc, renewParams) return d.Queue.EnqueueWriteTx(queryFunc, renewParams)
} }
func (d *SqliteNKodeRepo) Renew(id entities.CustomerId) error { func (d *SqliteNKodeRepo) Renew(id entities.CustomerID) error {
setXor, attrXor, err := d.renewCustomer(id) setXor, attrXor, err := d.renewCustomer(id)
if err != nil { if err != nil {
return err return err
@@ -192,8 +192,8 @@ func (d *SqliteNKodeRepo) Renew(id entities.CustomerId) error {
for _, row := range userRenewRows { for _, row := range userRenewRows {
user := entities.User{ user := entities.User{
Id: entities.UserIdFromString(row.ID), ID: entities.UserIDFromString(row.ID),
CustomerId: entities.CustomerId{}, CustomerID: entities.CustomerID{},
Email: "", Email: "",
EncipheredPasscode: entities.EncipheredNKode{}, EncipheredPasscode: entities.EncipheredNKode{},
Kp: entities.KeypadDimension{ Kp: entities.KeypadDimension{
@@ -215,7 +215,7 @@ func (d *SqliteNKodeRepo) Renew(id entities.CustomerId) error {
AlphaKey: security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), AlphaKey: security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey),
SetKey: security.Uint64ArrToByteArr(user.CipherKeys.SetKey), SetKey: security.Uint64ArrToByteArr(user.CipherKeys.SetKey),
Renew: 1, Renew: 1,
ID: uuid.UUID(user.Id).String(), ID: uuid.UUID(user.ID).String(),
} }
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil { if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
return err return err
@@ -224,7 +224,7 @@ func (d *SqliteNKodeRepo) Renew(id entities.CustomerId) error {
return nil return nil
} }
func (d *SqliteNKodeRepo) renewCustomer(id entities.CustomerId) ([]uint64, []uint64, error) { func (d *SqliteNKodeRepo) renewCustomer(id entities.CustomerID) ([]uint64, []uint64, error) {
customer, err := d.GetCustomer(id) customer, err := d.GetCustomer(id)
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
@@ -244,7 +244,7 @@ func (d *SqliteNKodeRepo) renewCustomer(id entities.CustomerId) ([]uint64, []uin
params := sqlc.RenewCustomerParams{ params := sqlc.RenewCustomerParams{
AttributeValues: security.Uint64ArrToByteArr(customer.Attributes.AttrVals), AttributeValues: security.Uint64ArrToByteArr(customer.Attributes.AttrVals),
SetValues: security.Uint64ArrToByteArr(customer.Attributes.SetVals), SetValues: security.Uint64ArrToByteArr(customer.Attributes.SetVals),
ID: uuid.UUID(customer.Id).String(), ID: uuid.UUID(customer.ID).String(),
} }
if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil { if err = d.Queue.EnqueueWriteTx(queryFunc, params); err != nil {
@@ -273,7 +273,7 @@ func (d *SqliteNKodeRepo) RefreshUserPasscode(user entities.User, passcodeIdx []
PassKey: security.Uint64ArrToByteArr(user.CipherKeys.PassKey), PassKey: security.Uint64ArrToByteArr(user.CipherKeys.PassKey),
MaskKey: security.Uint64ArrToByteArr(user.CipherKeys.MaskKey), MaskKey: security.Uint64ArrToByteArr(user.CipherKeys.MaskKey),
Salt: user.CipherKeys.Salt, Salt: user.CipherKeys.Salt,
ID: uuid.UUID(user.Id).String(), ID: uuid.UUID(user.ID).String(),
} }
return d.Queue.EnqueueWriteTx(queryFunc, params) return d.Queue.EnqueueWriteTx(queryFunc, params)
} }
@@ -289,14 +289,14 @@ func (d *SqliteNKodeRepo) AddSvg(svg string) error {
return d.Queue.EnqueueWriteTx(queryFunc, svg) return d.Queue.EnqueueWriteTx(queryFunc, svg)
} }
func (d *SqliteNKodeRepo) GetCustomer(id entities.CustomerId) (*entities.Customer, error) { func (d *SqliteNKodeRepo) GetCustomer(id entities.CustomerID) (*entities.Customer, error) {
customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String()) customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String())
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &entities.Customer{ return &entities.Customer{
Id: id, ID: id,
NKodePolicy: entities.NKodePolicy{ NKodePolicy: entities.NKodePolicy{
MaxNkodeLen: int(customer.MaxNkodeLen), MaxNkodeLen: int(customer.MaxNkodeLen),
MinNkodeLen: int(customer.MinNkodeLen), MinNkodeLen: int(customer.MinNkodeLen),
@@ -309,10 +309,10 @@ func (d *SqliteNKodeRepo) GetCustomer(id entities.CustomerId) (*entities.Custome
}, nil }, nil
} }
func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerId entities.CustomerId) (*entities.User, error) { func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerID entities.CustomerID) (*entities.User, error) {
userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{ userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{
Email: string(email), Email: string(email),
CustomerID: uuid.UUID(customerId).String(), CustomerID: uuid.UUID(customerID).String(),
}) })
if err != nil { if err != nil {
if errors.Is(err, sql.ErrNoRows) { if errors.Is(err, sql.ErrNoRows) {
@@ -331,8 +331,8 @@ func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerId entities.
renew = true renew = true
} }
user := entities.User{ user := entities.User{
Id: entities.UserIdFromString(userRow.ID), ID: entities.UserIDFromString(userRow.ID),
CustomerId: customerId, CustomerID: customerID,
Email: email, Email: email,
EncipheredPasscode: entities.EncipheredNKode{ EncipheredPasscode: entities.EncipheredNKode{
Code: userRow.Code, Code: userRow.Code,
@@ -350,7 +350,7 @@ func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerId entities.
}, },
Interface: entities.UserInterface{ Interface: entities.UserInterface{
IdxInterface: security.ByteArrToIntArr(userRow.IdxInterface), IdxInterface: security.ByteArrToIntArr(userRow.IdxInterface),
SvgId: security.ByteArrToIntArr(userRow.SvgIDInterface), SvgID: security.ByteArrToIntArr(userRow.SvgIDInterface),
Kp: &kp, Kp: &kp,
}, },
Renew: renew, Renew: renew,
@@ -360,24 +360,24 @@ func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerId entities.
} }
func (d *SqliteNKodeRepo) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) { func (d *SqliteNKodeRepo) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
ids, err := d.getRandomIds(kp.TotalAttrs()) ids, err := d.getRandomIDs(kp.TotalAttrs())
if err != nil { if err != nil {
return nil, err return nil, err
} }
return d.getSvgsById(ids) return d.getSvgsByID(ids)
} }
func (d *SqliteNKodeRepo) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIdInterface, error) { func (d *SqliteNKodeRepo) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIDInterface, error) {
return d.getRandomIds(kp.TotalAttrs()) return d.getRandomIDs(kp.TotalAttrs())
} }
func (d *SqliteNKodeRepo) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) { func (d *SqliteNKodeRepo) GetSvgStringInterface(idxs entities.SvgIDInterface) ([]string, error) {
return d.getSvgsById(idxs) return d.getSvgsByID(idxs)
} }
// Is this even useful? // Is this even useful?
func (d *SqliteNKodeRepo) AddUserPermission(userEmail entities.UserEmail, customerId entities.CustomerId, permission entities.UserPermission) error { func (d *SqliteNKodeRepo) AddUserPermission(userEmail entities.UserEmail, customerID entities.CustomerID, permission entities.UserPermission) error {
user, err := d.GetUser(userEmail, customerId) user, err := d.GetUser(userEmail, customerID)
if err != nil { if err != nil {
return err return err
} }
@@ -389,16 +389,16 @@ func (d *SqliteNKodeRepo) AddUserPermission(userEmail entities.UserEmail, custom
return q.AddUserPermission(ctx, params) return q.AddUserPermission(ctx, params)
} }
params := sqlc.AddUserPermissionParams{ params := sqlc.AddUserPermissionParams{
UserID: user.Id.String(), UserID: user.ID.String(),
Permission: permission.String(), Permission: permission.String(),
} }
return d.Queue.EnqueueWriteTx(queryFunc, params) return d.Queue.EnqueueWriteTx(queryFunc, params)
} }
func (d *SqliteNKodeRepo) getSvgsById(ids []int) ([]string, error) { func (d *SqliteNKodeRepo) getSvgsByID(ids []int) ([]string, error) {
svgs := make([]string, len(ids)) svgs := make([]string, len(ids))
for idx, id := range ids { for idx, id := range ids {
svg, err := d.Queue.Queries.GetSvgId(d.ctx, int64(id)) svg, err := d.Queue.Queries.GetSvgID(d.ctx, int64(id))
if err != nil { if err != nil {
return nil, err return nil, err
} }
@@ -407,7 +407,7 @@ func (d *SqliteNKodeRepo) getSvgsById(ids []int) ([]string, error) {
return svgs, nil return svgs, nil
} }
func (d *SqliteNKodeRepo) getRandomIds(count int) ([]int, error) { func (d *SqliteNKodeRepo) getRandomIDs(count int) ([]int, error) {
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx) totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
if err != nil { if err != nil {
log.Print(err) log.Print(err)

View File

@@ -28,24 +28,24 @@ func testSignupLoginRenew(t *testing.T, db CustomerUserRepository) {
assert.NoError(t, err) assert.NoError(t, err)
err = db.CreateCustomer(*customerOrig) err = db.CreateCustomer(*customerOrig)
assert.NoError(t, err) assert.NoError(t, err)
customer, err := db.GetCustomer(customerOrig.Id) customer, err := db.GetCustomer(customerOrig.ID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, customerOrig, customer) assert.Equal(t, customerOrig, customer)
username := "test_user@example.com" username := "test_user@example.com"
kp := entities.KeypadDefault kp := entities.KeypadDefault
passcodeIdx := []int{0, 1, 2, 3} passcodeIdx := []int{0, 1, 2, 3}
mockSvgInterface := make(entities.SvgIdInterface, kp.TotalAttrs()) mockSvgInterface := make(entities.SvgIDInterface, kp.TotalAttrs())
ui, err := entities.NewUserInterface(&kp, mockSvgInterface) ui, err := entities.NewUserInterface(&kp, mockSvgInterface)
assert.NoError(t, err) assert.NoError(t, err)
userOrig, err := entities.NewUser(*customer, username, passcodeIdx, *ui, kp) userOrig, err := entities.NewUser(*customer, username, passcodeIdx, *ui, kp)
assert.NoError(t, err) assert.NoError(t, err)
err = db.WriteNewUser(*userOrig) err = db.WriteNewUser(*userOrig)
assert.NoError(t, err) assert.NoError(t, err)
user, err := db.GetUser(entities.UserEmail(username), customer.Id) user, err := db.GetUser(entities.UserEmail(username), customer.ID)
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, userOrig, user) assert.Equal(t, userOrig, user)
err = db.Renew(customer.Id) err = db.Renew(customer.ID)
assert.NoError(t, err) assert.NoError(t, err)
} }

View File

@@ -489,14 +489,14 @@ func (q *Queries) GetSvgCount(ctx context.Context) (int64, error) {
return count, err return count, err
} }
const getSvgId = `-- name: GetSvgId :one const getSvgID = `-- name: GetSvgID :one
SELECT svg SELECT svg
FROM svg_icon FROM svg_icon
WHERE id = ? WHERE id = ?
` `
func (q *Queries) GetSvgId(ctx context.Context, id int64) (string, error) { func (q *Queries) GetSvgID(ctx context.Context, id int64) (string, error) {
row := q.db.QueryRowContext(ctx, getSvgId, id) row := q.db.QueryRowContext(ctx, getSvgID, id)
var svg string var svg string
err := row.Scan(&svg) err := row.Scan(&svg)
return svg, err return svg, err

View File

@@ -130,7 +130,7 @@ SELECT
FROM user FROM user
WHERE user.email = ? AND user.customer_id = ?; WHERE user.email = ? AND user.customer_id = ?;
-- name: GetSvgId :one -- name: GetSvgID :one
SELECT svg SELECT svg
FROM svg_icon FROM svg_icon
WHERE id = ?; WHERE id = ?;