cleanup code
This commit is contained in:
@@ -42,7 +42,8 @@ func testNKodeAPI(t *testing.T, db repository.CustomerUserRepository) {
|
|||||||
attrsPerKey := 5
|
attrsPerKey := 5
|
||||||
numbOfKeys := 4
|
numbOfKeys := 4
|
||||||
for idx := 0; idx < 1; idx++ {
|
for idx := 0; idx < 1; idx++ {
|
||||||
userEmail := entities.UserEmail("test_username" + security.GenerateRandomString(12) + "@example.com")
|
rand,
|
||||||
|
userEmail := entities.UserEmail("test_username" + security.GenerateNonSecureRandomString(12) + "@example.com")
|
||||||
passcodeLen := 4
|
passcodeLen := 4
|
||||||
nkodePolicy := entities.NewDefaultNKodePolicy()
|
nkodePolicy := entities.NewDefaultNKodePolicy()
|
||||||
keypadSize := entities.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
keypadSize := entities.KeypadDimension{AttrsPerKey: attrsPerKey, NumbOfKeys: numbOfKeys}
|
||||||
|
|||||||
@@ -245,6 +245,10 @@ func (h *NkodeHandler) RefreshTokenHandler(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
refreshClaims, err := security.ParseRegisteredClaimToken(refreshToken)
|
refreshClaims, err := security.ParseRegisteredClaimToken(refreshToken)
|
||||||
|
if err != nil {
|
||||||
|
c.String(500, "Internal Error")
|
||||||
|
return
|
||||||
|
}
|
||||||
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)
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ func TestNKodeAPI(t *testing.T) {
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
attrPerKey := 9
|
attrPerKey := 9
|
||||||
numKeys := 6
|
numKeys := 6
|
||||||
userEmail := "test_username" + security.GenerateRandomString(12) + "@example.com"
|
userEmail := "test_username" + security.GenerateNonSecureRandomString(12) + "@example.com"
|
||||||
|
|
||||||
// *** Signup ***
|
// *** Signup ***
|
||||||
resp, status, err := tr.Signup(customerID, attrPerKey, numKeys, userEmail)
|
resp, status, err := tr.Signup(customerID, attrPerKey, numKeys, userEmail)
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/config"
|
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
"git.infra.nkode.tech/dkelly/nkode-core/entities"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/security"
|
"git.infra.nkode.tech/dkelly/nkode-core/security"
|
||||||
"git.infra.nkode.tech/dkelly/nkode-core/sqlc"
|
"git.infra.nkode.tech/dkelly/nkode-core/sqlc"
|
||||||
@@ -409,39 +408,12 @@ func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
|
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
|
||||||
tx, err := d.Queue.Db.Begin()
|
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
return nil, config.ErrSqliteTx
|
|
||||||
}
|
|
||||||
rows, err := tx.Query("SELECT COUNT(*) as count FROM svg_icon;")
|
|
||||||
if err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, config.ErrSqliteTx
|
|
||||||
}
|
|
||||||
var tableLen int
|
|
||||||
if !rows.Next() {
|
|
||||||
return nil, config.ErrEmptySvgTable
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = rows.Scan(&tableLen); err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, config.ErrSqliteTx
|
|
||||||
}
|
|
||||||
perm, err := security.RandomPermutation(tableLen)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
perm, err := security.RandomPermutation(int(totalRows))
|
||||||
for idx := range perm {
|
|
||||||
perm[idx] += 1
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = tx.Commit(); err != nil {
|
|
||||||
log.Print(err)
|
|
||||||
return nil, config.ErrSqliteTx
|
|
||||||
}
|
|
||||||
|
|
||||||
return perm[:count], nil
|
return perm[:count], nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,8 +268,7 @@ func Choice[T any](items []T) T {
|
|||||||
return items[r.Intn(len(items))]
|
return items[r.Intn(len(items))]
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenerateRandomString creates a random string of a specified length.
|
func GenerateNonSecureRandomString(length int) string {
|
||||||
func GenerateRandomString(length int) string {
|
|
||||||
charset := []rune("abcdefghijklmnopqrstuvwxyz0123456789")
|
charset := []rune("abcdefghijklmnopqrstuvwxyz0123456789")
|
||||||
b := make([]rune, length)
|
b := make([]rune, length)
|
||||||
for i := range b {
|
for i := range b {
|
||||||
|
|||||||
Reference in New Issue
Block a user