Skip to content

Commit 214a847

Browse files
committed
test(kerberos): remove crufty tests, replace with working ones
1 parent 350d524 commit 214a847

7 files changed

+79
-323
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
},
1919
"devDependencies": {
2020
"chai": "^4.1.2",
21+
"chai-string": "^1.4.0",
2122
"clang-format": "^1.2.3",
2223
"eslint": "^4.19.1",
2324
"eslint-plugin-prettier": "^2.6.0",

test/gssapi_tests.js

-95
This file was deleted.

test/kerberos_tests.js

+78-86
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,97 @@
11
'use strict';
2-
3-
const expect = require('chai').expect;
4-
const http = require('http');
5-
const Kerberos = require('..').Kerberos;
2+
const kerberos = require('..');
3+
const request = require('request');
4+
const chai = require('chai');
5+
const expect = chai.expect;
6+
const SegfaultHandler = require('segfault-handler');
7+
SegfaultHandler.registerHandler();
8+
chai.use(require('chai-string'));
9+
10+
const username = process.env.KERBEROS_USERNAME || 'administrator';
11+
// const password = process.env.KERBEROS_PASSWORD || 'Password01';
12+
const realm = process.env.KERBEROS_REALM || 'example.com';
13+
const hostname = process.env.KERBEROS_HOSTNAME || 'hostname.example.com';
14+
const port = process.env.KERBEROS_PORT || '80';
615

716
describe('Kerberos', function() {
8-
it('simple initialize of Kerberos object', function(done) {
9-
const kerberos = new Kerberos();
10-
11-
// Initiate kerberos client
12-
kerberos.authGSSClientInit('[email protected]', Kerberos.GSS_C_MUTUAL_FLAG, function(
13-
err,
14-
context
15-
) {
17+
it('should authenticate against a kerberos server using GSSAPI', function(done) {
18+
const service = `HTTP@${hostname}`;
19+
20+
kerberos.initializeClient(service, {}, (err, client) => {
1621
expect(err).to.not.exist;
17-
expect(context).to.exist;
1822

19-
// Perform the first step
20-
kerberos.authGSSClientStep(context, function(/* err, result */) {
21-
// TODO: reenable next lines when osx support is complete
22-
// expect(err).to.not.exist;
23-
// expect(result).to.exist;
23+
kerberos.initializeServer(service, (err, server) => {
24+
expect(err).to.not.exist;
25+
expect(client.contextComplete).to.be.false;
26+
expect(server.contextComplete).to.be.false;
27+
28+
client.step('', (err, clientResponse) => {
29+
expect(err).to.not.exist;
30+
expect(client.contextComplete).to.be.false;
2431

25-
done();
32+
server.step(clientResponse, (err, serverResponse) => {
33+
expect(err).to.not.exist;
34+
expect(client.contextComplete).to.be.false;
35+
36+
client.step(serverResponse, err => {
37+
expect(err).to.not.exist;
38+
expect(client.contextComplete).to.be.true;
39+
40+
const expectedUsername = `${username}@${realm.toUpperCase()}`;
41+
expect(server.username).to.equal(expectedUsername);
42+
expect(client.username).to.equal(expectedUsername);
43+
expect(server.targetName).to.not.exist;
44+
done();
45+
});
46+
});
47+
});
2648
});
2749
});
2850
});
2951

30-
// for this test, please set the environment variables shown below.
31-
it('simple username password test', function(done) {
32-
const kerberos = new Kerberos();
52+
it('should authenticate against a kerberos HTTP endpoint', function(done) {
53+
const service = `HTTP@${hostname}`;
54+
const url = `http://${hostname}:${port}/`;
3355

34-
if (!process.env.KRB5_PW_TEST_USERNAME) {
35-
return done();
36-
}
56+
// send the initial request un-authenticated
57+
request.get(url, (err, response) => {
58+
expect(response.statusCode).to.equal(401);
3759

38-
kerberos.authUserKrb5Password(
39-
process.env.KRB5_PW_TEST_USERNAME,
40-
process.env.KRB5_PW_TEST_PASSWORD,
41-
process.env.KRB5_PW_TEST_SERVICE,
42-
function(err, ok) {
43-
expect(err).to.not.exist;
44-
expect(ok).to.be.true;
45-
done();
46-
}
47-
);
48-
});
49-
50-
//for this test, please set the environment variables shown below.
51-
it('negotiate HTTP Client Test', function(done) {
52-
///// REQUIRED ENVIRONMENT VARIABLES /////
53-
// give the host and path to a Negotiate protected resource on your network
54-
const httpHostname = process.env.NEGOTIATE_TEST_HOSTNAME;
55-
const httpPath = process.env.NEGOTIATE_TEST_PATH;
56-
//// OPTIONAL ENVIRONMENT VARIABLES
57-
// don't use the cache in $KRB5CCNAME, use the one in $NEGOTIATE_TEST_KRB5CCNAME instead
58-
const krb5CcName = process.env.NEGOTIATE_TEST_KRB5CCNAME || '';
59-
/////
60-
61-
if (!httpHostname) {
62-
return done();
63-
}
64-
65-
const serviceName = 'HTTP@' + httpHostname;
66-
const kerberos = new Kerberos();
67-
68-
kerberos.authGSSClientInit(serviceName, 0, krb5CcName, function(err, ctx) {
69-
expect(err).to.not.exist;
60+
// validate the response supports the Negotiate protocol
61+
const authenticateHeader = response.headers['www-authenticate'];
62+
expect(authenticateHeader).to.exist;
63+
expect(authenticateHeader).to.equal('Negotiate');
7064

71-
kerberos.authGSSClientStep(ctx, '', function(err) {
65+
// generate the first Kerberos token
66+
const mechOID = kerberos.GSS_MECH_OID_KRB5;
67+
kerberos.initializeClient(service, { mechOID }, (err, client) => {
7268
expect(err).to.not.exist;
7369

74-
const cleanupCtx = function() {
75-
kerberos.authGSSClientClean(ctx, function(err) {
76-
expect(err).to.not.exist;
77-
done();
78-
});
79-
};
80-
81-
const negotiateHeader = 'Negotiate ' + ctx.response;
82-
83-
const req = http.get(
84-
{
85-
hostname: httpHostname,
86-
path: httpPath,
87-
headers: {
88-
authorization: negotiateHeader
70+
client.step('', (err, kerberosToken) => {
71+
expect(err).to.not.exist;
72+
73+
// attach the Kerberos token and resend back to the host
74+
request.get(
75+
{ url, headers: { Authorization: `Negotiate ${kerberosToken}` } },
76+
(err, response) => {
77+
expect(err).to.not.exist;
78+
expect(response.statusCode).to.equal(200);
79+
80+
// validate the headers exist and contain a www-authenticate message
81+
const authenticateHeader = response.headers['www-authenticate'];
82+
expect(authenticateHeader).to.exist;
83+
expect(authenticateHeader).to.startWith('Negotiate');
84+
85+
// verify the return Kerberos token
86+
const tokenParts = authenticateHeader.split(' ');
87+
const serverKerberosToken = tokenParts[tokenParts.length - 1];
88+
client.step(serverKerberosToken, err => {
89+
expect(err).to.not.exist;
90+
expect(client.contextComplete).to.be.true;
91+
done();
92+
});
8993
}
90-
},
91-
function(res) {
92-
expect(res.statusCode).to.be.at.least(200);
93-
expect(res.statusCode).to.be.at.most(299);
94-
95-
res.on('data', data => console.log(` >> ${data}`));
96-
res.on('end', () => cleanupCtx());
97-
}
98-
);
99-
100-
req.on('error', function(err) {
101-
done(`http.get request failed: ${err.message}`);
102-
cleanupCtx();
94+
);
10395
});
10496
});
10597
});

test/kerberos_win32_test.js

-18
This file was deleted.

test/win32/security_buffer_descriptor_tests.js

-45
This file was deleted.

test/win32/security_buffer_tests.js

-24
This file was deleted.

0 commit comments

Comments
 (0)