feat: Created a mini nodeJS server with NewMan for testing without PostMan GUI.

This will mimic a run in a CD/CI environment or docker container.
This commit is contained in:
Simon Priet
2021-09-08 14:01:19 +02:00
parent 5fbd7c88fa
commit e69a613a37
5610 changed files with 740417 additions and 3 deletions

84
node_modules/node-oauth1/test/karma.conf.js generated vendored Normal file
View File

@@ -0,0 +1,84 @@
// Karma configuration
// Generated on Mon Nov 09 2015 18:53:12 GMT+0530 (IST)
process.env.CHROME_BIN = require('puppeteer').executablePath(); // eslint-disable-line no-process-env
module.exports = function (config) {
var configuration = {
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: '',
// frameworks to use
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
frameworks: ['mocha', 'browserify'],
// list of files / patterns to load in the browser
files: [
'../index.js',
'../test/unit/**/*.js'
],
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'../index.js': ['browserify'], // Mention path as per your test js folder
'../test/unit/**/*.js': ['browserify'] // Mention path as per your library js folder
},
// test results reporter to use
// possible values: 'dots', 'progress'
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
reporters: ['mocha'],
// web server port
port: 9876,
// the number of milliseconds to wait for an idle browser to come back up before bailing
browserNoActivityTimeout: 20000,
// enable / disable colors in the output (reporters and logs)
colors: true,
// level of logging
// one of: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
logLevel: config.LOG_WARN,
// enable / disable watching file and executing tests whenever any file changes
autoWatch: false,
// start these browsers
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
browsers: ['chrome_without_security'],
// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: true,
// Concurrency level
// how many browser should be started simultanous
concurrency: Infinity,
// Uncomment "karma-browserify" if you see an error like this:
// Error: No provider for "framework:browserify"! (Resolving: framework:browserify)
plugins: [
'karma-mocha',
'karma-chrome-launcher',
'karma-browserify',
'karma-mocha-reporter'
],
// Pass options to the client frameworks.
client: {
mocha: {
timeout: 10000 // 10 seconds
}
},
customLaunchers: {
chrome_without_security: {
base: 'ChromeHeadless',
flags: ['--disable-web-security']
}
}
};
config.set(configuration);
};

View File

@@ -0,0 +1,77 @@
var expect = require('chai').expect,
oauth = require('../../index'),
encode = oauth.percentEncode,
getAuthHeader = oauth.getAuthorizationHeader;
describe('getAuthorizationHeader()', function () {
it('should include all oauth1 params', function () {
var key,
params = {
oauth_signature_method: 'PLAINTEXT',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0',
oauth_callback: 'http://postman.com',
oauth_verifier: 'secret',
oauth_body_hash: 'xyz=',
oauth_signature: 'generatedSignature=='
},
authHeader = getAuthHeader(null, params);
for (key in params) {
expect(authHeader).to.include(`${key}="${encode(params[key])}"`);
}
});
it('should not encode params when disableParamsEncoding:true', function () {
var params = {
oauth_signature_method: 'PLAINTEXT',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0',
oauth_callback: 'http://postman.com',
oauth_verifier: 'secret',
oauth_body_hash: 'xyz=',
oauth_signature: 'generatedSignature=='
},
key,
authHeader = getAuthHeader(null, params, true);
for (key in params) {
expect(authHeader).to.include(`${key}="${params[key]}"`);
}
});
it('should add relm if provided', function () {
var realm = 'postman',
params = {
oauth_signature_method: 'PLAINTEXT',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
};
expect(getAuthHeader(realm, params)).to.include('realm="postman"');
});
it('should not include non-oauth1 params', function () {
var realm = 'postman',
params = {
oauth_signature_method: 'PLAINTEXT',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0',
random: 'non-oauth1 param'
};
expect(getAuthHeader(realm, params)).to.not.include('random');
});
});

View File

