Skip to content
This repository has been archived by the owner on Apr 21, 2020. It is now read-only.

Commit

Permalink
Update naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbreen committed Dec 11, 2014
1 parent 269018b commit e28012f
Show file tree
Hide file tree
Showing 26 changed files with 118 additions and 130 deletions.
18 changes: 9 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
* pointing to the correct working dir for the app. Update the working dir
* before doing anything involving relative paths.
*/
if (process.env.AUSPICE_HOME) {
console.log("Changing home directory to " + process.env.AUSPICE_HOME);
process.chdir(process.env.AUSPICE_HOME);
if (process.env.OAUTH_REVERSE_PROXY_HOME) {
console.log("Changing home directory to " + process.env.OAUTH_REVERSE_PROXY_HOME);
process.chdir(process.env.OAUTH_REVERSE_PROXY_HOME);
}

var auspice = require('./lib');
var oauth_reverse_proxy = require('./lib');
var logger = require('./lib/logger.js');

/**
* The config path can be provided as an environemnt variable. If not rpvoided, we chose
* sane defaults for Windows and non-Windows.
*/
var config_path = process.env.AUSPICE_CONFIG_PATH;
var config_path = process.env.OAUTH_REVERSE_PROXY_CONFIG_PATH;
if (!config_path) {
var os = require('os').type().toLowerCase();
if (os.indexOf('windows') !== -1 || os.indexOf('cygwin') !== -1) {
config_path = "C:\\ProgramData\\auspice\\config.d\\";
config_path = "C:\\ProgramData\\oauth_reverse_proxy\\config.d\\";
} else {
config_path = "/etc/auspice.d/";
config_path = "/etc/oauth_reverse_proxy.d/";
}
}

// Create an auspice instance at our configured root dir.
auspice.init(config_path, function(err, proxy) {
// Create an oauth_reverse_proxy instance at our configured root dir.
oauth_reverse_proxy.init(config_path, function(err, proxy) {
// If we caught a fatal error creating the proxies, log it and pause briefly before exiting
// to give Bunyan a chance to flush this error message.
if (err) {
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var ProxyConfig = require('./proxy/config.js');
var logger = require('./logger.js');

/**
* An Auspice instance is initialized around a configuration directory. Each Auspice proxy
* An oauth_reverse_proxy instance is initialized around a configuration directory. Each proxy
* is represented by a JSON configuration file in this directory.
*
* The directory is loaded once on startup. There is currently no provision for polling configuration
Expand All @@ -21,7 +21,7 @@ exports.init = function(config_dir, cb) {
/* istanbul ignore next */
if (err) return cb("Failed to open directory " + config_dir);

if (!stat.isDirectory()) return cb('Auspice config dir is not a directory');
if (!stat.isDirectory()) return cb('oauth_reverse_proxy config dir is not a directory');

// Load all proxy configurations.
loadConfigFiles(config_dir, cb);
Expand Down
2 changes: 1 addition & 1 deletion lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var util = require('util');
var bunyan = require('bunyan');

// Create a default logger to use if all else fails.
module.exports = bunyan.createLogger({name: 'auspice'});
module.exports = bunyan.createLogger({name: 'oauth_reverse_proxy'});

// Init the logger with a configuration object
/* istanbul ignore next */
Expand Down
4 changes: 2 additions & 2 deletions lib/proxy/authenticator.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var OAUTH_SIGNATURE_METHOD = 'oauth_signature_method';
var OAUTH_TIMESTAMP = 'oauth_timestamp';
var OAUTH_VERSION = 'oauth_version';

var CONSUMER_KEY_HEADER = exports.CONSUMER_KEY_HEADER = 'x-vp-auspice-consumer-key';
var CONSUMER_KEY_HEADER = exports.CONSUMER_KEY_HEADER = 'x-oauth-reverse-proxy-consumer-key';

/**
* All of these parameters must be present in a valid oauth header or query string.
Expand Down Expand Up @@ -367,7 +367,7 @@ exports.oauthValidator = function(keys) {
var signature_bases = constructStringsToSign(req, argument_pairs, consumer_secret);

// Because python (and possibly) some other libraries do not encode the signature, we can avoid spurious
// validation failures by comparing decoded signatures against the hash value computed by Auspice.
// validation failures by comparing decoded signatures against the hash value computed by oauth_reverse_proxy.
oauth_params[OAUTH_SIGNATURE] = encoding.decodeData(oauth_params[OAUTH_SIGNATURE]);

while (signature_bases.length > 0) {
Expand Down
18 changes: 3 additions & 15 deletions lib/proxy/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ var util = require('util');
var logger = require('../logger.js');

/**
* The proxy config is a representation of a JSON configuration file from the Auspice
* config directory. This class is responsible for exposing only those fields in the
* JSON that map to valid proxy configuration and for validating that the configuration
* is legitimate.
* The proxy config is a representation of a JSON configuration file from the oauth_reverse_proxy
* config directory. This class is responsible for exposing only those fields in the JSON that
* map to valid proxy configuration and for validating that the configuration is legitimate.
*/
function ProxyConfig(config) {
var this_obj = this;
Expand Down Expand Up @@ -57,14 +56,3 @@ ProxyConfig.prototype.isValid = function() {
};

module.exports = ProxyConfig;

/**
var pc = new ProxyConfig({
'from_port': 8888,
'to_port': 7000,
'keystore': '/var/lib/auspice/8888/7000'
});
logger.info(pc.from_port);
logger.info(pc.validate());
**/
8 changes: 4 additions & 4 deletions lib/proxy/header_modifier.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var uuid = require('node-uuid');

// Return the port, either by parsing the host header or by determining whether Auspice did ssl
// Return the port, either by parsing the host header or by determining whether oauth_reverse_proxy did ssl
// termination for the request.
function getPortForRequest(req) {
var port = req.headers.host.match(/:(\d+)/);
Expand All @@ -21,14 +21,14 @@ function safelySetHeader(req, header_name, header_value) {
}
}

var AUSPICE_VERSION = process.env.AUSPICE_VERSION || "tst";
var OAUTH_REVERSE_PROXY_VERSION = process.env.OAUTH_REVERSE_PROXY_VERSION || "tst";

// The Via header value won't change during runtime of this process, so create it once at startup.
var DEFAULT_VIA_HEADER = '1.1 localhost (Auspice v' + AUSPICE_VERSION + ')';
var DEFAULT_VIA_HEADER = '1.1 localhost (oauth_reverse_proxy v' + OAUTH_REVERSE_PROXY_VERSION + ')';

// Append x-forwarded-for, x-forwarded-port, x-forwarded-proto, x-forwarded-host, and via to the request
// headers before proxying to the target server. If these headers are already set, append information
// received by Auspice to the existing headers.
// received by oauth_reverse_proxy to the existing headers.
exports.applyXForwardedHeaders = function() {
return function(req, res, next) {

Expand Down
12 changes: 6 additions & 6 deletions lib/proxy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var HTTP_AGENT = http.globalAgent;
HTTP_AGENT.maxSockets = 1000;

/**
* An Auspice proxy is initialized around a JSON value that defines the necessary components
* An oauth_reverse_proxy is initialized around a JSON value that defines the necessary components
* of any proxy, such as the from and to ports as well as the directory in which OAuth secrets
* are stored.
*
Expand All @@ -32,13 +32,13 @@ HTTP_AGENT.maxSockets = 1000;
*
* An example proxy configured with a single consumer key named 'test-key' and consumer secret
* of 'terrible-consumer-secret' would contain the following as the sole entry in the
* a keystore directory of /var/auspice/8000/80:
* a keystore directory of /var/oauth_reverse_proxy/8000/80:
*
* /var/auspice/8000/80/test-key
* /var/oauth_reverse_proxy/8000/80/test-key
*
* The contents of this file would be 'terrible-consumer-secret'
*
* An Auspice proxy will manage its keystore and watch for changes to the filesystem. As
* An oauth_reverse_proxy will manage its keystore and watch for changes to the filesystem. As
* keys are added, removed, or changed, the proxy will dynamically reconfigure to reflect the
* new set of credentials.
*/
Expand Down Expand Up @@ -83,7 +83,7 @@ Proxy.prototype.start = function(cb) {
return next();
}

res.writeHead(413, "URL exceeds maximum allowed length for Auspice");
res.writeHead(413, "URL exceeds maximum allowed length for oauth_reverse_proxy");
res.end();
},
// Parse query string
Expand Down Expand Up @@ -136,5 +136,5 @@ Proxy.prototype.start = function(cb) {
});
};

// Expose Proxy class to auspice.
// Expose Proxy class.
module.exports = Proxy;
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var _ = require('underscore');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');

var auspice = require('../lib');
var oauth_reverse_proxy = require('../lib');
var Proxy = require('../lib/proxy');

// Start every test with an empty keys directory.
Expand All @@ -20,33 +20,33 @@ var slate_cleaner = function(done) {
}
};

// Attempt to initiate Auspice with various forms of broken config.
describe('Auspice config validation', function() {
// Attempt to initiate oauth_reverse_proxy with various forms of broken config.
describe('oauth_reverse_proxy config validation', function() {

// Before attempting to start Auspice, clean the malformed directories we need for test purposes.
// Before attempting to start oauth_reverse_proxy, clean the malformed directories we need for test purposes.
beforeEach(slate_cleaner);

// After we're done with all these tests and we've butchered our keys directory to a fair-thee-well,
// kill it with fire.
after(slate_cleaner);

it ('should reject an attempt to init Auspice with an unset config_dir parameter', function(done) {
auspice.init(null, function(err, proxy) {
it ('should reject an attempt to init oauth_reverse_proxy with an unset config_dir parameter', function(done) {
oauth_reverse_proxy.init(null, function(err, proxy) {
err.should.equal('Failed to open directory ' + null);
done();
});
});

it ('should reject an attempt to init Auspice with a config_dir referencing a nonexistent directory', function(done) {
auspice.init('./test/keys', function(err, proxy) {
it ('should reject an attempt to init oauth_reverse_proxy with a config_dir referencing a nonexistent directory', function(done) {
oauth_reverse_proxy.init('./test/keys', function(err, proxy) {
err.should.equal('Failed to open directory ./test/keys');
done();
});
});

it ('should reject an attempt to init Auspice with a config_dir referencing a non-directory inode', function(done) {
auspice.init('./test/auspice_abnormal_config.js', function(err, proxy) {
err.should.equal('Auspice config dir is not a directory');
it ('should reject an attempt to init oauth_reverse_proxy with a config_dir referencing a non-directory inode', function(done) {
oauth_reverse_proxy.init('./test/auth_proxy_abnormal_config.js', function(err, proxy) {
err.should.equal('oauth_reverse_proxy config dir is not a directory');
done();
});
});
Expand All @@ -55,7 +55,7 @@ describe('Auspice config validation', function() {
// Attempt to initiate a proxy with various forms of broken key directories.
describe('Proxy config validation', function() {

// Before attempting to start Auspice, clean the malformed directories we need for test purposes.
// Before attempting to start oauth-reverse_proxy, clean the malformed directories we need for test purposes.
beforeEach(slate_cleaner);

// After we're done with all these tests and we've butchered our keys directory to a fair-thee-well,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var rimraf = require('rimraf');
var mkdirp = require('mkdirp');
var crypto = require('crypto');

var auspice = require('../lib');
var oauth_reverse_proxy = require('../lib');
var keygen = require('../utils/keygen.js');
var request_sender = require('./utils/request_sender.js');

Expand All @@ -22,13 +22,13 @@ beforeEach(function() {
if (job_server) job_server.removeAllListeners();
});

// Create an Auspice proxy, and validate that it works properly even if there is no server
// Create an oauth_reverse_proxy, and validate that it works properly even if there is no server
// running behind it. Once this is done, start a server. After the completion of this
// test, the preconditions for all other test cases are in place. Thus, every test case
// must require auspice_bootstrap_test.
describe('Auspice Bootstrap', function() {
// must require auth_bootstrap_test.
describe('oauth_reverse_proxy bootstrap', function() {

// Before starting Auspice, create the keys we need for test clients.
// Before starting our oauth_reverse_proxy, create the keys we need for test clients.
before(function(done) {
rimraf('./test/keys/8008/8080', function(err) {
mkdirp('./test/keys/8008/8080', function(err) {
Expand Down Expand Up @@ -90,8 +90,8 @@ describe('Auspice Bootstrap', function() {

// Test that the proxy starts and loads all the keys created in the before function.
it ('should start cleanly', function(done) {
auspice.init('./test/config.d', function(err, proxies) {
if (err) done('Auspice startup failed: ' + err);
oauth_reverse_proxy.init('./test/config.d', function(err, proxies) {
if (err) done('oauth_reverse_proxy startup failed: ' + err);
exports.proxy = proxies["jobs_service.json"];

if (typeof exports.proxy === 'string') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@ var should = require('should');
var _ = require('underscore');

var keygen = require('../utils/keygen.js');
var auspice_bootstrap_test = require('./auspice_bootstrap_test.js');
var auth_proxy_bootstrap_test = require('./auth_proxy_bootstrap_test.js');

describe('Auspice Key Loader', function() {
describe('oauth_reverse_proxy key loader', function() {

it ('should support adding keys dynamically', function(done) {
keygen.createKey('./test/keys', 8008, 8080, 'dynamic-key', function(err) {
keygen.createKey('./test/keys', 8008, 8080, 'dynamic-key2', function(err) {
if (err) done(err);
var check_key = function() {
if (auspice_bootstrap_test.proxy.keys['dynamic-key']) {
if (auth_proxy_bootstrap_test.proxy.keys['dynamic-key']) {
// Turn the proxy.keys object into an array to get its length
auspice_bootstrap_test.proxy.keys.count.should.be.exactly(15);
auth_proxy_bootstrap_test.proxy.keys.count.should.be.exactly(15);
done();
} else setTimeout(check_key, 50);
};
Expand All @@ -28,10 +28,10 @@ describe('Auspice Key Loader', function() {
keygen.createKey('./test/keys', 8008, 8080, 'dynamic-key', 'happy-fun-key', function(err) {
if (err) done(err);
var check_key = function() {
if (auspice_bootstrap_test.proxy.keys['dynamic-key'] === 'happy-fun-key') {
if (auth_proxy_bootstrap_test.proxy.keys['dynamic-key'] === 'happy-fun-key') {
// Turn the proxy.keys object into an array to get its length
auspice_bootstrap_test.proxy.keys.count.should.be.exactly(15);
auspice_bootstrap_test.proxy.keys['dynamic-key'].should.equal('happy-fun-key');
auth_proxy_bootstrap_test.proxy.keys.count.should.be.exactly(15);
auth_proxy_bootstrap_test.proxy.keys['dynamic-key'].should.equal('happy-fun-key');
done();
} else setTimeout(check_key, 50);
};
Expand All @@ -45,10 +45,10 @@ describe('Auspice Key Loader', function() {
fs.unlink('./test/keys/8008/8080/dynamic-key2', function(err) {
if (err) done(err);
var check_key = function() {
if (auspice_bootstrap_test.proxy.keys['dynamic-key']) setTimeout(check_key, 50);
if (auth_proxy_bootstrap_test.proxy.keys['dynamic-key']) setTimeout(check_key, 50);
else {
// Turn the proxy.keys object into an array to get its length
auspice_bootstrap_test.proxy.keys.count.should.be.exactly(13);
auth_proxy_bootstrap_test.proxy.keys.count.should.be.exactly(13);
done();
}
};
Expand Down
4 changes: 2 additions & 2 deletions test/client_library_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ var os = require('os');

var job_server = require('./server/test_server.js').JobServer;

require('./auspice_bootstrap_test.js');
require('./auth_proxy_bootstrap_test.js');

// Creates a convenience function for running an external client and validating that the correct
// key is passed to the job server and the correct content is written to disk.
Expand All @@ -27,7 +27,7 @@ var create_client_test = function(verb, cmd, cwd, key) {
};

// These test clients are in the test/clients subdirectory. Each one tests a limited amount of OAuth
// functionality to validate that requests can be sent through Auspice properly using various languages.
// functionality to validate that requests can be sent through auth_proxy properly using various languages.
describe('Client library tests', function() {

it ('should support requests from ruby', function(done) {
Expand Down
6 changes: 3 additions & 3 deletions test/job_server_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ var validation_tools = require('./utils/validation_tools.js');
var test_server = require('./server/test_server.js');
var job_server = test_server.JobServer;

// Test the job server in isolation to make sure responses are handled as expected without Auspice involved.
// Test the job server in isolation to make sure responses are handled as expected without oauth_reverse_proxy involved.
describe('Job Server', function() {

// Initiate the job server in case auspice_bootstrap_test.js has not been required. This is the only test
// case where it might be valid to start the job server without starting Auspice: we are only testing the
// Initiate the job server in case auth_proxy_bootstrap_test.js has not been required. This is the only test
// case where it might be valid to start the job server without starting oauth_reverse_proxy: we are only testing the
// functionality of the job server here.
before(function(done) {
test_server.init(8080, function(err) {
Expand Down
8 changes: 4 additions & 4 deletions test/message_integrity_compression_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ var util = require('util');
var request_sender = require('./utils/request_sender.js');
var validation_tools = require('./utils/validation_tools.js');

// All tests must require auspice_bootstrap_test since that creates our proxy, starts our job server, and
// All tests must require auth_proxy_bootstrap_test since that creates our proxy, starts our job server, and
// and registers a beforeEach to keep the request_sender and job_server clean between test runs.
require('./auspice_bootstrap_test.js');
require('./auth_proxy_bootstrap_test.js');

// Tests that compressed response content is handled by Auspice.
describe('Auspice message integrity: verbs', function() {
// Tests that compressed response content is handled by oauth_reverse_proxy.
describe('oauth_reverse_proxy message integrity: verbs', function() {

['GET', 'POST', 'PUT', 'DELETE'].forEach(function(verb) {

Expand Down
Loading

0 comments on commit e28012f

Please sign in to comment.