Skip to content

Commit 8832c2f

Browse files
committed
temp test
1 parent 8b99326 commit 8832c2f

File tree

5 files changed

+804
-59
lines changed

5 files changed

+804
-59
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@sqlitecloud/drivers",
3-
"version": "1.0.276",
3+
"version": "1.0.289",
44
"description": "SQLiteCloud drivers for Typescript/Javascript in edge, web and node clients",
55
"main": "./lib/index.js",
66
"types": "./lib/index.d.ts",

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

Lines changed: 150 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import {
2222
test,
2323
CHINOOK_API_KEY
2424
} from './shared'
25+
import { SQLiteCloudTlsConnection } from '../../src/drivers/connection-tls'
26+
27+
jest.retryTimes(3)
2528

2629
describe.each([
2730
['', true],
@@ -212,6 +215,11 @@ describe.each([
212215
)
213216
})
214217

218+
it(`should${ok ? '' : "n't"} switch`, done => {
219+
const chinook = getConnection()
220+
chinook.sendCommands(`SWITCH APIKEY ${generated_key}`, test(done, chinook, ok))
221+
})
222+
215223
it(`should${ok ? '' : "n't"} list created`, done => {
216224
const chinook = getConnection()
217225
chinook.sendCommands(
@@ -245,6 +253,11 @@ describe.each([
245253
chinook.sendCommands(`REMOVE APIKEY ${generated_key}`, test(done, chinook, ok))
246254
})
247255

256+
it(`shouldn't switch`, done => {
257+
const chinook = getConnection()
258+
chinook.sendCommands(`SWITCH APIKEY ${generated_key}`, test(done, chinook, false))
259+
})
260+
248261
it(`should${ok ? '' : "n't"} list empty`, done => {
249262
const chinook = getConnection()
250263
chinook.sendCommands(
@@ -387,11 +400,31 @@ describe.each([
387400
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, ok))
388401
})
389402

403+
it(`should${ok ? '' : "n't"} verify`, done => {
404+
const chinook = getConnection()
405+
chinook.sendCommands(`VERIFY USER ${username} PASSWORD ${password}`, test(done, chinook, ok))
406+
})
407+
408+
it(`should${ok ? '' : "n't"} switch`, done => {
409+
const chinook = getConnection()
410+
chinook.sendCommands(`SWITCH USER ${username}`, test(done, chinook, ok))
411+
})
412+
413+
it(`should${ok ? '' : "n't"} set`, done => {
414+
const chinook = getConnection()
415+
chinook.sendCommands(`SET USER ${username}`, test(done, chinook, ok))
416+
})
417+
390418
it(`should${ok ? '' : "n't"} auth with apikey`, done => {
391419
const chinook = getConnection()
392420
chinook.sendCommands(`AUTH APIKEY ${key}`, test(done, chinook, ok))
393421
})
394422

423+
it(`should${ok ? '' : "n't"} switch apikey`, done => {
424+
const chinook = getConnection()
425+
chinook.sendCommands(`SWITCH APIKEY ${key}`, test(done, chinook, ok))
426+
})
427+
395428
it(`should${ok ? '' : "n't"} auth with hash`, done => {
396429
const chinook = getConnection()
397430
chinook.sendCommands(`AUTH USER ${username} HASH ${createHash('sha256').update(password).digest('base64')}`, test(done, chinook, ok))
@@ -476,6 +509,21 @@ describe.each([
476509
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, false))
477510
})
478511

512+
it(`shouldn't verify`, done => {
513+
const chinook = getConnection()
514+
chinook.sendCommands(`VERIFY USER ${username} PASSWORD ${password}`, test(done, chinook, false))
515+
})
516+
517+
it(`shouldn't switch`, done => {
518+
const chinook = getConnection()
519+
chinook.sendCommands(`SWITCH USER ${username}`, test(done, chinook, false))
520+
})
521+
522+
it(`shouldn't set`, done => {
523+
const chinook = getConnection()
524+
chinook.sendCommands(`SET USER ${username}`, test(done, chinook, false))
525+
})
526+
479527
it(`should${ok ? '' : "n't"} enable`, done => {
480528
const chinook = getConnection()
481529
chinook.sendCommands(
@@ -505,6 +553,41 @@ describe.each([
505553
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, ok))
506554
})
507555

556+
it(`should${ok ? '' : "n't"} add allowed ip to verify`, done => {
557+
const chinook = getConnection()
558+
chinook.sendCommands(`ADD ALLOWED IP 1.1.1.1 USER ${username}`, test(done, chinook, ok))
559+
})
560+
561+
it(`shouldn't verify`, done => {
562+
const chinook = getConnection()
563+
chinook.sendCommands(`VERIFY USER ${username} PASSWORD ${password} IP 1.1.1.12`, test(done, chinook, false))
564+
})
565+
566+
it(`should${ok ? '' : "n't"} verify`, done => {
567+
const chinook = getConnection()
568+
chinook.sendCommands(`VERIFY USER ${username} PASSWORD ${password} IP 1.1.1.1`, test(done, chinook, ok))
569+
})
570+
571+
it(`shouldn't auth`, done => {
572+
const chinook = getConnection()
573+
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, false))
574+
})
575+
576+
it(`should${ok ? '' : "n't"} remove allowed ip to verify`, done => {
577+
const chinook = getConnection()
578+
chinook.sendCommands(`REMOVE ALLOWED IP 1.1.1.1 USER ${username}`, test(done, chinook, ok))
579+
})
580+
581+
it(`should${ok ? '' : "n't"} switch`, done => {
582+
const chinook = getConnection()
583+
chinook.sendCommands(`SWITCH USER ${username}`, test(done, chinook, ok))
584+
})
585+
586+
it(`should${ok ? '' : "n't"} set`, done => {
587+
const chinook = getConnection()
588+
chinook.sendCommands(`SET USER ${username}`, test(done, chinook, ok))
589+
})
590+
508591
it(`should get user`, done => {
509592
const chinook = getConnection()
510593
chinook.sendCommands(`GET USER`, test(done, chinook, true, parseconnectionstring(CHINOOK_DATABASE_URL).username))
@@ -571,17 +654,40 @@ describe.each([
571654
chinook.sendCommands(`AUTH USER ${username} PASSWORD ${password}`, test(done, chinook, false))
572655
})
573656

574-
/* it.skip(`should set my password`, done => { //TOFIX?? is it normal that I can't auth right after changing my pass?
657+
it(`shouldn't switch`, done => {
658+
const chinook = getConnection()
659+
chinook.sendCommands(`SWITCH USER ${username}`, test(done, chinook, false))
660+
})
661+
662+
it(`shouldn't set`, done => {
663+
const chinook = getConnection()
664+
chinook.sendCommands(`SET USER ${username}`, test(done, chinook, false))
665+
})
666+
667+
it(`should set my password`, done => {
575668
let chinook = getConnection()
576669
const myPassword = randomName()
577670
chinook.sendCommands(`SET MY PASSWORD adminpasswordxxx`, (error: Error | null, results: any) => {
578671
try {
579672
expect(error).toBeNull()
580673
expect(results).toBe('OK')
581-
//chinook.close()
674+
chinook.close()
675+
676+
//with old pass it should fail
677+
chinook = new SQLiteCloudTlsConnection({ connectionstring: CHINOOK_DATABASE_URL }, (error: any) => {
678+
let cerr = ''
679+
if (error) {
680+
console.error(`getChinookTlsConnection - returned error: ${error}`)
681+
cerr = `getChinookTlsConnection - returned error: ${error}`
682+
}
683+
expect(error).toBeDefined()
684+
expect(cerr).toMatch(/error/i)
685+
})
686+
687+
//try with new pass
582688
chinook = new SQLiteCloudTlsConnection(
583689
{ connectionstring: CHINOOK_DATABASE_URL.replace(parseconnectionstring(CHINOOK_DATABASE_URL).password ?? 'defaultPassword', myPassword) },
584-
error => {
690+
(error: any) => {
585691
if (error) {
586692
console.error(`getChinookTlsConnection - returned error: ${error}`)
587693
}
@@ -591,15 +697,15 @@ describe.each([
591697
chinook.sendCommands(`SET MY PASSWORD ${parseconnectionstring(CHINOOK_DATABASE_URL).password}`, (error: Error | null, results: any) => {
592698
expect(error).toBeNull()
593699
expect(results).toBe('OK')
594-
done()
595700
})
596701
} catch (error) {
597702
done(error)
598703
} finally {
599704
chinook.close()
705+
done()
600706
}
601707
})
602-
}) */
708+
})
603709
})
604710

605711
describe.each([
@@ -629,6 +735,7 @@ describe.each([
629735
)
630736
)
631737
})
738+
632739
it(`should${ok ? '' : "n't"} listen table`, done => {
633740
const chinook = getConnection()
634741
chinook.sendCommands(
@@ -642,16 +749,29 @@ describe.each([
642749
)
643750
})
644751

645-
it.skip(`should${ok ? '' : "n't"} list pubsub connections`, done => {
752+
it(`should${ok ? '' : "n't"} list pubsub connections`, done => {
646753
const chinook = getConnection()
754+
647755
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-
})
756+
`LISTEN TABLE ${table} ${database ? `DATABASE ${database}` : ''}`,
757+
ok
758+
? (error: any, results: any) => {
759+
expect(error).toBeNull()
760+
expect(results).toMatch(
761+
/^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})$/
762+
)
763+
764+
chinook.sendCommands(
765+
`LIST PUBSUB CONNECTIONS`,
766+
test(done, chinook, ok, {
767+
id: expect.any(Number),
768+
dbname: database,
769+
chname: table,
770+
client_uuid: uuid()
771+
})
772+
)
773+
}
774+
: test(done, chinook, false)
655775
)
656776
})
657777

@@ -1086,11 +1206,21 @@ describe.each([
10861206
)
10871207
})
10881208

