Skip to content

Commit 8b99326

Browse files
committed
new tests + replaced react-native-buffer
1 parent b735d25 commit 8b99326

File tree

7 files changed

+1166
-74
lines changed

7 files changed

+1166
-74
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ npm install @sqlitecloud/drivers
1717
You also have to install Peer Dependencies
1818

1919
```bash
20-
npm install @sqlitecloud/drivers react-native-tcp-socket react-native-fast-base64
20+
npm install @sqlitecloud/drivers react-native-tcp-socket react-native-quick-base64
2121
```
2222

23-
React Native run IOS
23+
React Native run iOS
2424

2525
```bash
2626
cd ios && pod install && cd .. && npm run ios
@@ -32,7 +32,7 @@ React Native run Android (without ./ in Windows)
3232
cd android && ./gradlew clean build && cd .. && npm run android
3333
```
3434

35-
Expo run IOS
35+
Expo run iOS
3636

3737
```bash
3838
npx expo prebuild && npx expo run:ios

bun.lockb

-7 Bytes
Binary file not shown.

package-lock.json

Lines changed: 30 additions & 35 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.274",
3+
"version": "1.0.276",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",
@@ -43,19 +43,19 @@
4343
},
4444
"homepage": "https://github.com/sqlitecloud/sqlitecloud-js#readme",
4545
"dependencies": {
46+
"@craftzdog/react-native-buffer": "^6.0.5",
4647
"buffer": "^6.0.3",
4748
"eventemitter3": "^5.0.1",
4849
"jest-html-reporter": "^3.10.2",
4950
"lz4js": "^0.2.0",
50-
"react-native-buffer": "^6.0.3",
5151
"react-native-url-polyfill": "^2.0.0",
5252
"socket.io": "^4.7.5",
5353
"socket.io-client": "^4.7.5",
5454
"whatwg-url": "^14.0.0"
5555
},
5656
"peerDependencies": {
57-
"react-native-tcp-socket": "^6.2.0",
58-
"react-native-fast-base64": "*"
57+
"react-native-quick-base64": "*",
58+
"react-native-tcp-socket": "^6.2.0"
5959
},
6060
"devDependencies": {
6161
"@types/bun": "^1.1.1",
@@ -101,7 +101,7 @@
101101
"react-native": {
102102
"whatwg-url": "react-native-url-polyfill",
103103
"tls": "react-native-tcp-socket",
104-
"buffer": "react-native-buffer"
104+
"buffer": "@craftzdog/react-native-buffer"
105105
},
106106
"browser": {
107107
"tls": false

test/core/built-in-commands.test.ts

Lines changed: 68 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* built-in-commands.test.ts - test sqlitecloud built-in commands
33
*/
44

5+
import { createHash } from 'crypto'
56
import {
67
_,
78
CHINOOK_DATABASE_URL,
@@ -18,7 +19,8 @@ import {
1819
colseq,
1920
screaming_snake_case,
2021
regex_IP_UUID_N,
21-
test
22+
test,
23+
CHINOOK_API_KEY
2224
} from './shared'
2325

2426
describe.each([
@@ -194,26 +196,27 @@ describe.each([
194196
})
195197

196198
describe.each([
197-
['admin', randomName(), randomDate(), true],
198-
['admin', randomName(), 'WRONG_DATE', false],
199-
['NOT_EXIST', randomName(), randomDate(), false],
200-
['admin', '', randomDate(), false]
201-
])('api key', (username, keyName, expiration, ok) => {
202-
let key: string
199+
['admin', randomName(), randomDate(), _, true],
200+
['admin', randomName(), randomDate(), randomName(), true],
201+
['admin', randomName(), 'WRONG_DATE', _, false],
202+
['NOT_EXIST', randomName(), randomDate(), randomName(), false],
203+
['admin', '', randomDate(), _, false]
204+
])('api key', (username, keyName, expiration, key, ok) => {
205+
let generated_key: string
203206

204207
it(`should${ok ? '' : "n't"} create`, done => {
205208
const chinook = getConnection()
206209
chinook.sendCommands(
207-
`CREATE APIKEY USER ${username} NAME ${keyName} EXPIRATION "${expiration}"`,
208-
test(done, chinook, ok, /^[a-zA-Z0-9]{43}$/, (res: string) => (key = res))
210+
`CREATE APIKEY USER ${username} NAME ${keyName} EXPIRATION "${expiration}"${key ? ` KEY ${key}` : ''}`,
211+
test(done, chinook, ok, key ? key : /^[a-zA-Z0-9]{43}$/, (res: string) => (generated_key = res))
209212
)
210213
})
211214

212215
it(`should${ok ? '' : "n't"} list created`, done => {
213216
const chinook = getConnection()
214217
chinook.sendCommands(
215218
`LIST APIKEYS USER ${username} ${username == 'admin' ? '; LIST MY APIKEYS' : ''}`,
216-
test(done, chinook, ok, { creation_date: date(), expiration_date: expiration, key: key, name: keyName })
219+
test(done, chinook, ok, { creation_date: date(), expiration_date: expiration, key: generated_key, name: keyName })
217220
)
218221
})
219222

@@ -224,29 +227,29 @@ describe.each([
224227
expiration = randomDate()
225228
const chinook = getConnection()
226229
chinook.sendCommands(
227-
`SET APIKEY ${key} NAME ${keyName} EXPIRATION "${expiration}"; LIST APIKEYS USER ${username}`,
228-
test(done, chinook, false, { creation_date: date(), expiration_date: prevExpiration, key: key, name: prevKeyName })
230+
`SET APIKEY ${generated_key} NAME ${keyName} EXPIRATION "${expiration}"; LIST APIKEYS USER ${username}`,
231+
test(done, chinook, false, { creation_date: date(), expiration_date: prevExpiration, key: generated_key, name: prevKeyName })
229232
)
230233
})
231234

232235
it(`should${ok ? '' : "n't"} list renamed`, done => {
233236
const chinook = getConnection()
234237
chinook.sendCommands(
235238
`LIST APIKEYS USER ${username} ${username == 'admin' ? '; LIST MY APIKEYS' : ''}`,
236-
test(done, chinook, ok, { creation_date: date(), expiration_date: expiration, key: key, name: keyName })
239+
test(done, chinook, ok, { creation_date: date(), expiration_date: expiration, key: generated_key, name: keyName })
237240
)
238241
})
239242

240243
it(`should${ok ? '' : "n't"} remove`, done => {
241244
const chinook = getConnection()
242-
chinook.sendCommands(`REMOVE APIKEY ${key}`, test(done, chinook, ok))
245+
chinook.sendCommands(`REMOVE APIKEY ${generated_key}`, test(done, chinook, ok))
243246
})
244247

245248
it(`should${ok ? '' : "n't"} list empty`, done => {
246249
const chinook = getConnection()
247250
chinook.sendCommands(
248251
`LIST APIKEYS USER ${username} ${username == 'admin' ? '; LIST MY APIKEYS' : ''}`,
249-
test(done, chinook, false, { creation_date: date(), expiration_date: expiration, key: key, name: keyName })
252+
test(done, chinook, false, { creation_date: date(), expiration_date: expiration, key: generated_key, name: keyName })
250253
)
251254
})
252255
})
@@ -347,14 +350,14 @@ describe.each([
347350
})
348351

349352
describe.each([
350-
[randomName(), randomName(), 'READ', 'chinook.sqlite', 'artists', true],
351-
[randomName(), randomName(), '', '', '', true],
352-
[randomName(), randomName(), 'READ', '', '', true],
353-
[randomName(), randomName(), 'NOT_EXIST', '', '', false],
354-
[randomName(), randomName(), '', 'chinook.sqlite', 'artists', true]
353+
[randomName(), randomName(), 'READ', 'chinook.sqlite', 'artists', CHINOOK_API_KEY, true],
354+
[randomName(), randomName(), '', '', '', CHINOOK_API_KEY, true],
355+
[randomName(), randomName(), 'READ', '', '', CHINOOK_API_KEY, true],
356+
[randomName(), randomName(), 'NOT_EXIST', '', '', randomName(), false],
357+
[randomName(), randomName(), '', 'chinook.sqlite', 'artists', CHINOOK_API_KEY, true]
355358
//[randomName(), randomName(), 'READ', 'NOT_EXIST', '', false],
356359
//[randomName(), randomName(), 'READ', '', 'NOT_EXIST', false] core not checking if database or table exists
357-
])('user', (username, password, role, database, table, ok) => {
360+
])('user', (username, password, role, database, table, key, ok) => {
358361
it(`should${ok ? '' : "n't"} create`, done => {
359362
const chinook = getConnection()
360363
chinook.sendCommands(
@@ -384,6 +387,16 @@ describe.each([
384387
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, ok))
385388
})
386389

390+
it(`should${ok ? '' : "n't"} auth with apikey`, done => {
391+
const chinook = getConnection()
392+
chinook.sendCommands(`AUTH APIKEY ${key}`, test(done, chinook, ok))
393+
})
394+
395+
it(`should${ok ? '' : "n't"} auth with hash`, done => {
396+
const chinook = getConnection()
397+
chinook.sendCommands(`AUTH USER ${username} HASH ${createHash('sha256').update(password).digest('base64')}`, test(done, chinook, ok))
398+
})
399+
387400
it(`should${ok ? '' : "n't"} revoke role`, done => {
388401
const gOk = role != '' && ok
389402
const chinook = getConnection()
@@ -603,14 +616,44 @@ describe.each([
603616
chinook.sendCommands(`CREATE CHANNEL ${name} IF NOT EXISTS`, test(done, chinook, ok))
604617
})
605618

606-
/* it(`should${ok ? '' : "n't"} listen`, done => { //ERROR Data type: | is not defined in SCSP, it isn't supported yet
619+
it(`should${ok ? '' : "n't"} listen`, done => {
620+
//ERROR Data type: | is not defined in SCSP, it isn't supported yet
607621
const chinook = getConnection()
608-
chinook.sendCommands(`LISTEN ${name}`, test(done, chinook, ok))
622+
chinook.sendCommands(
623+
`LISTEN ${name}`,
624+
test(
625+
done,
626+
chinook,
627+
ok,
628+
/^PAUTH\s([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\s([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/
629+
)
630+
)
609631
})
610632
it(`should${ok ? '' : "n't"} listen table`, done => {
611633
const chinook = getConnection()
612-
chinook.sendCommands(`LISTEN TABLE ${table} ${database ? `DATABASE ${database}` : ''}`, test(done, chinook, ok))
613-
}) */
634+
chinook.sendCommands(
635+
`LISTEN TABLE ${table} ${database ? `DATABASE ${database}` : ''}`,
636+
test(
637+
done,
638+
chinook,
639+
ok,
640+
/^PAUTH\s([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\s([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})$/
641+
)
642+
)
643+
})
644+
645+
it.skip(`should${ok ? '' : "n't"} list pubsub connections`, done => {
646+
const chinook = getConnection()
647+
chinook.sendCommands(
648+
`LIST PUBSUB CONNECTIONS`,
649+
test(done, chinook, ok, {
650+
id: expect.any(Number),
651+
dbname: database,
652+
chname: table,
653+
client_uuid: uuid()
654+
})
655+
)
656+
})
614657

615658
it(`should${ok ? '' : "n't"} notify`, done => {
616659
const chinook = getConnection()

0 commit comments

Comments
 (0)