Skip to content

Commit

Permalink
Merge 0a4921d into 54a1773
Browse files Browse the repository at this point in the history
  • Loading branch information
deniak committed Jul 3, 2020
2 parents 54a1773 + 0a4921d commit 59939a9
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 11 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ config.js

# JSDoc output
doc/api/

# staging area for dev
test/staging/
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ var LdapAuth = require('ldapauth-fork');
var BasicStrategy = require('passport-http').BasicStrategy;

// Configuration file
require('./config.js');
let config = process.env.CONFIG || "config.js";
require("./" + config);
console.log("Loading config: " + config);

var app = express();
var requests = {};
Expand Down
40 changes: 40 additions & 0 deletions config-dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
'use strict';

global.DEFAULT_TEMP_LOCATION = './test/staging/';
// DEFAULT_HTTP_LOCATION without trailing slash
global.DEFAULT_HTTP_LOCATION = 'http://localhost:3001';
global.DEFAULT_LOG_LOCATION = '.';
global.DEFAULT_RESULT_LOCATION = './test/staging/';
global.DEFAULT_PORT = 3000;
global.RESOURCES_WHITELIST = './whitelist.json';
global.TOKEN_ENDPOINT = 'http://localhost:3001/authorize';
global.SPEC_GENERATOR = 'http://localhost:3001/generate';
global.USERNAME = '';
global.PASSWORD = '';
global.W3C_PUBSYSTEM_URL = 'http://localhost:3001/publish';
global.TR_INSTALL_CMD = 'mkdir -p ./test/staging/$dest && cp -R $source ./test/staging/$dest';
global.UPDATE_TR_SHORTLINK_CMD = '#';
global.MAIL_SENDER = 'Echidna <echidna@example.org>';
global.MAIL_REPLYTO = 'john.doe@example.org';
global.MAILING_LIST = 'public-mailing-list@example.org';
global.ATTACH_JSON = false;
global.ALLOWED_CLIENTS = [
// Same host (for tests):
/https?:\/\/localhost(:\d{1,4})?/i,
// W3C:
/https?:\/\/(www\.)?w3c?\.org/i,
// GitHub:
/https?:\/\/w3c\.github\.io/i
];
global.LDAP_URL = "ldap://localhost:1389";
global.LDAP_SEARCH_BASE = 'ou=user,dc=example,dc=org';
// LDAP_BIND_DN must contain the placeholder {{username}}
global.LDAP_BIND_DN = 'uid={{username}},ou=user,dc=example,dc=org';
global.GH_TOKEN = '123foobar';
global.GH_DIRECTOR_TEAM_ID = '2797096';
global.GH_COMM_TEAM_ID = '2794457';

global.LDAP_USER = "foo";
global.LDAP_PASSWORD = "bar";
global.LDAP_GROUPS = ["cn=123,ou=groups,dc=w3,dc=org", "cn=456,ou=groups,dc=w3,dc=org", "cn=32113,ou=groups,dc=w3,dc=org"];
global.SKIP_VALIDATION = true
4 changes: 3 additions & 1 deletion lib/orchestrator.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ var UserChecker = require('./user-checker');
var TransitionChecker = require('./transition-checker');

// Configuration file
require('../config.js');
let config = process.env.CONFIG || "config.js";
require("../" + config);
console.log("Loading config: " + config);

// Pseudo-constants:
var W3_ORG_PREFIX = /^https?:\/\/(www\.)?w3c?\.org/i;
Expand Down
8 changes: 6 additions & 2 deletions lib/specberus-wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var List = require('immutable').List;
var Map = require('immutable').Map;
var Specberus = require('specberus/lib/validator').Specberus;

require('../config.js');
let config = process.env.CONFIG || "config.js";
require("../" + config);
console.log("Loading config: " + config);