1209+
it(`should${ok ? '' : "n't"} switch`, done => {
1210+
const chinook = getConnection()
1211+
chinook.sendCommands(`SWITCH DATABASE ${database}`, test(done, chinook, ok))
1212+
})
1213+
10891214
it(`should${ok ? '' : "n't"} disable and list`, done => {
10901215
const chinook = getConnection()
10911216
chinook.sendCommands(`DISABLE DATABASE ${database}; LIST DATABASES`, test(done, chinook, false, { name: database }))
10921217
})
10931218

1219+
it(`shouldn't switch`, done => {
1220+
const chinook = getConnection()
1221+
chinook.sendCommands(`SWITCH DATABASE ${database}`, test(done, chinook, false))
1222+
})
1223+
10941224
it(`should${ok ? '' : "n't"} enable and list`, done => {
10951225
const chinook = getConnection()
10961226
chinook.sendCommands(`ENABLE DATABASE ${database}; LIST DATABASES`, test(done, chinook, ok, { name: database }))
@@ -1262,6 +1392,11 @@ describe.each([
12621392
test(done, chinook, false, { name: database })
12631393
)
12641394
})
1395+
1396+
it(`shouldn't switch`, done => {
1397+
const chinook = getConnection()
1398+
chinook.sendCommands(`SWITCH DATABASE ${database}`, test(done, chinook, false))
1399+
})
12651400
})
12661401

