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