@@ -0,0 +1,273 @@
var expect = require('chai').expect,
sign = require('../../index').SignatureMethod.sign;
describe('SignatureMethod.sign()', function () {
it('should throw error for unsupported signature method', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'UNKNOWN'
}
},
accessor = {};
expect(function () {sign(message, accessor)}).to.throw('Unsupported signature method');
});
it('should generate correct PLAINTEXT signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'PLAINTEXT',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: 'beta'
},
signature = 'alpha&beta';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC-SHA1 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA1',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: 'beta'
},
signature= 'kst31ZZPywC/vi+UVOU93hgdEMg=';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC-SHA256 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA256',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: 'beta'
},
signature= 'H3w+AlCMRPSZNn8gOI6GyvEXol6R0jVqNw4rr58nZmg=';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC-SHA512 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: 'beta'
},
signature = 'GF7ju0CZzAT7dM7cYx8z1km5MOrrjaQ+cJY00CX1sz052gIOOWacY55NcJkqSi28OQqcO6mhdxTOnO60uH4cEw==';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct RSA-SHA1 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'RSA-SHA1',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
privateKey: '-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgFKLvzM9zbm3I0+HWcHlBSqpfRY/bKs6NDLclERrzfnReFV4utjkhjaEQPPT6tHVHKrZkcxmIgwe3XrkJkUjcuingXIF+Fc3KpY61qJ4HSM50qIuHdi+C5YfuXwNrh6OOeZAhhqgSw2e2XqPfATbkYYwpIFpdVdcH/Pb2ynpd6VXAgMBAAECgYAbQE+LFyhH25Iou0KCpJ0kDHhjU+UIUlrRP8kjHYQOqXzUmtr0p903OkpHNPsc8wJX1SQxGra60aXE4HVR9fYFQNliAnSmA/ztGR4ddnirK1Gzog4y2OOkicTdSqJ/1XXtTEDSRkA0Z2DIqcWgudeSDzVjUpreYwQ/rCEZbi50AQJBAJcf9wi5bU8tdZUCg3/8MNDwHhr4If4V/9kmhsgNp+M/9tHwCbD05hCbiGS7g58DPF+6V2K30qQYq7yvBP8Te4ECQQCL1GhX/YwkD6rexi0E1bjz+RqhNLTR9kexkTfSYmL6zHeeIFSH8ROioGOJMU51lUtMNkkrKEeki5SZpkfaQOzXAkAvBnJPU6vQ7HtfH8YdiDMEgQNNLxMcxmmzf4qHK8CnNRsvnnrVho8kcdFSTwsY6t/Zhdl1TXANQeQGtYtfeAeBAkEAhUB351JSWJMtrHqCsFbTmHxNKk7F+kiObeMLpUvpM0PiwifhJmNQ6Oubr0Pzlw4c4ZXiCGSsUVxK0lmpo423pQJATYDoxVhZrKA3xDAifWoyxbyxf/WXtUGDaAOuZc/naVN5TKiqaEO6G+k3NpmOXNKsYU/Zd9e6P/TnfU74TyDDDA==\n-----END RSA PRIVATE KEY-----'
},
signature = 'Tok9L4dAnBWzd0KNgI9/kR3fhfE2keZybvf8UYPB1/bbdQsMHQRQYL1Ui1V94ZBlijeQmyHo67XLJe1zGwCTK5fAGSOtQU0mfvj4AvG4sG5SVg8auWgm5BQt/Lhe9cQJpVNqRhV8rMxOZ6mF9STpDGSx80MY2+FG4eThexe0vkQ=';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct RSA-SHA256 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'RSA-SHA256',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
privateKey: '-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgFKLvzM9zbm3I0+HWcHlBSqpfRY/bKs6NDLclERrzfnReFV4utjkhjaEQPPT6tHVHKrZkcxmIgwe3XrkJkUjcuingXIF+Fc3KpY61qJ4HSM50qIuHdi+C5YfuXwNrh6OOeZAhhqgSw2e2XqPfATbkYYwpIFpdVdcH/Pb2ynpd6VXAgMBAAECgYAbQE+LFyhH25Iou0KCpJ0kDHhjU+UIUlrRP8kjHYQOqXzUmtr0p903OkpHNPsc8wJX1SQxGra60aXE4HVR9fYFQNliAnSmA/ztGR4ddnirK1Gzog4y2OOkicTdSqJ/1XXtTEDSRkA0Z2DIqcWgudeSDzVjUpreYwQ/rCEZbi50AQJBAJcf9wi5bU8tdZUCg3/8MNDwHhr4If4V/9kmhsgNp+M/9tHwCbD05hCbiGS7g58DPF+6V2K30qQYq7yvBP8Te4ECQQCL1GhX/YwkD6rexi0E1bjz+RqhNLTR9kexkTfSYmL6zHeeIFSH8ROioGOJMU51lUtMNkkrKEeki5SZpkfaQOzXAkAvBnJPU6vQ7HtfH8YdiDMEgQNNLxMcxmmzf4qHK8CnNRsvnnrVho8kcdFSTwsY6t/Zhdl1TXANQeQGtYtfeAeBAkEAhUB351JSWJMtrHqCsFbTmHxNKk7F+kiObeMLpUvpM0PiwifhJmNQ6Oubr0Pzlw4c4ZXiCGSsUVxK0lmpo423pQJATYDoxVhZrKA3xDAifWoyxbyxf/WXtUGDaAOuZc/naVN5TKiqaEO6G+k3NpmOXNKsYU/Zd9e6P/TnfU74TyDDDA==\n-----END RSA PRIVATE KEY-----'
},
signature = 'A8ayuJe1RJd0zL4R8aBgbEY0PFviN6bk8G4QqAcGPSZfeGjFjwBlXWFysNy5iR8mm3/yWGboUMHWmtyPDtOnL2cJTc8fKhXwITFi7FmsUeA5cBK/HdWYoHLdWuNIZgDHsv8qvZCS4QD4qIILiys4uFK+W1br0zSJR9bsOTIZLng=';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct RSA-SHA512 signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'RSA-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
privateKey: '-----BEGIN RSA PRIVATE KEY-----\nMIICWwIBAAKBgFKLvzM9zbm3I0+HWcHlBSqpfRY/bKs6NDLclERrzfnReFV4utjkhjaEQPPT6tHVHKrZkcxmIgwe3XrkJkUjcuingXIF+Fc3KpY61qJ4HSM50qIuHdi+C5YfuXwNrh6OOeZAhhqgSw2e2XqPfATbkYYwpIFpdVdcH/Pb2ynpd6VXAgMBAAECgYAbQE+LFyhH25Iou0KCpJ0kDHhjU+UIUlrRP8kjHYQOqXzUmtr0p903OkpHNPsc8wJX1SQxGra60aXE4HVR9fYFQNliAnSmA/ztGR4ddnirK1Gzog4y2OOkicTdSqJ/1XXtTEDSRkA0Z2DIqcWgudeSDzVjUpreYwQ/rCEZbi50AQJBAJcf9wi5bU8tdZUCg3/8MNDwHhr4If4V/9kmhsgNp+M/9tHwCbD05hCbiGS7g58DPF+6V2K30qQYq7yvBP8Te4ECQQCL1GhX/YwkD6rexi0E1bjz+RqhNLTR9kexkTfSYmL6zHeeIFSH8ROioGOJMU51lUtMNkkrKEeki5SZpkfaQOzXAkAvBnJPU6vQ7HtfH8YdiDMEgQNNLxMcxmmzf4qHK8CnNRsvnnrVho8kcdFSTwsY6t/Zhdl1TXANQeQGtYtfeAeBAkEAhUB351JSWJMtrHqCsFbTmHxNKk7F+kiObeMLpUvpM0PiwifhJmNQ6Oubr0Pzlw4c4ZXiCGSsUVxK0lmpo423pQJATYDoxVhZrKA3xDAifWoyxbyxf/WXtUGDaAOuZc/naVN5TKiqaEO6G+k3NpmOXNKsYU/Zd9e6P/TnfU74TyDDDA==\n-----END RSA PRIVATE KEY-----'
},
signature = 'ArsxDvfXOVTQBfXLbNEkWEm+xfEnzAQLM7RET04cMtHrrcm80mWWMcsMN1jykR8ZnXVsVufO565cJQgWqBJ2aWQgUa4Yu2RQWGLuIYwnaiX6TxysO/ZuV5zDlTWQdQpjUmFWKuixZouMDH7CiV37PJLKkYaJzQaGTamHsJiUubE=';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC signature without tokenSecret', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: undefined
},
signature = 'zWgwoT1cmeYYmDXiEo9ylEAwu9h7qu/EG+Ylj6n0cedV9aK/gMkgGmTylrAbFpCmEKWo6wwfyvh+YFuJl2+1EQ==';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC signature without consumerSecret', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: undefined,
tokenSecret: 'beta'
},
signature = 'gyU8TWOoUeCIWgduAZvQ7WpA7hcvdvfvulksm8vyR17fQt+ZwuwnL6TSZCXbCtV7gmTi3Ggr6hO/UjEItG2qew==';
expect(sign(message, accessor)).to.eql(signature);
});
it('should generate correct HMAC signature without consumerSecret and tokenSecret', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'HMAC-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
consumerSecret: 'alpha',
tokenSecret: undefined
},
signature = 'zWgwoT1cmeYYmDXiEo9ylEAwu9h7qu/EG+Ylj6n0cedV9aK/gMkgGmTylrAbFpCmEKWo6wwfyvh+YFuJl2+1EQ==';
expect(sign(message, accessor)).to.eql(signature);
});
it('should throw error if private key is absent for RSA signature', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'RSA-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
privateKey: undefined
};
expect(function () {sign(message, accessor)}).to.throw();
});
it('should throw error if private key is not in valid PEM format', function () {
var message = {
action: 'https://postman.com/path',
method: 'GET',
parameters: {
oauth_signature_method: 'RSA-SHA512',
oauth_consumer_key: 'foo',
oauth_token: 'bar',
oauth_nonce: 'baz',
oauth_timestamp: '1588771035',
oauth_version: '1.0'
}
},
accessor = {
privateKey: 'invalid private key!!'
};
expect(function () {sign(message, accessor)}).to.throw();
});
});