├── .eslintignore ├── .eslintrc ├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── codecov.yml ├── gulpfile.js ├── index.js ├── lib └── loopback-ssl.js ├── package.json └── test ├── fixtures ├── certs │ ├── local.crt.pem │ ├── local.csr │ └── local.pem ├── configs │ ├── config-1.json │ ├── config-2.json │ ├── config-3.json │ ├── config-4.json │ ├── config-5.json │ ├── config-6.json │ ├── config-7.json │ └── config-8.json ├── server-ssl │ ├── boot │ │ └── root.js │ ├── component-config.json │ ├── config.json │ ├── datasources.json │ ├── middleware.json │ ├── model-config.json │ ├── models │ │ ├── note.js │ │ └── note.json │ └── server.js └── server │ ├── boot │ └── root.js │ ├── component-config.json │ ├── config.json │ ├── datasources.json │ ├── middleware.json │ ├── model-config.json │ ├── models │ ├── note.js │ └── note.json │ └── server.js ├── loopback-http-test.js ├── loopback-https-test.js ├── loopback-ssl-config-test.js └── loopback-ssl-test.js /.eslintignore: -------------------------------------------------------------------------------- 1 | /client/ 2 | /test/ 3 | /node_modules/ 4 | /log/ 5 | gulpfile.js 6 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "loopback", 3 | "rules": { 4 | "max-len": ["error", 100, 4, { 5 | "ignoreComments": true, 6 | "ignoreUrls": true, 7 | "ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)" 8 | }] 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | 11 | # Directory for instrumented libs generated by jscoverage/JSCover 12 | lib-cov 13 | 14 | # Coverage directory used by tools like istanbul 15 | coverage 16 | 17 | # nyc test coverage 18 | .nyc_output 19 | coverage 20 | report 21 | reports 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # node-waf configuration 27 | .lock-wscript 28 | 29 | # Compiled binary addons (http://nodejs.org/api/addons.html) 30 | build/Release 31 | 32 | # Dependency directories 33 | node_modules 34 | jspm_packages 35 | 36 | # Optional npm cache directory 37 | .npm 38 | 39 | # Optional REPL history 40 | .node_repl_history 41 | 42 | # Editor specific files 43 | .idea 44 | 45 | #archives 46 | *.zip 47 | *.tgz 48 | *.tar.gz -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | env: 4 | - CODECOV_TOKEN="565f4dce-707a-4fda-a467-ffcc4e24b661" 5 | 6 | node_js: 7 | - "8" 8 | - "6" 9 | - "4" 10 | 11 | before_install: 12 | - npm install -g eslint 13 | - npm install -g eslint-config-loopback 14 | - npm install -g istanbul 15 | - npm install -g codecov 16 | 17 | script: 18 | - gulp build 19 | 20 | after_success: 21 | - bash <(curl -s https://codecov.io/bash) 22 | - gulp codacy 23 | 24 | branches: 25 | only: 26 | - master 27 | - development 28 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Yantrashala 2 | 3 | We welcome contributions, but request you follow these guidelines. 4 | - [Raising issues](#raising-issues) 5 | - [Feature requests](#feature-requests) 6 | - [Pull-Requests](#pull-requests) 7 | 8 | This project adheres to the [Contributor Covenant 1.4](http://contributor-covenant.org/version/1/4/). 9 | By participating, you are expected to uphold this code. Please report unacceptable 10 | behavior to any of the [project's core team]. 11 | 12 | ## Raising issues 13 | 14 | Please raise any bug reports on the relevant project's issue tracker. Be sure to 15 | search the list to see if your issue has already been raised. 16 | 17 | A good bug report is one that make it easy for us to understand what you were 18 | trying to do and what went wrong. 19 | 20 | Provide as much context as possible so we can try to recreate the issue. 21 | If possible, include the relevant part of your flow. To do this, select the 22 | relevant nodes, press Ctrl-E and copy the flow data from the Export dialog. 23 | 24 | At a minimum, please include: 25 | 26 | - Version of loopback-ssl - either release number if you downloaded a zip, or the first few lines of `git log` if you are cloning the repository directly. 27 | - Version of node.js - what does `node -v` say? 28 | 29 | ## Feature requests 30 | 31 | For feature requests, please raise them on the [issues page](https://github.com/yantrashala/loopback-ssl/issues) with label "enhancement". 32 | 33 | ## Pull-Requests 34 | 35 | If you want to raise a pull-request with a new feature, or a refactoring 36 | of existing code, it may well get rejected if you haven't discussed it on 37 | the [issues page](https://github.com/yantrashala/loopback-ssl/issues) first. 38 | 39 | ### Coding standards 40 | 41 | Please ensure you follow the coding standards used through-out the existing 42 | code base. Some basic rules include: 43 | 44 | - all files must have the Apache license in the header. 45 | - indent with 4-spaces, no tabs. No arguments. 46 | - opening brace on same line as `if`/`for`/`function` and so on, closing brace 47 | on its own line. 48 | 49 | ## Attribution 50 | 51 | This Contributing article is adapted from node-red, version 0.16.2, available at https://github.com/node-red/node-red/blob/master/CODE_OF_CONDUCT.md 52 | 53 | # Yantrashala - Contributor Covenant Code of Conduct 54 | 55 | ## Our Pledge 56 | 57 | In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. 58 | 59 | ## Our Standards 60 | 61 | ### Examples of behavior that contributes to creating a positive environment include: 62 | - Using welcoming and inclusive language 63 | - Being respectful of differing viewpoints and experiences 64 | - Gracefully accepting constructive criticism 65 | - Focusing on what is best for the community 66 | - Showing empathy towards other community members 67 | 68 | ### Examples of unacceptable behavior by participants include: 69 | - The use of sexualized language or imagery and unwelcome sexual attention or advances 70 | - Trolling, insulting/derogatory comments, and personal or political attacks 71 | - Public or private harassment 72 | - Publishing others' private information, such as a physical or electronic address, without explicit permission 73 | - Other conduct which could reasonably be considered inappropriate in a professional setting 74 | 75 | ## Our Responsibilities 76 | 77 | Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. 78 | 79 | Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. 80 | 81 | ## Scope 82 | 83 | This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. 84 | 85 | ## Enforcement 86 | 87 | Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [INSERT EMAIL ADDRESS]. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. 88 | 89 | Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. 90 | 91 | ## Attribution 92 | 93 | This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4. 94 | 95 | [homepage]: http://contributor-covenant.org 96 | [version]: http://contributor-covenant.org/version/1/4/ 97 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # loopback-ssl 2 | 3 | Node module to enable HTTPS/SSL in a [loopback] application with simple configurations. The module also enables trusted peer authentication. 4 | 5 | [![Travis](https://img.shields.io/travis/yantrashala/loopback-ssl.svg?style=plastic)](https://img.shields.io/travis/yantrashala/loopback-ssl/master.svg) [![npm](https://img.shields.io/npm/dm/loopback-ssl.svg?style=plastic)](https://nodei.co/npm/loopback-ssl/) [![npm](https://img.shields.io/npm/dt/loopback-ssl.svg?style=plastic)](https://nodei.co/npm/loopback-ssl/) [![npm](https://img.shields.io/npm/l/loopback-ssl.svg?style=plastic)](https://github.com/yantrashala/loopback-ssl) [![David](https://img.shields.io/david/dev/yantrashala/loopback-ssl.svg?style=plastic)](https://www.npmjs.com/package/loopback-ssl) [![David](https://img.shields.io/david/yantrashala/loopback-ssl.svg?style=plastic)](https://www.npmjs.com/package/loopback-ssl) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/74ddc643152f4f439d6ef7d99ed9d5f6)](https://www.codacy.com/app/siddhartha-lahiri/loopback-ssl?utm_source=github.com&utm_medium=referral&utm_content=yantrashala/loopback-ssl&utm_campaign=Badge_Grade) [![Join the chat at https://gitter.im/yantrashala/loopback-ssl](https://badges.gitter.im/yantrashala/loopback-ssl.svg)](https://gitter.im/yantrashala/loopback-ssl?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 6 | 7 | 8 | # Features 9 | - Enable SSL in Loopback application 10 | - Enable mutual SSL authentication in Loopback 11 | 12 | # Setup 13 | 14 | ## Install [loopback]: 15 | ```bash 16 | 17 | # install loopback-cli 18 | npm install -g loopback-cli 19 | 20 | # create project directory 21 | mkdir 22 | cd 23 | 24 | # create loopback application 25 | lb 26 | # ? What's the name of your application? 27 | # ? Which version of LoopBack would you like to use? 3.x (current) 28 | # ? What kind of application do you have in mind? notes 29 | ``` 30 | 31 | ## Install [loopback-ssl]: 32 | ```js 33 | npm install loopback-ssl --save 34 | ``` 35 | 36 | ## Setup Configuration: 37 | Add the following lines of configuration in 'config.json' in location "\/server/config.json" 38 | ```js 39 | "httpMode": false, 40 | "certConfig": { 41 | "path": "/certificate/path/", 42 | "key": "local.pem", 43 | "cert": "local.crt.pem", 44 | "ca": [], 45 | "requestCert": false, 46 | "rejectUnauthorized": false 47 | } 48 | ``` 49 | 50 | ## Configure server.js 51 | Edit the server.js located at "\/server/server.js". Replace the code in server.js with the code below (assuming no prior customizations to the file) 52 | 53 | ### server.js 54 | ```js 55 | var loopback = require('loopback'); 56 | var boot = require('loopback-boot'); 57 | var loopbackSSL = require('loopback-ssl'); 58 | 59 | var app = module.exports = loopback(); 60 | 61 | boot(app, __dirname, function(err) { 62 | if (err) throw err; 63 | }); 64 | 65 | return loopbackSSL.startServer(app); 66 | ``` 67 | # Configuration options 68 | 69 | ## Option 1: HTTP (default loopback configuration) 70 | The configuration entry `"httpMode": true` will enable http (disable https). In this mode the `"certConfig": {..}` configuration is not required and can be omitted. 71 | ```js 72 | "httpMode": true 73 | ``` 74 | 75 | ## Option 2: HTTPS: Loading certificates from files 76 | The configuration entry `"httpMode": false` will enable https. 77 | ```js 78 | "httpMode": false, 79 | "certConfig": { 80 | "path": "/certificate/path/", 81 | "key": "serverkey.pem", 82 | "cert": "server-certificate.pem", 83 | "ca": [], 84 | "requestCert": false, 85 | "rejectUnauthorized": false 86 | } 87 | ``` 88 | - `"path"` - folder location where the certificates files will be installed 89 | - `"key"` - server key 90 | - `"cert"` - server certificate 91 | 92 | ## Option 3: HTTPS: Loading certificates from files & Mutual SSL authentication 93 | Will only work with pre-generated certificate files 94 | ```js 95 | "httpMode": false, 96 | "certConfig": { 97 | "path": "/certificate/path/", 98 | "key": "serverkey.pem", 99 | "cert": "server-certificate.pem", 100 | "ca": [ 101 | "client-certificate-to-validate.pem" 102 | ], 103 | "requestCert": true, 104 | "rejectUnauthorized": true 105 | } 106 | ``` 107 | - The `ca[]` configuration contains the list of client certificates which the server will authenticate 108 | - `"requestCert": true` enables mutual SSL authentication 109 | - `"rejectUnauthorized": true` enables the authenticity and validity check of client keys 110 | - For any reason, if the client certificate is a self signed certificate, `"rejectUnauthorized":` can be set to `false`. 111 | 112 | 113 | 114 | # Contributing 115 | 116 | - Want to contribute? Great! Please check this [guide](https://github.com/yantrashala/loopback-ssl/blob/master/CONTRIBUTING.md). 117 | - Fork it ( https://github.com/yantrashala/loopback-ssl/fork ) 118 | - Create your feature branch (git checkout -b new-feature) 119 | - Commit your changes (git commit -am 'Add some feature') 120 | - Push to the branch (git push origin new-feature) 121 | - Create new Pull Request 122 | 123 | # License 124 | 125 | [MIT](./LICENSE). 126 | 127 | # See Also 128 | - [Self Signed Certificates - Example][self_signed] 129 | 130 | [loopback]: http://loopback.io 131 | [loopback-ssl]: https://www.npmjs.com/package/loopback-ssl 132 | [trusted_peer]: https://github.com/coolaj86/nodejs-ssl-trusted-peer-example 133 | [self_signed]: https://github.com/coolaj86/nodejs-self-signed-certificate-example 134 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | codecov: 2 | token: 565f4dce-707a-4fda-a467-ffcc4e24b661 3 | notify: 4 | require_ci_to_pass: yes 5 | 6 | coverage: 7 | precision: 2 8 | round: down 9 | range: "70...100" 10 | 11 | status: 12 | project: yes 13 | patch: yes 14 | changes: no 15 | 16 | parsers: 17 | gcov: 18 | branch_detection: 19 | conditional: yes 20 | loop: yes 21 | method: no 22 | macro: no 23 | 24 | comment: 25 | layout: "reach, diff, flags, files, footer" 26 | behavior: default 27 | require_changes: no 28 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var eslint = require('gulp-eslint'); 5 | var shrinkwrap = require('gulp-shrinkwrap'); 6 | var gulpNSP = require('gulp-nsp'); 7 | var gulpIf = require('gulp-if'); 8 | var mocha = require('gulp-mocha'); 9 | var istanbul = require('gulp-istanbul'); 10 | var exit = require('gulp-exit'); 11 | var codacy = require('gulp-codacy'); 12 | 13 | gulp.task('lint', () => { 14 | return gulp.src(['index.js', 'lib/loopback-ssl.js', '!node_modules/**']) 15 | .pipe(eslint()) 16 | .pipe(eslint.format()) 17 | .pipe(eslint.failAfterError()); 18 | }); 19 | 20 | gulp.task('nsp', function(cb) { 21 | return gulpNSP({ 22 | shrinkwrap: __dirname + '/npm-shrinkwrap.json', 23 | package: __dirname + '/package.json', 24 | output: 'default', 25 | stopOnError: false, 26 | }, cb); 27 | }); 28 | 29 | gulp.task('shrinkwrap', function() { 30 | return gulp.src('./package.json') 31 | .pipe(shrinkwrap.lock()) 32 | .pipe(gulp.dest('./')); 33 | }); 34 | 35 | function isFixed(file) { 36 | return file.eslint != null && file.eslint.fixed; 37 | } 38 | 39 | gulp.task('test', function(cb) { 40 | gulp.src([ 41 | 'index.js', 42 | 'lib/**/*.js']) 43 | .pipe(istanbul()) 44 | .pipe(istanbul.hookRequire()) 45 | .on('finish', function() { 46 | gulp.src([ 47 | 'test/**/*-test.js']) 48 | .pipe(mocha({timeout: 1000})) 49 | .pipe(istanbul.writeReports()) 50 | .on('end', function() { 51 | cb(); 52 | }) 53 | .pipe(exit()); 54 | }); 55 | }); 56 | 57 | gulp.task('codacy', function codacyTask() { 58 | return gulp 59 | .src(['./coverage/lcov.info'], {read: false}) 60 | .pipe(codacy({ 61 | token: '6364b0b53a1a4d5795c5aa4f2bd66857', 62 | })) 63 | ; 64 | }); 65 | 66 | gulp.task('default', [ 67 | 'test', 68 | 'lint', 69 | 'nsp', 70 | 'codacy', 71 | ], function() {}); 72 | 73 | gulp.task('build', ['default']); 74 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var loopbackSSL = require('./lib/loopback-ssl'); 4 | const debug = require('debug')('loopback-ssl:index'); 5 | 6 | /** 7 | * 8 | * @param app 9 | */ 10 | var startServer = function(app) { 11 | if (app.get('httpMode')) { 12 | return loopbackSSL.startHttp(app); 13 | } else { 14 | return loopbackSSL.startHttps(app); 15 | } 16 | }; 17 | 18 | module.exports.startServer = startServer; 19 | -------------------------------------------------------------------------------- /lib/loopback-ssl.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var https = require('https'); 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | const debug = require('debug')('loopback-ssl:lib'); 7 | 8 | /** 9 | * 10 | * @param app 11 | * @returns {*} 12 | */ 13 | var startHttp = function(app) { 14 | debug('Starting in HTTP mode'); 15 | var baseUrl = 'http://' + app.get('host') + ':' + app.get('port'); 16 | debug('baseUrl', baseUrl); 17 | return app.listen(app.get('port'), appStartEvent(app, baseUrl)); 18 | }; 19 | 20 | /** 21 | * 22 | * @param app 23 | * @returns {*} 24 | */ 25 | var startHttps = function(app) { 26 | var cfg = app.get('certConfig'); 27 | debug('Starting in HTTPS mode'); 28 | var options = null; 29 | try { 30 | options = getServerOptions(cfg); 31 | debug('Config Options: ', options); 32 | } catch (err) { 33 | console.error('Error reading certificates', err.stack); 34 | process.exit(1); 35 | } 36 | var server = https.createServer(options, app); 37 | var baseUrl = 'https://' + app.get('host') + ':' + app.get('port'); 38 | debug('baseUrl', baseUrl); 39 | return server.listen(app.get('port'), appStartEvent(app, baseUrl)); 40 | }; 41 | 42 | /** 43 | * 44 | * @param app 45 | * @param baseUrl 46 | */ 47 | var appStartEvent = function(app, baseUrl) { 48 | app.emit('started'); 49 | console.log('Web server listening at: %s', baseUrl); 50 | if (app.get('loopback-component-explorer')) { 51 | var explorerPath = app.get('loopback-component-explorer').mountPath; 52 | console.log('Browse your REST API at %s%s', baseUrl, explorerPath); 53 | } 54 | }; 55 | 56 | /** 57 | * 58 | * @param cfg 59 | * @returns {*} 60 | */ 61 | var getServerOptions = function(cfg) { 62 | var options = {}; 63 | 64 | var certPath = path.resolve(cfg.path); 65 | debug('Starting in HTTPS mode - Reading certs from path', certPath); 66 | 67 | // create options which needs processing 68 | options = { 69 | key: fs.readFileSync(path.join(certPath, cfg.key)), 70 | cert: fs.readFileSync(path.join(certPath, cfg.cert)), 71 | ca: [], 72 | }; 73 | 74 | for (var i = 0; i < cfg.ca.length; i++) { 75 | options.ca.push(fs.readFileSync(path.join(certPath, cfg.ca[i]))); 76 | } 77 | 78 | // delete config keys which is no longer needed 79 | delete cfg.path; 80 | delete cfg.key; 81 | delete cfg.cert; 82 | delete cfg.ca; 83 | 84 | // merge processed options with rest of https config and return all 85 | return Object.assign(options, cfg); 86 | }; 87 | 88 | module.exports.startHttp = startHttp; 89 | module.exports.startHttps = startHttps; 90 | module.exports.getServerOptions = getServerOptions; 91 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "loopback-ssl", 3 | "version": "1.0.4", 4 | "description": "Node module to enable HTTPS/SSL in a loopback application with simple configurations. The module in addition enables trusted peer authentication.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "mocha test", 8 | "lint": "eslint ." 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/yantrashala/loopback-ssl.git" 13 | }, 14 | "keywords": [ 15 | "loopback", 16 | "ssl", 17 | "mutual authentication", 18 | "two way ssl", 19 | "trusted peer", 20 | "certificate", 21 | "https" 22 | ], 23 | "author": "Siddhartha Lahiri (https://github.com/yantrashala)", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/yantrashala/loopback-ssl/issues" 27 | }, 28 | "homepage": "https://github.com/yantrashala/loopback-ssl#readme", 29 | "devDependencies": { 30 | "chai": "^4.1.0", 31 | "codacy-coverage": "^2.0.2", 32 | "codecov": "^2.2.0", 33 | "compression": "^1.7.0", 34 | "cors": "^2.8.3", 35 | "coveralls": "^2.13.1", 36 | "eslint-config-loopback": "8.0.0", 37 | "gulp": "3.9.1", 38 | "gulp-codacy": "1.0.0", 39 | "gulp-eslint": "^4.0.0", 40 | "gulp-exit": "0.0.2", 41 | "gulp-if": "2.0.2", 42 | "gulp-istanbul": "^1.1.2", 43 | "gulp-mocha": "^4.3.1", 44 | "gulp-nsp": "2.4.2", 45 | "gulp-shrinkwrap": "2.0.3", 46 | "helmet": "1.3.0", 47 | "loopback": "2.36.0", 48 | "loopback-boot": "^2.25.0", 49 | "loopback-component-explorer": "2.7.0", 50 | "loopback-datasource-juggler": "2.53.0", 51 | "loopback-testing": "1.4.0", 52 | "mocha": "^3.4.2", 53 | "mocha-lcov-reporter": "1.3.0", 54 | "serve-favicon": "^2.4.3", 55 | "shrinkwrap": "0.4.0", 56 | "tape": "^4.7.0" 57 | }, 58 | "dependencies": { 59 | "debug": "^2.6.8" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/fixtures/certs/local.crt.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIEdzCCA1+gAwIBAgIJAPEegzvGoJ3oMA0GCSqGSIb3DQEBCwUAMIGDMQswCQYD 3 | VQQGEwJJTjELMAkGA1UECBMCTUExEDAOBgNVBAoTB1NhcGllbnQxDzANBgNVBAcT 4 | BkJvc3RvbjESMBAGA1UEAxMJbG9jYWxob3N0MQwwCgYDVQQLEwNkZXYxIjAgBgkq 5 | hkiG9w0BCQEWE3NsYWhpcmlAc2FwaWVudC5jb20wHhcNMTYwNzAxMTM1MjM1WhcN 6 | MTcwNzAxMTM1MjM1WjCBgzELMAkGA1UEBhMCSU4xCzAJBgNVBAgTAk1BMRAwDgYD 7 | VQQKEwdTYXBpZW50MQ8wDQYDVQQHEwZCb3N0b24xEjAQBgNVBAMTCWxvY2FsaG9z 8 | dDEMMAoGA1UECxMDZGV2MSIwIAYJKoZIhvcNAQkBFhNzbGFoaXJpQHNhcGllbnQu 9 | Y29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzwOTvMh8fK6ieG+w 10 | QaSSxaZJXd10wjV0T5uPpLYsbA4/ZDlVFqDAVNvlvgyQJ0//0/0zjOkhlqoL3ZBp 11 | WBwNstOO4CoHNOtvTD0SS8O0+dfAj7nz/vJN6iOqukSmb9KA49kTP1M15nT5zF27 12 | uSa7cJGcq/+M4AJIzOQ5UgnHhBhPBb8b0sxrqGE+hheZWduPu7c3Zmhdo6LZaMMu 13 | xrEfK//HD4rIPssa679O8DC1ZlrqOLby6hON5T4WbMJN81YHS7H8gXtETupUpp+m 14 | VcNfakn8i1UYJKy7W9Hfdx0ybxMLODqP4AJYQQuDOUrA7qQcMMOSlWjkFB/zckI/ 15 | N3vGNwIDAQABo4HrMIHoMB0GA1UdDgQWBBRIm+7LKOPq0mj7xsDcA8p/pWG/3TCB 16 | uAYDVR0jBIGwMIGtgBRIm+7LKOPq0mj7xsDcA8p/pWG/3aGBiaSBhjCBgzELMAkG 17 | A1UEBhMCSU4xCzAJBgNVBAgTAk1BMRAwDgYDVQQKEwdTYXBpZW50MQ8wDQYDVQQH 18 | EwZCb3N0b24xEjAQBgNVBAMTCWxvY2FsaG9zdDEMMAoGA1UECxMDZGV2MSIwIAYJ 19 | KoZIhvcNAQkBFhNzbGFoaXJpQHNhcGllbnQuY29tggkA8R6DO8agnegwDAYDVR0T 20 | BAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEATtrvfatOmvy1yTaX6yEKIya11evr 21 | FiZcfWUoatztkbE1kW76joiKSF4I3p9YwCUEvjwo0B+3VtGokoPWqmYlnt/WX/B3 22 | bjOWMq5HNNFsxDyHrllRqAi/mafJDWptR01yEZ8UC0ghqoZ5AOPxeNHH/s7zSgqX 23 | 22IoE+mAL+Hap4gDpWpBg/FDFqWFvTFk4yKlz7yAodkR59+Xoko4deLjMXBbtg8+ 24 | ZxZTl/WN+0ab74oglCVHJmqNZ8/Gi7mUfKl8YgKoSmBEsgJQ/wY09cWOodE8SFEE 25 | 51EHsxt+F9wKrikOXn8Na0IdZTIQR66L9eAu+oiYsc5Now8sdwcj+AAfjw== 26 | -----END CERTIFICATE----- 27 | -------------------------------------------------------------------------------- /test/fixtures/certs/local.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIICyTCCAbECAQAwgYMxCzAJBgNVBAYTAklOMQswCQYDVQQIEwJNQTEQMA4GA1UE 3 | ChMHU2FwaWVudDEPMA0GA1UEBxMGQm9zdG9uMRIwEAYDVQQDEwlsb2NhbGhvc3Qx 4 | DDAKBgNVBAsTA2RldjEiMCAGCSqGSIb3DQEJARYTc2xhaGlyaUBzYXBpZW50LmNv 5 | bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM8Dk7zIfHyuonhvsEGk 6 | ksWmSV3ddMI1dE+bj6S2LGwOP2Q5VRagwFTb5b4MkCdP/9P9M4zpIZaqC92QaVgc 7 | DbLTjuAqBzTrb0w9EkvDtPnXwI+58/7yTeojqrpEpm/SgOPZEz9TNeZ0+cxdu7km 8 | u3CRnKv/jOACSMzkOVIJx4QYTwW/G9LMa6hhPoYXmVnbj7u3N2ZoXaOi2WjDLsax 9 | Hyv/xw+KyD7LGuu/TvAwtWZa6ji28uoTjeU+FmzCTfNWB0ux/IF7RE7qVKafplXD 10 | X2pJ/ItVGCSsu1vR33cdMm8TCzg6j+ACWEELgzlKwO6kHDDDkpVo5BQf83JCPzd7 11 | xjcCAwEAAaAAMA0GCSqGSIb3DQEBCwUAA4IBAQCTETEYMtDRocMKbKUIKog7p0BX 12 | d2vDvhVxzBoWvY9y/yYfz9HViuCmv6yr+z/LZkkJX0nj6xd0rnYF6Zu5wIym1+tR 13 | i1rFN/Nn+wl0/ICog+NRA4JbaEOTYAhTKEIytVCLnK2TpWIxYOGLvlHm8B5ahLb1 14 | KDMdI5zVSccvdMkhKMyIh/S9lnsVupx5AXfyBKvYO7ZVNovzsmdIN3tMXZoypZc3 15 | Ef3SUQPnw2mvxKH+zPRDtZBQYHeCxRQAxAzXx1CMYP7ovF3AE+sP4msfGbFqWDKl 16 | v+5WEtbpQ4z+xE8AHnBt/MunbotWQc/t5xVaO8czjIcnCXYWuNY83n59mwwY 17 | -----END CERTIFICATE REQUEST----- 18 | -------------------------------------------------------------------------------- /test/fixtures/certs/local.pem: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEAzwOTvMh8fK6ieG+wQaSSxaZJXd10wjV0T5uPpLYsbA4/ZDlV 3 | FqDAVNvlvgyQJ0//0/0zjOkhlqoL3ZBpWBwNstOO4CoHNOtvTD0SS8O0+dfAj7nz 4 | /vJN6iOqukSmb9KA49kTP1M15nT5zF27uSa7cJGcq/+M4AJIzOQ5UgnHhBhPBb8b 5 | 0sxrqGE+hheZWduPu7c3Zmhdo6LZaMMuxrEfK//HD4rIPssa679O8DC1ZlrqOLby 6 | 6hON5T4WbMJN81YHS7H8gXtETupUpp+mVcNfakn8i1UYJKy7W9Hfdx0ybxMLODqP 7 | 4AJYQQuDOUrA7qQcMMOSlWjkFB/zckI/N3vGNwIDAQABAoIBAEUkO7bk+3clWMyC 8 | +UqjbgYnyP9Z1QJ8mhFwsqRf2CxrAc82uu2o2TQ+kdhNF+SZeqfSPOKGhxpsRzRE 9 | ZHryO70Lnf/O6cNKE01SZIb7obmEzyLyB8WSJmXabc5y2Wgl1bjEKwKOh0UmsrwI 10 | XoezoQ0zBTIJU4MKIEiWvXJiI8pBPmKmMuweqsXEGY2ontOc1I/w0Cm8ToUst1MT 11 | FXQwMH98ZrARIlpAW5sY+UHMI5XuxXnrJa5mXFosdYIwvqhH8iAqlWHEo8FyV7q3 12 | owpRVdAEevok+FW6AVR5AEDrqK4IPlD5ROr+252TkuBVzng0dzm61ccuueG98mT0 13 | nTHUfTECgYEA7S31RrybZQZTfasx3yM3e558flJKPF57ktlm/jHO9Bn6x6qIvXCm 14 | inEe7gfAddHMIYdy0+gRe2zkyLHwVzbZt4/dbKdCuj3fyEHKNB+7+vKqwiG8nqmE 15 | BbqW6MLuvU8lwgnolyJkmGgXofKxDDCceNK9Q7iIikpeQTiwkbbs1+kCgYEA33DW 16 | wsGdiW3S3Qg0BbFRVO6/YeIXUfzHmgVHn4VMNr8Exfz6zz92cgHacSHSsg3DsGSh 17 | d3EdF2M6rVrwRK+FIv9i3WN9O1gQ6Jx24VRNxg+fkUFIQxbm/ha32Z5M6ryrTuW+ 18 | Wpq+RF/VSpH+E/dEiuj0CLC7bX1FWXJKoGjs+R8CgYEA0vh5X5VvCDrLU1JPRzN1 19 | K9G63UZnYDGO6/3TvjIh60Gcr7RCc3fbu/OJVqOwj1yxnfV0r4eS3V3sV5TnuzxA 20 | BybCB97z3OQixWe37At6U2s9dvc5Z0xT8iCaEasrX1sis+nKaX0fS+3zb4uH7tbi 21 | qBqUXcOsOI6ULqG1dbfoDtkCgYAMcbpkSmg9uTIfQU+0aXXAJzPdfbwSwuNS/qxI 22 | hCIEgor/g+FsHXq5SsUhu+KCLCYT8ubTQid+n/YqpX/wM15U3qhg8COPZI48hkpQ 23 | rmNOfpxCeMJPijz/NcCzjA94m11nHYCGh0vFfxjf+FWQQxs8KVE+Eqm9pVZxbt4d 24 | JPrdvQKBgFPU4UXkyl1IJeAzmL3KygYzXa6PW02A2tziuf7TukJp1m2UWSwugWrq 25 | mNKc6rp+D6OC5Zo6yh3Myo3s3k7HtNxV0AmIt/l2CGZetvAnnLD9SSeB1/j77muP 26 | KgwnV8iZVeuz3sdbsOGE83AT9x2PUs2SLZL9FCMTsJ71q0CVWMyx 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /test/fixtures/configs/config-1.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": false, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [], 8 | "requestCert": false, 9 | "rejectUnauthorized": false 10 | } 11 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-2.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": true, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [], 8 | "requestCert": false, 9 | "rejectUnauthorized": false 10 | } 11 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-3.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": true, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [], 8 | "requestCert": true, 9 | "rejectUnauthorized": true 10 | } 11 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-4.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": false, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [], 8 | "requestCert": true, 9 | "rejectUnauthorized": true 10 | } 11 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-5.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": false, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [ 8 | "local.crt.pem" 9 | ], 10 | "requestCert": true, 11 | "rejectUnauthorized": false 12 | } 13 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-6.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": false, 3 | "certConfig": { 4 | "path": "./test/fixtures/certs/local/q", 5 | "key": "local.pem", 6 | "cert": "local.crt.pem", 7 | "ca": [], 8 | "requestCert": true, 9 | "rejectUnauthorized": false 10 | } 11 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-7.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": true, 3 | "certConfig": {} 4 | } -------------------------------------------------------------------------------- /test/fixtures/configs/config-8.json: -------------------------------------------------------------------------------- 1 | { 2 | "httpMode": false, 3 | "certConfig": { 4 | "path": "", 5 | "key": "", 6 | "cert": "", 7 | "ca": [], 8 | "requestCert": false, 9 | "rejectUnauthorized": false 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/boot/root.js: -------------------------------------------------------------------------------- 1 | module.exports = function(server) { 2 | // Install a `/` route that returns server status 3 | var router = server.loopback.Router(); 4 | router.get('/', server.loopback.status()); 5 | server.use(router); 6 | }; 7 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/component-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "loopback-component-explorer": { 3 | "mountPath": "/explorer" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "restApiRoot": "/", 3 | "host": "0.0.0.0", 4 | "port": 4124, 5 | "httpMode": false, 6 | "certConfig": { 7 | "path": "./test/fixtures/certs/", 8 | "key": "local.pem", 9 | "cert": "local.crt.pem", 10 | "ca": [], 11 | "requestCert": false, 12 | "rejectUnauthorized": false 13 | }, 14 | "remoting": { 15 | "context": { 16 | "enableHttpContext": false 17 | }, 18 | "rest": { 19 | "normalizeHttpPath": false, 20 | "xml": false 21 | }, 22 | "json": { 23 | "strict": false, 24 | "limit": "100kb" 25 | }, 26 | "urlencoded": { 27 | "extended": true, 28 | "limit": "100kb" 29 | }, 30 | "cors": false, 31 | "errorHandler": { 32 | "disableStackTrace": false 33 | } 34 | }, 35 | "legacyExplorer": false 36 | } 37 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/datasources.json: -------------------------------------------------------------------------------- 1 | { 2 | "db": { 3 | "name": "db", 4 | "connector": "memory" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/middleware.json: -------------------------------------------------------------------------------- 1 | { 2 | "initial:before": { 3 | "loopback#favicon": {} 4 | }, 5 | "initial": { 6 | "compression": {}, 7 | "cors": { 8 | "params": { 9 | "origin": true, 10 | "credentials": true, 11 | "maxAge": 86400 12 | } 13 | }, 14 | "helmet#xssFilter": {}, 15 | "helmet#frameguard": { 16 | "params": [ 17 | "deny" 18 | ] 19 | }, 20 | "helmet#hsts": { 21 | "params": { 22 | "maxAge": 0, 23 | "includeSubdomains": true 24 | } 25 | }, 26 | "helmet#hidePoweredBy": {}, 27 | "helmet#ieNoOpen": {}, 28 | "helmet#noSniff": {}, 29 | "helmet#noCache": { 30 | "enabled": false 31 | } 32 | }, 33 | "session": { 34 | }, 35 | "auth": { 36 | }, 37 | "parse": { 38 | }, 39 | "routes": { 40 | "loopback#rest": { 41 | "paths": ["${restApiRoot}"] 42 | } 43 | }, 44 | "files": { 45 | }, 46 | "final": { 47 | "loopback#urlNotFound": {} 48 | }, 49 | "final:after": { 50 | "loopback#errorHandler": {} 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/model-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "sources": [ 4 | "loopback/common/models", 5 | "loopback/server/models", 6 | "../common/models", 7 | "./models" 8 | ], 9 | "mixins": [ 10 | "loopback/common/mixins", 11 | "loopback/server/mixins", 12 | "../common/mixins", 13 | "./mixins" 14 | ] 15 | }, 16 | "Note": { 17 | "dataSource": "db" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/models/note.js: -------------------------------------------------------------------------------- 1 | module.exports = function(Note) { 2 | }; 3 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/models/note.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Note", 3 | "properties": { 4 | "title": { 5 | "type": "string", 6 | "required": true 7 | }, 8 | "content": { 9 | "type": "string" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/server-ssl/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var loopback = require('loopback'); 4 | var boot = require('loopback-boot'); 5 | var loopbackSSL = require('../../../index'); 6 | 7 | var app = module.exports = loopback(); 8 | 9 | boot(app, __dirname, function(err) { 10 | if (err) throw err; 11 | }); 12 | 13 | return loopbackSSL.startServer(app); 14 | -------------------------------------------------------------------------------- /test/fixtures/server/boot/root.js: -------------------------------------------------------------------------------- 1 | module.exports = function(server) { 2 | // Install a `/` route that returns server status 3 | var router = server.loopback.Router(); 4 | router.get('/', server.loopback.status()); 5 | server.use(router); 6 | }; 7 | -------------------------------------------------------------------------------- /test/fixtures/server/component-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "loopback-component-explorer": { 3 | "mountPath": "/explorer" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/fixtures/server/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "restApiRoot": "/", 3 | "host": "0.0.0.0", 4 | "port": 4123, 5 | "httpMode": true, 6 | "certConfig": {}, 7 | "remoting": { 8 | "context": { 9 | "enableHttpContext": false 10 | }, 11 | "rest": { 12 | "normalizeHttpPath": false, 13 | "xml": false 14 | }, 15 | "json": { 16 | "strict": false, 17 | "limit": "100kb" 18 | }, 19 | "urlencoded": { 20 | "extended": true, 21 | "limit": "100kb" 22 | }, 23 | "cors": false, 24 | "errorHandler": { 25 | "disableStackTrace": false 26 | } 27 | }, 28 | "legacyExplorer": false 29 | } 30 | -------------------------------------------------------------------------------- /test/fixtures/server/datasources.json: -------------------------------------------------------------------------------- 1 | { 2 | "db": { 3 | "name": "db", 4 | "connector": "memory" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /test/fixtures/server/middleware.json: -------------------------------------------------------------------------------- 1 | { 2 | "initial:before": { 3 | "loopback#favicon": {} 4 | }, 5 | "initial": { 6 | "compression": {}, 7 | "cors": { 8 | "params": { 9 | "origin": true, 10 | "credentials": true, 11 | "maxAge": 86400 12 | } 13 | }, 14 | "helmet#xssFilter": {}, 15 | "helmet#frameguard": { 16 | "params": [ 17 | "deny" 18 | ] 19 | }, 20 | "helmet#hsts": { 21 | "params": { 22 | "maxAge": 0, 23 | "includeSubdomains": true 24 | } 25 | }, 26 | "helmet#hidePoweredBy": {}, 27 | "helmet#ieNoOpen": {}, 28 | "helmet#noSniff": {}, 29 | "helmet#noCache": { 30 | "enabled": false 31 | } 32 | }, 33 | "session": { 34 | }, 35 | "auth": { 36 | }, 37 | "parse": { 38 | }, 39 | "routes": { 40 | "loopback#rest": { 41 | "paths": ["${restApiRoot}"] 42 | } 43 | }, 44 | "files": { 45 | }, 46 | "final": { 47 | "loopback#urlNotFound": {} 48 | }, 49 | "final:after": { 50 | "loopback#errorHandler": {} 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /test/fixtures/server/model-config.json: -------------------------------------------------------------------------------- 1 | { 2 | "_meta": { 3 | "sources": [ 4 | "loopback/common/models", 5 | "loopback/server/models", 6 | "../common/models", 7 | "./models" 8 | ], 9 | "mixins": [ 10 | "loopback/common/mixins", 11 | "loopback/server/mixins", 12 | "../common/mixins", 13 | "./mixins" 14 | ] 15 | }, 16 | "Note": { 17 | "dataSource": "db" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/fixtures/server/models/note.js: -------------------------------------------------------------------------------- 1 | module.exports = function(Note) { 2 | }; 3 | -------------------------------------------------------------------------------- /test/fixtures/server/models/note.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Note", 3 | "properties": { 4 | "title": { 5 | "type": "string", 6 | "required": true 7 | }, 8 | "content": { 9 | "type": "string" 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/fixtures/server/server.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var loopback = require('loopback'); 4 | var boot = require('loopback-boot'); 5 | var loopbackSSL = require('../../../index'); 6 | 7 | var app = module.exports = loopback(); 8 | 9 | boot(app, __dirname, function(err) { 10 | if (err) throw err; 11 | }); 12 | 13 | return loopbackSSL.startServer(app); 14 | -------------------------------------------------------------------------------- /test/loopback-http-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var lt = require('loopback-testing'); 4 | var assert = require('assert'); 5 | var app = require('./fixtures/server/server.js'); //path to app.js or server.js 6 | 7 | describe('Testing HTTP Server Start', function () { 8 | describe('/notes', function() { 9 | lt.beforeEach.withApp(app); 10 | lt.describe.whenCalledRemotely('GET', '/notes', function() { 11 | it('should have statusCode 200', function(done) { 12 | assert.equal(this.res.statusCode, 200); 13 | done(); 14 | }); 15 | }); 16 | }); 17 | }); -------------------------------------------------------------------------------- /test/loopback-https-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var lt = require('loopback-testing'); 4 | var assert = require('assert'); 5 | var app = require('./fixtures/server-ssl/server.js'); //path to app.js or server.js 6 | 7 | describe('Testing HTTPS Server Start', function () { 8 | describe('/notes', function() { 9 | lt.beforeEach.withApp(app); 10 | lt.describe.whenCalledRemotely('GET', '/notes', function() { 11 | it('should have statusCode 200', function(done) { 12 | assert.equal(this.res.statusCode, 200); 13 | done(); 14 | }); 15 | }); 16 | }); 17 | }); -------------------------------------------------------------------------------- /test/loopback-ssl-config-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var loopbackSSL = require('../lib/loopback-ssl'); 4 | var assert = require('chai').assert; 5 | 6 | var testConfig1 = require('./fixtures/configs/config-1.json'); 7 | var testConfig2 = require('./fixtures/configs/config-2.json'); 8 | var testConfig3 = require('./fixtures/configs/config-3.json'); 9 | var testConfig4 = require('./fixtures/configs/config-4.json'); 10 | var testConfig5 = require('./fixtures/configs/config-5.json'); 11 | var testConfig6 = require('./fixtures/configs/config-6.json'); 12 | var testConfig7 = require('./fixtures/configs/config-7.json'); 13 | 14 | describe('Testing Certificate Configuration', function () { 15 | it('test:1 - should be able to load server key and certificates', function(done){ 16 | var ret = loopbackSSL.getServerOptions(testConfig1.certConfig); 17 | done(); 18 | }); 19 | 20 | it('test:2 - should be able to load server key, ' + 21 | 'certificates and client authentication certificate', function(done){ 22 | var ret = loopbackSSL.getServerOptions(testConfig2.certConfig); 23 | done(); 24 | }); 25 | 26 | it('test:3 - should be able to load server key, ' + 27 | 'certificates and multiple client authentication certificate', function(done){ 28 | var ret = loopbackSSL.getServerOptions(testConfig3.certConfig); 29 | done(); 30 | }) 31 | 32 | it('test:4 - should be able enable mutual ssl', function(done){ 33 | var ret = loopbackSSL.getServerOptions(testConfig4.certConfig); 34 | assert.equal(ret.rejectUnauthorized, true); 35 | done(); 36 | }); 37 | 38 | it('test:5 - should be able disable client certificate validation', function(done){ 39 | var ret = loopbackSSL.getServerOptions(testConfig5.certConfig); 40 | assert.equal(ret.rejectUnauthorized, false); 41 | done(); 42 | }); 43 | 44 | it('test:6 - should fail if the key path is invalid', function(done){ 45 | try { 46 | loopbackSSL.getServerOptions(testConfig6.certConfig); 47 | } catch (e) { 48 | done(); 49 | } 50 | }); 51 | 52 | it('test:7 - should pass httpMode=true and no other options are provided', function(done){ 53 | try { 54 | loopbackSSL.getServerOptions(testConfig7.certConfig); 55 | } catch (e) { 56 | done(); 57 | } 58 | }); 59 | }); 60 | -------------------------------------------------------------------------------- /test/loopback-ssl-test.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | --------------------------------------------------------------------------------