Skip to content

Commit eed1ebd

Browse files
committed
Send empty principal in kerberos auth
This is needed for backwards compatibility with Neo4j versions earlier than 3.2. Commit also fixes formatting and adds tests.
1 parent df883d4 commit eed1ebd

File tree

2 files changed

+95
-16
lines changed

2 files changed

+95
-16
lines changed

src/v1/index.js

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,46 @@
1717
* limitations under the License.
1818
*/
1919

20-
import {int, isInt, inSafeRange, toNumber, toString} from './integer';
21-
import {Node, Relationship, UnboundRelationship, PathSegment, Path} from './graph-types'
22-
import {Neo4jError, SERVICE_UNAVAILABLE, SESSION_EXPIRED, PROTOCOL_ERROR} from './error';
20+
import {inSafeRange, int, isInt, toNumber, toString} from './integer';
21+
import {Node, Path, PathSegment, Relationship, UnboundRelationship} from './graph-types';
22+
import {Neo4jError, PROTOCOL_ERROR, SERVICE_UNAVAILABLE, SESSION_EXPIRED} from './error';
2323
import Result from './result';
2424
import ResultSummary from './result-summary';
2525
import Record from './record';
2626
import {Driver, READ, WRITE} from './driver';
2727
import RoutingDriver from './routing-driver';
2828
import VERSION from '../version';
29-
import {parseScheme, parseUrl} from "./internal/connector";
30-
import {assertString} from "./internal/util";
29+
import {parseScheme, parseUrl} from './internal/connector';
30+
import {assertString} from './internal/util';
3131

3232

33-
const auth ={
33+
const auth = {
3434
basic: (username, password, realm = undefined) => {
3535
if (realm) {
36-
return {scheme: "basic", principal: username, credentials: password, realm: realm};
36+
return {scheme: 'basic', principal: username, credentials: password, realm: realm};
3737
} else {
38-
return {scheme: "basic", principal: username, credentials: password};
38+
return {scheme: 'basic', principal: username, credentials: password};
3939
}
4040
},
41-
kerberos:(base64EncodedTicket)=> {
42-
return {scheme:"kerberos", credentials: base64EncodedTicket};
43-
},
44-
custom: (principal, credentials, realm, scheme, parameters = undefined ) => {
41+
kerberos: (base64EncodedTicket) => {
42+
return {
43+
scheme: 'kerberos',
44+
principal: '', // This empty string is required for backwards compatibility.
45+
credentials: base64EncodedTicket
46+
};
47+
},
48+
custom: (principal, credentials, realm, scheme, parameters = undefined) => {
4549
if (parameters) {
46-
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm,
47-
parameters: parameters}
50+
return {
51+
scheme: scheme, principal: principal, credentials: credentials, realm: realm,
52+
parameters: parameters
53+
};
4854
} else {
49-
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm}
55+
return {scheme: scheme, principal: principal, credentials: credentials, realm: realm};
5056
}
5157
}
5258
};
53-
let USER_AGENT = "neo4j-javascript/" + VERSION;
59+
const USER_AGENT = "neo4j-javascript/" + VERSION;
5460

5561
/**
5662
* Construct a new Neo4j Driver. This is your main entry point for this

test/v1/auth.test.js

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/**
2+
* Copyright (c) 2002-2017 "Neo Technology,","
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
20+
import neo4j from '../../src/v1';
21+
22+
describe('auth', () => {
23+
24+
it('should use correct username and password in basic auth', () => {
25+
const token = neo4j.auth.basic('cat', 'dog');
26+
expect(token).toEqual({
27+
scheme: 'basic',
28+
principal: 'cat',
29+
credentials: 'dog'
30+
});
31+
});
32+
33+
it('should support realm in basic auth', () => {
34+
const token = neo4j.auth.basic('cat', 'dog', 'apartment');
35+
expect(token).toEqual({
36+
scheme: 'basic',
37+
principal: 'cat',
38+
credentials: 'dog',
39+
realm: 'apartment'
40+
});
41+
});
42+
43+
it('should use correct ticket in kerberos', () => {
44+
const token = neo4j.auth.kerberos('my-ticket');
45+
expect(token).toEqual({
46+
scheme: 'kerberos',
47+
principal: '',
48+
credentials: 'my-ticket'
49+
});
50+
});
51+
52+
it('should construct correct custom auth', () => {
53+
const token = neo4j.auth.custom('cat', 'dog', 'apartment', 'pets');
54+
expect(token).toEqual({
55+
scheme: 'pets',
56+
principal: 'cat',
57+
credentials: 'dog',
58+
realm: 'apartment'
59+
});
60+
});
61+
62+
it('should support parameters in custom auth', () => {
63+
const token = neo4j.auth.custom('cat', 'dog', 'apartment', 'pets', {key1: 'value1', key2: 42});
64+
expect(token).toEqual({
65+
scheme: 'pets',
66+
principal: 'cat',
67+
credentials: 'dog',
68+
realm: 'apartment',
69+
parameters: {key1: 'value1', key2: 42}
70+
});
71+
});
72+
73+
});

0 commit comments

Comments
 (0)