diff --git a/packages/emeralt-auth-inmemory/package.json b/packages/emeralt-auth-inmemory/package.json index 0ff78ac..14a987c 100644 --- a/packages/emeralt-auth-inmemory/package.json +++ b/packages/emeralt-auth-inmemory/package.json @@ -15,7 +15,7 @@ "access": "public" }, "scripts": { - "test": "ava ../../test/auth.test.ts", + "test": "ava ../../test/auth.test.ts && ava ./test/*.test.ts", "build": "gemcart build" }, "devDependencies": { diff --git a/packages/emeralt-auth-inmemory/test/index.test.ts b/packages/emeralt-auth-inmemory/test/index.test.ts new file mode 100644 index 0000000..f122af4 --- /dev/null +++ b/packages/emeralt-auth-inmemory/test/index.test.ts @@ -0,0 +1,45 @@ +import { test } from '../../../test/utils' +import { EmeraltAuthInMemory } from '../src' + +test('provide users', async (t, authc) => { + // @ts-ignore + const auth = await authc({ + users: { tester: 'tester' }, + })({}) + + t.true(auth.comparePassword('tester', 'tester')) + t.false(auth.comparePassword('tester', 'wrong')) +}) + +test('canUser', async (t, authc) => { + // @ts-ignore + const auth = await authc({ + users: { tester: 'tester-pass' }, + })( + {}, + { + // @ts-ignore + getMetadata: () => ({ + _owner: 'tester', + }), + }, + ) + + t.true(await auth.canUser('tester', 'get', 'some-package')) + t.true(await auth.canUser('tester', 'publish', 'some-package')) + + // @ts-ignore + const auth2 = await authc({ + users: { tester: 'tester-pass' }, + })( + {}, + { + // @ts-ignore + getMetadata: () => ({ + _owner: 'other_user', // important + }), + }, + ) + + t.false(await auth2.canUser('tester', 'publish', 'some-package')) +}) diff --git a/packages/emeralt-cli/test/index.test.ts b/packages/emeralt-cli/test/index.test.ts index 2b022b3..f0b1ded 100644 --- a/packages/emeralt-cli/test/index.test.ts +++ b/packages/emeralt-cli/test/index.test.ts @@ -4,7 +4,7 @@ import { fork } from 'child_process' const sleep = (t) => new Promise((resolve) => setTimeout(resolve, t)) -test.serial('start server', async (t) => { +test.serial('start built emeralt', async (t) => { const server = fork('build/index.js') await sleep(1000) @@ -17,3 +17,17 @@ test.serial('start server', async (t) => { t.pass() }) + +test.serial('start emeralt', async (t) => { + require('../src/index') + + await sleep(1000) + + await supertest('http://localhost:8080') + .get('/-/ping') + .expect(200) + + // server.kill('SIGTERM') + + t.pass() +})