MCPcopy
hub / github.com/pocketbase/pocketbase / TestSecurityRandomStringBinds

Function TestSecurityRandomStringBinds

plugins/jsvm/binds_test.go:889–919  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

887}
888
889func TestSecurityRandomStringBinds(t *testing.T) {
890 vm := goja.New()
891 BindCore(vm)
892 BindSecurity(vm)
893
894 sceneraios := []struct {
895 js string
896 length int
897 }{
898 {`$security.randomString(6)`, 6},
899 {`$security.randomStringWithAlphabet(7, "abc")`, 7},
900 {`$security.pseudorandomString(8)`, 8},
901 {`$security.pseudorandomStringWithAlphabet(9, "abc")`, 9},
902 {`$security.randomStringByRegex("abc")`, 3},
903 }
904
905 for _, s := range sceneraios {
906 t.Run(s.js, func(t *testing.T) {
907 result, err := vm.RunString(s.js)
908 if err != nil {
909 t.Fatalf("Failed to execute js script, got %v", err)
910 }
911
912 v, _ := result.Export().(string)
913
914 if len(v) != s.length {
915 t.Fatalf("Expected %d length string, \ngot \n%v", s.length, v)
916 }
917 })
918 }
919}
920
921func TestSecurityJWTBinds(t *testing.T) {
922 sceneraios := []struct {

Callers

nothing calls this directly

Calls 3

BindCoreFunction · 0.85
BindSecurityFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…