Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 25 additions & 18 deletions packages/core/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
* @property {function(principal: string, credentials: string, realm: string, scheme: string, parameters: ?object)} custom
* the function to create a custom authentication token.
*/
const auth = {
const auth = {
basic: (username: string, password: string, realm?: string) => {
if (realm) {
return {
Expand Down Expand Up @@ -58,25 +58,32 @@
credentials: string,
realm: string,
scheme: string,
parameters?: string
parameters?: object
) => {
if (parameters) {
return {
scheme: scheme,
principal: principal,
credentials: credentials,
realm: realm,
parameters: parameters
}
} else {
return {
scheme: scheme,
principal: principal,
credentials: credentials,
realm: realm
}
const output: any = {
scheme: scheme,
principal: principal
}
if (isNotEmpty(credentials)) {
output.credentials = credentials
}
if (isNotEmpty(realm)) {
output.realm = realm
}
if (isNotEmpty(parameters)) {
output.parameters = parameters
}
return output
}
}

export default auth
function isNotEmpty<T extends object | string>(value: T | null | undefined): boolean {
return !(
value === null ||
value === undefined ||
value === '' ||
Object.getPrototypeOf(value) === Object.prototype && Object.keys(value).length === 0
)
}

export default auth
39 changes: 37 additions & 2 deletions packages/core/test/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,42 @@ import auth from '../src/auth'
describe('auth', () => {

test('.bearer()', () => {
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' } )
expect(auth.bearer('==Qyahiadakkda')).toEqual({ scheme: 'bearer', credentials: '==Qyahiadakkda' })
})

test.each([
[
['user', 'pass', 'realm', 'scheme', { param: 'param' }],
{
scheme: 'scheme',
principal: 'user',
credentials: 'pass',
realm: 'realm',
parameters: { param: 'param' }
}
],
[
['user', '', '', 'scheme', {}],
{
scheme: 'scheme',
principal: 'user'
}
],
[
['user', undefined, undefined, 'scheme', undefined],
{
scheme: 'scheme',
principal: 'user'
}
],
[
['user', null, null, 'scheme', null],
{
scheme: 'scheme',
principal: 'user'
}
]
])('.custom()', (args, output) => {
expect(auth.custom.apply(auth, args)).toEqual(output)
})

})
1 change: 1 addition & 0 deletions packages/testkit-backend/src/request-handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,7 @@ export function GetFeatures (_context, _params, wire) {
'Feature:Bolt:4.4',
'Feature:API:Result.List',
'Feature:API:Result.Peek',
'Optimization:ImplicitDefaultArguments',
'Temporary:ConnectionAcquisitionTimeout',
'Temporary:CypherPathAndRelationship',
'Temporary:DriverFetchSize',
Expand Down
6 changes: 6 additions & 0 deletions packages/testkit-backend/src/skipped-tests/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import skip, { ifEquals, ifEndsWith, ifStartsWith } from './skip'

const skippedTests = [
skip(
'Handle qid omission optmization can cause issues in nested queries',
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments'),
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments_multi_query'),
ifEquals('stub.optimizations.test_optimizations.TestOptimizations.test_uses_implicit_default_arguments_multi_query_nested')
),
skip(
'Fail while enable Temporary::ResultKeys',
ifEquals('neo4j.test_bookmarks.TestBookmarks.test_can_pass_bookmark_into_next_session'),
Expand Down