From 0ff5606d802ea03b278cc81ae14c0a53de7f6e4d Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 6 Nov 2022 15:28:41 +0200 Subject: [PATCH] renamed PseudoRandom to Pseudorandom --- apis/settings.go | 2 +- daos/record.go | 4 ++-- daos/record_expand.go | 2 +- forms/collection_upsert_test.go | 2 +- models/schema/schema.go | 2 +- resolvers/record_field_resolver.go | 4 ++-- tools/search/filter.go | 6 +++--- tools/security/random.go | 8 ++++---- tools/security/random_test.go | 8 ++++---- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/apis/settings.go b/apis/settings.go index 2ee1e71d..b7414faa 100644 --- a/apis/settings.go +++ b/apis/settings.go @@ -91,7 +91,7 @@ func (api *settingsApi) testS3(c echo.Context) error { } defer fs.Close() - testFileKey := "pb_test_" + security.PseudoRandomString(5) + "/test.txt" + testFileKey := "pb_test_" + security.PseudorandomString(5) + "/test.txt" if err := fs.Upload([]byte("test"), testFileKey); err != nil { return NewBadRequestError("Failed to upload a test file. Raw error: \n"+err.Error(), nil) diff --git a/daos/record.go b/daos/record.go index 5ac6d9cd..bb51bb54 100644 --- a/daos/record.go +++ b/daos/record.go @@ -530,7 +530,7 @@ func (dao *Dao) SyncRecordTableSchema(newCollection *models.Collection, oldColle // This way we are always doing 1 more rename operation but it provides better dev experience. if oldField == nil { - tempName := field.Name + security.PseudoRandomString(5) + tempName := field.Name + security.PseudorandomString(5) toRename[tempName] = field.Name // add @@ -539,7 +539,7 @@ func (dao *Dao) SyncRecordTableSchema(newCollection *models.Collection, oldColle return err } } else if oldField.Name != field.Name { - tempName := field.Name + security.PseudoRandomString(5) + tempName := field.Name + security.PseudorandomString(5) toRename[tempName] = field.Name // rename diff --git a/daos/record_expand.go b/daos/record_expand.go index 0bfc2078..4e081d07 100644 --- a/daos/record_expand.go +++ b/daos/record_expand.go @@ -129,7 +129,7 @@ func (dao *Dao) expandRecords(records []*models.Record, expandPath string, fetch } // indirect relation relField = &schema.SchemaField{ - Id: "indirect_" + security.PseudoRandomString(5), + Id: "indirect_" + security.PseudorandomString(5), Type: schema.FieldTypeRelation, Name: parts[0], Options: relFieldOptions, diff --git a/forms/collection_upsert_test.go b/forms/collection_upsert_test.go index 784adede..9a487ace 100644 --- a/forms/collection_upsert_test.go +++ b/forms/collection_upsert_test.go @@ -494,7 +494,7 @@ func TestCollectionUpsertWithCustomId(t *testing.T) { newCollection := func() *models.Collection { return &models.Collection{ - Name: "c_" + security.PseudoRandomString(4), + Name: "c_" + security.PseudorandomString(4), Schema: existingCollection.Schema, } } diff --git a/models/schema/schema.go b/models/schema/schema.go index 278ddff3..d1f54ccf 100644 --- a/models/schema/schema.go +++ b/models/schema/schema.go @@ -113,7 +113,7 @@ func (s *Schema) RemoveField(id string) { func (s *Schema) AddField(newField *SchemaField) { if newField.Id == "" { // set default id - newField.Id = strings.ToLower(security.PseudoRandomString(8)) + newField.Id = strings.ToLower(security.PseudorandomString(8)) } for i, field := range s.fields { diff --git a/resolvers/record_field_resolver.go b/resolvers/record_field_resolver.go index 52319de6..1bc15880 100644 --- a/resolvers/record_field_resolver.go +++ b/resolvers/record_field_resolver.go @@ -193,7 +193,7 @@ func (r *RecordFieldResolver) Resolve(fieldName string) (resultName string, plac currentCollectionName = collection.Name currentTableAlias = "__auth_" + inflector.Columnify(currentCollectionName) - authIdParamKey := "auth" + security.PseudoRandomString(5) + authIdParamKey := "auth" + security.PseudorandomString(5) authIdParams := dbx.Params{authIdParamKey: authRecordId} // --- @@ -354,7 +354,7 @@ func (r *RecordFieldResolver) resolveStaticRequestField(path ...string) (resultN resultVal = val } - placeholder := "f" + security.PseudoRandomString(5) + placeholder := "f" + security.PseudorandomString(5) name := fmt.Sprintf("{:%s}", placeholder) params := dbx.Params{placeholder: resultVal} diff --git a/tools/search/filter.go b/tools/search/filter.go index 8834c9a7..516a7994 100644 --- a/tools/search/filter.go +++ b/tools/search/filter.go @@ -133,7 +133,7 @@ func (f FilterData) resolveToken(token fexpr.Token, fieldResolver FieldResolver) // current datetime constant // --- if token.Literal == "@now" { - placeholder := "t" + security.PseudoRandomString(8) + placeholder := "t" + security.PseudorandomString(8) name := fmt.Sprintf("{:%s}", placeholder) params := dbx.Params{placeholder: types.NowDateTime().String()} @@ -161,13 +161,13 @@ func (f FilterData) resolveToken(token fexpr.Token, fieldResolver FieldResolver) return name, params, err case fexpr.TokenText: - placeholder := "t" + security.PseudoRandomString(8) + placeholder := "t" + security.PseudorandomString(8) name := fmt.Sprintf("{:%s}", placeholder) params := dbx.Params{placeholder: token.Literal} return name, params, nil case fexpr.TokenNumber: - placeholder := "t" + security.PseudoRandomString(8) + placeholder := "t" + security.PseudorandomString(8) name := fmt.Sprintf("{:%s}", placeholder) params := dbx.Params{placeholder: cast.ToFloat64(token.Literal)} diff --git a/tools/security/random.go b/tools/security/random.go index 6efb7d1a..e656655a 100644 --- a/tools/security/random.go +++ b/tools/security/random.go @@ -38,16 +38,16 @@ func RandomStringWithAlphabet(length int, alphabet string) string { // // The generated string matches [A-Za-z0-9]+ and it's transparent to URL-encoding. // -// For a cryptographically random string (but a little bit slower) use PseudoRandomString instead. -func PseudoRandomString(length int) string { +// For a cryptographically random string (but a little bit slower) use PseudorandomString instead. +func PseudorandomString(length int) string { return RandomStringWithAlphabet(length, defaultRandomAlphabet) } -// PseudoRandomStringWithAlphabet generates a pseudorandom string +// PseudorandomStringWithAlphabet generates a pseudorandom string // with the specified length and characters set. // // For a cryptographically random (but a little bit slower) use RandomStringWithAlphabet instead. -func PseudoRandomStringWithAlphabet(length int, alphabet string) string { +func PseudorandomStringWithAlphabet(length int, alphabet string) string { b := make([]byte, length) max := len(alphabet) diff --git a/tools/security/random_test.go b/tools/security/random_test.go index 85eb69ed..2130903e 100644 --- a/tools/security/random_test.go +++ b/tools/security/random_test.go @@ -15,12 +15,12 @@ func TestRandomStringWithAlphabet(t *testing.T) { testRandomStringWithAlphabet(t, security.RandomStringWithAlphabet) } -func TestPseudoRandomString(t *testing.T) { - testRandomString(t, security.PseudoRandomString) +func TestPseudorandomString(t *testing.T) { + testRandomString(t, security.PseudorandomString) } -func TestPseudoRandomStringWithAlphabet(t *testing.T) { - testRandomStringWithAlphabet(t, security.PseudoRandomStringWithAlphabet) +func TestPseudorandomStringWithAlphabet(t *testing.T) { + testRandomStringWithAlphabet(t, security.PseudorandomStringWithAlphabet) } // -------------------------------------------------------------------