1
1
import assert from "node:assert/strict" ;
2
2
import test from "node:test" ;
3
+ import { initializeWasm } from "../index.js" ;
4
+
5
+ const wasm = await initializeWasm ( {
6
+ "arcjet:js-req/bot-identifier" : {
7
+ detect ( ) {
8
+ return [ ] ;
9
+ } ,
10
+ } ,
11
+ "arcjet:js-req/email-validator-overrides" : {
12
+ hasGravatar ( ) {
13
+ return "unknown" ;
14
+ } ,
15
+ hasMxRecords ( ) {
16
+ return "unknown" ;
17
+ } ,
18
+ isDisposableEmail ( ) {
19
+ return "unknown" ;
20
+ } ,
21
+ isFreeEmail ( ) {
22
+ return "unknown" ;
23
+ } ,
24
+ } ,
25
+ "arcjet:js-req/filter-overrides" : {
26
+ ipLookup ( ) {
27
+ return undefined ;
28
+ } ,
29
+ } ,
30
+ "arcjet:js-req/sensitive-information-identifier" : {
31
+ detect ( ) {
32
+ return [ ] ;
33
+ } ,
34
+ } ,
35
+ "arcjet:js-req/verify-bot" : {
36
+ verify ( ) {
37
+ return "unverifiable" ;
38
+ } ,
39
+ } ,
40
+ } ) ;
41
+ assert . ok ( wasm ) ;
3
42
4
43
test ( "@arcjet/analyze-wasm" , async function ( t ) {
5
44
await t . test ( "should expose the public api" , async function ( ) {
@@ -8,3 +47,77 @@ test("@arcjet/analyze-wasm", async function (t) {
8
47
] ) ;
9
48
} ) ;
10
49
} ) ;
50
+
51
+ test ( "`detectSensitiveInfo`" , async function ( t ) {
52
+ await t . test ( "should detect a card number" , async function ( ) {
53
+ assert . deepEqual (
54
+ wasm . detectSensitiveInfo ( "a 4242424242424242 b" , {
55
+ entities : { tag : "allow" , val : [ ] } ,
56
+ skipCustomDetect : false ,
57
+ } ) ,
58
+ {
59
+ allowed : [ ] ,
60
+ denied : [
61
+ { end : 18 , identifiedType : { tag : "credit-card-number" } , start : 2 } ,
62
+ ] ,
63
+ } ,
64
+ ) ;
65
+ } ) ;
66
+
67
+ await t . test ( "should detect a card number if in `allow`" , async function ( ) {
68
+ assert . deepEqual (
69
+ wasm . detectSensitiveInfo ( "a 4242424242424242 b" , {
70
+ entities : { tag : "allow" , val : [ { tag : "credit-card-number" } ] } ,
71
+ skipCustomDetect : false ,
72
+ } ) ,
73
+ {
74
+ allowed : [
75
+ {
76
+ end : 18 ,
77
+ identifiedType : { tag : "credit-card-number" } ,
78
+ start : 2 ,
79
+ } ,
80
+ ] ,
81
+ denied : [ ] ,
82
+ } ,
83
+ ) ;
84
+ } ) ;
85
+
86
+ await t . test ( "should detect a card number w/ dashes" , async function ( ) {
87
+ assert . deepEqual (
88
+ wasm . detectSensitiveInfo ( "a 4242-4242-4242-4242 b" , {
89
+ entities : { tag : "allow" , val : [ { tag : "credit-card-number" } ] } ,
90
+ skipCustomDetect : false ,
91
+ } ) ,
92
+ {
93
+ allowed : [
94
+ {
95
+ end : 21 ,
96
+ identifiedType : { tag : "credit-card-number" } ,
97
+ start : 2 ,
98
+ } ,
99
+ ] ,
100
+ denied : [ ] ,
101
+ } ,
102
+ ) ;
103
+ } ) ;
104
+
105
+ await t . test ( "should detect a card number w/ spaces" , async function ( ) {
106
+ assert . deepEqual (
107
+ wasm . detectSensitiveInfo ( "a 4242 4242 4242 4242 b" , {
108
+ entities : { tag : "allow" , val : [ { tag : "credit-card-number" } ] } ,
109
+ skipCustomDetect : false ,
110
+ } ) ,
111
+ {
112
+ allowed : [
113
+ {
114
+ end : 21 ,
115
+ identifiedType : { tag : "credit-card-number" } ,
116
+ start : 2 ,
117
+ } ,
118
+ ] ,
119
+ denied : [ ] ,
120
+ } ,
121
+ ) ;
122
+ } ) ;
123
+ } ) ;
0 commit comments