This repository has been archived by the owner on May 16, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: extend tests for cli and auth-inmemory
- Loading branch information
1 parent
f3d9b32
commit 3591693
Showing
3 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { test } from '../../../test/utils' | ||
import { EmeraltAuthInMemory } from '../src' | ||
|
||
test<typeof EmeraltAuthInMemory>('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<typeof EmeraltAuthInMemory>('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')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters