(t *testing.T)
| 887 | } |
| 888 | |
| 889 | func 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 | |
| 921 | func TestSecurityJWTBinds(t *testing.T) { |
| 922 | sceneraios := []struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…