12671402
describe.each([
@@ -1310,7 +1445,7 @@ describe.each([
13101445

13111446
it(`should${/* can't get backups to work locally. enabled ? true : */ false ? '' : "n't"} restore ${database} backup`, done => {
13121447
const chinook = getConnection()
1313-
chinook.sendCommands(`RESTORE BACKUP DATABASE ${database}`, test(done, chinook, /* enabled ? true : */ false))
1448+
chinook.sendCommands(`RESTORE BACKUP DATABASE ${database}`, test(done, chinook, /* enabled ? true : */ false)) //[GENERATION <generation>] [INDEX <index>] [TIMESTAMP <timestamp>]
13141449
})
13151450
})
13161451

@@ -1828,7 +1963,7 @@ describe.each([
18281963
])('cluster settings', (key, value, detailed, no_read_only, ok) => {
18291964
let old_value = expect.stringMatching(/([0-9]|\/|\[)/)
18301965

1831-
it(`should${ok ? '' : "n't"} get key`, done => {
1966+
it(`should${ok ? '' : "n't"} get key: ${key && typeof key == 'string' && !key.includes('\\') ? key : 'something that will make me crash'}`, done => {
18321967
const chinook = getConnection()
18331968
chinook.sendCommands(
18341969
`GET KEY ${key}`,

0 commit comments

Comments
 (0)