/**
* @exports lib/specberus-wrapper
Expand Down Expand Up @@ -47,7 +49,9 @@ SpecberusWrapper.validate = function (url, profile, isRecTrack, isEditorial) {

sink.on('err', function (type, data) {
data.type = type;
errors = errors.push(data);
if (!["validation.html", "validation.css"].includes(type.name) || !global.SKIP_VALIDATION) {
errors = errors.push(data);
}
});

sink.on('exception', function (exception) {
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"jshint": "2.11.1",
"minami": "1.2.3",
"mocha": "8.0.1",
"morgan": "1.10.0"
"morgan": "1.10.0",
"ldapjs": "2.0.0"
},
"scripts": {
"audit": "npm audit | grep -oE 'https?\\:\\/\\/(www\\.)?(nodesecurity\\.io|npmjs\\.com)\\/advisories\\/[[:digit:]]+' | rev | cut -d '/' -f 1 | rev | diff known-vulns.txt -",
Expand Down
49 changes: 46 additions & 3 deletions test/lib/testserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ var htmlTemplate = require('./htmltemplate');
var getMetadata = require('./utils').getMetadata;
var draftsSystemPath = require('./utils').draftsSystemPath;
var request = require('request');
var ldap = require('ldapjs');

var PublishService = require('./fake-http-services').CreatedService;
var port = (process.env.PORT || 3000) + 1;
var port = (parseInt(process.env.PORT) || 3000) + 1;
var ldapPort = 1389;
require('../../config-dev.js');

/**
* @exports test/lib/TestServer
Expand All @@ -34,6 +37,7 @@ app.use(htmlTemplate('/drafts', draftsSystemPath));
app.use('/drafts', express.static(draftsSystemPath));
app.use(express.static('assets/'));
app.use(express.static('test/views/'));
app.use(express.static('test/staging/'));

app.get('/data/specs.json', function (req, res) {
var specs = [];
Expand Down Expand Up @@ -85,6 +89,35 @@ app.post('/publish', function (_, res) {
});

var server;
var ldapServer = ldap.createServer();

ldapServer.bind('uid=foo,ou=user,dc=example,dc=org', function(req, res, next) {
if (req.credentials !== global.LDAP_PASSWORD) {
return next(new ldap.InvalidCredentialsError());
}
console.log('bind DN: ' + req.dn.toString());
console.log('bind PW: ' + req.credentials);
res.end();
return next();
});

ldapServer.search(global.LDAP_SEARCH_BASE, function(req, res, next) {
var obj = {
dn: "uid="+global.LDAP_USER+","+req.dn.toString(),
attributes: {
uid: global.LDAP_USER,
objectclass: ['top', 'person'],
o: 'example',
memberOf: global.LDAP_GROUPS
}
};

if (req.filter.matches(obj.attributes))
res.send(obj);

res.end();
return next();
});

TestServer.start = function () {
var limitPort = port + 30;
Expand All @@ -103,7 +136,14 @@ TestServer.start = function () {
if (server.address() === null) {
throw new Error('Cannot find a free port for the test server ' + port);
}
global.SPEC_GENERATOR = this.location() + '/generate';

ldapServer.listen(ldapPort, 'localhost', function() {
console.log("LDAP server listening at " + ldapServer.url);
});

console.log("Token checker ready at " + this.location() + " /authorize");
console.log("Spec generator ready at " + this.location() + " /generate");
console.log("Publication backend ready at " + this.location() + " /publish");
};

TestServer.location = function () {
Expand All @@ -122,7 +162,10 @@ TestServer.getMetadata = function (name) {
return data;
};

TestServer.close = () => server.close();
TestServer.close = () => {
server.close();
ldapServer.close();
};

TestServer.start();

Expand Down
2 changes: 1 addition & 1 deletion test/lib/tokenchecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ tokenChecker.get('/authorize', function (req, res) {
var json = {
token: token,
spec: uri,
source: 'http://localhost:3001/drafts/',
source: 'http://localhost:3001/',
authorized: true
};

Expand Down
Empty file added test/staging/.gitkeep
Empty file.
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var List = Immutable.List;
var Map = Immutable.Map;
var pendingTests = 5;

require('../config.js');
require('../config-dev.js');

var server = require('./lib/testserver');
var FakeHttpServices = require('./lib/fake-http-services');
Expand Down Expand Up @@ -420,7 +420,7 @@ describe('SpecberusWrapper', function () {

it('should return an error property that has 4 errors', function () {
return expect(content).that.eventually.has.property('errors')
.that.has.size(6);
.that.has.size(4);
});
});

Expand Down

0 comments on commit 59939a9

Please sign in to comment.